]> git.armaanb.net Git - dmenu.git/blobdiff - dmenu.c
Close when the embedding window is destroyed
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 3b2f3ec9ec88321f8390b8493bcfd4add8182083..f8031497c8e116a9c6e045857d679e75445fd033 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -6,9 +6,7 @@
 #include <string.h>
 #include <strings.h>
 #include <time.h>
-#ifdef __OpenBSD__
 #include <unistd.h>
-#endif
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -558,6 +556,11 @@ run(void)
                if (XFilterEvent(&ev, None))
                        continue;
                switch(ev.type) {
+               case DestroyNotify:
+                       if (ev.xdestroywindow.window != win)
+                               break;
+                       cleanup();
+                       exit(1);
                case Expose:
                        if (ev.xexpose.count == 0)
                                drw_map(drw, win, 0, 0, mw, mh);
@@ -669,7 +672,7 @@ setup(void)
        XMapRaised(dpy, win);
        XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
        if (embed) {
-               XSelectInput(dpy, parentwin, FocusChangeMask);
+               XSelectInput(dpy, parentwin, FocusChangeMask | SubstructureNotifyMask);
                if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
                        for (i = 0; i < du && dws[i] != win; ++i)
                                XSelectInput(dpy, dws[i], FocusChangeMask);
@@ -750,11 +753,11 @@ main(int argc, char *argv[])
        lrpad = drw->fonts->h;
 
 #ifdef __OpenBSD__
-       if (pledge("stdio rpath", NULL) < 0)
+       if (pledge("stdio rpath", NULL) == -1)
                die("pledge");
 #endif
 
-       if (fast) {
+       if (fast && !isatty(0)) {
                grabkeyboard();
                readstdin();
        } else {