Alt+Tab is broken for Java (AWT/Swing) apps in Wayland session

Bug #1971693 reported by Dmitry Batrak
48
This bug affects 8 people
Affects Status Importance Assigned to Milestone
mutter (Ubuntu)
Fix Released
Low
Unassigned
Jammy
Fix Released
Low
Unassigned

Bug Description

Impact
------
When switching to a Java UI application using Alt+Tab, very often application's window is raised, but it doesn't get keyboard focus - it stays in the previous application, and that application continues to process keyboard events. When the problem occurs, hovering mouse over Java app's window gets the focus transferred to it.
This problem only happens in Wayland session, not in X.Org session. It can be reproduced in Ubuntu 22.04, but not in 20.04.4 version.

The problem seems to affect all Java versions - reproduced for different OpenJDK builds (8, 11, 17, 18). It can also be observed for Java version provided by Ubuntu's 'default-jre' package (11.0.15+10-Ubuntu-0ubuntu0.22.04.1).

Test Case
---------
1. sudo apt install default-jre
2. Download the minimal test case app from comment #1
3. From a terminal run the app
java Downloads/JTextFieldTest.java
4. Click on the terminal window (instead of the Java app)
5. Press Alt-Tab to switch focus back to the Java app
6. Type a few characters.

The characters should show in the Java app's text field instead of in the terminal window.

What Could Go Wrong
-------------------
See the master bug for this update at LP: #1972726

Revision history for this message
Dmitry Batrak (dmitry-batrak) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in ubuntu:
status: New → Confirmed
Revision history for this message
Dmitry Batrak (dmitry-batrak) wrote :

