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/input | |
parent | bea9f9c63fe3bd82343a2552f055162422d87d4d (diff) | |
download | sway-908095ef9a479cafaf7d815824f243b4576ff1bb.tar.xz |
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/input')
-rw-r--r-- | sway/input/cursor.c | 8 | ||||
-rw-r--r-- | sway/input/seat.c | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 19dc3165..be3fc9c7 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -675,7 +675,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, // Handle tiling resize via border if (resize_edge && button == BTN_LEFT && state == WLR_BUTTON_PRESSED && !is_floating) { - seat_set_focus(seat, &cont->node); + seat_set_focus_container(seat, cont); seat_begin_resize_tiling(seat, cont, button, edge); return; } @@ -704,7 +704,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, image = "sw-resize"; } cursor_set_image(seat->cursor, image, NULL); - seat_set_focus(seat, &cont->node); + seat_set_focus_container(seat, cont); seat_begin_resize_tiling(seat, cont, button, edge); return; } @@ -753,7 +753,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, // Handle mousedown on a container surface if (surface && cont && state == WLR_BUTTON_PRESSED) { - seat_set_focus(seat, &cont->node); + seat_set_focus_container(seat, cont); seat_pointer_notify_button(seat, time_msec, button, state); seat_begin_down(seat, cont, button, sx, sy); return; @@ -761,7 +761,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, // Handle clicking a container surface if (cont) { - seat_set_focus(seat, &cont->node); + seat_set_focus_container(seat, cont); seat_pointer_notify_button(seat, time_msec, button, state); return; } diff --git a/sway/input/seat.c b/sway/input/seat.c index b1808793..7c81e9d1 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -734,6 +734,16 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { seat_set_focus_warp(seat, node, true, true); } +void seat_set_focus_container(struct sway_seat *seat, + struct sway_container *con) { + seat_set_focus_warp(seat, con ? &con->node : NULL, true, true); +} + +void seat_set_focus_workspace(struct sway_seat *seat, + struct sway_workspace *ws) { + seat_set_focus_warp(seat, ws ? &ws->node : NULL, true, true); +} + void seat_set_focus_surface(struct sway_seat *seat, struct wlr_surface *surface, bool unfocus) { if (seat->focused_layer != NULL) { |