From 5bb8adbc3228901d199e8d22d6f712bd1d7d4e15 Mon Sep 17 00:00:00 2001 From: 0xFMD <30713087+0xFMD@users.noreply.github.com> Date: Sun, 31 Aug 2025 19:14:39 +0300 Subject: dispatchers: allow window address in swapwindow (#11518) --- src/managers/KeybindManager.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 0eab9689..536f85b1 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1608,15 +1608,9 @@ SDispatchResult CKeybindManager::focusCurrentOrLast(std::string args) { } SDispatchResult CKeybindManager::swapActive(std::string args) { - char arg = args[0]; - - if (!isDirection(args)) { - Debug::log(ERR, "Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return {.success = false, .error = std::format("Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; - } - - Debug::log(LOG, "Swapping active window in direction {}", arg); - const auto PLASTWINDOW = g_pCompositor->m_lastWindow.lock(); + char arg = args[0]; + const auto PLASTWINDOW = g_pCompositor->m_lastWindow.lock(); + PHLWINDOW PWINDOWTOCHANGETO = nullptr; if (!PLASTWINDOW) return {.success = false, .error = "Window to swap with not found"}; @@ -1624,14 +1618,21 @@ SDispatchResult CKeybindManager::swapActive(std::string args) { if (PLASTWINDOW->isFullscreen()) return {.success = false, .error = "Can't swap fullscreen window"}; - const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); - if (!PWINDOWTOCHANGETO) - return {.success = false, .error = "Window to swap with not found"}; + if (isDirection(args)) + PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); + else + PWINDOWTOCHANGETO = g_pCompositor->getWindowByRegex(args); + + if (!PWINDOWTOCHANGETO || PWINDOWTOCHANGETO == PLASTWINDOW) { + Debug::log(ERR, "Can't swap with {}, invalid window", args); + return {.success = false, .error = std::format("Can't swap with {}, invalid window", args)}; + } + + Debug::log(LOG, "Swapping active window with {}", args); updateRelativeCursorCoords(); g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO); PLASTWINDOW->warpCursor(); - return {}; } -- cgit v1.2.3