b5df8377f68364c25bde1c75c5c12f8e0c89ea45

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

Message

Add `no_gaps_when_only`

Diff

 1diff --git a/README.md b/README.md
 2index 66a11467a3388fc82168f7291bdc11c4ffcb2597..ecf3278a5c287012f9a07840cc08a7db567ab651 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -31,6 +31,16 @@ In your hyprland config replace the following dispatchers:
 6 
 7 You can use `hy3:makegroup` to create a new split.
 8 
 9+### Config fields
10+```conf
11+plugin {
12+  hy3 {
13+    # disable gaps when only one window is onscreen
14+    no_gaps_when_only = <bool>
15+  }
16+}
17+```
18+
19 ### Dispatcher list
20  - `hy3:makegroup, <h | v | opposite>` - make a vertical or horizontal split
21  - `hy3:movefocus, <l | u | d | r | left | down | up | right>` - move the focus left, up, down, or right
22diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
23index 33fc0b619a7c70f67383285a4f0101244ab36d0d..7951730fa6ae53776cf75d61b85084f5ad3516eb 100644
24--- a/src/Hy3Layout.cpp
25+++ b/src/Hy3Layout.cpp
26@@ -480,10 +480,10 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool force) {
27 	const bool display_top    = STICKS(node->position.y, monitor->vecPosition.y + monitor->vecReservedTopLeft.y);
28 	const bool display_bottom = STICKS(node->position.y + node->size.y, monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y);
29 
30-	const auto* border_size = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue;
31-	const auto* gaps_in     = &g_pConfigManager->getConfigValuePtr("general:gaps_in")->intValue;
32-	const auto* gaps_out    = &g_pConfigManager->getConfigValuePtr("general:gaps_out")->intValue;
33-	static auto* const single_window_no_gaps = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only")->intValue;
34+	static const auto* border_size           = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue;
35+	static const auto* gaps_in               = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue;
36+	static const auto* gaps_out              = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue;
37+	static const auto* single_window_no_gaps = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only")->intValue;
38 
39 	if (!g_pCompositor->windowExists(window) || !window->m_bIsMapped) {
40 		Debug::log(ERR, "Node %p holding invalid window %p!!", node, window);
41@@ -498,14 +498,15 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool force) {
42 	auto calcPos = window->m_vPosition + Vector2D(*border_size, *border_size);
43 	auto calcSize = window->m_vSize - Vector2D(2 * *border_size, 2 * *border_size);
44 
45-	const auto workspace_node_count = this->getWorkspaceNodeCount(window->m_iWorkspaceID);
46+	auto root_node = this->getWorkspaceRootGroup(window->m_iWorkspaceID);
47+	auto only_node = root_node->data.as_group.children.size() == 1
48+		&& root_node->data.as_group.children.front()->data.type == Hy3NodeData::Window;
49 
50-	if (*single_window_no_gaps
51-			&& !g_pCompositor->isWorkspaceSpecial(window->m_iWorkspaceID)
52-			&& (workspace_node_count == 1
53-					|| (window->m_bIsFullscreen
54-							&& g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED)))
55-	{
56+	if (!g_pCompositor->isWorkspaceSpecial(window->m_iWorkspaceID)
57+			&& ((*single_window_no_gaps && only_node)
58+					 || (window->m_bIsFullscreen
59+							 && g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_FULL))
60+	) {
61 		window->m_vRealPosition = window->m_vPosition;
62 		window->m_vRealSize = window->m_vSize;
63