a small clock for X11 that displays time as pixels
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(harshly) force window managers to ignore us and not show a border or any other decorations

subscribe to expose events and force a redraw if we were just
exposed; needed after coming back from xlock

jcs 51e618f8 240152c0

+24 -7
+24 -7
pixelclock.c
··· 1 1 /* vim:ts=8 2 - * $Id: pixelclock.c,v 1.3 2005/06/28 22:05:56 jcs Exp $ 2 + * $Id: pixelclock.c,v 1.4 2005/06/29 03:19:42 jcs Exp $ 3 3 * 4 4 * pixelclock 5 5 * a different way of looking at time ··· 92 92 time_t now; 93 93 struct tm *t; 94 94 95 + XEvent event; 96 + 95 97 bzero(&x, sizeof(struct xinfo)); 96 98 97 99 x.width = DEFWIDTH; ··· 124 126 hourtick = x.dpy_height / 24; 125 127 126 128 for (;;) { 127 - if (gettimeofday(&tv[0], NULL)) 129 + if (gettimeofday(&tv[0], NULL)) 128 130 errx(1, "gettimeofday"); 129 131 /* NOTREACHED */ 130 132 ··· 136 138 newpos = (hourtick * t->tm_hour) + 137 139 (float)(((float)t->tm_min / 60.0) * hourtick) - 3; 138 140 139 - if (newpos != lastpos) { 141 + /* check if we just got exposed */ 142 + bzero(&event, sizeof(XEvent)); 143 + XCheckWindowEvent(x.dpy, x.win, ExposureMask, &event); 144 + 145 + /* only redraw if our time changed enough to move the box or if 146 + * we were just exposed */ 147 + if ((newpos != lastpos) || (event.type == Expose)) { 140 148 XClearWindow(x.dpy, x.win); 141 149 142 150 XSetForeground(x.dpy, x.gc, getcolor("yellow")); ··· 181 189 { 182 190 int rc; 183 191 XGCValues values; 192 + XSetWindowAttributes attributes; 184 193 XTextProperty win_name_prop; 185 194 186 195 if (!(x.dpy = XOpenDisplay(display))) ··· 201 210 BlackPixel(x.dpy, x.screen), 202 211 BlackPixel(x.dpy, x.screen)); 203 212 204 - if (!(x.gc = XCreateGC(x.dpy, x.win, 0, &values))) 205 - errx(1, "XCreateGC"); 206 - /* NOTREACHED */ 207 - 208 213 if (!(rc = XStringListToTextProperty(&win_name, 1, &win_name_prop))) 209 214 errx(1, "XStringListToTextProperty"); 210 215 /* NOTREACHED */ 211 216 212 217 XSetWMName(x.dpy, x.win, &win_name_prop); 213 218 219 + /* remove all window manager decorations and force our position/size */ 220 + /* XXX: apparently this is not very nice */ 221 + attributes.override_redirect = True; 222 + XChangeWindowAttributes(x.dpy, x.win, CWOverrideRedirect, &attributes); 223 + 224 + if (!(x.gc = XCreateGC(x.dpy, x.win, 0, &values))) 225 + errx(1, "XCreateGC"); 226 + /* NOTREACHED */ 227 + 214 228 XMapWindow(x.dpy, x.win); 229 + 230 + /* we want to know when we're exposed */ 231 + XSelectInput(x.dpy, x.win, ExposureMask); 215 232 216 233 XFlush(x.dpy); 217 234 XSync(x.dpy, False);