cb9e33299907d6db0d4ad875ad3cb95649ce435f

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

Message

return floating window candidates when no tiled candidate is present

Diff

 1diff --git a/CHANGELOG.md b/CHANGELOG.md
 2index ee95e66cf6545d8bf164f554c97aa8f53bfd0493..de6d08ba34587089e5a6d2075651ade15b421403 100644
 3--- a/CHANGELOG.md
 4+++ b/CHANGELOG.md
 5@@ -7,6 +7,7 @@
 6 - Improved performance of tab bars
 7 - Tab bars now use windowsMove for all animations
 8 - Fixed tab bars rendering in the wrong workspace
 9+- Floating windows will now be focused when all tiled windows are closed
10 
11 # hl0.43.0 and before
12 
13diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
14index da41daaa83adb7fd508eddb3aad304000ce83958..f27ff3a6354aec7dc59950c5ad24bff8fe917956 100644
15--- a/src/Hy3Layout.cpp
16+++ b/src/Hy3Layout.cpp
17@@ -618,8 +618,10 @@ PHLWINDOW Hy3Layout::getNextWindowCandidate(PHLWINDOW window) {
18 		return g_pCompositor->getFullscreenWindowOnWorkspace(window->m_pWorkspace->m_iID);
19 	}
20 
21-	// return the first floating window on the same workspace that has not asked not to be focused
22-	if (window->m_bIsFloating) {
23+	PHLWINDOW selection;
24+
25+	auto findFloating = [&]() {
26+		// return the first floating window on the same workspace that has not asked not to be focused
27 		for (auto& w: g_pCompositor->m_vWindows | std::views::reverse) {
28 			if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && !w->isX11OverrideRedirect()
29 			    && w->m_pWorkspace == window->m_pWorkspace && !w->m_bX11ShouldntFocus
30@@ -628,15 +630,25 @@ PHLWINDOW Hy3Layout::getNextWindowCandidate(PHLWINDOW window) {
31 				return w;
32 			}
33 		}
34-	}
35 
36-	auto* node = this->getWorkspaceFocusedNode(window->m_pWorkspace, true);
37-	if (node == nullptr) return nullptr;
38+		return PHLWINDOW();
39+	};
40 
41-	if (node->data.is_window()) {
42-		return node->data.as_window();
43+	auto findTiled = [&]() {
44+		auto* node = this->getWorkspaceFocusedNode(window->m_pWorkspace, true);
45+		if (node != nullptr && node->data.is_window()) {
46+			return node->data.as_window();
47+		}
48+
49+		return PHLWINDOW();
50+	};
51+
52+	if (window->m_bIsFloating) {
53+		if (auto floating = findFloating()) return floating;
54+		return findTiled();
55 	} else {
56-		return nullptr;
57+		if (auto tiled = findTiled()) return tiled;
58+		return findFloating();
59 	}
60 }
61