Fix text centering

This commit is contained in:
Samuel Dudik 2020-07-29 19:39:15 +02:00
parent ba24eb9d58
commit 792444a331
2 changed files with 13 additions and 10 deletions

View file

@ -1,16 +1,16 @@
const static char *background_color = "#FFFFFF"; const static char *background_color = "#FFFFFF";
const static char *border_color = "#FF0000"; 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 char *font_color = "#00FF00";
const static unsigned short text_padding = 10;
const static unsigned short width = 325; const static unsigned short width = 300;
const static unsigned short height = 50;
const static unsigned short border_size = 5; const static unsigned short border_size = 5;
const static unsigned short pos_x = 50; const static unsigned short pos_x = 30;
const static unsigned short pos_y = 50; const static unsigned short pos_y = 30;
enum corners { top_left, top_right, down_right, down_left }; enum corners { top_left, top_right, down_right, down_left };
enum corners corner = top_right; enum corners corner = top_right;
const static short duration = 5; const static unsigned short duration = 5;

11
main.c
View file

@ -36,19 +36,20 @@ int main(int argc, char *argv[])
unsigned short x = pos_x; unsigned short x = pos_x;
unsigned short y = pos_y; unsigned short y = pos_y;
int height = font->ascent - font->descent + text_padding * 2;
switch (corner) { switch (corner) {
case down_right: case down_right:
y = window_height - height + 5; y = window_height - height - border_size * 2 - pos_y;
case top_right: case top_right:
x = window_width - width - border_size * 2 - pos_x; x = window_width - width - border_size * 2 - pos_x;
break; break;
case down_left: case down_left:
y = window_height - height + 5; y = window_height - height - border_size * 2 - pos_y;
} }
Window window = XCreateWindow( Window window = XCreateWindow(
display, root, x, display, root, x,
y, width, font->ascent + 10 + border_size, border_size, y, width, height, border_size,
DefaultDepth(display, screen), CopyFromParent, DefaultDepth(display, screen), CopyFromParent,
DefaultVisual(display, screen), DefaultVisual(display, screen),
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
@ -58,7 +59,9 @@ int main(int argc, char *argv[])
XMapWindow(display, window); 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); XNextEvent(display, &event);