Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jdk17u
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
einsteinathome
openjdk
jdk17u
Commits
14e3de9c
Commit
14e3de9c
authored
Jul 18, 2024
by
Matthias Baesken
Browse files
Options
Downloads
Patches
Plain Diff
8319103: Popups that request focus are not shown on Linux with Wayland
Backport-of: f3ed27582e16c3a323f590863cbeec6d35e20b58
parent
385952ce
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
+29
-7
29 additions, 7 deletions
src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
test/jdk/javax/swing/JPopupMenu/FocusablePopupDismissTest.java
+94
-0
94 additions, 0 deletions
...jdk/javax/swing/JPopupMenu/FocusablePopupDismissTest.java
with
123 additions
and
7 deletions
src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java
+
29
−
7
View file @
14e3de9c
...
...
@@ -564,6 +564,21 @@ public abstract class UNIXToolkit extends SunToolkit
@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
...
...
@@ -578,18 +593,22 @@ public abstract class UNIXToolkit extends SunToolkit
}
}
@Override
public
void
dismissPopupOnFocusLostIfNeeded
(
Window
invoker
)
{
if
(!
isOnWayland
()
||
invoker
==
null
||
Arrays
.
asList
(
invoker
.
getWindowFocusListeners
())
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
)
{
return
;
}
invoker
.
ad
dWindowFocusListener
(
waylandWindowFocusListen
er
);
addWaylan
dWindowFocusListener
ToWindow
(
invok
er
);
}
@Override
...
...
@@ -599,5 +618,8 @@ public abstract class UNIXToolkit extends SunToolkit
}
invoker
.
removeWindowFocusListener
(
waylandWindowFocusListener
);
for
(
Window
ownedWindow
:
invoker
.
getOwnedWindows
())
{
ownedWindow
.
removeWindowFocusListener
(
waylandWindowFocusListener
);
}
}
}
This diff is collapsed.
Click to expand it.
test/jdk/javax/swing/JPopupMenu/FocusablePopupDismissTest.java
0 → 100644
+
94
−
0
View file @
14e3de9c
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @key headful
* @bug 8319103
* @requires (os.family == "linux")
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Tests if the focusable popup can be dismissed when the parent
* window or the popup itself loses focus in Wayland.
* @run main/manual FocusablePopupDismissTest
*/
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
import
javax.swing.JPopupMenu
;
import
javax.swing.JTextField
;
import
java.awt.Window
;
import
java.util.List
;
public
class
FocusablePopupDismissTest
{
private
static
final
String
INSTRUCTIONS
=
"""
A frame with a "Click me" button should appear next to the window
with this instruction.
Click on the "Click me" button.
If the JTextField popup with "Some text" is not showing on the screen,
click Fail.
The following steps require some focusable system window to be displayed
on the screen. This could be a system settings window, file manager, etc.
Click on the "Click me" button if the popup is not displayed
on the screen.
While the popup is displayed, click on some other window on the desktop.
If the popup has disappeared, click Pass, otherwise click Fail.
"""
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
System
.
getenv
(
"WAYLAND_DISPLAY"
)
==
null
)
{
//test is valid only when running on Wayland.
return
;
}
PassFailJFrame
.
builder
()
.
title
(
"FocusablePopupDismissTest"
)
.
instructions
(
INSTRUCTIONS
)
.
rows
(
20
)
.
columns
(
45
)
.
testUI
(
FocusablePopupDismissTest:
:
createTestUI
)
.
build
()
.
awaitAndCheck
();
}
static
List
<
Window
>
createTestUI
()
{
JFrame
frame
=
new
JFrame
(
"FocusablePopupDismissTest"
);
JButton
button
=
new
JButton
(
"Click me"
);
frame
.
add
(
button
);
button
.
addActionListener
(
e
->
{
JPopupMenu
popupMenu
=
new
JPopupMenu
();
JTextField
textField
=
new
JTextField
(
"Some text"
,
10
);
popupMenu
.
add
(
textField
);
popupMenu
.
show
(
button
,
0
,
button
.
getHeight
());
});
frame
.
pack
();
return
List
.
of
(
frame
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment