Skip to content

Commit

Permalink
8319103: Popups that request focus are not shown on Linux with Wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
azvegint committed Nov 13, 2023
1 parent 03db828 commit 0421fed
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ public boolean isRunningOnWayland() {
@Override
public void windowLostFocus(WindowEvent e) {
Window window = e.getWindow();
Window oppositeWindow = e.getOppositeWindow();

// The focus can move between the window calling the popup,
// and the popup window itself.
// We only dismiss the popup in other cases.
if (oppositeWindow != null) {
if (window == oppositeWindow.getParent() ) {
addWaylandWindowFocusListenerToWindow(oppositeWindow);
return;
}
if (window.getParent() == oppositeWindow) {
return;
}
}

window.removeWindowFocusListener(this);

// AWT
Expand All @@ -516,18 +531,22 @@ public void windowLostFocus(WindowEvent e) {
}
}

private static void addWaylandWindowFocusListenerToWindow(Window window) {
if (!Arrays
.asList(window.getWindowFocusListeners())
.contains(waylandWindowFocusListener)
) {
window.addWindowFocusListener(waylandWindowFocusListener);
}
}

@Override
public void dismissPopupOnFocusLostIfNeeded(Window invoker) {
if (!isOnWayland()
|| invoker == null
|| Arrays
.asList(invoker.getWindowFocusListeners())
.contains(waylandWindowFocusListener)
) {
if (!isOnWayland() || invoker == null) {
return;
}

invoker.addWindowFocusListener(waylandWindowFocusListener);
addWaylandWindowFocusListenerToWindow(invoker);
}

@Override
Expand All @@ -537,5 +556,8 @@ public void dismissPopupOnFocusLostIfNeededCleanUp(Window invoker) {
}

invoker.removeWindowFocusListener(waylandWindowFocusListener);
for (Window ownedWindow : invoker.getOwnedWindows()) {
ownedWindow.removeWindowFocusListener(waylandWindowFocusListener);
}
}
}

0 comments on commit 0421fed

Please sign in to comment.