New lines are now printed properly

This commit is contained in:
Samuel Dudik 2020-08-13 20:45:08 +02:00
parent 30b0961b2e
commit b41b280509
2 changed files with 24 additions and 15 deletions

View file

@ -1,4 +1,5 @@
* Handle multiple notifications at the same time * Handle multiple notifications at the same time
* Properly handle duration = 0 * ~~Properly handle duration = 0~~
* Keyboard shortcut to dismiss and accept notifications (also mouse) * Keyboard shortcut to dismiss and accept notifications (also mouse)
* Properly print new lines * ~~Properly print new lines~~
* Refactor code

34
herbe.c
View file

@ -24,23 +24,31 @@ static void die(const char *format, ...)
int get_max_len(char *body, XftFont *font, int max_text_width) int get_max_len(char *body, XftFont *font, int max_text_width)
{ {
int body_len = strlen(body); int eol = strlen(body);
XGlyphInfo info; XGlyphInfo info;
XftTextExtentsUtf8(display, font, (FcChar8 *)body, body_len, &info); XftTextExtentsUtf8(display, font, (FcChar8 *)body, eol, &info);
if (info.width < max_text_width) 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, (FcChar8 *)body, eol, &info); eol = max_text_width / font->max_advance_width;
info.width = 0;
while (info.width < max_text_width)
{
eol++;
XftTextExtentsUtf8(display, font, (FcChar8 *)body, eol, &info);
}
eol--;
} }
eol--; for (int i = 0; i < eol; i++)
if (body[i] == '\n')
return ++i;
if (info.width < max_text_width)
return eol;
int temp = eol; int temp = eol;
@ -167,4 +175,4 @@ int main(int argc, char *argv[])
XCloseDisplay(display); XCloseDisplay(display);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }