From f0c99d276aa9e796c679c2359de1272736a273b7 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Mon, 19 Jan 2026 21:18:50 +0100 Subject: [PATCH] Cancel pending frame callback before destroying surface and ignore old surfaces This applies two of the improvements in the pull request "Fix bug complying with wlr-layer-shell-unstable-v1 which causes crashes" to the overhauled codebase. Reference: https://github.com/jjsullivan5196/wvkbd/pull/pr114 Co-authored-by: Armando DiCianno --- main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.c b/main.c index 329e80e..c722c97 100644 --- a/main.c +++ b/main.c @@ -515,6 +515,12 @@ void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) { + // Swallow events for old/destroyed surface + if (surface != layer_surface) { + zwlr_layer_surface_v1_ack_configure(surface, serial); + return; + }; + // Not what we expected, or redimension, refresh and restart if (keyboard.w != w || keyboard.h != h) { zwlr_layer_surface_v1_ack_configure(surface, serial); @@ -665,7 +671,15 @@ hide() zwlr_layer_surface_v1_destroy(layer_surface); layer_surface = NULL; layer_surface_configured = false; + + // Cancel pending frame callback before destroying surface + if (draw_surf.frame_cb) { + wl_callback_destroy(draw_surf.frame_cb); + draw_surf.frame_cb = NULL; + } + wl_surface_destroy(draw_surf.surf); + draw_surf.attached = false; hidden = true; }