0 Replies Latest reply: Nov 28, 2011 12:02 PM by hwaite RSS

    XGrabKeyboard freezes Swing application

      I'm trying to bypass the window manager and reroute all keyboard input directly to a JFC application. On Linux, this is accomplished via JNI calls to Xlib's 'XGrabKeyboard' or XCB's 'xcb_grab_keyboard'. Unfortunately, capturing keyboard input appears to hang up the application completely. The native code is invoked in a dedicated thread so I can't imagine where a deadlock is occurring. Not only is the UI unresponsive, but the JFrame becomes immobile as well (which is not the case if AWT event queue thread is blocked). Can anyone give me a hint as to why this is happening and how to prevent it?

        new Thread(
          new Runnable() {
            public void run() {
      JNIEXPORT void JNICALL Java_test_Test_grabKeyboard (JNIEnv* env, jclass cls) {
        Display* dpy = XOpenDisplay(0);
          dpy, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync, CurrentTime
        XEvent ev;
        for (;;) XNextEvent(dpy, &ev);
        XUngrabKeyboard(dpy, CurrentTime);