f71ac3756570abf028a4c9fc5a07b58a09ba5072

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

Use hyprland algorithm to find floating window to focus in direction

Diff

 1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 2index e26a05488103e8130c8da2a064bb393a35f5381e..7182bd8f4a44ea9f92ff3de9fe5a4a208bdd96c8 100644
 3--- a/src/Hy3Layout.cpp
 4+++ b/src/Hy3Layout.cpp
 5@@ -942,38 +942,13 @@ void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible
 6 	if (p_workspace->m_bHasFullscreenWindow) return;
 7 
 8 	if (current_window != nullptr && current_window->m_bIsFloating) {
 9-		CWindow* next_window = nullptr;
10-		double next_distance = -1;
11-
12-		for (auto& w: g_pCompositor->m_vWindows) {
13-			if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2
14-			    && w->m_iWorkspaceID == current_window->m_iWorkspaceID && !w->m_bX11ShouldntFocus
15-			    && !w->m_bNoFocus && w.get() != current_window)
16-			{
17-				double distance = 0;
18-
19-				auto cpos = current_window->m_vRealPosition.vec() + (current_window->m_vRealSize.vec() / 2);
20-				auto tpos = w->m_vRealPosition.vec() + (w->m_vRealSize.vec() / 2);
21-
22-				auto x_offset = tpos.x - cpos.x;
23-				auto y_offset = tpos.y - cpos.y;
24-
25-				if (abs(x_offset) > abs(y_offset)) {
26-					if (x_offset < 0 && direction == ShiftDirection::Left) distance = -x_offset;
27-					else if (x_offset > 0 && direction == ShiftDirection::Right) distance = x_offset;
28-				} else {
29-					if (y_offset < 0 && direction == ShiftDirection::Up) distance = -y_offset;
30-					else if (y_offset > 0 && direction == ShiftDirection::Down) distance = y_offset;
31-				}
32-
33-				if (distance <= 0) continue;
34-
35-				if (next_distance == -1 || distance < next_distance) {
36-					next_window = w.get();
37-					next_distance = distance;
38-				}
39-			}
40-		}
41+		auto* next_window = g_pCompositor->getWindowInDirection(
42+		    current_window,
43+		    direction == ShiftDirection::Left   ? 'l'
44+		    : direction == ShiftDirection::Up   ? 'u'
45+		    : direction == ShiftDirection::Down ? 'd'
46+		                                        : 'r'
47+		);
48 
49 		if (next_window != nullptr) g_pCompositor->focusWindow(next_window);
50 		return;