Browse Source

windows: Treat absolute mouse as pen events when SDL_HINT_PEN_MOUSE_EVENTS=0.

Some caveats:

- the fake pen will leave proximity only when relative mode is disabled
- unsure if detecting proximity is even possible from raw mouse input

Fixes #12324.
Susko3 9 months ago
parent
commit
cb6272ed2d

+ 14 - 1
src/video/windows/SDL_windowsevents.c

@@ -579,6 +579,11 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
         return;
         return;
     }
     }
 
 
+    SDL_Mouse *mouse = SDL_GetMouse();
+    if (!mouse) {
+        return;
+    }
+
     if (GetMouseMessageSource(rawmouse->ulExtraInformation) != SDL_MOUSE_EVENT_SOURCE_MOUSE ||
     if (GetMouseMessageSource(rawmouse->ulExtraInformation) != SDL_MOUSE_EVENT_SOURCE_MOUSE ||
         (SDL_TouchDevicesAvailable() && (rawmouse->ulExtraInformation & 0x80) == 0x80)) {
         (SDL_TouchDevicesAvailable() && (rawmouse->ulExtraInformation & 0x80) == 0x80)) {
         return;
         return;
@@ -648,7 +653,7 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
                         }
                         }
                     }
                     }
                 }
                 }
-            } else {
+            } else if (mouse->pen_mouse_events) {
                 const int MAXIMUM_TABLET_RELATIVE_MOTION = 32;
                 const int MAXIMUM_TABLET_RELATIVE_MOTION = 32;
                 if (SDL_abs(relX) > MAXIMUM_TABLET_RELATIVE_MOTION ||
                 if (SDL_abs(relX) > MAXIMUM_TABLET_RELATIVE_MOTION ||
                     SDL_abs(relY) > MAXIMUM_TABLET_RELATIVE_MOTION) {
                     SDL_abs(relY) > MAXIMUM_TABLET_RELATIVE_MOTION) {
@@ -656,6 +661,14 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
                 } else {
                 } else {
                     SDL_SendMouseMotion(timestamp, window, mouseID, true, (float)relX, (float)relY);
                     SDL_SendMouseMotion(timestamp, window, mouseID, true, (float)relX, (float)relY);
                 }
                 }
+            } else {
+                int screen_x = virtual_desktop ? GetSystemMetrics(SM_XVIRTUALSCREEN) : 0;
+                int screen_y = virtual_desktop ? GetSystemMetrics(SM_YVIRTUALSCREEN) : 0;
+
+                if (!data->raw_input_fake_pen_id) {
+                    data->raw_input_fake_pen_id = SDL_AddPenDevice(timestamp, "raw mouse input", window, NULL, (void *)(size_t)-1);
+                }
+                SDL_SendPenMotion(timestamp, data->raw_input_fake_pen_id, window, (float)(x + screen_x - window->x), (float)(y + screen_y - window->y));
             }
             }
 
 
             data->last_raw_mouse_position.x = x;
             data->last_raw_mouse_position.x = x;

+ 5 - 0
src/video/windows/SDL_windowsrawinput.c

@@ -118,6 +118,11 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
         WIN_PollRawInput(_this, poll_start);
         WIN_PollRawInput(_this, poll_start);
     }
     }
 
 
+    if (_this->internal->raw_input_fake_pen_id) {
+        SDL_RemovePenDevice(0, SDL_GetKeyboardFocus(), _this->internal->raw_input_fake_pen_id);
+        _this->internal->raw_input_fake_pen_id = 0;
+    }
+
     devices[0].dwFlags |= RIDEV_REMOVE;
     devices[0].dwFlags |= RIDEV_REMOVE;
     devices[0].hwndTarget = NULL;
     devices[0].hwndTarget = NULL;
     devices[1].dwFlags |= RIDEV_REMOVE;
     devices[1].dwFlags |= RIDEV_REMOVE;

+ 1 - 0
src/video/windows/SDL_windowsvideo.h

@@ -594,6 +594,7 @@ struct SDL_VideoData
     bool raw_keyboard_flag_nohotkeys;
     bool raw_keyboard_flag_nohotkeys;
     bool pending_E1_key_sequence;
     bool pending_E1_key_sequence;
     Uint32 raw_input_enabled;
     Uint32 raw_input_enabled;
+    SDL_PenID raw_input_fake_pen_id;
 
 
     WIN_GameInputData *gameinput_context;
     WIN_GameInputData *gameinput_context;