简体   繁体   中英

x11 - Unable to move window after XGrabKeyboard

After calling XGrabKeyboard() , my application captures and displays all key presses / releases, including those for the GUI and PrintScreen keys. However, the user is no longer able to move the application's window. So far, this occurs on Fedora 17 and Ubuntu 12.04.

How can I allow the user to move the application while being under the effect of XGrabKeyboard() ?

Below is sample code for my Qt application:

bool KeyboardStatus::x11Event(XEvent *event) {
    switch (event->type) {
        case FocusIn:
            XGrabKeyboard(x11Info().display(), winId(), false, GrabModeAsync, GrabModeAsync, CurrentTime);
            break;

        case FocusOut:
            XUngrabKeyboard(x11Info().display(), CurrentTime);
            break;

        case KeyPress:
            // Display which key was pressed to user
            return true;

        case KeyRelease:
            // Display which key was released to user
            return true;
    }

    return false;
}

Taking the grab statement out of the event handler does not solve the issue. Here is a sample project which illustrates the problem: TestGrab.zip

I have tried this on KDE, FVWM and GNOME (just using Xlib), and only the GNOME window manager has this problem.

I thought it might be possible to fix it by picking up the ConfigureNotify event, but it is not generated when you try to move the window.

I have had similar problem with XFCE on Cygwin. Here the problem was with insufficient input mask passed to XSelectInput. Adding FocusChangeMask to KeyPressMask | KeyReleaseMask solved the problem.

Once again, it helped me to fix similar problem on xfce/cygwin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM