Skip to content

Custom cursors not correct sized with specific auto-scale settings #357

@HeikoKlare

Description

@HeikoKlare

Description
Custom cursors only seem to be sized correctly when DPIUtil's native zoom and device zoom are equals (such as when swt.autoScale==quarter (either explicitly or implicitly when monitor-specific scaling is enabled).
In other cases, the cursor is supposed to sized according to device zoom but is actually sized according to native zoom, resulting in an unexpected cursor size.

See also:

Reproduction
A reproduction is given in eclipse-platform/eclipse.platform.swt#2308

Expected Behavior
Custom cursors should always be sized according to the current device zoom (either the global one when monitor-specific scaling is disabled or otherwise the one that is current for the monitor of the control the cursor belongs to).

The behavior should particularly be validated for different combinations of auto-scale settings in which native zoom and device zoom are not the same, such as:

  • Monitor-specific scaling disabled, auto-scaling mode integer200 (default), some fractional primary monitor zoom (such as 150%) and some other monitor with a different scale value, then test the cursor on both monitors (this conforms to the default SWT configuration)
  • Monitor specific scaling disabled, scaling set to a specific value (such as swt.autoScale=200) while the primary monitor zoom has a different value (such as 150%), then test the cursor on both monitors (can be achieved with SWT configuration: -Dswt.autoScale=200)
  • Monitor specific-scaling enabled, scaling set to a specific value (such as swt.autoScale=200) while having two monitors with other soome values (e.g., 125% and 150%), then test the cursor on both monitors (can be achieved with SWT configuration: -Dswt.autoScale.updateOnRuntime=true -Dswt.autoScale=200)

For the sake of avoiding regressions, behavior should also be tested for the cases in which it currently works, i.e., without monitor-specific scaling and swt.autoScale=quarter and with monitor-specific scaling enabled, both tested with multiple monitors having different fractional zooms.

Additional knowledge
The issue seems to be caused by the native zoom (of the widget) is used for sizing the cursor instead of using a zoom value according to the device zoom.
One affected place in the code is this:
https://github.com/eclipse-platform/eclipse.platform.swt/blob/2ddc1ad4e2ca9f3988abc479026a34a29d21da96/bundles/org.eclipse.swt/Eclipse%20SWT/win32/org/eclipse/swt/widgets/Control.java#L5476-L5488
It might be a solution to replace the SetCursor call with this:

OS.SetCursor (Cursor.win32_getHandle(cursor, DPIUtil.getZoomForAutoscaleProperty(getNativeZoom())));

The relevant places are probably the ones that have been touched by this PR:

We need to make sure that we capture all those places and not only, e.g., the one explicitly mentioned above.

Also note that simply using DPIUtil.getDeviceZoom() would not be a solution as it does not take the current monitor into account, thus leading to wrong cursor sizes when monitor-specific scaling is enabled.

Metadata

Metadata

Labels

HiDPIA HiDPI-Related Issue or FeatureSWTIssue for SWTregression

Type

Projects

Status

✅ Approved

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions