Skip to content

Commit aceb68c

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 0324a13 commit aceb68c

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
@@ -5375,14 +5375,25 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
53755375
}
53765376

53775377
private Monitor getContainingMonitor(int x, int y) {
5378+
return getContainingMonitorOptional(x, y).orElse(getPrimaryMonitor());
5379+
}
5380+
5381+
private Optional<Monitor> getContainingMonitorOptional(int x, int y) {
53785382
Monitor[] monitors = getMonitors();
53795383
for (Monitor currentMonitor : monitors) {
53805384
Rectangle clientArea = currentMonitor.getClientArea();
53815385
if (clientArea.contains(x, y)) {
5382-
return currentMonitor;
5386+
return Optional.of(currentMonitor);
53835387
}
53845388
}
5385-
return getPrimaryMonitor();
5389+
return Optional.empty();
5390+
}
5391+
5392+
Point translatePointIfInDisplayCoordinateGap(int x, int y) {
5393+
if(getContainingMonitorOptional(x, y).isEmpty() && getContainingMonitorInPixelsCoordinateOptional(x, y).isPresent()) {
5394+
return translateLocationInPointInDisplayCoordinateSystem(x, y);
5395+
}
5396+
return new Point(x, y);
53865397
}
53875398

53885399
private Monitor getContainingMonitor(int x, int y, int width, int height) {
@@ -5403,14 +5414,18 @@ private Monitor getContainingMonitor(int x, int y, int width, int height) {
54035414
}
54045415

54055416
private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPixels) {
5417+
return getContainingMonitorInPixelsCoordinateOptional(xInPixels, yInPixels).orElse(getPrimaryMonitor());
5418+
}
5419+
5420+
private Optional<Monitor> getContainingMonitorInPixelsCoordinateOptional(int xInPixels, int yInPixels) {
54065421
Monitor[] monitors = getMonitors();
54075422
for (Monitor current : monitors) {
54085423
Rectangle clientArea = getMonitorClientAreaInPixels(current);
54095424
if (clientArea.contains(xInPixels, yInPixels)) {
5410-
return current;
5425+
return Optional.of(current);
54115426
}
54125427
}
5413-
return getPrimaryMonitor();
5428+
return Optional.empty();
54145429
}
54155430

54165431
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)