Progress with multiline/word-wrap support

This commit is contained in:
Samuel Dudik 2020-08-01 12:54:00 +02:00
parent 6a655a7cbd
commit ed9d201bce
3 changed files with 32 additions and 7 deletions

View file

@ -1,10 +1,10 @@
const static char *background_color = "#3e3e3e"; 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=13";
const static unsigned int padding = 15; const static unsigned int padding = 15;
const static unsigned int width = 300; const static unsigned int width = 200;
const static unsigned int border_size = 2; const static unsigned int border_size = 2;
const static unsigned int pos_x = 40; const static unsigned int pos_x = 40;
const static unsigned int pos_y = 50; const static unsigned int pos_y = 50;
@ -12,4 +12,4 @@ const static unsigned int pos_y = 50;
enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
enum corners corner = TOP_RIGHT; enum corners corner = TOP_RIGHT;
const static unsigned int duration = 5; /* in seconds */ const static unsigned int duration = 15; /* in seconds */

31
herbe.c
View file

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <math.h>
#include "config.h" #include "config.h"
@ -31,6 +32,16 @@ int get_eol(char *body, XftFont *font)
} }
return --eol; return --eol;
// if (body[eol] == ' ')
// return --eol;
// while (body[eol] != ' ')
// {
// eol--;
// }
// return ++eol;
} }
void expire() void expire()
@ -95,9 +106,13 @@ int main(int argc, char *argv[])
y = window_height - height - border_size * 2 - pos_y; y = window_height - height - border_size * 2 - pos_y;
} }
XGlyphInfo info;
XftTextExtentsUtf8(display, font, body, strlen(body), &info);
int num_of_lines = ceil((float)info.width / (width - 2 * padding));
window = XCreateWindow( window = XCreateWindow(
display, RootWindow(display, screen), x, display, RootWindow(display, screen), x,
y, width, height, border_size, y, width, (num_of_lines - 1) * 5 + num_of_lines * (font->ascent - font->descent) + 2 * padding, border_size,
DefaultDepth(display, screen), CopyFromParent, DefaultDepth(display, screen), CopyFromParent,
visual, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
@ -109,7 +124,13 @@ int main(int argc, char *argv[])
XMapWindow(display, window); XMapWindow(display, window);
int eol = get_eol(body, font); int eols[num_of_lines + 1];
eols[0] = 0;
for (int i = 1; i < num_of_lines + 1; i++)
{
eols[i] = eols[i - 1] + get_eol(body + eols[i - 1], font);
}
XEvent event; XEvent event;
@ -120,7 +141,11 @@ 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, body, eol);
for (int i = 1; i < num_of_lines + 1; i++)
{
XftDrawStringUtf8(draw, &color, font, padding, 5 * (i - 1) + (font->ascent - font->descent) * i + padding, body + eols[i - 1], eols[i] - eols[i - 1]);
}
} }
if (event.type == ButtonPress) if (event.type == ButtonPress)
break; break;

View file

@ -1,5 +1,5 @@
default: default:
gcc herbe.c -lX11 -lXft -I/usr/include/freetype2 -o herbe gcc herbe.c -lX11 -lXft -I/usr/include/freetype2 -lm -o herbe
install: default install: default
cp herbe /usr/local/bin cp herbe /usr/local/bin