From 55484ef02303e9605b8b7041b84bfb9d70af2663 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 1 Mar 2025 12:37:02 -0800
Subject: [PATCH] Moved WIN_UpdateMouseCapture() to be with the other mouse
functions
---
src/video/windows/SDL_windowsevents.c | 72 +++++++++++++--------------
1 file changed, 35 insertions(+), 37 deletions(-)
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index 84c8ff72cddcf..f271db85b828e 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -317,6 +317,41 @@ static void WIN_CheckAsyncMouseRelease(Uint64 timestamp, SDL_WindowData *data)
data->mouse_button_flags = (WPARAM)-1;
}
+static void WIN_UpdateMouseCapture(void)
+{
+ SDL_Window *focusWindow = SDL_GetKeyboardFocus();
+
+ if (focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
+ SDL_WindowData *data = focusWindow->internal;
+
+ if (!data->mouse_tracked) {
+ POINT cursorPos;
+
+ if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
+ bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
+ SDL_MouseID mouseID = SDL_GLOBAL_MOUSE_ID;
+
+ SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, false, (float)cursorPos.x, (float)cursorPos.y);
+ SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
+ !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT,
+ (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0);
+ SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
+ !swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT,
+ (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0);
+ SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
+ SDL_BUTTON_MIDDLE,
+ (GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0);
+ SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
+ SDL_BUTTON_X1,
+ (GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0);
+ SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
+ SDL_BUTTON_X2,
+ (GetAsyncKeyState(VK_XBUTTON2) & 0x8000) != 0);
+ }
+ }
+ }
+}
+
static void WIN_UpdateFocus(SDL_Window *window, bool expect_focus)
{
SDL_WindowData *data = window->internal;
@@ -2399,43 +2434,6 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
}
}
-#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
-static void WIN_UpdateMouseCapture(void)
-{
- SDL_Window *focusWindow = SDL_GetKeyboardFocus();
-
- if (focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
- SDL_WindowData *data = focusWindow->internal;
-
- if (!data->mouse_tracked) {
- POINT cursorPos;
-
- if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
- bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
- SDL_MouseID mouseID = SDL_GLOBAL_MOUSE_ID;
-
- SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, false, (float)cursorPos.x, (float)cursorPos.y);
- SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
- !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT,
- (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0);
- SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
- !swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT,
- (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0);
- SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
- SDL_BUTTON_MIDDLE,
- (GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0);
- SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
- SDL_BUTTON_X1,
- (GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0);
- SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
- SDL_BUTTON_X2,
- (GetAsyncKeyState(VK_XBUTTON2) & 0x8000) != 0);
- }
- }
- }
-}
-#endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
-
int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS)
{
if (g_WindowsEnableMessageLoop) {