From 7cd3e5f34affc85ed57345fe3473d64d83151677 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 14 Apr 2022 23:02:10 +0200 Subject: [PATCH] Added workspace dispatcher + and - --- src/managers/KeybindManager.cpp | 35 +++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index dbb5fa06..f4e0df94 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -56,6 +56,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t else if (k.handler == "movefocus") { moveFocusTo(k.arg); } else if (k.handler == "togglegroup") { toggleGroup(k.arg); } else if (k.handler == "changegroupactive") { changeGroupActive(k.arg); } + else { + Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str()); + } found = true; } @@ -130,10 +133,28 @@ void CKeybindManager::toggleActivePseudo(std::string args) { void CKeybindManager::changeworkspace(std::string args) { int workspaceToChangeTo = 0; - try { - workspaceToChangeTo = stoi(args); - } catch (...) { - Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str()); + + if (args.find_first_of("+") == 0) { + try { + workspaceToChangeTo = g_pCompositor->m_pLastMonitor->activeWorkspace + std::stoi(args.substr(1)); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str()); + return; + } + } else if (args.find_first_of("-") == 0) { + try { + workspaceToChangeTo = std::clamp(g_pCompositor->m_pLastMonitor->activeWorkspace - std::stoi(args.substr(1)), 1, INT_MAX); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str()); + return; + } + } else { + try { + workspaceToChangeTo = stoi(args); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str()); + return; + } } // if it exists, we warp to it @@ -171,6 +192,9 @@ void CKeybindManager::changeworkspace(std::string args) { Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); + // focus + g_pInputManager->refocus(); + return; } @@ -198,6 +222,9 @@ void CKeybindManager::changeworkspace(std::string args) { g_pCompositor->deactivateAllWLRWorkspaces(); wlr_ext_workspace_handle_v1_set_active(PWORKSPACE->m_pWlrHandle, true); + // focus (clears the last) + g_pInputManager->refocus(); + Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); }