22a65c169c507994827bf15c6fee63a9d5d607a0

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

Message

Add autotiling support

Diff

 1diff --git a/README.md b/README.md
 2index 2191a893a2fff1e15cdb67b110b1023b6999644d..2f62c93944cbf08c6c5a416e9dbcb955cec7c9dc 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -11,6 +11,7 @@ i3 / sway like layout for [hyprland](https://github.com/hyprwm/hyprland).
 6 - [x] i3 like tiling
 7 - [x] Node based window manipulation (you can interact with multiple windows at once)
 8 - [x] Greatly improved tabbed node groups over base hyprland
 9+- [x] Optional autotiling
10 
11 Additional features may be suggested in the repo issues or the [matrix room](https://matrix.to/#/#hy3:outfoxxed.me).
12 
13@@ -184,6 +185,27 @@ plugin {
14       # inactive tab bar text color
15       col.text.inactive = <color>
16     }
17+
18+    # autotiling settings
19+    autotile {
20+      # enable autotile
21+      enable = <bool>
22+
23+      # make autotile-created groups ephemeral
24+      ephemeral_groups = <bool>
25+
26+      # if a window would be squished smaller than this width, a vertical split will be created
27+      # -1 = never automatically split vertically
28+      # 0 = always automatically split vertically
29+      # <number> = pixel height to split at
30+      trigger_width = <int>
31+
32+      # if a window would be squished smaller than this height, a horizontal split will be created
33+      # -1 = never automatically split horizontally
34+      # 0 = always automatically split horizontally
35+      # <number> = pixel height to split at
36+      trigger_height = <int>
37+    }
38   }
39 }
40 ```
41diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
42index 097b11e3a98a756a30c2e0a36a9390e2805a4d03..57a6c3e81e5174df9404badb4e3126a7202ba917 100644
43--- a/src/Hy3Layout.cpp
44+++ b/src/Hy3Layout.cpp
45@@ -154,6 +154,34 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) {
46 		);
47 	}
48 
49+	{
50+		// clang-format off
51+		static const auto* at_enable = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:enable")->intValue;
52+		static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue;
53+		static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue;
54+		static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue;
55+		// clang-format on
56+
57+		auto& target_group = opening_into->data.as_group;
58+		if (*at_enable && opening_after != nullptr && target_group.children.size() > 1
59+		    && target_group.layout != Hy3GroupLayout::Tabbed)
60+		{
61+			auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH;
62+			auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height;
63+			auto target_size = is_horizontal ? opening_into->size.x : opening_into->size.y;
64+			auto size_after_addition = target_size / (target_group.children.size() + 1);
65+
66+			if (trigger >= 0 && (trigger == 0 || size_after_addition < trigger)) {
67+				auto opening_after1 = opening_after->intoGroup(
68+				    is_horizontal ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH,
69+				    *at_ephemeral ? GroupEphemeralityOption::Ephemeral : GroupEphemeralityOption::Standard
70+				);
71+				opening_into = opening_after;
72+				opening_after = opening_after1;
73+			}
74+		}
75+	}
76+
77 	this->nodes.push_back({
78 	    .parent = opening_into,
79 	    .data = window,
80diff --git a/src/main.cpp b/src/main.cpp
81index f493eb54636b6cd087f6d1b493e28d4c62470024..5185f2ee1c37791d6510ee109593ecb50edc2808 100644
82--- a/src/main.cpp
83+++ b/src/main.cpp
84@@ -38,6 +38,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
85 	CONF("tabs:col.text.urgent", int, 0xff000000);
86 	CONF("tabs:col.text.inactive", int, 0xff000000);
87 
88+	// autotiling
89+	CONF("autotile:enable", int, 0);
90+	CONF("autotile:ephemeral_groups", int, 1);
91+	CONF("autotile:trigger_height", int, 0);
92+	CONF("autotile:trigger_width", int, 0);
93+
94 #undef CONF
95 
96 	g_Hy3Layout = std::make_unique<Hy3Layout>();