diff options
Diffstat (limited to 'src/managers/KeybindManager.cpp')
| -rw-r--r-- | src/managers/KeybindManager.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
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 {}; } |
