Small refactoring
This commit is contained in:
parent
025055056c
commit
e81696c2d3
3 changed files with 19 additions and 24 deletions
22
config.h
22
config.h
|
@ -1,16 +1,16 @@
|
||||||
const static char *background_color = "#3e3e3e";
|
static const char *background_color = "#3e3e3e";
|
||||||
const static char *border_color = "#ececec";
|
static const char *border_color = "#ececec";
|
||||||
const static char *font_color = "#ececec";
|
static const char *font_color = "#ececec";
|
||||||
const static char *font_pattern = "Inconsolata:style=Medium:size=13";
|
static const char *font_pattern = "Inconsolata:style=Medium:size=13";
|
||||||
const static unsigned line_spacing = 5;
|
static const unsigned line_spacing = 5;
|
||||||
const static unsigned int padding = 15;
|
static const unsigned int padding = 15;
|
||||||
|
|
||||||
const static unsigned int width = 400;
|
static const unsigned int width = 400;
|
||||||
const static unsigned int border_size = 2;
|
static const unsigned int border_size = 2;
|
||||||
const static unsigned int pos_x = 30;
|
static const unsigned int pos_x = 30;
|
||||||
const static unsigned int pos_y = 50;
|
static const 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 */
|
static const unsigned int duration = 15; /* in seconds */
|
||||||
|
|
15
herbe.c
15
herbe.c
|
@ -72,7 +72,7 @@ int main(int argc, char *argv[])
|
||||||
while (info.width < max_text_width)
|
while (info.width < max_text_width)
|
||||||
{
|
{
|
||||||
eol++;
|
eol++;
|
||||||
XftTextExtentsUtf8(display, font, body + eols[num_of_lines - 1], eol, &info);
|
XftTextExtentsUtf8(display, font, (FcChar8 *)body + eols[num_of_lines - 1], eol, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
--eol;
|
--eol;
|
||||||
|
@ -114,16 +114,11 @@ int main(int argc, char *argv[])
|
||||||
unsigned int text_height = font->ascent - font->descent;
|
unsigned int text_height = font->ascent - font->descent;
|
||||||
unsigned int height = (num_of_lines - 2) * line_spacing + (num_of_lines - 1) * text_height + 2 * padding;
|
unsigned int height = (num_of_lines - 2) * line_spacing + (num_of_lines - 1) * text_height + 2 * padding;
|
||||||
|
|
||||||
switch (corner)
|
if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
|
||||||
{
|
|
||||||
case BOTTOM_RIGHT:
|
|
||||||
y = screen_height - height - border_size * 2 - pos_y;
|
|
||||||
case TOP_RIGHT:
|
|
||||||
x = screen_width - width - border_size * 2 - pos_x;
|
x = screen_width - width - border_size * 2 - pos_x;
|
||||||
break;
|
|
||||||
case BOTTOM_LEFT:
|
if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
|
||||||
y = screen_height - height - border_size * 2 - pos_y;
|
y = screen_height - height - border_size * 2 - pos_y;
|
||||||
}
|
|
||||||
|
|
||||||
window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen), CopyFromParent, visual,
|
window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen), CopyFromParent, visual,
|
||||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
||||||
|
@ -145,7 +140,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
XClearWindow(display, window);
|
XClearWindow(display, window);
|
||||||
for (int i = 1; i < num_of_lines; i++)
|
for (int i = 1; i < num_of_lines; i++)
|
||||||
XftDrawStringUtf8(draw, &color, font, padding, line_spacing * (i - 1) + text_height * i + padding, body + eols[i - 1], eols[i] - eols[i - 1]);
|
XftDrawStringUtf8(draw, &color, font, padding, line_spacing * (i - 1) + text_height * i + padding, (FcChar8 *)body + eols[i - 1], eols[i] - eols[i - 1]);
|
||||||
}
|
}
|
||||||
if (event.type == ButtonPress)
|
if (event.type == ButtonPress)
|
||||||
break;
|
break;
|
||||||
|
|
2
makefile
2
makefile
|
@ -1,5 +1,5 @@
|
||||||
default:
|
default:
|
||||||
gcc herbe.c -lX11 -lXft -I/usr/include/freetype2 -lm -o herbe
|
gcc herbe.c -Wall -Wextra -Werror -pedantic -lX11 -lXft -I/usr/include/freetype2 -lm -o herbe
|
||||||
|
|
||||||
install: default
|
install: default
|
||||||
cp herbe /usr/local/bin
|
cp herbe /usr/local/bin
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue