e920cb95e889ca36abdb35f34abc85778e09301c

Author
André Silva <andrerfosilva@gmail.com>
Committer
André Silva <andrerfosilva@gmail.com>
Date

Message

allow restricting workspaces for autotiling

Diff

 1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 2index e7470375895657fcd917a5bb857dec989e3ec0c3..b527cdca26715620fe077d5af048f4d05b6aaeeb 100644
 3--- a/src/Hy3Layout.cpp
 4+++ b/src/Hy3Layout.cpp
 5@@ -1,3 +1,5 @@
 6+#include <regex>
 7+#include <set>
 8 #include <hyprland/src/Compositor.hpp>
 9 #include <hyprland/src/plugins/PluginAPI.hpp>
10 
11@@ -14,6 +16,30 @@ std::unique_ptr<HOOK_CALLBACK_FN> urgentHookPtr
12 std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr
13     = std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook);
14 
15+std::set<int> getAutotileWorkspaces() {
16+	std::set<int> workspaces;
17+	auto at_workspaces = HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue;
18+
19+	if (at_workspaces == "all") {
20+		return workspaces;
21+	}
22+
23+	// split on space and comma
24+	const std::regex regex { R"([\s,]+)" };
25+	const auto begin = std::regex_token_iterator(at_workspaces.begin(), at_workspaces.end(), regex, -1);
26+	const auto end = std::regex_token_iterator<std::string::iterator>();
27+
28+    for (auto s = begin; s != end; ++s) {
29+        try {
30+			workspaces.insert(std::stoi(*s));
31+        } catch (...) {
32+			hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s);
33+        }
34+    }
35+
36+	return workspaces;
37+}
38+
39 bool performContainment(Hy3Node& node, bool contained, CWindow* window) {
40 	if (node.data.type == Hy3NodeType::Group) {
41 		auto& group = node.data.as_group;
42@@ -163,11 +189,13 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) {
43 		static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue;
44 		static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue;
45 		static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue;
46+		static const auto at_workspaces = getAutotileWorkspaces();
47 		// clang-format on
48 
49 		auto& target_group = opening_into->data.as_group;
50 		if (*at_enable && opening_after != nullptr && target_group.children.size() > 1
51-		    && target_group.layout != Hy3GroupLayout::Tabbed)
52+		    && target_group.layout != Hy3GroupLayout::Tabbed &&
53+			(at_workspaces.empty() || at_workspaces.contains(opening_into->workspace_id)))
54 		{
55 			auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH;
56 			auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height;
57diff --git a/src/main.cpp b/src/main.cpp
58index 5185f2ee1c37791d6510ee109593ecb50edc2808..138ec7f1ae429cb8a099ccf13259e67542abe32e 100644
59--- a/src/main.cpp
60+++ b/src/main.cpp
61@@ -43,6 +43,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
62 	CONF("autotile:ephemeral_groups", int, 1);
63 	CONF("autotile:trigger_height", int, 0);
64 	CONF("autotile:trigger_width", int, 0);
65+	CONF("autotile:workspaces", str, "all");
66 
67 #undef CONF
68