From f70d0ec5aa7ad7fdfd8229204c3a0cbfe04f13e7 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 18 May 2022 12:18:58 +0200 Subject: [PATCH] Added movetoworkspacesilent --- src/helpers/MiscFunctions.cpp | 20 +++++++ src/helpers/MiscFunctions.hpp | 1 + src/layout/DwindleLayout.cpp | 4 +- src/managers/KeybindManager.cpp | 97 +++++++++++++++++++++++---------- src/managers/KeybindManager.hpp | 1 + 5 files changed, 93 insertions(+), 30 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 61ae0c497..ebc8c2137 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -1,6 +1,7 @@ #include "MiscFunctions.hpp" #include "../defines.hpp" #include +#include "../Compositor.hpp" void addWLSignal(wl_signal* pSignal, wl_listener* pListener, void* pOwner, std::string ownerString) { ASSERT(pSignal); @@ -120,4 +121,23 @@ bool isNumber(const std::string& str) { bool isDirection(const std::string& arg) { return arg == "l" || arg == "r" || arg == "u" || arg == "d" || arg == "t" || arg == "b"; +} + +int getWorkspaceIDFromString(const std::string& in, std::string& outName) { + int result = INT_MAX; + if (in.find("name:") == 0) { + const auto WORKSPACENAME = in.substr(in.find_first_of(':') + 1); + const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME); + if (!WORKSPACE) { + result = g_pCompositor->getNextAvailableNamedWorkspace(); + } else { + result = WORKSPACE->m_iID; + } + outName = WORKSPACENAME; + } else { + result = std::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); + outName = std::to_string(result); + } + + return result; } \ No newline at end of file diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index e7b207dea..ff7cc70ad 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -9,5 +9,6 @@ void scaleBox(wlr_box*, float); std::string removeBeginEndSpacesTabs(std::string); bool isNumber(const std::string&); bool isDirection(const std::string&); +int getWorkspaceIDFromString(const std::string&, std::string&); float getPlusMinusKeywordResult(std::string in, float relative); \ No newline at end of file diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index d224e7752..5c133336f 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -176,7 +176,7 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); // Populate the node with our window's data - PNODE->workspaceID = PMONITOR->activeWorkspace; + PNODE->workspaceID = pWindow->m_iWorkspaceID; PNODE->pWindow = pWindow; PNODE->isNode = false; PNODE->layout = this; @@ -184,7 +184,7 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { SDwindleNodeData* OPENINGON; const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor(); - if (PMONITOR->ID == MONFROMCURSOR->ID) + if (PMONITOR->ID == MONFROMCURSOR->ID && PNODE->workspaceID == PMONITOR->activeWorkspace) OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal())); else OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 87f0b94d5..542585291 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -3,20 +3,21 @@ CKeybindManager::CKeybindManager() { // initialize all dispatchers - m_mDispatchers["exec"] = spawn; - m_mDispatchers["killactive"] = killActive; - m_mDispatchers["togglefloating"] = toggleActiveFloating; - m_mDispatchers["workspace"] = changeworkspace; - m_mDispatchers["fullscreen"] = fullscreenActive; - m_mDispatchers["movetoworkspace"] = moveActiveToWorkspace; - m_mDispatchers["pseudo"] = toggleActivePseudo; - m_mDispatchers["movefocus"] = moveFocusTo; - m_mDispatchers["movewindow"] = moveActiveTo; - m_mDispatchers["togglegroup"] = toggleGroup; - m_mDispatchers["changegroupactive"] = changeGroupActive; - m_mDispatchers["togglesplit"] = toggleSplit; - m_mDispatchers["splitratio"] = alterSplitRatio; - m_mDispatchers["focusmonitor"] = focusMonitor; + m_mDispatchers["exec"] = spawn; + m_mDispatchers["killactive"] = killActive; + m_mDispatchers["togglefloating"] = toggleActiveFloating; + m_mDispatchers["workspace"] = changeworkspace; + m_mDispatchers["fullscreen"] = fullscreenActive; + m_mDispatchers["movetoworkspace"] = moveActiveToWorkspace; + m_mDispatchers["movetoworkspacesilent"] = moveActiveToWorkspaceSilent; + m_mDispatchers["pseudo"] = toggleActivePseudo; + m_mDispatchers["movefocus"] = moveFocusTo; + m_mDispatchers["movewindow"] = moveActiveTo; + m_mDispatchers["togglegroup"] = toggleGroup; + m_mDispatchers["changegroupactive"] = changeGroupActive; + m_mDispatchers["togglesplit"] = toggleSplit; + m_mDispatchers["splitratio"] = alterSplitRatio; + m_mDispatchers["focusmonitor"] = focusMonitor; } void CKeybindManager::addKeybind(SKeybind kb) { @@ -167,19 +168,7 @@ void CKeybindManager::changeworkspace(std::string args) { int workspaceToChangeTo = 0; std::string workspaceName = ""; - if (args.find("name:") == 0) { - const auto WORKSPACENAME = args.substr(args.find_first_of(':') + 1); - const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME); - if (!WORKSPACE) { - workspaceToChangeTo = g_pCompositor->getNextAvailableNamedWorkspace(); - } else { - workspaceToChangeTo = WORKSPACE->m_iID; - } - workspaceName = WORKSPACENAME; - } else { - workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); - workspaceName = std::to_string(workspaceToChangeTo); - } + workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName); if (workspaceToChangeTo == INT_MAX) { Debug::log(ERR, "Error in changeworkspace, invalid value"); @@ -349,6 +338,58 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { } } +void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { + // hacky, but works lol + + int workspaceToMoveTo = 0; + std::string workspaceName = ""; + + workspaceToMoveTo = getWorkspaceIDFromString(args, workspaceName); + + if (workspaceToMoveTo == INT_MAX) { + Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value"); + return; + } + + const auto PWINDOW = g_pCompositor->m_pLastWindow; + + if (!g_pCompositor->windowValidMapped(PWINDOW)) + return; + + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + + if (workspaceToMoveTo == PMONITOR->activeWorkspace) + return; + + // may be null until later! + auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToMoveTo); + + const auto PMONITORNEW = PWORKSPACE ? g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID) : PMONITOR; + + const auto OLDWORKSPACEIDONMONITOR = PMONITORNEW->activeWorkspace; + const auto OLDWORKSPACEIDRETURN = PMONITOR->activeWorkspace; + + const auto POLDWORKSPACEONMON = g_pCompositor->getWorkspaceByID(OLDWORKSPACEIDONMONITOR); + const auto POLDWORKSPACEIDRETURN = g_pCompositor->getWorkspaceByID(OLDWORKSPACEIDRETURN); + + moveActiveToWorkspace(args); + + PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToMoveTo); + + changeworkspace(std::to_string(OLDWORKSPACEIDONMONITOR)); + changeworkspace(std::to_string(OLDWORKSPACEIDRETURN)); + + // revert animations + PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0,0)); + PWORKSPACE->m_fAlpha.setValueAndWarp(0.f); + + POLDWORKSPACEIDRETURN->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); + POLDWORKSPACEIDRETURN->m_fAlpha.setValueAndWarp(255.f); + + POLDWORKSPACEONMON->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); + POLDWORKSPACEONMON->m_fAlpha.setValueAndWarp(255.f); +} + void CKeybindManager::moveFocusTo(std::string args) { char arg = args[0]; @@ -508,4 +549,4 @@ void CKeybindManager::focusMonitor(std::string arg) { Debug::log(ERR, "Error in focusMonitor: no such monitor"); } -} \ No newline at end of file +} diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 7f01859a8..014f2cdd2 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -38,6 +38,7 @@ private: static void changeworkspace(std::string); static void fullscreenActive(std::string); static void moveActiveToWorkspace(std::string); + static void moveActiveToWorkspaceSilent(std::string); static void moveFocusTo(std::string); static void moveActiveTo(std::string); static void toggleGroup(std::string);