#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <locale.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
static Atom utf8string;
static Atom wmdelete;
static Atom netatom[NetLast];
+static XIM xim;
/* flags */
static int iflag = 0; /* whether to disable icons */
CWBorderPixel | CWEventMask | CWSaveUnder,
&swa);
+ menu->xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, menu->win, XNFocusWindow, menu->win, NULL);
+ if (menu->xic == NULL)
+ errx(1, "XCreateIC: could not obtain input method");
+
return menu;
}
errx(1, "could not grab keyboard");
}
+/* try to grab focus, we may have to wait for another process to ungrab */
+static void
+grabfocus(Window win)
+{
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
+ Window focuswin;
+ int i, revertwin;
+
+ for (i = 0; i < 100; ++i) {
+ XGetInputFocus(dpy, &focuswin, &revertwin);
+ if (focuswin == win)
+ return;
+ XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
+ nanosleep(&ts, NULL);
+ }
+ errx(1, "cannot grab focus");
+}
+
/* ungrab pointer and keyboard */
static void
ungrab(void)
}
prevmenu = currmenu;
+ grabfocus(currmenu->win);
}
/* get menu of given window */
XEvent ev;
mapmenu(currmenu);
-
while (!XNextEvent(dpy, &ev)) {
switch(ev.type) {
case Expose:
XClassHint classh;
/* open connection to server and set X variables */
+ if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ warnx("warning: no locale support");
if ((dpy = XOpenDisplay(NULL)) == NULL)
errx(1, "could not open display");
screen = DefaultScreen(dpy);
XrmInitialize();
if ((xrm = XResourceManagerString(dpy)) != NULL)
xdb = XrmGetStringDatabase(xrm);
+ if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL)
+ errx(1, "XOpenIM: could not open input device");
/* get configuration */
getresources();