/*
* Incoming Mail Checker
*
- * (c) 2005--2008 Martin Mares <mj@ucw.cz>
+ * (c) 2005--2010 Martin Mares <mj@ucw.cz>
*/
#define _GNU_SOURCE
static int check_interval = 30;
static int force_refresh;
static int allow_bells = 1;
+static int allow_osd = 1;
static int minimum_priority;
static time_t last_scan_time;
static char *run_cmd = "mutt -f %s";
int sender_mbox;
int hotkey;
int led;
+ int osd;
};
struct option_node {
o->sender_mbox = -1;
o->hotkey = -1;
o->led = -1;
+ o->osd = -1;
}
static void
MERGE(sender_mbox);
MERGE(hotkey);
MERGE(led);
+ MERGE(osd);
}
}
rethink_display();
}
-#ifdef CONFIG_X_LEDS
+#ifdef CONFIG_X11
#include <X11/Xlib.h>
+#include <X11/Xatom.h>
-static Display *leds_dpy;
+static Display *x11_dpy;
static unsigned leds_care, leds_have, leds_want;
+static unsigned osd_care, osd_have, osd_want;
+static Atom osd_pty;
static void
-leds_init(void)
+x11_init(void)
{
- leds_care = 0;
+ leds_care = (global_options.led >= 0 ? (1 << global_options.led) : 0);
+ osd_care = (global_options.osd >= 0);
CLIST_FOR_EACH(struct option_node *, o, options)
- if (o->o.led > 0)
- leds_care |= (1 << o->o.led);
- if (!leds_care)
{
- debug("LEDS: No mailbox wants them\n");
+ if (o->o.led > 0)
+ leds_care |= (1 << o->o.led);
+ if (o->o.osd > 0)
+ osd_care = 1;
+ }
+
+ if (!leds_care && !osd_care)
+ {
+ debug("X11: No mailbox wants LEDs or OSD\n");
return;
}
if (!getenv("DISPLAY"))
{
- debug("LEDS: Do not have X display\n");
+ debug("X11: Do not have X display\n");
return;
}
- if (!(leds_dpy = XOpenDisplay(NULL)))
+ if (!(x11_dpy = XOpenDisplay(NULL)))
die("Cannot open X display, although the DISPLAY variable is set");
+ if (osd_care)
+ {
+ osd_pty = XInternAtom(x11_dpy, "OSD_QUEUE", False);
+ if (!osd_pty)
+ die("Cannot intern OSD_QUEUE atom");
+ }
+
leds_have = ~0U;
+ debug("X11: Initialized\n");
}
static void
XKeyboardControl cc;
cc.led = i;
cc.led_mode = (leds_want & (1 << i)) ? LedModeOn : LedModeOff;
- XChangeKeyboardControl(leds_dpy, KBLed | KBLedMode, &cc);
+ XChangeKeyboardControl(x11_dpy, KBLed | KBLedMode, &cc);
}
- XFlush(leds_dpy);
+ XFlush(x11_dpy);
leds_have = leds_want;
}
+static void
+sync_osd(void)
+{
+ if (!osd_want || !allow_osd)
+ {
+ osd_have = 0;
+ return;
+ }
+ if (osd_have)
+ 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);
+ XFlush(x11_dpy);
+}
+
static void
rethink_leds(void)
{
- if (!leds_dpy)
+ if (!x11_dpy)
return;
leds_want = 0;
+ osd_want = 0;
CLIST_FOR_EACH(struct mbox *, b, mboxes)
- if (b->o.led > 0 && b->new)
- leds_want |= (1 << b->o.led);
+ {
+ if (b->o.led > 0 && b->new)
+ leds_want |= (1 << b->o.led);
+ if (b->o.osd > 0 && b->new)
+ osd_want = 1;
+ }
sync_leds();
+ sync_osd();
}
static void
-leds_cleanup(void)
+x11_cleanup(void)
{
- if (!leds_dpy)
+ if (!x11_dpy)
return;
leds_want = 0;
#else
-static void leds_init(void) { }
+static void x11_init(void) { }
static void rethink_leds(void) { }
-static void leds_cleanup(void) { }
+static void x11_cleanup(void) { }
#endif
Mailbox options (set with `-o', use upper case to negate):\n\
0-9\t\t\tSet mailbox priority (0=default)\n\
b\t\t\tBeep when a message arrives\n\
+d\t\t\tSend an on-screen-display message (requires OSDD)\n\
e\t\t\tHide from display if empty\n\
f\t\t\tShow flagged messages if there are no new ones\n\
h\t\t\tHide from display\n\
case 'b':
o->beep = value;
break;
+ case 'd':
+ o->osd = value;
+ break;
case 'e':
o->hide_if_empty = value;
break;
charset_init();
term_init();
- leds_init();
+ x11_init();
scan_and_redraw();
next_active(0, 1);
allow_bells = 0;
print_status("Bells and whistles are now disabled. Pssst!");
break;
+ case 'd':
+ allow_osd = 1;
+ print_status("On-screen display is now enabled.");
+ break;
+ case 'D':
+ allow_osd = 0;
+ print_status("On-screen display is now disabled. Watch your step.");
+ break;
default:
if (ch >= '0' && ch <= '9')
{
}
}
- leds_cleanup();
+ x11_cleanup();
term_cleanup();
return 0;
}