aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-07 00:03:01 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-07 00:03:01 +1000
commitf57a3919cf5ad7c3edbf9e2e19051971a5f2d42f (patch)
tree0f802f51d929d830133c1aada040e051ff79a9e3 /sway/tree/layout.c
parentMerge pull request #2422 from ggreer/compiler-errors (diff)
downloadsway-f57a3919cf5ad7c3edbf9e2e19051971a5f2d42f.tar.gz
sway-f57a3919cf5ad7c3edbf9e2e19051971a5f2d42f.tar.zst
sway-f57a3919cf5ad7c3edbf9e2e19051971a5f2d42f.zip
Move workspace moving code out of container_move_to
container_move_to handled moving containers to new parents, as well as moving workspaces to new outputs. This commit removes the workspace-moving code from this function and introduces workspace_move_to_output. Moving workspaces using container_move_to only happened from the move command, so it's been implemented as a static function in that file. Simplifying container_move_to makes it easier for me to fix some issues in #2420.
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 07de9664..9485e675 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -142,6 +142,10 @@ struct sway_container *container_remove_child(struct sway_container *child) {
142 142
143void container_move_to(struct sway_container *container, 143void container_move_to(struct sway_container *container,
144 struct sway_container *destination) { 144 struct sway_container *destination) {
145 if (!sway_assert(container->type == C_CONTAINER ||
146 container->type == C_VIEW, "Expected a container or view")) {
147 return;
148 }
145 if (container == destination 149 if (container == destination
146 || container_has_ancestor(container, destination)) { 150 || container_has_ancestor(container, destination)) {
147 return; 151 return;
@@ -154,11 +158,8 @@ void container_move_to(struct sway_container *container,
154 container->width = container->height = 0; 158 container->width = container->height = 0;
155 container->saved_width = container->saved_height = 0; 159 container->saved_width = container->saved_height = 0;
156 160
157 struct sway_container *new_parent, *new_parent_focus; 161 struct sway_container *new_parent;
158 struct sway_seat *seat = input_manager_get_default_seat(input_manager);
159 162
160 // Get the focus of the destination before we change it.
161 new_parent_focus = seat_get_focus_inactive(seat, destination);
162 if (destination->type == C_VIEW) { 163 if (destination->type == C_VIEW) {
163 new_parent = container_add_sibling(destination, container); 164 new_parent = container_add_sibling(destination, container);
164 } else { 165 } else {
@@ -167,24 +168,7 @@ void container_move_to(struct sway_container *container,
167 } 168 }
168 wl_signal_emit(&container->events.reparent, old_parent); 169 wl_signal_emit(&container->events.reparent, old_parent);
169 170
170 if (container->type == C_WORKSPACE) { 171 if (container->type == C_VIEW) {
171 // If moving a workspace to a new output, maybe create a new workspace
172 // on the previous output
173 if (old_parent->children->length == 0) {
174 char *ws_name = workspace_next_name(old_parent->name);
175 struct sway_container *ws = workspace_create(old_parent, ws_name);
176 free(ws_name);
177 seat_set_focus(seat, ws);
178 }
179
180 // Try to remove an empty workspace from the destination output.
181 container_reap_empty_recursive(new_parent_focus);
182
183 container_sort_workspaces(new_parent);
184 seat_set_focus(seat, new_parent);
185 workspace_output_raise_priority(container, old_parent, new_parent);
186 ipc_event_workspace(NULL, container, "move");
187 } else if (container->type == C_VIEW) {
188 ipc_event_window(container, "move"); 172 ipc_event_window(container, "move");
189 } 173 }
190 container_notify_subtree_changed(old_parent); 174 container_notify_subtree_changed(old_parent);