Skip to content

Commit

Permalink
[win32] Update shell zoom before position change
Browse files Browse the repository at this point in the history
When a Shell is moved to a new position, the new position can be located on a different monitor. If autoScaleOnRuntimeActive is active and the monitor has a different zoom than the previous one, this would lead to a wrong positioning of the shell due to the stored zoom of the shell. Therefor the Shell nativeZoom must update BEFORE the location change will be applied. This commit adds this behaviour on win32.

Contributes to #62 and #127
  • Loading branch information
akoch-yatta authored and amartya4256 committed Jul 17, 2024
1 parent dfdd38f commit 713f1b0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5251,4 +5251,15 @@ static String withCrLf (String string) {
static boolean isActivateShellOnForceFocus() {
return "true".equals(System.getProperty("org.eclipse.swt.internal.activateShellOnForceFocus", "true")); //$NON-NLS-1$
}

Monitor getContainingMonitor(int x, int y) {
Monitor[] monitors = getMonitors();
for (Monitor current : monitors) {
Rectangle clientArea = current.getClientArea();
if (clientArea.contains(x, y)) {
return current;
}
}
return getPrimaryMonitor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,40 @@ public void setAlpha (int alpha) {
}
}

private void updateNativeZoomBeforePositionChange(int x, int y) {
if (DPIUtil.isAutoScaleOnRuntimeActive()) {
Monitor monitor = display.getContainingMonitor(x, y);
this.nativeZoom = monitor.zoom;
System.out.println("Update shell zoom (" + handle + ") " + monitor.zoom);
}
}

@Override
public void setLocation(Point location) {
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
updateNativeZoomBeforePositionChange(location.x, location.y);
super.setLocation(location);
}

@Override
public void setLocation(int x, int y) {
updateNativeZoomBeforePositionChange(x, y);
super.setLocation(x, y);
}

@Override
public void setBounds(Rectangle rect) {
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
updateNativeZoomBeforePositionChange(rect.x, rect.y);
super.setBounds(rect);
}

@Override
public void setBounds(int x, int y, int width, int height) {
updateNativeZoomBeforePositionChange(x, y);
super.setBounds(x, y, width, height);
}

@Override
void setBoundsInPixels (int x, int y, int width, int height, int flags, boolean defer) {
if (fullScreen) setFullScreen (false);
Expand Down

0 comments on commit 713f1b0

Please sign in to comment.