Skip to content

Commit 0fa596c

Browse files
committed
[Win] Disallow autoscale mode "integer" for monitor-specific scaling
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".
1 parent a6dd128 commit 0fa596c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,52 @@ public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
650650
return zoom;
651651
}
652652

653-
public static boolean isAutoScaleOnRuntimeActive() {
653+
public static boolean isMonitorSpecificScalingActive() {
654654
boolean updateOnRuntimeValue = Boolean.getBoolean (SWT_AUTOSCALE_UPDATE_ON_RUNTIME);
655655
return updateOnRuntimeValue;
656656
}
657657

658+
public static void setAutoScaleForMonitorSpecificScaling() {
659+
boolean isDefaultAutoScale = autoScaleValue == null;
660+
if (isDefaultAutoScale) {
661+
autoScaleValue = "quarter";
662+
} else if (!isSupportedAutoScaleForMonitorSpecificScaling()) {
663+
throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED,
664+
"monitor-specific scaling is only implemented for auto-scale values \"quarter\", \"exact\", \"false\" or a concrete zoom value, but \""
665+
+ autoScaleValue + "\" has been specified");
666+
}
667+
}
668+
669+
/**
670+
* Monitor-specific scaling on Windows only supports auto-scale modes in which
671+
* all elements (font, images, control bounds etc.) are scaled equally or almost
672+
* equally. The previously default mode "integer"/"integer200", which rounded
673+
* the scale factor for everything but fonts to multiples of 100, is complex and
674+
* difficult to realize with monitor-specific rescaling of UI elements. Since a
675+
* uniform scale factor for everything should perspectively be used anyway,
676+
* there will be support for complex auto-scale modes for monitor-specific
677+
* scaling.
678+
*
679+
* The supported modes are "quarter" and "exact" or explicit zoom values given
680+
* by the value itself or "false". Every other value will be treated as
681+
* "integer"/"integer200" and is thus not supported.
682+
*/
683+
private static boolean isSupportedAutoScaleForMonitorSpecificScaling() {
684+
if (autoScaleValue == null) {
685+
return false;
686+
}
687+
switch (autoScaleValue.toLowerCase()) {
688+
case "false", "quarter", "exact": return true;
689+
}
690+
try {
691+
Integer.parseInt(autoScaleValue);
692+
return true;
693+
} catch (NumberFormatException e) {
694+
// unsupported value, use default
695+
}
696+
return false;
697+
}
698+
658699
/**
659700
* AutoScale ImageDataProvider.
660701
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,9 @@ public void close () {
948948
protected void create (DeviceData data) {
949949
checkSubclass ();
950950
checkDisplay (thread = Thread.currentThread (), true);
951-
if (DPIUtil.isAutoScaleOnRuntimeActive()) {
951+
if (DPIUtil.isMonitorSpecificScalingActive()) {
952952
setRescalingAtRuntime(true);
953+
DPIUtil.setAutoScaleForMonitorSpecificScaling();
953954
}
954955
createDisplay (data);
955956
register (this);

0 commit comments

Comments
 (0)