Bug 2173985

Summary: XWayland apps steal focus
Product: [Fedora] Fedora Reporter: Jiri Eischmann <jeischma>
Component: mutterAssignee: Florian Müllner <fmuellner>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 38CC: alciregi, awilliam, fmuellner, fzatlouk, gnome-sig, jadahl, kparal, lruzicka, mail, otaylor, philip.wyett, pnemade, renault, robatino, rstrode, sbierman, walters, wtogami, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: AcceptedFreezeException
Fixed In Version: mutter-44~beta-3.fc38 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-03-07 19:43:47 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2083911, 2083912    

Description Jiri Eischmann 2023-02-28 15:20:50 UTC
I run GNOME 44.beta on Fedora 38 and I've noticed that apps running on XWayland steal focus from other windows to the point that it prevents me from using them. See the linked video.
I've been able to reproduce it with three applications running on XWayland: Firefox, Chrome and GIMP.
You can get the video here: https://vps.eischmann.cz/nextcloud/index.php/s/kefsSDSaGpcBLQt

Comment 1 Fedora Blocker Bugs Application 2023-02-28 15:23:40 UTC
Proposed as a Blocker for 38-final by Fedora user eischmann using the blocker tracking app because:

 The intensity of stealing the focus is so high that it basically prevents you from using other apps on the same workspace.

Comment 2 Lukas Ruzicka 2023-03-02 14:05:32 UTC
I am unable to reproduce on my laptop. I have tried with Gimp and Chromium, but I can easily switch between windows withou any problems with focus. The same holds true for laptop only mode, or with external monitors, the single apps being placed on one desktop or multiple desktops.

Laptop is Lenovo P1 4th gen, running 6.2.1-300.fc38.x86_64 with gnome-shell-44~beta-2.fc38.x86_64.

Comment 3 Alessio 2023-03-03 11:37:11 UTC
*** Bug 2175151 has been marked as a duplicate of this bug. ***

Comment 5 Adam Williamson 2023-03-04 02:56:28 UTC
The upstream issue suggests this isn't so much about the app 'stealing' the focus as the app *losing* it? Like Lukas I cannot reproduce this (I've been using F38 for months and have zero issues like this), but that may be because I'm not running any Java/Swing apps...

Comment 6 Zbigniew Jędrzejewski-Szmek 2023-03-04 09:27:33 UTC
I was using 'git gui' (X11 app with tcl/tk) and focus handling was also messed up,
but I wasn't able to pin down the exactly problem. I can't reproduce the issue now.
Anyway, I'll report if I have more info, but if it's the same issue, it's not related
to Java/Swing.

Comment 7 Warren Togami 2023-03-04 09:34:32 UTC
I have two systems here with a fresh Fedora 37 Workstation install from yesterday upgraded to Fedora 38. Here's the 100% reproduce procedure for two related failures.

Scenario 1: XWayland -> Launch Wayland app
==========================================
1. Login to GNOME.
2. Run any Xwayland app. glxgears or chromium both work.
3. Super+gnome-terminal launch
4. FAIL: You see gnome-terminal but the cursor is hollow instead of solid indicating it lacks input focus. Clicking within the terminal doesn't fix keyboard input focus. Clicking on UI elements in that wayland app does work.
5. FAIL: Immediately after gnome-terminal had launched try alt-tab. gnome-terminal is missing as a valid alt-tab window for quite a while so it doesn't work. Wait long enough and it appears. Then alt-tab to the Xwayland app then back to the wayland app fixes input focus for the latter.

