X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=65f25ce576e819421da9320afd7808c730e84ab4;hb=1a13d0465d1a6f4f74bc5b07b04c9bd542f20ba6;hp=314256f0c3cf567d80d19d8157ac149dc3be9eb6;hpb=377bd37e212b1ec4c03a481245603c6560d0be22;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index 314256f..65f25ce 100644 --- a/dmenu.c +++ b/dmenu.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -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,9 +553,14 @@ run(void) XEvent ev; while (!XNextEvent(dpy, &ev)) { - if (XFilterEvent(&ev, None)) + if (XFilterEvent(&ev, win)) 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); @@ -658,15 +664,17 @@ 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) + die("XOpenIM failed: could not open input device"); + 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); @@ -730,8 +738,6 @@ 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); @@ -746,7 +752,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 {