From: Martin Mares Date: Sun, 18 Jul 2010 09:51:57 +0000 (+0200) Subject: OSD message options (and even messages themselves) made configurable X-Git-Tag: v1.4~16 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ad83dd5c4803f74a7ba386323b8bfcad1d4ff0da;p=checkmail.git OSD message options (and even messages themselves) made configurable --- diff --git a/cm.c b/cm.c index aa5fc7a..b9b2050 100644 --- a/cm.c +++ b/cm.c @@ -93,6 +93,14 @@ static clist mboxes; static struct mbox **mbox_array; static int num_mboxes, mbox_array_size; +struct osd_opt_node { + cnode n; + char *val; + char key[1]; +}; + +static clist osd_opts; + static void redraw_line(int i); static void rethink_display(void); @@ -163,6 +171,18 @@ setup_options(struct mbox *b) } } +static void +add_osd_opt(char *arg) +{ + struct osd_opt_node *n = xmalloc(sizeof(*n) + strlen(arg)); + strcpy(n->key, arg); + n->val = strchr(n->key, '='); + if (!n->val) + die("Malformed OSD option"); + *n->val++ = 0; + clist_add_tail(&osd_opts, &n->n); +} + static char * mbox_name(char *path) { @@ -622,6 +642,14 @@ x11_init(void) osd_pty = XInternAtom(x11_dpy, "OSD_QUEUE", False); if (!osd_pty) die("Cannot intern OSD_QUEUE atom"); + + // If OSD options contain no message, add one + int seen_msg = 0; + CLIST_FOR_EACH(struct osd_opt_node *, n, osd_opts) + if (!n->key[0]) + seen_msg = 1; + if (!seen_msg) + add_osd_opt("=You have new mail"); } leds_have = ~0U; @@ -659,8 +687,20 @@ sync_osd(void) return; debug("OSD: Displaying\n"); - char msg[] = ":You have new mail\n\n"; - XChangeProperty(x11_dpy, DefaultRootWindow(x11_dpy), osd_pty, XA_STRING, 8, PropModeAppend, (unsigned char *) msg, sizeof(msg)-1); + char msg[1024]; + unsigned pos = 0; + CLIST_FOR_EACH(struct osd_opt_node *, n, osd_opts) + { + pos += snprintf(msg+pos, sizeof(msg)-pos-1, "%s:%s\n", n->key, n->val); + if (pos > sizeof(msg)-1) + { + pos = sprintf(msg, "OSD message too long!\n"); + break; + } + } + msg[pos++] = '\n'; + + XChangeProperty(x11_dpy, DefaultRootWindow(x11_dpy), osd_pty, XA_STRING, 8, PropModeAppend, (unsigned char *) msg, pos); XFlush(x11_dpy); } @@ -998,6 +1038,7 @@ Options:\n\ -o =\tSet mailbox options\n\ -o \t\tSet default options for all mailboxes\n\ -p \t\tSet minimum priority to show\n\ +-s =\t\tSet on-screen display options (consult OSDD docs)\n\ \n\ Mailbox options (set with `-o', use upper case to negate):\n\ 0-9\t\t\tSet mailbox priority (0=default)\n\ @@ -1090,9 +1131,10 @@ main(int argc, char **argv) clist_init(&mboxes); clist_init(&options); clist_init(&patterns); + clist_init(&osd_opts); int c; - while ((c = getopt(argc, argv, "c:dim:o:p:")) >= 0) + while ((c = getopt(argc, argv, "c:dim:o:p:s:")) >= 0) switch (c) { case 'c': @@ -1115,6 +1157,9 @@ main(int argc, char **argv) case 'p': minimum_priority = atol(optarg); break; + case 's': + add_osd_opt(optarg); + break; default: usage(); }