Scenario 2: XWayland -> Super+Click to Wayland app
==================================================
1. Login to GNOME.
2. Run any wayland app (e.g. gnome-terminal is good choice because the hollow cursor is a visible indicator that window doesn't have input focus)
3. Run any Xwayland app (e.g. chromium defaults to X11 unless you change it in about:flags)
4. Alt-tab to the wayland app. This works no problem.
5. Alt-tab back to the Xwayland app.
6. FAIL: Super+Click to switch to the wayland app. gnome-terminal shows the hollow cursor indicating it doesn't have input focus. Typing does nothing. Clicking fails to switch input focus to the window.
7. Alt-tab to the Xwayland app then back to the wayland app fixes input focus.

Notes
=====
* halfline had a hunch this was a stuck modifier. Tried removing ibus-typing-booster and upgrading xorg-x11-server-Xwayland to F39 version, no change of behavior. The way how keyboard input fails to do anything entirely suggests this isn't a stuck modifier.

Comment 8 Ray Strode [halfline] 2023-03-04 13:20:16 UTC
see https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2878

Comment 9 Ray Strode [halfline] 2023-03-04 13:53:20 UTC
I haven't been following along on this issue, but I did a scratch build with Carlos's fixes here:

https://koji.fedoraproject.org/koji/taskinfo?taskID=98277581

if anyone wants to try it.

Comment 10 Adam Williamson 2023-03-04 16:49:53 UTC
Ray: that MR is listed as addressing https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5932 , which is reported as being specific to GNOME-on-X11.

What https://gitlab.gnome.org/GNOME/mutter/-/issues/2635 (the upstream issue originally linked here) actually says is "Globally active X11 windows, which usually means any Java/Swing windows, like IntelliJ for example, don't receive input focus anymore after some of the recent grab/focus related changes." That is, Java/Swing apps aren't the *only* affected apps, just a *common* type of affected app. BUt "Globally active X11 windows" isn't "all X11 windows", is it? I don't know what "globally active" *means* exactly, it might be useful to have a definition. Presumably Chromium and glxgears are "globally active"? What would *not* be "globally active"?

Comment 11 Warren Togami 2023-03-04 18:12:43 UTC
I confirmed Ray's scratch build solved the problem for me! It fixed both of the scenarios I wrote above in comment 7. 

I don't know about "globally active" but the following apps all triggered the input focus problem when using Super to switch to a wayland app.
chromium, glxgears, gparted, hexchat

Comment 12 Ray Strode [halfline] 2023-03-04 18:16:20 UTC
afaict, "globally active" means "window that explicitly calls XSetInputFocus itself."

Anyway, to be clear (now, that is. tbf, I didn't mention it before),
one of the patches I added to the scratch build has this commit message:

From faa003812c10ab14bc69d6add078ff10528dc78b Mon Sep 17 00:00:00 2001
Subject: [PATCH 1/3] x11: Avoid updating focus on wayland compositor
...
An example of this breaking can be reproduced with a Spotify and
Firefox window, moving the focus from the first to the second by
going to the GNOME Shell overview in between, and clicking the
Firefox window from there. The Firefox window will be raised, but
refuse to take focus.
...

It's one that was already merged upstream.

Comment 13 Ray Strode [halfline] 2023-03-04 20:14:21 UTC
(well more likely, I guess, "globally active" means app has input focus in Xwayland and mutter)

Comment 14 Adam Williamson 2023-03-05 17:07:34 UTC
There's +4 for Beta FE in https://pagure.io/fedora-qa/blocker-review/issue/1057 , so listing as accepted FE.

I was able to reproduce this with glxgears, and yeah, it's pretty wacky. For me it also hung around after I quit glxgears, which is...fun.

Comment 15 Couret Charles-Antoine 2023-03-05 17:10:26 UTC
I agree with you Adam, I've the impression it's not happening every time (here with Thunderbird), and when it happens a reboot or playing with TTY switchings can be required to fix it.
Very annoying when it's happening.

Comment 16 Ray Strode [halfline] 2023-03-05 18:05:09 UTC
okay since warren confirmed the scratch build worked, I'll just build that directly.

Comment 17 Ray Strode [halfline] 2023-03-05 18:16:24 UTC
i started the build here: Task info: https://koji.fedoraproject.org/koji/taskinfo?taskID=98329439


I've gotta make a run to the airport, now, though. if someone else wants to run fedpkg update...otherwise will do when i get back in a couple of hours.

Comment 18 Fedora Update System 2023-03-05 21:07:21 UTC
FEDORA-2023-b05331d2bc has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2023-b05331d2bc

Comment 19 Fedora Update System 2023-03-06 02:26:15 UTC
FEDORA-2023-b05331d2bc has been pushed to the Fedora 38 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-b05331d2bc

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 20 Jiri Eischmann 2023-03-06 09:15:41 UTC
The latest update with backported focus fixes works for me and I no longer experience this bug.

Comment 21 František Zatloukal 2023-03-06 14:57:22 UTC
Discussed in ticket: https://pagure.io/fedora-qa/blocker-review/issue/1057

The decision to classify this bug as an RejectedBlocker (Beta) was made:

"This doesn't affect any pre-installed applications and so doesn't violate any Beta Release Criteria."

Comment 22 Fedora Update System 2023-03-07 19:43:47 UTC
FEDORA-2023-b05331d2bc has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 23 Silvio Bierman 2023-04-21 10:58:33 UTC
I run Fedora 38 and have been since before the beta came out. From the beginning I have been experiencing focus issues. The pattern is:

After login:

- open an application (gnome terminal works, but so does Chrome)
- see application get focus (cursor looks normal, typing works)
- open a second window for the same application or open any other application
- expect the focus to be on the newly opened application/window
- type anything and discover the focus is still on the previous window
- open any new application (even after closing all previously opened windows) and see they do not receive focus

I am running the latest updates of F38 with default Gnome desktop / Wayland.

The bug is maddening. Expecting to be typing in the Chrome address bar but being inside an obscured terminal is frightening enough. Experiencing the same when you expect to be in new local terminal window while still typing inside an obscured server side terminal session is pure horror!

I actually expected this problem to be fixed very soon because of the severity. Now that F38 has been released the bug is still there so I decided to report.

Cheers,

Silvio

Comment 24 Adam Williamson 2023-04-21 15:59:26 UTC
Hi Silvio! Sorry about that. Can you file a new report? This specific bug was reproduced by multiple people (see above) and reported definitely fixed by the update (also see above), so whatever you're seeing, it's not exactly this bug.

I wasn't aware that anyone was still having problems along these lines; if such a report had been flagged as a potential blocker bug it would've been reviewed as one prior to F38's release, but none was.