Commit 301819cd1d7dac2d0e953a6f1780d234431d9f75

Yufei Huang 2021-11-08T20:34:20

SDL_windowsmouse.c: Fix WIN_CreateCursor does not scale with system cursor size preference

diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 031fcc0..54fdce9 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();
     }