diff --git a/README.md b/README.md index 2191a89..2f62c93 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ i3 / sway like layout for [hyprland](https://github.com/hyprwm/hyprland). - [x] i3 like tiling - [x] Node based window manipulation (you can interact with multiple windows at once) - [x] Greatly improved tabbed node groups over base hyprland +- [x] Optional autotiling Additional features may be suggested in the repo issues or the [matrix room](https://matrix.to/#/#hy3:outfoxxed.me). @@ -184,6 +185,27 @@ plugin { # inactive tab bar text color col.text.inactive = } + + # autotiling settings + autotile { + # enable autotile + enable = + + # make autotile-created groups ephemeral + ephemeral_groups = + + # if a window would be squished smaller than this width, a vertical split will be created + # -1 = never automatically split vertically + # 0 = always automatically split vertically + # = pixel height to split at + trigger_width = + + # if a window would be squished smaller than this height, a horizontal split will be created + # -1 = never automatically split horizontally + # 0 = always automatically split horizontally + # = pixel height to split at + trigger_height = + } } } ``` diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 097b11e..57a6c3e 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -154,6 +154,34 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) { ); } + { + // clang-format off + static const auto* at_enable = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:enable")->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_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue; + // clang-format on + + auto& target_group = opening_into->data.as_group; + if (*at_enable && opening_after != nullptr && target_group.children.size() > 1 + && target_group.layout != Hy3GroupLayout::Tabbed) + { + auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH; + auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height; + auto target_size = is_horizontal ? opening_into->size.x : opening_into->size.y; + auto size_after_addition = target_size / (target_group.children.size() + 1); + + if (trigger >= 0 && (trigger == 0 || size_after_addition < trigger)) { + auto opening_after1 = opening_after->intoGroup( + is_horizontal ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH, + *at_ephemeral ? GroupEphemeralityOption::Ephemeral : GroupEphemeralityOption::Standard + ); + opening_into = opening_after; + opening_after = opening_after1; + } + } + } + this->nodes.push_back({ .parent = opening_into, .data = window, diff --git a/src/main.cpp b/src/main.cpp index f493eb5..5185f2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { CONF("tabs:col.text.urgent", int, 0xff000000); CONF("tabs:col.text.inactive", int, 0xff000000); + // autotiling + CONF("autotile:enable", int, 0); + CONF("autotile:ephemeral_groups", int, 1); + CONF("autotile:trigger_height", int, 0); + CONF("autotile:trigger_width", int, 0); + #undef CONF g_Hy3Layout = std::make_unique();