aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-05-31 12:33:08 +0200
committervaxerski <[email protected]>2022-05-31 12:33:08 +0200
commitdf722cbb86bdc3b45827234c34e6ab90d02d5068 (patch)
tree8b12be8a0ca40f62a5530e0dce7e6d709e44a6bc
parent68f7e565e628a1a52b4bc043e102c7bab7e6dd9a (diff)
downloadHyprland-df722cbb86bdc3b45827234c34e6ab90d02d5068.tar.gz
Hyprland-df722cbb86bdc3b45827234c34e6ab90d02d5068.zip
Added relative monitor workspace offset
-rw-r--r--src/Compositor.cpp15
-rw-r--r--src/Compositor.hpp1
-rw-r--r--src/helpers/MiscFunctions.cpp55
3 files changed, 69 insertions, 2 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index f11a2a4d..01566985 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 43082b48..d3e76819 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 440bdc26..c7688cb1 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;