Skip to content

Commit 7bce6bd

Browse files
committed
Improve Shell::setBounds scaling on monitor change
This commit contributes to the correct scaling of the Shell using its own zoom on Shell::setBounds call as the scaling of the shell in case of a monitor change is also handled by the DPI_CHANGED event. contributes to #62 and #127
1 parent a0a0485 commit 7bce6bd

File tree

1 file changed

+10
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,11 @@ public Point getLocation() {
15821582
public void setLocation(Point location) {
15831583
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
15841584
checkWidget ();
1585-
Point locationInPixels = getDisplay().translateToDisplayCoordinates(location, getZoom());
1586-
setLocationInPixels(locationInPixels.x, locationInPixels.y);
1585+
Monitor monitor = location instanceof MonitorAwarePoint monitorAwareLocation ? monitorAwareLocation.getMonitor() : null;
1586+
Point size = getSize();
1587+
MonitorAwareRectangle monAwareBounds = new MonitorAwareRectangle(location.x, location.y, size.x, size.y, monitor);
1588+
Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(monAwareBounds, getZoom());
1589+
setLocationInPixels(boundsInPixels.x, boundsInPixels.y);
15871590
}
15881591

15891592
@Override
@@ -1596,7 +1599,11 @@ public void setBounds(Rectangle rect) {
15961599
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
15971600
checkWidget ();
15981601
Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(rect, getZoom());
1599-
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
1602+
// The scaling of the width and height in case of a monitor change is handled by
1603+
// the WM_DPICHANGED event so we don't need to use the target monitor zoom for
1604+
// scaling them here.
1605+
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, DPIUtil.scaleUp(rect.width, getZoom()),
1606+
DPIUtil.scaleUp(rect.width, getZoom()));
16001607
}
16011608

16021609
@Override

0 commit comments

Comments
 (0)