After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 703265 - keyboard focus not moved correctly
keyboard focus not moved correctly
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: message-tray
3.8.x
Other Linux
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2013-06-28 15:24 UTC by William Jon McCann
Modified: 2013-10-08 17:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
notificationDaemon: Supply a bigger timestamp when activating the window (1.73 KB, patch)
2013-10-07 19:26 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
notificationDaemon: Focus the new window before destroying the notification (1.43 KB, patch)
2013-10-07 20:12 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description William Jon McCann 2013-06-28 15:24:59 UTC
Many times recently I've noticed that when I alt tab to another app the new window comes to the foreground visually but doesn't get keyboard focus. All typing goes to the previously used window. This is not only confusing as all get out but a pretty serious security issue.
Comment 1 William Jon McCann 2013-06-28 15:26:44 UTC
Observed on gnome-shell-3.8.3-2.fc19.x86_64.
Comment 2 Owen Taylor 2013-06-28 15:27:25 UTC
Moving to Mutter, since shell has minimal involvement here, and there were changes in the Mutter code prior to 3.8.

Do the window decorations and the focused state change for the old window? For the new window?

If anybody can provide reproduction instructions, that would be appreciated (I've never seen this on my system, so it's probably specific to *something*)
Comment 3 William Jon McCann 2013-07-01 22:51:59 UTC
I'm using maximized windows so can't answer the first and second question. But I think that the app menu definitely changed. I was in google docs writing a Document and I got a notification that my name was mentioned on irc. I can't recall if I clicked the notification or I used alt-tab. Likely one or the other. But when it switched to xchat visually the keyboard focus was still in gdocs/Firefox and I typed into my document.
Comment 4 Owen Taylor 2013-07-02 19:05:17 UTC
Can you reproduce this if intentionally with non-maximized windows?

"visually the keyboard focus was still in gdocs/Firefox"

What does that mean in detail?
Comment 5 Jasper St. Pierre (not reading bugmail) 2013-07-02 19:59:07 UTC
There are known bugs about XChat and notifications and keyboard focus, but every time I've tried to debug it, it went away.
Comment 6 Jasper St. Pierre (not reading bugmail) 2013-10-07 19:26:45 UTC
Created attachment 256666 [details] [review]
notificationDaemon: Supply a bigger timestamp when activating the window

When the user clicks on the notification, we first try to focus the last window
that the user was looking at. Afterwards, we try to focus the window that the
user wanted to raise. There's a race here: when we focus each window, we send
them both WM_TAKE_FOCUS events with the same exact timestamp, which means that
the winner is whoever processed their message and sent it off to the server
last.

This is worsened by a recent mutter bug that gets tripped up in situations like
this, leading it to stop tracking the FocusIn for the window afterwards, making
it look like no window is focused, but the last app actually does have focus.

There's no easy way to prevent the re-focusing behavior from happening, so as a
hack, make the window that the user actually wanted to raise with the
notification "win" the race by giving it a bigger timestamp.
Comment 7 Jasper St. Pierre (not reading bugmail) 2013-10-07 20:12:31 UTC
Created attachment 256671 [details] [review]
notificationDaemon: Focus the new window before destroying the notification

Destroying the notification will make the key focus be reset to NULL, which
means that gnome-shell will try to focus the MRU window, thinking the user is
done interacting and wants to go back to whatever they were doing.

Unfortunately, since we focus two windows at the same time, they will have
the same timestamp, meaning that the window that actually gets focused will
be a race as to whoever responds to their WM_TAKE_FOCUS event last.

If we explicitly set the focus beforehand, then gnome-shell will believe it
got key focus taken away from it, and won't try to focus the MRU when the
key focus drops to NULL.



---

A simpler approach that prevents focusing the other window.
Comment 8 Owen Taylor 2013-10-08 16:57:23 UTC
Review of attachment 256671 [details] [review]:

Looks good to me
Comment 9 Jasper St. Pierre (not reading bugmail) 2013-10-08 17:06:23 UTC
Attachment 256671 [details] pushed as 55edfd2 - notificationDaemon: Focus the new window before destroying the notification