Skip to content

Commit 4ee56bc

Browse files
Limit autoscale mode to quarter and exact only
swt applications will be limited to use autoscale modes quarter and exact only otherwise user will see an error message stating the incompatibility. Also the tests testing other autoscale values have been removed.
1 parent f01daf7 commit 4ee56bc

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
111111
}
112112

113113
@ParameterizedTest
114-
@CsvSource({ "0.5, 100, true", "1.0, 200, true", "2.0, 200, true", "2.0, quarter, true", "0.5, 100, false",
114+
@CsvSource({ "2.0, quarter, true", "0.5, 100, false",
115115
"1.0, 200, false", "2.0, 200, false", "2.0, quarter, false", })
116116
public void testAutoScaleImageData(float scaleFactor, String autoScale, boolean monitorSpecificScaling) {
117117
Win32DPIUtils.setMonitorSpecificScaling(monitorSpecificScaling);

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ public static Optional<AutoScaleMethod> forString(String s) {
5151

5252
private static String autoScaleValue;
5353

54-
private static final Set<String> ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact", "false");
54+
private static final Set<String> ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact");
55+
56+
/**
57+
* System property that enforces to use autoScale value despite incompatibility
58+
* For e.g. Monitor-specific scaling with int200 autoscale value
59+
*/
60+
private static final String SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK = "swt.autoScale.force";
5561
/**
5662
* System property to enable to scale the application on runtime
5763
* when a DPI change is detected.
@@ -128,20 +134,20 @@ static void setAutoScaleValue(String autoScaleValueArg) {
128134
*
129135
*/
130136
public static boolean isSetupCompatibleToMonitorSpecificScaling() {
131-
if (DPIUtil.getAutoScaleValue() == null) {
132-
return false;
133-
}
137+
// Per-monitor DPI supported only on Windows
138+
if (!"win32".equals(SWT.getPlatform())) {
139+
return false;
140+
}
134141

135-
if(ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(DPIUtil.getAutoScaleValue().toLowerCase())) {
136-
return true;
137-
}
138-
try {
139-
Integer.parseInt(DPIUtil.getAutoScaleValue());
140-
return true;
141-
} catch (NumberFormatException e) {
142-
// unsupported value, use default
143-
}
144-
return false;
142+
// Default means: treat as "quarter" (compatible)
143+
if (autoScaleValue == null || "true".equalsIgnoreCase(System.getProperty(SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK))) {
144+
return true;
145+
}
146+
147+
String value = autoScaleValue.toLowerCase(Locale.ROOT);
148+
149+
// Compatible only if one of the known values
150+
return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(value);
145151
}
146152

147153
public static boolean isMonitorSpecificScalingActive() {

0 commit comments

Comments
 (0)