diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-07 00:03:01 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-07 00:03:01 +1000 |
commit | f57a3919cf5ad7c3edbf9e2e19051971a5f2d42f (patch) | |
tree | 0f802f51d929d830133c1aada040e051ff79a9e3 | |
parent | Merge pull request #2422 from ggreer/compiler-errors (diff) | |
download | sway-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.
-rw-r--r-- | sway/commands/move.c | 44 | ||||
-rw-r--r-- | sway/tree/layout.c | 28 |
2 files changed, 49 insertions, 23 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 841da4c4..1af98e1f 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "sway/commands.h" | 8 | #include "sway/commands.h" |
9 | #include "sway/input/cursor.h" | 9 | #include "sway/input/cursor.h" |
10 | #include "sway/input/seat.h" | 10 | #include "sway/input/seat.h" |
11 | #include "sway/ipc-server.h" | ||
11 | #include "sway/output.h" | 12 | #include "sway/output.h" |
12 | #include "sway/tree/arrange.h" | 13 | #include "sway/tree/arrange.h" |
13 | #include "sway/tree/container.h" | 14 | #include "sway/tree/container.h" |
@@ -15,6 +16,7 @@ | |||
15 | #include "sway/tree/workspace.h" | 16 | #include "sway/tree/workspace.h" |
16 | #include "stringop.h" | 17 | #include "stringop.h" |
17 | #include "list.h" | 18 | #include "list.h" |
19 | #include "log.h" | ||
18 | 20 | ||
19 | static const char* expected_syntax = | 21 | static const char* expected_syntax = |
20 | "Expected 'move <left|right|up|down> <[px] px>' or " | 22 | "Expected 'move <left|right|up|down> <[px] px>' or " |
@@ -152,6 +154,46 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
152 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | 154 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); |
153 | } | 155 | } |
154 | 156 | ||
157 | static void workspace_move_to_output(struct sway_container *workspace, | ||
158 | struct sway_container *output) { | ||
159 | if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) { | ||
160 | return; | ||
161 | } | ||
162 | if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) { | ||
163 | return; | ||
164 | } | ||
165 | if (workspace->parent == output) { | ||
166 | return; | ||
167 | } | ||
168 | struct sway_container *old_output = container_remove_child(workspace); | ||
169 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
170 | struct sway_container *new_output_focus = | ||
171 | seat_get_focus_inactive(seat, output); | ||
172 | |||
173 | container_add_child(output, workspace); | ||
174 | wl_signal_emit(&workspace->events.reparent, old_output); | ||
175 | |||
176 | // If moving the last workspace from the old output, create a new workspace | ||
177 | // on the old output | ||
178 | if (old_output->children->length == 0) { | ||
179 | char *ws_name = workspace_next_name(old_output->name); | ||
180 | struct sway_container *ws = workspace_create(old_output, ws_name); | ||
181 | free(ws_name); | ||
182 | seat_set_focus(seat, ws); | ||
183 | } | ||
184 | |||
185 | // Try to remove an empty workspace from the destination output. | ||
186 | container_reap_empty_recursive(new_output_focus); | ||
187 | |||
188 | container_sort_workspaces(output); | ||
189 | seat_set_focus(seat, output); | ||
190 | workspace_output_raise_priority(workspace, old_output, output); | ||
191 | ipc_event_workspace(NULL, workspace, "move"); | ||
192 | |||
193 | container_notify_subtree_changed(old_output); | ||
194 | container_notify_subtree_changed(output); | ||
195 | } | ||
196 | |||
155 | static struct cmd_results *cmd_move_workspace(struct sway_container *current, | 197 | static struct cmd_results *cmd_move_workspace(struct sway_container *current, |
156 | int argc, char **argv) { | 198 | int argc, char **argv) { |
157 | struct cmd_results *error = NULL; | 199 | struct cmd_results *error = NULL; |
@@ -173,7 +215,7 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, | |||
173 | if (current->type != C_WORKSPACE) { | 215 | if (current->type != C_WORKSPACE) { |
174 | current = container_parent(current, C_WORKSPACE); | 216 | current = container_parent(current, C_WORKSPACE); |
175 | } | 217 | } |
176 | container_move_to(current, destination); | 218 | workspace_move_to_output(current, destination); |
177 | 219 | ||
178 | arrange_windows(source); | 220 | arrange_windows(source); |
179 | arrange_windows(destination); | 221 | arrange_windows(destination); |
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 | ||
143 | void container_move_to(struct sway_container *container, | 143 | void 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); |