mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 18:05:58 +01:00
Master layout: lose or inherit fullscreen on deliberate window switching (#1213)
* Master layout: Lose fullscreen status when deliberately switching away from a fullscreen window * Master layout: implemented inherit_fullscreen config parameter When set, if you are on a fullscreen window and you cycle to the next, swap master, etc, it will be automatically fullscreened.
This commit is contained in:
parent
0c1bec023f
commit
46891b12cf
3 changed files with 60 additions and 6 deletions
|
@ -110,6 +110,7 @@ void CConfigManager::setDefaultVars() {
|
||||||
configValues["master:new_on_top"].intValue = 0;
|
configValues["master:new_on_top"].intValue = 0;
|
||||||
configValues["master:no_gaps_when_only"].intValue = 0;
|
configValues["master:no_gaps_when_only"].intValue = 0;
|
||||||
configValues["master:orientation"].strValue = "left";
|
configValues["master:orientation"].strValue = "left";
|
||||||
|
configValues["master:inherit_fullscreen"].intValue = 1;
|
||||||
|
|
||||||
configValues["animations:enabled"].intValue = 1;
|
configValues["animations:enabled"].intValue = 1;
|
||||||
configValues["animations:speed"].floatValue = 7.f;
|
configValues["animations:speed"].floatValue = 7.f;
|
||||||
|
|
|
@ -582,6 +582,8 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
|
||||||
if (!PNODE2 || !PNODE)
|
if (!PNODE2 || !PNODE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const auto inheritFullscreen = prepareLoseFocus(pWindow);
|
||||||
|
|
||||||
if (PNODE->workspaceID != PNODE2->workspaceID) {
|
if (PNODE->workspaceID != PNODE2->workspaceID) {
|
||||||
std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID);
|
std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID);
|
||||||
std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID);
|
std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID);
|
||||||
|
@ -597,6 +599,8 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
|
||||||
|
|
||||||
g_pHyprRenderer->damageWindow(pWindow);
|
g_pHyprRenderer->damageWindow(pWindow);
|
||||||
g_pHyprRenderer->damageWindow(pWindow2);
|
g_pHyprRenderer->damageWindow(pWindow2);
|
||||||
|
|
||||||
|
prepareNewFocus(pWindow2, inheritFullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
|
void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
|
||||||
|
@ -651,14 +655,14 @@ CWindow* CHyprMasterLayout::getNextWindow(CWindow* pWindow, bool next) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (PNODE->isMaster) {
|
if (PNODE->isMaster) {
|
||||||
// focus the first non master
|
// focus the last non master
|
||||||
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
||||||
if (it->pWindow != pWindow && it->workspaceID == pWindow->m_iWorkspaceID) {
|
if (it->pWindow != pWindow && it->workspaceID == pWindow->m_iWorkspaceID) {
|
||||||
return it->pWindow;
|
return it->pWindow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// focus next
|
// focus previous
|
||||||
bool reached = false;
|
bool reached = false;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
||||||
|
@ -683,6 +687,28 @@ CWindow* CHyprMasterLayout::getNextWindow(CWindow* pWindow, bool next) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CHyprMasterLayout::prepareLoseFocus(CWindow* pWindow) {
|
||||||
|
if (!pWindow)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//if the current window is fullscreen, make it normal again if we are about to lose focus
|
||||||
|
if (pWindow->m_bIsFullscreen) {
|
||||||
|
g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL);
|
||||||
|
const auto INHERIT = &g_pConfigManager->getConfigValuePtr("master:inherit_fullscreen")->intValue;
|
||||||
|
return *INHERIT == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHyprMasterLayout::prepareNewFocus(CWindow* pWindow, bool inheritFullscreen) {
|
||||||
|
if (!pWindow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (inheritFullscreen)
|
||||||
|
g_pCompositor->setWindowFullscreen(pWindow, true, FULLSCREEN_MAXIMIZED);
|
||||||
|
}
|
||||||
|
|
||||||
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))
|
if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO))
|
||||||
|
@ -706,6 +732,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PMASTER)
|
if (!PMASTER)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
if (PMASTER->pWindow != PWINDOW) {
|
if (PMASTER->pWindow != PWINDOW) {
|
||||||
switchWindows(PWINDOW, PMASTER->pWindow);
|
switchWindows(PWINDOW, PMASTER->pWindow);
|
||||||
switchToWindow(PWINDOW);
|
switchToWindow(PWINDOW);
|
||||||
|
@ -726,17 +753,21 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
const bool inheritFullscreen = prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID);
|
const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID);
|
||||||
|
|
||||||
if (!PMASTER)
|
if (!PMASTER)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (PMASTER->pWindow != PWINDOW)
|
if (PMASTER->pWindow != PWINDOW) {
|
||||||
switchToWindow(PMASTER->pWindow);
|
switchToWindow(PMASTER->pWindow);
|
||||||
else {
|
prepareNewFocus(PMASTER->pWindow, inheritFullscreen);
|
||||||
|
} 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) {
|
||||||
switchToWindow(n.pWindow);
|
switchToWindow(n.pWindow);
|
||||||
|
prepareNewFocus(n.pWindow, inheritFullscreen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,14 +780,22 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switchToWindow(getNextWindow(PWINDOW, true));
|
const bool inheritFullscreen = prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
|
const auto PNEXTWINDOW = getNextWindow(PWINDOW, true);
|
||||||
|
switchToWindow(PNEXTWINDOW);
|
||||||
|
prepareNewFocus(PNEXTWINDOW, inheritFullscreen);
|
||||||
} else if (message == "cycleprev") {
|
} else if (message == "cycleprev") {
|
||||||
const auto PWINDOW = header.pWindow;
|
const auto PWINDOW = header.pWindow;
|
||||||
|
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switchToWindow(getNextWindow(PWINDOW, false));
|
const bool inheritFullscreen = prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
|
const auto PPREVWINDOW = getNextWindow(PWINDOW, true);
|
||||||
|
switchToWindow(PPREVWINDOW);
|
||||||
|
prepareNewFocus(PPREVWINDOW, inheritFullscreen);
|
||||||
} else if (message == "swapnext") {
|
} else if (message == "swapnext") {
|
||||||
if (!g_pCompositor->windowValidMapped(header.pWindow))
|
if (!g_pCompositor->windowValidMapped(header.pWindow))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -769,6 +808,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true);
|
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true);
|
||||||
|
|
||||||
if (PWINDOWTOSWAPWITH) {
|
if (PWINDOWTOSWAPWITH) {
|
||||||
|
prepareLoseFocus(header.pWindow);
|
||||||
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
||||||
g_pCompositor->focusWindow(header.pWindow);
|
g_pCompositor->focusWindow(header.pWindow);
|
||||||
}
|
}
|
||||||
|
@ -784,6 +824,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false);
|
const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false);
|
||||||
|
|
||||||
if (PWINDOWTOSWAPWITH) {
|
if (PWINDOWTOSWAPWITH) {
|
||||||
|
prepareLoseFocus(header.pWindow);
|
||||||
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
switchWindows(header.pWindow, PWINDOWTOSWAPWITH);
|
||||||
g_pCompositor->focusWindow(header.pWindow);
|
g_pCompositor->focusWindow(header.pWindow);
|
||||||
}
|
}
|
||||||
|
@ -802,6 +843,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (MASTERS + 2 > WINDOWS)
|
if (MASTERS + 2 > WINDOWS)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prepareLoseFocus(header.pWindow);
|
||||||
|
|
||||||
if (!PNODE || PNODE->isMaster) {
|
if (!PNODE || PNODE->isMaster) {
|
||||||
// first non-master node
|
// first non-master node
|
||||||
for (auto& n : m_lMasterNodesData) {
|
for (auto& n : m_lMasterNodesData) {
|
||||||
|
@ -832,6 +875,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (WINDOWS < 2 || MASTERS < 2)
|
if (WINDOWS < 2 || MASTERS < 2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prepareLoseFocus(header.pWindow);
|
||||||
|
|
||||||
if (!PNODE || !PNODE->isMaster) {
|
if (!PNODE || !PNODE->isMaster) {
|
||||||
// first non-master node
|
// first non-master node
|
||||||
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) {
|
||||||
|
@ -851,6 +896,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
||||||
|
|
||||||
if (message == "orientationleft")
|
if (message == "orientationleft")
|
||||||
|
@ -870,6 +917,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
||||||
|
|
||||||
if (PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) {
|
if (PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) {
|
||||||
|
@ -885,6 +934,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
||||||
if (!PWINDOW)
|
if (!PWINDOW)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
prepareLoseFocus(PWINDOW);
|
||||||
|
|
||||||
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID);
|
||||||
|
|
||||||
if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT) {
|
if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT) {
|
||||||
|
|
|
@ -75,6 +75,8 @@ private:
|
||||||
void calculateWorkspace(const int&);
|
void calculateWorkspace(const int&);
|
||||||
CWindow* getNextWindow(CWindow*, bool);
|
CWindow* getNextWindow(CWindow*, bool);
|
||||||
int getMastersOnWorkspace(const int&);
|
int getMastersOnWorkspace(const int&);
|
||||||
|
bool prepareLoseFocus(CWindow*);
|
||||||
|
void prepareNewFocus(CWindow*, bool inherit_fullscreen);
|
||||||
|
|
||||||
friend struct SMasterNodeData;
|
friend struct SMasterNodeData;
|
||||||
friend struct SMasterWorkspaceData;
|
friend struct SMasterWorkspaceData;
|
||||||
|
|
Loading…
Reference in a new issue