diff --git a/dunst.c b/dunst.c index 2b1fcaf..8139ebc 100644 --- a/dunst.c +++ b/dunst.c @@ -61,6 +61,7 @@ msg_queue_t *pop(msg_queue_t *queue); void drawmsg(const char *msg); void handleXEvents(void); void hide_win(void); +void next_win(void); void run(void); void setup(void); void show_win(void); @@ -146,19 +147,13 @@ handleXEvents(void) { XRaiseWindow(dc->dpy, win); break; case ButtonPress: - if(ev.xbutton.window == win && msgqueuehead != NULL) { - msgqueuehead = pop(msgqueuehead); - if(msgqueuehead == NULL) { - hide_win(); - } + if(ev.xbutton.window == win) { + next_win(); } break; case KeyPress: - if (XLookupKeysym(&ev.xkey, 0) == KEY && msgqueuehead != NULL) { - msgqueuehead = pop(msgqueuehead); - if(msgqueuehead == NULL) { - hide_win(); - } + if(XLookupKeysym(&ev.xkey, 0) == KEY) { + next_win(); } } } @@ -177,6 +172,17 @@ hide_win(void) { visible = False; } +void +next_win(void) { + if(msgqueuehead == NULL) { + return; + } + msgqueuehead = pop(msgqueuehead); + if(msgqueuehead == NULL) { + hide_win(); + } +} + void run(void) { @@ -189,11 +195,7 @@ run(void) { if(msgqueuehead != NULL) { show_win(); if(difftime(now, msgqueuehead->start) > global_timeout) { - msgqueuehead = pop(msgqueuehead); - if(msgqueuehead == NULL) { - hide_win(); - } - + next_win(); } handleXEvents(); } else if (!loop) {