aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
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
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')
-rw-r--r--sway/commands/focus.c3
-rw-r--r--sway/commands/move.c19
-rw-r--r--sway/commands/sticky.c6
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/commands/titlebar_border_thickness.c7
5 files changed, 37 insertions, 2 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 79b2f551..25df5130 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -37,6 +37,9 @@ static struct sway_node *get_node_in_output_direction(
37 struct sway_output *output, enum wlr_direction dir) { 37 struct sway_output *output, enum wlr_direction dir) {
38 struct sway_seat *seat = config->handler_context.seat; 38 struct sway_seat *seat = config->handler_context.seat;
39 struct sway_workspace *ws = output_get_active_workspace(output); 39 struct sway_workspace *ws = output_get_active_workspace(output);
40 if (!sway_assert(ws, "Expected output to have a workspace")) {
41 return NULL;
42 }
40 if (ws->fullscreen) { 43 if (ws->fullscreen) {
41 return seat_get_focus_inactive(seat, &ws->fullscreen->node); 44 return seat_get_focus_inactive(seat, &ws->fullscreen->node);
42 } 45 }
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
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c
index 5b70199c..9df1fe09 100644
--- a/sway/commands/sticky.c
+++ b/sway/commands/sticky.c
@@ -9,6 +9,7 @@
9#include "sway/tree/view.h" 9#include "sway/tree/view.h"
10#include "sway/tree/workspace.h" 10#include "sway/tree/workspace.h"
11#include "list.h" 11#include "list.h"
12#include "log.h"
12#include "util.h" 13#include "util.h"
13 14
14struct cmd_results *cmd_sticky(int argc, char **argv) { 15struct cmd_results *cmd_sticky(int argc, char **argv) {
@@ -29,6 +30,11 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
29 // move container to active workspace 30 // move container to active workspace
30 struct sway_workspace *active_workspace = 31 struct sway_workspace *active_workspace =
31 output_get_active_workspace(container->workspace->output); 32 output_get_active_workspace(container->workspace->output);
33 if (!sway_assert(active_workspace,
34 "Expected output to have a workspace")) {
35 return cmd_results_new(CMD_FAILURE,
36 "Expected output to have a workspace");
37 }
32 if (container->workspace != active_workspace) { 38 if (container->workspace != active_workspace) {
33 struct sway_workspace *old_workspace = container->workspace; 39 struct sway_workspace *old_workspace = container->workspace;
34 container_detach(container); 40 container_detach(container);
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index 0e2c2d10..b978af16 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -118,6 +118,10 @@ static void container_swap(struct sway_container *con1,
118 output_get_active_workspace(con1->workspace->output); 118 output_get_active_workspace(con1->workspace->output);
119 struct sway_workspace *vis2 = 119 struct sway_workspace *vis2 =
120 output_get_active_workspace(con2->workspace->output); 120 output_get_active_workspace(con2->workspace->output);
121 if (!sway_assert(vis1 && vis2, "con1 or con2 are on an output without a"
122 "workspace. This should not happen")) {
123 return;
124 }
121 125
122 char *stored_prev_name = NULL; 126 char *stored_prev_name = NULL;
123 if (seat->prev_workspace_name) { 127 if (seat->prev_workspace_name) {
diff --git a/sway/commands/titlebar_border_thickness.c b/sway/commands/titlebar_border_thickness.c
index 3c5e9ba1..7c27c163 100644
--- a/sway/commands/titlebar_border_thickness.c
+++ b/sway/commands/titlebar_border_thickness.c
@@ -21,7 +21,12 @@ struct cmd_results *cmd_titlebar_border_thickness(int argc, char **argv) {
21 21
22 for (int i = 0; i < root->outputs->length; ++i) { 22 for (int i = 0; i < root->outputs->length; ++i) {
23 struct sway_output *output = root->outputs->items[i]; 23 struct sway_output *output = root->outputs->items[i];
24 arrange_workspace(output_get_active_workspace(output)); 24 struct sway_workspace *ws = output_get_active_workspace(output);
25 if (!sway_assert(ws, "Expected output to have a workspace")) {
26 return cmd_results_new(CMD_FAILURE,
27 "Expected output to have a workspace");
28 }
29 arrange_workspace(ws);
25 output_damage_whole(output); 30 output_damage_whole(output);
26 } 31 }
27 32