From c44cafda9723e268dcedd71eb2f9b918429bbd0f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 9 Jul 2022 18:39:41 +0200 Subject: [PATCH] added cyclenext param previous --- src/Compositor.cpp | 23 +++++++++++++++++++++++ src/Compositor.hpp | 1 + src/managers/KeybindManager.cpp | 7 +++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 0dd0d705..906946c8 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -938,6 +938,29 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) { return nullptr; } +CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow) { + bool gotToWindow = false; + for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); it++) { + if (it->get() != pWindow && !gotToWindow) + continue; + + if (it->get() == pWindow) { + gotToWindow = true; + continue; + } + + if ((*it)->m_iWorkspaceID == pWindow->m_iWorkspaceID && (*it)->m_bIsMapped && !(*it)->m_bHidden) + return it->get(); + } + + for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); it++) { + if (it->get() != pWindow && (*it)->m_iWorkspaceID == pWindow->m_iWorkspaceID && (*it)->m_bIsMapped && !(*it)->m_bHidden) + return it->get(); + } + + return nullptr; +} + int CCompositor::getNextAvailableNamedWorkspace() { int lowest = -1337 + 1; for (auto& w : m_vWorkspaces) { diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 6aaef464..5415eff8 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -127,6 +127,7 @@ public: CWindow* getWindowInDirection(CWindow*, char); void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr); CWindow* getNextWindowOnWorkspace(CWindow*); + CWindow* getPrevWindowOnWorkspace(CWindow*); int getNextAvailableNamedWorkspace(); bool isPointOnAnyMonitor(const Vector2D&); CWindow* getConstraintWindow(SMouse*); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 13bdf1e4..348f0655 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1044,11 +1044,14 @@ void CKeybindManager::moveActive(std::string args) { g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(X, Y)); } -void CKeybindManager::circleNext(std::string) { +void CKeybindManager::circleNext(std::string arg) { if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) return; - g_pCompositor->focusWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow)); + if (arg == "last" || arg == "l" || arg == "prev" || arg == "p") + g_pCompositor->focusWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow)); + else + g_pCompositor->focusWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow)); const auto MIDPOINT = g_pCompositor->m_pLastWindow->m_vRealPosition.goalv() + g_pCompositor->m_pLastWindow->m_vRealSize.goalv() / 2.f;