diff --git a/hyprtester/src/tests/main/master.cpp b/hyprtester/src/tests/main/master.cpp index 9cd20e83..441143ac 100644 --- a/hyprtester/src/tests/main/master.cpp +++ b/hyprtester/src/tests/main/master.cpp @@ -3,7 +3,53 @@ #include "../../hyprctlCompat.hpp" #include "tests.hpp" -static int ret = 0; +static int ret = 0; + +// reqs 1 master 3 slaves +static void testOrientations() { + OK(getFromSocket("/keyword master:orientation top")); + + // top + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "at: 22,22"); + EXPECT_CONTAINS(str, "size: 1876"); + } + + // cycle = top, right, bottom, center, left + + // right + OK(getFromSocket("/dispatch layoutmsg orientationnext")); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "at: 873,22"); + EXPECT_CONTAINS(str, "size: 1025,1036"); + } + + // bottom + OK(getFromSocket("/dispatch layoutmsg orientationnext")); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "at: 22,495"); + EXPECT_CONTAINS(str, "size: 1876"); + } + + // center + OK(getFromSocket("/dispatch layoutmsg orientationnext")); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "at: 450,22"); + EXPECT_CONTAINS(str, "size: 1020,1036"); + } + + // left + OK(getFromSocket("/dispatch layoutmsg orientationnext")); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "at: 22,22"); + EXPECT_CONTAINS(str, "size: 1025,1036"); + } +} static void focusMasterPrevious() { // setup @@ -44,6 +90,8 @@ static void focusMasterPrevious() { OK(getFromSocket("/dispatch layoutmsg focusmaster previous")); EXPECT_CONTAINS(getFromSocket("/activewindow"), "class: master"); + testOrientations(); + // clean up NLog::log("{}Killing all windows", Colors::YELLOW); Tests::killAllWindows(); diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp index a0329b22..7f421e49 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp @@ -668,15 +668,15 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); if (command == "orientationleft") - m_workspaceData.orientation = ORIENTATION_LEFT; + m_workspaceData.explicitOrientation = ORIENTATION_LEFT; else if (command == "orientationright") - m_workspaceData.orientation = ORIENTATION_RIGHT; + m_workspaceData.explicitOrientation = ORIENTATION_RIGHT; else if (command == "orientationtop") - m_workspaceData.orientation = ORIENTATION_TOP; + m_workspaceData.explicitOrientation = ORIENTATION_TOP; else if (command == "orientationbottom") - m_workspaceData.orientation = ORIENTATION_BOTTOM; + m_workspaceData.explicitOrientation = ORIENTATION_BOTTOM; else if (command == "orientationcenter") - m_workspaceData.orientation = ORIENTATION_CENTER; + m_workspaceData.explicitOrientation = ORIENTATION_CENTER; calculateWorkspace(); } else if (command == "orientationnext") { @@ -837,6 +837,34 @@ void CMasterAlgorithm::buildOrientationCycleVectorFromEOperation(std::vector("master:orientation"); + + const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(m_parent->space()->workspace()); + std::string orientationString; + if (WORKSPACERULE.layoutopts.contains("orientation")) + orientationString = WORKSPACERULE.layoutopts.at("orientation"); + else + orientationString = *PORIENT; + + eOrientation orientation = ORIENTATION_LEFT; + // override if workspace rule is set + if (!orientationString.empty()) { + if (orientationString == "top") + orientation = ORIENTATION_TOP; + else if (orientationString == "right") + orientation = ORIENTATION_RIGHT; + else if (orientationString == "bottom") + orientation = ORIENTATION_BOTTOM; + else if (orientationString == "center") + orientation = ORIENTATION_CENTER; + else + orientation = ORIENTATION_LEFT; + } + + return orientation; +} + void CMasterAlgorithm::runOrientationCycle(Hyprutils::String::CVarList2* vars, int next) { std::vector cycle; if (vars != nullptr) @@ -854,7 +882,7 @@ void CMasterAlgorithm::runOrientationCycle(Hyprutils::String::CVarList2* vars, i int nextOrPrev = 0; for (size_t i = 0; i < cycle.size(); ++i) { - if (m_workspaceData.orientation == cycle[i]) { + if (m_workspaceData.explicitOrientation.value_or(defaultOrientation()) == cycle[i]) { nextOrPrev = i + next; break; } @@ -865,36 +893,12 @@ void CMasterAlgorithm::runOrientationCycle(Hyprutils::String::CVarList2* vars, i else if (nextOrPrev < 0) nextOrPrev = cycle.size() + (nextOrPrev % sc(cycle.size())); - m_workspaceData.orientation = cycle.at(nextOrPrev); + m_workspaceData.explicitOrientation = cycle.at(nextOrPrev); calculateWorkspace(); } eOrientation CMasterAlgorithm::getDynamicOrientation() { - static auto PORIENT = CConfigValue("master:orientation"); - - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(m_parent->space()->workspace()); - std::string orientationString; - if (WORKSPACERULE.layoutopts.contains("orientation")) - orientationString = WORKSPACERULE.layoutopts.at("orientation"); - else - orientationString = *PORIENT; - - eOrientation orientation = m_workspaceData.orientation; - // override if workspace rule is set - if (!orientationString.empty()) { - if (orientationString == "top") - orientation = ORIENTATION_TOP; - else if (orientationString == "right") - orientation = ORIENTATION_RIGHT; - else if (orientationString == "bottom") - orientation = ORIENTATION_BOTTOM; - else if (orientationString == "center") - orientation = ORIENTATION_CENTER; - else - orientation = ORIENTATION_LEFT; - } - - return orientation; + return m_workspaceData.explicitOrientation.value_or(defaultOrientation()); } int CMasterAlgorithm::getNodesNo() { diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp index 4524587f..5cfa6b36 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp @@ -19,8 +19,8 @@ namespace Layout::Tiled { }; struct SMasterWorkspaceData { - WORKSPACEID workspaceID = WORKSPACE_INVALID; - eOrientation orientation = ORIENTATION_LEFT; + WORKSPACEID workspaceID = WORKSPACE_INVALID; + std::optional explicitOrientation; // Previously focused non-master window when `focusmaster previous` command was issued WP focusMasterPrev; @@ -71,5 +71,6 @@ namespace Layout::Tiled { SP getNextTarget(SP, bool, bool); int getMastersNo(); bool isWindowTiled(PHLWINDOW); + eOrientation defaultOrientation(); }; }; \ No newline at end of file