Skip to content

Commit 6e4241d

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
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 306966b commit 6e4241d

File tree

1 file changed

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

1 file changed

+32
-1
lines changed

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

Lines changed: 32 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,35 @@ 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+
*/
371+
372+
private static int getPointerSizeScaleFactor() {
373+
if (OsVersion.IS_WIN10_1809) {
374+
int[] cursorBaseSize = OS.readRegistryDwords(OS.HKEY_CURRENT_USER, "Control Panel\\Cursors", "CursorBaseSize");
375+
if (cursorBaseSize != null && cursorBaseSize.length > 0 && cursorBaseSize[0] > 0) {
376+
return cursorBaseSize[0] / 32;
377+
}
378+
}
379+
return 1;
380+
}
381+
352382
@Override
353383
void destroy () {
354384
device.deregisterResourceWithZoomSupport(this);
@@ -635,7 +665,8 @@ public ImageDataCursorHandleProvider(ImageData source, int hotspotX, int hotspot
635665

636666
@Override
637667
public CursorHandle createHandle(Device device, int zoom) {
638-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom, DEFAULT_ZOOM);
668+
int accessibilityFactor = getPointerSizeScaleFactor();
669+
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom * accessibilityFactor, DEFAULT_ZOOM);
639670
return setupCursorFromImageData(device, scaledSource, getHotpotXInPixels(zoom),
640671
getHotpotYInPixels(zoom));
641672
}

0 commit comments

Comments
 (0)