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 /sway/commands/move.c | |
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.
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 44 |
1 files changed, 43 insertions, 1 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); |