aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-02-21 13:24:13 -0500
committerLibravatar emersion <contact@emersion.fr>2019-02-21 21:18:03 +0100
commitd3d7956576341bbbfb60d045175b0e8a44752e0b (patch)
tree0df81ca066ab77d569baf41623f652b1c7f8a638 /sway/commands/move.c
parentMerge pull request #3743 from RedSoxFan/fix-output-get-active-workspace (diff)
downloadsway-d3d7956576341bbbfb60d045175b0e8a44752e0b.tar.gz
sway-d3d7956576341bbbfb60d045175b0e8a44752e0b.tar.zst
sway-d3d7956576341bbbfb60d045175b0e8a44752e0b.zip
Handle NULL from output_get_active_workspace
This modifies the places where output_get_active_workspace is called to handle a NULL result. Some places already handled it and did not need a change, some just have guard off code blocks, others return errors, and some have sway_asserts since the case should never happen. A lot of this is probably just safety precautions since they probably will never be called when `output_get_active_workspace` is not fully configured with a workspace.
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 16f8cdb6..d4fb9022 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -283,6 +283,9 @@ static bool container_move_in_direction(struct sway_container *container,
283 return false; 283 return false;
284 } 284 }
285 struct sway_workspace *ws = output_get_active_workspace(new_output); 285 struct sway_workspace *ws = output_get_active_workspace(new_output);
286 if (!sway_assert(ws, "Expected output to have a workspace")) {
287 return false;
288 }
286 container_move_to_workspace(container, ws); 289 container_move_to_workspace(container, ws);
287 return true; 290 return true;
288 } 291 }
@@ -360,6 +363,9 @@ static bool container_move_in_direction(struct sway_container *container,
360 output_get_in_direction(container->workspace->output, move_dir); 363 output_get_in_direction(container->workspace->output, move_dir);
361 if (output) { 364 if (output) {
362 struct sway_workspace *ws = output_get_active_workspace(output); 365 struct sway_workspace *ws = output_get_active_workspace(output);
366 if (!sway_assert(ws, "Expected output to have a workspace")) {
367 return false;
368 }
363 container_move_to_workspace_from_direction(container, ws, move_dir); 369 container_move_to_workspace_from_direction(container, ws, move_dir);
364 return true; 370 return true;
365 } 371 }
@@ -525,6 +531,10 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
525 case N_OUTPUT: { 531 case N_OUTPUT: {
526 struct sway_output *output = destination->sway_output; 532 struct sway_output *output = destination->sway_output;
527 struct sway_workspace *ws = output_get_active_workspace(output); 533 struct sway_workspace *ws = output_get_active_workspace(output);
534 if (!sway_assert(ws, "Expected output to have a workspace")) {
535 return cmd_results_new(CMD_FAILURE,
536 "Expected output to have a workspace");
537 }
528 container_move_to_workspace(container, ws); 538 container_move_to_workspace(container, ws);
529 } 539 }
530 break; 540 break;
@@ -538,7 +548,11 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
538 // restore focus on destination output back to its last active workspace 548 // restore focus on destination output back to its last active workspace
539 struct sway_workspace *new_workspace = 549 struct sway_workspace *new_workspace =
540 output_get_active_workspace(new_output); 550 output_get_active_workspace(new_output);
541 if (new_output_last_ws && new_output_last_ws != new_workspace) { 551 if (!sway_assert(new_workspace, "Expected output to have a workspace")) {
552 return cmd_results_new(CMD_FAILURE,
553 "Expected output to have a workspace");
554 }
555 if (new_output_last_ws != new_workspace) {
542 struct sway_node *new_output_last_focus = 556 struct sway_node *new_output_last_focus =
543 seat_get_focus_inactive(seat, &new_output_last_ws->node); 557 seat_get_focus_inactive(seat, &new_output_last_ws->node);
544 seat_set_raw_focus(seat, new_output_last_focus); 558 seat_set_raw_focus(seat, new_output_last_focus);
@@ -585,6 +599,9 @@ static void workspace_move_to_output(struct sway_workspace *workspace,
585 workspace_detach(workspace); 599 workspace_detach(workspace);
586 struct sway_workspace *new_output_old_ws = 600 struct sway_workspace *new_output_old_ws =
587 output_get_active_workspace(output); 601 output_get_active_workspace(output);
602 if (!sway_assert(new_output_old_ws, "Expected output to have a workspace")) {
603 return;
604 }
588 605
589 output_add_workspace(output, workspace); 606 output_add_workspace(output, workspace);
590 607