From 365caa49ff4e4f87da687adfa237b8f855aee42b Mon Sep 17 00:00:00 2001 From: vaxerski Date: Thu, 2 Jan 2025 17:36:02 +0100 Subject: keybinds: attempt to wrap around if fallback is allowed in movefocus fixes #8909 --- src/Compositor.cpp | 57 +++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 4e22f398..c8ed22df 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1460,42 +1460,46 @@ void CCompositor::addToFadingOutSafe(PHLWINDOW pWindow) { } PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { - if (!isDirection(dir)) return nullptr; - // 0 -> history, 1 -> shared length - static auto PMETHOD = CConfigValue("binds:focus_preferred_method"); - static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); - - const auto PMONITOR = pWindow->m_pMonitor.lock(); + const auto PMONITOR = pWindow->m_pMonitor.lock(); if (!PMONITOR) return nullptr; // ?? const auto WINDOWIDEALBB = pWindow->isFullscreen() ? CBox{PMONITOR->vecPosition, PMONITOR->vecSize} : pWindow->getWindowIdealBoundingBoxIgnoreReserved(); + const auto PWORKSPACE = pWindow->m_pWorkspace; - const auto POSA = Vector2D(WINDOWIDEALBB.x, WINDOWIDEALBB.y); - const auto SIZEA = Vector2D(WINDOWIDEALBB.width, WINDOWIDEALBB.height); + return getWindowInDirection(WINDOWIDEALBB, PWORKSPACE, dir, pWindow, pWindow->m_bIsFloating); +} - const auto PWORKSPACE = pWindow->m_pWorkspace; - auto leaderValue = -1; - PHLWINDOW leaderWindow = nullptr; +PHLWINDOW CCompositor::getWindowInDirection(const CBox& box, PHLWORKSPACE pWorkspace, char dir, PHLWINDOW ignoreWindow, bool useVectorAngles) { + if (!isDirection(dir)) + return nullptr; - if (!pWindow->m_bIsFloating) { + // 0 -> history, 1 -> shared length + static auto PMETHOD = CConfigValue("binds:focus_preferred_method"); + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); - // for tiled windows, we calc edges + const auto POSA = box.pos(); + const auto SIZEA = box.size(); + + auto leaderValue = -1; + PHLWINDOW leaderWindow = nullptr; + + if (!useVectorAngles) { for (auto const& w : m_vWindows) { - if (w == pWindow || !w->m_pWorkspace || !w->m_bIsMapped || w->isHidden() || (!w->isFullscreen() && w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) + if (w == ignoreWindow || !w->m_pWorkspace || !w->m_bIsMapped || w->isHidden() || (!w->isFullscreen() && w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) continue; - if (pWindow->m_pMonitor == w->m_pMonitor && pWindow->m_pWorkspace != w->m_pWorkspace) + if (pWorkspace->m_pMonitor == w->m_pMonitor && pWorkspace != w->m_pWorkspace) continue; - if (PWORKSPACE->m_bHasFullscreenWindow && !w->isFullscreen() && !w->m_bCreatedOverFullscreen) + if (pWorkspace->m_bHasFullscreenWindow && !w->isFullscreen() && !w->m_bCreatedOverFullscreen) continue; - if (!*PMONITORFALLBACK && pWindow->m_pMonitor != w->m_pMonitor) + if (!*PMONITORFALLBACK && pWorkspace->m_pMonitor != w->m_pMonitor) continue; const auto BWINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); @@ -1557,9 +1561,6 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { } } } else { - // for floating windows, we calculate best distance and angle. - // if there is a window with angle better than THRESHOLD, only distance counts - if (dir == 'u') dir = 't'; if (dir == 'd') @@ -1578,20 +1579,20 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { constexpr float THRESHOLD = 0.3 * M_PI; for (auto const& w : m_vWindows) { - if (w == pWindow || !w->m_bIsMapped || !w->m_pWorkspace || w->isHidden() || (!w->isFullscreen() && !w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) + if (w == ignoreWindow || !w->m_bIsMapped || !w->m_pWorkspace || w->isHidden() || (!w->isFullscreen() && !w->m_bIsFloating) || !w->m_pWorkspace->isVisible()) continue; - if (pWindow->m_pMonitor == w->m_pMonitor && pWindow->m_pWorkspace != w->m_pWorkspace) + if (pWorkspace->m_pMonitor == w->m_pMonitor && pWorkspace != w->m_pWorkspace) continue; - if (PWORKSPACE->m_bHasFullscreenWindow && !w->isFullscreen() && !w->m_bCreatedOverFullscreen) + if (pWorkspace->m_bHasFullscreenWindow && !w->isFullscreen() && !w->m_bCreatedOverFullscreen) continue; - if (!*PMONITORFALLBACK && pWindow->m_pMonitor != w->m_pMonitor) + if (!*PMONITORFALLBACK && pWorkspace->m_pMonitor != w->m_pMonitor) continue; - const auto DIST = w->middle().distance(pWindow->middle()); - const auto ANGLE = vectorAngles(Vector2D{w->middle() - pWindow->middle()}, VECTORS.at(dir)); + const auto DIST = w->middle().distance(box.middle()); + const auto ANGLE = vectorAngles(Vector2D{w->middle() - box.middle()}, VECTORS.at(dir)); if (ANGLE > M_PI_2) continue; // if the angle is over 90 degrees, ignore. Wrong direction entirely. @@ -1603,8 +1604,8 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) { } } - if (!leaderWindow && PWORKSPACE->m_bHasFullscreenWindow) - leaderWindow = PWORKSPACE->getFullscreenWindow(); + if (!leaderWindow && pWorkspace->m_bHasFullscreenWindow) + leaderWindow = pWorkspace->getFullscreenWindow(); } if (leaderValue != -1) -- cgit v1.2.3