diff options
| author | nyx <nnyyxxxx@protonmail.com> | 2025-04-26 17:52:07 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-26 23:52:07 +0200 |
| commit | 94c55fe9091078f56acfcff00c4287226b710511 (patch) | |
| tree | e4e6a6f3b704f3a06a09d25586f91c996c75ee62 /src/helpers/MiscFunctions.cpp | |
| parent | 742bce016cb848d222fbfcfcf8d3894ea3fdaeff (diff) | |
helpers: properly support next/prev for workspace switching (#10074)
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index e2d3c907..bb5510b6 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -170,12 +170,35 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { if (!valid(PWORKSPACE)) return {WORKSPACE_INVALID}; - const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->getPrevWorkspaceIDName().id); + const auto PREVWORKSPACEIDNAME = PWORKSPACE->getPrevWorkspaceIDName(); - if (!PLASTWORKSPACE) + if (PREVWORKSPACEIDNAME.id == -1) return {WORKSPACE_INVALID}; + const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PREVWORKSPACEIDNAME.id); + + if (!PLASTWORKSPACE) { + Debug::log(LOG, "previous workspace {} doesn't exist yet", PREVWORKSPACEIDNAME.id); + return {PREVWORKSPACEIDNAME.id, PREVWORKSPACEIDNAME.name}; + } + return {PLASTWORKSPACE->m_id, PLASTWORKSPACE->m_name}; + } else if (in == "next") { + if (!g_pCompositor->m_lastMonitor || !g_pCompositor->m_lastMonitor->activeWorkspace) { + Debug::log(ERR, "no active monitor or workspace for 'next'"); + return {WORKSPACE_INVALID}; + } + + auto PCURRENTWORKSPACE = g_pCompositor->m_lastMonitor->activeWorkspace; + + WORKSPACEID nextId = PCURRENTWORKSPACE->m_id + 1; + + if (nextId <= 0) + return {WORKSPACE_INVALID}; + + result.id = nextId; + result.name = std::to_string(nextId); + return result; } else { if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) { bool absolute = in[1] == '~'; |
