8922749ff033d30d7b67b8adb4f073fa851960b2

Author
Samuel Recker <samuel.recker@gmail.com>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

Add configurable horizontal tab padding

Diff

  1diff --git a/CHANGELOG.md b/CHANGELOG.md
  2index 657330a57f2e938a9937d5bdb612639d67d1b23e..a61dbfb7b1132a1c00ff61bec94d49db6144ce28 100644
  3--- a/CHANGELOG.md
  4+++ b/CHANGELOG.md
  5@@ -1,5 +1,9 @@
  6 # Changelog
  7 
  8+# Upcoming
  9+
 10+- Added configurable horizontal tab padding
 11+
 12 # hl0.56.0.1 and before
 13 
 14 - Fix mouse up+left mouse resize
 15diff --git a/README.md b/README.md
 16index cdde20300b9452470598801b1821cac98bd2ab64..9e1aa1f21cd1ed05895600a76f545df606afab9c 100644
 17--- a/README.md
 18+++ b/README.md
 19@@ -243,8 +243,14 @@ plugin {
 20       # height of the tab bar
 21       height = <int> # default: 22
 22 
 23-      # padding between the tab bar and its focused node
 24-      padding = <int> # default: 6
 25+      # vertical padding between the tab bar and its focused node
 26+      padding = <int> # default: 5
 27+
 28+      # horizontal padding between tabs; -1 uses the value of padding
 29+      padding_horizontal = <int> # default: -1
 30+
 31+      # if horizontal padding should be added at the outer edges of the tab bar
 32+      padding_outer = <bool> # default: true
 33 
 34       # the tab bar should animate in/out from the top instead of below the window
 35       from_top = <bool> # default: false
 36diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp
 37index 617fb5425894af93e8d2d5c1bb05bc15a551ac78..b48480ceb079a0735a6e590bc886947d21e1c224 100644
 38--- a/src/TabGroup.cpp
 39+++ b/src/TabGroup.cpp
 40@@ -13,6 +13,8 @@
 41 #include <hyprland/src/workspace/HLWorkspace.hpp>
 42 #include <hyprland/src/desktop/view/window/WindowPresentation.hpp>
 43 #include <hyprland/src/desktop/view/types/Geometric.hpp>
 44+#include <hyprland/src/desktop/view/window/WindowPresentation.hpp>
 45+#include <hyprland/src/desktop/view/types/Geometric.hpp>
 46 #include <hyprland/src/helpers/Color.hpp>
 47 #include <hyprland/src/animation/AnimationManager.hpp>
 48 #include <hyprland/src/managers/input/InputManager.hpp>
 49@@ -55,6 +57,15 @@ CHyprColor merge_colors(Args... colors) {
 50 	return CHyprColor(Hyprgraphics::CColor(oklab), alpha);
 51 }
 52 
 53+constexpr std::pair<double, double>
 54+tab_entry_geometry(double group_width, double padding, bool outer, double offset, double width) {
 55+	if (outer) return {offset * group_width + padding * 0.5, width * group_width - padding};
 56+	return {offset * (group_width + padding), width * (group_width + padding) - padding};
 57+}
 58+
 59+static_assert(tab_entry_geometry(100, 20, false, 0.0, 0.25) == std::pair {0.0, 10.0});
 60+static_assert(tab_entry_geometry(100, 20, false, 0.75, 0.25) == std::pair {90.0, 10.0});
 61+
 62 Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(&node) {
 63 	auto& mgr = Animation::mgr();
 64 	mgr->createAnimation(
 65@@ -747,6 +758,9 @@ void Hy3TabGroup::renderTabBar(Render::CRenderContext& ctx) {
 66 	static const auto window_rounding = CConfigValue<Config::INTEGER>("decoration:rounding");
 67 	static const auto enter_from_top = CConfigValue<Config::INTEGER>("plugin:hy3:tabs:from_top");
 68 	static const auto padding = CConfigValue<Config::INTEGER>("plugin:hy3:tabs:padding");
 69+	static const auto padding_horizontal =
 70+	    CConfigValue<Config::INTEGER>("plugin:hy3:tabs:padding_horizontal");
 71+	static const auto padding_outer = CConfigValue<Config::INTEGER>("plugin:hy3:tabs:padding_outer");
 72 
 73 	auto [box, scaledBox] = this->getRenderBB(ctx);
 74 
 75@@ -826,15 +840,26 @@ void Hy3TabGroup::renderTabBar(Render::CRenderContext& ctx) {
 76 
 77 	auto fade_opacity = this->bar.fade_opacity->value()
 78 	                  * (valid(this->workspace) ? this->workspace->m_alpha->value() : 1.0);
 79+	auto horizontal_padding = *padding_horizontal < 0 ? *padding : *padding_horizontal;
 80 
 81 	auto render_entry = [&](Hy3TabBarEntry& entry) {
 82+		auto [entry_x, entry_width] = tab_entry_geometry(
 83+		    box.w,
 84+		    horizontal_padding,
 85+		    *padding_outer,
 86+		    entry.offset->value(),
 87+		    entry.width->value()
 88+		);
 89 		Vector2D entry_pos = {
 90-		    (box.x + (entry.offset->value() * box.w) + (*padding * 0.5)) * scale,
 91+		    (box.x + entry_x) * scale,
 92 		    scaledBox.y
 93 		        + ((entry.vertical_pos->value() * (box.h + *padding) * scale)
 94 		           * (*enter_from_top ? -1 : 1)),
 95 		};
 96-		Vector2D entry_size = {((entry.width->value() * box.w) - *padding) * scale, scaledBox.h};
 97+		Vector2D entry_size = {
 98+		    entry_width * scale,
 99+		    scaledBox.h,
100+		};
101 		if (entry_size.x < 0 || entry_size.y < 0 || fade_opacity == 0.0) return;
102 
103 		CBox box = {
104diff --git a/src/main.cpp b/src/main.cpp
105index 91fd96a0198a446bb0a6a39c1f8d2ec9ca4caf91..275dc3dd06aa3222d4297bb7aebd1d3c7273618a 100644
106--- a/src/main.cpp
107+++ b/src/main.cpp
108@@ -42,6 +42,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
109 	// tabs
110 	CONF("tabs:height", Int, 22);
111 	CONF("tabs:padding", Int, 5);
112+	CONF("tabs:padding_horizontal", Int, -1);
113+	CONF("tabs:padding_outer", Bool, true);
114 	CONF("tabs:from_top", Bool, false);
115 	CONF("tabs:radius", Int, 6);
116 	CONF("tabs:border_width", Int, 2);