From b750b5108741a32cc7c777ea08683cc89ec3b426 Mon Sep 17 00:00:00 2001 From: fedejeanne Date: Mon, 28 Apr 2025 11:59:07 +0200 Subject: [PATCH] Use the native device zoom when getting the handle for a cursor #2057 Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/2057 --- .../Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java | 6 +++--- .../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, 8 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 719a4020a21..93044f9809d 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,13 @@ 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, int zoom) { +public static Long win32_getHandle (Cursor cursor) { + // The size of the cursor should match the zoom of the current monitor + int zoom = DPIUtil.getNativeDeviceZoom(); 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 bb9e8fe3ca5..64078dbf050 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, getZoom())); + OS.SetCursor (Cursor.win32_getHandle(cursor)); 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 18fefed3cf5..7b78661f142 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, getZoom())); + OS.SetCursor (Cursor.win32_getHandle(cursor)); 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 f340d38e918..ed9f6d7f39c 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, getZoom())); + if (inEvent) OS.SetCursor (Cursor.win32_getHandle(clientCursor)); } } @@ -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, getZoom())); + OS.SetCursor (Cursor.win32_getHandle(clientCursor)); 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 6e7d8001a0f..95e94bbfc39 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, getZoom()); + long hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : Cursor.win32_getHandle(cursor); OS.SetCursor (hCursor); }