5 #include <sys/select.h>
11 static inline unsigned long _RGB(int r, int g, int b)
13 return b + (g << 8) + (r << 16);
17 Display *display = XOpenDisplay(NULL);
20 int fd = ConnectionNumber(display);
23 XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo);
25 XSetWindowAttributes attribs;
26 attribs.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone);
27 attribs.override_redirect = 1;
28 attribs.border_pixel = 0;
29 attribs.background_pixel = 0;
31 Window window = XCreateWindow(display, DefaultRootWindow(display), 10, 10, 24 / 2 * 8, 24, 0,
32 vinfo.depth, InputOutput, vinfo.visual,
33 CWColormap | CWOverrideRedirect | CWBorderPixel | CWBackPixel, &attribs);
34 XMapWindow(display, window);
36 Font font = XLoadFont(display, "*x24");
38 GC ctx = XCreateGC(display, window, 0, NULL);
39 XSetForeground(display, ctx, _RGB(255, 255, 255));
40 XSetFont(display, ctx, font);
43 time_t t = time(NULL);
44 struct tm *tm = localtime(&t);
47 strftime(buf, 9, "%H:%M:%S", tm);
48 XClearWindow(display, window);
49 XDrawString(display, window, ctx, 0, 24, buf, 8);
52 while (XPending(display))
53 XNextEvent(display, &event);
58 select(fd + 1, &set, NULL, NULL, &(struct timeval) {1, 0});