From 1a147160cf6d9ab2f4d23e772176ffb1c9752868 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 29 Jan 2023 13:03:42 +0000 Subject: [PATCH] fix crashes with removing outputs --- src/events/Events.cpp | 24 +++++++++++++++++++++++- src/events/Events.hpp | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 2e1573f..19e6e26 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -86,6 +86,22 @@ void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t s Debug::log(LOG, "configure for %s", PLAYERSURFACE->m_pMonitor->name.c_str()); } +void Events::handleLSClosed(void *data, zwlr_layer_surface_v1 *zwlr_layer_surface_v1) { + const auto PLAYERSURFACE = (CLayerSurface*)data; + + for (auto& m : g_pHyprpaper->m_vMonitors) { + std::erase_if(m->layerSurfaces, [&](const auto& other) { return other.get() == PLAYERSURFACE; }); + if (m->pCurrentLayerSurface == PLAYERSURFACE) { + if (m->layerSurfaces.empty()) { + m->pCurrentLayerSurface = nullptr; + } else { + m->pCurrentLayerSurface = m->layerSurfaces.begin()->get(); + g_pHyprpaper->recheckMonitor(m.get()); + } + } + } +} + void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { if (strcmp(interface, wl_compositor_interface.name) == 0) { g_pHyprpaper->m_sCompositor = (wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 4); @@ -109,6 +125,12 @@ void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t nam } void Events::handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name) { - // todo + for (auto& m : g_pHyprpaper->m_vMonitors) { + if (m->wayland_name == name) { + Debug::log(LOG, "Destroying output %s", m->name.c_str()); + std::erase_if(g_pHyprpaper->m_vMonitors, [&](const auto& other) { return other->wayland_name == name; }); + return; + } + } } diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 2b01d2e..8f6f09a 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -17,6 +17,8 @@ namespace Events { void ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height); + void handleLSClosed(void *data, zwlr_layer_surface_v1 *zwlr_layer_surface_v1); + void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name); @@ -35,7 +37,7 @@ namespace Events { inline const wl_output_listener outputListener = {.geometry = geometry, .mode = mode, .done = done, .scale = scale, .name = name, .description = description}; - inline const zwlr_layer_surface_v1_listener layersurfaceListener = { .configure = ls_configure }; + inline const zwlr_layer_surface_v1_listener layersurfaceListener = { .configure = ls_configure, .closed = handleLSClosed }; inline const struct wl_registry_listener registryListener = { .global = handleGlobal, .global_remove = handleGlobalRemove };