From 610b30364e1d5206b43b873e3f11d5d66d2e28e5 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 28 Apr 2018 08:16:21 +0900 Subject: [PATCH 1/4] wayland renderer: Fix bottom positioning - reset size when it changes, so there is no blank below text - ignore exclude zone to overlap bar regardless of rendering order --- lib/renderers/wayland/wayland.c | 2 +- lib/renderers/wayland/wayland.h | 2 +- lib/renderers/wayland/window.c | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 69ca230..5309280 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -40,7 +40,7 @@ render(const struct bm_menu *menu) if (wayland->input.code != wayland->input.last_code) { struct window *window; wl_list_for_each(window, &wayland->windows, link) { - bm_wl_window_render(window, menu); + bm_wl_window_render(window, wayland->display, menu); } wayland->input.last_code = wayland->input.code; } diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index 9fd9dc7..e0aeb4d 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -117,7 +117,7 @@ struct wayland { void bm_wl_repeat(struct wayland *wayland); bool bm_wl_registry_register(struct wayland *wayland); void bm_wl_registry_destroy(struct wayland *wayland); -void bm_wl_window_render(struct window *window, const struct bm_menu *menu); +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); 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); diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index e195e38..5ca4578 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -204,7 +204,7 @@ static const struct wl_callback_listener listener = { }; void -bm_wl_window_render(struct window *window, const struct bm_menu *menu) +bm_wl_window_render(struct window *window, struct wl_display *display, const struct bm_menu *menu) { assert(window && menu); @@ -229,6 +229,9 @@ bm_wl_window_render(struct window *window, const struct bm_menu *menu) break; window->height = result.height; + zwlr_layer_surface_v1_set_size(window->layer_surface, 0, window->height); + wl_surface_commit(window->surface); + wl_display_roundtrip(display); destroy_buffer(buffer); } @@ -299,6 +302,7 @@ bm_wl_window_create(struct window *window, struct wl_display *display, struct wl if (layer_shell && (window->layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell, surface, output, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "menu"))) { zwlr_layer_surface_v1_add_listener(window->layer_surface, &layer_surface_listener, window); + 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); From 992e5add42ddc126b7872c53b88fc3bff47fed3f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 28 Apr 2018 08:17:58 +0900 Subject: [PATCH 2/4] 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 --- lib/renderers/wayland/wayland.c | 13 +++++++++++++ lib/renderers/wayland/wayland.h | 1 + lib/renderers/wayland/window.c | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index 5309280..dd97009 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -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"; diff --git a/lib/renderers/wayland/wayland.h b/lib/renderers/wayland/wayland.h index e0aeb4d..cc50feb 100644 --- a/lib/renderers/wayland/wayland.h +++ b/lib/renderers/wayland/wayland.h @@ -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); diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index 5ca4578..6cf0c52 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -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 { From 3ae6ad7c48b358f1d074ec28946a415c0279558c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 28 Apr 2018 08:18:14 +0900 Subject: [PATCH 3/4] wayland renderer: remove useless wl_surface_damage call window->height is 0 at this point anyway... --- lib/renderers/wayland/window.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index 6cf0c52..4669f20 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -321,7 +321,6 @@ bm_wl_window_create(struct window *window, struct wl_display *display, struct wl window->shm = shm; window->surface = surface; - wl_surface_damage(surface, 0, 0, window->width, window->height); return true; } From 67c3c04acbc8e00a9fcbcba63940eea66dd3d01f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 29 Apr 2018 20:41:04 +0900 Subject: [PATCH 4/4] client: update help (--bottom available for wayland) --- client/common/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/common/common.c b/client/common/common.c index 7782925..f59088c 100644 --- a/client/common/common.c +++ b/client/common/common.c @@ -82,7 +82,7 @@ usage(FILE *out, const char *name) " c = ncurses, w == wayland, x == x11\n" " (...) At end of help indicates the backend support for option.\n\n" - " -b, --bottom appears at the bottom of the screen. (x)\n" + " -b, --bottom appears at the bottom of the screen. (wx)\n" " -f, --grab show the menu before reading stdin. (wx)\n" " -m, --monitor index of monitor where menu will appear. (x)\n" " --fn defines the font to be used ('name [size]'). (wx)\n"