sxalert

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

commit 20bfa34182ff7b13e7124600c290d40d9387b2ff
parent e96eb29bf79df48bb4c1d1dbfb75bbbcc8eec9be
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date:   Sat,  4 Nov 2023 16:59:50 +0000

Added timeout with proper rendering

Diffstat:
MMakefile | 2+-
Mconfig.h | 8+++++---
Msxalert.c | 41+++++++++++++++++++++++++++++++----------
3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,2 +1,2 @@ sxalert: - gcc sxalert.c -I/usr/include/freetype2/ -lXft -lX11 -lfreetype + c99 sxalert.c -I/usr/include/freetype2/ -lXft -lX11 -lfreetype diff --git a/config.h b/config.h @@ -2,11 +2,13 @@ #define BUFFER 2054 +static int duration = 4000; /* in milliseconds */ + /* default appearance */ -static char text_color[7] = "FFFFFF"; -static char bg_color[7] = "090909"; -static char border_color[7] = "CCCCCC"; +static char text_color[7] = "e1ba9b"; +static char bg_color[7] = "081019"; +static char border_color[7] = "e1ba9b"; static int border_width = 1; static int text_x_padding = 10; diff --git a/sxalert.c b/sxalert.c @@ -1,16 +1,26 @@ +/* simpleXalert v0.1 + * Simple notification program for X + * GNU GPL v3.0 + * + * sxalert.c - main program + */ + #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> +#include <getopt.h> +#include <time.h> +#include <poll.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xft/Xft.h> -#define VERSION "v0.1" - #include "config.h" +#define VERSION "v0.1" + static void die(const char *msg, int code) { @@ -90,18 +100,29 @@ draw(int border, char **lines, int linecount, int linestart) XftDraw *draw = XftDrawCreate(dpy, win, visual, cmap); - while(1) { /* TODO: add timer & click to exit functionality */ - XEvent ev; + while (1) { + struct pollfd pfd = { + .fd = ConnectionNumber(dpy), + .events = POLLIN, + }; + Bool pending = XPending(dpy) > 0 || poll(&pfd, 1, duration) > 0; + + if (!pending) + break; + 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, text_x_padding, spacing, (XftChar8 *)lines[i], strlen(lines[i])); - spacing += text_height * 2; + int spacing = text_height * 2; + for (int i = linestart; i < linecount; i++) { + XftDrawStringUtf8(draw, &color, font, text_x_padding, spacing, (XftChar8 *)lines[i], strlen(lines[i])); + spacing += text_height * 2; } - } else if (ev.type == KeyPress) { - break; + } else if (ev.type == ButtonPress) { //&& ev.xbutton.button == 1) { + printf("Event: mouse xbutton.butotn = 1\n LEFT CLICK\n"); + break; // Exit the loop if a key is pressed } }