VirtualBox

Changeset 62008 in vbox for trunk


Ignore:
Timestamp:
Jul 4, 2016 1:34:20 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8151: X11: Runtime UI: Avoid race conflict between grabbing and dragging machine-window by delaying keyboard grabbing until mouse button release.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited

Legend:

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

    r61987 r62008  
    269269        return;
    270270
    271 #ifdef VBOX_WS_X11
    272 # if QT_VERSION >= 0x050000
     271#if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
    273272    /* Due to X11 async nature we may have lost the focus already by the time we get the focus
    274273     * notification, so we do a sanity check that we still have it. If we don't have the focus
     
    287286    if (m_windows.value(uScreenId)->winId() != actualWinId)
    288287        return;
    289 # endif /* QT_VERSION >= 0x050000 */
    290 #endif /* VBOX_WS_X11 */
     288#endif /* VBOX_WS_X11 && QT_VERSION >= 0x050000 */
    291289
    292290    /* If such view exists: */
     
    366364         * is trying to click outside of internal window geometry. */
    367365
    368         /* Use the Qt5 keyboard grabbing: */
    369         m_views[uScreenId]->grabKeyboard();
    370         /* And grab the mouse button (if mouse is not captured),
     366        /* Grab the mouse button (if mouse is not captured),
    371367         * We do not check for failure as we do not currently implement a back-up plan. */
    372368        if (!uisession()->isMouseCaptured())
    373369            xcb_grab_button_checked(QX11Info::connection(), 0, QX11Info::appRootWindow(),
    374                                     XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
    375                                     XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
     370                                    XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_SYNC,
     371                                    XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
     372        /* Delay the actual keyboard grab request if the mouse button is held down and the mouse
     373         * is not captured to work around window managers which transfer the focus when the user
     374         * clicks in the title bar and then try to grab the keyboard and sulk if they fail. */
     375        xcb_query_pointer_cookie_t xcbRequestCookie = xcb_query_pointer(QX11Info::connection(), QX11Info::appRootWindow());
     376        xcb_query_pointer_reply_t *pReply = xcb_query_pointer_reply(QX11Info::connection(), xcbRequestCookie, NULL);
     377        /* And use the Qt5 keyboard grabbing finally: */
     378        if (uisession()->isMouseCaptured() || !pReply || !(pReply->mask & XCB_KEY_BUT_MASK_BUTTON_1))
     379            m_views[uScreenId]->grabKeyboard();
     380        free(pReply);
    376381
    377382# endif /* QT_VERSION >= 0x050000 */
     
    14401445            releaseKeyboard();
    14411446            xcb_allow_events_checked(QX11Info::connection(), XCB_ALLOW_REPLAY_POINTER, pButtonEvent->time);
     1447            break;
     1448        }
     1449        case XCB_BUTTON_RELEASE:
     1450        {
     1451            /* If the mouse button was pressed when we captured the keyboard then we
     1452             * will have delayed doing the grab. Do it now on button release.
     1453             * This will not hurt if it is already grabbed. */
     1454            if (m_iKeyboardCaptureViewIndex != -1)
     1455                m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
    14421456            break;
    14431457        }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r61945 r62008  
    19101910        case XCB_KEY_RELEASE:
    19111911        case XCB_BUTTON_PRESS:
     1912        case XCB_BUTTON_RELEASE:
    19121913        {
    19131914            /* Delegate key-event handling to the keyboard-handler and let it
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