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 762756 - keyboard focus problem on dismiss of menus under wayland
keyboard focus problem on dismiss of menus under wayland
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Wayland
3.19.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 765477 766594 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-02-26 21:32 UTC by Caolan McNamara
Modified: 2016-05-18 07:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtk-demo patch to demo this (1.41 KB, patch)
2016-02-26 21:32 UTC, Caolan McNamara
none Details | Review
Simple reproducer for testing purpose. (2.37 KB, text/plain)
2016-04-27 07:21 UTC, Olivier Fourdan
  Details
wayland: Perform seat grab focus checks on native windows (3.40 KB, patch)
2016-04-27 10:15 UTC, Carlos Garnacho
committed Details | Review

Description Caolan McNamara 2016-02-26 21:32:49 UTC
Created attachment 322494 [details] [review]
gtk-demo patch to demo this

A patch to gtk3-demo to demo an apparent keyboard focus problem on deactivation of a menu belonging to a menubar

a) in gtk3-demo activate the menus example
b) click in the gtkentry, cursor is visible
c) activate a menu in the menubar
d) press esc
e) cursor remains unshown in gtkentry, but typing will add text to it

alt tab to another app and back and it regains its focus

this also affects glade and LibreOffice (with experimental native gtk3 menubar
enabled)

Maybe a missing focus-in-event to the toplevel after the menu window is dismissed ?
Comment 1 Olivier Fourdan 2016-04-22 12:06:09 UTC
Yes, same with gnome-terminal, very visible if using the block shaped cursor.
Comment 2 Olivier Fourdan 2016-04-22 14:14:48 UTC
Seems this is a regression introduced with the GdkSeat implementation but a more precise git bisect is not really possible because the tree doesn't always build for each commit.

Adding Carlos in CC.
Comment 3 Olivier Fourdan 2016-04-27 07:21:26 UTC
Created attachment 326834 [details]
Simple reproducer for testing purpose.

This simple reproducer demonstrates that the bug is related to a focus-out event which is received in Wayland and not in X11.

 1. Build and run the probgram in X11
 2. Open the menu, dismiss, no focus out.

Now redo the same in Wayland:

 3. Open the menu, a focus-out event is received and the cursor stops.

I could not use git bisect, but simply reverting commit d54f208d on master fixes the issue so this is really gdk_seat_grab() with GtkMenu causing the issue.
Comment 4 Olivier Fourdan 2016-04-27 08:05:52 UTC
Ok, could be because the Wayland and X11 backend differ wrt focus handling.

The X server will emit FocusIn and FocusOut events on grab/ungrab and the X11 backend handles that in _gdk_device_manager_core_handle_focus() taking into account things like the mode and detail given by the XEvent. The X11 backend will not necessarily emit the focus change GdkEvent.

The Wayland backend tries to emulate that but emits the focus change GdkEvent quite unconditionally, and I reckon this could be the problem.

Relevant code:

For X11: https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkdevicemanager-core-x11.c#n811

For Wayland: gdk_wayland_device_grab() https://git.gnome.org/browse/gtk+/tree/gdk/wayland/gdkdevice-wayland.c#n642
and device_emit_grab_crossing() https://git.gnome.org/browse/gtk+/tree/gdk/wayland/gdkdevice-wayland.c#n600
Comment 5 Olivier Fourdan 2016-04-27 08:41:55 UTC
In the X11 case, when opening the menu, we have:

Gdk-Message: focus out:		window: 46137347, detail: NotifyAncestor, mode: NotifyGrab
Gdk-Message: focus out:		window: 46137347, detail: NotifyInferior, mode: NotifyGrab

And then for that window, HAS_FOCUS (toplevel) == true, had_focus == true, therefore (HAS_FOCUS (toplevel) != had_focus) is false, the GDK_FOCUS_CHANGE event is not emitted.
Comment 6 Carlos Garnacho 2016-04-27 10:15:03 UTC
Created attachment 326851 [details] [review]
wayland: Perform seat grab focus checks on native windows

We don't care about the specific (possibly client-side) window that
requested the focus here, only the toplevel. Fixes mistakenly sent
focus events when the grab happens inside the current focus window.
Comment 7 Carlos Garnacho 2016-04-27 11:31:49 UTC
Attachment 326851 [details] pushed as 14967d8 - wayland: Perform seat grab focus checks on native windows
Comment 8 Carlos Garnacho 2016-04-27 11:33:10 UTC
*** Bug 765477 has been marked as a duplicate of this bug. ***
Comment 9 Carlos Garnacho 2016-04-27 11:35:52 UTC
The patch has been also backported to gtk-3-20
Comment 10 zhouzhenghui 2016-05-18 07:56:33 UTC
*** Bug 766594 has been marked as a duplicate of this bug. ***