Calendar/time for progman

Add an -f flag to specify the strftime format for the icon title

+24 -8
+9 -2
xcalicon.1
··· 7 7 .Sh SYNOPSIS 8 8 .Nm 9 9 .Op Fl d Ar display 10 + .Op Fl f Ar format 10 11 .Sh DESCRIPTION 11 12 .Nm 12 13 shows the current date as an icon, and the time as the icon's title. 13 14 Un-iconifying the program shows the same icon in a small window. 14 15 .Sh OPTIONS 15 16 .Bl -tag -width Ds 16 - .It Fl d 17 - Use a different X11 display. 17 + .It Fl d Ar display 18 + Use a different X11 display named 19 + .Ar display . 20 + .It Fl f Ar format 21 + Use a custom 22 + .Fn strftime 3 23 + format string instead of the default 24 + .Fa "%a %H:%M" . 18 25 .El 19 26 .Sh AUTHORS 20 27 .Nm
+15 -6
xcalicon.c
··· 46 46 Pixmap digits_pm_mask; 47 47 XpmAttributes digits_pm_attrs; 48 48 Pixmap icon_pm; 49 + char *title_fmt; 49 50 } xinfo = { 0 }; 50 51 51 52 extern char *__progname; ··· 58 59 int last_day = 0; 59 60 int last_min = -1; 60 61 61 - #define WINDOW_WIDTH 200 62 - #define WINDOW_HEIGHT 100 62 + #define WINDOW_WIDTH 200 63 + #define WINDOW_HEIGHT 100 64 + #define DEFAULT_TITLE_FMT "%a %H:%M" 63 65 64 66 int 65 67 main(int argc, char* argv[]) ··· 73 75 char *display = NULL; 74 76 int ch; 75 77 76 - while ((ch = getopt(argc, argv, "d:")) != -1) { 78 + while ((ch = getopt(argc, argv, "d:f:")) != -1) { 77 79 switch (ch) { 78 80 case 'd': 79 81 display = optarg; 82 + break; 83 + case 'f': 84 + xinfo.title_fmt = strdup(optarg); 80 85 break; 81 86 default: 82 87 usage(); ··· 92 97 if (pledge("stdio") == -1) 93 98 err(1, "pledge"); 94 99 #endif 100 + 101 + if (xinfo.title_fmt == NULL) 102 + xinfo.title_fmt = strdup(DEFAULT_TITLE_FMT); 95 103 96 104 /* setup exit handler pipe that we'll poll on */ 97 105 if (pipe2(exit_msg, O_CLOEXEC) != 0) ··· 191 199 XDestroyWindow(xinfo.dpy, xinfo.win); 192 200 XFree(hints); 193 201 XCloseDisplay(xinfo.dpy); 202 + free(xinfo.title_fmt); 194 203 195 204 return 0; 196 205 } ··· 209 218 usage(void) 210 219 { 211 220 fprintf(stderr, "usage: %s %s\n", __progname, 212 - "[-d display]"); 221 + "[-d display] [-f title date format]"); 213 222 exit(1); 214 223 } 215 224 ··· 218 227 { 219 228 XTextProperty title_prop; 220 229 XWindowAttributes xgwa; 221 - char title[50]; 230 + char title[100]; 222 231 char *titlep = (char *)&title; 223 232 int rc, dwidth, xo, yo; 224 233 struct tm *tm; ··· 233 242 #endif 234 243 last_min = tm->tm_min; 235 244 236 - strftime(title, sizeof(title), "%a %H:%M", tm); 245 + strftime(title, sizeof(title), xinfo.title_fmt, tm); 237 246 238 247 /* update icon and window titles */ 239 248 if (!(rc = XStringListToTextProperty(&titlep, 1, &title_prop)))