Progress with multiline/word-wrap support
This commit is contained in:
parent
6a655a7cbd
commit
ed9d201bce
3 changed files with 32 additions and 7 deletions
6
config.h
6
config.h
|
@ -1,10 +1,10 @@
|
|||
const static char *background_color = "#3e3e3e";
|
||||
const static char *border_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 width = 300;
|
||||
const static unsigned int width = 200;
|
||||
const static unsigned int border_size = 2;
|
||||
const static unsigned int pos_x = 40;
|
||||
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 corner = TOP_RIGHT;
|
||||
|
||||
const static unsigned int duration = 5; /* in seconds */
|
||||
const static unsigned int duration = 15; /* in seconds */
|
||||
|
|
31
herbe.c
31
herbe.c
|
@ -4,6 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
@ -31,6 +32,16 @@ int get_eol(char *body, XftFont *font)
|
|||
}
|
||||
|
||||
return --eol;
|
||||
|
||||
// if (body[eol] == ' ')
|
||||
// return --eol;
|
||||
|
||||
// while (body[eol] != ' ')
|
||||
// {
|
||||
// eol--;
|
||||
// }
|
||||
|
||||
// return ++eol;
|
||||
}
|
||||
|
||||
void expire()
|
||||
|
@ -95,9 +106,13 @@ int main(int argc, char *argv[])
|
|||
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(
|
||||
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,
|
||||
visual,
|
||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
||||
|
@ -109,7 +124,13 @@ int main(int argc, char *argv[])
|
|||
|
||||
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;
|
||||
|
||||
|
@ -120,7 +141,11 @@ int main(int argc, char *argv[])
|
|||
if (event.type == Expose)
|
||||
{
|
||||
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)
|
||||
break;
|
||||
|
|
2
makefile
2
makefile
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
cp herbe /usr/local/bin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue