From af49b7c36156f62307535855feb304efa151e4d7 Mon Sep 17 00:00:00 2001 From: Ilia Bozhinov Date: Sun, 22 Oct 2023 22:16:37 +0200 Subject: [PATCH] xwayland: fix destruction sequence when there are pending transactions --- src/view/xwayland.cpp | 7 +++++-- src/view/xwayland/xwayland-toplevel.cpp | 4 +++- src/view/xwayland/xwayland-toplevel.hpp | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/view/xwayland.cpp b/src/view/xwayland.cpp index 06b57b7f0..8771bfa85 100644 --- a/src/view/xwayland.cpp +++ b/src/view/xwayland.cpp @@ -275,8 +275,11 @@ void wf::xwayland_bring_to_front(wlr_surface *surface) #if WF_HAS_XWAYLAND if (wlr_surface_is_xwayland_surface(surface)) { - auto xw = wlr_xwayland_surface_from_wlr_surface(surface); - wlr_xwayland_surface_restack(xw, NULL, XCB_STACK_MODE_ABOVE); + // Conversion to wlr surface might fail if we are at the very end of the surface life cycle. + if (auto xw = wlr_xwayland_surface_from_wlr_surface(surface)) + { + wlr_xwayland_surface_restack(xw, NULL, XCB_STACK_MODE_ABOVE); + } } #endif diff --git a/src/view/xwayland/xwayland-toplevel.cpp b/src/view/xwayland/xwayland-toplevel.cpp index d471ab3e4..0ccdf7268 100644 --- a/src/view/xwayland/xwayland-toplevel.cpp +++ b/src/view/xwayland/xwayland-toplevel.cpp @@ -18,7 +18,9 @@ wf::xw::xwayland_toplevel_t::xwayland_toplevel_t(wlr_xwayland_surface *xw) this->xw = NULL; on_xw_destroy.disconnect(); on_surface_commit.disconnect(); - emit_ready(); + + // Emit the ready signal on the next idle, to give all substructures time to properly deinitialize. + idle_ready.run_once([&] () { emit_ready(); }); }); on_xw_destroy.connect(&xw->events.destroy); diff --git a/src/view/xwayland/xwayland-toplevel.hpp b/src/view/xwayland/xwayland-toplevel.hpp index d27843417..9e0bbf895 100644 --- a/src/view/xwayland/xwayland-toplevel.hpp +++ b/src/view/xwayland/xwayland-toplevel.hpp @@ -2,6 +2,7 @@ #include "config.h" #include "wayfire/geometry.hpp" +#include "wayfire/util.hpp" #include #include #include @@ -44,6 +45,7 @@ class xwayland_toplevel_t : public wf::toplevel_t, public std::enable_shared_fro wf::wl_listener_wrapper on_surface_commit; wf::wl_listener_wrapper on_xw_destroy; + wf::wl_idle_call idle_ready; wlr_xwayland_surface *xw; wf::point_t output_offset = {0, 0};