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 780422 - Focus events are not always matched
Focus events are not always matched
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Backend: Wayland
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-03-22 21:17 UTC by Jonathon Jongsma
Modified: 2018-05-02 18:19 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jonathon Jongsma 2017-03-22 21:17:03 UTC
In virt-viewer, we are getting a warning in the terminal when running under wayland. 

Some very short background: virt-viewer does certain things (e.g. grab the keyboard, enable usb auto-redirect, etc) when the spice widget gets focus, and "undoes" those things when the widget loses focus. 

The reason that we are getting a warning is because we are not getting matched focus-in and focus-out events. When running under wayland in Fedora 25, if we click inside the virt-viewer window, a focus-in event is generated. However, when clicking outside of the window, *two* focus-out events are generated. The handler for the first event runs without problem, but the second one generates a warning since it is attempting to perform a task that has already been performed by the first handler.

I bisected gtk+ to determine when the problem appeared, and came up with the following commit:

commit de2268000d7e3eb5e84603810f9a6f971efb1072
Author: Carlos Garnacho <carlosg@gnome.org>
Date:   Wed Jun 24 17:48:18 2015 +0200

    wayland: Ensure device grabs generate crossing/focus events
    
    On X11 this is something the windowing system does for us, which the
    wayland backend should emulate, being grabs completely client-side.
    
    So, if the grab and current focus windows differ, make sure we emit
    focus/crossing events as it corresponds to the grab device.

I've not yet been able to create a minimal test case to trigger this bug in gtk+.

This bug was initially opened in the spice bug tracker, but after discussing it with some Gtk+ developers, they suggested opening a bug in Gtk+. Original bug is here: https://bugs.freedesktop.org/show_bug.cgi?id=99296
Comment 1 Olivier Fourdan 2018-04-19 09:57:42 UTC
So, I took a closer looks at this issue.

I reckon the problem comes from device_emit_grab_crossing() in gdkdevice-wayland.c *and* the way spice-gtk uses grabs.

Basically, spice-gtk issue a grab each time the pointer enters the spice-gtk window and release the grab when the pointer leaves the widget.

When the grab is on the keyboard (as it is here), a focus event is sent (either focus_in of focus_out).

In gdk_wayland_device_grab(), device_emit_grab_crossing() is called only if the current keyboard focus differs from the window on which the grab is issued.

Similarly, in gdk_wayland_device_ungrab(), device_emit_grab_crossing() is called only if the window with a grab (if any) differs from the currently focused window.

But entering/leaving widget does not atually change keyboard focus (it's an emulated event), so when the user clicks on another window, a real focus_out event is emitted.

So spice-gtk logic of issuing a _keyboard_ grab/ungrab on _pointer_ enter/leave events defeats the logic in gdkdevice-wayland.c
Comment 2 GNOME Infrastructure Team 2018-05-02 18:19:17 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/792.