New lines are now printed properly
This commit is contained in:
parent
30b0961b2e
commit
b41b280509
2 changed files with 24 additions and 15 deletions
5
TODO.md
5
TODO.md
|
@ -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
34
herbe.c
|
@ -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);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue