misc cleanup

This commit is contained in:
Sascha Kruse 2011-09-09 19:58:10 +02:00
parent 7312dfa70a
commit ef7cb76dc5

34
dunst.c
View File

@ -41,7 +41,7 @@ static Window win;
static double global_timeout = 10; static double global_timeout = 10;
static msg_queue_t *msgqueuehead = NULL; static msg_queue_t *msgqueuehead = NULL;
static time_t now; static time_t now;
static int loop = True; static int listen_to_dbus = True;
static int visible = False; static int visible = False;
static KeySym key = NoSymbol; static KeySym key = NoSymbol;
static KeySym mask = 0; static KeySym mask = 0;
@ -55,7 +55,6 @@ msg_queue_t *pop(msg_queue_t *queue);
/* misc funtions */ /* misc funtions */
void drawmsg(const char *msg); void drawmsg(const char *msg);
void handleXEvents(void); void handleXEvents(void);
void hide_win(void);
void next_win(void); void next_win(void);
void run(void); void run(void);
void setup(void); void setup(void);
@ -154,19 +153,6 @@ handleXEvents(void) {
} }
} }
void
hide_win(void) {
if(!visible) {
/* window is already hidden */
return;
}
XUngrabButton(dc->dpy, AnyButton, AnyModifier, win);
XUnmapWindow(dc->dpy, win);
XFlush(dc->dpy);
visible = False;
}
void void
next_win(void) { next_win(void) {
if(msgqueuehead == NULL) { if(msgqueuehead == NULL) {
@ -174,7 +160,15 @@ next_win(void) {
} }
msgqueuehead = pop(msgqueuehead); msgqueuehead = pop(msgqueuehead);
if(msgqueuehead == NULL) { if(msgqueuehead == NULL) {
hide_win(); /* hide window */
if(!visible) {
/* window is already hidden */
return;
}
XUngrabButton(dc->dpy, AnyButton, AnyModifier, win);
XUnmapWindow(dc->dpy, win);
XFlush(dc->dpy);
visible = False;
} }
} }
@ -183,7 +177,7 @@ run(void) {
while(True) { while(True) {
/* dbus_poll blocks for max 2 seconds, if no events are present */ /* dbus_poll blocks for max 2 seconds, if no events are present */
if(loop) { if(listen_to_dbus) {
dbus_poll(); dbus_poll();
} }
now = time(&now); now = time(&now);
@ -193,7 +187,7 @@ run(void) {
next_win(); next_win();
} }
handleXEvents(); handleXEvents();
} else if (!loop) { } else if (!listen_to_dbus) {
break; break;
} }
} }
@ -316,7 +310,7 @@ main(int argc, char *argv[]) {
global_timeout = atoi(argv[++i]); global_timeout = atoi(argv[++i]);
else if(!strcmp(argv[i], "-msg")) { else if(!strcmp(argv[i], "-msg")) {
msgqueuehead = append(msgqueuehead, argv[++i]); msgqueuehead = append(msgqueuehead, argv[++i]);
loop = False; listen_to_dbus = False;
} }
else if(!strcmp(argv[i], "-key")) { else if(!strcmp(argv[i], "-key")) {
key = XStringToKeysym(argv[i+1]); key = XStringToKeysym(argv[i+1]);
@ -354,7 +348,7 @@ main(int argc, char *argv[]) {
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
} }
if(loop) { if(listen_to_dbus) {
initdbus(); initdbus();
} }
dc = initdc(); dc = initdc();