Allow mouse messages from Wacom pens, e.g. right click pen buttons, etc.
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Aug 2019 15:32:15 -0700
changeset 130458254c364ec4a
parent 13044 99f2845397a4
child 13046 695321a18b46
Allow mouse messages from Wacom pens, e.g. right click pen buttons, etc.
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Fri Aug 30 08:03:19 2019 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Fri Aug 30 15:32:15 2019 -0700
     1.3 @@ -47,9 +47,6 @@
     1.4  #include "wmmsg.h"
     1.5  #endif
     1.6  
     1.7 -/* For processing mouse WM_*BUTTON* and WM_MOUSEMOVE message-data from GetMessageExtraInfo() */
     1.8 -#define MOUSEEVENTF_FROMTOUCH 0xFF515700
     1.9 -
    1.10  /* Masks for processing the windows KEYDOWN and KEYUP messages */
    1.11  #define REPEATED_KEYMASK    (1<<30)
    1.12  #define EXTENDED_KEYMASK    (1<<24)
    1.13 @@ -246,7 +243,7 @@
    1.14  
    1.15  /*
    1.16  * Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also
    1.17 -*  so this funciton reconciles our view of the world with the current buttons reported by windows
    1.18 +*  so this function reconciles our view of the world with the current buttons reported by windows
    1.19  */
    1.20  static void
    1.21  WIN_CheckWParamMouseButtons(WPARAM wParam, SDL_WindowData *data, SDL_MouseID mouseID)
    1.22 @@ -365,26 +362,40 @@
    1.23     This is used to implement a workaround.. */
    1.24  static SDL_bool isWin10FCUorNewer = SDL_FALSE;
    1.25  
    1.26 -/* Checks a mouse or raw packet for touch indication.
    1.27 -   returns: 0 for not touch input, 1 for touch input.
    1.28 -*/
    1.29 -static LPARAM
    1.30 -GetMessageExtraInfoAndCheckMousePacketTouch(int *checkTouch) {
    1.31 +/* We want to generate mouse events from mouse and pen, and touch events from touchscreens */
    1.32 +#define MI_WP_SIGNATURE         0xFF515700
    1.33 +#define MI_WP_SIGNATURE_MASK    0xFFFFFF00
    1.34 +#define IsTouchEvent(dw) ((dw) & MI_WP_SIGNATURE_MASK) == MI_WP_SIGNATURE
    1.35 +
    1.36 +typedef enum
    1.37 +{
    1.38 +    SDL_MOUSE_EVENT_SOURCE_UNKNOWN,
    1.39 +    SDL_MOUSE_EVENT_SOURCE_MOUSE,
    1.40 +    SDL_MOUSE_EVENT_SOURCE_TOUCH,
    1.41 +    SDL_MOUSE_EVENT_SOURCE_PEN,
    1.42 +} SDL_MOUSE_EVENT_SOURCE;
    1.43 +
    1.44 +static SDL_MOUSE_EVENT_SOURCE GetMouseMessageSource()
    1.45 +{
    1.46      LPARAM extrainfo = GetMessageExtraInfo();
    1.47      /* Mouse data (ignoring synthetic mouse events generated for touchscreens) */
    1.48      /* Versions below Vista will set the low 7 bits to the Mouse ID and don't use bit 7:
    1.49         Check bits 8-32 for the signature (which will indicate a Tablet PC Pen or Touch Device).
    1.50         Only check bit 7 when Vista and up(Cleared=Pen, Set=Touch(which we need to filter out)),
    1.51         when the signature is set. The Mouse ID will be zero for an actual mouse. */
    1.52 -    *checkTouch = (!(((extrainfo & 0x7F) && (isVistaOrNewer ? (extrainfo & 0x80) : 1)) || ((extrainfo & 0xFFFFFF00) == 0xFF515700)));
    1.53 -    return extrainfo;
    1.54 +    if (IsTouchEvent(extrainfo)) {
    1.55 +        if (extrainfo & 0x80) {
    1.56 +            return SDL_MOUSE_EVENT_SOURCE_TOUCH;
    1.57 +        } else {
    1.58 +            return SDL_MOUSE_EVENT_SOURCE_PEN;
    1.59 +        }
    1.60 +    }
    1.61 +    return SDL_MOUSE_EVENT_SOURCE_MOUSE;
    1.62  }
    1.63  
    1.64  LRESULT CALLBACK
    1.65  WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    1.66  {
    1.67 -    int checkTouch = -1; /* Default to -1 for not yet loaded */
    1.68 -    LPARAM extrainfo;    /* The extra info when checkTouch >= 0. */
    1.69      SDL_WindowData *data;
    1.70      LRESULT returnCode = -1;
    1.71  
    1.72 @@ -512,10 +523,9 @@
    1.73      case WM_MOUSEMOVE:
    1.74          {
    1.75              SDL_Mouse *mouse = SDL_GetMouse();
    1.76 -            extrainfo = GetMessageExtraInfoAndCheckMousePacketTouch(&checkTouch); /* load */
    1.77              if (!mouse->relative_mode || mouse->relative_mode_warp) {
    1.78                  /* Only generate mouse events for real mouse */
    1.79 -                if (((extrainfo & MOUSEEVENTF_FROMTOUCH) != MOUSEEVENTF_FROMTOUCH) && checkTouch) {
    1.80 +                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH) {
    1.81                      SDL_SendMouseMotion(data->window, 0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
    1.82                      if (isWin10FCUorNewer && mouse->relative_mode_warp) {
    1.83                          /* To work around #3931, Win10 bug introduced in Fall Creators Update, where
    1.84 @@ -546,11 +556,8 @@
    1.85      case WM_XBUTTONDBLCLK:
    1.86          {
    1.87              SDL_Mouse *mouse = SDL_GetMouse();
    1.88 -            if (checkTouch < 0) {
    1.89 -                extrainfo = GetMessageExtraInfoAndCheckMousePacketTouch(&checkTouch);
    1.90 -            }
    1.91              if (!mouse->relative_mode || mouse->relative_mode_warp) {
    1.92 -                if (((extrainfo & MOUSEEVENTF_FROMTOUCH) != MOUSEEVENTF_FROMTOUCH) && checkTouch) {
    1.93 +                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH) {
    1.94                      WIN_CheckWParamMouseButtons(wParam, data, 0);
    1.95                  }
    1.96              }
    1.97 @@ -576,9 +583,9 @@
    1.98  
    1.99              /* Mouse data (ignoring synthetic mouse events generated for touchscreens) */
   1.100              if (inp.header.dwType == RIM_TYPEMOUSE) {
   1.101 -                extrainfo = GetMessageExtraInfoAndCheckMousePacketTouch(&checkTouch);
   1.102 -                if (!checkTouch)
   1.103 +                if (GetMouseMessageSource() == SDL_MOUSE_EVENT_SOURCE_TOUCH) {
   1.104                      break;
   1.105 +                }
   1.106                  if (isRelative) {
   1.107                      RAWMOUSE* rawmouse = &inp.data.mouse;
   1.108