Skip to content

Commit 2fde7cc

Browse files
committed
[win32] Register internal ZoomChange listener for monitor specific scaling
As the DPI change behavior in the windows implementation is fully using the ZoomChange event now, it must be ensured, that the internal ZoomChange listener, that adapt the Wigets for monitor specific scaling must be be registered in this case.
1 parent b2b5d45 commit 2fde7cc

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public void testSetFontWithMonitorSpecificScalingEnabled() {
5858
}
5959

6060
@Test
61-
public void testScaleFontCorrectlyInNoAutoScaleScenario() {
61+
public void testDoNotScaleFontInNoAutoScaleScenario() {
6262
Win32DPIUtils.setMonitorSpecificScaling(false);
6363
Display display = Display.getDefault();
6464

6565
assertFalse("Autoscale property is not set to false", display.isRescalingAtRuntime());
6666
int scalingFactor = 2;
6767
FontComparison fontComparison = updateFont(scalingFactor);
68-
assertEquals("Font height in pixels is not adjusted according to the scale factor",
69-
fontComparison.originalFontHeight * scalingFactor, fontComparison.currentFontHeight);
68+
assertEquals("Font height in pixels is different when setting the same font again",
69+
fontComparison.originalFontHeight, fontComparison.currentFontHeight);
7070
}
7171

7272
@Test

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ public Widget (Widget parent, int style) {
194194
}
195195

196196
void registerDPIChangeListener() {
197-
this.addListener(SWT.ZoomChanged, event -> {
198-
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(event.detail) / DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
199-
handleDPIChange(event, scalingFactor);
200-
});
197+
if (display.isRescalingAtRuntime()) {
198+
this.addListener(SWT.ZoomChanged, event -> {
199+
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(event.detail) / DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
200+
handleDPIChange(event, scalingFactor);
201+
});
202+
}
201203
}
202204

203205
void _addListener (int eventType, Listener listener) {

0 commit comments

Comments
 (0)