From 118006e8766a56b6fadff2c66d659dbba9ae200f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 22 Mar 2022 21:59:14 +0100 Subject: [PATCH] fixed layersurface coord mapping --- src/Compositor.cpp | 2 +- src/events/Layers.cpp | 13 ++++++------- src/managers/InputManager.cpp | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 953ae1c8..d7b7df4a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -467,5 +467,5 @@ void CCompositor::fixXWaylandWindowsOnWorkspace(const int& id) { } bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) { - return !m_sSeat.exclusiveClient || m_sSeat.exclusiveClient == wl_resource_get_client(surface->resource); + return !m_sSeat.exclusiveClient || (surface && m_sSeat.exclusiveClient == wl_resource_get_client(surface->resource)); } \ No newline at end of file diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index d89bcf73..cc05a386 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -51,7 +51,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { WLRLAYERSURFACE->data = layerSurface; layerSurface->monitorID = PMONITOR->ID; - Debug::log(LOG, "LayerSurface %x (namespace %s layer %d) created on monitor %s", layerSurface, layerSurface->layerSurface->_namespace, layerSurface->layer, PMONITOR->szName.c_str()); + Debug::log(LOG, "LayerSurface %x (namespace %s layer %d) created on monitor %s", layerSurface->layerSurface, layerSurface->layerSurface->_namespace, layerSurface->layer, PMONITOR->szName.c_str()); } void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) { @@ -70,6 +70,8 @@ void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) { const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); + Debug::log(LOG, "LayerSurface %x destroyed", layersurface->layerSurface); + // remove the layersurface as it's not used anymore PMONITOR->m_aLayerSurfaceLists[layersurface->layer].remove(layersurface); delete layersurface; @@ -79,9 +81,6 @@ void Events::listener_destroyLayerSurface(wl_listener* listener, void* data) { g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITOR->ID); } - - - Debug::log(LOG, "LayerSurface %x destroyed", layersurface); } void Events::listener_mapLayerSurface(wl_listener* listener, void* data) { @@ -105,10 +104,10 @@ void Events::listener_mapLayerSurface(wl_listener* listener, void* data) { g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID); - if (layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP || layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) + if (layersurface->layerSurface->current.keyboard_interactive) g_pCompositor->focusSurface(layersurface->layerSurface->surface); - Debug::log(LOG, "LayerSurface %x mapped", layersurface); + Debug::log(LOG, "LayerSurface %x mapped", layersurface->layerSurface); } void Events::listener_unmapLayerSurface(wl_listener* listener, void* data) { @@ -120,7 +119,7 @@ void Events::listener_unmapLayerSurface(wl_listener* listener, void* data) { if (layersurface->layerSurface->surface == g_pCompositor->m_pLastFocus) g_pCompositor->m_pLastFocus = nullptr; - Debug::log(LOG, "LayerSurface %x unmapped", layersurface); + Debug::log(LOG, "LayerSurface %x unmapped", layersurface->layerSurface); } void Events::listener_commitLayerSurface(wl_listener* listener, void* data) { diff --git a/src/managers/InputManager.cpp b/src/managers/InputManager.cpp index baf88402..03f47bcd 100644 --- a/src/managers/InputManager.cpp +++ b/src/managers/InputManager.cpp @@ -23,6 +23,7 @@ void CInputManager::mouseMoveUnified(uint32_t time) { wlr_surface* foundSurface = nullptr; Vector2D mouseCoords = getMouseCoordsInternal(); const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); + Vector2D surfaceCoords; Vector2D surfacePos; // first, we check if the workspace doesnt have a fullscreen window @@ -40,10 +41,10 @@ void CInputManager::mouseMoveUnified(uint32_t time) { // then surfaces on top if (!foundSurface) - foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &surfacePos); + foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &surfaceCoords); if (!foundSurface) - foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfacePos); + foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords); // then windows const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdeal(mouseCoords); @@ -55,10 +56,10 @@ void CInputManager::mouseMoveUnified(uint32_t time) { // then surfaces below if (!foundSurface) - foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &surfacePos); + foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &surfaceCoords); if (!foundSurface) - foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfacePos); + foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfaceCoords); if (!foundSurface) { @@ -72,14 +73,14 @@ void CInputManager::mouseMoveUnified(uint32_t time) { if (time) wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat); - g_pCompositor->focusSurface(foundSurface); - - Vector2D surfaceLocal = Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y) - surfacePos; + Vector2D surfaceLocal = surfacePos == Vector2D() ? surfaceCoords : Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y) - surfacePos; wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); - g_pCompositor->m_pLastMonitor = g_pCompositor->getMonitorFromCursor(); + g_pCompositor->focusSurface(foundSurface); + + g_pCompositor->m_pLastMonitor = PMONITOR; g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); } @@ -105,10 +106,14 @@ void CInputManager::onMouseButton(wlr_event_pointer_button* e) { break; } + refocus(); + // notify app if we didnt handle it - const auto PWINDOW = g_pCompositor->vectorToWindow(getMouseCoordsInternal()); - if (g_pCompositor->windowValidMapped(PWINDOW) && g_pCompositor->doesSeatAcceptInput(g_pXWaylandManager->getWindowSurface(PWINDOW))) + if (g_pCompositor->doesSeatAcceptInput(g_pCompositor->m_pLastFocus)) { wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, e->time_msec, e->button, e->state); + Debug::log(LOG, "Seat notified of button %i (state %i) on surface %x", e->button, e->state, g_pCompositor->m_pLastFocus); + } + } Vector2D CInputManager::getMouseCoordsInternal() {