Skip to content

Commit

Permalink
Translate points in display coordinate space gap
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amartya4256 committed Oct 9, 2024
1 parent 0324a13 commit aceb68c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5375,14 +5375,25 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
}

private Monitor getContainingMonitor(int x, int y) {
return getContainingMonitorOptional(x, y).orElse(getPrimaryMonitor());
}

private Optional<Monitor> getContainingMonitorOptional(int x, int y) {
Monitor[] monitors = getMonitors();
for (Monitor currentMonitor : monitors) {
Rectangle clientArea = currentMonitor.getClientArea();
if (clientArea.contains(x, y)) {
return currentMonitor;
return Optional.of(currentMonitor);
}
}
return getPrimaryMonitor();
return Optional.empty();
}

Point translatePointIfInDisplayCoordinateGap(int x, int y) {
if(getContainingMonitorOptional(x, y).isEmpty() && getContainingMonitorInPixelsCoordinateOptional(x, y).isPresent()) {
return translateLocationInPointInDisplayCoordinateSystem(x, y);
}
return new Point(x, y);
}

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

private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPixels) {
return getContainingMonitorInPixelsCoordinateOptional(xInPixels, yInPixels).orElse(getPrimaryMonitor());
}

private Optional<Monitor> getContainingMonitorInPixelsCoordinateOptional(int xInPixels, int yInPixels) {
Monitor[] monitors = getMonitors();
for (Monitor current : monitors) {
Rectangle clientArea = getMonitorClientAreaInPixels(current);
if (clientArea.contains(xInPixels, yInPixels)) {
return current;
return Optional.of(current);
}
}
return getPrimaryMonitor();
return Optional.empty();
}

private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,8 @@ public void setLocation(Point location) {

@Override
public void setLocation(int x, int y) {
Point location = display.translateLocationInPixelsInDisplayCoordinateSystem(x, y);
Point translatedPoint = display.translatePointIfInDisplayCoordinateGap(x, y);
Point location = display.translateLocationInPixelsInDisplayCoordinateSystem(translatedPoint.x, translatedPoint.y);
setLocationInPixels(location.x, location.y);
}

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

@Override
public void setBounds(int x, int y, int width, int height) {
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(x, y, width, height);
Point translatedPoint = display.translatePointIfInDisplayCoordinateGap(x, y);
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(translatedPoint.x, translatedPoint.y, width, height);
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
}

Expand Down

0 comments on commit aceb68c

Please sign in to comment.