diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-24 16:03:24 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-24 16:03:24 +1000 |
commit | b6a238c7b70bfb6520c55c480bf6a7e60b4f7db4 (patch) | |
tree | 545fb9969d935078f8eaf094fd0b4f9cde6014d7 /sway/commands/move.c | |
parent | Fix crash when unmapping a view with reapable parents (diff) | |
download | sway-b6a238c7b70bfb6520c55c480bf6a7e60b4f7db4.tar.gz sway-b6a238c7b70bfb6520c55c480bf6a7e60b4f7db4.tar.zst sway-b6a238c7b70bfb6520c55c480bf6a7e60b4f7db4.zip |
Fix crash when running move <direction> in an empty workspace
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index da0f89e9..4ce8d089 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -175,8 +175,12 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, | |||
175 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 175 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
176 | } | 176 | } |
177 | 177 | ||
178 | static void move_in_direction(struct sway_container *container, | 178 | static struct cmd_results *move_in_direction(struct sway_container *container, |
179 | enum wlr_direction direction, int move_amt) { | 179 | enum wlr_direction direction, int move_amt) { |
180 | if (container->type == C_WORKSPACE) { | ||
181 | return cmd_results_new(CMD_FAILURE, "move", | ||
182 | "Cannot move workspaces in a direction"); | ||
183 | } | ||
180 | // For simplicity, we'll arrange the entire workspace. The reason for this | 184 | // For simplicity, we'll arrange the entire workspace. The reason for this |
181 | // is moving the container might reap the old parent, and container_move | 185 | // is moving the container might reap the old parent, and container_move |
182 | // does not return a surviving parent. | 186 | // does not return a surviving parent. |
@@ -192,6 +196,8 @@ static void move_in_direction(struct sway_container *container, | |||
192 | arrange_windows(new_ws, txn); | 196 | arrange_windows(new_ws, txn); |
193 | } | 197 | } |
194 | transaction_commit(txn); | 198 | transaction_commit(txn); |
199 | |||
200 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
195 | } | 201 | } |
196 | 202 | ||
197 | struct cmd_results *cmd_move(int argc, char **argv) { | 203 | struct cmd_results *cmd_move(int argc, char **argv) { |
@@ -212,13 +218,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { | |||
212 | } | 218 | } |
213 | 219 | ||
214 | if (strcasecmp(argv[0], "left") == 0) { | 220 | if (strcasecmp(argv[0], "left") == 0) { |
215 | move_in_direction(current, MOVE_LEFT, move_amt); | 221 | return move_in_direction(current, MOVE_LEFT, move_amt); |
216 | } else if (strcasecmp(argv[0], "right") == 0) { | 222 | } else if (strcasecmp(argv[0], "right") == 0) { |
217 | move_in_direction(current, MOVE_RIGHT, move_amt); | 223 | return move_in_direction(current, MOVE_RIGHT, move_amt); |
218 | } else if (strcasecmp(argv[0], "up") == 0) { | 224 | } else if (strcasecmp(argv[0], "up") == 0) { |
219 | move_in_direction(current, MOVE_UP, move_amt); | 225 | return move_in_direction(current, MOVE_UP, move_amt); |
220 | } else if (strcasecmp(argv[0], "down") == 0) { | 226 | } else if (strcasecmp(argv[0], "down") == 0) { |
221 | move_in_direction(current, MOVE_DOWN, move_amt); | 227 | return move_in_direction(current, MOVE_DOWN, move_amt); |
222 | } else if (strcasecmp(argv[0], "container") == 0 | 228 | } else if (strcasecmp(argv[0], "container") == 0 |
223 | || strcasecmp(argv[0], "window") == 0) { | 229 | || strcasecmp(argv[0], "window") == 0) { |
224 | return cmd_move_container(current, argc, argv); | 230 | return cmd_move_container(current, argc, argv); |