aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-03-12 13:57:40 -0400
committerLibravatar emersion <contact@emersion.fr>2019-03-12 19:14:04 +0100
commit3330faded5ed59b19b2a1982bb52c05322b03510 (patch)
treef6acaeb4793ff21534e84ea5b9b37bf87ddf7f91
parentconfig.in: allow launch apps with args via dmenu (diff)
downloadsway-3330faded5ed59b19b2a1982bb52c05322b03510.tar.gz
sway-3330faded5ed59b19b2a1982bb52c05322b03510.tar.zst
sway-3330faded5ed59b19b2a1982bb52c05322b03510.zip
Handle seat_get_focused_workspace returning NULL
This modifiers the callers of seat_get_focused_workspace to handle getting NULL as the return value, if they did not already.
-rw-r--r--sway/commands/focus.c5
-rw-r--r--sway/commands/scratchpad.c5
-rw-r--r--sway/commands/workspace.c6
-rw-r--r--sway/desktop/layer_shell.c1
-rw-r--r--sway/tree/root.c4
-rw-r--r--sway/tree/workspace.c13
6 files changed, 27 insertions, 7 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 25df5130..6344a765 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -208,6 +208,11 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
208 "There is no output with that name"); 208 "There is no output with that name");
209 } 209 }
210 struct sway_workspace *ws = seat_get_focused_workspace(seat); 210 struct sway_workspace *ws = seat_get_focused_workspace(seat);
211 if (!ws) {
212 free(identifier);
213 return cmd_results_new(CMD_FAILURE,
214 "No focused workspace to base directions off of");
215 }
211 output = output_get_in_direction(ws->output, direction); 216 output = output_get_in_direction(ws->output, direction);
212 217
213 if (!output) { 218 if (!output) {
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
index 71afa306..34871bc6 100644
--- a/sway/commands/scratchpad.c
+++ b/sway/commands/scratchpad.c
@@ -12,6 +12,11 @@ static void scratchpad_toggle_auto(void) {
12 struct sway_seat *seat = input_manager_current_seat(); 12 struct sway_seat *seat = input_manager_current_seat();
13 struct sway_container *focus = seat_get_focused_container(seat); 13 struct sway_container *focus = seat_get_focused_container(seat);
14 struct sway_workspace *ws = seat_get_focused_workspace(seat); 14 struct sway_workspace *ws = seat_get_focused_workspace(seat);
15 if (!ws) {
16 sway_log(SWAY_DEBUG,
17 "No focused workspace to toggle scratchpad windows on");
18 return;
19 }
15 20
16 // If the focus is in a floating split container, 21 // If the focus is in a floating split container,
17 // operate on the split container instead of the child. 22 // operate on the split container instead of the child.
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 362dcd1b..b911b2f6 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -185,8 +185,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
185 struct sway_seat *seat = config->handler_context.seat; 185 struct sway_seat *seat = config->handler_context.seat;
186 struct sway_workspace *current = seat_get_focused_workspace(seat); 186 struct sway_workspace *current = seat_get_focused_workspace(seat);
187 if (!current) { 187 if (!current) {
188 return cmd_results_new(CMD_FAILURE, "workspace", 188 return cmd_results_new(CMD_FAILURE, "No workspace to switch from");
189 "No workspace to switch from");
190 } 189 }
191 190
192 struct sway_workspace *ws = NULL; 191 struct sway_workspace *ws = NULL;
@@ -227,6 +226,9 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
227 } 226 }
228 free(name); 227 free(name);
229 } 228 }
229 if (!ws) {
230 return cmd_results_new(CMD_FAILURE, "No workspace to switch to");
231 }
230 workspace_switch(ws, no_auto_back_and_forth); 232 workspace_switch(ws, no_auto_back_and_forth);
231 seat_consider_warp_to_focus(seat); 233 seat_consider_warp_to_focus(seat);
232 } 234 }
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index b2fea880..1667995c 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -373,7 +373,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
373 struct sway_seat *seat = input_manager_get_default_seat(); 373 struct sway_seat *seat = input_manager_get_default_seat();
374 if (seat) { 374 if (seat) {
375 struct sway_workspace *ws = seat_get_focused_workspace(seat); 375 struct sway_workspace *ws = seat_get_focused_workspace(seat);
376
377 if (ws != NULL) { 376 if (ws != NULL) {
378 output = ws->output; 377 output = ws->output;
379 } 378 }
diff --git a/sway/tree/root.c b/sway/tree/root.c
index 6e13d6ce..0744192b 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -96,6 +96,10 @@ void root_scratchpad_remove_container(struct sway_container *con) {
96void root_scratchpad_show(struct sway_container *con) { 96void root_scratchpad_show(struct sway_container *con) {
97 struct sway_seat *seat = input_manager_current_seat(); 97 struct sway_seat *seat = input_manager_current_seat();
98 struct sway_workspace *new_ws = seat_get_focused_workspace(seat); 98 struct sway_workspace *new_ws = seat_get_focused_workspace(seat);
99 if (!new_ws) {
100 sway_log(SWAY_DEBUG, "No focused workspace to show scratchpad on");
101 return;
102 }
99 struct sway_workspace *old_ws = con->workspace; 103 struct sway_workspace *old_ws = con->workspace;
100 104
101 // If the current con or any of its parents are in fullscreen mode, we 105 // If the current con or any of its parents are in fullscreen mode, we
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 73322491..5e28197b 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -368,13 +368,13 @@ struct sway_workspace *workspace_by_name(const char *name) {
368 struct sway_seat *seat = input_manager_current_seat(); 368 struct sway_seat *seat = input_manager_current_seat();
369 struct sway_workspace *current = seat_get_focused_workspace(seat); 369 struct sway_workspace *current = seat_get_focused_workspace(seat);
370 370
371 if (strcmp(name, "prev") == 0) { 371 if (current && strcmp(name, "prev") == 0) {
372 return workspace_prev(current); 372 return workspace_prev(current);
373 } else if (strcmp(name, "prev_on_output") == 0) { 373 } else if (current && strcmp(name, "prev_on_output") == 0) {
374 return workspace_output_prev(current, false); 374 return workspace_output_prev(current, false);
375 } else if (strcmp(name, "next") == 0) { 375 } else if (current && strcmp(name, "next") == 0) {
376 return workspace_next(current); 376 return workspace_next(current);
377 } else if (strcmp(name, "next_on_output") == 0) { 377 } else if (current && strcmp(name, "next_on_output") == 0) {
378 return workspace_output_next(current, false); 378 return workspace_output_next(current, false);
379 } else if (strcmp(name, "current") == 0) { 379 } else if (strcmp(name, "current") == 0) {
380 return current; 380 return current;
@@ -399,6 +399,11 @@ static struct sway_workspace *workspace_output_prev_next_impl(
399 struct sway_output *output, int dir, bool create) { 399 struct sway_output *output, int dir, bool create) {
400 struct sway_seat *seat = input_manager_current_seat(); 400 struct sway_seat *seat = input_manager_current_seat();
401 struct sway_workspace *workspace = seat_get_focused_workspace(seat); 401 struct sway_workspace *workspace = seat_get_focused_workspace(seat);
402 if (!workspace) {
403 sway_log(SWAY_DEBUG,
404 "No focused workspace to base prev/next on output off of");
405 return NULL;
406 }
402 407
403 int index = list_find(output->workspaces, workspace); 408 int index = list_find(output->workspaces, workspace);
404 if (!workspace_is_empty(workspace) && create && 409 if (!workspace_is_empty(workspace) && create &&