prepare stuff for type-to-select
This commit is contained in:
parent
6abae763c6
commit
f472bfacd9
31
xmenu.c
31
xmenu.c
|
@ -5,6 +5,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
@ -30,6 +31,7 @@ static struct Monitor mon;
|
||||||
static Atom utf8string;
|
static Atom utf8string;
|
||||||
static Atom wmdelete;
|
static Atom wmdelete;
|
||||||
static Atom netatom[NetLast];
|
static Atom netatom[NetLast];
|
||||||
|
static XIM xim;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
static int iflag = 0; /* whether to disable icons */
|
static int iflag = 0; /* whether to disable icons */
|
||||||
|
@ -372,6 +374,11 @@ allocmenu(struct Menu *parent, struct Item *list, unsigned level)
|
||||||
CWBorderPixel | CWEventMask | CWSaveUnder,
|
CWBorderPixel | CWEventMask | CWSaveUnder,
|
||||||
&swa);
|
&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;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,6 +776,24 @@ grabkeyboard(void)
|
||||||
errx(1, "could not grab keyboard");
|
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 */
|
/* ungrab pointer and keyboard */
|
||||||
static void
|
static void
|
||||||
ungrab(void)
|
ungrab(void)
|
||||||
|
@ -1016,6 +1041,7 @@ mapmenu(struct Menu *currmenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
prevmenu = currmenu;
|
prevmenu = currmenu;
|
||||||
|
grabfocus(currmenu->win);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get menu of given window */
|
/* get menu of given window */
|
||||||
|
@ -1126,7 +1152,6 @@ run(struct Menu *currmenu)
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
mapmenu(currmenu);
|
mapmenu(currmenu);
|
||||||
|
|
||||||
while (!XNextEvent(dpy, &ev)) {
|
while (!XNextEvent(dpy, &ev)) {
|
||||||
switch(ev.type) {
|
switch(ev.type) {
|
||||||
case Expose:
|
case Expose:
|
||||||
|
@ -1295,6 +1320,8 @@ main(int argc, char *argv[])
|
||||||
XClassHint classh;
|
XClassHint classh;
|
||||||
|
|
||||||
/* open connection to server and set X variables */
|
/* open connection to server and set X variables */
|
||||||
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
|
warnx("warning: no locale support");
|
||||||
if ((dpy = XOpenDisplay(NULL)) == NULL)
|
if ((dpy = XOpenDisplay(NULL)) == NULL)
|
||||||
errx(1, "could not open display");
|
errx(1, "could not open display");
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
|
@ -1304,6 +1331,8 @@ main(int argc, char *argv[])
|
||||||
XrmInitialize();
|
XrmInitialize();
|
||||||
if ((xrm = XResourceManagerString(dpy)) != NULL)
|
if ((xrm = XResourceManagerString(dpy)) != NULL)
|
||||||
xdb = XrmGetStringDatabase(xrm);
|
xdb = XrmGetStringDatabase(xrm);
|
||||||
|
if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL)
|
||||||
|
errx(1, "XOpenIM: could not open input device");
|
||||||
|
|
||||||
/* get configuration */
|
/* get configuration */
|
||||||
getresources();
|
getresources();
|
||||||
|
|
1
xmenu.h
1
xmenu.h
|
@ -98,4 +98,5 @@ struct Menu {
|
||||||
int maxtextw; /* maximum text width */
|
int maxtextw; /* maximum text width */
|
||||||
unsigned level; /* menu level relative to root */
|
unsigned level; /* menu level relative to root */
|
||||||
Window win; /* menu window to map on the screen */
|
Window win; /* menu window to map on the screen */
|
||||||
|
XIC xic; /* input context */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user