aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhilipp Mildenberger <[email protected]>2023-02-10 20:13:38 +0100
committerGitHub <[email protected]>2023-02-10 19:13:38 +0000
commit42f4664022352c6432271916b40d24c40a4bfce1 (patch)
treee57ef361e91503625e646f60f116416daa095f7f
parentd1a7f1dd368517854fdcc12a9bdd189578eef435 (diff)
downloadHyprland-42f4664022352c6432271916b40d24c40a4bfce1.tar.gz
Hyprland-42f4664022352c6432271916b40d24c40a4bfce1.zip
Added support for layoutmsg params and added the param 'newfocus' for 'swapwithmaster' and 'focusmaster' (#1522)
* Added support for layoutmsg params and added the param 'newfocus' for 'swapwithmaster' and 'focusmaster', which lets the user decide what the new focused window should be
-rw-r--r--src/layout/MasterLayout.cpp62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp
index 2b1dd15a..4febd882 100644
--- a/src/layout/MasterLayout.cpp
+++ b/src/layout/MasterLayout.cpp
@@ -745,7 +745,16 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f);
};
- if (message == "swapwithmaster") {
+ CVarList vars(message, 0, ' ');
+
+ if (vars.size() < 1 || vars[0].empty()) {
+ Debug::log(ERR, "layoutmsg called without params");
+ return 0;
+ }
+
+ auto command = vars[0];
+
+ if (command == "swapwithmaster") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -759,21 +768,34 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
if (!PMASTER)
return 0;
+ // first message argument can have the following values:
+ // * master - keep the focus at the new master
+ // * child - keep the focus at the new child
+ // * auto (default) - swap the focus (keep the focus of the previously selected window)
if (PMASTER->pWindow != PWINDOW) {
+ const auto NEWCHILD = PMASTER->pWindow;
switchWindows(PWINDOW, PMASTER->pWindow);
- switchToWindow(PWINDOW);
+ if (vars.size() >= 2 && vars[1] == "child")
+ switchToWindow(NEWCHILD);
+ else // default switch to new master
+ switchToWindow(PMASTER->pWindow);
} else {
for (auto& n : m_lMasterNodesData) {
if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) {
switchWindows(n.pWindow, PMASTER->pWindow);
- switchToWindow(n.pWindow);
+ // if master is focused keep master focused (don't do anything)
+ if (vars.size() >= 2 && vars[1] == "master") {
+ switchToWindow(PMASTER->pWindow);
+ } else { // default switch to child
+ switchToWindow(n.pWindow);
+ }
break;
}
}
}
return 0;
- } else if (message == "focusmaster") {
+ } else if (command == "focusmaster") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -786,10 +808,16 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
if (!PMASTER)
return 0;
+ // first message argument can have the following values:
+ // * master - keep the focus at the new master, even if it was focused before
+ // * auto (default) - swap the focus with the first child, if the current focus was master, otherwise focus master
if (PMASTER->pWindow != PWINDOW) {
switchToWindow(PMASTER->pWindow);
prepareNewFocus(PMASTER->pWindow, inheritFullscreen);
+ } else if (vars.size() >= 2 && vars[1] == "master") {
+ return 0;
} else {
+ // if master is focused keep master focused (don't do anything)
for (auto& n : m_lMasterNodesData) {
if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) {
switchToWindow(n.pWindow);
@@ -800,7 +828,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
}
return 0;
- } else if (message == "cyclenext") {
+ } else if (command == "cyclenext") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -811,7 +839,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
const auto PNEXTWINDOW = getNextWindow(PWINDOW, true);
switchToWindow(PNEXTWINDOW);
prepareNewFocus(PNEXTWINDOW, inheritFullscreen);
- } else if (message == "cycleprev") {
+ } else if (command == "cycleprev") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -822,7 +850,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
const auto PPREVWINDOW = getNextWindow(PWINDOW, false);
switchToWindow(PPREVWINDOW);
prepareNewFocus(PPREVWINDOW, inheritFullscreen);
- } else if (message == "swapnext") {
+ } else if (command == "swapnext") {
if (!g_pCompositor->windowValidMapped(header.pWindow))
return 0;
@@ -838,7 +866,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
g_pCompositor->focusWindow(header.pWindow);
}
- } else if (message == "swapprev") {
+ } else if (command == "swapprev") {
if (!g_pCompositor->windowValidMapped(header.pWindow))
return 0;
@@ -854,7 +882,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
g_pCompositor->focusWindow(header.pWindow);
}
- } else if (message == "addmaster") {
+ } else if (command == "addmaster") {
if (!g_pCompositor->windowValidMapped(header.pWindow))
return 0;
@@ -885,7 +913,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
recalculateMonitor(header.pWindow->m_iMonitorID);
- } else if (message == "removemaster") {
+ } else if (command == "removemaster") {
if (!g_pCompositor->windowValidMapped(header.pWindow))
return 0;
@@ -916,7 +944,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
}
recalculateMonitor(header.pWindow->m_iMonitorID);
- } else if (message == "orientationleft" || message == "orientationright" || message == "orientationtop" || message == "orientationbottom") {
+ } else if (command == "orientationleft" || command == "orientationright" || command == "orientationtop" || command == "orientationbottom") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -926,18 +954,18 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
- if (message == "orientationleft")
+ if (command == "orientationleft")
PWORKSPACEDATA->orientation = ORIENTATION_LEFT;
- else if (message == "orientationright")
+ else if (command == "orientationright")
PWORKSPACEDATA->orientation = ORIENTATION_RIGHT;
- else if (message == "orientationtop")
+ else if (command == "orientationtop")
PWORKSPACEDATA->orientation = ORIENTATION_TOP;
- else if (message == "orientationbottom")
+ else if (command == "orientationbottom")
PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM;
recalculateMonitor(header.pWindow->m_iMonitorID);
- } else if (message == "orientationnext") {
+ } else if (command == "orientationnext") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)
@@ -954,7 +982,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
}
recalculateMonitor(header.pWindow->m_iMonitorID);
- } else if (message == "orientationprev") {
+ } else if (command == "orientationprev") {
const auto PWINDOW = header.pWindow;
if (!PWINDOW)