Skip to content

Commit

Permalink
JBR-6207 Wayland: many popup windows positioned incorrectly
Browse files Browse the repository at this point in the history
When popup's parent is also its top-level window, use that instead of
null
  • Loading branch information
mkartashev authored and jbrbot committed Nov 8, 2024
1 parent e302f47 commit 47d484b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
public class WLComponentPeer implements ComponentPeer {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.wl.WLComponentPeer");
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.wl.focus.WLComponentPeer");
private static final PlatformLogger popupLog = PlatformLogger.getLogger("sun.awt.wl.popup.WLComponentPeer");

private static final String appID = System.getProperty("sun.java.command");

Expand Down Expand Up @@ -224,6 +225,17 @@ public boolean requestFocus(Component lightweightChild, boolean temporary,
return true;
}

private static Window getToplevel(Component component) {
Container container = component instanceof Container c ? c : component.getParent();
for(Container p = container; p != null; p = p.getParent()) {
if (p instanceof Window) {
return (Window)p;
}
}

return null;
}

protected void wlSetVisible(boolean v) {
this.visible = v;
if (v) {
Expand All @@ -238,7 +250,7 @@ protected void wlSetVisible(boolean v) {
final Component popupParent = AWTAccessor.getWindowAccessor().getPopupParent(popup);
final int parentWidth = popupParent.getWidth();
final int parentHeight = popupParent.getHeight();
final Window toplevel = SwingUtilities.getWindowAncestor(popupParent);
final Window toplevel = getToplevel(popupParent);
// We need to provide popup "parent" location relative to
// the surface it is painted upon:
final Point toplevelLocation = toplevel == null
Expand All @@ -251,6 +263,15 @@ protected void wlSetVisible(boolean v) {
final Point offsetFromParent = popup.getLocation();
final int offsetX = offsetFromParent.x;
final int offsetY = offsetFromParent.y;

if (popupLog.isLoggable(PlatformLogger.Level.FINE)) {
popupLog.info("New popup: " + popup);
popupLog.info("\tparent:" + popupParent);
popupLog.info("\ttoplevel: " + toplevel);
popupLog.info("\tanchor from toplevel offset: " + toplevelLocation);
popupLog.info("\toffset from anchor: " + offsetFromParent);
}

nativeCreateWLPopup(nativePtr,
getParentNativePtr(target), parentX, parentY, parentWidth, parentHeight,
thisWidth, thisHeight,
Expand Down

0 comments on commit 47d484b

Please sign in to comment.