From 95b7c405d464b0eb04141cbbfe077371f5a9d47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 1 Nov 2019 20:19:53 +0100 Subject: [PATCH] wayland: wayl_win_destroy(): unmap windows before destroying This will trigger e.d. keyboard_leave() and wl_pointer_leave() events, which ensures there aren't any references to the destroyed window from the global wayland struct. Call wl_display_roundtrip() to trigger those events *before* we destroy the window. --- wayland.c | 21 +++++++++++++++++++++ wayland.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/wayland.c b/wayland.c index 91c3ac28..6a1d0fae 100644 --- a/wayland.c +++ b/wayland.c @@ -639,6 +639,7 @@ struct wl_window * wayl_win_init(struct wayland *wayl) { struct wl_window *win = calloc(1, sizeof(*win)); + win->wayl = wayl; win->surface = wl_compositor_create_surface(wayl->compositor); if (win->surface == NULL) { @@ -687,6 +688,25 @@ wayl_win_destroy(struct wl_window *win) if (win == NULL) return; + /* + * First, unmap all surfaces to trigger things like + * keyboard_leave() and wl_pointer_leave(). + * + * This ensures we remove all references to *this* window from the + * global wayland struct (since it no longer has neither keyboard + * nor mouse focus). + */ + + /* Scrollback search */ + wl_surface_attach(win->search_surface, NULL, 0, 0); + wl_surface_commit(win->search_surface); + wl_display_roundtrip(win->wayl->display); + + /* Main window */ + wl_surface_attach(win->surface, NULL, 0, 0); + wl_surface_commit(win->surface); + wl_display_roundtrip(win->wayl->display); + tll_free(win->on_outputs); if (win->search_sub_surface != NULL) wl_subsurface_destroy(win->search_sub_surface); @@ -702,6 +722,7 @@ wayl_win_destroy(struct wl_window *win) xdg_surface_destroy(win->xdg_surface); if (win->surface != NULL) wl_surface_destroy(win->surface); + free(win); } diff --git a/wayland.h b/wayland.h index d0a8332f..7e7bfd4c 100644 --- a/wayland.h +++ b/wayland.h @@ -72,7 +72,9 @@ struct wl_primary { uint32_t serial; }; +struct wayland; struct wl_window { + struct wayland *wayl; struct wl_surface *surface; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel;