VirtualBox

Changeset 63779 in vbox for trunk


Ignore:
Timestamp:
Sep 9, 2016 2:11:40 PM (8 years ago)
Author:
vboxsync
Message:

bugref:8151: FE/Qt: improve X11 keyboard capturing. We currently intercept mouse clicks outside of the machine window when the keyboard is grabbed so that we can release the keyboard grab in time to prevent it interfering with window drags and other operations. Fixes: only grab the mouse button if the cursor is outside of the machine views to prevent interfering with input to the machine; and catch a few cases where the mouse button grab was not released.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r63612 r63779  
    369369         * user is trying to click outside of internal window geometry. */
    370370
    371         /* Grab the mouse button. We do not check for failure as we do not currently implement a back-up plan. */
    372         xcb_grab_button_checked(QX11Info::connection(), 0, QX11Info::appRootWindow(),
    373                                 XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
    374                                 XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
     371         /* Grab the mouse button if the cursor is outside of our views.
     372          * We do not check for failure as we do not currently implement a back-up plan. */
     373         if (!isItListenedView(QApplication::widgetAt(QCursor::pos())))
     374             xcb_grab_button_checked(QX11Info::connection(), 0, QX11Info::appRootWindow(),
     375                                     XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
     376                                     XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
    375377        /* And grab the keyboard, using XCB directly, as Qt does not report failure. */
    376378        xcb_grab_keyboard_cookie_t xcbGrabCookie = xcb_grab_keyboard(QX11Info::connection(), false, m_views[m_iKeyboardCaptureViewIndex]->winId(),
     
    379381        if (pGrabReply == NULL || pGrabReply->status != XCB_GRAB_STATUS_SUCCESS)
    380382        {
     383            /* Release the mouse button grab.
     384             * We do not check for failure as we do not currently implement a back-up plan. */
     385            xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1,
     386                                      QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
    381387            /* Try again later: */
    382388            free(pGrabReply);
     
    477483        /* Ungrab using XCB: */
    478484        xcb_ungrab_keyboard(QX11Info::connection(), XCB_TIME_CURRENT_TIME);
    479         /* And release the mouse button,
     485        /* Release the mouse button grab.
    480486         * We do not check for failure as we do not currently implement a back-up plan. */
    481         xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1, QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
     487        xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1,
     488                                  QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
    482489
    483490# endif /* QT_VERSION >= 0x050000 */
     
    17571764                break;
    17581765            }
     1766#if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
     1767            case QEvent::Enter:
     1768            {
     1769                /* Release the mouse button grab.
     1770                 * We do not check for failure as we do not currently implement a back-up plan. */
     1771                xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1,
     1772                                          QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
     1773
     1774                break;
     1775            }
     1776            case QEvent::Leave:
     1777            {
     1778                /* Grab the mouse button if the keyboard is captured.
     1779                 * We do not check for failure as we do not currently implement a back-up plan. */
     1780                if (m_fIsKeyboardCaptured)
     1781                    xcb_grab_button_checked(QX11Info::connection(), 0, QX11Info::appRootWindow(),
     1782                                            XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
     1783                                            XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
     1784
     1785                break;
     1786            }
     1787#endif /* VBOX_WS_X11 && QT_VERSION >= 0x050000 */
    17591788            case QEvent::KeyPress:
    17601789            case QEvent::KeyRelease:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette