From a4d69a15b34e54d8438a7242b151b1d31cbef46a Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 20 Mar 2022 10:43:39 +0100 Subject: [PATCH] handle surface monitor better --- src/events/Events.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 29df8ea0..e254ecc9 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -141,11 +141,21 @@ void Events::listener_monitorDestroy(wl_listener* listener, void* data) { void Events::listener_newLayerSurface(wl_listener* listener, void* data) { const auto WLRLAYERSURFACE = (wlr_layer_surface_v1*)data; - if (!WLRLAYERSURFACE->output || !WLRLAYERSURFACE->output->data) { - Debug::log(LOG, "New LayerSurface has no preferred monitor."); + if (!WLRLAYERSURFACE->output) { + const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); + + if (!PMONITOR) { + Debug::log(ERR, "No monitor at cursor on new layer without a monitor. Ignoring."); + wlr_layer_surface_v1_destroy(WLRLAYERSURFACE); + return; + } + + Debug::log(LOG, "New LayerSurface has no preferred monitor. Assigning Monitor %s", PMONITOR->szName); + + WLRLAYERSURFACE->output = PMONITOR->output; } - const auto PMONITOR = (SMonitor*)((WLRLAYERSURFACE->output && WLRLAYERSURFACE->output->data) ? WLRLAYERSURFACE->output->data : g_pCompositor->getMonitorFromCursor()); + const auto PMONITOR = (SMonitor*)g_pCompositor->getMonitorFromOutput(WLRLAYERSURFACE->output); PMONITOR->m_aLayerSurfaceLists[WLRLAYERSURFACE->pending.layer].push_back(new SLayerSurface()); SLayerSurface* layerSurface = PMONITOR->m_aLayerSurfaceLists[WLRLAYERSURFACE->pending.layer].back(); @@ -163,7 +173,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { layerSurface->monitorID = PMONITOR->ID; // todo: arrange - Debug::log(LOG, "LayerSurface %x created on monitor %s", layerSurface, PMONITOR->szName.c_str()); + Debug::log(LOG, "LayerSurface %x (namespace %s layer %d) created on monitor %s", layerSurface, layerSurface->layerSurface->_namespace, layerSurface->layer, PMONITOR->szName.c_str()); } void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) {