herbe

[fork] notifications
Log | Files | Refs | README | LICENSE

commit 792444a3319047b9fad97b1a3388439125de0c83
parent ba24eb9d586534730e20629dba675cc6abf2ef72
Author: Samuel Dudik <samuel.dudik@gmail.com>
Date:   Wed, 29 Jul 2020 19:39:15 +0200

Fix text centering

Diffstat:
Mconfig.h | 12++++++------
Mmain.c | 11+++++++----
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/config.h b/config.h @@ -1,16 +1,16 @@ const static char *background_color = "#FFFFFF"; const static char *border_color = "#FF0000"; -const static char *font_style = "Inconsolata:style=Medium:size=13"; +const static char *font_style = "Inconsolata:style=Medium:size=15"; const static char *font_color = "#00FF00"; +const static unsigned short text_padding = 10; -const static unsigned short width = 325; -const static unsigned short height = 50; +const static unsigned short width = 300; const static unsigned short border_size = 5; -const static unsigned short pos_x = 50; -const static unsigned short pos_y = 50; +const static unsigned short pos_x = 30; +const static unsigned short pos_y = 30; enum corners { top_left, top_right, down_right, down_left }; enum corners corner = top_right; -const static short duration = 5; +const static unsigned short duration = 5; diff --git a/main.c b/main.c @@ -36,19 +36,20 @@ int main(int argc, char *argv[]) unsigned short x = pos_x; unsigned short y = pos_y; + int height = font->ascent - font->descent + text_padding * 2; switch (corner) { case down_right: - y = window_height - height + 5; + y = window_height - height - border_size * 2 - pos_y; case top_right: x = window_width - width - border_size * 2 - pos_x; break; case down_left: - y = window_height - height + 5; + y = window_height - height - border_size * 2 - pos_y; } Window window = XCreateWindow( display, root, x, - y, width, font->ascent + 10 + border_size, border_size, + y, width, height, border_size, DefaultDepth(display, screen), CopyFromParent, DefaultVisual(display, screen), CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); @@ -58,7 +59,9 @@ int main(int argc, char *argv[]) XMapWindow(display, window); - XftDrawString8(draw, &color, font, 5, font->ascent + 5, (XftChar8 *)argv[1], strlen(argv[1])); + XftDrawString8(draw, &color, font, text_padding, height - text_padding, (XftChar8 *)argv[1], strlen(argv[1])); + + // TODO free xftcolor XNextEvent(display, &event);