From a94f4d0edcdb54ac59b399df36273555f29ffc7d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 15:48:22 -0400 Subject: Always give keyboard focus to the topmost layer --- include/rootston/seat.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 0b1dbe2d..0d8e1749 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -4,6 +4,7 @@ #include #include "rootston/input.h" #include "rootston/keyboard.h" +#include "rootston/layers.h" struct roots_seat { struct roots_input *input; @@ -15,6 +16,9 @@ struct roots_seat { int32_t touch_id; double touch_x, touch_y; + // If the focused layer is set, views cannot receive keyboard focus + struct roots_layer_surface *focused_layer; + struct wl_list views; // roots_seat_view::link bool has_focus; @@ -100,6 +104,9 @@ struct roots_view *roots_seat_get_focus(struct roots_seat *seat); void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view); +void roots_seat_set_focus_layer(struct roots_seat *seat, + struct roots_layer_surface *layer); + void roots_seat_cycle_focus(struct roots_seat *seat); void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view); -- cgit v1.2.3 From 37036df822fb339d790be24abbaa09253f889d25 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 17:00:09 -0400 Subject: Handle layer surfaces below shell surfaces --- include/rootston/seat.h | 4 ++-- rootston/cursor.c | 6 ++++++ rootston/layer_shell.c | 3 ++- rootston/seat.c | 20 +++++++++++++------- 4 files changed, 23 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 0d8e1749..6f482723 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -17,7 +17,7 @@ struct roots_seat { double touch_x, touch_y; // If the focused layer is set, views cannot receive keyboard focus - struct roots_layer_surface *focused_layer; + struct wlr_layer_surface *focused_layer; struct wl_list views; // roots_seat_view::link bool has_focus; @@ -105,7 +105,7 @@ struct roots_view *roots_seat_get_focus(struct roots_seat *seat); void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view); void roots_seat_set_focus_layer(struct roots_seat *seat, - struct roots_layer_surface *layer); + struct wlr_layer_surface *layer); void roots_seat_cycle_focus(struct roots_seat *seat); diff --git a/rootston/cursor.c b/rootston/cursor.c index 1ee195c2..6252b6e1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -271,6 +271,12 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, break; case WLR_BUTTON_PRESSED: roots_seat_set_focus(seat, view); + if (surface && !view) { + struct wlr_layer_surface *layer = surface->role_data; + if (layer->current.keyboard_interactive) { + roots_seat_set_focus_layer(seat, layer); + } + } break; } } diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index cac325b8..749da40d 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -218,7 +218,8 @@ void arrange_layers(struct roots_output *output) { struct roots_input *input = output->desktop->server->input; struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { - roots_seat_set_focus_layer(seat, topmost); + roots_seat_set_focus_layer(seat, + topmost ? topmost->layer_surface : NULL); } } diff --git a/rootston/seat.c b/rootston/seat.c index 41768fdd..cfdeab00 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -804,26 +804,33 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { } } +/** + * Focus semantics of layer surfaces are somewhat detached from the normal focus + * flow. For layers above the shell layer, for example, you cannot unfocus them. + * You also cannot alt-tab between layer surfaces and shell surfaces. + */ void roots_seat_set_focus_layer(struct roots_seat *seat, - struct roots_layer_surface *layer) { + struct wlr_layer_surface *layer) { struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); - seat->focused_layer = layer; if (!layer) { - wlr_seat_keyboard_clear_focus(seat->seat); + seat->focused_layer = NULL; return; } if (seat->has_focus) { struct roots_view *prev_focus = roots_seat_get_focus(seat); + wlr_seat_keyboard_clear_focus(seat->seat); view_activate(prev_focus, false); } seat->has_focus = false; - struct wlr_layer_surface *layer_surface = layer->layer_surface; + if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) { + seat->focused_layer = layer; + } if (keyboard != NULL) { - wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, + wlr_seat_keyboard_notify_enter(seat->seat, layer->surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); } else { - wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, + wlr_seat_keyboard_notify_enter(seat->seat, layer->surface, NULL, 0, NULL); } } @@ -854,7 +861,6 @@ void roots_seat_cycle_focus(struct roots_seat *seat) { } void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { - wlr_log(L_DEBUG, "begin move"); struct roots_cursor *cursor = seat->cursor; cursor->mode = ROOTS_CURSOR_MOVE; cursor->offs_x = cursor->cursor->x; -- cgit v1.2.3 From 333ab599022a645f92facf41cde03ab03866b08f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 20:39:33 -0400 Subject: Add wlr_surface_is_*_surface And wlr_*_surface_from_wlr_surface --- include/wlr/types/wlr_layer_shell.h | 5 +++++ include/wlr/types/wlr_wl_shell.h | 5 +++++ include/wlr/types/wlr_xdg_shell.h | 5 +++++ include/wlr/types/wlr_xdg_shell_v6.h | 5 +++++ rootston/cursor.c | 5 +++-- types/wlr_layer_shell.c | 10 ++++++++++ types/wlr_wl_shell.c | 10 ++++++++++ types/wlr_xdg_shell.c | 11 +++++++++++ types/wlr_xdg_shell_v6.c | 11 +++++++++++ 9 files changed, 65 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 8d093ada..1312e568 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -99,4 +99,9 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface, */ void wlr_layer_surface_close(struct wlr_layer_surface *surface); +bool wlr_surface_is_layer_surface(struct wlr_surface *surface); + +struct wlr_layer_surface *wlr_layer_surface_from_wlr_surface( + struct wlr_surface *surface); + #endif diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 00f2bb69..63b1a837 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -150,4 +150,9 @@ struct wlr_wl_shell_surface *wlr_wl_shell_surface_popup_at( struct wlr_wl_shell_surface *surface, double sx, double sy, double *popup_sx, double *popup_sy); +bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface); + +struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface( + struct wlr_surface *surface); + #endif diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 9938f4b1..b779017f 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -229,4 +229,9 @@ struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_xdg_surface *surface, double sx, double sy, double *popup_sx, double *popup_sy); +bool wlr_surface_is_xdg_surface(struct wlr_surface *surface); + +struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface( + struct wlr_surface *surface); + #endif diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index d01240eb..04c1f324 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -289,4 +289,9 @@ void wlr_positioner_v6_invert_x( void wlr_positioner_v6_invert_y( struct wlr_xdg_positioner_v6 *positioner); +bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface); + +struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( + struct wlr_surface *surface); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 6252b6e1..6fb2688c 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -271,8 +271,9 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, break; case WLR_BUTTON_PRESSED: roots_seat_set_focus(seat, view); - if (surface && !view) { - struct wlr_layer_surface *layer = surface->role_data; + if (wlr_surface_is_layer_surface(surface)) { + struct wlr_layer_surface *layer = + wlr_layer_surface_from_wlr_surface(surface); if (layer->current.keyboard_interactive) { roots_seat_set_focus_layer(seat, layer); } diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index b81fb4c6..c4e39a17 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -34,6 +34,16 @@ static struct wlr_layer_surface *layer_surface_from_resource( return wl_resource_get_user_data(resource); } +bool wlr_surface_is_layer_surface(struct wlr_surface *surface) { + return strcmp(surface->role, zwlr_layer_surface_role) == 0; +} + +struct wlr_layer_surface *wlr_layer_surface_from_wlr_surface( + struct wlr_surface *surface) { + assert(wlr_surface_is_layer_surface(surface)); + return (struct wlr_layer_surface *)surface->role_data; +} + static void layer_surface_configure_destroy( struct wlr_layer_surface_configure *configure) { if (configure == NULL) { diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index cac64c44..a2123bce 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -12,6 +12,16 @@ static const char *wlr_wl_shell_surface_role = "wl-shell-surface"; +bool wlr_surface_is_wl_shell_surface(struct wlr_surface *surface) { + return strcmp(surface->role, wlr_wl_shell_surface_role) == 0; +} + +struct wlr_wl_surface *wlr_wl_shell_surface_from_wlr_surface( + struct wlr_surface *surface) { + assert(wlr_surface_is_wl_shell_surface(surface)); + return (struct wlr_wl_surface *)surface->role_data; +} + static void shell_pointer_grab_end(struct wlr_seat_pointer_grab *grab) { struct wlr_wl_shell_popup_grab *popup_grab = grab->data; diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index d3be2c4f..d70021fd 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -16,6 +16,17 @@ static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; static const char *wlr_desktop_xdg_popup_role = "xdg_popup"; +bool wlr_surface_is_xdg_surface(struct wlr_surface *surface) { + return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || + strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0; +} + +struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface( + struct wlr_surface *surface) { + assert(wlr_surface_is_xdg_surface(surface)); + return (struct wlr_xdg_surface *)surface->role_data; +} + struct wlr_xdg_positioner { struct wl_resource *resource; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 64d44f22..5c83db70 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -16,6 +16,17 @@ static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel_v6"; static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6"; +bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface) { + return strcmp(surface->role, wlr_desktop_xdg_toplevel_role) == 0 || + strcmp(surface->role, wlr_desktop_xdg_popup_role) == 0; +} + +struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface( + struct wlr_surface *surface) { + assert(wlr_surface_is_xdg_surface_v6(surface)); + return (struct wlr_xdg_surface_v6 *)surface->role_data; +} + struct wlr_xdg_positioner_v6_resource { struct wl_resource *resource; struct wlr_xdg_positioner_v6 attrs; -- cgit v1.2.3