From 301819cd1d7dac2d0e953a6f1780d234431d9f75 Mon Sep 17 00:00:00 2001
From: Yufei Huang <[EMAIL REDACTED]>
Date: Mon, 8 Nov 2021 20:34:20 +0800
Subject: [PATCH] SDL_windowsmouse.c: Fix WIN_CreateCursor does not scale with
system cursor size preference
---
src/video/windows/SDL_windowsmouse.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 031fcc03ec..54fdce95fa 100644
--- a/src/video/windows/SDL_windowsmouse.c
+++ b/src/video/windows/SDL_windowsmouse.c
@@ -96,6 +96,7 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
const size_t pad = (sizeof (size_t) * 8); /* 32 or 64, or whatever. */
SDL_Cursor *cursor;
HICON hicon;
+ HICON hcursor;
HDC hdc;
BITMAPV4HEADER bmh;
LPVOID pixels;
@@ -150,11 +151,20 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
return NULL;
}
+ /* The cursor returned by CreateIconIndirect does not respect system cursor size
+ preference, use CopyImage to duplicate the cursor with desired sizes */
+ hcursor = CopyImage(hicon, IMAGE_CURSOR, 0, 0, LR_COPYDELETEORG | LR_DEFAULTSIZE);
+ if (!hcursor) {
+ DestroyIcon(hicon);
+ WIN_SetError("CopyImage()");
+ return NULL;
+ }
+
cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) {
- cursor->driverdata = hicon;
+ cursor->driverdata = hcursor;
} else {
- DestroyIcon(hicon);
+ DestroyIcon(hcursor);
SDL_OutOfMemory();
}