Skip to content

Decoration plugin: Add title_align option #3103

Description

@froloffw7

Summary

This FR adds customizable text alignment for window titles in the decor (pixman/cairo decoration) plugin, along with the corresponding XML metadata.

Feature added:

title_align: Allows aligning the title bar text (left, center, right).

Current behavior: Title text always aligned left

Benefits

Title text alignment can be changed as required

Configuration Example (wayfire.ini)

[decoration]
title_height = 30
font = JetBrains Mono 10
font_scale = 0.85
title_align = center

How it was tested

  • Verified left, center, and right alignments on various window widths.
--- a/plugins/decor/deco-theme.hpp	2026-07-27 10:26:17.000000000 +0200
+++ b/plugins/decor/deco-theme.hpp	2026-08-06 17:28:50.638747400 +0200
@@ -72,6 +72,7 @@
     wf::option_wrapper_t<std::string> font{"decoration/font"};
     wf::option_wrapper_t<wf::color_t> font_color{"decoration/font_color"};
     wf::option_wrapper_t<int> title_height{"decoration/title_height"};
+    wf::option_wrapper_t<std::string> title_align{"decoration/title_align"};
     wf::option_wrapper_t<int> border_size{"decoration/border_size"};
     wf::option_wrapper_t<double> font_scale{"decoration/font_scale"};
     wf::option_wrapper_t<double> button_scale{"decoration/button_scale"};
--- a/plugins/decor/deco-theme.cppg	2026-07-27 10:26:17.000000000 +0200
+++ b/plugins/decor/deco-theme.cpp	2026-08-06 17:30:20.329837617 +0200
@@ -86,6 +86,31 @@
     layout = pango_cairo_create_layout(cr);
     pango_layout_set_font_description(layout, font_desc);
     pango_layout_set_text(layout, text.c_str(), text.size());
+    // --- ALIGNMENT LOGIC ---
+    int pango_text_width, pango_text_height;
+    pango_layout_get_pixel_size(layout, &pango_text_width, &pango_text_height);
+    // config settings
+    std::string align = (std::string)title_align;
+    double x_offset = 10.0; // "left" alignment default offset
+
+    if (align == "center") 
+    {
+        x_offset = (width - pango_text_width) / 2.0;
+    } 
+    else if (align == "right") 
+    {
+        x_offset = width - pango_text_width - 10.0; // 10px right offset
+    }
+    if (x_offset < 10.0) 
+    {
+        x_offset = 10.0;
+    }
+    cairo_move_to(cr, x_offset, 0);
+    // ---------------------------
     cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
     pango_cairo_show_layout(cr, layout);
     pango_font_description_free(font_desc);
--- a/metadata/decoration.xml	2026-07-27 10:26:17.000000000 +0200
+++ b/metadata/decoration.xml	2026-08-06 17:26:43.752761331 +0200
@@ -28,6 +28,11 @@
 			<max>100</max>
 			<min>0</min>
 		</option>
+		<option name="title_align" type="string">
+			<_short>Title bar text align</_short>
+			<_long>Sets the alignment of the title bars text</_long>
+			<default>left</default>
+		</option>
 		<option name="border_size" type="int">
 			<_short>Border size</_short>
 			<_long>Sets the border size in pixels.</_long>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions