Skip to content

Commit

Permalink
IDEA-141456 Multimonitor HIDPI support for Linux
Browse files Browse the repository at this point in the history
Fixed conflict with JBR-3388
  • Loading branch information
YaaZ committed Jan 23, 2023
1 parent 3581ea9 commit bf073b9
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,12 @@ XBaseMenuWindow getMenuWindowFromPoint(Point pt) {
*
************************************************/

GraphicsConfiguration getCurrentGraphicsConfiguration() {
void updateCurrentGraphicsConfiguration() {
Component hw = SunToolkit.getHeavyweightComponent(target);
XWindow peer = AWTAccessor.getComponentAccessor().getPeer(hw);
if (peer != null && peer.graphicsConfig != null) {
return peer.graphicsConfig;
graphicsConfig = peer.graphicsConfig;
}
return graphicsConfig;
}

/**
Expand Down
42 changes: 31 additions & 11 deletions src/java.desktop/unix/classes/sun/awt/X11/XBaseWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,22 @@ protected int getScale() {
protected int scaleUp(int x) {
return x;
}
protected int scaleUpX(int x) {
return x;
}
protected int scaleUpY(int y) {
return y;
}

protected int scaleDown(int x) {
return x;
}
protected int scaleDownX(int x) {
return x;
}
protected int scaleDownY(int y) {
return y;
}

/**
* Creates window with parameters specified by {@code params}
Expand Down Expand Up @@ -383,8 +395,8 @@ private void create(XCreateWindowParams params) {
}
window = XlibWrapper.XCreateWindow(XToolkit.getDisplay(),
parentWindow.longValue(),
scaleUp(bounds.x),
scaleUp(bounds.y),
scaleUpX(bounds.x),
scaleUpY(bounds.y),
scaleUp(bounds.width),
scaleUp(bounds.height),
0, // border
Expand Down Expand Up @@ -523,8 +535,8 @@ public void setSizeHints(long flags, int x, int y, int width, int height) {
// we want to reset PPosition in hints. This is necessary
// for locationByPlatform functionality
if ((flags & XUtilConstants.PPosition) != 0) {
hints.set_x(scaleUp(x));
hints.set_y(scaleUp(y));
hints.set_x(scaleUpX(x));
hints.set_y(scaleUpY(y));
}
if ((flags & XUtilConstants.PSize) != 0) {
hints.set_width(scaleUp(width));
Expand Down Expand Up @@ -757,7 +769,8 @@ public void xSetBounds(int x, int y, int width, int height) {
XToolkit.awtLock();
try {
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(),
scaleUp(x), scaleUp(y),
parentWindow == null ? scaleUpX(x) : scaleUp(x),
parentWindow == null ? scaleUpY(y) : scaleUp(y),
scaleUp(width), scaleUp(height));
} finally {
XToolkit.awtUnlock();
Expand All @@ -780,8 +793,8 @@ static Point toOtherWindow(long src, long dst, int x, int y) {

if (srcPeer != null && dstPeer != null) {
// (x, y) is relative to src
rpt.x = x + srcPeer.getAbsoluteX() - dstPeer.getAbsoluteX();
rpt.y = y + srcPeer.getAbsoluteY() - dstPeer.getAbsoluteY();
rpt.x = dstPeer.scaleDownX(srcPeer.scaleUpX(x + srcPeer.getAbsoluteX()) - dstPeer.scaleUpX(dstPeer.getAbsoluteX()));
rpt.y = dstPeer.scaleDownY(srcPeer.scaleUpY(y + srcPeer.getAbsoluteY()) - dstPeer.scaleUpY(dstPeer.getAbsoluteY()));
} else if (dstPeer != null && XlibUtil.isRoot(src, dstPeer.getScreenNumber())) {
// from root into peer
rpt.x = x - dstPeer.getAbsoluteX();
Expand All @@ -791,8 +804,15 @@ static Point toOtherWindow(long src, long dst, int x, int y) {
rpt.x = x + srcPeer.getAbsoluteX();
rpt.y = y + srcPeer.getAbsoluteY();
} else {
int scale = srcPeer == null ? 1 : srcPeer.getScale();
rpt = XlibUtil.translateCoordinates(src, dst, new Point(x, y), scale);
if (srcPeer != null) {
x = srcPeer.scaleUp(x);
y = srcPeer.scaleUp(y);
}
rpt = XlibUtil.translateCoordinates(src, dst, x, y);
if (dstPeer != null) {
rpt.x = dstPeer.scaleDown(rpt.x);
rpt.y = dstPeer.scaleDown(rpt.y);
}
}
return rpt;
}
Expand Down Expand Up @@ -1091,8 +1111,8 @@ public void handleConfigureNotifyEvent(XEvent xev) {
insLog.finer("Configure, {0}", xe);
}

x = scaleDown(xe.get_x());
y = scaleDown(xe.get_y());
x = scaleDownX(xe.get_x());
y = scaleDownY(xe.get_y());
width = scaleDown(xe.get_width());
height = scaleDown(xe.get_height());
}
Expand Down
7 changes: 5 additions & 2 deletions src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,10 @@ public void applyShape(Region shape) {

int scale = getScale();
if (scale != 1) {
shape = shape.getScaledRegion(scale, scale);
Rectangle bounds = graphicsConfig.getBounds();
shape = shape.getTranslatedRegion(-bounds.x, -bounds.y)
.getScaledRegion(scale, scale)
.getTranslatedRegion(bounds.x, bounds.y);
}

XlibWrapper.SetRectangularShape(
Expand Down Expand Up @@ -1395,7 +1398,7 @@ public boolean updateGraphicsData(GraphicsConfiguration gc) {
}

initGraphicsConfiguration();
doValidateSurface();
syncBounds();
return false;
}
}
37 changes: 26 additions & 11 deletions src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,19 @@ private void processConfigureEvent(XConfigureEvent xe) {
currentInsets, newDimensions);
}

checkIfOnNewScreen(newDimensions.getBounds());
checkIfOnNewScreen(newDimensions.getBounds(), () -> {

Point oldLocation = getLocation();
dimensions = newDimensions;
if (!newLocation.equals(oldLocation)) {
handleMoved(newDimensions);
}
reconfigureContentWindow(newDimensions);
updateChildrenSizes();
Point oldLocation = getLocation();
dimensions = newDimensions;
if (!newLocation.equals(oldLocation)) {
handleMoved(newDimensions);
}
reconfigureContentWindow(newDimensions);
updateChildrenSizes();

repositionSecurityWarning();

repositionSecurityWarning();
});
}

private void checkShellRectSize(Rectangle shellRect) {
Expand Down Expand Up @@ -899,7 +901,8 @@ private void setShellBounds(Rectangle rec) {
}
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getShell(),
scaleUp(rec.x), scaleUp(rec.y),
parentWindow == null ? scaleUpX(rec.x) : scaleUp(rec.x),
parentWindow == null ? scaleUpY(rec.y) : scaleUp(rec.y),
scaleUp(rec.width), scaleUp(rec.height));
}

Expand All @@ -918,7 +921,8 @@ private void setShellPosition(Rectangle rec) {
}
updateSizeHints(rec.x, rec.y, rec.width, rec.height);
XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(),
scaleUp(rec.x), scaleUp(rec.y));
parentWindow == null ? scaleUpX(rec.x) : scaleUp(rec.x),
parentWindow == null ? scaleUpY(rec.y) : scaleUp(rec.y));
}

public void setResizable(boolean resizable) {
Expand Down Expand Up @@ -1396,4 +1400,15 @@ public final Optional<Boolean> getMWMDecorTitleProperty() {
public final boolean getWindowTitleVisible() {
return getMWMDecorTitleProperty().orElse(true);
}

@Override
public boolean updateGraphicsData(GraphicsConfiguration gc) {
boolean ret = super.updateGraphicsData(gc);
if (content != null) {
content.initGraphicsConfiguration();
content.syncBounds();
}
updateMinimumSize();
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -606,20 +606,18 @@ private boolean processXdndPosition(XClientMessageEvent xclient) {
y = (int)(xclient.get_data(2) & 0xFFFF);

if (xwindow != null) {
x = xwindow.scaleDown(x);
y = xwindow.scaleDown(y);
x = xwindow.scaleDownX(x);
y = xwindow.scaleDownY(y);
} else {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
X11GraphicsConfig gc = (X11GraphicsConfig)gd.getDefaultConfiguration();
Rectangle rt = gc.getBounds();
rt.x = gc.scaleUp(rt.x);
rt.y = gc.scaleUp(rt.y);
rt.width = gc.scaleUp(rt.width);
rt.height = gc.scaleUp(rt.height);
if (rt.contains(x, y)) {
x = gc.scaleDown(x);
y = gc.scaleDown(y);
x = gc.scaleDownX(x);
y = gc.scaleDownY(y);
break;
}
}
Expand Down
49 changes: 26 additions & 23 deletions src/java.desktop/unix/classes/sun/awt/X11/XEmbeddedFramePeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,30 @@ public void handleConfigureNotifyEvent(XEvent xev)
// fix for 5063031
// if we use super.handleConfigureNotifyEvent() we would get wrong
// size and position because embedded frame really is NOT a decorated one
checkIfOnNewScreen(toGlobal(new Rectangle(scaleDown(xe.get_x()),
scaleDown(xe.get_y()),
scaleDown(xe.get_width()),
scaleDown(xe.get_height()))));

Rectangle oldBounds = getBounds();

synchronized (getStateLock()) {
x = scaleDown(xe.get_x());
y = scaleDown(xe.get_y());
width = scaleDown(xe.get_width());
height = scaleDown(xe.get_height());
checkIfOnNewScreen(toGlobal(new Rectangle(
scaleDown(xe.get_x()),
scaleDown(xe.get_y()),
scaleDown(xe.get_width()),
scaleDown(xe.get_height()))), () -> {

Rectangle oldBounds = getBounds();

synchronized (getStateLock()) {
x = scaleDown(xe.get_x());
y = scaleDown(xe.get_y());
width = scaleDown(xe.get_width());
height = scaleDown(xe.get_height());

dimensions.setClientSize(width, height);
dimensions.setLocation(x, y);
}

dimensions.setClientSize(width, height);
dimensions.setLocation(x, y);
}
if (!getLocation().equals(oldBounds.getLocation())) {
handleMoved(dimensions);
}
reconfigureContentWindow(dimensions);

if (!getLocation().equals(oldBounds.getLocation())) {
handleMoved(dimensions);
}
reconfigureContentWindow(dimensions);
});
}

protected void traverseOutForward() {
Expand Down Expand Up @@ -276,16 +279,16 @@ public int getAbsoluteX()
{
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
XToolkit.getDefaultRootWindow(),
new Point(0, 0), getScale());
return absoluteLoc != null ? absoluteLoc.x : 0;
0, 0);
return absoluteLoc != null ? scaleDownX(absoluteLoc.x) : 0;
}

public int getAbsoluteY()
{
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
XToolkit.getDefaultRootWindow(),
new Point(0, 0), getScale());
return absoluteLoc != null ? absoluteLoc.y : 0;
0, 0);
return absoluteLoc != null ? scaleDownY(absoluteLoc.y) : 0;
}

public int getWidth() {
Expand Down
12 changes: 12 additions & 0 deletions src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Insets;
import java.awt.MenuBar;
import java.awt.Rectangle;
import java.awt.peer.FramePeer;
import sun.awt.SunToolkit;
import sun.awt.X11GraphicsConfig;
import sun.util.logging.PlatformLogger;
import sun.awt.AWTAccessor;

Expand Down Expand Up @@ -710,4 +712,14 @@ public void emulateActivation(boolean doActivate) {
handleWindowFocusOut(null, 0);
}
}

@Override
public boolean updateGraphicsData(GraphicsConfiguration gc) {
boolean ret = super.updateGraphicsData(gc);
if (menubarPeer != null) {
menubarPeer.initGraphicsConfiguration();
menubarPeer.syncBounds();
}
return ret;
}
}
3 changes: 2 additions & 1 deletion src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ protected MappingData map() {
* @see XBaseMenuWindow#getSubmenuBounds
*/
protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
updateCurrentGraphicsConfiguration();
Rectangle globalBounds = toGlobal(itemBounds);
Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
Rectangle screenBounds = graphicsConfig.getBounds();
Rectangle res;
res = fitWindowBelow(globalBounds, windowSize, screenBounds);
if (res != null) {
Expand Down
6 changes: 5 additions & 1 deletion src/java.desktop/unix/classes/sun/awt/X11/XMenuWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ protected MappingData map() {
* @see XBaseMenuWindow#getSubmenuBounds
*/
protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
updateCurrentGraphicsConfiguration();
Rectangle globalBounds = toGlobal(itemBounds);
Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
Rectangle screenBounds = graphicsConfig.getBounds();
Rectangle res;
res = fitWindowRight(globalBounds, windowSize, screenBounds);
if (res != null) {
Expand Down Expand Up @@ -385,6 +386,9 @@ boolean ensureCreated() {
params.add(OVERRIDE_REDIRECT, Boolean.TRUE);
params.add(XWindow.TARGET, target);
init(params);
} else {
initGraphicsConfiguration();
syncBounds();
}
return true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ public int fillPointWithCoords(Point point) {
point.x = Native.getInt(XlibWrapper.larg3);
point.y = Native.getInt(XlibWrapper.larg4);
GraphicsDevice device = gds[i];
if (device instanceof X11GraphicsDevice) {
int scale = ((X11GraphicsDevice) device).getScaleFactor();
point.x = XlibUtil.scaleDown(point.x, scale);
point.y = XlibUtil.scaleDown(point.y, scale);
if (device instanceof X11GraphicsDevice x11d) {
point.x = x11d.scaleDownX(point.x);
point.y = x11d.scaleDownY(point.y);
}
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ Vector<MenuItem> getMenuTargetItems() {
* @param windowSize the desired size of menu's window
*/
protected Rectangle getWindowBounds(Point origin, Dimension windowSize) {
updateCurrentGraphicsConfiguration();
Rectangle globalBounds = new Rectangle(origin.x, origin.y, 0, 0);
Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
Rectangle screenBounds = graphicsConfig.getBounds();
Rectangle res;
res = fitWindowRight(globalBounds, windowSize, screenBounds);
if (res != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/java.desktop/unix/classes/sun/awt/X11/XRobotPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class XRobotPeer implements RobotPeer {

@Override
public void mouseMove(int x, int y) {
mouseMoveImpl(xgc, xgc.scaleUp(x), xgc.scaleUp(y));
mouseMoveImpl(xgc, xgc.scaleUpX(x), xgc.scaleUpY(y));
}

@Override
Expand Down

0 comments on commit bf073b9

Please sign in to comment.