dispatchers: allow window address in swapwindow (#11518)

This commit is contained in:
0xFMD 2025-08-31 19:14:39 +03:00 committed by GitHub
parent ea42041f93
commit 5bb8adbc32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 127 additions and 13 deletions

View file

@ -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 {};
}