]> git.lizzy.rs Git - clockoverlay.git/commitdiff
Initial commit
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 26 Apr 2022 13:20:00 +0000 (15:20 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 26 Apr 2022 13:20:00 +0000 (15:20 +0200)
Makefile [new file with mode: 0644]
clockoverlay.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..88eadbe
--- /dev/null
@@ -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});
+       }
+}