Skip to content

Commit 2db7bba

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 2db7bba

File tree

1 file changed

+36
-1
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+36
-1
lines changed

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

Lines changed: 36 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.internal.win32.version.*;
2223

2324
/**
2425
* Instances of this class manage operating system resources that
@@ -349,6 +350,39 @@ private void setHandleForZoomLevel(CursorHandle handle, Integer zoom) {
349350
}
350351
}
351352

353+
/**
354+
* Retrieves the scaling factor of the mouse pointer size as set in Windows
355+
* 10/11 "Settings > Accessibility > Mouse pointer and touch > Size".
356+
* <p>
357+
* This method reads the "CursorBaseSize" registry value under
358+
* {@code HKEY_CURRENT_USER\Control Panel\Cursors}. If this registry value
359+
* exists (introduced in Windows 10 version 1809 for accessibility cursor
360+
* scaling), the method computes the scale factor by dividing the base size by
361+
* the default system cursor size (32px). If the registry value is not present
362+
* or cannot be read, the method returns {@code 1} indicating default size.
363+
* <p>
364+
* <strong>Note:</strong> This approach is only valid for Windows 10 1809+ with
365+
* the modern accessibility pointer setting. For classic themes or older Windows
366+
* versions, this value may not be present or honored.
367+
*
368+
* @return the cursor scaling factor (e.g., 1 for default size, 2 for double
369+
* size, etc.)
370+
* @since 3.131
371+
*/
372+
public static int getPointerSizeScaleFactor() {
373+
final int defaultCursorSize = 32;
374+
int scaleFactor = 1; // Default: standard size
375+
376+
if (OsVersion.IS_WIN10_1809) {
377+
int[] cursorBaseSize = OS.readRegistryDwords(OS.HKEY_CURRENT_USER, "Control Panel\\Cursors", "CursorBaseSize");
378+
if (cursorBaseSize != null && cursorBaseSize.length > 0 && cursorBaseSize[0] > 0) {
379+
scaleFactor = cursorBaseSize[0] / defaultCursorSize;
380+
}
381+
}
382+
383+
return scaleFactor;
384+
}
385+
352386
@Override
353387
void destroy () {
354388
device.deregisterResourceWithZoomSupport(this);
@@ -635,7 +669,8 @@ public ImageDataCursorHandleProvider(ImageData source, int hotspotX, int hotspot
635669

636670
@Override
637671
public CursorHandle createHandle(Device device, int zoom) {
638-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom, DEFAULT_ZOOM);
672+
int accessibilityFactor = getPointerSizeScaleFactor();
673+
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom * accessibilityFactor, DEFAULT_ZOOM);
639674
return setupCursorFromImageData(device, scaledSource, getHotpotXInPixels(zoom),
640675
getHotpotYInPixels(zoom));
641676
}

0 commit comments

Comments
 (0)