master: add dispatchers rollnext and rollprev (#4209)

This commit is contained in:
thejch 2023-12-22 03:37:38 -08:00 committed by GitHub
parent bd952dcef2
commit 7cec618fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1332,6 +1332,50 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
nd.percMaster = std::clamp(newMfact, 0.05f, 0.95f);
}
}
} else if (command == "rollnext") {
const auto PWINDOW = header.pWindow;
const auto PNODE = getNodeFromWindow(PWINDOW);
const auto OLDMASTER = PNODE->isMaster ? PNODE : getMasterNodeOnWorkspace(PNODE->workspaceID);
const auto OLDMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *OLDMASTER);
for (auto& nd : m_lMasterNodesData) {
if (nd.workspaceID == PNODE->workspaceID && !nd.isMaster) {
nd.isMaster = true;
const auto NEWMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), nd);
m_lMasterNodesData.splice(OLDMASTERIT, m_lMasterNodesData, NEWMASTERIT);
const bool inheritFullscreen = prepareLoseFocus(PWINDOW);
switchToWindow(nd.pWindow);
prepareNewFocus(nd.pWindow, inheritFullscreen);
OLDMASTER->isMaster = false;
m_lMasterNodesData.splice(m_lMasterNodesData.end(), m_lMasterNodesData, OLDMASTERIT);
break;
}
}
recalculateMonitor(PWINDOW->m_iMonitorID);
} else if (command == "rollprev") {
const auto PWINDOW = header.pWindow;
const auto PNODE = getNodeFromWindow(PWINDOW);
const auto OLDMASTER = PNODE->isMaster ? PNODE : getMasterNodeOnWorkspace(PNODE->workspaceID);
const auto OLDMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *OLDMASTER);
for (auto& nd : m_lMasterNodesData | std::views::reverse) {
if (nd.workspaceID == PNODE->workspaceID && !nd.isMaster) {
nd.isMaster = true;
const auto NEWMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), nd);
m_lMasterNodesData.splice(OLDMASTERIT, m_lMasterNodesData, NEWMASTERIT);
const bool inheritFullscreen = prepareLoseFocus(PWINDOW);
switchToWindow(nd.pWindow);
prepareNewFocus(nd.pWindow, inheritFullscreen);
OLDMASTER->isMaster = false;
m_lMasterNodesData.splice(m_lMasterNodesData.begin(), m_lMasterNodesData, OLDMASTERIT);
break;
}
}
recalculateMonitor(PWINDOW->m_iMonitorID);
}
return 0;