next_win()

replaced copy&paste code with function
This commit is contained in:
Sascha Kruse 2011-09-08 23:50:55 +02:00
parent 86ee9b11bb
commit c7c46243a7

32
dunst.c
View File

@ -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) {