diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/ResetMonitorSpecificScalingExtension.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/ResetMonitorSpecificScalingExtension.java index ae0b70eed1..1434a8d8e0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/ResetMonitorSpecificScalingExtension.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/internal/ResetMonitorSpecificScalingExtension.java @@ -25,7 +25,7 @@ protected ResetMonitorSpecificScalingExtension() { @Override public void beforeEach(ExtensionContext context) throws Exception { - wasMonitorSpecificScalingActive = Win32DPIUtils.isMonitorSpecificScalingActive(); + wasMonitorSpecificScalingActive = DPIUtil.isMonitorSpecificScalingActive(); Display.getDefault().dispose(); } 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 fced84b43e..546f1ebe0a 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 @@ -50,6 +50,17 @@ public static Optional forString(String s) { private static AutoScaleMethod autoScaleMethod; private static String autoScaleValue; + /** + * System property to enable to scale the application on runtime + * when a DPI change is detected. + * + * Important: This flag is only parsed and used on Win32. Setting it to + * true on GTK or cocoa will be ignored. + */ + static final String SWT_AUTOSCALE_UPDATE_ON_RUNTIME = "swt.autoScale.updateOnRuntime"; /** * System property that controls the autoScale functionality. @@ -87,9 +98,17 @@ public static Optional forString(String s) { */ private static final String SWT_AUTOSCALE_METHOD = "swt.autoScale.method"; + /** + * 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"; + + private static final Set ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set.of("quarter", "exact"); + static { autoScaleValue = System.getProperty (SWT_AUTOSCALE); - + setUseSmoothScalingByDefaultProvider(() -> isMonitorSpecificScalingActive()); String value = System.getProperty (SWT_AUTOSCALE_METHOD); AUTO_SCALE_METHOD_SETTING = AutoScaleMethod.forString(value).orElse(AutoScaleMethod.AUTO); autoScaleMethod = AUTO_SCALE_METHOD_SETTING != AutoScaleMethod.AUTO ? AUTO_SCALE_METHOD_SETTING : AutoScaleMethod.NEAREST; @@ -103,6 +122,11 @@ static void setAutoScaleValue(String autoScaleValueArg) { autoScaleValue = autoScaleValueArg; } +public static boolean isMonitorSpecificScalingActive() { + boolean updateOnRuntimeValue = Boolean.getBoolean (DPIUtil.SWT_AUTOSCALE_UPDATE_ON_RUNTIME); + return updateOnRuntimeValue; +} + public static int pixelToPoint(int size, int zoom) { if (zoom == 100 || size == SWT.DEFAULT) return size; float scaleFactor = getScalingFactor (zoom); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java index 078e81ac02..4917b2a036 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java @@ -33,21 +33,6 @@ * @noreference This class is not intended to be referenced by clients */ public class Win32DPIUtils { - /** - * System property to enable to scale the application on runtime - * when a DPI change is detected. - *
    - *
  • "true": the application is scaled on DPI changes
  • - *
  • "false": the application will remain in its initial scaling
  • - *
- * Important: This flag is only parsed and used on Win32. Setting it to - * true on GTK or cocoa will be ignored. - */ - private static final String SWT_AUTOSCALE_UPDATE_ON_RUNTIME = "swt.autoScale.updateOnRuntime"; - - static { - DPIUtil.setUseSmoothScalingByDefaultProvider(() -> isMonitorSpecificScalingActive()); - } public static boolean setDPIAwareness(int desiredDpiAwareness) { if (desiredDpiAwareness == OS.GetThreadDpiAwarenessContext()) { @@ -278,7 +263,7 @@ public static Rectangle pointToPixel(Drawable drawable, Rectangle rect, int zoom } public static void setMonitorSpecificScaling(boolean activate) { - System.setProperty(SWT_AUTOSCALE_UPDATE_ON_RUNTIME, Boolean.toString(activate)); + System.setProperty(DPIUtil.SWT_AUTOSCALE_UPDATE_ON_RUNTIME, Boolean.toString(activate)); } public static void setAutoScaleForMonitorSpecificScaling() { @@ -322,10 +307,6 @@ private static boolean isSupportedAutoScaleForMonitorSpecificScaling() { return false; } - public static boolean isMonitorSpecificScalingActive() { - boolean updateOnRuntimeValue = Boolean.getBoolean (SWT_AUTOSCALE_UPDATE_ON_RUNTIME); - return updateOnRuntimeValue; - } public static int getPrimaryMonitorZoomAtStartup() { long hDC = OS.GetDC(0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index a2b325bdbb..56132ce466 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -949,7 +949,7 @@ public void close () { protected void create (DeviceData data) { checkSubclass (); checkDisplay (thread = Thread.currentThread (), true); - if (Win32DPIUtils.isMonitorSpecificScalingActive()) { + if (DPIUtil.isMonitorSpecificScalingActive()) { setMonitorSpecificScaling(true); Win32DPIUtils.setAutoScaleForMonitorSpecificScaling(); }