summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshadowmax31 <ety_95@protonmail.com>2023-09-04 10:45:58 -0400
committerGitHub <noreply@github.com>2023-09-04 16:45:58 +0200
commitb4c832a1f2d1d85815a28990c7337a1ffc34fc9b (patch)
tree4412403a0e782ac5f8eec1e7092bcc18725121cf /src
parent9f3a64481ecb277de6775efbb0f3d8d7648a610c (diff)
master: Add orientationcycle command on MasterLayout (#3128)
Diffstat (limited to 'src')
-rw-r--r--src/layout/MasterLayout.cpp77
-rw-r--r--src/layout/MasterLayout.hpp8
2 files changed, 59 insertions, 26 deletions
diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp
index b5a867d8..f82ac206 100644
--- a/src/layout/MasterLayout.cpp
+++ b/src/layout/MasterLayout.cpp
@@ -1080,42 +1080,71 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
recalculateMonitor(header.pWindow->m_iMonitorID);
} else if (command == "orientationnext") {
- const auto PWINDOW = header.pWindow;
-
- if (!PWINDOW)
- return 0;
+ runOrientationCycle(header, nullptr, 1);
+ } else if (command == "orientationprev") {
+ runOrientationCycle(header, nullptr, -1);
+ } else if (command == "orientationcycle") {
+ runOrientationCycle(header, &vars, 1);
+ }
- prepareLoseFocus(PWINDOW);
+ return 0;
+}
- const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
+// If vars is null, we use the default list
+void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarList* vars, int direction) {
+ std::vector<eOrientation> cycle;
+ if (vars != nullptr)
+ buildOrientationCycleVectorFromVars(cycle, *vars);
- if (PWORKSPACEDATA->orientation == ORIENTATION_CENTER) {
- PWORKSPACEDATA->orientation = ORIENTATION_LEFT;
- } else {
- PWORKSPACEDATA->orientation = (eOrientation)(PWORKSPACEDATA->orientation + 1);
- }
+ if (cycle.size() == 0)
+ buildOrientationCycleVectorFromEOperation(cycle);
- recalculateMonitor(header.pWindow->m_iMonitorID);
- } else if (command == "orientationprev") {
- const auto PWINDOW = header.pWindow;
+ const auto PWINDOW = header.pWindow;
- if (!PWINDOW)
- return 0;
+ if (!PWINDOW)
+ return;
- prepareLoseFocus(PWINDOW);
+ prepareLoseFocus(PWINDOW);
- const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
+ const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
- if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT) {
- PWORKSPACEDATA->orientation = ORIENTATION_CENTER;
- } else {
- PWORKSPACEDATA->orientation = (eOrientation)(PWORKSPACEDATA->orientation - 1);
+ int nextOrPrev = 0;
+ for (size_t i = 0; i < cycle.size(); ++i) {
+ if (PWORKSPACEDATA->orientation == cycle.at(i)) {
+ nextOrPrev = i + direction;
+ break;
}
+ }
- recalculateMonitor(header.pWindow->m_iMonitorID);
+ if (nextOrPrev >= (int)cycle.size())
+ nextOrPrev = nextOrPrev % (int)cycle.size();
+ else if (nextOrPrev < 0)
+ nextOrPrev = cycle.size() + (nextOrPrev % (int)cycle.size());
+
+ PWORKSPACEDATA->orientation = cycle.at(nextOrPrev);
+ recalculateMonitor(header.pWindow->m_iMonitorID);
+}
+
+void CHyprMasterLayout::buildOrientationCycleVectorFromEOperation(std::vector<eOrientation>& cycle) {
+ for (int i = 0; i <= ORIENTATION_CENTER; ++i) {
+ cycle.push_back((eOrientation)i);
}
+}
- return 0;
+void CHyprMasterLayout::buildOrientationCycleVectorFromVars(std::vector<eOrientation>& cycle, CVarList& vars) {
+ for (size_t i = 1; i < vars.size(); ++i) {
+ if (vars[i] == "top") {
+ cycle.push_back(ORIENTATION_TOP);
+ } else if (vars[i] == "right") {
+ cycle.push_back(ORIENTATION_RIGHT);
+ } else if (vars[i] == "bottom") {
+ cycle.push_back(ORIENTATION_BOTTOM);
+ } else if (vars[i] == "left") {
+ cycle.push_back(ORIENTATION_LEFT);
+ } else if (vars[i] == "center") {
+ cycle.push_back(ORIENTATION_CENTER);
+ }
+ }
}
void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) {
diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp
index 7cc11511..3c381dac 100644
--- a/src/layout/MasterLayout.hpp
+++ b/src/layout/MasterLayout.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "IHyprLayout.hpp"
+#include "../config/ConfigManager.hpp"
#include <vector>
#include <list>
#include <deque>
@@ -32,7 +33,7 @@ struct SMasterNodeData {
int workspaceID = -1;
bool operator==(const SMasterNodeData& rhs) const {
- return pWindow == rhs.pWindow;
+ return pWindow == rhs.pWindow;
}
};
@@ -41,7 +42,7 @@ struct SMasterWorkspaceData {
eOrientation orientation = ORIENTATION_LEFT;
bool operator==(const SMasterWorkspaceData& rhs) const {
- return workspaceID == rhs.workspaceID;
+ return workspaceID == rhs.workspaceID;
}
};
@@ -71,6 +72,9 @@ class CHyprMasterLayout : public IHyprLayout {
bool m_bForceWarps = false;
+ void buildOrientationCycleVectorFromVars(std::vector<eOrientation>& cycle, CVarList& vars);
+ void buildOrientationCycleVectorFromEOperation(std::vector<eOrientation>& cycle);
+ void runOrientationCycle(SLayoutMessageHeader& header, CVarList* vars, int next);
int getNodesOnWorkspace(const int&);
void applyNodeDataToWindow(SMasterNodeData*);
SMasterNodeData* getNodeFromWindow(CWindow*);