sxalert

Simple notification system for X
Log | Files | Refs | README | LICENSE

commit e96eb29bf79df48bb4c1d1dbfb75bbbcc8eec9be
parent 725ae8394ded8df453c53e62a77e503bdc8ed5ae
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date:   Sat,  4 Nov 2023 00:36:43 +0000

Colors as arguments

Diffstat:
Mconfig.h | 9+++++----
Msxalert.c | 20+++++++++++++++-----
2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/config.h b/config.h @@ -4,10 +4,11 @@ /* default appearance */ -static char text_color[7] = "FFBFBF"; -static char bg_color[7] = "300000"; -static char border_color[7] = "530000"; +static char text_color[7] = "FFFFFF"; +static char bg_color[7] = "090909"; +static char border_color[7] = "CCCCCC"; -static int border_width = 5; +static int border_width = 1; +static int text_x_padding = 10; const char *fontname = "DejaVu Sans Mono:size=12:antialias=true"; diff --git a/sxalert.c b/sxalert.c @@ -26,7 +26,7 @@ usage(const char *bin) } static void -help(void) +help(void) /* TODO: update */ { printf("sXalert %s\n", VERSION); printf("Alert utility for X\n\n"); @@ -75,9 +75,10 @@ draw(int border, char **lines, int linecount, int linestart) if (!XftColorAllocName(dpy, visual, cmap, text_color_pnd, &color)) die("Cannot allocate Xft color\n", EXIT_FAILURE); XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[0], strlen(lines[0]), &extents); - int text_height = extents.height; /* int text_width = extents.width; for some reason this is always 61 */ + int text_height = extents.height; /* TODO: int text_width = extents.width; for some reason this is always 61 */ int height = (linecount - linestart) * (text_height * 2) + text_height; + /* TODO: calculate position dynamically */ Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 1500, 50, 400, height, border, hex2int(border_color), hex2int(bg_color)); /* make window fixed */ XSetWindowAttributes attributes; @@ -89,14 +90,14 @@ draw(int border, char **lines, int linecount, int linestart) XftDraw *draw = XftDrawCreate(dpy, win, visual, cmap); - while(1) { + while(1) { /* TODO: add timer & click to exit functionality */ XEvent ev; XNextEvent(dpy, &ev); if (ev.type == Expose) { int spacing = text_height * 2; for (int i=linestart; i<linecount; i++) { - XftDrawStringUtf8(draw, &color, font, 10, spacing, (XftChar8 *)lines[i], strlen(lines[i])); + XftDrawStringUtf8(draw, &color, font, text_x_padding, spacing, (XftChar8 *)lines[i], strlen(lines[i])); spacing += text_height * 2; } } else if (ev.type == KeyPress) { @@ -119,7 +120,7 @@ main(int argc, char **argv) char text[BUFFER]; extern char *optarg; - while ((c = getopt(argc, argv, "s:b:vh")) != -1 ) { + while ((c = getopt(argc, argv, "s:b:t:g:r:vh")) != -1 ) { switch (c) { case 'v': die(VERSION, EXIT_SUCCESS); @@ -132,6 +133,15 @@ main(int argc, char **argv) case 'b': border_width=atoi(optarg); /* overwrite default in config.h */ break; + case 't': + strncpy(text_color, optarg, 7); + break; + case 'g': + strncpy(bg_color, optarg, 7); + break; + case 'r': + strncpy(border_color, optarg, 7); + break; } }