From 9c5086c47f3fee9cf4fd341493b18d1ba4be4d60 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Tue, 9 Sep 2025 14:16:44 +0200 Subject: [PATCH] SWT: Respect Windows accessibility cursor size setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, the mouse pointer size can be increased in Accessibility settings. Previously SWT always created cursors at their logical bitmap size (e.g. 16x16, 32x32), ignoring the accessibility scale. This change reads `CursorBaseSize` from `HKCU\Control Panel\Cursors` and uses it as a scale factor when creating SWT cursors. For example, with scale = 5, a 16px cursor bitmap is scaled to 80px before being displayed, matching the user’s configured pointer size. This aligns SWT custom cursors with the system accessibility setting and improves usability for users with enlarged cursors. --- .../org/eclipse/swt/graphics/Cursor.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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 52cb8d8002e..9227e6d1dc6 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 @@ -19,6 +19,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; +import org.eclipse.swt.internal.win32.version.*; /** * Instances of this class manage operating system resources that @@ -349,6 +350,35 @@ private void setHandleForZoomLevel(CursorHandle handle, Integer zoom) { } } +/** + * Retrieves the scaling factor of the mouse pointer size as set in Windows + * 10/11 "Settings > Accessibility > Mouse pointer and touch > Size". + *

+ * This method reads the "CursorBaseSize" registry value under + * {@code HKEY_CURRENT_USER\Control Panel\Cursors}. If this registry value + * exists (introduced in Windows 10 version 1809 for accessibility cursor + * scaling), the method computes the scale factor by dividing the base size by + * the default system cursor size (32px). If the registry value is not present + * or cannot be read, the method returns {@code 1} indicating default size. + *

+ * Note: This approach is only valid for Windows 10 1809+ with + * the modern accessibility pointer setting. For classic themes or older Windows + * versions, this value may not be present or honored. + * + * @return the cursor scaling factor (e.g., 1 for default size, 2 for double + * size, etc.) + */ + +private static int getPointerSizeScaleFactor() { + if (OsVersion.IS_WIN10_1809) { + int[] cursorBaseSize = OS.readRegistryDwords(OS.HKEY_CURRENT_USER, "Control Panel\\Cursors", "CursorBaseSize"); + if (cursorBaseSize != null && cursorBaseSize.length > 0 && cursorBaseSize[0] > 0) { + return cursorBaseSize[0] / 32; + } + } + return 1; +} + @Override void destroy () { device.deregisterResourceWithZoomSupport(this); @@ -635,7 +665,8 @@ public ImageDataCursorHandleProvider(ImageData source, int hotspotX, int hotspot @Override public CursorHandle createHandle(Device device, int zoom) { - ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom, DEFAULT_ZOOM); + int accessibilityFactor = getPointerSizeScaleFactor(); + ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom * accessibilityFactor, DEFAULT_ZOOM); return setupCursorFromImageData(device, scaledSource, getHotpotXInPixels(zoom), getHotpotYInPixels(zoom)); }