diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-06 19:26:56 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-06 19:26:56 +1000 |
commit | 908095ef9a479cafaf7d815824f243b4576ff1bb (patch) | |
tree | 812b58eae73d0816610e93c6595facb42b141536 /sway/commands | |
parent | bea9f9c63fe3bd82343a2552f055162422d87d4d (diff) |
Introduce seat_set_focus_container and seat_set_focus_workspace
These are the same as seat_set_focus, but accept a specific type rather
than using nodes. Doing this adds more typesafety and lets us avoid
using &con->node which looks a little ugly.
This fixes a crash that pretty much nobody would ever come across. If
you have a bindsym for "focus" with no arguments and run it from an
empty workspace, sway would crash because it assumes `container` is not
NULL.
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/floating.c | 2 | ||||
-rw-r--r-- | sway/commands/focus.c | 6 | ||||
-rw-r--r-- | sway/commands/fullscreen.c | 2 | ||||
-rw-r--r-- | sway/commands/move.c | 7 | ||||
-rw-r--r-- | sway/commands/swap.c | 10 |
5 files changed, 14 insertions, 13 deletions
diff --git a/sway/commands/floating.c b/sway/commands/floating.c index d8729094..97662a18 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -25,7 +25,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) { // Wrap the workspace's children in a container so we can float it container = workspace_wrap_children(workspace); workspace->layout = L_HORIZ; - seat_set_focus(config->handler_context.seat, &container->node); + seat_set_focus_container(config->handler_context.seat, container); } // If the container is in a floating split container, diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 58721b7e..668a0c7b 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -179,7 +179,7 @@ static struct cmd_results *focus_mode(struct sway_workspace *ws, new_focus = seat_get_focus_inactive_tiling(seat, ws); } if (new_focus) { - seat_set_focus(seat, &new_focus->node); + seat_set_focus_container(seat, new_focus); } else { return cmd_results_new(CMD_FAILURE, "focus", "Failed to find a %s container in workspace", @@ -230,8 +230,8 @@ struct cmd_results *cmd_focus(int argc, char **argv) { "Command 'focus' cannot be used above the workspace level"); } - if (argc == 0) { - seat_set_focus(seat, node); + if (argc == 0 && container) { + seat_set_focus_container(seat, container); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c index 3bbe00c5..22d747b9 100644 --- a/sway/commands/fullscreen.c +++ b/sway/commands/fullscreen.c @@ -23,7 +23,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) { // Wrap the workspace's children in a container so we can fullscreen it container = workspace_wrap_children(workspace); workspace->layout = L_HORIZ; - seat_set_focus(config->handler_context.seat, &container->node); + seat_set_focus_container(config->handler_context.seat, container); } bool enable = !container->is_fullscreen; diff --git a/sway/commands/move.c b/sway/commands/move.c index 59f1cf78..2e9c00f8 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -624,7 +624,7 @@ static void workspace_move_to_output(struct sway_workspace *workspace, char *ws_name = workspace_next_name(old_output->wlr_output->name); struct sway_workspace *ws = workspace_create(old_output, ws_name); free(ws_name); - seat_set_focus(seat, &ws->node); + seat_set_focus_workspace(seat, ws); } workspace_consider_destroy(new_output_old_ws); @@ -734,8 +734,9 @@ static struct cmd_results *cmd_move_in_direction( ipc_event_window(container, "move"); } - seat_set_focus(config->handler_context.seat, &new_ws->node); - seat_set_focus(config->handler_context.seat, &container->node); + // Hack to re-focus container + seat_set_focus_workspace(config->handler_context.seat, new_ws); + seat_set_focus_container(config->handler_context.seat, container); if (old_ws != new_ws) { ipc_event_workspace(old_ws, new_ws, "focus"); diff --git a/sway/commands/swap.c b/sway/commands/swap.c index a0ffbda8..e7f9cbea 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c @@ -52,20 +52,20 @@ static void swap_focus(struct sway_container *con1, if (workspace_is_visible(ws2)) { seat_set_focus_warp(seat, &con2->node, false, true); } - seat_set_focus(seat, ws1 != ws2 ? &con2->node : &con1->node); + seat_set_focus_container(seat, ws1 != ws2 ? con2 : con1); } else if (focus == con2 && (layout1 == L_TABBED || layout1 == L_STACKED)) { if (workspace_is_visible(ws1)) { seat_set_focus_warp(seat, &con1->node, false, true); } - seat_set_focus(seat, ws1 != ws2 ? &con1->node : &con2->node); + seat_set_focus_container(seat, ws1 != ws2 ? con1 : con2); } else if (ws1 != ws2) { - seat_set_focus(seat, focus == con1 ? &con2->node : &con1->node); + seat_set_focus_container(seat, focus == con1 ? con2 : con1); } else { - seat_set_focus(seat, &focus->node); + seat_set_focus_container(seat, focus); } } else { - seat_set_focus(seat, &focus->node); + seat_set_focus_container(seat, focus); } } |