config.h
[xmenu] / xmenu.c
diff --git a/xmenu.c b/xmenu.c
index 7aa49c6..41303cc 100644 (file)
--- a/xmenu.c
+++ b/xmenu.c
@@ -79,7 +79,7 @@ static void setcurrmenu(struct Menu *currmenu_new);
 static void parsestdin(void);
 static void run(void);
 static void freewindow(struct Menu *menu);
 static void parsestdin(void);
 static void run(void);
 static void freewindow(struct Menu *menu);
-static void cleanupexit(void);
+static void cleanup(void);
 static void usage(void);
 
 /* X variables */
 static void usage(void);
 
 /* X variables */
@@ -146,7 +146,9 @@ main(int argc, char *argv[])
        /* run event loop */
        run();
 
        /* run event loop */
        run();
 
-       return 1;   /* UNREACHABLE */
+       cleanup();
+
+       return 0;
 }
 
 /* get color from color string */
 }
 
 /* get color from color string */
@@ -490,12 +492,14 @@ setcurrmenu(struct Menu *currmenu_new)
                lcamenu = menu;
        }
 
                lcamenu = menu;
        }
 
+       /* unmap menus from currmenu (inclusive) until lcamenu (exclusive) */
        for (menu = currmenu; menu != lcamenu; menu = menu->parent) {
                XUnmapWindow(dpy, menu->win);
        }
 
        currmenu = currmenu_new;
 
        for (menu = currmenu; menu != lcamenu; menu = menu->parent) {
                XUnmapWindow(dpy, menu->win);
        }
 
        currmenu = currmenu_new;
 
+       /* map menus from currmenu (inclusive) until lcamenu (exclusive) */
        item = NULL;
        for (menu = currmenu; menu != lcamenu; menu = menu->parent) {
                XMapWindow(dpy, menu->win);
        item = NULL;
        for (menu = currmenu; menu != lcamenu; menu = menu->parent) {
                XMapWindow(dpy, menu->win);
@@ -574,8 +578,6 @@ run(void)
        struct Item *previtem = NULL;
        XEvent ev;
 
        struct Item *previtem = NULL;
        XEvent ev;
 
-       setcurrmenu(rootmenu);
-
        while (!XNextEvent(dpy, &ev)) {
                switch(ev.type) {
                case Expose:
        while (!XNextEvent(dpy, &ev)) {
                switch(ev.type) {
                case Expose:
@@ -606,11 +608,11 @@ run(void)
                                        setcurrmenu(item->submenu);
                                } else {
                                        printf("%s\n", item->output);
                                        setcurrmenu(item->submenu);
                                } else {
                                        printf("%s\n", item->output);
-                                       cleanupexit();
+                                       return;
                                }
                                drawmenu();
                        } else {
                                }
                                drawmenu();
                        } else {
-                               cleanupexit();
+                               return;
                        }
                        break;
                case LeaveNotify:
                        }
                        break;
                case LeaveNotify:
@@ -637,19 +639,18 @@ freewindow(struct Menu *menu)
 
 /* cleanup and exit */
 static void
 
 /* cleanup and exit */
 static void
-cleanupexit(void)
+cleanup(void)
 {
        freewindow(rootmenu);
        XFreeFont(dpy, dc.font);
        XFreeGC(dpy, dc.gc);
        XCloseDisplay(dpy);
 {
        freewindow(rootmenu);
        XFreeFont(dpy, dc.font);
        XFreeGC(dpy, dc.gc);
        XCloseDisplay(dpy);
-       exit(0);
 }
 
 /* show usage */
 static void
 usage(void)
 {
 }
 
 /* show usage */
 static void
 usage(void)
 {
-       (void)fprintf(stderr, "usage: xmenu [-w] menuname\n");
+       (void)fprintf(stderr, "usage: xmenu [-w]\n");
        exit(1);
 }
        exit(1);
 }