Text now respects right padding
This commit is contained in:
parent
5035afe94f
commit
6a655a7cbd
2 changed files with 30 additions and 3 deletions
2
config.h
2
config.h
|
@ -2,7 +2,7 @@ const static char *background_color = "#3e3e3e";
|
||||||
const static char *border_color = "#ececec";
|
const static char *border_color = "#ececec";
|
||||||
const static char *font_color = "#ececec";
|
const static char *font_color = "#ececec";
|
||||||
const static char *font_pattern = "Inconsolata:style=Medium:size=15";
|
const static char *font_pattern = "Inconsolata:style=Medium:size=15";
|
||||||
const static unsigned int padding = 20;
|
const static unsigned int padding = 15;
|
||||||
|
|
||||||
const static unsigned int width = 300;
|
const static unsigned int width = 300;
|
||||||
const static unsigned int border_size = 2;
|
const static unsigned int border_size = 2;
|
||||||
|
|
31
herbe.c
31
herbe.c
|
@ -10,6 +10,29 @@
|
||||||
Display *display;
|
Display *display;
|
||||||
Window window;
|
Window window;
|
||||||
|
|
||||||
|
int get_eol(char *body, XftFont *font)
|
||||||
|
{
|
||||||
|
int body_len = strlen(body);
|
||||||
|
XGlyphInfo info;
|
||||||
|
XftTextExtentsUtf8(display, font, body, body_len, &info);
|
||||||
|
|
||||||
|
int max_text_width = width - 2 * padding;
|
||||||
|
|
||||||
|
if (info.width < max_text_width)
|
||||||
|
return body_len;
|
||||||
|
|
||||||
|
int eol = max_text_width / font->max_advance_width;
|
||||||
|
info.width = 0;
|
||||||
|
|
||||||
|
while (info.width < max_text_width)
|
||||||
|
{
|
||||||
|
eol++;
|
||||||
|
XftTextExtentsUtf8(display, font, body, eol, &info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return --eol;
|
||||||
|
}
|
||||||
|
|
||||||
void expire()
|
void expire()
|
||||||
{
|
{
|
||||||
XEvent event;
|
XEvent event;
|
||||||
|
@ -26,6 +49,8 @@ int main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *body = argv[1];
|
||||||
|
|
||||||
signal(SIGALRM, expire);
|
signal(SIGALRM, expire);
|
||||||
alarm(duration);
|
alarm(duration);
|
||||||
|
|
||||||
|
@ -84,6 +109,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
XMapWindow(display, window);
|
XMapWindow(display, window);
|
||||||
|
|
||||||
|
int eol = get_eol(body, font);
|
||||||
|
|
||||||
XEvent event;
|
XEvent event;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
@ -93,7 +120,7 @@ int main(int argc, char *argv[])
|
||||||
if (event.type == Expose)
|
if (event.type == Expose)
|
||||||
{
|
{
|
||||||
XClearWindow(display, window);
|
XClearWindow(display, window);
|
||||||
XftDrawStringUtf8(draw, &color, font, padding, height - padding, (XftChar8 *)argv[1], strlen(argv[1]));
|
XftDrawStringUtf8(draw, &color, font, padding, height - padding, body, eol);
|
||||||
}
|
}
|
||||||
if (event.type == ButtonPress)
|
if (event.type == ButtonPress)
|
||||||
break;
|
break;
|
||||||
|
@ -105,4 +132,4 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue