make dmenu_path script executable
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 3b2f3ec..ae56f4f 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);
@@ -661,15 +664,24 @@ setup(void)
                            CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
        XSetClassHint(dpy, win, &ch);
 
-       /* open input methods */
-       xim = XOpenIM(dpy, NULL, NULL, NULL);
+
+       /* input methods */
+       if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL) {
+               XSetLocaleModifiers("@im=local");
+               if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL) {
+                       XSetLocaleModifiers("@im=");
+                       if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL)
+                               die("XOpenIM failed. Could not open input device.\n");
+               }
+       }
+
        xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
                        XNClientWindow, win, XNFocusWindow, win, NULL);
 
        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 +762,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 {