diff options
author | Ankit Pandey <anpandey@protonmail.com> | 2022-12-11 16:44:48 -0800 |
---|---|---|
committer | Ronan Pigott <ronan@rjp.ie> | 2023-03-14 23:26:42 -0700 |
commit | 90c2d631e2dc4c7633bb8fcd92f300a4a2dffb86 (patch) | |
tree | 218db72a61c8e7b55cf39d241e51ee0780636670 /sway/tree/root.c | |
parent | man: add warning for hide_cursor configuration (diff) | |
download | sway-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/root.c')
-rw-r--r-- | sway/tree/root.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/sway/tree/root.c b/sway/tree/root.c index 95129a88..233358d2 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -56,6 +56,16 @@ void root_destroy(struct sway_root *root) { | |||
56 | free(root); | 56 | free(root); |
57 | } | 57 | } |
58 | 58 | ||
59 | static void set_container_transform(struct sway_workspace *ws, | ||
60 | struct sway_container *con) { | ||
61 | struct sway_output *output = ws->output; | ||
62 | struct wlr_box box = {0}; | ||
63 | if (output) { | ||
64 | output_get_box(output, &box); | ||
65 | } | ||
66 | con->transform = box; | ||
67 | } | ||
68 | |||
59 | void root_scratchpad_add_container(struct sway_container *con, struct sway_workspace *ws) { | 69 | void root_scratchpad_add_container(struct sway_container *con, struct sway_workspace *ws) { |
60 | if (!sway_assert(!con->scratchpad, "Container is already in scratchpad")) { | 70 | if (!sway_assert(!con->scratchpad, "Container is already in scratchpad")) { |
61 | return; | 71 | return; |
@@ -64,6 +74,8 @@ void root_scratchpad_add_container(struct sway_container *con, struct sway_works | |||
64 | struct sway_container *parent = con->pending.parent; | 74 | struct sway_container *parent = con->pending.parent; |
65 | struct sway_workspace *workspace = con->pending.workspace; | 75 | struct sway_workspace *workspace = con->pending.workspace; |
66 | 76 | ||
77 | set_container_transform(workspace, con); | ||
78 | |||
67 | // Clear the fullscreen mode when sending to the scratchpad | 79 | // Clear the fullscreen mode when sending to the scratchpad |
68 | if (con->pending.fullscreen_mode != FULLSCREEN_NONE) { | 80 | if (con->pending.fullscreen_mode != FULLSCREEN_NONE) { |
69 | container_fullscreen_disable(con); | 81 | container_fullscreen_disable(con); |
@@ -142,15 +154,12 @@ void root_scratchpad_show(struct sway_container *con) { | |||
142 | } | 154 | } |
143 | workspace_add_floating(new_ws, con); | 155 | workspace_add_floating(new_ws, con); |
144 | 156 | ||
145 | // Make sure the container's center point overlaps this workspace | 157 | if (new_ws->output) { |
146 | double center_lx = con->pending.x + con->pending.width / 2; | 158 | struct wlr_box output_box; |
147 | double center_ly = con->pending.y + con->pending.height / 2; | 159 | output_get_box(new_ws->output, &output_box); |
148 | 160 | floating_fix_coordinates(con, &con->transform, &output_box); | |
149 | struct wlr_box workspace_box; | ||
150 | workspace_get_box(new_ws, &workspace_box); | ||
151 | if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) { | ||
152 | container_floating_resize_and_center(con); | ||
153 | } | 161 | } |
162 | set_container_transform(new_ws, con); | ||
154 | 163 | ||
155 | arrange_workspace(new_ws); | 164 | arrange_workspace(new_ws); |
156 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); | 165 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); |
@@ -173,6 +182,8 @@ void root_scratchpad_hide(struct sway_container *con) { | |||
173 | return; | 182 | return; |
174 | } | 183 | } |
175 | 184 | ||
185 | set_container_transform(con->pending.workspace, con); | ||
186 | |||
176 | disable_fullscreen(con, NULL); | 187 | disable_fullscreen(con, NULL); |
177 | container_for_each_child(con, disable_fullscreen, NULL); | 188 | container_for_each_child(con, disable_fullscreen, NULL); |
178 | container_detach(con); | 189 | container_detach(con); |