diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d9e3ebf2..2f1746c9 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -649,4 +649,27 @@ void CCompositor::deactivateAllWLRWorkspaces() { if (w.m_pWlrHandle) wlr_ext_workspace_handle_v1_set_active(w.m_pWlrHandle, false); } +} + +CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) { + bool gotToWindow = false; + for (auto& w : m_lWindows) { + if (&w != pWindow && !gotToWindow) + continue; + + if (&w == pWindow) { + gotToWindow = true; + continue; + } + + if (w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w)) + return &w; + } + + for (auto& w : m_lWindows) { + if (&w != pWindow && w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w)) + return &w; + } + + return nullptr; } \ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index c6b31e0a..9f1fdc87 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -103,6 +103,7 @@ public: void cleanupWindows(); CWindow* getWindowInDirection(CWindow*, char); void deactivateAllWLRWorkspaces(); + CWindow* getNextWindowOnWorkspace(CWindow*); private: void initAllSignals(); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 54d5b605..dbb5fa06 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -281,16 +281,32 @@ void CKeybindManager::moveFocusTo(std::string args) { const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; - if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) + auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + Vector2D middle = PWINDOWTOCHANGETO->m_vEffectivePosition + PWINDOWTOCHANGETO->m_vEffectiveSize / 2.f; + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); + }; + + if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) { + const auto PWINDOWTOCHANGETO = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + if (!PWINDOWTOCHANGETO) + return; + + switchToWindow(PWINDOWTOCHANGETO); + return; + } const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); if (PWINDOWTOCHANGETO) { - g_pCompositor->focusWindow(PWINDOWTOCHANGETO); - Vector2D middle = PWINDOWTOCHANGETO->m_vPosition + PWINDOWTOCHANGETO->m_vSize / 2.f; - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); - } + switchToWindow(PWINDOWTOCHANGETO); + } else { + const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW); + if (PWINDOWNEXT) { + switchToWindow(PWINDOWNEXT); + } + } } void CKeybindManager::toggleGroup(std::string args) {