GdkKeymap::keys-changed signal is emitted many times when connecting a USB keyboard
Steps to reproduce
- Track a callback that is connected to the
GdkKeymap::keys-changed
signal. For example, debug the program from the second step in an IDE or attach to that process after launching, and put a breakpoint into thekey_hash_keys_changed()
callback in gtkkeyhash.c. You can also add aputs("key_hash_keys_changed");
line intokey_hash_keys_changed()
and recompile GTK. - Launch a GTK program such as gnome-system-monitor or gtk3-demo.
- Connect a USB keyboard (or disconnect, then connect a USB or PS/2 keyboard).
Current behavior
The GdkKeymap::keys-changed
signal is emitted repeatedly and the key_hash_keys_changed()
callback is called from 575 to 3150 times after a single keyboard connection. Luckily key_hash->keycode_hash
is always NULL
and the function returns immediately (at least during my tests).
Expected outcome
The GdkKeymap::keys-changed
signal is emitted once and the key_hash_keys_changed()
callback is called once.
Version information
- Latest version of GTK+ from the gtk-3-24 branch: 3.24.2-83-g3c49c593
- Manjaro Linux stable with the latest updates as of 2019-01-13
- X11 session
- XFCE desktop environment
- GTK+ was configured like this for testing:
./configure --prefix=/home/igor/Documents/C/LinuxProjects/external/installed --enable-debug=yes
. However the Arch and Manjaro-packaged version of gtk3 exhibits the same behavior. - Possible relevant system configuration: I'm not using .Xmodmap; I'm using 2 keyboard layouts - English (programmer Dvorak) and Ukrainian. But the issue happens even if I remove one of the layouts or if I replace these two layouts with a single English US layout.
Additional information
The tests described above are artificial and do not constitute an issue on their own. However the repeated emitting of the signal can cause issues to applications that connect a slow-running callback to this signal. In particular this causes performance issues to libxfce4ui and xfsettingsd as described in this XFCE bug report. The specific slow libxfce4ui callback connected to the signal is xfce_shortcuts_grabber_keys_changed()
.
Note that the GdkKeymap::keys-changed
signal is emitted multiple times in other scenarios as well, such as simply launching an application or resuming from hibernation (I have traced these events only in xfsettingsd).
If this is not a bug and emitting the GdkKeymap::keys-changed
signal so many times after a single user-initiated event is normal, please mention this in the GDK documentation; and please recommend how to avoid performance issues in callbacks connected to this signal (either in the documentation or in a comment to this issue).