aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/focus.c
diff options
context:
space:
mode:
authorLibravatar Nicolas Avrutin <nicolas@avrutin.net>2022-03-06 19:38:03 -0500
committerLibravatar Ronan Pigott <rpigott@berkeley.edu>2022-03-06 18:24:16 -0700
commit9f98c38d3e02b0187de31a434cc4315a22834593 (patch)
tree906e2f25726491783f78bdf90ed9ac8e18985647 /sway/commands/focus.c
parentsway/input: destroy sway_switch properly (diff)
downloadsway-9f98c38d3e02b0187de31a434cc4315a22834593.tar.gz
sway-9f98c38d3e02b0187de31a434cc4315a22834593.tar.zst
sway-9f98c38d3e02b0187de31a434cc4315a22834593.zip
commands/focus: fix segfault when no container is already focused.
Fixes #6690.
Diffstat (limited to 'sway/commands/focus.c')
-rw-r--r--sway/commands/focus.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 2e8584c9..facd82de 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -285,7 +285,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws,
285 } 285 }
286 } else { 286 } else {
287 return cmd_results_new(CMD_FAILURE, 287 return cmd_results_new(CMD_FAILURE,
288 "Failed to find a %s container in workspace", 288 "Failed to find a %s container in workspace.",
289 floating ? "floating" : "tiling"); 289 floating ? "floating" : "tiling");
290 } 290 }
291 return cmd_results_new(CMD_SUCCESS, NULL); 291 return cmd_results_new(CMD_SUCCESS, NULL);
@@ -295,7 +295,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
295 int argc, char **argv) { 295 int argc, char **argv) {
296 if (!argc) { 296 if (!argc) {
297 return cmd_results_new(CMD_INVALID, 297 return cmd_results_new(CMD_INVALID,
298 "Expected 'focus output <direction|name>'"); 298 "Expected 'focus output <direction|name>'.");
299 } 299 }
300 char *identifier = join_args(argv, argc); 300 char *identifier = join_args(argv, argc);
301 struct sway_output *output = output_by_name_or_id(identifier); 301 struct sway_output *output = output_by_name_or_id(identifier);
@@ -305,13 +305,13 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
305 if (!parse_direction(identifier, &direction)) { 305 if (!parse_direction(identifier, &direction)) {
306 free(identifier); 306 free(identifier);
307 return cmd_results_new(CMD_INVALID, 307 return cmd_results_new(CMD_INVALID,
308 "There is no output with that name"); 308 "There is no output with that name.");
309 } 309 }
310 struct sway_workspace *ws = seat_get_focused_workspace(seat); 310 struct sway_workspace *ws = seat_get_focused_workspace(seat);
311 if (!ws) { 311 if (!ws) {
312 free(identifier); 312 free(identifier);
313 return cmd_results_new(CMD_FAILURE, 313 return cmd_results_new(CMD_FAILURE,
314 "No focused workspace to base directions off of"); 314 "No focused workspace to base directions off of.");
315 } 315 }
316 output = output_get_in_direction(ws->output, direction); 316 output = output_get_in_direction(ws->output, direction);
317 317
@@ -375,10 +375,14 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
375 struct sway_seat *seat = config->handler_context.seat; 375 struct sway_seat *seat = config->handler_context.seat;
376 if (node->type < N_WORKSPACE) { 376 if (node->type < N_WORKSPACE) {
377 return cmd_results_new(CMD_FAILURE, 377 return cmd_results_new(CMD_FAILURE,
378 "Command 'focus' cannot be used above the workspace level"); 378 "Command 'focus' cannot be used above the workspace level.");
379 } 379 }
380 380
381 if (argc == 0 && container) { 381 if (argc == 0) {
382 if (!container) {
383 return cmd_results_new(CMD_FAILURE, "No container to focus was specified.");
384 }
385
382 if (container_is_scratchpad_hidden_or_child(container)) { 386 if (container_is_scratchpad_hidden_or_child(container)) {
383 root_scratchpad_show(container); 387 root_scratchpad_show(container);
384 } 388 }