1
0
Fork 0
mirror of https://github.com/Cloudef/bemenu synced 2024-06-01 04:16:21 +02:00

wayland renderer: Implement grab_keyboard

This avoids locking oneself out when running bemenu interactively,
as input would be grabbed too early without that and layer shell
does not allow to 'ungrab' focus by clicking on another window
This commit is contained in:
Dominique Martinet 2018-04-28 08:17:58 +09:00
parent 610b30364e
commit 992e5add42
3 changed files with 22 additions and 1 deletions

View File

@ -189,6 +189,18 @@ set_bottom(const struct bm_menu *menu, bool bottom)
}
}
static void
grab_keyboard(const struct bm_menu *menu, bool grab)
{
struct wayland *wayland = menu->renderer->internal;
assert(wayland);
struct window *window;
wl_list_for_each(window, &wayland->windows, link) {
bm_wl_window_grab_keyboard(window, wayland->display, grab);
}
}
static void
destructor(struct bm_menu *menu)
{
@ -282,6 +294,7 @@ register_renderer(struct render_api *api)
api->poll_key = poll_key;
api->render = render;
api->set_bottom = set_bottom;
api->grab_keyboard = grab_keyboard;
api->priorty = BM_PRIO_GUI;
api->version = BM_PLUGIN_VERSION;
return "wayland";

View File

@ -119,6 +119,7 @@ bool bm_wl_registry_register(struct wayland *wayland);
void bm_wl_registry_destroy(struct wayland *wayland);
void bm_wl_window_render(struct window *window, struct wl_display *display, const struct bm_menu *menu);
void bm_wl_window_set_bottom(struct window *window, struct wl_display *display, bool bottom);
void bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab);
bool bm_wl_window_create(struct window *window, struct wl_display *display, struct wl_shm *shm, struct wl_output *output, struct zwlr_layer_shell_v1 *layer_shell, struct wl_surface *surface);
void bm_wl_window_destroy(struct window *window);

View File

@ -295,6 +295,14 @@ bm_wl_window_set_bottom(struct window *window, struct wl_display *display, bool
wl_display_roundtrip(display);
}
void
bm_wl_window_grab_keyboard(struct window *window, struct wl_display *display, bool grab)
{
zwlr_layer_surface_v1_set_keyboard_interactivity(window->layer_surface, grab);
wl_surface_commit(window->surface);
wl_display_roundtrip(display);
}
bool
bm_wl_window_create(struct window *window, struct wl_display *display, struct wl_shm *shm, struct wl_output *output, struct zwlr_layer_shell_v1 *layer_shell, struct wl_surface *surface)
{
@ -305,7 +313,6 @@ bm_wl_window_create(struct window *window, struct wl_display *display, struct wl
zwlr_layer_surface_v1_set_exclusive_zone(window->layer_surface, -1);
zwlr_layer_surface_v1_set_anchor(window->layer_surface, (window->bottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
zwlr_layer_surface_v1_set_size(window->layer_surface, 0, 32);
zwlr_layer_surface_v1_set_keyboard_interactivity(window->layer_surface, true);
wl_surface_commit(surface);
wl_display_roundtrip(display);
} else {