diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-02 21:36:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 21:36:01 -0400 |
commit | 447dcd3cb3cb482684068fa2c8278920447631a5 (patch) | |
tree | c6436df2cf49f6ca2a648d39392105590d5ee92e | |
parent | Merge pull request #1668 from acrisci/split-containers (diff) | |
parent | Give layer shells under the shell layer focus (diff) | |
download | sway-447dcd3cb3cb482684068fa2c8278920447631a5.tar.gz sway-447dcd3cb3cb482684068fa2c8278920447631a5.tar.zst sway-447dcd3cb3cb482684068fa2c8278920447631a5.zip |
Merge pull request #1703 from swaywm/layer-keyboard
Give keyboard input to layer surfaces that ask for it
-rw-r--r-- | include/sway/input/seat.h | 7 | ||||
-rw-r--r-- | sway/desktop/layer_shell.c | 27 | ||||
-rw-r--r-- | sway/input/cursor.c | 11 | ||||
-rw-r--r-- | sway/input/seat.c | 36 |
4 files changed, 77 insertions, 4 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index c780a52b..137fcd22 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _SWAY_INPUT_SEAT_H | 1 | #ifndef _SWAY_INPUT_SEAT_H |
2 | #define _SWAY_INPUT_SEAT_H | 2 | #define _SWAY_INPUT_SEAT_H |
3 | 3 | ||
4 | #include <wlr/types/wlr_layer_shell.h> | ||
4 | #include <wlr/types/wlr_seat.h> | 5 | #include <wlr/types/wlr_seat.h> |
5 | #include "sway/input/input-manager.h" | 6 | #include "sway/input/input-manager.h" |
6 | 7 | ||
@@ -28,6 +29,9 @@ struct sway_seat { | |||
28 | bool has_focus; | 29 | bool has_focus; |
29 | struct wl_list focus_stack; // list of containers in focus order | 30 | struct wl_list focus_stack; // list of containers in focus order |
30 | 31 | ||
32 | // If the focused layer is set, views cannot receive keyboard focus | ||
33 | struct wlr_layer_surface *focused_layer; | ||
34 | |||
31 | struct wl_listener focus_destroy; | 35 | struct wl_listener focus_destroy; |
32 | struct wl_listener new_container; | 36 | struct wl_listener new_container; |
33 | 37 | ||
@@ -57,6 +61,9 @@ void seat_set_focus(struct sway_seat *seat, struct sway_container *container); | |||
57 | void seat_set_focus_warp(struct sway_seat *seat, | 61 | void seat_set_focus_warp(struct sway_seat *seat, |
58 | struct sway_container *container, bool warp); | 62 | struct sway_container *container, bool warp); |
59 | 63 | ||
64 | void seat_set_focus_layer(struct sway_seat *seat, | ||
65 | struct wlr_layer_surface *layer); | ||
66 | |||
60 | struct sway_container *seat_get_focus(struct sway_seat *seat); | 67 | struct sway_container *seat_get_focus(struct sway_seat *seat); |
61 | 68 | ||
62 | /** | 69 | /** |
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index c18f51c7..3c7b45f7 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c | |||
@@ -7,6 +7,8 @@ | |||
7 | #include <wlr/types/wlr_output_damage.h> | 7 | #include <wlr/types/wlr_output_damage.h> |
8 | #include <wlr/types/wlr_output.h> | 8 | #include <wlr/types/wlr_output.h> |
9 | #include <wlr/util/log.h> | 9 | #include <wlr/util/log.h> |
10 | #include "sway/input/input-manager.h" | ||
11 | #include "sway/input/seat.h" | ||
10 | #include "sway/layers.h" | 12 | #include "sway/layers.h" |
11 | #include "sway/output.h" | 13 | #include "sway/output.h" |
12 | #include "sway/server.h" | 14 | #include "sway/server.h" |
@@ -187,6 +189,31 @@ void arrange_layers(struct sway_output *output) { | |||
187 | &usable_area, false); | 189 | &usable_area, false); |
188 | arrange_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], | 190 | arrange_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], |
189 | &usable_area, false); | 191 | &usable_area, false); |
192 | |||
193 | // Find topmost keyboard interactive layer, if such a layer exists | ||
194 | uint32_t layers_above_shell[] = { | ||
195 | ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, | ||
196 | ZWLR_LAYER_SHELL_V1_LAYER_TOP, | ||
197 | }; | ||
198 | size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]); | ||
199 | struct sway_layer_surface *layer, *topmost = NULL; | ||
200 | for (size_t i = 0; i < nlayers; ++i) { | ||
201 | wl_list_for_each_reverse(layer, | ||
202 | &output->layers[layers_above_shell[i]], link) { | ||
203 | if (layer->layer_surface->current.keyboard_interactive) { | ||
204 | topmost = layer; | ||
205 | break; | ||
206 | } | ||
207 | } | ||
208 | if (topmost != NULL) { | ||
209 | break; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | struct sway_seat *seat; | ||
214 | wl_list_for_each(seat, &input_manager->seats, link) { | ||
215 | seat_set_focus_layer(seat, topmost ? topmost->layer_surface : NULL); | ||
216 | } | ||
190 | } | 217 | } |
191 | 218 | ||
192 | static void handle_output_destroy(struct wl_listener *listener, void *data) { | 219 | static void handle_output_destroy(struct wl_listener *listener, void *data) { |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 97b4473c..9229e92d 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -180,13 +180,18 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
180 | double sx, sy; | 180 | double sx, sy; |
181 | struct sway_container *cont = | 181 | struct sway_container *cont = |
182 | container_at_cursor(cursor, &surface, &sx, &sy); | 182 | container_at_cursor(cursor, &surface, &sx, &sy); |
183 | if (surface && wlr_surface_is_layer_surface(surface)) { | ||
184 | struct wlr_layer_surface *layer = | ||
185 | wlr_layer_surface_from_wlr_surface(surface); | ||
186 | if (layer->current.keyboard_interactive) { | ||
187 | seat_set_focus_layer(cursor->seat, layer); | ||
188 | return; | ||
189 | } | ||
190 | } | ||
183 | // Avoid moving keyboard focus from a surface that accepts it to one | 191 | // Avoid moving keyboard focus from a surface that accepts it to one |
184 | // that does not unless the change would move us to a new workspace. | 192 | // that does not unless the change would move us to a new workspace. |
185 | // | 193 | // |
186 | // This prevents, for example, losing focus when clicking on swaybar. | 194 | // This prevents, for example, losing focus when clicking on swaybar. |
187 | // | ||
188 | // TODO: Replace this condition with something like | ||
189 | // !surface_accepts_keyboard_input | ||
190 | if (surface && cont && cont->type != C_VIEW) { | 195 | if (surface && cont && cont->type != C_VIEW) { |
191 | struct sway_container *new_ws = cont; | 196 | struct sway_container *new_ws = cont; |
192 | if (new_ws && new_ws->type != C_WORKSPACE) { | 197 | if (new_ws && new_ws->type != C_WORKSPACE) { |
diff --git a/sway/input/seat.c b/sway/input/seat.c index c41f7b2e..cf519a82 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -352,8 +352,11 @@ void seat_configure_xcursor(struct sway_seat *seat) { | |||
352 | 352 | ||
353 | void seat_set_focus_warp(struct sway_seat *seat, | 353 | void seat_set_focus_warp(struct sway_seat *seat, |
354 | struct sway_container *container, bool warp) { | 354 | struct sway_container *container, bool warp) { |
355 | struct sway_container *last_focus = seat_get_focus(seat); | 355 | if (seat->focused_layer) { |
356 | return; | ||
357 | } | ||
356 | 358 | ||
359 | struct sway_container *last_focus = seat_get_focus(seat); | ||
357 | if (container && last_focus == container) { | 360 | if (container && last_focus == container) { |
358 | return; | 361 | return; |
359 | } | 362 | } |
@@ -419,6 +422,37 @@ void seat_set_focus(struct sway_seat *seat, | |||
419 | seat_set_focus_warp(seat, container, true); | 422 | seat_set_focus_warp(seat, container, true); |
420 | } | 423 | } |
421 | 424 | ||
425 | void seat_set_focus_layer(struct sway_seat *seat, | ||
426 | struct wlr_layer_surface *layer) { | ||
427 | if (!layer) { | ||
428 | seat->focused_layer = NULL; | ||
429 | return; | ||
430 | } | ||
431 | if (seat->focused_layer == layer) { | ||
432 | return; | ||
433 | } | ||
434 | if (seat->has_focus) { | ||
435 | struct sway_container *focus = seat_get_focus(seat); | ||
436 | if (focus->type == C_VIEW) { | ||
437 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); | ||
438 | view_set_activated(focus->sway_view, false); | ||
439 | } | ||
440 | } | ||
441 | if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) { | ||
442 | seat->focused_layer = layer; | ||
443 | } | ||
444 | struct wlr_keyboard *keyboard = | ||
445 | wlr_seat_get_keyboard(seat->wlr_seat); | ||
446 | if (keyboard) { | ||
447 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, | ||
448 | layer->surface, keyboard->keycodes, | ||
449 | keyboard->num_keycodes, &keyboard->modifiers); | ||
450 | } else { | ||
451 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, | ||
452 | layer->surface, NULL, 0, NULL); | ||
453 | } | ||
454 | } | ||
455 | |||
422 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, | 456 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, |
423 | struct sway_container *container) { | 457 | struct sway_container *container) { |
424 | return seat_get_focus_by_type(seat, container, C_TYPES); | 458 | return seat_get_focus_by_type(seat, container, C_TYPES); |