allow restricting workspaces for autotiling

This commit is contained in:
André Silva 2023-09-12 23:39:40 +01:00
parent 2680b1933b
commit e920cb95e8
No known key found for this signature in database
GPG key ID: 7C34FA12A023DC55
2 changed files with 30 additions and 1 deletions

View file

@ -1,3 +1,5 @@
#include <regex>
#include <set>
#include <hyprland/src/Compositor.hpp> #include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp> #include <hyprland/src/plugins/PluginAPI.hpp>
@ -14,6 +16,30 @@ std::unique_ptr<HOOK_CALLBACK_FN> urgentHookPtr
std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr
= std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook); = std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook);
std::set<int> getAutotileWorkspaces() {
std::set<int> 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<std::string::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) { bool performContainment(Hy3Node& node, bool contained, CWindow* window) {
if (node.data.type == Hy3NodeType::Group) { if (node.data.type == Hy3NodeType::Group) {
auto& group = node.data.as_group; auto& group = node.data.as_group;
@ -163,11 +189,13 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) {
static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue; 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_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_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue;
static const auto at_workspaces = getAutotileWorkspaces();
// clang-format on // clang-format on
auto& target_group = opening_into->data.as_group; auto& target_group = opening_into->data.as_group;
if (*at_enable && opening_after != nullptr && target_group.children.size() > 1 if (*at_enable && opening_after != nullptr && target_group.children.size() > 1
&& target_group.layout != Hy3GroupLayout::Tabbed) && target_group.layout != Hy3GroupLayout::Tabbed &&
(at_workspaces.empty() || at_workspaces.contains(opening_into->workspace_id)))
{ {
auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH; auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH;
auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height; auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height;

View file

@ -43,6 +43,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
CONF("autotile:ephemeral_groups", int, 1); CONF("autotile:ephemeral_groups", int, 1);
CONF("autotile:trigger_height", int, 0); CONF("autotile:trigger_height", int, 0);
CONF("autotile:trigger_width", int, 0); CONF("autotile:trigger_width", int, 0);
CONF("autotile:workspaces", str, "all");
#undef CONF #undef CONF