Skip to content

Commit f17abb5

Browse files
SWT: Respect Windows accessibility cursor size setting
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.
1 parent fdbb769 commit f17abb5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.swt.*;
2020
import org.eclipse.swt.internal.*;
2121
import org.eclipse.swt.internal.win32.*;
22+
import org.eclipse.swt.widgets.*;
2223

2324
/**
2425
* Instances of this class manage operating system resources that
@@ -635,7 +636,8 @@ public ImageDataCursorHandleProvider(ImageData source, int hotspotX, int hotspot
635636

636637
@Override
637638
public CursorHandle createHandle(Device device, int zoom) {
638-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom, DEFAULT_ZOOM);
639+
int accessibilityFactor = Display.getPointerSizeScaleFactor();
640+
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom * accessibilityFactor, DEFAULT_ZOOM);
639641
return setupCursorFromImageData(device, scaledSource, getHotpotXInPixels(zoom),
640642
getHotpotYInPixels(zoom));
641643
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,39 @@ public static boolean isSystemDarkTheme () {
21922192
return isDarkTheme;
21932193
}
21942194

2195+
/**
2196+
* Retrieves the scaling factor of the mouse pointer size as set in Windows
2197+
* 10/11 "Settings > Accessibility > Mouse pointer and touch > Size".
2198+
* <p>
2199+
* This method reads the "CursorBaseSize" registry value under
2200+
* {@code HKEY_CURRENT_USER\Control Panel\Cursors}. If this registry value
2201+
* exists (introduced in Windows 10 version 1809 for accessibility cursor
2202+
* scaling), the method computes the scale factor by dividing the base size by
2203+
* the default system cursor size (32px). If the registry value is not present
2204+
* or cannot be read, the method returns {@code 1} indicating default size.
2205+
* <p>
2206+
* <strong>Note:</strong> This approach is only valid for Windows 10 1809+ with
2207+
* the modern accessibility pointer setting. For classic themes or older Windows
2208+
* versions, this value may not be present or honored.
2209+
*
2210+
* @return the cursor scaling factor (e.g., 1 for default size, 2 for double
2211+
* size, etc.)
2212+
* @since 3.131
2213+
*/
2214+
public static int getPointerSizeScaleFactor() {
2215+
final int defaultCursorSize = 32;
2216+
int scaleFactor = 1; // Default: standard size
2217+
2218+
if (OsVersion.IS_WIN10_1809) {
2219+
int[] cursorBaseSize = OS.readRegistryDwords(OS.HKEY_CURRENT_USER, "Control Panel\\Cursors", "CursorBaseSize");
2220+
if (cursorBaseSize != null && cursorBaseSize.length > 0 && cursorBaseSize[0] > 0) {
2221+
scaleFactor = cursorBaseSize[0] / defaultCursorSize;
2222+
}
2223+
}
2224+
2225+
return scaleFactor;
2226+
}
2227+
21952228
int getLastEventTime () {
21962229
return OS.GetMessageTime ();
21972230
}

0 commit comments

Comments
 (0)