Skip to content

Commit

Permalink
[Win] Disallow autoscale mode "integer" for monitor-specific scaling
Browse files Browse the repository at this point in the history
The default auto-scale value is "integer"/"integer200", which makes
everything in the UI except fonts not scale according to the actual
native zoom value but according to a value rounded to 100 or 200. While
most code performing adaptations to zoom considers this for a static
zoom value applied to the whole application, it leads to hard-to-resolve
issues when scaling every shell according to the current monitor's zoom.

Since that autoscale mode is complex and should be replaced by uniform
scaling of everything (in particular when images are based on vector
graphics that can sharply be rendered for every zoom factor) anyway,
this is not to be supported by the monitor-specific scaling feature
currently being introduced for Windows. With this change, that mode will
thus be limited to reasonable autoscale modes like "quarter" and "exact"
or ones fixing the zoom value like specifying an explicit value or
"false".
  • Loading branch information
HeikoKlare committed Jan 13, 2025
1 parent c49cee7 commit 1900fcd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,34 @@ public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
return zoom;
}

public static boolean isAutoScaleOnRuntimeActive() {
public static boolean isMonitorSpecificScalingActive() {
return autoScaleOnRuntime;
}

public static void setAutoScaleForMonitorSpecificScaling() {
boolean isDefaultAutoScale = autoScaleValue == null;
if (isDefaultAutoScale) {
autoScaleValue = "quarter";
} else if (!isSupportedAutoScaleForMonitorSpecificScaling()) {
throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED,
"monitor-specific scaling is only implemented for auto-scale values \"quarter\", \"exact\", \"false\" or a concrete zoom value, but \""
+ autoScaleValue + "\" has been specified");
}
}

private static boolean isSupportedAutoScaleForMonitorSpecificScaling() {
switch (autoScaleValue) {
case "false", "quarter", "exact": return true;
}
try {
Integer.parseInt(autoScaleValue);
return true;
} catch (NumberFormatException e) {
// unsupported value, use default
}
return false;
}

/**
* AutoScale ImageDataProvider.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,9 @@ public void close () {
protected void create (DeviceData data) {
checkSubclass ();
checkDisplay (thread = Thread.currentThread (), true);
if (DPIUtil.isAutoScaleOnRuntimeActive()) {
if (DPIUtil.isMonitorSpecificScalingActive()) {
setRescalingAtRuntime(true);
DPIUtil.setAutoScaleForMonitorSpecificScaling();
}
createDisplay (data);
register (this);
Expand Down

0 comments on commit 1900fcd

Please sign in to comment.