Skip to content

Commit

Permalink
JBR-6036 Wayland: Cannot invoke "java.awt.Component.getWidth()" becau…
Browse files Browse the repository at this point in the history
…se "popupParent" is null

Not all POPUP Window's have their parent set. And only those who do
shall be treated as popups in the Wayland's sense.
  • Loading branch information
mkartashev authored and jbrbot committed Nov 8, 2024
1 parent 9ceaebb commit 8608092
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ protected void wlSetVisible(boolean v) {
this.visible = v;
if (this.visible) {
final String title = getTitle();
final boolean isPopup = target instanceof Window window && window.getType() == Window.Type.POPUP;
final boolean isWlPopup = targetIsWlPopup();
final int thisWidth = getWidth();
final int thisHeight = getHeight();
performLocked(() -> {
if (isPopup) {
if (isWlPopup) {
Window popup = (Window) target;
final Component popupParent = AWTAccessor.getWindowAccessor().getPopupParent(popup);
final int parentWidth = popupParent.getWidth();
Expand Down Expand Up @@ -281,6 +281,16 @@ protected void wlSetVisible(boolean v) {
}
}

/**
* Returns true if our target should be treated as a popup in Wayland's sense,
* i.e. it has to have a parent to position relative to.
*/
private boolean targetIsWlPopup() {
return target instanceof Window window
&& window.getType() == Window.Type.POPUP
&& AWTAccessor.getWindowAccessor().getPopupParent(window) != null;
}

void configureWLSurface() {
synchronized (sizeLock) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
Expand Down Expand Up @@ -1002,11 +1012,11 @@ void notifyConfigured(int newWidth, int newHeight, boolean active, boolean maxim
log.fine(String.format("%s configured to %dx%d", this, newWidth, newHeight));
}

final boolean isPopup = target instanceof Window window && window.getType() == Window.Type.POPUP;
boolean isWlPopup = targetIsWlPopup();

if (newWidth != 0 && newHeight != 0) performUnlocked(() ->target.setSize(newWidth, newHeight));

if (newWidth == 0 || newHeight == 0 || isPopup) {
if (newWidth == 0 || newHeight == 0 || isWlPopup) {
// From xdg-shell.xml: "If the width or height arguments are zero,
// it means the client should decide its own window dimension".

Expand Down

0 comments on commit 8608092

Please sign in to comment.