Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions metadata/decoration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@
<max>1.0</max>
<min>0.1</min>
</option>
<option name="title_halign" type="string">
Comment thread
ammen99 marked this conversation as resolved.
<_short>Title horizontal alignment</_short>
<_long>Sets the horizontal alignment of the title text. Valid values are left, center and right.</_long>
<default>left</default>
<desc>
<value>left</value>
<_name>left</_name>
</desc>
<desc>
<value>center</value>
<_name>center</_name>
</desc>
<desc>
<value>right</value>
<_name>right</_name>
</desc>
</option>
<option name="title_valign" type="string">
<_short>Title vertical alignment</_short>
<_long>Sets the vertical alignment of the title text. Valid values are top, center and bottom.</_long>
<default>top</default>
<desc>
<value>top</value>
<_name>top</_name>
</desc>
<desc>
<value>center</value>
<_name>center</_name>
</desc>
<desc>
<value>bottom</value>
<_name>bottom</_name>
</desc>
</option>
<option name="title_height" type="int">
<_short>Title bar height</_short>
<_long>Sets the height of the title bars in pixels.</_long>
Expand Down
37 changes: 37 additions & 0 deletions plugins/decor/deco-theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions plugins/decor/deco-theme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class decoration_theme_t
wf::option_wrapper_t<int> button_padding{"decoration/button_padding"};
wf::option_wrapper_t<wf::color_t> active_color{"decoration/active_color"};
wf::option_wrapper_t<wf::color_t> inactive_color{"decoration/inactive_color"};
wf::option_wrapper_t<std::string> title_halign{"decoration/title_halign"};
wf::option_wrapper_t<std::string> title_valign{"decoration/title_valign"};
};
}
}
Loading