The problem seems to be related to Java apps using 'Globally Active' input focus model (as per https://www.x.org/releases/current/doc/xorg-docs/icccm/icccm.html#Input_Focus). I'm attaching a minimal native X application's code, for which the problem can be reproduced as well - see focusTest.c file. Steps to reproduce are the same as for Java app - launch the app from terminal, click back at terminal window, press Alt+Tab, then type some text. App's window will be raised but won't receive keyboard focus, while will still receive X protocol's FocusIn event.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Libera.chat.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1971693/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
Revision history for this message
Dmitry Batrak (dmitry-batrak) wrote :

The bot strongly recommends to set package for the bug, but I have no idea at the moment where the problem is exactly. This is definitely not a Java bug, my best guess is that it's a recent problem in mutter Wayland compositor, so I'll pick that. But this just as well might be e.g. an XWayland issue.
If anyone knows better, please update the package field, or let me know if I should update it.

affects: ubuntu → mutter (Ubuntu)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Hopefully this is fixed by https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2402 which has gone into the mutter 42.1 release. See also bug 1969574.

Changed in mutter (Ubuntu):
status: Confirmed → Fix Committed
tags: added: fixed-in-42.1 fixed-upstream
Revision history for this message
George (george-labuschagne-gmail) wrote :

~vanvugt Thanks! When should 42.1 come to Ubuntu 22.04?

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I don't have any ETAs. Packaging, updating the many patches we carry, and testing, all take time.

Jeremy Bícha (jbicha)
Changed in mutter (Ubuntu):
importance: Undecided → Low
Changed in mutter (Ubuntu Jammy):
importance: Undecided → Low
status: New → In Progress
description: updated
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

We should keep using bug 1969574 since that's what's been reported on and linked to for the past few weeks.

Revision history for this message
Timo Aaltonen (tjaalton) wrote : Please test proposed package

Hello Dmitry, or anyone else affected,

Accepted mutter into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/mutter/42.1-0ubuntu1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in mutter (Ubuntu Jammy):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-jammy
Revision history for this message
trespasserw (trespasserw) wrote :

Hi Timo,

could you please tell which packages should be installed from -proposed? Upgrading `mutter` and `mutter-common` to 42.1-0ubuntu1 didn't fix the problem for me :(

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package mutter - 42.1-1ubuntu1

---------------
mutter (42.1-1ubuntu1) kinetic; urgency=medium

  [ Jeremy Bicha ]
  * Merge from Debian unstable. Remaining changes:
    - Add triple-buffering patch
    - Add x11-Add-support-for-fractional-scaling-using-Randr.patch:
      + X11: Add support for fractional scaling using Randr
    - Add ubuntu/wayland-data-device-Allow-any-drag-timestamp....patch
      + Allow any drag timestamp as drag start serial
    - Add backends-native-kms-crtc-Don-t-compare-gamma-values-on-un.patch
      + Avoid memory errors when comparing gamma values
    - Add monitor-manager-Ensure-monitors-settings-after-backend-ha.patch
      + Ensure privacy screen settings are applied on startup
    - Add patches from GNOME !2364
      + Fix X11 selection related crash when Xwayland died
    - debian/libmutter-10-0.symbols: Add symbols for triple buffering patch
  * Refresh triple buffering patch with latest version

  [ Marco Trevisan (Treviño) ]
  * debian/patches: Adapt expected messages to new domains

mutter (42.1-1) unstable; urgency=medium

  * New upstream release
    (LP: #1972726, #1967274, #1965557, #1969574, #1948410, #1967219, #1971693)
  * Drop patches applied in new release
  * debian/libmutter-10-0.symbols: Add new symbol
  * debian/libmutter-10-0.symbols: Drop a symbol that was only in experimental
  * Add Breaks against old gtk3 & gtk4 versions.
    See Ubuntu bug 1972721
  * Release to unstable

mutter (42.0-5) experimental; urgency=medium

  * Team upload
  * d/patches: Update to upstream commit 42.0-74-g6c8e8fbba
    - Bug fixes targeted for 42.1
    - d/p/clutter-stage-Repick-when-pointer-actor-goes-unmapped.patch:
      Replace with the version that was applied upstream
    - d/p/core-Account-ClutterStage-grabs-on-Wayland-key-focus-sync.patch:
      Mark as applied upstream

mutter (42.0-4) unstable; urgency=medium

  * Team upload
  * d/patches: Update to upstream commit 42.0-55-gbe9deeba0
    - Update translations
    - Update upstream status of cherry-picked patches
    - Add various bug fixes including LP: #1959888, LP: #1964037
  * d/p/core-Account-ClutterStage-grabs-on-Wayland-key-focus-sync.patch:
    Add patch proposed upstream to fix grabs vs. system-modal prompts.
    This is particularly annoying when using pkexec, or when using gcr as
    a passphrase prompt for PGP, ssh and/or sudo.
    (Closes: #1008998, LP: #1964442)

 -- Jeremy Bicha <email address hidden> Fri, 13 May 2022 09:14:41 -0400

Changed in mutter (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Dmitry Batrak (dmitry-batrak) wrote :

I believe, libmutter package (libmutter-10-0 to be exact) should be upgraded to fix the problem, as mutter binary by itself isn't used by gnome-shell.

I couldn't upgrade libmutter-10-0 selectively as per https://wiki.ubuntu.com/Testing/EnableProposed due to some errors. I'm not experienced enough in Ubuntu package management system to resolve them.

I can confirm though, that a 'full' upgrade from -proposed does fix the issue for me.

Revision history for this message
trespasserw (trespasserw) wrote :

Thanks, upgrading `libmutter-10-0` along with a couple of dependencies did help.

There is weird caret blinking on switching from Terminal to IDEA (as if the former briefly regains the focus between ultimately relinquish it), but I can live with it.

Revision history for this message
Jeremy Bícha (jbicha) wrote :

I installed libmutter-10-0 42.1-0ubuntu1 and verified that the Test Case works successfully now.

tags: added: verification-done verification-done-jammy
removed: verification-needed verification-needed-jammy
Revision history for this message
Łukasz Zemczak (sil2100) wrote : Update Released

The verification of the Stable Release Update for mutter has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package mutter - 42.1-0ubuntu1

---------------
mutter (42.1-0ubuntu1) jammy; urgency=medium

  [ Jeremy Bicha ]
  * New upstream release
    (LP: #1972726, #1948410, #1967219, #1971693)
  * Refresh triple buffering patch with latest version
  * Drop patches applied in new release
  * debian/libmutter-10-0.symbols: Add new symbol
  * Add Breaks against old gtk3 & gtk4 versions.
    See Ubuntu bug 1972721

  [ Marco Trevisan (Treviño) ]
  * debian/patches: Adapt expected log messages to new domains

 -- Jeremy Bicha <email address hidden> Fri, 13 May 2022 12:10:07 -0400

Changed in mutter (Ubuntu Jammy):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.