Skip to content

Commit

Permalink
windows: handle WM_POINTERCAPTURECHANGED events, fix maybe-undefined …
Browse files Browse the repository at this point in the history
…behavior.

Fixes libsdl-org#11843.
Fixes libsdl-org#11844.
  • Loading branch information
icculus committed Jan 6, 2025
1 parent c7584df commit 896f0a2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/video/windows/SDL_windowsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
#ifndef WM_POINTERLEAVE
#define WM_POINTERLEAVE 0x024A
#endif
#ifndef WM_POINTERCAPTURECHANGED
#define WM_POINTERCAPTURECHANGED 0x024C
#endif
#ifndef WM_UNICHAR
#define WM_UNICHAR 0x0109
#endif
Expand Down Expand Up @@ -1163,25 +1166,25 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
returnCode = 0;
} break;

case WM_POINTERCAPTURECHANGED:
case WM_POINTERLEAVE:
{
const UINT32 pointerid = GET_POINTERID_WPARAM(wParam);
void *hpointer = (void *) (size_t) pointerid;
const SDL_PenID pen = SDL_FindPenByHandle(hpointer);
if (pen == 0) {
break; // not a pen, or not a pen we already knew about.
}

// if this just left the _window_, we don't care. If this is no longer visible to the tablet, time to remove it!
if (!IS_POINTER_INCONTACT_WPARAM(wParam)) {
SDL_RemovePenDevice(WIN_GetEventTimestamp(), pen);
if (pen != 0) {
// if this just left the _window_, we don't care. If this is no longer visible to the tablet, time to remove it!
if ((msg == WM_POINTERCAPTURECHANGED) || !IS_POINTER_INCONTACT_WPARAM(wParam)) {
SDL_RemovePenDevice(WIN_GetEventTimestamp(), pen);
}
}
returnCode = 0;
} break;

case WM_POINTERUPDATE: {
POINTER_INPUT_TYPE pointer_type = PT_POINTER;
if (!data->videodata->GetPointerType || !data->videodata->GetPointerType(GET_POINTERID_WPARAM(wParam), &pointer_type)) {
returnCode = 0;
break; // oh well.
}

Expand All @@ -1195,6 +1198,8 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara

case WM_POINTERDOWN:
case WM_POINTERUP: {
returnCode = 0; // always mark this event handled, so it doesn't go to DefWindowProc (see #11843).

POINTER_PEN_INFO pen_info;
const UINT32 pointerid = GET_POINTERID_WPARAM(wParam);
void *hpointer = (void *) (size_t) pointerid;
Expand Down Expand Up @@ -1242,8 +1247,6 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
if (msg == WM_POINTERDOWN) {
SDL_SendPenTouch(timestamp, pen, window, (pen_info.penFlags & PEN_FLAG_INVERTED) != 0, true);
}

returnCode = 0;
} break;

case WM_MOUSEMOVE:
Expand Down

0 comments on commit 896f0a2

Please sign in to comment.