From 66f8ada3b73227291c12dd05bfe10eb86198c960 Mon Sep 17 00:00:00 2001 From: fedejeanne Date: Mon, 5 May 2025 10:43:18 +0200 Subject: [PATCH] Do not use DPIUtil.getNativeDeviceZoom() to get the cursor handle #2057 Pass the native zoom to Cursor.win32_getHandle(Cursor, int) instead Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/2057 --- .../Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java | 5 ++--- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java | 2 +- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java | 2 +- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java | 4 ++-- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java index 93044f9809d..f1002ba50be 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java @@ -355,13 +355,12 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { * Get the handle for a cursor given a zoom level. * * @param cursor the cursor + * @param zoom zoom level (in %) of the monitor the cursor is currently in. * @return The handle of the cursor. * * @noreference This method is not intended to be referenced by clients. */ -public static Long win32_getHandle (Cursor cursor) { - // The size of the cursor should match the zoom of the current monitor - int zoom = DPIUtil.getNativeDeviceZoom(); +public static Long win32_getHandle (Cursor cursor, int zoom) { if (cursor.isDisposed()) { return cursor.handle; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index 64078dbf050..cf98f3bf2b4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -5475,7 +5475,7 @@ LRESULT WM_SETCURSOR (long wParam, long lParam) { if (control == null) return null; Cursor cursor = control.findCursor (); if (cursor != null) { - OS.SetCursor (Cursor.win32_getHandle(cursor)); + OS.SetCursor (Cursor.win32_getHandle(cursor, getNativeZoom())); return LRESULT.ONE; } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index 7b78661f142..3033af31782 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -2659,7 +2659,7 @@ LRESULT WM_SETCURSOR (long wParam, long lParam) { RECT rect = new RECT (); OS.GetClientRect (handle, rect); if (OS.PtInRect (rect, pt)) { - OS.SetCursor (Cursor.win32_getHandle(cursor)); + OS.SetCursor (Cursor.win32_getHandle(cursor, getNativeZoom())); switch (msg) { case OS.WM_LBUTTONDOWN: case OS.WM_RBUTTONDOWN: diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java index ed9f6d7f39c..11f841b8613 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java @@ -823,7 +823,7 @@ public void setCursor(Cursor newCursor) { checkWidget(); clientCursor = newCursor; if (newCursor != null) { - if (inEvent) OS.SetCursor (Cursor.win32_getHandle(clientCursor)); + if (inEvent) OS.SetCursor (Cursor.win32_getHandle(clientCursor, getNativeZoom())); } } @@ -892,7 +892,7 @@ long transparentProc (long hwnd, long msg, long wParam, long lParam) { break; case OS.WM_SETCURSOR: if (clientCursor != null) { - OS.SetCursor (Cursor.win32_getHandle(clientCursor)); + OS.SetCursor (Cursor.win32_getHandle(clientCursor, getNativeZoom())); return 1; } if (resizeCursor != 0) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index 95e94bbfc39..a7cf7cd9cae 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -4663,7 +4663,7 @@ void setCursor () { * is IDC_ARROW. */ Cursor cursor = findCursor (); - long hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : Cursor.win32_getHandle(cursor); + long hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : Cursor.win32_getHandle(cursor, getNativeZoom()); OS.SetCursor (hCursor); }