Skip to content

Commit cb6272e

Browse files
Susko3icculus
authored andcommitted
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.
1 parent dccf486 commit cb6272e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/video/windows/SDL_windowsevents.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
579579
return;
580580
}
581581

582+
SDL_Mouse *mouse = SDL_GetMouse();
583+
if (!mouse) {
584+
return;
585+
}
586+
582587
if (GetMouseMessageSource(rawmouse->ulExtraInformation) != SDL_MOUSE_EVENT_SOURCE_MOUSE ||
583588
(SDL_TouchDevicesAvailable() && (rawmouse->ulExtraInformation & 0x80) == 0x80)) {
584589
return;
@@ -648,14 +653,22 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
648653
}
649654
}
650655
}
651-
} else {
656+
} else if (mouse->pen_mouse_events) {
652657
const int MAXIMUM_TABLET_RELATIVE_MOTION = 32;
653658
if (SDL_abs(relX) > MAXIMUM_TABLET_RELATIVE_MOTION ||
654659
SDL_abs(relY) > MAXIMUM_TABLET_RELATIVE_MOTION) {
655660
/* Ignore this motion, probably a pen lift and drop */
656661
} else {
657662
SDL_SendMouseMotion(timestamp, window, mouseID, true, (float)relX, (float)relY);
658663
}
664+
} else {
665+
int screen_x = virtual_desktop ? GetSystemMetrics(SM_XVIRTUALSCREEN) : 0;
666+
int screen_y = virtual_desktop ? GetSystemMetrics(SM_YVIRTUALSCREEN) : 0;
667+
668+
if (!data->raw_input_fake_pen_id) {
669+
data->raw_input_fake_pen_id = SDL_AddPenDevice(timestamp, "raw mouse input", window, NULL, (void *)(size_t)-1);
670+
}
671+
SDL_SendPenMotion(timestamp, data->raw_input_fake_pen_id, window, (float)(x + screen_x - window->x), (float)(y + screen_y - window->y));
659672
}
660673

661674
data->last_raw_mouse_position.x = x;

src/video/windows/SDL_windowsrawinput.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ static DWORD WINAPI WIN_RawInputThread(LPVOID param)
118118
WIN_PollRawInput(_this, poll_start);
119119
}
120120

121+
if (_this->internal->raw_input_fake_pen_id) {
122+
SDL_RemovePenDevice(0, SDL_GetKeyboardFocus(), _this->internal->raw_input_fake_pen_id);
123+
_this->internal->raw_input_fake_pen_id = 0;
124+
}
125+
121126
devices[0].dwFlags |= RIDEV_REMOVE;
122127
devices[0].hwndTarget = NULL;
123128
devices[1].dwFlags |= RIDEV_REMOVE;

src/video/windows/SDL_windowsvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ struct SDL_VideoData
594594
bool raw_keyboard_flag_nohotkeys;
595595
bool pending_E1_key_sequence;
596596
Uint32 raw_input_enabled;
597+
SDL_PenID raw_input_fake_pen_id;
597598

598599
WIN_GameInputData *gameinput_context;
599600

0 commit comments

Comments
 (0)