Skip to content

Commit 43f71a8

Browse files
committed
Translate points in display coordinate space gap
This contribution fixes the current behaviour of the display coordinate system of eclipse where a point can be manually set to somewhere in the gap between the 2 monitor in the coordinate space (in the points system). This fix translates those points to inside the scaled down space of a monitor providing it the right coordinates in the display coordinate space. contributes to #62 and #127
1 parent b0413a8 commit 43f71a8

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5377,14 +5377,25 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
53775377
}
53785378

53795379
private Monitor getContainingMonitor(int x, int y) {
5380+
return getContainingMonitorOptional(x, y).orElse(getPrimaryMonitor());
5381+
}
5382+
5383+
private Optional<Monitor> getContainingMonitorOptional(int x, int y) {
53805384
Monitor[] monitors = getMonitors();
53815385
for (Monitor currentMonitor : monitors) {
53825386
Rectangle clientArea = currentMonitor.getClientArea();
53835387
if (clientArea.contains(x, y)) {
5384-
return currentMonitor;
5388+
return Optional.of(currentMonitor);
53855389
}
53865390
}
5387-
return getPrimaryMonitor();
5391+
return Optional.empty();
5392+
}
5393+
5394+
Point translatePointIfInDisplayCoordinateGap(int x, int y) {
5395+
if(getContainingMonitorOptional(x, y).isEmpty() && getContainingMonitorInPixelsCoordinateOptional(x, y).isPresent()) {
5396+
return translateLocationInPointInDisplayCoordinateSystem(x, y);
5397+
}
5398+
return new Point(x, y);
53885399
}
53895400

53905401
private Monitor getContainingMonitor(int x, int y, int width, int height) {
@@ -5405,14 +5416,18 @@ private Monitor getContainingMonitor(int x, int y, int width, int height) {
54055416
}
54065417

54075418
private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPixels) {
5419+
return getContainingMonitorInPixelsCoordinateOptional(xInPixels, yInPixels).orElse(getPrimaryMonitor());
5420+
}
5421+
5422+
private Optional<Monitor> getContainingMonitorInPixelsCoordinateOptional(int xInPixels, int yInPixels) {
54085423
Monitor[] monitors = getMonitors();
54095424
for (Monitor current : monitors) {
54105425
Rectangle clientArea = getMonitorClientAreaInPixels(current);
54115426
if (clientArea.contains(xInPixels, yInPixels)) {
5412-
return current;
5427+
return Optional.of(current);
54135428
}
54145429
}
5415-
return getPrimaryMonitor();
5430+
return Optional.empty();
54165431
}
54175432

54185433
private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,8 @@ public void setLocation(Point location) {
15861586

15871587
@Override
15881588
public void setLocation(int x, int y) {
1589-
Point location = display.translateLocationInPixelsInDisplayCoordinateSystem(x, y);
1589+
Point translatedPoint = display.translatePointIfInDisplayCoordinateGap(x, y);
1590+
Point location = display.translateLocationInPixelsInDisplayCoordinateSystem(translatedPoint.x, translatedPoint.y);
15901591
setLocationInPixels(location.x, location.y);
15911592
}
15921593

@@ -1598,7 +1599,8 @@ public void setBounds(Rectangle rect) {
15981599

15991600
@Override
16001601
public void setBounds(int x, int y, int width, int height) {
1601-
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(x, y, width, height);
1602+
Point translatedPoint = display.translatePointIfInDisplayCoordinateGap(x, y);
1603+
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(translatedPoint.x, translatedPoint.y, width, height);
16021604
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
16031605
}
16041606

0 commit comments

Comments
 (0)