From e57a2d7ec87ae775828ea8628ef4eeafce8e6e70 Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Wed, 17 Apr 2024 13:04:16 +0200 Subject: 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. --- src/layout/DwindleLayout.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/layout/DwindleLayout.cpp') 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) { -- cgit v1.2.3