Skip to content

Commit 22eece1

Browse files
committed
Deprecate insufficient Display#setRescalingAtRuntime() method
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 system property for global activation of monitor-specific scaling is specified. In consequence, calling #setRescalingAtRuntime() does not take the full intended effect. This change deprecates the method so that the system property needs to be set for proper initialization of the monitor-specific scaling functionality. It also adapts the according tests to the deprecation of the API and alternatives to be used.
1 parent e0b4fe9 commit 22eece1

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DisplayWin32Test.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,46 @@
88
import org.junit.jupiter.api.extension.*;
99

1010
@ExtendWith(PlatformSpecificExecutionExtension.class)
11+
@ExtendWith(ResetMonitorSpecificScalingExtension.class)
1112
public class DisplayWin32Test {
1213

13-
private Display display;
14-
15-
@BeforeEach
16-
public void createDisplay() {
17-
display = new Display();
14+
@Test
15+
public void monitorSpecificScaling_activate() {
16+
DPIUtil.setMonitorSpecificScaling(true);
17+
Display display = Display.getDefault();
18+
assertTrue(display.isRescalingAtRuntime());
19+
assertEquals(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, OS.GetThreadDpiAwarenessContext());
1820
}
1921

20-
@AfterEach
21-
public void destroyDisplay() {
22-
display.dispose();
22+
@Test
23+
public void monitorSpecificScaling_deactivate() {
24+
DPIUtil.setMonitorSpecificScaling(false);
25+
Display display = Display.getDefault();
26+
assertFalse(display.isRescalingAtRuntime());
2327
}
2428

2529
@Test
30+
@SuppressWarnings("removal")
2631
public void setRescaleAtRuntime_activate() {
32+
Display display = Display.getDefault();
2733
display.setRescalingAtRuntime(true);
2834
assertTrue(display.isRescalingAtRuntime());
2935
assertEquals(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, OS.GetThreadDpiAwarenessContext());
3036
}
3137

3238
@Test
39+
@SuppressWarnings("removal")
3340
public void setRescaleAtRuntime_deactivate() {
41+
Display display = Display.getDefault();
3442
display.setRescalingAtRuntime(false);
3543
assertFalse(display.isRescalingAtRuntime());
3644
assertEquals(OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE, OS.GetThreadDpiAwarenessContext());
3745
}
3846

3947
@Test
48+
@SuppressWarnings("removal")
4049
public void setRescaleAtRuntime_toggling() {
50+
Display display = Display.getDefault();
4151
display.setRescalingAtRuntime(false);
4252
assertFalse(display.isRescalingAtRuntime());
4353
assertEquals(OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE, OS.GetThreadDpiAwarenessContext());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6858,7 +6858,10 @@ public boolean isRescalingAtRuntime() {
68586858
* @param activate whether rescaling shall be activated or deactivated
68596859
* @return whether activating or deactivating the rescaling was successful
68606860
* @since 3.127
6861+
* @deprecated this method should not be used as it needs to be called already
6862+
* during instantiation to take proper effect
68616863
*/
6864+
@Deprecated(since = "2025-03", forRemoval = true)
68626865
public boolean setRescalingAtRuntime(boolean activate) {
68636866
// not implemented for Cocoa
68646867
return false;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6294,7 +6294,10 @@ public boolean isRescalingAtRuntime() {
62946294
* @param activate whether rescaling shall be activated or deactivated
62956295
* @return whether activating or deactivating the rescaling was successful
62966296
* @since 3.127
6297+
* @deprecated this method should not be used as it needs to be called already
6298+
* during instantiation to take proper effect
62976299
*/
6300+
@Deprecated(since = "2025-03", forRemoval = true)
62986301
public boolean setRescalingAtRuntime(boolean activate) {
62996302
// not implemented for GTK
63006303
return false;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ protected void create (DeviceData data) {
949949
checkSubclass ();
950950
checkDisplay (thread = Thread.currentThread (), true);
951951
if (DPIUtil.isMonitorSpecificScalingActive()) {
952-
setRescalingAtRuntime(true);
952+
setMonitorSpecificScaling(true);
953953
DPIUtil.setAutoScaleForMonitorSpecificScaling();
954954
}
955955
createDisplay (data);
@@ -5263,6 +5263,7 @@ private long openThemeData(final char[] themeName) {
52635263
return OS.OpenThemeData(hwndMessage, themeName, dpi);
52645264
}
52655265
}
5266+
52665267
/**
52675268
* {@return whether rescaling of shells at runtime when the DPI scaling of a
52685269
* shell's monitor changes is activated for this device}
@@ -5288,8 +5289,15 @@ public boolean isRescalingAtRuntime() {
52885289
* @param activate whether rescaling shall be activated or deactivated
52895290
* @return whether activating or deactivating the rescaling was successful
52905291
* @since 3.127
5292+
* @deprecated this method should not be used as it needs to be called already
5293+
* during instantiation to take proper effect
52915294
*/
5295+
@Deprecated(since = "2025-03", forRemoval = true)
52925296
public boolean setRescalingAtRuntime(boolean activate) {
5297+
return setMonitorSpecificScaling(activate);
5298+
}
5299+
5300+
private boolean setMonitorSpecificScaling(boolean activate) {
52935301
int desiredApiAwareness = activate ? OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 : OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
52945302
if (setDPIAwareness(desiredApiAwareness)) {
52955303
rescalingAtRuntime = activate;

0 commit comments

Comments
 (0)