Skip to content

Commit 6aedc48

Browse files
Slartibartyslouken
authored andcommitted
win32: Invalidate window message mouse button flags when reading buttons from raw input or GameInput
SDL2 would set a high bit in the mouse button flags to indicate when raw input had been read from, without this, if you hold down a mouse button and left raw input mode (leaving relative mode) the button would remain partially stuck, and would require two clicks to start producing mouse down events again. SDL3's raw input code was refactored to not use the mouse button flags, but forgot to invalidate the flags, causing this bug to manifest.
1 parent 81e3066 commit 6aedc48

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/video/windows/SDL_windowsevents.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL
701701
float fAmount = (float)amount / WHEEL_DELTA;
702702
SDL_SendMouseWheel(WIN_GetEventTimestamp(), window, mouseID, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
703703
}
704+
705+
/* Invalidate the mouse button flags. If we don't do this then disabling raw input
706+
will cause held down mouse buttons to persist when released. */
707+
windowdata->mouse_button_flags = (WPARAM)-1;
704708
}
705709
}
706710

src/video/windows/SDL_windowsgameinput.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ static void GAMEINPUT_InitialMouseReading(WIN_GameInputData *data, SDL_Window *w
279279
bool down = ((state.buttons & mask) != 0);
280280
SDL_SendMouseButton(timestamp, window, mouseID, GAMEINPUT_button_map[i], down);
281281
}
282+
283+
// Invalidate mouse button flags
284+
window->internal->mouse_button_flags = (WPARAM)-1;
282285
}
283286
}
284287

@@ -308,6 +311,9 @@ static void GAMEINPUT_HandleMouseDelta(WIN_GameInputData *data, SDL_Window *wind
308311
SDL_SendMouseButton(timestamp, window, mouseID, GAMEINPUT_button_map[i], down);
309312
}
310313
}
314+
315+
// Invalidate mouse button flags
316+
window->internal->mouse_button_flags = (WPARAM)-1;
311317
}
312318
if (delta.wheelX || delta.wheelY) {
313319
float fAmountX = (float)delta.wheelX / WHEEL_DELTA;

0 commit comments

Comments
 (0)