Avoid sending regular mouse messages for touch input
authorSam Lantinga
Mon, 06 Apr 2020 19:21:56 -0700
changeset 13694a76372587774
parent 13693 d075df3ffa57
child 13695 775d08dd98db
Avoid sending regular mouse messages for touch input
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Wed Mar 25 01:34:15 2020 -0400
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Apr 06 19:21:56 2020 -0700
     1.3 @@ -75,6 +75,9 @@
     1.4  #ifndef WM_MOUSEHWHEEL
     1.5  #define WM_MOUSEHWHEEL 0x020E
     1.6  #endif
     1.7 +#ifndef WM_POINTERUPDATE
     1.8 +#define WM_POINTERUPDATE 0x0245
     1.9 +#endif
    1.10  #ifndef WM_UNICHAR
    1.11  #define WM_UNICHAR 0x0109
    1.12  #endif
    1.13 @@ -523,12 +526,19 @@
    1.14          returnCode = 0;
    1.15          break;
    1.16  
    1.17 +    case WM_POINTERUPDATE:
    1.18 +        {
    1.19 +            data->last_pointer_update = lParam;
    1.20 +            break;
    1.21 +        }
    1.22 +
    1.23      case WM_MOUSEMOVE:
    1.24          {
    1.25              SDL_Mouse *mouse = SDL_GetMouse();
    1.26              if (!mouse->relative_mode || mouse->relative_mode_warp) {
    1.27                  /* Only generate mouse events for real mouse */
    1.28 -                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH) {
    1.29 +                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH &&
    1.30 +                    lParam != data->last_pointer_update) {
    1.31                      SDL_SendMouseMotion(data->window, 0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
    1.32                      if (isWin10FCUorNewer && mouse->relative_mode_warp) {
    1.33                          /* To work around #3931, Win10 bug introduced in Fall Creators Update, where
    1.34 @@ -563,7 +573,8 @@
    1.35          {
    1.36              SDL_Mouse *mouse = SDL_GetMouse();
    1.37              if (!mouse->relative_mode || mouse->relative_mode_warp) {
    1.38 -                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH) {
    1.39 +                if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH &&
    1.40 +                    lParam != data->last_pointer_update) {
    1.41                      WIN_CheckWParamMouseButtons(wParam, data, 0);
    1.42                  }
    1.43              }
    1.44 @@ -589,7 +600,8 @@
    1.45  
    1.46              /* Mouse data (ignoring synthetic mouse events generated for touchscreens) */
    1.47              if (inp.header.dwType == RIM_TYPEMOUSE) {
    1.48 -                if (GetMouseMessageSource() == SDL_MOUSE_EVENT_SOURCE_TOUCH) {
    1.49 +                if (GetMouseMessageSource() == SDL_MOUSE_EVENT_SOURCE_TOUCH ||
    1.50 +                    (GetMessageExtraInfo() & 0x82) == 0x82) {
    1.51                      break;
    1.52                  }
    1.53                  if (isRelative) {
     2.1 --- a/src/video/windows/SDL_windowswindow.c	Wed Mar 25 01:34:15 2020 -0400
     2.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Apr 06 19:21:56 2020 -0700
     2.3 @@ -188,6 +188,7 @@
     2.4      data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
     2.5      data->created = created;
     2.6      data->mouse_button_flags = 0;
     2.7 +    data->last_pointer_update = (LPARAM)-1;
     2.8      data->videodata = videodata;
     2.9      data->initializing = SDL_TRUE;
    2.10  
     3.1 --- a/src/video/windows/SDL_windowswindow.h	Wed Mar 25 01:34:15 2020 -0400
     3.2 +++ b/src/video/windows/SDL_windowswindow.h	Mon Apr 06 19:21:56 2020 -0700
     3.3 @@ -39,6 +39,7 @@
     3.4      WNDPROC wndproc;
     3.5      SDL_bool created;
     3.6      WPARAM mouse_button_flags;
     3.7 +    LPARAM last_pointer_update;
     3.8      SDL_bool initializing;
     3.9      SDL_bool expected_resize;
    3.10      SDL_bool in_border_change;