herbe

git clone git://mattcarlson.org/repos/herbe.git
Log | Files | Refs

commit e17d37b371f5aa89fb172781a14193a49392d984
parent caf58caa5da948e97030121d3c4c24b95c338c48
Author: Matthew Carlson <matt@mcarlson.xyz>
Date:   Sat,  3 Jul 2021 01:45:01 +0000

centertext

Diffstat:
Mherbe.c | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/herbe.c b/herbe.c @@ -122,15 +122,16 @@ int main(int argc, char *argv[]) XftColorAllocName(display, visual, colormap, border_color, &color); attributes.border_pixel = color.pixel; + XftFont *font = XftFontOpenName(display, screen, font_pattern); + int num_of_lines = 0; int max_text_width = width - 2 * padding; + int max_font_width = font->max_advance_width; int lines_size = 5; char **lines = malloc(lines_size * sizeof(char *)); if (!lines) die("malloc failed"); - XftFont *font = XftFontOpenName(display, screen, font_pattern); - for (int i = 1; i < argc; i++) { for (unsigned int eol = get_max_len(argv[i], font, max_text_width); eol; argv[i] += eol, num_of_lines++, eol = get_max_len(argv[i], font, max_text_width)) @@ -188,9 +189,11 @@ int main(int argc, char *argv[]) if (event.type == Expose) { XClearWindow(display, window); - for (int i = 0; i < num_of_lines; i++) - XftDrawStringUtf8(draw, &color, font, padding, line_spacing * i + text_height * (i + 1) + padding, - (FcChar8 *)lines[i], strlen(lines[i])); + for (int i = 0; i < num_of_lines; i++){ + int len = strlen(lines[i]); + XftDrawStringUtf8(draw, &color, font, (width - len*max_font_width)/2, line_spacing * i + text_height * (i + 1) + padding, + (FcChar8 *)lines[i], len); + } } else if (event.type == ButtonPress) { @@ -217,4 +220,4 @@ int main(int argc, char *argv[]) XCloseDisplay(display); return exit_code; -} -\ No newline at end of file +}