aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Ankit Pandey <anpandey@protonmail.com>2022-12-11 16:44:48 -0800
committerLibravatar Ronan Pigott <ronan@rjp.ie>2023-03-14 23:26:42 -0700
commit90c2d631e2dc4c7633bb8fcd92f300a4a2dffb86 (patch)
tree218db72a61c8e7b55cf39d241e51ee0780636670 /sway/tree/arrange.c
parentman: add warning for hide_cursor configuration (diff)
downloadsway-90c2d631e2dc4c7633bb8fcd92f300a4a2dffb86.tar.gz
sway-90c2d631e2dc4c7633bb8fcd92f300a4a2dffb86.tar.zst
sway-90c2d631e2dc4c7633bb8fcd92f300a4a2dffb86.zip
root: Try to preserve relative positions of floating containers
This makes the behavior of floating containers more consistent with i3. The coordinates of the container are scaled when the size of the workspace it is on changes or when the container is moved between workspaces on different outputs. For scratchpad containers, add a new state that preserves the dimensions of the last output the window appeared on. This is necessary because after a container is hidden in the scratchpad, we expect it to be in the same relative position on the output when it reappears. We can't just use the container's attached workspace because that workspace's dimensions might have been changed or the workspace as a whole could have been destroyed.
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 9c1a11e5..af925d05 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -264,6 +264,9 @@ void arrange_workspace(struct sway_workspace *workspace) {
264 area->width, area->height, area->x, area->y); 264 area->width, area->height, area->x, area->y);
265 265
266 bool first_arrange = workspace->width == 0 && workspace->height == 0; 266 bool first_arrange = workspace->width == 0 && workspace->height == 0;
267 struct wlr_box prev_box;
268 workspace_get_box(workspace, &prev_box);
269
267 double prev_x = workspace->x - workspace->current_gaps.left; 270 double prev_x = workspace->x - workspace->current_gaps.left;
268 double prev_y = workspace->y - workspace->current_gaps.top; 271 double prev_y = workspace->y - workspace->current_gaps.top;
269 workspace->width = area->width; 272 workspace->width = area->width;
@@ -277,13 +280,14 @@ void arrange_workspace(struct sway_workspace *workspace) {
277 if (!first_arrange && (diff_x != 0 || diff_y != 0)) { 280 if (!first_arrange && (diff_x != 0 || diff_y != 0)) {
278 for (int i = 0; i < workspace->floating->length; ++i) { 281 for (int i = 0; i < workspace->floating->length; ++i) {
279 struct sway_container *floater = workspace->floating->items[i]; 282 struct sway_container *floater = workspace->floating->items[i];
280 container_floating_translate(floater, diff_x, diff_y);
281 double center_x = floater->pending.x + floater->pending.width / 2;
282 double center_y = floater->pending.y + floater->pending.height / 2;
283 struct wlr_box workspace_box; 283 struct wlr_box workspace_box;
284 workspace_get_box(workspace, &workspace_box); 284 workspace_get_box(workspace, &workspace_box);
285 if (!wlr_box_contains_point(&workspace_box, center_x, center_y)) { 285 floating_fix_coordinates(floater, &prev_box, &workspace_box);
286 container_floating_move_to_center(floater); 286 // Set transformation for scratchpad windows.
287 if (floater->scratchpad) {
288 struct wlr_box output_box;
289 output_get_box(output, &output_box);
290 floater->transform = output_box;
287 } 291 }
288 } 292 }
289 } 293 }