From be03497b82be332a124dd170e8741623791ef7c4 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:39:06 +0000 Subject: [PATCH] layout/algos: use binds:window_direction_monitor_fallback for moves (#13508) ref https://github.com/hyprwm/Hyprland/discussions/13473 --- hyprtester/src/tests/main/workspaces.cpp | 121 ++++++++++++++++++ .../tiled/dwindle/DwindleAlgorithm.cpp | 9 +- .../tiled/master/MasterAlgorithm.cpp | 7 +- .../tiled/monocle/MonocleAlgorithm.cpp | 5 + .../tiled/scrolling/ScrollingAlgorithm.cpp | 8 +- src/managers/KeybindManager.cpp | 12 +- 6 files changed, 153 insertions(+), 9 deletions(-) diff --git a/hyprtester/src/tests/main/workspaces.cpp b/hyprtester/src/tests/main/workspaces.cpp index a126d1b2..788b2357 100644 --- a/hyprtester/src/tests/main/workspaces.cpp +++ b/hyprtester/src/tests/main/workspaces.cpp @@ -255,6 +255,126 @@ static void testMultimonBAF() { Tests::killAllWindows(); } +static void testMultimonFocus() { + NLog::log("{}Testing multimon focus and move", Colors::YELLOW); + + OK(getFromSocket("/keyword input:follow_mouse 0")); + OK(getFromSocket("/dispatch focusmonitor HEADLESS-3")); + OK(getFromSocket("/dispatch workspace 8")); + OK(getFromSocket("/dispatch focusmonitor HEADLESS-2")); + OK(getFromSocket("/dispatch workspace 7")); + + for (auto const& win : {"a", "b"}) { + if (!Tests::spawnKitty(win)) { + NLog::log("{}Failed to spawn kitty with win class `{}`", Colors::RED, win); + ++TESTS_FAILED; + ret = 1; + return; + } + } + + OK(getFromSocket("/dispatch focuswindow class:a")); + OK(getFromSocket("/dispatch movefocus r")); + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 7 "); + } + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: b"); + } + + OK(getFromSocket("/dispatch movefocus r")); + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + Tests::spawnKitty("c"); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: c"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + OK(getFromSocket("/dispatch movefocus l")); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: b"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 7 "); + } + + OK(getFromSocket("/dispatch movewindow r")); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: b"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + OK(getFromSocket("/dispatch movefocus r")); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: c"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + OK(getFromSocket("/dispatch movefocus l")); + + OK(getFromSocket("/keyword general:no_focus_fallback true")); + OK(getFromSocket("/keyword binds:window_direction_monitor_fallback false")); + + OK(getFromSocket("/dispatch movefocus l")); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: b"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + OK(getFromSocket("/dispatch movewindow l")); + + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "class: b"); + } + + { + auto str = getFromSocket("/activeworkspace"); + EXPECT_CONTAINS(str, "workspace ID 8 "); + } + + OK(getFromSocket("/reload")); + + Tests::killAllWindows(); +} + static bool test() { NLog::log("{}Testing workspaces", Colors::GREEN); @@ -594,6 +714,7 @@ static bool test() { Tests::killAllWindows(); testMultimonBAF(); + testMultimonFocus(); // destroy the headless output OK(getFromSocket("/output remove HEADLESS-3")); diff --git a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp index 1c8c43a7..17ddfe8a 100644 --- a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp +++ b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp @@ -549,6 +549,8 @@ std::optional CDwindleAlgorithm::predictSizeForNewTarget() { } void CDwindleAlgorithm::moveTargetInDirection(SP t, Math::eDirection dir, bool silent) { + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + const auto PNODE = getNodeFromTarget(t); const Vector2D originalPos = t->position().middle(); @@ -557,12 +559,15 @@ void CDwindleAlgorithm::moveTargetInDirection(SP t, Math::eDirection di const auto FOCAL_POINT = focalPointForDir(t, dir); + const auto PMONITORFOCAL = g_pCompositor->getMonitorFromVector(FOCAL_POINT.value_or(t->position().middle())); + + if (PMONITORFOCAL != m_parent->space()->workspace()->m_monitor && !*PMONITORFALLBACK) + return; // noop + t->window()->setAnimationsToMove(); removeTarget(t); - const auto PMONITORFOCAL = g_pCompositor->getMonitorFromVector(FOCAL_POINT.value_or(t->position().middle())); - if (PMONITORFOCAL != m_parent->space()->workspace()->m_monitor) { // move with a focal point diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp index 88540d20..f2914a46 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp @@ -403,7 +403,9 @@ void CMasterAlgorithm::swapTargets(SP a, SP b) { } void CMasterAlgorithm::moveTargetInDirection(SP t, Math::eDirection dir, bool silent) { - const auto PWINDOW2 = g_pCompositor->getWindowInDirection(t->window(), dir); + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + + const auto PWINDOW2 = g_pCompositor->getWindowInDirection(t->window(), dir); if (!t->window()) return; @@ -424,6 +426,9 @@ void CMasterAlgorithm::moveTargetInDirection(SP t, Math::eDirection dir t->window()->setAnimationsToMove(); if (t->window()->m_workspace != targetWs) { + if (!*PMONITORFALLBACK) + return; // noop + t->assignToSpace(targetWs->m_space, focalPointForDir(t, dir)); } else if (PWINDOW2) { // if same monitor, switch windows diff --git a/src/layout/algorithm/tiled/monocle/MonocleAlgorithm.cpp b/src/layout/algorithm/tiled/monocle/MonocleAlgorithm.cpp index 3551b370..fe92f27c 100644 --- a/src/layout/algorithm/tiled/monocle/MonocleAlgorithm.cpp +++ b/src/layout/algorithm/tiled/monocle/MonocleAlgorithm.cpp @@ -202,6 +202,11 @@ void CMonocleAlgorithm::swapTargets(SP a, SP b) { } void CMonocleAlgorithm::moveTargetInDirection(SP t, Math::eDirection dir, bool silent) { + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + + if (!*PMONITORFALLBACK) + return; // noop + // try to find a monitor in the specified direction, thats the logical thing if (!t || !t->space() || !t->space()->workspace()) return; diff --git a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp index 3b5dca4a..0c3bb1cc 100644 --- a/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp +++ b/src/layout/algorithm/tiled/scrolling/ScrollingAlgorithm.cpp @@ -848,7 +848,9 @@ void CScrollingAlgorithm::moveTargetInDirection(SP t, Math::eDirection } void CScrollingAlgorithm::moveTargetTo(SP t, Math::eDirection dir, bool silent) { - const auto DATA = dataFor(t); + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + + const auto DATA = dataFor(t); if (!DATA) return; @@ -953,6 +955,10 @@ void CScrollingAlgorithm::moveTargetTo(SP t, Math::eDirection dir, bool if (!commenceDir()) { // dir wasn't commenced, move to a workspace if possible // with the original dir + + if (!*PMONITORFALLBACK) + return; // noop + const auto MONINDIR = g_pCompositor->getMonitorInDirection(m_parent->space()->workspace()->m_monitor.lock(), dir); if (MONINDIR && MONINDIR != m_parent->space()->workspace()->m_monitor && MONINDIR->m_activeWorkspace) { t->assignToSpace(MONINDIR->m_activeWorkspace->m_space, focalPointForDir(t, dir)); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1640efc3..c9c512ae 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1468,9 +1468,10 @@ SDispatchResult CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } SDispatchResult CKeybindManager::moveFocusTo(std::string args) { - static auto PFULLCYCLE = CConfigValue("binds:movefocus_cycles_fullscreen"); - static auto PGROUPCYCLE = CConfigValue("binds:movefocus_cycles_groupfirst"); - Math::eDirection dir = Math::fromChar(args[0]); + static auto PFULLCYCLE = CConfigValue("binds:movefocus_cycles_fullscreen"); + static auto PGROUPCYCLE = CConfigValue("binds:movefocus_cycles_groupfirst"); + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + Math::eDirection dir = Math::fromChar(args[0]); if (dir == Math::DIRECTION_DEFAULT) { Log::logger->log(Log::ERR, "Cannot move focus in direction {}, unsupported direction. Supported: l,r,u/t,d/b", args[0]); @@ -1479,7 +1480,8 @@ SDispatchResult CKeybindManager::moveFocusTo(std::string args) { const auto PLASTWINDOW = Desktop::focusState()->window(); if (!PLASTWINDOW || !PLASTWINDOW->aliveAndVisible()) { - tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(dir)); + if (*PMONITORFALLBACK) + tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(dir)); return {}; } @@ -1509,7 +1511,7 @@ SDispatchResult CKeybindManager::moveFocusTo(std::string args) { Log::logger->log(Log::DEBUG, "No window found in direction {}, looking for a monitor", Math::toString(dir)); - if (tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(dir))) + if (*PMONITORFALLBACK && tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(dir))) return {}; static auto PNOFALLBACK = CConfigValue("general:no_focus_fallback");