diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index b527cdc..bcf84d0 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include #include "globals.hpp" #include "Hy3Layout.hpp" @@ -16,30 +16,6 @@ std::unique_ptr urgentHookPtr std::unique_ptr tickHookPtr = std::make_unique(Hy3Layout::tickHook); -std::set getAutotileWorkspaces() { - std::set workspaces; - auto at_workspaces = HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue; - - if (at_workspaces == "all") { - return workspaces; - } - - // split on space and comma - const std::regex regex { R"([\s,]+)" }; - const auto begin = std::regex_token_iterator(at_workspaces.begin(), at_workspaces.end(), regex, -1); - const auto end = std::regex_token_iterator(); - - for (auto s = begin; s != end; ++s) { - try { - workspaces.insert(std::stoi(*s)); - } catch (...) { - hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s); - } - } - - return workspaces; -} - bool performContainment(Hy3Node& node, bool contained, CWindow* window) { if (node.data.type == Hy3NodeType::Group) { auto& group = node.data.as_group; @@ -189,13 +165,14 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) { static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue; static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue; static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue; - static const auto at_workspaces = getAutotileWorkspaces(); // clang-format on + this->updateAtWorkspaces(); + auto& target_group = opening_into->data.as_group; if (*at_enable && opening_after != nullptr && target_group.children.size() > 1 - && target_group.layout != Hy3GroupLayout::Tabbed && - (at_workspaces.empty() || at_workspaces.contains(opening_into->workspace_id))) + && target_group.layout != Hy3GroupLayout::Tabbed + && this->shouldAtWorkspace(opening_into->workspace_id)) { auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH; auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height; @@ -1738,3 +1715,41 @@ Hy3Node* Hy3Layout::shiftOrGetFocus( return nullptr; } + +void Hy3Layout::updateAtWorkspaces() { + static const auto* at_raw_workspaces + = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue; + + if (*at_raw_workspaces == this->at_raw_workspaces) { + return; + } + + this->at_raw_workspaces = *at_raw_workspaces; + this->at_workspaces.clear(); + + if (this->at_raw_workspaces == "all") { + return; + } + + // split on space and comma + const std::regex regex {R"([\s,]+)"}; + const auto begin = std::regex_token_iterator( + this->at_raw_workspaces.begin(), + this->at_raw_workspaces.end(), + regex, + -1 + ); + const auto end = std::regex_token_iterator(); + + for (auto s = begin; s != end; ++s) { + try { + this->at_workspaces.insert(std::stoi(*s)); + } catch (...) { + hy3_log(ERR, "autotile:workspaces: invalid workspace id: {}", (std::string) *s); + } + } +} + +bool Hy3Layout::shouldAtWorkspace(int workspace_id) { + return this->at_workspaces.empty() || this->at_workspaces.contains(workspace_id); +} diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index f532f73..f701663 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -9,6 +9,7 @@ enum class GroupEphemeralityOption { }; #include +#include #include @@ -138,5 +139,11 @@ private: // nullptr. if once is true, only one group will be broken out of / into Hy3Node* shiftOrGetFocus(Hy3Node&, ShiftDirection, bool shift, bool once, bool visible); + void updateAtWorkspaces(); + bool shouldAtWorkspace(int); + + std::string at_raw_workspaces; + std::set at_workspaces; + friend struct Hy3Node; };