diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index f4730892367..c8a0f99ecf6 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -978,7 +978,7 @@ void CHyprMasterLayout::alterSplitRatio(PHLWINDOW pWindow, float ratio, bool exa recalculateMonitor(pWindow->monitorID()); } -PHLWINDOW CHyprMasterLayout::getNextWindow(PHLWINDOW pWindow, bool next) { +PHLWINDOW CHyprMasterLayout::getNextWindow(PHLWINDOW pWindow, bool next, bool loopAround) { if (!isWindowTiled(pWindow)) return nullptr; @@ -997,6 +997,13 @@ PHLWINDOW CHyprMasterLayout::getNextWindow(PHLWINDOW pWindow, bool next) { CANDIDATE = std::find_if(nodes.begin(), nodes.end(), [&](const auto& other) { return other != *PNODE && ISMASTER != other.isMaster && other.workspaceID == PNODE->workspaceID; }); + if (CANDIDATE != nodes.end() && !loopAround) { + if (CANDIDATE->isMaster && next) + return nullptr; + if (!CANDIDATE->isMaster && ISMASTER && !next) + return nullptr; + } + return CANDIDATE == nodes.end() ? nullptr : CANDIDATE->pWindow.lock(); } @@ -1110,7 +1117,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PNEXTWINDOW = getNextWindow(PWINDOW, true); + const bool noLoopAround = vars.size() >= 2 && vars[1] == "noLoopAround"; + const auto PNEXTWINDOW = getNextWindow(PWINDOW, true, !noLoopAround); switchToWindow(PNEXTWINDOW); } else if (command == "cycleprev") { const auto PWINDOW = header.pWindow; @@ -1118,7 +1126,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PPREVWINDOW = getNextWindow(PWINDOW, false); + const bool noLoopAround = vars.size() >= 2 && vars[1] == "noLoopAround"; + const auto PPREVWINDOW = getNextWindow(PWINDOW, false, !noLoopAround); switchToWindow(PPREVWINDOW); } else if (command == "swapnext") { if (!validMapped(header.pWindow)) @@ -1129,7 +1138,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri return 0; } - const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true); + const bool noLoopAround = vars.size() >= 2 && vars[1] == "noLoopAround"; + const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true, !noLoopAround); if (PWINDOWTOSWAPWITH) { g_pCompositor->setWindowFullscreenInternal(header.pWindow, FSMODE_NONE); @@ -1145,7 +1155,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri return 0; } - const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false); + const bool noLoopAround = vars.size() >= 2 && vars[1] == "noLoopAround"; + const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false, !noLoopAround); if (PWINDOWTOSWAPWITH) { g_pCompositor->setWindowFullscreenClient(header.pWindow, FSMODE_NONE); diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index 4841ef08fbe..03ca3c3bd9f 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -87,7 +87,7 @@ class CHyprMasterLayout : public IHyprLayout { SMasterNodeData* getMasterNodeOnWorkspace(const WORKSPACEID&); SMasterWorkspaceData* getMasterWorkspaceData(const WORKSPACEID&); void calculateWorkspace(PHLWORKSPACE); - PHLWINDOW getNextWindow(PHLWINDOW, bool); + PHLWINDOW getNextWindow(PHLWINDOW, bool, bool); int getMastersOnWorkspace(const WORKSPACEID&); friend struct SMasterNodeData;