diff options
author | Maarten de Vries <[email protected]> | 2024-04-17 13:04:16 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-17 12:04:16 +0100 |
commit | e57a2d7ec87ae775828ea8628ef4eeafce8e6e70 (patch) | |
tree | 45e5f30a7e463924a380bb3394ba314667efc7bc | |
parent | e8e02e81e84bb04efa0c926361ec80c60744f665 (diff) | |
download | Hyprland-e57a2d7ec87ae775828ea8628ef4eeafce8e6e70.tar.gz Hyprland-e57a2d7ec87ae775828ea8628ef4eeafce8e6e70.zip |
keybindmgr: add optional `silent` suffix to `movewindow`. (#5597)
With the `silent` suffix, the focus remains on the current position in
the layout or the current monitor, instead of following the moved
window. When combined with `movewindow mon:X`, this this allows you to
get the same behavior as xmonad's `windowToScreen` command.
-rw-r--r-- | src/layout/DwindleLayout.cpp | 13 | ||||
-rw-r--r-- | src/layout/DwindleLayout.hpp | 2 | ||||
-rw-r--r-- | src/layout/IHyprLayout.hpp | 2 | ||||
-rw-r--r-- | src/layout/MasterLayout.cpp | 10 | ||||
-rw-r--r-- | src/layout/MasterLayout.hpp | 2 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 22 |
6 files changed, 36 insertions, 15 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index ea078349..711938e7 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -897,11 +897,13 @@ SWindowRenderLayoutHints CHyprDwindleLayout::requestRenderHints(CWindow* pWindow return hints; } -void CHyprDwindleLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { +void CHyprDwindleLayout::moveWindowTo(CWindow* pWindow, const std::string& dir, bool silent) { if (!isDirection(dir)) return; - const auto PNODE = getNodeFromWindow(pWindow); + const auto PNODE = getNodeFromWindow(pWindow); + const int originalWorkspaceID = pWindow->workspaceID(); + const Vector2D originalPos = pWindow->middle(); if (!PNODE) return; @@ -934,6 +936,13 @@ void CHyprDwindleLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) onWindowCreatedTiling(pWindow); m_vOverrideFocalPoint.reset(); + + // restore focus to the previous position + if (silent) { + const auto PNODETOFOCUS = getClosestNodeOnWorkspace(originalWorkspaceID, originalPos); + if (PNODETOFOCUS && PNODETOFOCUS->pWindow) + g_pCompositor->focusWindow(PNODETOFOCUS->pWindow); + } } void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index 718a47ca..11b927d1 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -56,7 +56,7 @@ class CHyprDwindleLayout : public IHyprLayout { virtual std::any layoutMessage(SLayoutMessageHeader, std::string); virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); virtual void switchWindows(CWindow*, CWindow*); - virtual void moveWindowTo(CWindow*, const std::string& dir); + virtual void moveWindowTo(CWindow*, const std::string& dir, bool silent); virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index d6c41d3b..e05580c4 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -136,7 +136,7 @@ class IHyprLayout { Called when the user requests a window move in a direction. The layout is free to ignore. */ - virtual void moveWindowTo(CWindow*, const std::string& direction) = 0; + virtual void moveWindowTo(CWindow*, const std::string& direction, bool silent = false) = 0; /* Called when the user requests to change the splitratio by or to X diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 0999303f..4ef68712 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -949,7 +949,7 @@ SWindowRenderLayoutHints CHyprMasterLayout::requestRenderHints(CWindow* pWindow) return hints; // master doesnt have any hints } -void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { +void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir, bool silent) { if (!isDirection(dir)) return; @@ -965,12 +965,16 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { onWindowRemovedTiling(pWindow); pWindow->moveToWorkspace(PWINDOW2->m_pWorkspace); pWindow->m_iMonitorID = PWINDOW2->m_iMonitorID; - const auto pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - g_pCompositor->setActiveMonitor(pMonitor); + if (!silent) { + const auto pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + g_pCompositor->setActiveMonitor(pMonitor); + } onWindowCreatedTiling(pWindow); } else { // if same monitor, switch windows switchWindows(pWindow, PWINDOW2); + if (silent) + g_pCompositor->focusWindow(PWINDOW2); } } diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index de4a97a3..de4ac41d 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -62,7 +62,7 @@ class CHyprMasterLayout : public IHyprLayout { virtual std::any layoutMessage(SLayoutMessageHeader, std::string); virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); virtual void switchWindows(CWindow*, CWindow*); - virtual void moveWindowTo(CWindow*, const std::string& dir); + virtual void moveWindowTo(CWindow*, const std::string& dir, bool silent); virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1a97c3da..e6d54ae1 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1216,15 +1216,20 @@ void CKeybindManager::swapActive(std::string args) { } void CKeybindManager::moveActiveTo(std::string args) { - char arg = args[0]; + char arg = args[0]; + bool silent = args.ends_with(" silent"); + if (silent) + args = args.substr(0, args.length() - 7); if (args.starts_with("mon:")) { const auto PNEWMONITOR = g_pCompositor->getMonitorFromString(args.substr(4)); if (!PNEWMONITOR) return; - moveActiveToWorkspace(PNEWMONITOR->activeWorkspace->getConfigName()); - return; + if (silent) + moveActiveToWorkspaceSilent(PNEWMONITOR->activeWorkspace->getConfigName()); + else + moveActiveToWorkspace(PNEWMONITOR->activeWorkspace->getConfigName()); } if (!isDirection(args)) { @@ -1258,8 +1263,9 @@ void CKeybindManager::moveActiveTo(std::string args) { // If the window to change to is on the same workspace, switch them const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); if (PWINDOWTOCHANGETO) { - g_pLayoutManager->getCurrentLayout()->moveWindowTo(PLASTWINDOW, args); - g_pCompositor->warpCursorTo(PLASTWINDOW->middle()); + g_pLayoutManager->getCurrentLayout()->moveWindowTo(PLASTWINDOW, args, silent); + if (!silent) + g_pCompositor->warpCursorTo(PLASTWINDOW->middle()); return; } @@ -1269,8 +1275,10 @@ void CKeybindManager::moveActiveTo(std::string args) { return; const auto PWORKSPACE = PMONITORTOCHANGETO->activeWorkspace; - - moveActiveToWorkspace(PWORKSPACE->getConfigName()); + if (silent) + moveActiveToWorkspaceSilent(PWORKSPACE->getConfigName()); + else + moveActiveToWorkspace(PWORKSPACE->getConfigName()); } void CKeybindManager::toggleGroup(std::string args) { |