a92314b57a1c611e3e24cfa31c14c4dc3ea638e5

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #54 from Olekoop/master

Add option to center window title

Diff

 1diff --git a/README.md b/README.md
 2index 08671328b643c8cfbe2943e2a19744fed923fc11..24f04f0dca069048250a850e1973e8a46eaa3630 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -201,6 +201,9 @@ plugin {
 6       # render the window title on the bar
 7       render_text = <bool> # default: true
 8 
 9+      # center the window title
10+      text_center = <bool> # default: false
11+
12       # font to render the window title with
13       text_font = <string> # default: Sans
14 
15diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp
16index 217b88e6e9415ea5059b9d6d59e629f6f62f2388..788898497abff53721e9fac5883009cb710caafb 100644
17--- a/src/TabGroup.cpp
18+++ b/src/TabGroup.cpp
19@@ -128,6 +128,7 @@ void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) {
20 	// clang-format off
21 	static const auto* s_rounding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:rounding")->intValue;
22 	static const auto* render_text = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:render_text")->intValue;
23+	static const auto* text_center = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_center")->intValue;
24 	static const auto* text_font = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_font")->strValue;
25 	static const auto* text_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_height")->intValue;
26 	static const auto* text_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_padding")->intValue;
27@@ -224,6 +225,9 @@ void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) {
28 			PangoLayout* layout = pango_cairo_create_layout(cairo);
29 			pango_layout_set_text(layout, this->window_title.c_str(), -1);
30 
31+			if (*text_center)
32+				pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
33+
34 			PangoFontDescription* font_desc = pango_font_description_from_string(text_font->c_str());
35 			pango_font_description_set_size(font_desc, *text_height * scale * PANGO_SCALE);
36 			pango_layout_set_font_description(layout, font_desc);
37diff --git a/src/main.cpp b/src/main.cpp
38index b0820f485937fbf525d5b085ca63bc710ad86766..aebe592e8ce28dee42d210d9d049dbeb62e4ff6e 100644
39--- a/src/main.cpp
40+++ b/src/main.cpp
41@@ -44,6 +44,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
42 	CONF("tabs:from_top", int, 0);
43 	CONF("tabs:rounding", int, 3);
44 	CONF("tabs:render_text", int, 1);
45+	CONF("tabs:text_center", int, 0);
46 	CONF("tabs:text_font", str, "Sans");
47 	CONF("tabs:text_height", int, 8);
48 	CONF("tabs:text_padding", int, 3);