@@ -50,6 +50,17 @@ public static Optional<AutoScaleMethod> forString(String s) {
5050 private static AutoScaleMethod autoScaleMethod ;
5151
5252 private static String autoScaleValue ;
53+ /**
54+ * System property to enable to scale the application on runtime
55+ * when a DPI change is detected.
56+ * <ul>
57+ * <li>"true": the application is scaled on DPI changes</li>
58+ * <li>"false": the application will remain in its initial scaling</li>
59+ * </ul>
60+ * <b>Important:</b> This flag is only parsed and used on Win32. Setting it to
61+ * true on GTK or cocoa will be ignored.
62+ */
63+ static final String SWT_AUTOSCALE_UPDATE_ON_RUNTIME = "swt.autoScale.updateOnRuntime" ;
5364
5465 /**
5566 * System property that controls the autoScale functionality.
@@ -87,6 +98,14 @@ public static Optional<AutoScaleMethod> forString(String s) {
8798 */
8899 private static final String SWT_AUTOSCALE_METHOD = "swt.autoScale.method" ;
89100
101+ /**
102+ * System property that enforces to use autoScale value despite incompatibility
103+ * For e.g. Monitor-specific scaling with int200 autoscale value
104+ */
105+ private static final String SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK = "swt.autoScale.force" ;
106+
107+ private static final Set <String > ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME = Set .of ("quarter" , "exact" );
108+
90109 static {
91110 autoScaleValue = System .getProperty (SWT_AUTOSCALE );
92111
@@ -95,14 +114,57 @@ public static Optional<AutoScaleMethod> forString(String s) {
95114 autoScaleMethod = AUTO_SCALE_METHOD_SETTING != AutoScaleMethod .AUTO ? AUTO_SCALE_METHOD_SETTING : AutoScaleMethod .NEAREST ;
96115 }
97116
98- static String getAutoScaleValue () {
117+ public static String getAutoScaleValue () {
99118 return autoScaleValue ;
100119}
101120
102121static void setAutoScaleValue (String autoScaleValueArg ) {
103122 autoScaleValue = autoScaleValueArg ;
104123}
105124
125+ /**
126+ * Returns {@code true} only if the current setup is compatible
127+ * with monitor-specific scaling. Returns {@code false} if:
128+ * <ul>
129+ * <li>Not running on Windows</li>
130+ * <li>The current auto-scale mode is incompatible</li>
131+ * </ul>
132+ *
133+ * <p>Allowed values: {@code false}, {@code quarter}, {@code exact}.
134+ *
135+ */
136+ public static boolean isSetupCompatibleToMonitorSpecificScaling () {
137+ if ("true" .equalsIgnoreCase (System .getProperty (SWT_AUTOSCALE_DISABLE_COMPATIBILITY_CHECK ))) {
138+ return true ;
139+ }
140+ // Per-monitor DPI supported only on Windows and when monitor
141+ if (!"win32" .equals (SWT .getPlatform ())) {
142+ return false ;
143+ }
144+
145+ // Default means: treat as "quarter" (compatible)
146+ if (autoScaleValue == null ) {
147+ return true ;
148+ }
149+
150+ String value = autoScaleValue .toLowerCase (Locale .ROOT );
151+
152+ // Compatible only if one of the known values
153+ return ALLOWED_AUTOSCALE_VALUES_FOR_UPDATE_ON_RUNTIME .contains (value );
154+ }
155+
156+ public static void setAutoScaleForMonitorSpecificScaling () {
157+ boolean isDefaultAutoScale = DPIUtil .getAutoScaleValue () == null ;
158+ if (isDefaultAutoScale ) {
159+ DPIUtil .setAutoScaleValue ("quarter" );
160+ }
161+ }
162+
163+ public static boolean isMonitorSpecificScalingActive () {
164+ boolean updateOnRuntimeValue = Boolean .getBoolean (DPIUtil .SWT_AUTOSCALE_UPDATE_ON_RUNTIME );
165+ return updateOnRuntimeValue ;
166+ }
167+
106168public static int pixelToPoint (int size , int zoom ) {
107169 if (zoom == 100 || size == SWT .DEFAULT ) return size ;
108170 float scaleFactor = getScalingFactor (zoom );
0 commit comments