summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorTom Benham <38216488+tomben13@users.noreply.github.com>2024-03-04 18:05:20 +0100
committerGitHub <noreply@github.com>2024-03-04 17:05:20 +0000
commit07c7235b7245375802c767472d62b776458c221d (patch)
tree0142f781261616ff9d9c02d5a2855bb4ce1c31d8 /src/managers/KeybindManager.cpp
parent12da0fc84f8b084f7b13702b811cbed7dae9854c (diff)
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 <tom.benham@quadrille.fr>
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp35
1 files changed, 24 insertions, 11 deletions
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<Hyprlang::INT>("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) {