Skip to content

Commit 3d00780

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 db8608f commit 3d00780

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
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: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +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+
5556
/**
5657
* System property to enable to scale the application on runtime
5758
* when a DPI change is detected.
5859
* <ul>
60+
* <li>"force": the application is scaled on DPI changes even on values that are normally not allowed for auto-scaling. See allowed values {@link #ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME}.</li>
5961
* <li>"true": the application is scaled on DPI changes</li>
6062
* <li>"false": the application will remain in its initial scaling</li>
6163
* </ul>
@@ -140,25 +142,19 @@ static void setAutoScaleValue(String autoScaleValueArg) {
140142
* scaling.
141143
*/
142144
public static boolean isSetupCompatibleToMonitorSpecificScaling() {
143-
if (DPIUtil.getAutoScaleValue() == null) {
145+
if (!"win32".equals(SWT.getPlatform())) {
144146
return false;
145147
}
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());
148+
if (autoScaleValue == null || "force".equals(System.getProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME))) {
152149
return true;
153-
} catch (NumberFormatException e) {
154-
// unsupported value, use default
155150
}
156-
return false;
151+
String value = autoScaleValue.toLowerCase(Locale.ROOT);
152+
return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(value);
157153
}
158154

159155
public static boolean isMonitorSpecificScalingActive() {
160-
boolean updateOnRuntimeValue = Boolean.getBoolean (DPIUtil.SWT_AUTOSCALE_UPDATE_ON_RUNTIME);
161-
return updateOnRuntimeValue;
156+
String updateOnRunTimeValue = System.getProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME);
157+
return "force".equalsIgnoreCase(updateOnRunTimeValue) || "true".equalsIgnoreCase(updateOnRunTimeValue);
162158
}
163159

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

0 commit comments

Comments
 (0)