From 883d8d306c704a4bcc496402b2ce5f67934440c5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 15:16:14 -0400 Subject: [PATCH 1/7] Identify topmost interactive layer surface --- examples/layer-shell.c | 11 ++++++++--- rootston/layer_shell.c | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index f084d10f..591213d0 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -36,6 +36,7 @@ static int32_t margin_top = 0; static double alpha = 1.0; static bool run_display = true; static bool animate = false; +static bool keyboard_interactive = false; static double frame = 0; static int cur_x = -1, cur_y = -1; static int buttons = 0; @@ -274,7 +275,7 @@ int main(int argc, char **argv) { int32_t margin_right = 0, margin_bottom = 0, margin_left = 0; bool found; int c; - while ((c = getopt(argc, argv, "nw:h:o:l:a:x:m:t:")) != -1) { + while ((c = getopt(argc, argv, "knw:h:o:l:a:x:m:t:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -354,6 +355,9 @@ int main(int argc, char **argv) { case 'n': animate = true; break; + case 'k': + keyboard_interactive = true; + break; default: break; } @@ -407,9 +411,10 @@ int main(int argc, char **argv) { zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, exclusive_zone); zwlr_layer_surface_v1_set_margin(layer_surface, margin_top, margin_right, margin_bottom, margin_left); + zwlr_layer_surface_v1_set_keyboard_interactivity( + layer_surface, keyboard_interactive); zwlr_layer_surface_v1_add_listener(layer_surface, - &layer_surface_listener, layer_surface); - // TODO: interactivity + &layer_surface_listener, layer_surface); wl_surface_commit(wl_surface); wl_display_roundtrip(display); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index d3a91659..0304cff4 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -192,6 +192,29 @@ void arrange_layers(struct roots_output *output) { arrange_layer(output->wlr_output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &usable_area, false); + + // Find topmost keyboard interactive layer, if such a layer exists + uint32_t layers_above_shell[] = { + ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, + ZWLR_LAYER_SHELL_V1_LAYER_TOP, + }; + struct roots_layer_surface *layer, *topmost = NULL; + for (size_t i = 0; + i < sizeof(layers_above_shell) / sizeof(layers_above_shell[0]); + ++i) { + wl_list_for_each_reverse(layer, + &output->layers[layers_above_shell[i]], + link) { + if (layer->layer_surface->current.keyboard_interactive) { + topmost = layer; + break; + } + } + if (topmost != NULL) { + break; + } + } + wlr_log(L_DEBUG, "topmost interactive layer: %p", topmost); } static void handle_output_destroy(struct wl_listener *listener, void *data) { From a94f4d0edcdb54ac59b399df36273555f29ffc7d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 15:48:22 -0400 Subject: [PATCH 2/7] Always give keyboard focus to the topmost layer --- examples/layer-shell.c | 45 +++++++++++++++++++++++++++++++++++++++-- include/rootston/seat.h | 7 +++++++ rootston/layer_shell.c | 7 ++++++- rootston/seat.c | 37 +++++++++++++++++++++++++++++---- 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 591213d0..0aac0839 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -17,7 +17,7 @@ static struct wl_compositor *compositor = NULL; static struct wl_seat *seat = NULL; static struct wl_shm *shm = NULL; static struct wl_pointer *pointer = NULL; -//static struct wl_keyboard *keyboard = NULL; +static struct wl_keyboard *keyboard = NULL; static struct zwlr_layer_shell_v1 *layer_shell = NULL; struct zwlr_layer_surface_v1 *layer_surface; static struct wl_output *wl_output = NULL; @@ -212,6 +212,46 @@ struct wl_pointer_listener pointer_listener = { .axis_discrete = wl_pointer_axis_discrete, }; +static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, + uint32_t format, int32_t fd, uint32_t size) { + // Who cares +} + +static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { + wlr_log(L_DEBUG, "Keyboard enter"); +} + +static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, struct wl_surface *surface) { + wlr_log(L_DEBUG, "Keyboard leave"); +} + +static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { + wlr_log(L_DEBUG, "Key event: %d %d", key, state); +} + +static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, + uint32_t mods_locked, uint32_t group) { + // Who cares +} + +static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, + int32_t rate, int32_t delay) { + // Who cares +} + +static struct wl_keyboard_listener keyboard_listener = { + .keymap = wl_keyboard_keymap, + .enter = wl_keyboard_enter, + .leave = wl_keyboard_leave, + .key = wl_keyboard_key, + .modifiers = wl_keyboard_modifiers, + .repeat_info = wl_keyboard_repeat_info, +}; + static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capability caps) { if ((caps & WL_SEAT_CAPABILITY_POINTER)) { @@ -219,7 +259,8 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, wl_pointer_add_listener(pointer, &pointer_listener, NULL); } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { - // TODO + keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL); } } 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); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 0304cff4..cac325b8 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -214,7 +214,12 @@ void arrange_layers(struct roots_output *output) { break; } } - wlr_log(L_DEBUG, "topmost interactive layer: %p", topmost); + + 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); + } } static void handle_output_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/seat.c b/rootston/seat.c index bdcad5c7..41768fdd 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "rootston/cursor.h" @@ -723,7 +724,6 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { wl_list_insert(&seat->input->server->desktop->views, &view->link); } - bool unfullscreen = true; #ifdef WLR_HAS_XWAYLAND @@ -781,14 +781,18 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { return; } - view_activate(view, true); - - seat->has_focus = true; wl_list_remove(&seat_view->link); wl_list_insert(&seat->views, &seat_view->link); view_damage_whole(view); + if (seat->focused_layer) { + return; + } + + view_activate(view, true); + seat->has_focus = true; + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); if (keyboard != NULL) { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, @@ -800,6 +804,30 @@ 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_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); + seat->focused_layer = layer; + if (!layer) { + wlr_seat_keyboard_clear_focus(seat->seat); + return; + } + if (seat->has_focus) { + struct roots_view *prev_focus = roots_seat_get_focus(seat); + view_activate(prev_focus, false); + } + seat->has_focus = false; + struct wlr_layer_surface *layer_surface = layer->layer_surface; + if (keyboard != NULL) { + wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, + keyboard->keycodes, keyboard->num_keycodes, + &keyboard->modifiers); + } else { + wlr_seat_keyboard_notify_enter(seat->seat, layer_surface->surface, + NULL, 0, NULL); + } +} + void roots_seat_cycle_focus(struct roots_seat *seat) { if (wl_list_empty(&seat->views)) { return; @@ -826,6 +854,7 @@ 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; From 046d909e7a15710549cf9db117013b99d5a51ac1 Mon Sep 17 00:00:00 2001 From: Danilo Spinella Date: Mon, 2 Apr 2018 23:35:03 +0200 Subject: [PATCH 3/7] Change meson option names to use hypen Replace underscore with hypen in meson option names, following style recommendations. http://mesonbuild.com/Style-guide.html#naming-options --- meson.build | 22 +++++++++++----------- meson_options.txt | 12 ++++++------ rootston/meson.build | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index 04c93817..0d8fbe58 100644 --- a/meson.build +++ b/meson.build @@ -58,30 +58,30 @@ libinput = dependency('libinput', version: '>=1.7.0') xkbcommon = dependency('xkbcommon') udev = dependency('libudev') pixman = dependency('pixman-1') -libcap = dependency('libcap', required: get_option('enable_libcap') == 'true') -systemd = dependency('libsystemd', required: get_option('enable_systemd') == 'true') -elogind = dependency('libelogind', required: get_option('enable_elogind') == 'true') +libcap = dependency('libcap', required: get_option('enable-libcap') == 'true') +systemd = dependency('libsystemd', required: get_option('enable-systemd') == 'true') +elogind = dependency('libelogind', required: get_option('enable-elogind') == 'true') math = cc.find_library('m', required: false) exclude_headers = [] wlr_parts = [] wlr_deps = [] -if libcap.found() and get_option('enable_libcap') != 'false' +if libcap.found() and get_option('enable-libcap') != 'false' conf_data.set('WLR_HAS_LIBCAP', true) wlr_deps += libcap endif -if systemd.found() and get_option('enable_systemd') != 'false' +if systemd.found() and get_option('enable-systemd') != 'false' conf_data.set('WLR_HAS_SYSTEMD', true) wlr_deps += systemd endif -if elogind.found() and get_option('enable_elogind') != 'false' +if elogind.found() and get_option('enable-elogind') != 'false' conf_data.set('WLR_HAS_ELOGIND', true) endif -if get_option('enable_x11_backend') or get_option('enable_xwayland') +if get_option('enable-x11_backend') or get_option('enable-xwayland') xcb = dependency('xcb') xcb_composite = dependency('xcb-composite') xcb_xfixes = dependency('xcb-xfixes') @@ -91,7 +91,7 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland') xcb_icccm = dependency('xcb-icccm', required: false) xcb_xkb = dependency('xcb-xkb', required: false) - xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true') + xcb_errors = dependency('xcb-errors', required: get_option('enable-xcb_errors') == 'true') if xcb_icccm.found() conf_data.set('WLR_HAS_XCB_ICCCM', true) @@ -101,7 +101,7 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland') conf_data.set('WLR_HAS_XCB_XKB', true) endif - if xcb_errors.found() and get_option('enable_xcb_errors') != 'false' + if xcb_errors.found() and get_option('enable-xcb_errors') != 'false' conf_data.set('WLR_HAS_XCB_ERRORS', true) endif @@ -114,11 +114,11 @@ else add_project_arguments('-DMESA_EGL_NO_X11_HEADERS', language: 'c') endif -if get_option('enable_x11_backend') +if get_option('enable-x11_backend') conf_data.set('WLR_HAS_X11_BACKEND', true) endif -if get_option('enable_xwayland') +if get_option('enable-xwayland') subdir('xwayland') wlr_parts += [lib_wlr_xwayland] conf_data.set('WLR_HAS_XWAYLAND', true) diff --git a/meson_options.txt b/meson_options.txt index 9e8567d0..de29e401 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,6 +1,6 @@ -option('enable_libcap', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for capabilities') -option('enable_systemd', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind') -option('enable_elogind', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind') -option('enable_xcb_errors', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Use xcb-errors util library') -option('enable_xwayland', type: 'boolean', value: true, description: 'Enable support X11 applications') -option('enable_x11_backend', type: 'boolean', value: true, description: 'Enable X11 backend') +option('enable-libcap', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for capabilities') +option('enable-systemd', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind') +option('enable-elogind', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Enable support for logind') +option('enable-xcb_errors', type: 'combo', choices: ['auto', 'true', 'false'], value: 'auto', description: 'Use xcb-errors util library') +option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support X11 applications') +option('enable-x11_backend', type: 'boolean', value: true, description: 'Enable X11 backend') diff --git a/rootston/meson.build b/rootston/meson.build index 1b78c7c8..53a4635d 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -13,7 +13,7 @@ sources = [ 'xdg_shell_v6.c', 'xdg_shell.c', ] -if get_option('enable_xwayland') +if get_option('enable-xwayland') sources += ['xwayland.c'] endif executable( From 37036df822fb339d790be24abbaa09253f889d25 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 17:00:09 -0400 Subject: [PATCH 4/7] 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(-) 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; From 9ae861c416e84feda2ffb577b97c43d6222560af Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 18:51:40 -0400 Subject: [PATCH 5/7] Address review feedback --- rootston/layer_shell.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 749da40d..1cd93b3c 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -198,13 +198,11 @@ void arrange_layers(struct roots_output *output) { ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, ZWLR_LAYER_SHELL_V1_LAYER_TOP, }; + size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]); struct roots_layer_surface *layer, *topmost = NULL; - for (size_t i = 0; - i < sizeof(layers_above_shell) / sizeof(layers_above_shell[0]); - ++i) { + for (size_t i = 0; i < nlayers; ++i) { wl_list_for_each_reverse(layer, - &output->layers[layers_above_shell[i]], - link) { + &output->layers[layers_above_shell[i]], link) { if (layer->layer_surface->current.keyboard_interactive) { topmost = layer; break; From 333ab599022a645f92facf41cde03ab03866b08f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 20:39:33 -0400 Subject: [PATCH 6/7] 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(-) 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; From 506acbdecd4436117729e4c40678645725ed2d1f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 20:57:09 -0400 Subject: [PATCH 7/7] Missed a spot --- include/wlr/xwayland.h | 5 +++++ xwayland/xwm.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 9b9d9cf9..66622de3 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -185,4 +185,9 @@ void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland, bool wlr_xwayland_surface_is_unmanaged( const struct wlr_xwayland_surface *surface); +bool wlr_surface_is_xwayland_surface(struct wlr_surface *surface); + +struct wlr_xwayland_surface *wlr_xwayland_surface_from_wlr_surface( + struct wlr_surface *surface); + #endif diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 6702c3c9..4fa7d311 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1,6 +1,7 @@ #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #endif +#include #include #include #include @@ -58,6 +59,18 @@ const char *atom_map[ATOM_LAST] = { "_NET_WM_WINDOW_TYPE_COMBO", }; +const char *wlr_xwayland_surface_role = "wlr_xwayland_surface"; + +bool wlr_surface_is_xwayland_surface(struct wlr_surface *surface) { + return strcmp(surface->role, wlr_xwayland_surface_role) == 0; +} + +struct wlr_xwayland_surface *wlr_xwayland_surface_from_wlr_surface( + struct wlr_surface *surface) { + assert(wlr_surface_is_xwayland_surface(surface)); + return (struct wlr_xwayland_surface *)surface->role_data; +} + /* General helpers */ // TODO: replace this with hash table? static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm, @@ -574,6 +587,7 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm, read_surface_property(xwm, xsurface, props[i]); } + wlr_surface_set_role(xsurface->surface, wlr_xwayland_surface_role, NULL, 0); wlr_surface_set_role_committed(xsurface->surface, handle_surface_commit, xsurface);