diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f11a2a4d2..015669854 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1021,4 +1021,19 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, SMonitor* pMoni g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID); g_pInputManager->refocus(); +} + +bool CCompositor::workspaceIDOutOfBounds(const int& id) { + int lowestID = 99999; + int highestID = -99999; + + for (auto& w : m_lWorkspaces) { + if (w.m_iID < lowestID) + lowestID = w.m_iID; + + if (w.m_iID > highestID) + highestID = w.m_iID; + } + + return std::clamp(id, lowestID, highestID) != id; } \ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 43082b482..d3e76819f 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -129,6 +129,7 @@ public: void moveWindowToWorkspace(CWindow*, const std::string&); int getNextAvailableMonitorID(); void moveWorkspaceToMonitor(CWorkspace*, SMonitor*); + bool workspaceIDOutOfBounds(const int&); private: void initAllSignals(); diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 440bdc26a..c7688cb1f 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -135,8 +135,59 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } outName = WORKSPACENAME; } else { - result = std::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); - outName = std::to_string(result); + if (in[0] == 'm') { + // monitor relative + result = (int)getPlusMinusKeywordResult(in.substr(1), 0); + + // result now has +/- what we should move on mon + int remains = (int)result; + int currentID = g_pCompositor->m_pLastMonitor->activeWorkspace; + int searchID = currentID; + + while (remains != 0) { + if (remains < 0) + searchID--; + else + searchID++; + + if (g_pCompositor->workspaceIDOutOfBounds(searchID)){ + // means we need to wrap around + int lowestID = 99999; + int highestID = -99999; + + for (auto& w : g_pCompositor->m_lWorkspaces) { + if (w.m_iID < lowestID) + lowestID = w.m_iID; + + if (w.m_iID > highestID) + highestID = w.m_iID; + } + + if (remains < 0) + searchID = highestID; + else + searchID = lowestID; + } + + if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE) { + if (PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) { + currentID = PWORKSPACE->m_iID; + + if (remains < 0) + remains++; + else + remains--; + } + } + } + + result = currentID; + outName = g_pCompositor->getWorkspaceByID(currentID)->m_szName; + + } else { + result = std::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); + outName = std::to_string(result); + } } return result;