Skip to content

Commit

Permalink
master: make loop around optional when cycling
Browse files Browse the repository at this point in the history
  • Loading branch information
lonyelon committed Jan 1, 2025
1 parent 788ae58 commit 5f93dfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down Expand Up @@ -1110,15 +1117,17 @@ 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;

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))
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/layout/MasterLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5f93dfe

Please sign in to comment.