5b91b0e151fa7ec1a3095bf1ada023df3360f8e5
- Author
- André Silva <andrerfosilva@gmail.com>
- Committer
- André Silva <andrerfosilva@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
2index b527cdca26715620fe077d5af048f4d05b6aaeeb..bcf84d0a183490c274b08fc0c6805c7b6205e3ea 100644
3--- a/src/Hy3Layout.cpp
4+++ b/src/Hy3Layout.cpp
5@@ -1,7 +1,7 @@
6-#include <regex>
7-#include <set>
8 #include <hyprland/src/Compositor.hpp>
9 #include <hyprland/src/plugins/PluginAPI.hpp>
10+#include <regex>
11+#include <set>
12
13 #include "globals.hpp"
14 #include "Hy3Layout.hpp"
15@@ -16,30 +16,6 @@ std::unique_ptr<HOOK_CALLBACK_FN> urgentHookPtr
16 std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr
17 = std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook);
18
19-std::set<int> getAutotileWorkspaces() {
20- std::set<int> workspaces;
21- auto at_workspaces = HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue;
22-
23- if (at_workspaces == "all") {
24- return workspaces;
25- }
26-
27- // split on space and comma
28- const std::regex regex { R"([\s,]+)" };
29- const auto begin = std::regex_token_iterator(at_workspaces.begin(), at_workspaces.end(), regex, -1);
30- const auto end = std::regex_token_iterator<std::string::iterator>();
31-
32- for (auto s = begin; s != end; ++s) {
33- try {
34- workspaces.insert(std::stoi(*s));
35- } catch (...) {
36- hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s);
37- }
38- }
39-
40- return workspaces;
41-}
42-
43 bool performContainment(Hy3Node& node, bool contained, CWindow* window) {
44 if (node.data.type == Hy3NodeType::Group) {
45 auto& group = node.data.as_group;
46@@ -189,13 +165,14 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) {
47 static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue;
48 static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue;
49 static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue;
50- static const auto at_workspaces = getAutotileWorkspaces();
51 // clang-format on
52
53+ this->updateAtWorkspaces();
54+
55 auto& target_group = opening_into->data.as_group;
56 if (*at_enable && opening_after != nullptr && target_group.children.size() > 1
57- && target_group.layout != Hy3GroupLayout::Tabbed &&
58- (at_workspaces.empty() || at_workspaces.contains(opening_into->workspace_id)))
59+ && target_group.layout != Hy3GroupLayout::Tabbed
60+ && this->shouldAtWorkspace(opening_into->workspace_id))
61 {
62 auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH;
63 auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height;
64@@ -1738,3 +1715,41 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
65
66 return nullptr;
67 }
68+
69+void Hy3Layout::updateAtWorkspaces() {
70+ static const auto* at_raw_workspaces
71+ = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue;
72+
73+ if (*at_raw_workspaces == this->at_raw_workspaces) {
74+ return;
75+ }
76+
77+ this->at_raw_workspaces = *at_raw_workspaces;
78+ this->at_workspaces.clear();
79+
80+ if (this->at_raw_workspaces == "all") {
81+ return;
82+ }
83+
84+ // split on space and comma
85+ const std::regex regex {R"([\s,]+)"};
86+ const auto begin = std::regex_token_iterator(
87+ this->at_raw_workspaces.begin(),
88+ this->at_raw_workspaces.end(),
89+ regex,
90+ -1
91+ );
92+ const auto end = std::regex_token_iterator<std::string::iterator>();
93+
94+ for (auto s = begin; s != end; ++s) {
95+ try {
96+ this->at_workspaces.insert(std::stoi(*s));
97+ } catch (...) {
98+ hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s);
99+ }
100+ }
101+}
102+
103+bool Hy3Layout::shouldAtWorkspace(int workspace_id) {
104+ return this->at_workspaces.empty() || this->at_workspaces.contains(workspace_id);
105diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
106index f532f739443929fb656501cf02ece88ff77437c7..f7016639aa7bef02b64d842c975e22a04c1643b3 100644
107--- a/src/Hy3Layout.hpp
108+++ b/src/Hy3Layout.hpp
109@@ -9,6 +9,7 @@ enum class GroupEphemeralityOption {
110 };
111
112 #include <list>
113+#include <set>
114
115 #include <hyprland/src/layout/IHyprLayout.hpp>
116
117@@ -138,5 +139,11 @@ private:
118 // nullptr. if once is true, only one group will be broken out of / into
119 Hy3Node* shiftOrGetFocus(Hy3Node&, ShiftDirection, bool shift, bool once, bool visible);
120
121+ void updateAtWorkspaces();
122+ bool shouldAtWorkspace(int);
123+
124+ std::string at_raw_workspaces;
125+ std::set<int> at_workspaces;
126+
127 friend struct Hy3Node;
128 };