dmenu.1: document improved fastgrab behaviour from previous patch
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index c852e92..6b8f51b 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <strings.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -144,7 +145,7 @@ drawmenu(void)
        drw_setscheme(drw, scheme[SchemeNorm]);
        drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
 
-       drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL);
+       curpos = TEXTW(text) - TEXTW(&text[cursor]);
        if ((curpos += lrpad / 2 - 1) < w) {
                drw_setscheme(drw, scheme[SchemeNorm]);
                drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
@@ -552,7 +553,7 @@ run(void)
        XEvent ev;
 
        while (!XNextEvent(dpy, &ev)) {
-               if (XFilterEvent(&ev, win))
+               if (XFilterEvent(&ev, None))
                        continue;
                switch(ev.type) {
                case Expose:
@@ -664,6 +665,7 @@ setup(void)
                        XNClientWindow, win, XNFocusWindow, win, NULL);
 
        XMapRaised(dpy, win);
+       XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
        if (embed) {
                XSelectInput(dpy, parentwin, FocusChangeMask);
                if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) {
@@ -729,6 +731,8 @@ main(int argc, char *argv[])
 
        if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
                fputs("warning: no locale support\n", stderr);
+       if (!XSetLocaleModifiers(""))
+               fputs("warning: no locale modifiers support\n", stderr);
        if (!(dpy = XOpenDisplay(NULL)))
                die("cannot open display");
        screen = DefaultScreen(dpy);
@@ -743,7 +747,12 @@ main(int argc, char *argv[])
                die("no fonts could be loaded.");
        lrpad = drw->fonts->h;
 
-       if (fast) {
+#ifdef __OpenBSD__
+       if (pledge("stdio rpath", NULL) == -1)
+               die("pledge");
+#endif
+
+       if (fast && !isatty(0)) {
                grabkeyboard();
                readstdin();
        } else {