Skip to content

Commit 30d0715

Browse files
GetLocation as Point.WithMonitor to ensure correct monitor association
Previously, dialog positioning could be incorrect if the monitor was misidentified when restoring location. By returning the shell's location as a Point.WithMonitor (including monitor reference), we ensure dialogs and secondary shells open on the intended monitor, even in multi-monitor setups. This fixes issues where dialogs could appear on the wrong monitor after moving the parent shell.
1 parent fdbb769 commit 30d0715

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
9393

9494
@Override
9595
public Point translateFromDisplayCoordinates(Point point) {
96-
return translateLocationInPixelsToPoints(point.x, point.y);
96+
Monitor monitor = point instanceof Point.WithMonitor pointWithMonitor ? pointWithMonitor.getMonitor() : null;
97+
return translateLocationInPixelsToPoints(point.x, point.y, monitor);
9798
}
9899

99100
@Override
@@ -117,7 +118,7 @@ public Rectangle translateToDisplayCoordinates(Rectangle rect) {
117118
@Override
118119
public Point getCursorLocation() {
119120
Point cursorLocationInPixels = display.getCursorLocationInPixels();
120-
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y);
121+
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y, null);
121122
}
122123

123124
@Override
@@ -131,8 +132,10 @@ private Point translateLocationInPointsToPixels(int x, int y, Monitor monitor) {
131132
return getPixelsFromPoint(monitor, x, y);
132133
}
133134

134-
private Point translateLocationInPixelsToPoints(int x, int y) {
135-
Monitor monitor = getContainingMonitorForPixels(x, y);
135+
private Point translateLocationInPixelsToPoints(int x, int y, Monitor monitor) {
136+
if (monitor == null) {
137+
monitor = getContainingMonitorForPixels(x, y);
138+
}
136139
return getPointFromPixels(monitor, x, y);
137140
}
138141

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ public int getAlpha () {
924924
OS.GetWindowRect (handle, rect);
925925
int width = rect.right - rect.left;
926926
int height = rect.bottom - rect.top;
927-
return new Rectangle (rect.left, rect.top, width, height);
927+
return new Rectangle.WithMonitor (rect.left, rect.top, width, height, getMonitor());
928928
}
929929

930930
ToolTip getCurrentToolTip () {
@@ -1017,7 +1017,7 @@ public int getImeInputMode () {
10171017
if (OS.IsIconic (handle)) return super.getLocationInPixels ();
10181018
RECT rect = new RECT ();
10191019
OS.GetWindowRect (handle, rect);
1020-
return new Point (rect.left, rect.top);
1020+
return new Point.WithMonitor (rect.left, rect.top, getMonitor());
10211021
}
10221022

10231023
@Override

0 commit comments

Comments
 (0)