Code cleanup
This commit is contained in:
parent
384c1fae6d
commit
5f7cd56600
2 changed files with 31 additions and 29 deletions
11
config.h
11
config.h
|
@ -1,16 +1,15 @@
|
||||||
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_style = "Inconsolata:style=Medium:size=15";
|
|
||||||
const static char *font_color = "#ececec";
|
const static char *font_color = "#ececec";
|
||||||
const static unsigned short text_padding = 10;
|
const static char *font_pattern = "Inconsolata:style=Medium:size=15";
|
||||||
|
const static unsigned short padding = 20;
|
||||||
|
|
||||||
const static unsigned short width = 300;
|
const static unsigned short width = 300;
|
||||||
const static unsigned short border_size = 2;
|
const static unsigned short border_size = 2;
|
||||||
const static unsigned short pos_x = 40;
|
const static unsigned short pos_x = 40;
|
||||||
const static unsigned short pos_y = 50;
|
const static unsigned short pos_y = 50;
|
||||||
|
|
||||||
enum corners { top_left, top_right, down_right, down_left };
|
enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
|
||||||
enum corners corner = top_right;
|
enum corners corner = TOP_RIGHT;
|
||||||
|
|
||||||
const static unsigned short duration = 5;
|
const static unsigned short duration = 5; /* in seconds */
|
49
herbe.c
49
herbe.c
|
@ -20,7 +20,8 @@ void expire()
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
if (argc != 2)
|
||||||
|
{
|
||||||
fprintf(stderr, "Usage: herbe message\n");
|
fprintf(stderr, "Usage: herbe message\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -37,45 +38,47 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
int screen = DefaultScreen(display);
|
int screen = DefaultScreen(display);
|
||||||
|
Visual *visual = DefaultVisual(display, screen);
|
||||||
|
Colormap colormap = DefaultColormap(display, screen);
|
||||||
|
|
||||||
int window_width = DisplayWidth(display, screen);
|
int window_width = DisplayWidth(display, screen);
|
||||||
int window_height = DisplayHeight(display, screen);
|
int window_height = DisplayHeight(display, screen);
|
||||||
|
|
||||||
XftColor color;
|
XftColor color;
|
||||||
|
|
||||||
Window root = RootWindow(display, screen);
|
|
||||||
XSetWindowAttributes attributes;
|
XSetWindowAttributes attributes;
|
||||||
attributes.override_redirect = True;
|
attributes.override_redirect = True;
|
||||||
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), background_color, &color);
|
XftColorAllocName(display, visual, colormap, background_color, &color);
|
||||||
attributes.background_pixel = color.pixel;
|
attributes.background_pixel = color.pixel;
|
||||||
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), border_color, &color);
|
XftColorAllocName(display, visual, colormap, border_color, &color);
|
||||||
attributes.border_pixel = color.pixel;
|
attributes.border_pixel = color.pixel;
|
||||||
|
|
||||||
XftFont *font = XftFontOpenName(display, screen, font_style);
|
XftFont *font = XftFontOpenName(display, screen, font_pattern);
|
||||||
|
|
||||||
unsigned short x = pos_x;
|
unsigned short x = pos_x;
|
||||||
unsigned short y = pos_y;
|
unsigned short y = pos_y;
|
||||||
int height = font->ascent - font->descent + text_padding * 2;
|
unsigned short height = font->ascent - font->descent + padding * 2;
|
||||||
|
|
||||||
switch (corner)
|
switch (corner)
|
||||||
{
|
{
|
||||||
case down_right:
|
case BOTTOM_RIGHT:
|
||||||
y = window_height - height - border_size * 2 - pos_y;
|
y = window_height - height - border_size * 2 - pos_y;
|
||||||
case top_right:
|
case TOP_RIGHT:
|
||||||
x = window_width - width - border_size * 2 - pos_x;
|
x = window_width - width - border_size * 2 - pos_x;
|
||||||
break;
|
break;
|
||||||
case down_left:
|
case BOTTOM_LEFT:
|
||||||
y = window_height - height - border_size * 2 - pos_y;
|
y = window_height - height - border_size * 2 - pos_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = XCreateWindow(
|
window = XCreateWindow(
|
||||||
display, root, x,
|
display, RootWindow(display, screen), x,
|
||||||
y, width, height, border_size,
|
y, width, height, border_size,
|
||||||
DefaultDepth(display, screen), CopyFromParent,
|
DefaultDepth(display, screen), CopyFromParent,
|
||||||
DefaultVisual(display, screen),
|
visual,
|
||||||
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
||||||
|
|
||||||
XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen));
|
XftDraw *draw = XftDrawCreate(display, window, visual, colormap);
|
||||||
XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), font_color, &color);
|
XftColorAllocName(display, visual, colormap, font_color, &color);
|
||||||
|
|
||||||
XSelectInput(display, window, ExposureMask | ButtonPress);
|
XSelectInput(display, window, ExposureMask | ButtonPress);
|
||||||
|
|
||||||
|
@ -90,16 +93,16 @@ int main(int argc, char *argv[])
|
||||||
if (event.type == Expose)
|
if (event.type == Expose)
|
||||||
{
|
{
|
||||||
XClearWindow(display, window);
|
XClearWindow(display, window);
|
||||||
XftDrawStringUtf8(draw, &color, font, text_padding, height - text_padding, (XftChar8 *)argv[1], strlen(argv[1]));
|
XftDrawStringUtf8(draw, &color, font, padding, height - padding, (XftChar8 *)argv[1], strlen(argv[1]));
|
||||||
}
|
}
|
||||||
if (event.type == ButtonPress)
|
if (event.type == ButtonPress)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
XftDrawDestroy(draw);
|
XftDrawDestroy(draw);
|
||||||
XftColorFree(display, DefaultVisual(display, screen), DefaultColormap(display, screen), &color);
|
XftColorFree(display, visual, colormap, &color);
|
||||||
XftFontClose(display, font);
|
XftFontClose(display, font);
|
||||||
|
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue