From 04f0efadc33fd3ac9fb0ed176dbc00dde9906f8e Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 20:21:21 +1000 Subject: [PATCH 1/6] add switching to previous workspace --- src/helpers/Workspace.hpp | 3 +++ src/managers/KeybindManager.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp index 5a3a24ba..9243c9cc 100644 --- a/src/helpers/Workspace.hpp +++ b/src/helpers/Workspace.hpp @@ -18,6 +18,9 @@ public: int m_iID = -1; std::string m_szName = ""; uint64_t m_iMonitorID = -1; + // Previous workspace ID is stored during a workspace change, allowing travel + // to the previous workspace. + int m_iPrevWorkspaceID = -1; bool m_bHasFullscreenWindow = false; eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9939993a..543066c1 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -454,11 +454,31 @@ void CKeybindManager::changeworkspace(std::string args) { int workspaceToChangeTo = 0; std::string workspaceName = ""; + // Flag needed so that the previous workspace is not recorded when switching + // to a previous workspace. + bool isSwitchingToPrevious = false; + if (args.find("[internal]") == 0) { workspaceToChangeTo = std::stoi(args.substr(10)); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); if (PWORKSPACE) workspaceName = PWORKSPACE->m_szName; + } else if (args.find("previous") == 0) { + const auto P_MONITOR = g_pCompositor->getMonitorFromCursor(); + const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID(P_MONITOR->activeWorkspace); + + // Do nothing if there's no previous workspace, otherwise switch to it. + if (P_CURRENT_WORKSPACE->m_iPrevWorkspaceID == -1) { + Debug::log(LOG, "No previous workspace to change to"); + return; + } + else { + workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; + isSwitchingToPrevious = true; + + // TODO: Add support for cycles + P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + } } else { workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName); } @@ -477,6 +497,10 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); + if (!isSwitchingToPrevious) + // Remember previous workspace. + PWORKSPACETOCHANGETO->m_iPrevWorkspaceID = g_pCompositor->getMonitorFromCursor()->activeWorkspace; + if (workspaceToChangeTo == SPECIAL_WORKSPACE_ID) PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID; @@ -541,6 +565,10 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID)).get(); + if (!isSwitchingToPrevious) + // Remember previous workspace. + PWORKSPACE->m_iPrevWorkspaceID = OLDWORKSPACE; + // start anim on new workspace PWORKSPACE->startAnim(true, ANIMTOLEFT); From d6ff7e40cfde6a8484b50911358032b4c53c721c Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 20:40:06 +1000 Subject: [PATCH 2/6] add general:workspace_back_and_forth option --- src/config/ConfigManager.cpp | 1 + src/managers/KeybindManager.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index ff1791f5..53c008f9 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -34,6 +34,7 @@ void CConfigManager::setDefaultVars() { configValues["general:apply_sens_to_raw"].intValue = 0; configValues["general:main_mod"].strValue = "SUPER"; // exposed to the user for easier configuring configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask("SUPER"); // actually used and automatically calculated + configValues["general:workspace_back_and_forth"].intValue = 0; configValues["general:damage_tracking"].strValue = "full"; configValues["general:damage_tracking_internal"].intValue = DAMAGE_TRACKING_FULL; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 543066c1..45af02a0 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -464,8 +464,8 @@ void CKeybindManager::changeworkspace(std::string args) { if (PWORKSPACE) workspaceName = PWORKSPACE->m_szName; } else if (args.find("previous") == 0) { - const auto P_MONITOR = g_pCompositor->getMonitorFromCursor(); - const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID(P_MONITOR->activeWorkspace); + const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID( + g_pCompositor->getMonitorFromCursor()->activeWorkspace); // Do nothing if there's no previous workspace, otherwise switch to it. if (P_CURRENT_WORKSPACE->m_iPrevWorkspaceID == -1) { @@ -488,6 +488,21 @@ void CKeybindManager::changeworkspace(std::string args) { return; } + // Workspace_back_and_forth being enabled means that an attempt to switch to + // the current workspace will instead switch to the previous. + if (g_pConfigManager->getConfigValuePtr("general:workspace_back_and_forth")->intValue == 1 + && g_pCompositor->getMonitorFromCursor()->activeWorkspace == workspaceToChangeTo) { + + const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID( + g_pCompositor->getMonitorFromCursor()->activeWorkspace); + + workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; + isSwitchingToPrevious = true; + + // TODO: Add support for cycles + P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + } + // remove constraints g_pInputManager->unconstrainMouse(); From 9ee42836d5e2c707f7cf203628a0ae530d59c5cd Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 20:47:56 +1000 Subject: [PATCH 3/6] add general:allow_workspace_cycles option --- src/config/ConfigManager.cpp | 1 + src/managers/KeybindManager.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 53c008f9..079d9a8d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -35,6 +35,7 @@ void CConfigManager::setDefaultVars() { configValues["general:main_mod"].strValue = "SUPER"; // exposed to the user for easier configuring configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask("SUPER"); // actually used and automatically calculated configValues["general:workspace_back_and_forth"].intValue = 0; + configValues["general:allow_workspace_cycles"].intValue = 0; configValues["general:damage_tracking"].strValue = "full"; configValues["general:damage_tracking_internal"].intValue = DAMAGE_TRACKING_FULL; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 45af02a0..ab22d98f 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -476,8 +476,10 @@ void CKeybindManager::changeworkspace(std::string args) { workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; isSwitchingToPrevious = true; - // TODO: Add support for cycles - P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + // If the previous workspace ID isn't reset, cycles can form when continually going + // to the previous workspace again and again. + if (!g_pConfigManager->getConfigValuePtr("general:allow_workspace_cycles")->intValue) + P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; } } else { workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName); @@ -499,8 +501,10 @@ void CKeybindManager::changeworkspace(std::string args) { workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; isSwitchingToPrevious = true; - // TODO: Add support for cycles - P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + // If the previous workspace ID isn't reset, cycles can form when continually going + // to the previous workspace again and again. + if (!g_pConfigManager->getConfigValuePtr("general:allow_workspace_cycles")->intValue) + P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; } // remove constraints From 3c8c605541d6b3e046951ba8710dfb2e9452a3de Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 21:58:46 +1000 Subject: [PATCH 4/6] fix style conflicts and config + monitor retrieval --- src/config/ConfigManager.cpp | 4 ++-- src/helpers/Workspace.hpp | 2 +- src/managers/KeybindManager.cpp | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 079d9a8d..893f4ef0 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -34,8 +34,6 @@ void CConfigManager::setDefaultVars() { configValues["general:apply_sens_to_raw"].intValue = 0; configValues["general:main_mod"].strValue = "SUPER"; // exposed to the user for easier configuring configValues["general:main_mod_internal"].intValue = g_pKeybindManager->stringToModMask("SUPER"); // actually used and automatically calculated - configValues["general:workspace_back_and_forth"].intValue = 0; - configValues["general:allow_workspace_cycles"].intValue = 0; configValues["general:damage_tracking"].strValue = "full"; configValues["general:damage_tracking_internal"].intValue = DAMAGE_TRACKING_FULL; @@ -142,6 +140,8 @@ void CConfigManager::setDefaultVars() { configValues["binds:pass_mouse_when_bound"].intValue = 1; configValues["binds:scroll_event_delay"].intValue = 300; + configValues["binds:workspace_back_and_forth"].intValue = 0; + configValues["binds:allow_workspace_cycles"].intValue = 0; configValues["gestures:workspace_swipe"].intValue = 0; configValues["gestures:workspace_swipe_fingers"].intValue = 3; diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp index 9243c9cc..3faebdd8 100644 --- a/src/helpers/Workspace.hpp +++ b/src/helpers/Workspace.hpp @@ -20,7 +20,7 @@ public: uint64_t m_iMonitorID = -1; // Previous workspace ID is stored during a workspace change, allowing travel // to the previous workspace. - int m_iPrevWorkspaceID = -1; + int m_iPrevWorkspaceID = -1; bool m_bHasFullscreenWindow = false; eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index ab22d98f..374525a2 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -464,22 +464,23 @@ void CKeybindManager::changeworkspace(std::string args) { if (PWORKSPACE) workspaceName = PWORKSPACE->m_szName; } else if (args.find("previous") == 0) { - const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID( + const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID( g_pCompositor->getMonitorFromCursor()->activeWorkspace); // Do nothing if there's no previous workspace, otherwise switch to it. - if (P_CURRENT_WORKSPACE->m_iPrevWorkspaceID == -1) { + if (PCURRENTWORKSPACE->m_iPrevWorkspaceID == -1) { Debug::log(LOG, "No previous workspace to change to"); return; } else { - workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; + workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID; isSwitchingToPrevious = true; // If the previous workspace ID isn't reset, cycles can form when continually going // to the previous workspace again and again. - if (!g_pConfigManager->getConfigValuePtr("general:allow_workspace_cycles")->intValue) - P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + static auto *const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; + if (!*PALLOWWORKSPACECYCLES) + PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1; } } else { workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName); @@ -492,19 +493,20 @@ void CKeybindManager::changeworkspace(std::string args) { // Workspace_back_and_forth being enabled means that an attempt to switch to // the current workspace will instead switch to the previous. - if (g_pConfigManager->getConfigValuePtr("general:workspace_back_and_forth")->intValue == 1 - && g_pCompositor->getMonitorFromCursor()->activeWorkspace == workspaceToChangeTo) { + static auto *const PBACKANDFORTH = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue; + if (*PBACKANDFORTH && g_pCompositor->m_pLastMonitor->activeWorkspace == workspaceToChangeTo) { - const auto P_CURRENT_WORKSPACE = g_pCompositor->getWorkspaceByID( - g_pCompositor->getMonitorFromCursor()->activeWorkspace); + const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID( + g_pCompositor->m_pLastMonitor->activeWorkspace); - workspaceToChangeTo = P_CURRENT_WORKSPACE->m_iPrevWorkspaceID; + workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID; isSwitchingToPrevious = true; // If the previous workspace ID isn't reset, cycles can form when continually going // to the previous workspace again and again. - if (!g_pConfigManager->getConfigValuePtr("general:allow_workspace_cycles")->intValue) - P_CURRENT_WORKSPACE->m_iPrevWorkspaceID = -1; + static auto *const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; + if (!*PALLOWWORKSPACECYCLES) + PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1; } // remove constraints @@ -518,7 +520,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (!isSwitchingToPrevious) // Remember previous workspace. - PWORKSPACETOCHANGETO->m_iPrevWorkspaceID = g_pCompositor->getMonitorFromCursor()->activeWorkspace; + PWORKSPACETOCHANGETO->m_iPrevWorkspaceID = g_pCompositor->m_pLastMonitor->activeWorkspace; if (workspaceToChangeTo == SPECIAL_WORKSPACE_ID) PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID; From 6ec932d11fcc490f3d3f8c544af8fa1a5c8ef4f7 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 22:05:35 +1000 Subject: [PATCH 5/6] fix bug which allowed a switch to workspace ID -1. This only happened for the workspace_back_and_forth setting, since it was missing a check. --- src/managers/KeybindManager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 374525a2..ddf65b42 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -493,11 +493,12 @@ void CKeybindManager::changeworkspace(std::string args) { // Workspace_back_and_forth being enabled means that an attempt to switch to // the current workspace will instead switch to the previous. + const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID( + g_pCompositor->m_pLastMonitor->activeWorkspace); static auto *const PBACKANDFORTH = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue; - if (*PBACKANDFORTH && g_pCompositor->m_pLastMonitor->activeWorkspace == workspaceToChangeTo) { - - const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID( - g_pCompositor->m_pLastMonitor->activeWorkspace); + if (*PBACKANDFORTH + && PCURRENTWORKSPACE->m_iID == workspaceToChangeTo + && PCURRENTWORKSPACE->m_iPrevWorkspaceID != -1) { workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID; isSwitchingToPrevious = true; From 9dbdd66da417eb2316387f3af078349c50bc2929 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Sun, 21 Aug 2022 22:11:40 +1000 Subject: [PATCH 6/6] fix retrieval of monitor --- src/managers/KeybindManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index ddf65b42..3d821d14 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -465,7 +465,7 @@ void CKeybindManager::changeworkspace(std::string args) { workspaceName = PWORKSPACE->m_szName; } else if (args.find("previous") == 0) { const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID( - g_pCompositor->getMonitorFromCursor()->activeWorkspace); + g_pCompositor->m_pLastMonitor->activeWorkspace); // Do nothing if there's no previous workspace, otherwise switch to it. if (PCURRENTWORKSPACE->m_iPrevWorkspaceID == -1) {