Fix some issues with a lost focus of the maximized window after using swapwithmaster in fullscreen mode (#1524)

* Fix some issues with a lost focus of the maximized window after using swapwithmaster in fullscreen mode

* Keep current fullscreen mode when `prepareNewFocus` is executed
This commit is contained in:
Philipp Mildenberger 2023-02-11 14:00:05 +01:00 committed by GitHub
parent bda8208aaa
commit 97e0f02621
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -733,7 +733,7 @@ void CHyprMasterLayout::prepareNewFocus(CWindow* pWindow, bool inheritFullscreen
return; return;
if (inheritFullscreen) if (inheritFullscreen)
g_pCompositor->setWindowFullscreen(pWindow, true, FULLSCREEN_MAXIMIZED); g_pCompositor->setWindowFullscreen(pWindow, true, g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_efFullscreenMode);
} }
std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) { std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
@ -754,6 +754,11 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
auto command = vars[0]; auto command = vars[0];
// swapwithmaster <master | child | auto>
// 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 (command == "swapwithmaster") { if (command == "swapwithmaster") {
const auto PWINDOW = header.pWindow; const auto PWINDOW = header.pWindow;
@ -768,34 +773,38 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
if (!PMASTER) if (!PMASTER)
return 0; 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; const auto NEWCHILD = PMASTER->pWindow;
switchWindows(PWINDOW, PMASTER->pWindow);
if (vars.size() >= 2 && vars[1] == "child") if (PMASTER->pWindow != PWINDOW) {
switchToWindow(NEWCHILD); const auto NEWMASTER = PWINDOW;
else // default switch to new master const bool newFocusToChild = vars.size() >= 2 && vars[1] == "child";
switchToWindow(PMASTER->pWindow); const bool inheritFullscreen = prepareLoseFocus(NEWMASTER);
switchWindows(NEWMASTER, NEWCHILD);
const auto NEWFOCUS = newFocusToChild ? NEWCHILD : NEWMASTER;
switchToWindow(NEWFOCUS);
prepareNewFocus(NEWFOCUS, inheritFullscreen);
} else { } else {
for (auto& n : m_lMasterNodesData) { for (auto& n : m_lMasterNodesData) {
if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) { if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) {
switchWindows(n.pWindow, PMASTER->pWindow); const auto NEWMASTER = n.pWindow;
// if master is focused keep master focused (don't do anything) const bool inheritFullscreen = prepareLoseFocus(NEWCHILD);
if (vars.size() >= 2 && vars[1] == "master") { switchWindows(NEWMASTER, NEWCHILD);
switchToWindow(PMASTER->pWindow); const bool newFocusToMaster = vars.size() >= 2 && vars[1] == "master";
} else { // default switch to child const auto NEWFOCUS = newFocusToMaster ? NEWMASTER : NEWCHILD;
switchToWindow(n.pWindow); switchToWindow(NEWFOCUS);
} prepareNewFocus(NEWFOCUS, inheritFullscreen);
break; break;
} }
} }
} }
return 0; return 0;
} else if (command == "focusmaster") { }
// focusmaster <master | auto>
// 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
else if (command == "focusmaster") {
const auto PWINDOW = header.pWindow; const auto PWINDOW = header.pWindow;
if (!PWINDOW) if (!PWINDOW)
@ -808,9 +817,6 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
if (!PMASTER) if (!PMASTER)
return 0; 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) { if (PMASTER->pWindow != PWINDOW) {
switchToWindow(PMASTER->pWindow); switchToWindow(PMASTER->pWindow);
prepareNewFocus(PMASTER->pWindow, inheritFullscreen); prepareNewFocus(PMASTER->pWindow, inheritFullscreen);