diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java index 66f0b3c400e..ecce8aff23d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java @@ -111,7 +111,7 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() { } @ParameterizedTest - @CsvSource({ "0.5, 100, true", "1.0, 200, true", "2.0, 200, true", "2.0, quarter, true", "0.5, 100, false", + @CsvSource({ "2.0, quarter, true", "0.5, 100, false", "1.0, 200, false", "2.0, 200, false", "2.0, quarter, false", }) public void testAutoScaleImageData(float scaleFactor, String autoScale, boolean monitorSpecificScaling) { Win32DPIUtils.setMonitorSpecificScaling(monitorSpecificScaling); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index eb407d39f64..66b3e7107df 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -51,7 +51,14 @@ public static Optional forString(String s) { private static String autoScaleValue; - private static final Set ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact", "false"); + private static final Set ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact"); + + /** + * System property that enforces to use autoScale value despite incompatibility + * For e.g. Monitor-specific scaling with int200 autoscale value + */ + private static final String SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK = "swt.autoScale.force"; + /** * System property to enable to scale the application on runtime * when a DPI change is detected. @@ -140,20 +147,20 @@ static void setAutoScaleValue(String autoScaleValueArg) { * scaling. */ public static boolean isSetupCompatibleToMonitorSpecificScaling() { - if (DPIUtil.getAutoScaleValue() == null) { + // Per-monitor DPI supported only on Windows + if (!"win32".equals(SWT.getPlatform())) { return false; } - if (ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(DPIUtil.getAutoScaleValue().toLowerCase())) { + // Default means: treat as "quarter" (compatible) + if (autoScaleValue == null || "true".equalsIgnoreCase(System.getProperty(SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK))) { return true; } - try { - Integer.parseInt(DPIUtil.getAutoScaleValue()); - return true; - } catch (NumberFormatException e) { - // unsupported value, use default - } - return false; + + String value = autoScaleValue.toLowerCase(Locale.ROOT); + + // Compatible only if one of the known values + return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME.contains(value); } public static boolean isMonitorSpecificScalingActive() {