diff options
author | Charles Taylor <[email protected]> | 2022-08-21 20:21:21 +1000 |
---|---|---|
committer | Charles Taylor <[email protected]> | 2022-08-21 20:21:21 +1000 |
commit | 04f0efadc33fd3ac9fb0ed176dbc00dde9906f8e (patch) | |
tree | 8b71885e32d5bfed3e20ad8e8e584e4f66121a3a | |
parent | 9513031da30861b6ab593625aebe88b811758427 (diff) | |
download | Hyprland-04f0efadc33fd3ac9fb0ed176dbc00dde9906f8e.tar.gz Hyprland-04f0efadc33fd3ac9fb0ed176dbc00dde9906f8e.zip |
add switching to previous workspace
-rw-r--r-- | src/helpers/Workspace.hpp | 3 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 28 |
2 files changed, 31 insertions, 0 deletions
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<CWorkspace>(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); |