From 0eabb368f5bdbd78824100ddc72e173f76ccdff5 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Sun, 25 Feb 2024 20:01:41 -0800 Subject: [PATCH] [WaylandWindow] Unmap surface before sending activation request Fixes lbonn/rofi#117 --- include/wayland.h | 1 + source/modes/wayland-window.c | 1 + source/wayland/display.c | 17 ++++++++++++++--- source/wayland/view.c | 5 ++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/wayland.h b/include/wayland.h index 522757df6..b2ca49d84 100644 --- a/include/wayland.h +++ b/include/wayland.h @@ -39,6 +39,7 @@ void display_buffer_pool_free(display_buffer_pool *pool); cairo_surface_t *display_buffer_pool_get_next_buffer(display_buffer_pool *pool); void display_surface_commit(cairo_surface_t *surface); +void display_surface_unmap(void); gboolean display_get_surface_dimensions(int *width, int *height); void display_set_surface_dimensions(int width, int height, int x_margin, diff --git a/source/modes/wayland-window.c b/source/modes/wayland-window.c index 91b26ec7a..0cc5cea0f 100644 --- a/source/modes/wayland-window.c +++ b/source/modes/wayland-window.c @@ -412,6 +412,7 @@ static ModeMode wayland_window_mode_result(Mode *sw, int mretv, } else if (mretv & MENU_QUICK_SWITCH) { retv = (ModeMode)(mretv & MENU_LOWER_MASK); } else if ((mretv & MENU_OK)) { + rofi_view_hide(); ForeignToplevelHandle *toplevel = (ForeignToplevelHandle *)g_list_nth_data(pd->toplevels, selected_line); foreign_toplevel_handle_activate(toplevel, pd->wayland->last_seat->seat); diff --git a/source/wayland/display.c b/source/wayland/display.c index 6346231f3..b8fab17f5 100644 --- a/source/wayland/display.c +++ b/source/wayland/display.c @@ -318,6 +318,18 @@ void display_surface_commit(cairo_surface_t *surface) { wl_surface_commit(wayland->surface); } +void display_surface_unmap(void) { + if (wayland->wlr_surface != NULL) { + zwlr_layer_surface_v1_destroy(wayland->wlr_surface); + wayland->wlr_surface = NULL; + } + if (wayland->surface != NULL) { + wl_surface_destroy(wayland->surface); + wayland->surface = NULL; + } + wl_display_flush(wayland->display); +} + static void wayland_frame_callback(void *data, struct wl_callback *callback, uint32_t timestamp) { if (wayland->frame_cb != NULL) { @@ -1409,6 +1421,7 @@ wayland_layer_shell_surface_closed(void *data, zwlr_layer_surface_v1_destroy(surface); wl_surface_destroy(wayland->surface); + wayland->wlr_surface = NULL; wayland->surface = NULL; // In this case, we recreate the layer shell surface the best we can and @@ -1633,9 +1646,7 @@ static void wayland_display_cleanup(void) { return; } - if (wayland->surface != NULL) { - wl_surface_destroy(wayland->surface); - } + display_surface_unmap(); nk_bindings_seat_free(wayland->bindings_seat); g_hash_table_unref(wayland->seats_by_name); diff --git a/source/wayland/view.c b/source/wayland/view.c index 28410eef7..f440bc90f 100644 --- a/source/wayland/view.c +++ b/source/wayland/view.c @@ -423,7 +423,10 @@ static int wayland_rofi_view_calculate_window_height(RofiViewState *state) { return widget_get_desired_height(main_window, state->width); } -static void wayland_rofi_view_hide(void) {} +static void wayland_rofi_view_hide(void) { + display_surface_unmap(); + display_early_cleanup(); +} static void wayland_rofi_view_cleanup() { g_debug("Cleanup.");