helpers: properly support next/prev for workspace switching (#10074)

This commit is contained in:
nyx 2025-04-26 17:52:07 -04:00 committed by GitHub
parent 742bce016c
commit 94c55fe909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,12 +170,35 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
if (!valid(PWORKSPACE)) if (!valid(PWORKSPACE))
return {WORKSPACE_INVALID}; 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}; 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}; 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 { } else {
if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) { if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) {
bool absolute = in[1] == '~'; bool absolute = in[1] == '~';