From 2a946832bac72592f85d25cdb32f02b1bb841296 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 5 Jul 2023 11:05:48 -0700
Subject: [PATCH] Added GetClientScreenRect() and fixed build for C89 compilers
(cherry picked from commit 61ff86617ac9aa86e843aacd29b060b628bf9456)
---
src/video/windows/SDL_windowswindow.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 27f5223ce99e..371b79ee45bd 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -1273,6 +1273,13 @@ void WIN_OnWindowEnter(_THIS, SDL_Window *window)
}
}
+static BOOL GetClientScreenRect(HWND hwnd, RECT *rect)
+{
+ return GetClientRect(hwnd, rect) && /* RECT( left , top , right , bottom ) */
+ ClientToScreen(hwnd, (LPPOINT)rect) && /* POINT( left , top ) */
+ ClientToScreen(hwnd, (LPPOINT)rect + 1); /* POINT( right , bottom ) */
+}
+
void WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
@@ -1293,9 +1300,7 @@ void WIN_UpdateClipCursor(SDL_Window *window)
(window->mouse_rect.w > 0 && window->mouse_rect.h > 0)) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp && data->mouse_relative_mode_center) {
- if (GetClientRect(data->hwnd, &rect)) { /* RECT( left , top , right , bottom ) */
- ClientToScreen(data->hwnd, (LPPOINT)&rect); /* POINT( left , top ) */
- ClientToScreen(data->hwnd, (LPPOINT)&rect + 1); /* POINT( right , bottom ) */
+ if (GetClientScreenRect(data->hwnd, &rect)) {
/* WIN_WarpCursor() jitters by +1, and remote desktop warp wobble is +/- 1 */
LONG remote_desktop_adjustment = GetSystemMetrics(SM_REMOTESESSION) ? 2 : 0;
LONG cx, cy;
@@ -1316,9 +1321,7 @@ void WIN_UpdateClipCursor(SDL_Window *window)
}
}
} else {
- if (GetClientRect(data->hwnd, &rect)) {
- ClientToScreen(data->hwnd, (LPPOINT)&rect);
- ClientToScreen(data->hwnd, (LPPOINT)&rect + 1);
+ if (GetClientScreenRect(data->hwnd, &rect)) {
if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) {
SDL_Rect mouse_rect_win_client;
RECT mouse_rect, intersection;