From 9f98c38d3e02b0187de31a434cc4315a22834593 Mon Sep 17 00:00:00 2001 From: Nicolas Avrutin Date: Sun, 6 Mar 2022 19:38:03 -0500 Subject: commands/focus: fix segfault when no container is already focused. Fixes #6690. --- sway/commands/focus.c | 16 ++++++++++------ 1 file 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, } } else { return cmd_results_new(CMD_FAILURE, - "Failed to find a %s container in workspace", + "Failed to find a %s container in workspace.", floating ? "floating" : "tiling"); } return cmd_results_new(CMD_SUCCESS, NULL); @@ -295,7 +295,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat, int argc, char **argv) { if (!argc) { return cmd_results_new(CMD_INVALID, - "Expected 'focus output '"); + "Expected 'focus output '."); } char *identifier = join_args(argv, argc); struct sway_output *output = output_by_name_or_id(identifier); @@ -305,13 +305,13 @@ static struct cmd_results *focus_output(struct sway_seat *seat, if (!parse_direction(identifier, &direction)) { free(identifier); return cmd_results_new(CMD_INVALID, - "There is no output with that name"); + "There is no output with that name."); } struct sway_workspace *ws = seat_get_focused_workspace(seat); if (!ws) { free(identifier); return cmd_results_new(CMD_FAILURE, - "No focused workspace to base directions off of"); + "No focused workspace to base directions off of."); } output = output_get_in_direction(ws->output, direction); @@ -375,10 +375,14 @@ struct cmd_results *cmd_focus(int argc, char **argv) { struct sway_seat *seat = config->handler_context.seat; if (node->type < N_WORKSPACE) { return cmd_results_new(CMD_FAILURE, - "Command 'focus' cannot be used above the workspace level"); + "Command 'focus' cannot be used above the workspace level."); } - if (argc == 0 && container) { + if (argc == 0) { + if (!container) { + return cmd_results_new(CMD_FAILURE, "No container to focus was specified."); + } + if (container_is_scratchpad_hidden_or_child(container)) { root_scratchpad_show(container); } -- cgit v1.2.3