summaryrefslogtreecommitdiff
path: root/src/layout/MasterLayout.cpp
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/layout/MasterLayout.cpp
parent9f3a64481ecb277de6775efbb0f3d8d7648a610c (diff)
master: Add orientationcycle command on MasterLayout (#3128)
Diffstat (limited to 'src/layout/MasterLayout.cpp')
-rw-r--r--src/layout/MasterLayout.cpp77
1 files changed, 53 insertions, 24 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) {