From 7801e922031eead50d9bc61126da5c6b20de71e3 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Tue, 6 Mar 2012 21:39:19 +0100 Subject: [PATCH] don't timeout when idle --- config.def.h | 3 +++ config.mk | 2 +- dunst.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index a908872..c885844 100644 --- a/config.def.h +++ b/config.def.h @@ -23,6 +23,9 @@ int sort = True; /* sort messages by urgency */ int indicate_hidden = True; /* show count of hidden messages */ /* const char *geom = "x1"; */ +/* If this is > 0, messages won't be closed, when user is idle for + * longer than idle_threshold seconds */ +const int idle_threshold = 120; char *key_string = NULL; /* set to NULL for no keybinging */ /* char *key_string = "space"; */ diff --git a/config.mk b/config.mk index 6f31c20..c7c6a16 100644 --- a/config.mk +++ b/config.mk @@ -11,7 +11,7 @@ XINERAMAFLAGS = -DXINERAMA # includes and libs INCS = -I${X11INC} -I/usr/lib/dbus-1.0/include -I/usr/include/dbus-1.0 -LIBS = -L${X11LIB} -lX11 -ldbus-1 -lpthread -lrt ${XINERAMALIBS} +LIBS = -L${X11LIB} -lX11 -lXext -lXss -ldbus-1 -lpthread -lrt ${XINERAMALIBS} # flags CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} diff --git a/dunst.c b/dunst.c index a6ac681..76dc92d 100644 --- a/dunst.c +++ b/dunst.c @@ -13,6 +13,7 @@ #ifdef XINERAMA #include #endif +#include #include "config.h" #include "dunst.h" @@ -48,6 +49,7 @@ static int visible = False; static KeySym key = NoSymbol; static screen_info scr; static dimension_t geometry; +static XScreenSaverInfo *screensaver_info; static int font_h; /* list functions */ @@ -68,6 +70,7 @@ void free_msgqueue_t(msg_queue_t *elem); void handle_mouse_click(XEvent ev); void handleXEvents(void); void initmsg(msg_queue_t *msg); +int is_idle(void); char *string_replace(const char *needle, const char *replacement, char *haystack); void run(void); void setup(void); @@ -179,6 +182,11 @@ check_timeouts(void) { cur = msgqueue; while(cur != NULL) { + if(is_idle()) { + cur->start = now; + cur = cur->next; + continue; + } if(cur->start == 0 || cur->timeout == 0) { cur = cur->next; continue; @@ -483,6 +491,17 @@ initmsg(msg_queue_t *msg) { } +int +is_idle(void) +{ + XScreenSaverQueryInfo(dc->dpy, DefaultRootWindow(dc->dpy), + screensaver_info); + if(idle_threshold == 0) { + return False; + } + return screensaver_info->idle / 1000 > idle_threshold; +} + char * string_replace(const char *needle, const char *replacement, char *haystack) { char *tmp, *start; @@ -611,6 +630,7 @@ main(int argc, char *argv[]) { &geometry.x, &geometry.y, &geometry.w, &geometry.h); key = key_string ? XStringToKeysym(key_string) : NoSymbol; + screensaver_info = XScreenSaverAllocInfo(); while(1) { static struct option long_options[] = {