diff options
| author | Nikolai Nechaev <nikolay_nechaev@mail.ru> | 2025-11-26 07:44:26 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-25 22:44:26 +0000 |
| commit | 40d8fa84919c6d0e9fcb1536f4bc09710d4c031c (patch) | |
| tree | e45044c92e5d8f716f2aa15668c61fed5aaf5895 /src/helpers/MiscFunctions.cpp | |
| parent | 1c1746de61a90dbbae072f3fc618c45af33fdd59 (diff) | |
compositor: Configurable behavior when window to be focused conflicts with fullscreen (#12033)
Renames `misc:new_window_takes_over_fullscreen` into
`misc:on_focus_under_fullscreen` and implements the following behavior:
- By default, when a tiling window is being focused on a workspace where
a fullscreen/maximized window exists, respect
the `misc:on_focus_under_fullscreen` config variable.
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index d11e1be6..25b179e9 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -3,6 +3,7 @@ #include <algorithm> #include "../Compositor.hpp" #include "../managers/TokenManager.hpp" +#include "../desktop/state/FocusState.hpp" #include "Monitor.hpp" #include "../config/ConfigManager.hpp" #include "fs/FsUtils.hpp" @@ -146,7 +147,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { } else if (in.starts_with("empty")) { const bool same_mon = in.substr(5).contains("m"); const bool next = in.substr(5).contains("n"); - if ((same_mon || next) && !g_pCompositor->m_lastMonitor) { + if ((same_mon || next) && !Desktop::focusState()->monitor()) { Debug::log(ERR, "Empty monitor workspace on monitor null!"); return {WORKSPACE_INVALID}; } @@ -155,12 +156,12 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { if (same_mon) { for (auto const& rule : g_pConfigManager->getAllWorkspaceRules()) { const auto PMONITOR = g_pCompositor->getMonitorFromString(rule.monitor); - if (PMONITOR && (PMONITOR->m_id != g_pCompositor->m_lastMonitor->m_id)) + if (PMONITOR && (PMONITOR->m_id != Desktop::focusState()->monitor()->m_id)) invalidWSes.insert(rule.workspaceId); } } - WORKSPACEID id = next ? g_pCompositor->m_lastMonitor->activeWorkspaceID() : 0; + WORKSPACEID id = next ? Desktop::focusState()->monitor()->activeWorkspaceID() : 0; while (++id < LONG_MAX) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id); if (!invalidWSes.contains(id) && (!PWORKSPACE || PWORKSPACE->getWindows() == 0)) { @@ -169,10 +170,10 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { } } } else if (in.starts_with("prev")) { - if (!g_pCompositor->m_lastMonitor) + if (!Desktop::focusState()->monitor()) return {WORKSPACE_INVALID}; - const auto PWORKSPACE = g_pCompositor->m_lastMonitor->m_activeWorkspace; + const auto PWORKSPACE = Desktop::focusState()->monitor()->m_activeWorkspace; if (!valid(PWORKSPACE)) return {WORKSPACE_INVALID}; @@ -191,12 +192,12 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { return {PLASTWORKSPACE->m_id, PLASTWORKSPACE->m_name}; } else if (in == "next") { - if (!g_pCompositor->m_lastMonitor || !g_pCompositor->m_lastMonitor->m_activeWorkspace) { + if (!Desktop::focusState()->monitor() || !Desktop::focusState()->monitor()->m_activeWorkspace) { Debug::log(ERR, "no active monitor or workspace for 'next'"); return {WORKSPACE_INVALID}; } - auto PCURRENTWORKSPACE = g_pCompositor->m_lastMonitor->m_activeWorkspace; + auto PCURRENTWORKSPACE = Desktop::focusState()->monitor()->m_activeWorkspace; WORKSPACEID nextId = PCURRENTWORKSPACE->m_id + 1; @@ -209,7 +210,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { } else { if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) { bool absolute = in[1] == '~'; - if (!g_pCompositor->m_lastMonitor) { + if (!Desktop::focusState()->monitor()) { Debug::log(ERR, "Relative monitor workspace on monitor null!"); return {WORKSPACE_INVALID}; } @@ -227,14 +228,14 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { // Collect all the workspaces we can't jump to. for (auto const& ws : g_pCompositor->getWorkspaces()) { - if (ws->m_isSpecialWorkspace || (ws->m_monitor != g_pCompositor->m_lastMonitor)) { + if (ws->m_isSpecialWorkspace || (ws->m_monitor != Desktop::focusState()->monitor())) { // Can't jump to this workspace invalidWSes.insert(ws->m_id); } } for (auto const& rule : g_pConfigManager->getAllWorkspaceRules()) { const auto PMONITOR = g_pCompositor->getMonitorFromString(rule.monitor); - if (!PMONITOR || PMONITOR->m_id == g_pCompositor->m_lastMonitor->m_id) { + if (!PMONITOR || PMONITOR->m_id == Desktop::focusState()->monitor()->m_id) { // Can't be invalid continue; } @@ -245,7 +246,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { // Prepare all named workspaces in case when we need them std::vector<WORKSPACEID> namedWSes; for (auto const& ws : g_pCompositor->getWorkspaces()) { - if (ws->m_isSpecialWorkspace || (ws->m_monitor != g_pCompositor->m_lastMonitor) || ws->m_id >= 0) + if (ws->m_isSpecialWorkspace || (ws->m_monitor != Desktop::focusState()->monitor()) || ws->m_id >= 0) continue; namedWSes.push_back(ws->m_id); @@ -272,7 +273,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { } else { // Just take a blind guess at where we'll probably end up - WORKSPACEID activeWSID = g_pCompositor->m_lastMonitor->m_activeWorkspace ? g_pCompositor->m_lastMonitor->m_activeWorkspace->m_id : 1; + WORKSPACEID activeWSID = Desktop::focusState()->monitor()->m_activeWorkspace ? Desktop::focusState()->monitor()->m_activeWorkspace->m_id : 1; WORKSPACEID predictedWSID = activeWSID + remains; int remainingWSes = 0; char walkDir = in[1]; @@ -371,7 +372,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { bool onAllMonitors = in[0] == 'e'; bool absolute = in[1] == '~'; - if (!g_pCompositor->m_lastMonitor) { + if (!Desktop::focusState()->monitor()) { Debug::log(ERR, "Relative monitor workspace on monitor null!"); return {WORKSPACE_INVALID}; } @@ -389,7 +390,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { std::vector<WORKSPACEID> validWSes; for (auto const& ws : g_pCompositor->getWorkspaces()) { - if (ws->m_isSpecialWorkspace || (ws->m_monitor != g_pCompositor->m_lastMonitor && !onAllMonitors)) + if (ws->m_isSpecialWorkspace || (ws->m_monitor != Desktop::focusState()->monitor() && !onAllMonitors)) continue; validWSes.push_back(ws->m_id); @@ -414,7 +415,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size(); // get the current item - WORKSPACEID activeWSID = g_pCompositor->m_lastMonitor->m_activeWorkspace ? g_pCompositor->m_lastMonitor->m_activeWorkspace->m_id : 1; + WORKSPACEID activeWSID = Desktop::focusState()->monitor()->m_activeWorkspace ? Desktop::focusState()->monitor()->m_activeWorkspace->m_id : 1; for (ssize_t i = 0; i < sc<ssize_t>(validWSes.size()); i++) { if (validWSes[i] == activeWSID) { currentItem = i; @@ -437,8 +438,8 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { result.name = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_name; } else { if (in[0] == '+' || in[0] == '-') { - if (g_pCompositor->m_lastMonitor) { - const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_lastMonitor->activeWorkspaceID()); + if (Desktop::focusState()->monitor()) { + const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, Desktop::focusState()->monitor()->activeWorkspaceID()); if (!PLUSMINUSRESULT.has_value()) return {WORKSPACE_INVALID}; |
