wmiikgrab can be exit with Escape, it reports all key event and resends the original one to the specific client, however the client must have to accept synthetic events (like wmii frames)

This commit is contained in:
Anselm R. Garbe 2006-07-04 14:07:08 +02:00
parent 74750219da
commit 9ed7244658
2 changed files with 23 additions and 37 deletions

View File

@ -5,7 +5,7 @@ include ../config.mk
CFLAGS += -I../liblitz -I../libixp -I../libcext CFLAGS += -I../liblitz -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext LDFLAGS += -L../libixp -lixp -L../libcext -lcext
X11LDFLAGS += -L../liblitz -llitz X11LDFLAGS += -L../liblitz -llitz -lXtst
X11SRC = wmiimenu.c wmiipsel.c wmiiwarp.c wmiikgrab.c X11SRC = wmiimenu.c wmiipsel.c wmiiwarp.c wmiikgrab.c
SRC = wmiir.c wmiisetsid.c SRC = wmiir.c wmiisetsid.c

View File

@ -24,45 +24,32 @@ usage()
exit(1); exit(1);
} }
static void
emulate_key_press(unsigned long mod, KeyCode key)
{
XEvent e;
Window win;
int revert;
XGetInputFocus(dpy, &win, &revert);
e.xkey.type = KeyPress;
e.xkey.time = CurrentTime;
e.xkey.window = win;
e.xkey.display = dpy;
e.xkey.state = mod;
e.xkey.keycode = key;
XSendEvent(dpy, win, True, KeyPressMask, &e);
e.xkey.type = KeyRelease;
XSendEvent(dpy, win, True, KeyReleaseMask, &e);
XSync(dpy, False);
}
static void static void
next_keystroke(unsigned long *mod, KeyCode *code) next_keystroke(unsigned long *mod, KeyCode *code)
{ {
XEvent e; XEvent e;
KeySym sym; KeySym sym;
Window win;
int revert;
*mod = 0; *mod = 0;
do { XGetInputFocus(dpy, &win, &revert);
XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
/* do {*/
XMaskEvent(dpy, KeyPressMask, &e); XMaskEvent(dpy, KeyPressMask, &e);
*mod |= e.xkey.state; XSendEvent(dpy, win, True, KeyPressMask, &e);
*mod |= e.xkey.state;/* & valid_mask;*/
*code = (KeyCode) e.xkey.keycode; *code = (KeyCode) e.xkey.keycode;
sym = XKeycodeToKeysym(dpy, e.xkey.keycode, 0); sym = XKeycodeToKeysym(dpy, e.xkey.keycode, 0);
} while(IsModifierKey(sym)); /* } while(IsModifierKey(sym));*/
XUngrabKeyboard(dpy, CurrentTime);
XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
} }
static void static Bool
print_key(unsigned long mod, KeyCode code) print_key(unsigned long mod, KeyCode code)
{ {
char buf[256]; char buf[256], *k;
buf[0] = 0; buf[0] = 0;
if(mod & ShiftMask) if(mod & ShiftMask)
@ -80,17 +67,19 @@ print_key(unsigned long mod, KeyCode code)
if(mod & Mod5Mask) if(mod & Mod5Mask)
cext_strlcat(buf, "Mod5-", sizeof(buf)); cext_strlcat(buf, "Mod5-", sizeof(buf));
cext_strlcat(buf, if((k = XKeysymToString(XKeycodeToKeysym(dpy, code, 0))))
XKeysymToString(XKeycodeToKeysym(dpy, code, 0)), sizeof(buf)); cext_strlcat(buf, k, sizeof(buf));
fprintf(stdout, "EventType=Key;EventValue='%s'\n", buf); fprintf(stdout, "EventType=Key;EventValue='%s'\n", buf);
return strncmp(buf, "Escape", 7);
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
unsigned long mod; unsigned long mod = 0;
KeyCode code; KeyCode code = 0;
/* command line args */ /* command line args */
if(argc > 1) { if(argc > 1) {
@ -107,13 +96,10 @@ main(int argc, char **argv)
} }
root = DefaultRootWindow(dpy); root = DefaultRootWindow(dpy);
XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime); do {
for(;;) {
next_keystroke(&mod, &code); next_keystroke(&mod, &code);
print_key(mod, code); XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
emulate_key_press(mod, code); } while (print_key(mod, code));
}
XUngrabKeyboard(dpy, CurrentTime);
XSync(dpy, False); XSync(dpy, False);
return 0; return 0;