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.

allow highlighted hours to be specified on the command line, overriding the default 9am/noon/5pm

originally from marius aamodt eriksen <marius@monkey.org> with some
tweaks from me

update usage() to reflect the new syntax

jcs 9a93c5ab 51e618f8

+53 -21
+53 -21
pixelclock.c
··· 1 1 /* vim:ts=8 2 - * $Id: pixelclock.c,v 1.4 2005/06/29 03:19:42 jcs Exp $ 2 + * $Id: pixelclock.c,v 1.5 2005/07/07 18:07:03 jcs Exp $ 3 3 * 4 4 * pixelclock 5 5 * a different way of looking at time ··· 50 50 /* so our window manager knows us */ 51 51 char* win_name = "pixelclock"; 52 52 53 - /* hours to highlight (start work, lunch, etc.) */ 54 - int hihours[] = { 9, 12, 17 }; 53 + /* default hours to highlight (9am, noon, 5pm) */ 54 + const float defhours[3] = { 9.0, 12.0, 17.0 }; 55 55 56 56 struct xinfo { 57 57 Display* dpy; ··· 86 86 main(int argc, char* argv[]) 87 87 { 88 88 char *display = NULL, *p; 89 - int c, hi, y, z; 89 + int c, i, y; 90 90 int hourtick, lastpos = -1, newpos = 0; 91 91 struct timeval tv[2]; 92 92 time_t now; 93 93 struct tm *t; 94 94 95 + float *hihours; 96 + int nhihours; 97 + 95 98 XEvent event; 96 99 97 100 bzero(&x, sizeof(struct xinfo)); 98 - 99 101 x.width = DEFWIDTH; 100 102 101 103 while ((c = getopt_long_only(argc, argv, "", longopts, NULL)) != -1) { ··· 117 119 } 118 120 } 119 121 122 + argc -= optind; 123 + argv += optind; 124 + 125 + if (argc == 0) { 126 + /* use default times */ 127 + nhihours = sizeof(defhours) / sizeof(defhours[0]); 128 + if ((hihours = alloca(sizeof(defhours))) == NULL) 129 + err(1, NULL); 130 + 131 + for (i = 0; i < nhihours; i++) 132 + hihours[i] = defhours[i]; 133 + } else { 134 + /* get times from args */ 135 + nhihours = argc; 136 + if ((hihours = alloca(nhihours * sizeof(float))) == NULL) 137 + err(1, NULL); 138 + 139 + for (i = 0; i < argc; ++i) { 140 + int h, m; 141 + char *p = argv[i]; 142 + 143 + /* parse times like 14:12 */ 144 + h = atoi(p); 145 + if ((p = strchr(p, ':')) == NULL) 146 + errx(1, "Invalid time %s", argv[i]); 147 + m = atoi(p + 1); 148 + 149 + if (h > 23 || h < 0 || m > 59 || m < 0) 150 + errx(1, "Invalid time %s", argv[i]); 151 + 152 + hihours[i] = h + (m / 60.0); 153 + } 154 + } 155 + 120 156 init_x(display); 121 157 122 158 signal(SIGINT, handler); ··· 147 183 if ((newpos != lastpos) || (event.type == Expose)) { 148 184 XClearWindow(x.dpy, x.win); 149 185 186 + /* draw the current time */ 150 187 XSetForeground(x.dpy, x.gc, getcolor("yellow")); 151 188 XFillRectangle(x.dpy, x.win, x.gc, 152 189 0, newpos, 153 190 x.width, 6); 154 191 155 - /* draw the hour marks */ 192 + /* draw the hour ticks */ 193 + XSetForeground(x.dpy, x.gc, getcolor("blue")); 156 194 for (y = 1; y <= 23; y++) { 157 - hi = 0; 158 - for (z = 0; z < sizeof(&hihours); z++) 159 - if (y == hihours[z]) { 160 - hi = 1; 161 - break; 162 - } 163 - 164 - if (hi) 165 - XSetForeground(x.dpy, x.gc, 166 - getcolor("green")); 167 - else 168 - XSetForeground(x.dpy, x.gc, 169 - getcolor("blue")); 195 + XFillRectangle(x.dpy, x.win, x.gc, 196 + 0, (y * hourtick), 197 + x.width, 2); 198 + } 170 199 200 + /* highlight requested times */ 201 + XSetForeground(x.dpy, x.gc, getcolor("green")); 202 + for (i = 0; i < nhihours; i++) { 171 203 XFillRectangle(x.dpy, x.win, x.gc, 172 - 0, (y * hourtick), 204 + 0, (hihours[i] * hourtick), 173 205 x.width, 2); 174 206 } 175 207 ··· 261 293 usage(void) 262 294 { 263 295 fprintf(stderr, "usage: %s %s\n", __progname, 264 - "[-display host:dpy] [-width]"); 296 + "[-display host:dpy] [-width <pixels>] [time ...]"); 265 297 exit(1); 266 298 }