Skip to content

Commit 5071736

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Limit autoscale mode for monitor-specific scaling to quarter and exact
SWT applications will be limited to use autoscale modes quarter and exact when having monitor-specific scaling enabled. With other, unsupported values the application will not start. To enforce application start with an incompatible autoscale mode, a new "force" value for the swt.autoScale.updateOnRuntime property is introduced. Also the tests testing other autoscale values have been removed.
1 parent 407cb9a commit 5071736

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
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: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ 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+
5556
/**
56-
* System property to enable to scale the application on runtime
57-
* when a DPI change is detected.
57+
* System property to enable to scale the application on runtime when a DPI
58+
* change is detected.
5859
* <ul>
60+
* <li>"force": the application is scaled on DPI changes even if an unsupported
61+
* value for swt.autoScale are defined. See allowed values
62+
* {@link #ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME}.</li>
5963
* <li>"true": the application is scaled on DPI changes</li>
6064
* <li>"false": the application will remain in its initial scaling</li>
6165
* </ul>
@@ -140,25 +144,19 @@ static void setAutoScaleValue(String autoScaleValueArg) {
140144
* scaling.
141145
*/
142146
public static boolean isSetupCompatibleToMonitorSpecificScaling() {
143-
if (DPIUtil.getAutoScaleValue() == null) {
147+
if (!"win32".equals(SWT.getPlatform())) {
144148
return false;
145149
}
146-
147-
if (ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(DPIUtil.getAutoScaleValue().toLowerCase())) {
148-
return true;
149-
}
150-
try {
151-
Integer.parseInt(DPIUtil.getAutoScaleValue());
150+
if (autoScaleValue == null || "force".equals(System.getProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME))) {
152151
return true;
153-
} catch (NumberFormatException e) {
154-
// unsupported value, use default
155152
}
156-
return false;
153+
String value = autoScaleValue.toLowerCase(Locale.ROOT);
154+
return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(value);
157155
}
158156

159157
public static boolean isMonitorSpecificScalingActive() {
160-
boolean updateOnRuntimeValue = Boolean.getBoolean (DPIUtil.SWT_AUTOSCALE_UPDATE_ON_RUNTIME);
161-
return updateOnRuntimeValue;
158+
String updateOnRuntimeValue = System.getProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME);
159+
return "force".equalsIgnoreCase(updateOnRuntimeValue) || "true".equalsIgnoreCase(updateOnRuntimeValue);
162160
}
163161

164162
public static int pixelToPoint(int size, int zoom) {

0 commit comments

Comments
 (0)