From 07c7235b7245375802c767472d62b776458c221d Mon Sep 17 00:00:00 2001 From: Tom Benham <38216488+tomben13@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:05:20 +0100 Subject: keybinds: Better handling of workspace_back_and_forth (#4952) * Removed redundant boolean condition * Better handling of workspace_back_and_forth when using focusworkspaceoncurrentmonitor dispatcher * Fixed config acquisition --------- Co-authored-by: Tom Benham --- src/managers/KeybindManager.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9e12750b..47a4b119 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1546,9 +1546,9 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) { void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { std::string workspaceName; - const int WORKSPACEID = getWorkspaceIDFromString(args, workspaceName); + int workspaceID = getWorkspaceIDFromString(args, workspaceName); - if (WORKSPACEID == WORKSPACE_INVALID) { + if (workspaceID == WORKSPACE_INVALID) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!"); return; } @@ -1560,30 +1560,43 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { return; } - auto PWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID); + auto pWorkspace = g_pCompositor->getWorkspaceByID(workspaceID); - if (!PWORKSPACE) { - PWORKSPACE = g_pCompositor->createNewWorkspace(WORKSPACEID, PCURRMONITOR->ID); + if (!pWorkspace) { + pWorkspace = g_pCompositor->createNewWorkspace(workspaceID, PCURRMONITOR->ID); // we can skip the moving, since it's already on the current monitor - changeworkspace(PWORKSPACE->getConfigName()); + changeworkspace(pWorkspace->getConfigName()); return; } - if (PWORKSPACE->m_iMonitorID != PCURRMONITOR->ID) { - const auto POLDMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); + static auto PBACKANDFORTH = CConfigValue("binds:workspace_back_and_forth"); + + if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspace == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) { + const int PREVWORKSPACEID = pWorkspace->m_sPrevWorkspace.iID; + const auto PREVWORKSPACENAME = pWorkspace->m_sPrevWorkspace.name; + // Workspace to focus is previous workspace + pWorkspace = g_pCompositor->getWorkspaceByID(PREVWORKSPACEID); + if (!pWorkspace) + pWorkspace = g_pCompositor->createNewWorkspace(PREVWORKSPACEID, PCURRMONITOR->ID, PREVWORKSPACENAME); + + workspaceID = pWorkspace->m_iID; + } + + if (pWorkspace->m_iMonitorID != PCURRMONITOR->ID) { + const auto POLDMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!POLDMONITOR) { // wat Debug::log(ERR, "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!"); return; } - if (POLDMONITOR->activeWorkspace == WORKSPACEID) { + if (POLDMONITOR->activeWorkspace == workspaceID) { g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR); return; } else { - g_pCompositor->moveWorkspaceToMonitor(PWORKSPACE, PCURRMONITOR, true); + g_pCompositor->moveWorkspaceToMonitor(pWorkspace, PCURRMONITOR, true); } } - changeworkspace(PWORKSPACE->getConfigName()); + changeworkspace(pWorkspace->getConfigName()); } void CKeybindManager::toggleSpecialWorkspace(std::string args) { -- cgit v1.2.3