VirtualBox

Changeset 47729 in vbox for trunk


Ignore:
Timestamp:
Aug 14, 2013 2:13:41 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87971
Message:

FE/Qt: Mouse handler: filter fake mouse events (Windows host).

File:
1 edited

Legend:

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

    r47728 r47729  
    678678}
    679679
     680/* Try to detect if the mouse event is fake and actually generated by a touch device. */
     681#ifdef Q_WS_WIN
     682#if (WINVER < 0x0601)
     683typedef enum tagINPUT_MESSAGE_DEVICE_TYPE {
     684  IMDT_UNAVAILABLE  = 0, // 0x0
     685  IMDT_KEYBOARD     = 1, // 0x1
     686  IMDT_MOUSE        = 2, // 0x2
     687  IMDT_TOUCH        = 4, // 0x4
     688  IMDT_PEN          = 8 // 0x8
     689} INPUT_MESSAGE_DEVICE_TYPE;
     690
     691typedef enum tagINPUT_MESSAGE_ORIGIN_ID {
     692  IMO_UNAVAILABLE  = 0x00000000,
     693  IMO_HARDWARE     = 0x00000001,
     694  IMO_INJECTED     = 0x00000002,
     695  IMO_SYSTEM       = 0x00000004
     696} INPUT_MESSAGE_ORIGIN_ID;
     697
     698typedef struct tagINPUT_MESSAGE_SOURCE {
     699  INPUT_MESSAGE_DEVICE_TYPE deviceType;
     700  INPUT_MESSAGE_ORIGIN_ID   originId;
     701} INPUT_MESSAGE_SOURCE;
     702#endif /* WINVER < 0x0601 */
     703
     704#define MOUSEEVENTF_FROMTOUCH 0xFF515700
     705#define MOUSEEVENTF_MASK      0xFFFFFF00
     706
     707typedef BOOL WINAPI FNGetCurrentInputMessageSource(INPUT_MESSAGE_SOURCE *inputMessageSource);
     708typedef FNGetCurrentInputMessageSource *PFNGetCurrentInputMessageSource;
     709
     710static bool mouseIsTouchSource(int iEventType, Qt::MouseButtons mouseButtons)
     711{
     712    NOREF(mouseButtons);
     713
     714    static PFNGetCurrentInputMessageSource pfnGetCurrentInputMessageSource = (PFNGetCurrentInputMessageSource)-1;
     715    if (pfnGetCurrentInputMessageSource == (PFNGetCurrentInputMessageSource)-1)
     716    {
     717        HMODULE hUser = GetModuleHandle(L"user32.dll");
     718        if (hUser)
     719            pfnGetCurrentInputMessageSource =
     720                (PFNGetCurrentInputMessageSource)GetProcAddress(hUser, "GetCurrentInputMessageSource");
     721    }
     722
     723    int deviceType = -1;
     724    if (pfnGetCurrentInputMessageSource)
     725    {
     726        INPUT_MESSAGE_SOURCE inputMessageSource;
     727        BOOL fSuccess = pfnGetCurrentInputMessageSource(&inputMessageSource);
     728        deviceType = fSuccess? inputMessageSource.deviceType: -2;
     729    }
     730    else
     731    {
     732        if (   iEventType == QEvent::MouseButtonPress
     733            || iEventType == QEvent::MouseButtonRelease
     734            || iEventType == QEvent::MouseMove)
     735            deviceType = (GetMessageExtraInfo() & MOUSEEVENTF_MASK) == MOUSEEVENTF_FROMTOUCH? IMDT_TOUCH: -3;
     736    }
     737
     738    LogRelFlow(("mouseIsTouchSource: deviceType %d\n", deviceType));
     739    return deviceType == IMDT_TOUCH || deviceType == IMDT_PEN;
     740}
     741#else
     742/* Apparently Q_WS_MAC does not generate fake mouse events.
     743 * Other platforms, which have no known method to detect fake events are handled here too.
     744 */
     745static bool mouseIsTouchSource(int iEventType, Qt::MouseButtons mouseButtons)
     746{
     747    NOREF(iEventType);
     748    NOREF(mouseButtons);
     749    return false;
     750}
     751#endif
     752
    680753/* Separate function to handle most of existing mouse-events: */
    681754bool UIMouseHandler::mouseEvent(int iEventType, ulong uScreenId,
     
    684757                                int wheelDelta, Qt::Orientation wheelDirection)
    685758{
     759    /* Ignore fake mouse events. */
     760    if (uisession()->isMouseSupportsMultiTouch() && mouseIsTouchSource(iEventType, mouseButtons))
     761        return true;
     762
    686763    /* Check if machine is still running: */
    687764    if (!uisession()->isRunning())
Note: See TracChangeset for help on using the changeset viewer.

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