VirtualBox

Changeset 63579 in vbox


Ignore:
Timestamp:
Aug 17, 2016 3:45:21 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:7846: Runtime UI: Implementing mouse native event filter allowing us among other potential things to prevent unwanted translation of Meta+LMB events to RMB events under OSX host.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/CocoaEventHelper.h

    r62493 r63579  
    3636const char *darwinEventTypeName(unsigned long eEvtType);
    3737void darwinPrintEvent(const char *pszPrefix, ConstNativeNSEventRef pEvent);
     38void darwinPostStrippedMouseEvent(ConstNativeNSEventRef pEvent);
    3839
    3940RT_C_DECLS_END
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/CocoaEventHelper.mm

    r52727 r63579  
    2121
    2222/* Global includes */
     23#import <Cocoa/Cocoa.h>
    2324#import <AppKit/NSEvent.h>
    2425#include <Carbon/Carbon.h>
     
    293294}
    294295
     296void darwinPostStrippedMouseEvent(ConstNativeNSEventRef pEvent)
     297{
     298    /* Create and post new stripped event: */
     299    NSEvent *pNewEvent = [NSEvent mouseEventWithType:[pEvent type]
     300                                            location:[pEvent locationInWindow]
     301                                       modifierFlags:0
     302                                           timestamp:[pEvent timestamp] // [NSDate timeIntervalSinceReferenceDate] ?
     303                                        windowNumber:[pEvent windowNumber]
     304                                             context:[pEvent context]
     305                                         eventNumber:[pEvent eventNumber]
     306                                          clickCount:[pEvent clickCount]
     307                                            pressure:[pEvent pressure]];
     308    [NSApp postEvent:pNewEvent atStart:YES];
     309}
     310
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r63578 r63579  
    593593    /* Depending on event kind: */
    594594    const UInt32 uEventKind = ::GetEventKind(event);
    595     switch(uEventKind)
     595    switch (uEventKind)
    596596    {
    597597        /* Watch for simple key-events: */
     
    10451045    /* Depending on event kind: */
    10461046    const UInt32 uEventKind = ::GetEventKind(event);
    1047     switch(uEventKind)
     1047    switch (uEventKind)
    10481048    {
    10491049        /* Watch for simple key-events: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r63578 r63579  
    17861786     * Returning @c false means passing event to Qt. */
    17871787    bool fResult = false; /* Pass to Qt by default. */
    1788     switch(::GetEventClass(event))
     1788    switch (::GetEventClass(event))
    17891789    {
    17901790        /* Watch for keyboard-events: */
    17911791        case kEventClassKeyboard:
    17921792        {
    1793             switch(::GetEventKind(event))
     1793            switch (::GetEventKind(event))
    17941794            {
    17951795                /* Watch for key-events: */
     
    19151915    EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage));
    19161916
    1917     switch(::GetEventClass(event))
     1917    switch (::GetEventClass(event))
    19181918    {
    19191919        /* Watch for keyboard-events: */
    19201920        case kEventClassKeyboard:
    19211921        {
    1922             switch(::GetEventKind(event))
     1922            switch (::GetEventKind(event))
    19231923            {
    19241924                /* Watch for key-events: */
     
    19361936            break;
    19371937        }
     1938        /* Watch for mouse-events: */
     1939        case kEventClassMouse:
     1940        {
     1941            switch (::GetEventKind(event))
     1942            {
     1943                /* Watch for button-events: */
     1944                case kEventMouseDown:
     1945                case kEventMouseUp:
     1946                {
     1947                    /* Delegate button-event handling to the mouse-handler: */
     1948                    return machineLogic()->mouseHandler()->nativeEventFilter(pMessage, screenId());
     1949                }
     1950                default:
     1951                    break;
     1952            }
     1953            break;
     1954        }
    19381955        default:
    19391956            break;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp

    r63175 r63579  
    5555#include <QTouchEvent>
    5656
     57/* GUI includes: */
     58#if defined(VBOX_WS_MAC) && QT_VERSION >= 0x050000
     59# include "CocoaEventHelper.h"
     60#endif
     61
    5762/* COM includes: */
    5863#include "CMouse.h"
     
    264269}
    265270
    266 #ifdef VBOX_WS_X11
    267 # if QT_VERSION < 0x050000
     271#if QT_VERSION < 0x050000
     272# ifdef VBOX_WS_X11
     273
    268274bool UIMouseHandler::x11EventFilter(XEvent *pEvent, ulong /* uScreenId */)
    269275{
     
    293299    return fResult;
    294300}
    295 # endif /* QT_VERSION < 0x050000 */
    296 #endif /* VBOX_WS_X11 */
     301
     302# endif /* VBOX_WS_X11 */
     303#else /* QT_VERSION >= 0x050000 */
     304
     305bool UIMouseHandler::nativeEventFilter(void *pMessage, ulong uScreenId)
     306{
     307    /* Make sure view with passed index exists: */
     308    if (!m_views.contains(uScreenId))
     309        return false;
     310
     311    /* Check if some system event should be filtered out.
     312     * Returning @c true means filtering-out,
     313     * Returning @c false means passing event to Qt. */
     314    bool fResult = false; /* Pass to Qt by default. */
     315
     316# if defined(VBOX_WS_MAC)
     317
     318    /* Acquire carbon event reference from the cocoa one: */
     319    EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage));
     320
     321    /* Depending on event kind: */
     322    const UInt32 uEventKind = ::GetEventKind(event);
     323    switch (uEventKind)
     324    {
     325        /* Watch for button-events: */
     326        case kEventMouseDown:
     327        case kEventMouseUp:
     328        {
     329            /* Acquire button number: */
     330            EventMouseButton enmButton = 0;
     331            ::GetEventParameter(event, kEventParamMouseButton, typeMouseButton,
     332                                NULL, sizeof(enmButton), NULL, &enmButton);
     333            /* If the event comes for primary mouse button: */
     334            if (enmButton == kEventMouseButtonPrimary)
     335            {
     336                /* Acquire modifiers: */
     337                UInt32 uKeyModifiers = ~0U;
     338                ::GetEventParameter(event, kEventParamKeyModifiers, typeUInt32,
     339                                    NULL, sizeof(uKeyModifiers), NULL, &uKeyModifiers);
     340                /* If the event comes with Control modifier: */
     341                if (uKeyModifiers == controlKey)
     342                {
     343                    /* Replacing it with the stripped one: */
     344                    darwinPostStrippedMouseEvent(pMessage);
     345                    /* And filter out initial one: */
     346                    return true;
     347                }
     348            }
     349        }
     350    }
     351
     352# elif defined(VBOX_WS_WIN)
     353
     354    /* Nothing for now. */
     355
     356# elif defined(VBOX_WS_X11)
     357
     358    /* Nothing for now. */
     359
     360# else
     361
     362#  warning "port me!"
     363
     364# endif
     365
     366    /* Return result: */
     367    return fResult;
     368}
     369
     370#endif /* QT_VERSION >= 0x050000 */
    297371
    298372/* Machine state-change handler: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.h

    r62493 r63579  
    7575    int state() const;
    7676
    77 #ifdef VBOX_WS_X11
    78 # if QT_VERSION < 0x050000
    79     /** X11: Qt4: Handles all native events. */
     77#if QT_VERSION < 0x050000
     78# ifdef VBOX_WS_X11
     79    /** Qt4: X11: Performs pre-processing of all the native events. */
    8080    bool x11EventFilter(XEvent *pEvent, ulong uScreenId);
    81 # endif /* QT_VERSION < 0x050000 */
    82 #endif /* VBOX_WS_X11 */
     81# endif
     82#else
     83    /** Qt5: Performs pre-processing of all the native events. */
     84    bool nativeEventFilter(void *pMessage, ulong uScreenId);
     85#endif
    8386
    8487protected slots:
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