From: Elias Fleckenstein Date: Tue, 26 Apr 2022 13:20:00 +0000 (+0200) Subject: Initial commit X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=e372536de827f9db01fd4e150f8b5de58839e4aa;p=clockoverlay.git Initial commit --- e372536de827f9db01fd4e150f8b5de58839e4aa 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 +#include +#include +#include +#include +#include +#include +#include +#include + +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}); + } +}