diff --git a/metadata/decoration.xml b/metadata/decoration.xml index a72a4f1d7..7a5f02457 100644 --- a/metadata/decoration.xml +++ b/metadata/decoration.xml @@ -21,6 +21,40 @@ 1.0 0.1 + + <_short>Title horizontal alignment + <_long>Sets the horizontal alignment of the title text. Valid values are left, center and right. + left + + left + <_name>left + + + center + <_name>center + + + right + <_name>right + + + + <_short>Title vertical alignment + <_long>Sets the vertical alignment of the title text. Valid values are top, center and bottom. + top + + top + <_name>top + + + center + <_name>center + + + bottom + <_name>bottom + + <_short>Title bar height <_long>Sets the height of the title bars in pixels. diff --git a/plugins/decor/deco-theme.cpp b/plugins/decor/deco-theme.cpp index ee20da021..080044085 100644 --- a/plugins/decor/deco-theme.cpp +++ b/plugins/decor/deco-theme.cpp @@ -86,8 +86,45 @@ cairo_surface_t*decoration_theme_t::render_text(std::string text, layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, text.c_str(), text.size()); + + /* Horizontal alignment */ + std::string halign = title_halign; + + if (halign == "center") + { + pango_layout_set_width(layout, width * PANGO_SCALE); + pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); + } else if (halign == "right") + { + pango_layout_set_width(layout, (width - 2) * PANGO_SCALE); + pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); + } else + { + pango_layout_set_width(layout, width * PANGO_SCALE); + pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); + } + + /* Vertical alignment */ + int text_width, text_height; + pango_layout_get_pixel_size(layout, &text_width, &text_height); + + std::string valign = title_valign; + + double y = 0.0; + + if (valign == "center") + { + y = (height - text_height) / 2.0; + } else if (valign == "bottom") + { + y = height - text_height; + } + + cairo_move_to(cr, 0, y); + 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); g_object_unref(layout); cairo_destroy(cr); diff --git a/plugins/decor/deco-theme.hpp b/plugins/decor/deco-theme.hpp index 7fa80d0de..487068aa2 100644 --- a/plugins/decor/deco-theme.hpp +++ b/plugins/decor/deco-theme.hpp @@ -78,6 +78,8 @@ class decoration_theme_t wf::option_wrapper_t button_padding{"decoration/button_padding"}; wf::option_wrapper_t active_color{"decoration/active_color"}; wf::option_wrapper_t inactive_color{"decoration/inactive_color"}; + wf::option_wrapper_t title_halign{"decoration/title_halign"}; + wf::option_wrapper_t title_valign{"decoration/title_valign"}; }; } }