diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-04-26 15:20:00 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-04-26 15:20:00 +0200 |
commit | e372536de827f9db01fd4e150f8b5de58839e4aa (patch) | |
tree | dca7010e387c9b012210bde8480bc0337931c4f5 | |
download | clockoverlay-e372536de827f9db01fd4e150f8b5de58839e4aa.tar.xz |
Initial commit
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | clockoverlay.c | 60 |
2 files changed, 62 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e399d2a --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +clockoverlay: clockoverlay.c + cc clockoverlay.c -o clockoverlay -lX11 diff --git a/clockoverlay.c b/clockoverlay.c new file mode 100644 index 0000000..88eadbe --- /dev/null +++ b/clockoverlay.c @@ -0,0 +1,60 @@ +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/select.h> +#include <time.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +static inline unsigned long _RGB(int r, int g, int b) +{ + return b + (g << 8) + (r << 16); +} + +int main(void) { + Display *display = XOpenDisplay(NULL); + assert(display); + + int fd = ConnectionNumber(display); + + XVisualInfo vinfo; + XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo); + + XSetWindowAttributes attribs; + attribs.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); + attribs.override_redirect = 1; + attribs.border_pixel = 0; + attribs.background_pixel = 0; + + Window window = XCreateWindow(display, DefaultRootWindow(display), 10, 10, 24 / 2 * 8, 24, 0, + vinfo.depth, InputOutput, vinfo.visual, + CWColormap | CWOverrideRedirect | CWBorderPixel | CWBackPixel, &attribs); + XMapWindow(display, window); + + Font font = XLoadFont(display, "*x24"); + + GC ctx = XCreateGC(display, window, 0, NULL); + XSetForeground(display, ctx, _RGB(255, 255, 255)); + XSetFont(display, ctx, font); + + for (;;) { + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + char buf[9]; + strftime(buf, 9, "%H:%M:%S", tm); + XClearWindow(display, window); + XDrawString(display, window, ctx, 0, 24, buf, 8); + + XEvent event; + while (XPending(display)) + XNextEvent(display, &event); + + fd_set set; + FD_ZERO(&set); + FD_SET(fd, &set); + select(fd + 1, &set, NULL, NULL, &(struct timeval) {1, 0}); + } +} |