mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 03:25:59 +01:00
added swapnext and swapprev for master
This commit is contained in:
parent
9c3aeda9f9
commit
00ef40dda1
3 changed files with 100 additions and 67 deletions
|
@ -452,8 +452,80 @@ void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
|
||||||
recalculateMonitor(pWindow->m_iMonitorID);
|
recalculateMonitor(pWindow->m_iMonitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CWindow* CHyprMasterLayout::getNextWindow(CWindow* pWindow, bool next) {
|
||||||
|
if (!isWindowTiled(pWindow))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
const auto PNODE = getNodeFromWindow(pWindow);
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
if (PNODE->isMaster) {
|
||||||
|
// focus the first non master
|
||||||
|
for (auto n : m_lMasterNodesData) {
|
||||||
|
if (n.pWindow != pWindow && n.workspaceID == pWindow->m_iWorkspaceID) {
|
||||||
|
return n.pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// focus next
|
||||||
|
bool reached = false;
|
||||||
|
bool found = false;
|
||||||
|
for (auto n : m_lMasterNodesData) {
|
||||||
|
if (n.pWindow == pWindow) {
|
||||||
|
reached = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n.workspaceID == pWindow->m_iWorkspaceID && reached) {
|
||||||
|
return n.pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
const auto PMASTER = getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID);
|
||||||
|
|
||||||
|
if (PMASTER)
|
||||||
|
return PMASTER->pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (PNODE->isMaster) {
|
||||||
|
// focus the first non master
|
||||||
|
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
||||||
|
if (it->pWindow != pWindow && it->workspaceID == pWindow->m_iWorkspaceID) {
|
||||||
|
return it->pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// focus next
|
||||||
|
bool reached = false;
|
||||||
|
bool found = false;
|
||||||
|
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
||||||
|
if (it->pWindow == pWindow) {
|
||||||
|
reached = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->workspaceID == pWindow->m_iWorkspaceID && reached) {
|
||||||
|
return it->pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
const auto PMASTER = getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID);
|
||||||
|
|
||||||
|
if (PMASTER)
|
||||||
|
return PMASTER->pWindow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
|
std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
|
||||||
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
|
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
|
||||||
|
if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO))
|
||||||
|
return;
|
||||||
|
|
||||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||||
Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f;
|
Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f;
|
||||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
||||||
|
@ -479,80 +551,40 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
} else if (message == "cyclenext") {
|
} else if (message == "cyclenext") {
|
||||||
const auto PWINDOW = header.pWindow;
|
const auto PWINDOW = header.pWindow;
|
||||||
|
|
||||||
if (!isWindowTiled(PWINDOW))
|
switchToWindow(getNextWindow(PWINDOW, true));
|
||||||
return 0;
|
|
||||||
|
|
||||||
const auto PNODE = getNodeFromWindow(PWINDOW);
|
|
||||||
|
|
||||||
if (PNODE->isMaster) {
|
|
||||||
// focus the first non master
|
|
||||||
for (auto n : m_lMasterNodesData) {
|
|
||||||
if (n.pWindow != PWINDOW && n.workspaceID == PWINDOW->m_iWorkspaceID) {
|
|
||||||
switchToWindow(n.pWindow);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// focus next
|
|
||||||
bool reached = false;
|
|
||||||
bool found = false;
|
|
||||||
for (auto n : m_lMasterNodesData) {
|
|
||||||
if (n.pWindow == PWINDOW) {
|
|
||||||
reached = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.workspaceID == PWINDOW->m_iWorkspaceID && reached) {
|
|
||||||
switchToWindow(n.pWindow);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID);
|
|
||||||
|
|
||||||
if (PMASTER)
|
|
||||||
switchToWindow(PMASTER->pWindow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (message == "cycleprev") {
|
} else if (message == "cycleprev") {
|
||||||
const auto PWINDOW = header.pWindow;
|
const auto PWINDOW = header.pWindow;
|
||||||
|
|
||||||
if (!isWindowTiled(PWINDOW))
|
switchToWindow(getNextWindow(PWINDOW, false));
|
||||||
|
} else if (message == "swapnext") {
|
||||||
|
if (!g_pCompositor->windowValidMapped(header.pWindow))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const auto PNODE = getNodeFromWindow(PWINDOW);
|
if (header.pWindow->m_bIsFloating) {
|
||||||
|
g_pKeybindManager->m_mDispatchers["swapnext"]("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (PNODE->isMaster) {
|
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true);
|
||||||
// focus the first non master
|
|
||||||
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
|
||||||
if (it->pWindow != PWINDOW && it->workspaceID == PWINDOW->m_iWorkspaceID) {
|
|
||||||
switchToWindow(it->pWindow);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// focus next
|
|
||||||
bool reached = false;
|
|
||||||
bool found = false;
|
|
||||||
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
|
||||||
if (it->pWindow == PWINDOW) {
|
|
||||||
reached = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it->workspaceID == PWINDOW->m_iWorkspaceID && reached) {
|
if (PWINDOWTOSWAPWITH) {
|
||||||
switchToWindow(it->pWindow);
|
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
||||||
found = true;
|
g_pCompositor->focusWindow(header.pWindow);
|
||||||
break;
|
}
|
||||||
}
|
} else if (message == "swapprev") {
|
||||||
}
|
if (!g_pCompositor->windowValidMapped(header.pWindow))
|
||||||
if (!found) {
|
return 0;
|
||||||
const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID);
|
|
||||||
|
|
||||||
if (PMASTER)
|
if (header.pWindow->m_bIsFloating) {
|
||||||
switchToWindow(PMASTER->pWindow);
|
g_pKeybindManager->m_mDispatchers["swapnext"]("prev");
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false);
|
||||||
|
|
||||||
|
if (PWINDOWTOSWAPWITH) {
|
||||||
|
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
||||||
|
g_pCompositor->focusWindow(header.pWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
SMasterNodeData* getNodeFromWindow(CWindow*);
|
SMasterNodeData* getNodeFromWindow(CWindow*);
|
||||||
SMasterNodeData* getMasterNodeOnWorkspace(const int&);
|
SMasterNodeData* getMasterNodeOnWorkspace(const int&);
|
||||||
void calculateWorkspace(const int&);
|
void calculateWorkspace(const int&);
|
||||||
|
CWindow* getNextWindow(CWindow*, bool);
|
||||||
|
|
||||||
friend struct SMasterNodeData;
|
friend struct SMasterNodeData;
|
||||||
};
|
};
|
|
@ -39,7 +39,7 @@ CKeybindManager::CKeybindManager() {
|
||||||
m_mDispatchers["dpms"] = dpms;
|
m_mDispatchers["dpms"] = dpms;
|
||||||
m_mDispatchers["movewindowpixel"] = moveWindow;
|
m_mDispatchers["movewindowpixel"] = moveWindow;
|
||||||
m_mDispatchers["resizewindowpixel"] = resizeWindow;
|
m_mDispatchers["resizewindowpixel"] = resizeWindow;
|
||||||
m_mDispatchers["swapnext"] = swapNext;
|
m_mDispatchers["swapnext"] = swapnext;
|
||||||
|
|
||||||
m_tScrollTimer.reset();
|
m_tScrollTimer.reset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue