master: make loop around optional when cycling (#8926)

This commit is contained in:
Sergio Miguéns 2025-01-04 17:40:33 +01:00 committed by GitHub
parent e8317ae34d
commit b0bae15499
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View file

@ -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 loop) {
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() && !loop) {
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 NOLOOP = vars.size() >= 2 && vars[1] == "noloop";
const auto PNEXTWINDOW = getNextWindow(PWINDOW, true, !NOLOOP);
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 NOLOOP = vars.size() >= 2 && vars[1] == "noloop";
const auto PPREVWINDOW = getNextWindow(PWINDOW, false, !NOLOOP);
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 NOLOOP = vars.size() >= 2 && vars[1] == "noloop";
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true, !NOLOOP);
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 NOLOOP = vars.size() >= 2 && vars[1] == "noloop";
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false, !NOLOOP);
if (PWINDOWTOSWAPWITH) {
g_pCompositor->setWindowFullscreenClient(header.pWindow, FSMODE_NONE);

View file

@ -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;