2e3583343f109ec2f2644ab6cdfa69b82456b0d5

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

Message

Merge remote-tracking branch 'andresilva/autotile-workspaces'

Diff

  1diff --git a/README.md b/README.md
  2index 07941e9950a0ba9fb5741c97ae6dfb7457cd97c5..13f708d46bea083c0bd902f5f3ee10042537e67e 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -226,6 +226,12 @@ plugin {
  6       # 0 = always automatically split horizontally
  7       # <number> = pixel height to split at
  8       trigger_height = <int> # default: 0
  9+     
 10+      # a space or comma separated list of workspace ids where autotile should be enabled
 11+      # it's possible to create an exception rule by prefixing the definition with "not:"
 12+      # workspaces = 1,2 # autotiling will only be enabled on workspaces 1 and 2
 13+      # workspaces = not:1,2 # autotiling will be enabled on all workspaces except 1 and 2
 14+      workspaces = <string> # default: all
 15     }
 16   }
 17 }
 18diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 19index 6afa1b1e24433e69ad8dd13e46cd3bd85ab1cffb..7da1d2fbb65edc1b74bbd340c2f7cbfa2afa6824 100644
 20--- a/src/Hy3Layout.cpp
 21+++ b/src/Hy3Layout.cpp
 22@@ -1,5 +1,7 @@
 23 #include <hyprland/src/Compositor.hpp>
 24 #include <hyprland/src/plugins/PluginAPI.hpp>
 25+#include <regex>
 26+#include <set>
 27 
 28 #include "globals.hpp"
 29 #include "Hy3Layout.hpp"
 30@@ -165,9 +167,12 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) {
 31 		static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue;
 32 		// clang-format on
 33 
 34+		this->updateAutotileWorkspaces();
 35+
 36 		auto& target_group = opening_into->data.as_group;
 37 		if (*at_enable && opening_after != nullptr && target_group.children.size() > 1
 38-		    && target_group.layout != Hy3GroupLayout::Tabbed)
 39+		    && target_group.layout != Hy3GroupLayout::Tabbed
 40+		    && this->shouldAutotileWorkspace(opening_into->workspace_id))
 41 		{
 42 			auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH;
 43 			auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height;
 44@@ -1714,3 +1719,51 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
 45 
 46 	return nullptr;
 47 }
 48+
 49+void Hy3Layout::updateAutotileWorkspaces() {
 50+	static const auto* autotile_raw_workspaces
 51+	    = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue;
 52+
 53+	if (*autotile_raw_workspaces == this->autotile.raw_workspaces) {
 54+		return;
 55+	}
 56+
 57+	this->autotile.raw_workspaces = *autotile_raw_workspaces;
 58+	this->autotile.workspaces.clear();
 59+
 60+	if (this->autotile.raw_workspaces == "all") {
 61+		return;
 62+	}
 63+
 64+	this->autotile.workspace_blacklist = this->autotile.raw_workspaces.rfind("not:", 0) == 0;
 65+
 66+	const auto autotile_raw_workspaces_filtered = (this->autotile.workspace_blacklist)
 67+	                                                ? this->autotile.raw_workspaces.substr(4)
 68+	                                                : this->autotile.raw_workspaces;
 69+
 70+	// split on space and comma
 71+	const std::regex regex {R"([\s,]+)"};
 72+	const auto begin = std::sregex_token_iterator(
 73+	    autotile_raw_workspaces_filtered.begin(),
 74+	    autotile_raw_workspaces_filtered.end(),
 75+	    regex,
 76+	    -1
 77+	);
 78+	const auto end = std::sregex_token_iterator();
 79+
 80+	for (auto s = begin; s != end; ++s) {
 81+		try {
 82+			this->autotile.workspaces.insert(std::stoi(*s));
 83+		} catch (...) {
 84+			hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s);
 85+		}
 86+	}
 87+}
 88+
 89+bool Hy3Layout::shouldAutotileWorkspace(int workspace_id) {
 90+	if (this->autotile.workspace_blacklist) {
 91+		return !this->autotile.workspaces.contains(workspace_id);
 92+	} else {
 93+		return this->autotile.workspaces.empty() || this->autotile.workspaces.contains(workspace_id);
 94+	}
 95+}
 96diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
 97index 885e1b6e730f8d4962a639eb342a4540fe2f4ee0..5aef41af6abf727e060561d9bef1c72aa4388363 100644
 98--- a/src/Hy3Layout.hpp
 99+++ b/src/Hy3Layout.hpp
100@@ -9,6 +9,7 @@ enum class GroupEphemeralityOption {
101 };
102 
103 #include <list>
104+#include <set>
105 
106 #include <hyprland/src/layout/IHyprLayout.hpp>
107 
108@@ -139,5 +140,14 @@ private:
109 	// nullptr. if once is true, only one group will be broken out of / into
110 	Hy3Node* shiftOrGetFocus(Hy3Node&, ShiftDirection, bool shift, bool once, bool visible);
111 
112+	void updateAutotileWorkspaces();
113+	bool shouldAutotileWorkspace(int);
114+
115+	struct {
116+		std::string raw_workspaces;
117+		bool workspace_blacklist;
118+		std::set<int> workspaces;
119+	} autotile;
120+
121 	friend struct Hy3Node;
122 };
123diff --git a/src/main.cpp b/src/main.cpp
124index 5185f2ee1c37791d6510ee109593ecb50edc2808..138ec7f1ae429cb8a099ccf13259e67542abe32e 100644
125--- a/src/main.cpp
126+++ b/src/main.cpp
127@@ -43,6 +43,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
128 	CONF("autotile:ephemeral_groups", int, 1);
129 	CONF("autotile:trigger_height", int, 0);
130 	CONF("autotile:trigger_width", int, 0);
131+	CONF("autotile:workspaces", str, "all");
132 
133 #undef CONF
134