Skip to content

Commit 4b00a40

Browse files
committed
Change monitor-specific scaling setting before Display creation
The method Display#setRescalingAtRuntime() allows to activate the monitor-specific scaling mechanism on Windows. This must, however, actually be activated before the Display is instantiated, like it is done during the Display constructor execution if the VM argument for global activation of monitor-specific scaling is specified. In consequence, calling #setRescalingAtRuntime() does not take the full intended effect. This change deprecated the method (along with its according accessor #isRescalingAtRuntime()) and adds a new method to activate monitor-specific scaling on the Display class instead of an instance to be used for subsequent displays to be instantiated.
1 parent 950ca8a commit 4b00a40

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6833,6 +6833,22 @@ static boolean isActivateShellOnForceFocus() {
68336833
return "true".equals(System.getProperty("org.eclipse.swt.internal.activateShellOnForceFocus", "true")); //$NON-NLS-1$
68346834
}
68356835

6836+
/**
6837+
* Activates or deactivates monitor-specific scaling of shells at runtime for
6838+
* all Displays subsequently created whenever the DPI scaling of the shell's
6839+
* monitor changes. This only affects displays created after calling this
6840+
* method.
6841+
* <p>
6842+
* <b>Note:</b> This functionality is only available on Windows. Calling this
6843+
* method on other operating system will have no effect.
6844+
*
6845+
* @param activated whether monitor-specific scaling shall be activated or
6846+
* deactivated
6847+
* @since 3.129
6848+
*/
6849+
public static void setMonitorSpecificScaling(boolean activated) {
6850+
}
6851+
68366852
/**
68376853
* {@return whether rescaling of shells at runtime when the DPI scaling of a
68386854
* shell's monitor changes is activated for this device}
@@ -6841,7 +6857,10 @@ static boolean isActivateShellOnForceFocus() {
68416857
* method on other operating system will always return false.
68426858
*
68436859
* @since 3.127
6860+
* @deprecated this method should not be used as the corresponding
6861+
* {@link #setRescalingAtRuntime(boolean)} should not be used either
68446862
*/
6863+
@Deprecated(since = "2025-03", forRemoval = true)
68456864
public boolean isRescalingAtRuntime() {
68466865
return false;
68476866
}
@@ -6858,7 +6877,12 @@ public boolean isRescalingAtRuntime() {
68586877
* @param activate whether rescaling shall be activated or deactivated
68596878
* @return whether activating or deactivating the rescaling was successful
68606879
* @since 3.127
6880+
* @deprecated this method should not be used as it needs to be called already
6881+
* during instantiation to take proper effect; use
6882+
* {@link #setMonitorSpecificScaling(boolean)} before creating a
6883+
* Display instead
68616884
*/
6885+
@Deprecated(since = "2025-03", forRemoval = true)
68626886
public boolean setRescalingAtRuntime(boolean activate) {
68636887
// not implemented for Cocoa
68646888
return false;

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6269,6 +6269,22 @@ static boolean isActivateShellOnForceFocus() {
62696269
return "true".equals(System.getProperty("org.eclipse.swt.internal.activateShellOnForceFocus", "true")); //$NON-NLS-1$
62706270
}
62716271

6272+
/**
6273+
* Activates or deactivates monitor-specific scaling of shells at runtime for
6274+
* all Displays subsequently created whenever the DPI scaling of the shell's
6275+
* monitor changes. This only affects displays created after calling this
6276+
* method.
6277+
* <p>
6278+
* <b>Note:</b> This functionality is only available on Windows. Calling this
6279+
* method on other operating system will have no effect.
6280+
*
6281+
* @param activated whether monitor-specific scaling shall be activated or
6282+
* deactivated
6283+
* @since 3.129
6284+
*/
6285+
public static void setMonitorSpecificScaling(boolean activated) {
6286+
}
6287+
62726288
/**
62736289
* {@return whether rescaling of shells at runtime when the DPI scaling of a
62746290
* shell's monitor changes is activated for this device}
@@ -6277,7 +6293,10 @@ static boolean isActivateShellOnForceFocus() {
62776293
* method on other operating system will always return false.
62786294
*
62796295
* @since 3.127
6296+
* @deprecated this method should not be used as the corresponding
6297+
* {@link #setRescalingAtRuntime(boolean)} should not be used either
62806298
*/
6299+
@Deprecated(since = "2025-03", forRemoval = true)
62816300
public boolean isRescalingAtRuntime() {
62826301
return false;
62836302
}
@@ -6294,7 +6313,12 @@ public boolean isRescalingAtRuntime() {
62946313
* @param activate whether rescaling shall be activated or deactivated
62956314
* @return whether activating or deactivating the rescaling was successful
62966315
* @since 3.127
6316+
* @deprecated this method should not be used as it needs to be called already
6317+
* during instantiation to take proper effect; use
6318+
* {@link #setMonitorSpecificScaling(boolean)} before creating a
6319+
* Display instead
62976320
*/
6321+
@Deprecated(since = "2025-03", forRemoval = true)
62986322
public boolean setRescalingAtRuntime(boolean activate) {
62996323
// not implemented for GTK
63006324
return false;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public class Display extends Device implements Executor {
139139
boolean useOwnDC;
140140
boolean externalEventLoop; // events are dispatched outside SWT, e.g. TrackPopupMenu or DoDragDrop
141141
private CoordinateSystemMapper coordinateSystemMapper;
142+
private static boolean monitorSpecificScaling;
142143
private boolean rescalingAtRuntime;
143144

144145
/* Widget Table */
@@ -948,7 +949,7 @@ public void close () {
948949
protected void create (DeviceData data) {
949950
checkSubclass ();
950951
checkDisplay (thread = Thread.currentThread (), true);
951-
if (DPIUtil.isAutoScaleOnRuntimeActive()) {
952+
if (monitorSpecificScaling || DPIUtil.isAutoScaleOnRuntimeActive()) {
952953
setRescalingAtRuntime(true);
953954
}
954955
createDisplay (data);
@@ -5270,6 +5271,24 @@ private long openThemeData(final char[] themeName) {
52705271
return OS.OpenThemeData(hwndMessage, themeName, dpi);
52715272
}
52725273
}
5274+
5275+
/**
5276+
* Activates or deactivates monitor-specific scaling of shells at runtime for
5277+
* all Displays subsequently created whenever the DPI scaling of the shell's
5278+
* monitor changes. This only affects displays created after calling this
5279+
* method.
5280+
* <p>
5281+
* <b>Note:</b> This functionality is only available on Windows. Calling this
5282+
* method on other operating system will have no effect.
5283+
*
5284+
* @param activated whether monitor-specific scaling shall be activated or
5285+
* deactivated
5286+
* @since 3.129
5287+
*/
5288+
public static void setMonitorSpecificScaling(boolean activated) {
5289+
monitorSpecificScaling = activated;
5290+
}
5291+
52735292
/**
52745293
* {@return whether rescaling of shells at runtime when the DPI scaling of a
52755294
* shell's monitor changes is activated for this device}
@@ -5278,7 +5297,10 @@ private long openThemeData(final char[] themeName) {
52785297
* method on other operating system will always return false.
52795298
*
52805299
* @since 3.127
5300+
* @deprecated this method should not be used as the corresponding
5301+
* {@link #setRescalingAtRuntime(boolean)} should not be used either
52815302
*/
5303+
@Deprecated(since = "2025-03", forRemoval = true)
52825304
public boolean isRescalingAtRuntime() {
52835305
return rescalingAtRuntime;
52845306
}
@@ -5295,7 +5317,12 @@ public boolean isRescalingAtRuntime() {
52955317
* @param activate whether rescaling shall be activated or deactivated
52965318
* @return whether activating or deactivating the rescaling was successful
52975319
* @since 3.127
5320+
* @deprecated this method should not be used as it needs to be called already
5321+
* during instantiation to take proper effect; use
5322+
* {@link #setMonitorSpecificScaling(boolean)} before creating a
5323+
* Display instead
52985324
*/
5325+
@Deprecated(since = "2025-03", forRemoval = true)
52995326
public boolean setRescalingAtRuntime(boolean activate) {
53005327
int desiredApiAwareness = activate ? OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 : OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
53015328
if (setDPIAwareness(desiredApiAwareness)) {

0 commit comments

Comments
 (0)