JBR-1740 Menu remains open when application loses focus

(cherry picked from commit f987d22cd2)
(cherry picked from commit 4a7913c9e6)
This commit is contained in:
Dmitry Batrak
2022-05-17 16:51:15 +03:00
committed by jbrbot
parent 97723f7c69
commit c0109c6e03
2 changed files with 15 additions and 0 deletions

View File

@@ -494,6 +494,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
private static XMouseInfoPeer xPeer;
private static Boolean isXWayland;
static {
if (GraphicsEnvironment.isHeadless()) {
localEnv = null;
@@ -2877,4 +2879,11 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
public static boolean getSunAwtDisableGrab() {
return Boolean.getBoolean("sun.awt.disablegrab");
}
static synchronized boolean isXWayland() {
if (isXWayland == null) {
isXWayland = getEnv("WAYLAND_DISPLAY") != null;
}
return isXWayland;
}
}

View File

@@ -878,6 +878,12 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
}
handleWindowFocusOut(oppositeWindow, xfe.get_serial());
}
if (XToolkit.isXWayland() && XAwtState.getGrabWindow() != null) {
// under XWayland, pointer grab doesn't give us ability to receive button events for native Wayland
// windows, so the logic in handleButtonPressRelease method won't work, and we need this workaround
// to cancel the grab on switching to another application
postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
}
}
}
}