GNOME Bugzilla – Bug 657578
Toggling the state of a GtkCheckButton causes accessible window activate and deactivate signals to be emitted
Last modified: 2012-03-07 14:57:53 UTC
Created attachment 195013 [details] test script Steps to reproduce: 1. Launch the test script in a terminal 2. Launch gtk3-demo's Printing demo 3. Press Alt+R repeatedly to toggle the state of the 'Reverse' CheckButton Results: Each keypress results in window:activate and window:deactivate for the Print dialog.
This is because button activations do a key grab and a key grab moves the keyboard focus to the grab window. And then, when releasing the grab, moves the focus back to where it was before. This causes FOCUS_IN/FOCUS_OUT events and because a11y listens to those, we get events. What the code should do is listen to notify::is-active or notify:has-toplevel-focus (no idea which one).
Created attachment 203858 [details] [review] x11: Unify focus handling code This code was essentially copy-pasted in two locations, so unify them in the same place.
Created attachment 203859 [details] [review] x11: Avoid spurious focus events on grabs We want to avoid handling focus events for the private focus window, otherwise the keyboard grab taken by for example buttons will cause a spurious FOCUS_OUT/FOCUS_IN on the toplevel. The code that did this seems to have been lost in the XI2 transition for GTK3.
Makes sense to me. Looking at gtk+ 2.24, I see that we had explicit code to ignore anything but key events on focus_window - do we need something like that, or are these focus events the only thing that happens to the focus window ?
http://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkwindow-x11.c?h=3.2.0#n564 says that we only use GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK. And as we do want and do handle KeyPress and KeyRelease events properly, I think these are the only other events. I could probably also remove GDK_FOCUS_CHANGE_MASK here, but I'm not sure this has side effects, so I opted for restoring GTK2 behavior instead.
Comment on attachment 203859 [details] [review] x11: Avoid spurious focus events on grabs I'm reopening this bug because the patch was backed out. It turns out that it causes some important focus events to not fire because of https://bugs.freedesktop.org/show_bug.cgi?id=44079 - we should wait until that is fixed inside the X server and people actually run that X server before applying this patch again.
Comment on attachment 203859 [details] [review] x11: Avoid spurious focus events on grabs Patch was committed as db4a6040afd3d1cabbb306037e811f37d62e2e76 and reverted by 18406b7b04da088f8a3efe7cca5ac1647080dc0b , hence updating status to get it off the "accepted-commit_now" list.
Committed the patch again. See https://mail.gnome.org/archives/gtk-devel-list/2012-March/msg00017.html for details.