diff --git a/src/Compositor.cpp b/src/Compositor.cpp index a6370de34..44d7c89ea 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1198,6 +1198,26 @@ CWindow* CCompositor::getFirstWindowOnWorkspace(const int& id) { return nullptr; } +CWindow* CCompositor::getTopLeftWindowOnWorkspace(const int& id) { + const auto PWORKSPACE = getWorkspaceByID(id); + + if (!PWORKSPACE) + return nullptr; + + const auto PMONITOR = getMonitorFromID(PWORKSPACE->m_iMonitorID); + + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID != id || !w->m_bIsMapped || w->isHidden()) + continue; + + const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); + + if (WINDOWIDEALBB.x <= PMONITOR->vecPosition.x + 1 && WINDOWIDEALBB.y <= PMONITOR->vecPosition.y + 1) + return w.get(); + } + return nullptr; +} + bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) { if (g_pSessionLockManager->isSessionLocked()) { if (g_pSessionLockManager->isSurfaceSessionLock(surface)) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 6101aa5e7..09f3d193e 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -158,6 +158,7 @@ class CCompositor { CWindow* getUrgentWindow(); bool hasUrgentWindowOnWorkspace(const int&); CWindow* getFirstWindowOnWorkspace(const int&); + CWindow* getTopLeftWindowOnWorkspace(const int&); CWindow* getFullscreenWindowOnWorkspace(const int&); bool doesSeatAcceptInput(wlr_surface*); bool isWindowActive(CWindow*); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 3839115af..d82005e36 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -551,13 +551,27 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal) { } } + static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; + if (const auto PLASTWINDOW = pWorkspace->getLastFocusedWindow(); PLASTWINDOW) g_pCompositor->focusWindow(PLASTWINDOW); else { - g_pCompositor->focusWindow(nullptr); - g_pInputManager->simulateMouseMovement(); + CWindow* pWindow = nullptr; + + if (*PFOLLOWMOUSE == 1) + pWindow = g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()); + + if (!pWindow) + pWindow = g_pCompositor->getTopLeftWindowOnWorkspace(pWorkspace->m_iID); + + if (!pWindow) + pWindow = g_pCompositor->getFirstWindowOnWorkspace(pWorkspace->m_iID); + + g_pCompositor->focusWindow(pWindow); } + g_pInputManager->simulateMouseMovement(); + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); // set some flags and fire event