VirtualBox

Changeset 63578 in vbox


Ignore:
Timestamp:
Aug 17, 2016 1:51:53 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:7846: Runtime UI: Moving native event filter code from keyboard-handler to machine-view so that it can be used for mouse related tasks as well.

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

Legend:

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

    r63567 r63578  
    5858
    5959#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    60 
    61 /* Qt includes: */
    62 #if QT_VERSION >= 0x050000
    63 # include <QAbstractNativeEventFilter>
    64 #endif /* QT_VERSION >= 0x050000 */
    6560
    6661/* GUI includes: */
     
    10095enum { KeyExtended = 0x01, KeyPressed = 0x02, KeyPause = 0x04, KeyPrint = 0x08 };
    10196enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
    102 
    103 
    104 #if QT_VERSION >= 0x050000
    105 /** QAbstractNativeEventFilter extension
    106   * allowing to pre-process native platform events. */
    107 class KeyboardHandlerEventFilter : public QAbstractNativeEventFilter
    108 {
    109 public:
    110 
    111     /** Constructor which takes the passed @a pParent to redirect events to. */
    112     KeyboardHandlerEventFilter(UIKeyboardHandler *pParent)
    113         : m_pParent(pParent)
    114     {}
    115 
    116     /** Handles all native events. */
    117     bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult)
    118     {
    119         /* Redirect event to parent: */
    120         Q_UNUSED(pResult);
    121         return m_pParent->nativeEventPreprocessor(eventType, pMessage);
    122     }
    123 
    124 private:
    125 
    126     /** Holds the passed parent reference. */
    127     UIKeyboardHandler *m_pParent;
    128 };
    129 #endif /* QT_VERSION >= 0x050000 */
    13097
    13198
     
    10601027#else /* QT_VERSION >= 0x050000 */
    10611028
    1062 bool UIKeyboardHandler::nativeEventPreprocessor(const QByteArray &eventType, void *pMessage)
    1063 {
    1064     /* Redirect event to machine-view: */
    1065     return m_views.contains(m_iKeyboardHookViewIndex) ? m_views.value(m_iKeyboardHookViewIndex)->nativeEventPreprocessor(eventType, pMessage) : false;
    1066 }
    1067 
    1068 bool UIKeyboardHandler::nativeEventPostprocessor(void *pMessage, ulong uScreenId)
    1069 {
     1029bool UIKeyboardHandler::nativeEventFilter(void *pMessage, ulong uScreenId)
     1030{
     1031    /* Make sure view with passed index exists: */
     1032    if (!m_views.contains(uScreenId))
     1033        return false;
     1034
    10701035    /* Check if some system event should be filtered out.
    10711036     * Returning @c true means filtering-out,
     
    15861551    , m_pAltGrMonitor(0)
    15871552#endif /* VBOX_WS_WIN */
    1588 #if QT_VERSION >= 0x050000
    1589     , m_pPrivateEventFilter(0)
    1590 #endif /* QT_VERSION >= 0x050000 */
    15911553    , m_cMonitors(1)
    15921554{
     
    16671629
    16681630#endif /* VBOX_WS_WIN */
    1669 
    1670 #if QT_VERSION >= 0x050000
    1671     /* If private event-filter is installed: */
    1672     if (m_pPrivateEventFilter)
    1673     {
    1674         /* Uninstall existing private event-filter: */
    1675         qApp->removeNativeEventFilter(m_pPrivateEventFilter);
    1676         delete m_pPrivateEventFilter;
    1677         m_pPrivateEventFilter = 0;
    1678     }
    1679 #endif /* QT_VERSION >= 0x050000 */
    16801631
    16811632    /* Update keyboard hook view index: */
     
    17651716
    17661717#endif /* VBOX_WS_WIN */
    1767 
    1768 #if QT_VERSION >= 0x050000
    1769 # if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
    1770                 /* If private event-filter is NOT installed;
    1771                  * Or installed but NOT for that view: */
    1772                 if (!m_pPrivateEventFilter || (int)uScreenId != m_iKeyboardHookViewIndex)
    1773                 {
    1774                     /* If private event-filter is installed: */
    1775                     if (m_pPrivateEventFilter)
    1776                     {
    1777                         /* Uninstall existing private event-filter: */
    1778                         qApp->removeNativeEventFilter(m_pPrivateEventFilter);
    1779                         delete m_pPrivateEventFilter;
    1780                         m_pPrivateEventFilter = 0;
    1781                     }
    1782                     /* Install new private event-filter: */
    1783                     m_pPrivateEventFilter = new KeyboardHandlerEventFilter(this);
    1784                     qApp->installNativeEventFilter(m_pPrivateEventFilter);
    1785                 }
    1786 # endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    1787 #endif /* QT_VERSION >= 0x050000 */
    17881718
    17891719                /* Update keyboard hook view index: */
     
    18351765
    18361766#endif /* VBOX_WS_WIN */
    1837 
    1838 #if QT_VERSION >= 0x050000
    1839 # if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
    1840                 /* If private event-filter is installed: */
    1841                 if (m_pPrivateEventFilter)
    1842                 {
    1843                     /* Uninstall existing private event-filter: */
    1844                     qApp->removeNativeEventFilter(m_pPrivateEventFilter);
    1845                     delete m_pPrivateEventFilter;
    1846                     m_pPrivateEventFilter = 0;
    1847                 }
    1848 # endif /* VBOX_WS_WIN || VBOX_WS_X11 */
    1849 #endif /* QT_VERSION >= 0x050000 */
    18501767
    18511768                /* Update keyboard hook view index: */
     
    19451862#else /* QT_VERSION >= 0x050000 */
    19461863    Q_UNUSED(event);
    1947     QByteArray eventType("mac_generic_NSEvent");
    1948     return m_views[m_iKeyboardHookViewIndex]->nativeEventPreprocessor(eventType, unconst(pvCocoaEvent));
     1864    return nativeEventFilter(unconst(pvCocoaEvent), m_iKeyboardHookViewIndex);
    19491865#endif /* QT_VERSION >= 0x050000 */
    19501866}
     
    20111927    return m_views[m_iKeyboardHookViewIndex]->winEvent(&message, &dummyResult);
    20121928#else /* QT_VERSION >= 0x050000 */
    2013     QByteArray eventType("windows_generic_MSG");
    2014     return m_views[m_iKeyboardHookViewIndex]->nativeEventPreprocessor(eventType, &message);
     1929    return nativeEventFilter(&message, m_iKeyboardHookViewIndex);
    20151930#endif /* QT_VERSION >= 0x050000 */
    20161931}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

    r62493 r63578  
    5252# endif /* QT_VERSION < 0x050000 */
    5353#endif /* VBOX_WS_X11 */
    54 #if QT_VERSION >= 0x050000
    55 class KeyboardHandlerEventFilter;
    56 #endif /* QT_VERSION >= 0x050000 */
    5754
    5855
     
    111108#if QT_VERSION < 0x050000
    112109# if defined(VBOX_WS_MAC)
    113     /** Qt4: Mac: Performs final pre-processing of all the native events. */
     110    /** Qt4: Mac: Performs pre-processing of all the native events. */
    114111    bool macEventFilter(const void *pvCocoaEvent, EventRef event, ulong uScreenId);
    115112# elif defined(VBOX_WS_WIN)
    116     /** Qt4: Win: Performs final pre-processing of all the native events. */
     113    /** Qt4: Win: Performs pre-processing of all the native events. */
    117114    bool winEventFilter(MSG *pMsg, ulong uScreenId);
    118115# elif defined(VBOX_WS_X11)
    119     /** Qt4: X11: Performs final pre-processing of all the native events. */
     116    /** Qt4: X11: Performs pre-processing of all the native events. */
    120117    bool x11EventFilter(XEvent *pEvent, ulong uScreenId);
    121118# endif /* VBOX_WS_X11 */
    122 #else /* QT_VERSION >= 0x050000 */
     119#else
    123120    /** Qt5: Performs pre-processing of all the native events. */
    124     bool nativeEventPreprocessor(const QByteArray &eventType, void *pMessage);
    125     /** Qt5: Performs post-processing of all the native events. */
    126     bool nativeEventPostprocessor(void *pMessage, ulong uScreenId);
    127 #endif /* QT_VERSION >= 0x050000 */
     121    bool nativeEventFilter(void *pMessage, ulong uScreenId);
     122#endif
    128123
    129124protected slots:
     
    240235#endif /* VBOX_WS_WIN */
    241236
    242 #if QT_VERSION >= 0x050000
    243     /** Win: Holds the native event filter instance. */
    244     KeyboardHandlerEventFilter *m_pPrivateEventFilter;
    245     /** Win: Allows the native event filter to
    246       * redirect events directly to nativeEventPreprocessor handler. */
    247     friend class KeyboardHandlerEventFilter;
    248 #endif /* QT_VERSION >= 0x050000 */
    249 
    250237    ULONG m_cMonitors;
    251238};
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r63567 r63578  
    7171#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    7272
     73/* Qt includes: */
     74#if QT_VERSION >= 0x050000
     75# include <QAbstractNativeEventFilter>
     76#endif
     77
    7378/* GUI includes: */
    7479#ifdef VBOX_WS_MAC
     
    123128
    124129
     130#if QT_VERSION >= 0x050000
     131/** QAbstractNativeEventFilter extension
     132  * allowing to pre-process native platform events. */
     133class UINativeEventFilter : public QAbstractNativeEventFilter
     134{
     135public:
     136
     137    /** Constructs native event filter storing @a pParent to redirect events to. */
     138    UINativeEventFilter(UIMachineView *pParent)
     139        : m_pParent(pParent)
     140    {}
     141
     142    /** Redirects all the native events to parent. */
     143    bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long * /* pResult */)
     144    {
     145        return m_pParent->nativeEventPreprocessor(eventType, pMessage);
     146    }
     147
     148private:
     149
     150    /** Holds the passed parent reference. */
     151    UIMachineView *m_pParent;
     152};
     153#endif
     154
     155
    125156/* static */
    126157UIMachineView* UIMachineView::create(  UIMachineWindow *pMachineWindow
     
    214245    if (!pMachineView)
    215246        return;
     247
     248    /* Cleanup filters: */
     249    pMachineView->cleanupFilters();
    216250
    217251    /* Cleanup frame-buffer: */
     
    622656    , m_fIsDraggingFromGuest(false)
    623657#endif
     658#if QT_VERSION >= 0x050000
     659    , m_pNativeEventFilter(0)
     660#endif
    624661{
    625662}
     
    823860    /* Machine state-change updater: */
    824861    connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged()));
     862}
     863
     864void UIMachineView::cleanupFilters()
     865{
     866#if QT_VERSION >= 0x050000
     867    /* If native event filter exists: */
     868    if (m_pNativeEventFilter)
     869    {
     870        /* Uninstall/destroy existing native event filter: */
     871        qApp->removeNativeEventFilter(m_pNativeEventFilter);
     872        delete m_pNativeEventFilter;
     873        m_pNativeEventFilter = 0;
     874    }
     875#endif
    825876}
    826877
     
    15111562}
    15121563
     1564#if QT_VERSION >= 0x050000
     1565void UIMachineView::focusInEvent(QFocusEvent *pEvent)
     1566{
     1567    /* Call to base-class: */
     1568    QAbstractScrollArea::focusInEvent(pEvent);
     1569
     1570    /* If native event filter isn't exists: */
     1571    if (!m_pNativeEventFilter)
     1572    {
     1573        /* Create/install new native event filter: */
     1574        m_pNativeEventFilter = new UINativeEventFilter(this);
     1575        qApp->installNativeEventFilter(m_pNativeEventFilter);
     1576    }
     1577}
     1578
     1579void UIMachineView::focusOutEvent(QFocusEvent *pEvent)
     1580{
     1581    /* If native event filter exists: */
     1582    if (m_pNativeEventFilter)
     1583    {
     1584        /* Uninstall/destroy existing native event filter: */
     1585        qApp->removeNativeEventFilter(m_pNativeEventFilter);
     1586        delete m_pNativeEventFilter;
     1587        m_pNativeEventFilter = 0;
     1588    }
     1589
     1590    /* Call to base-class: */
     1591    QAbstractScrollArea::focusOutEvent(pEvent);
     1592}
     1593#endif
     1594
    15131595#ifdef VBOX_WITH_DRAG_AND_DROP
    15141596bool UIMachineView::dragAndDropCanAccept(void) const
     
    18221904bool UIMachineView::nativeEventPreprocessor(const QByteArray &eventType, void *pMessage)
    18231905{
     1906    /* Check if some event should be filtered out.
     1907     * Returning @c true means filtering-out,
     1908     * Returning @c false means passing event to Qt. */
     1909
    18241910# if defined(VBOX_WS_MAC)
    18251911
     
    18291915    EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage));
    18301916
    1831     /* Check if some NSEvent should be filtered out.
    1832      * Returning @c true means filtering-out,
    1833      * Returning @c false means passing event to Qt. */
    18341917    switch(::GetEventClass(event))
    18351918    {
     
    18461929                {
    18471930                    /* Delegate key-event handling to the keyboard-handler: */
    1848                     return machineLogic()->keyboardHandler()->nativeEventPostprocessor(pMessage, screenId());
     1931                    return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId());
    18491932                }
    18501933                default:
     
    18641947    MSG *pEvent = static_cast<MSG*>(pMessage);
    18651948
    1866     /* Check if some MSG event should be filtered out.
    1867      * Returning @c true means filtering-out,
    1868      * Returning @c false means passing event to Qt. */
    18691949    switch (pEvent->message)
    18701950    {
     
    18751955        case WM_SYSKEYUP:
    18761956        {
    1877             /* Can't do COM inter-process calls from a SendMessage handler,
    1878              * see http://support.microsoft.com/kb/131056. */
     1957            // WORKAROUND:
     1958            // Can't do COM inter-process calls from a SendMessage handler,
     1959            // see http://support.microsoft.com/kb/131056.
    18791960            if (vboxGlobal().isSeparateProcess() && InSendMessage())
    18801961            {
     
    18961977
    18971978            /* Delegate key-event handling to the keyboard-handler: */
    1898             return machineLogic()->keyboardHandler()->nativeEventPostprocessor(pMessage, screenId());
     1979            return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId());
    18991980        }
    19001981        default:
     
    19091990    xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
    19101991
    1911     /* Check if some XCB event should be filtered out.
    1912      * Returning @c true means filtering-out,
    1913      * Returning @c false means passing event to Qt. */
    19141992    switch (pEvent->response_type & ~0x80)
    19151993    {
     
    19171995        case XCB_KEY_PRESS:
    19181996        case XCB_KEY_RELEASE:
    1919         case XCB_BUTTON_PRESS:
    1920         {
    1921             /* Delegate key-event handling to the keyboard-handler and let it
    1922              * filter out button presses out of the view windows: */
    1923             return machineLogic()->keyboardHandler()->nativeEventPostprocessor(pMessage, screenId());
     1997        case XCB_BUTTON_PRESS: // TODO: Move to mouse-filter case!
     1998        {
     1999            /* Delegate key-event handling to the keyboard-handler: */
     2000            return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId());
    19242001        }
    19252002        default:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r62493 r63578  
    6565 class CDnDTarget;
    6666#endif /* VBOX_WITH_DRAG_AND_DROP */
     67#if QT_VERSION >= 0x050000
     68class UINativeEventFilter;
     69#endif
    6770
    6871
     
    186189    //virtual void cleanupConsoleConnections() {}
    187190    //virtual void cleanupConnections() {}
    188     //virtual void cleanupFilters() {}
     191    virtual void cleanupFilters();
    189192    //virtual void cleanupCommon() {}
    190193    virtual void cleanupFrameBuffer();
     
    280283    void moveEvent(QMoveEvent *pEvent);
    281284    void paintEvent(QPaintEvent *pEvent);
     285
     286#if QT_VERSION >= 0x050000
     287    /** Handles focus-in @a pEvent. */
     288    void focusInEvent(QFocusEvent *pEvent);
     289    /** Handles focus-out @a pEvent. */
     290    void focusOutEvent(QFocusEvent *pEvent);
     291#endif
    282292
    283293#ifdef VBOX_WITH_DRAG_AND_DROP
     
    427437#endif
    428438
     439#if QT_VERSION >= 0x050000
     440    /** Holds the native event filter instance. */
     441    UINativeEventFilter *m_pNativeEventFilter;
     442    /** Allows the native event filter to redirect
     443      * events directly to nativeEventPreprocessor(). */
     444    friend class UINativeEventFilter;
     445#endif
     446
    429447    /* Friend classes: */
    430448    friend class UIKeyboardHandler;
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