VirtualBox

Changeset 61987 in vbox for trunk


Ignore:
Timestamp:
Jul 1, 2016 5:13:12 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8151: Runtime UI: Cleanup for r108385: Some coding-style care, reordering, comments and probably a crash fix.

File:
1 edited

Legend:

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

    r61954 r61987  
    315315         * S.a. UIKeyboardHandler::eventFilter for more information. */
    316316
    317 #elif defined(VBOX_WS_X11) && QT_VERSION < 0x050000
     317#elif defined(VBOX_WS_X11)
     318# if QT_VERSION < 0x050000
    318319
    319320        /* On X11, we are using passive XGrabKey for normal (windowed) mode
     
    357358        }
    358359
     360# else /* QT_VERSION >= 0x050000 */
     361
     362        /* On X11, we are using Qt5 method to grab the keyboard.
     363         * This wrapper is using xcb_grab_keyboard function which is a part of active keyboard grabbing.
     364         * Active keyboard grabbing causes a problems on certain old window managers - a window cannot
     365         * be moved using the mouse. So we additionally grabbing the mouse as well to detect that user
     366         * is trying to click outside of internal window geometry. */
     367
     368        /* Use the Qt5 keyboard grabbing: */
     369        m_views[uScreenId]->grabKeyboard();
     370        /* And grab the mouse button (if mouse is not captured),
     371         * We do not check for failure as we do not currently implement a back-up plan. */
     372        if (!uisession()->isMouseCaptured())
     373            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);
     376
     377# endif /* QT_VERSION >= 0x050000 */
    359378#else
    360379
    361380        /* On other platforms we are just praying Qt method to work: */
    362381        m_views[uScreenId]->grabKeyboard();
    363 #if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
    364         /* Mouse capture hack for when the keyboard is captured.  We do not
    365          * check for failure as we do not currently implement a back-up plan. */
    366         if (!uisession()->isMouseCaptured())
    367             xcb_grab_button_checked(QX11Info::connection(), 0, QX11Info::appRootWindow(), XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, XCB_MOD_MASK_ANY);
    368 #endif /* defined(VBOX_WS_X11) && QT_VERSION >= 0x050000 */
    369382
    370383#endif
     
    412425         * S.a. UIKeyboardHandler::eventFilter for more information. */
    413426
    414 #elif defined(VBOX_WS_X11) && QT_VERSION < 0x050000
     427#elif defined(VBOX_WS_X11)
     428# if QT_VERSION < 0x050000
    415429
    416430        /* On X11, we are using passive XGrabKey for normal (windowed) mode
     
    440454        }
    441455
     456# else /* QT_VERSION >= 0x050000 */
     457
     458        /* On X11, we are using Qt5 method to release the keyboard.
     459         * This wrapper is using xcb_ungrab_keyboard function which is a part of active keyboard grabbing.
     460         * Active keyboard grabbing causes a problems on certain old window managers - a window cannot
     461         * be moved using the mouse. So we finally releasing additionally grabbed mouse as well to
     462         * allow further user interactions. */
     463
     464        /* Use the Qt5 keyboard releasing: */
     465        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
     466        /* And release the mouse button,
     467         * We do not check for failure as we do not currently implement a back-up plan. */
     468        xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1, QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
     469
     470# endif /* QT_VERSION >= 0x050000 */
    442471#else
    443472
    444473        /* On other platforms we are just praying Qt method to work: */
    445474        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
    446 #if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
    447         /* Mouse capture hack for when the keyboard is captured. */
    448         if (!uisession()->isMouseCaptured())
    449             xcb_ungrab_button_checked(QX11Info::connection(), XCB_BUTTON_INDEX_1, QX11Info::appRootWindow(), XCB_MOD_MASK_ANY);
    450 #endif /* defined(VBOX_WS_X11) && QT_VERSION >= 0x050000 */
    451475
    452476#endif
     
    13851409            break;
    13861410        }
    1387         /* If we see a mouse press outside of our views while the mouse is not
    1388          * captured, release the keyboard before letting the event owner see it.
    1389          * This is because some owners cannot deal with failures to grab the
    1390          * keyboard themselves (e.g. window managers dragging windows).  Only
    1391          * works if we have passively grabbed the mouse button. */
     1411        /* Watch for mouse-events: */
    13921412        case XCB_BUTTON_PRESS:
    13931413        {
     1414            /* Do nothing if mouse is actively grabbed: */
     1415            if (uisession()->isMouseCaptured())
     1416                break;
     1417
     1418            /* If we see a mouse press outside of our views while the mouse is not
     1419             * captured, release the keyboard before letting the event owner see it.
     1420             * This is because some owners cannot deal with failures to grab the
     1421             * keyboard themselves (e.g. window managers dragging windows).
     1422             * Only works if we have passively grabbed the mouse button. */
     1423
    13941424            /* Cast to XCB key-event: */
    13951425            xcb_button_press_event_t *pButtonEvent = static_cast<xcb_button_press_event_t*>(pMessage);
    1396             QWidget *pWidget = qApp->widgetAt(pButtonEvent->root_x, pButtonEvent->root_y);
    1397 
    1398             if (uisession()->isMouseCaptured())
    1399                 break;
     1426
     1427            /* Detect the widget which should receive the event actually: */
     1428            const QWidget *pWidget = qApp->widgetAt(pButtonEvent->root_x, pButtonEvent->root_y);
    14001429            if (pWidget)
    14011430            {
    1402                 QPoint pos = pWidget->mapFromGlobal(QPoint(pButtonEvent->root_x, pButtonEvent->root_y));
     1431                /* Redirect the event to corresponding widget: */
     1432                const QPoint pos = pWidget->mapFromGlobal(QPoint(pButtonEvent->root_x, pButtonEvent->root_y));
    14031433                pButtonEvent->event = pWidget->effectiveWinId();
    14041434                pButtonEvent->event_x = pos.x();
     
    14071437                break;
    14081438            }
    1409             m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
     1439            /* Release the keyboard finally: */
     1440            releaseKeyboard();
    14101441            xcb_allow_events_checked(QX11Info::connection(), XCB_ALLOW_REPLAY_POINTER, pButtonEvent->time);
    14111442            break;
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