const static char *border_color = "#ececec";
const static char *font_color = "#ececec";
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 border_size = 2;
Display *display;
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()
{
XEvent event;
exit(EXIT_FAILURE);
}
+ char *body = argv[1];
+
signal(SIGALRM, expire);
alarm(duration);
XMapWindow(display, window);
+ int eol = get_eol(body, font);
+
XEvent event;
while (1)
if (event.type == Expose)
{
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)
break;
XCloseDisplay(display);
return EXIT_SUCCESS;
-}
+}
\ No newline at end of file