! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Shortcuts stop working for ~15s when connecting a USB keyboard
Status:
RESOLVED: MOVED
Product:
Libxfce4ui
Component:
General

Comments

Description Igor Kushnir 2019-01-10 15:41:19 CET
Created attachment 8236 
Simple workaround for repeating xfce_shortcuts_grabber_keys_changed calls

Whenever I connect an external USB keyboard, xfsettingsd's and Xorg's CPU usage increases. In GNOME System Monitor xfsettingsd's Status changes from Sleeping to Running and it takes 1-2% CPU; Xorg's CPU usage jumps from 1-2% to 25%, i.e. the entire CPU core in my 4-core system. During this high CPU usage time (~15s) keyboard shortcuts - configured in XFCE settings -> Keyboard -> Application Shortcuts - don't work.

I have this problem for many months (maybe years) now. A similar shortcuts-not-working-for-a-time issue happens when resuming from hibernation. Similar issues were reported: https://forum.manjaro.org/t/keyboard-shortcuts-stop-working-after-reconnecting-the-usb-keyboard-when-xmodmap-is-present/39482, https://forum.manjaro.org/t/keyboard-shortucts-stop-working-in-xfce-after-user-switch-resume/35849/9 and on other forums/bug trackers as well. I don't use Xmodmap, but I do have 2 keyboard layouts configured. The issue happens on my Manjaro system with the packaged versions of XFCE packages as well as with the latest git versions of libxfce4ui, exo, xfconf and xfce4-settings. The issue does not happen on a Debian stable (stretch) system with its packaged XFCE versions with similar configuration (2 layouts).

When I attach to the xfsettingsd process in KDevelop and interrupt it right after plugging in a USB keyboard, I get xfce_shortcuts_grabber_keys_changed->...->xfce_shortcuts_grabber_grab in the frame stack. I made the following change in libxfce4ui's xfce-shortcuts-grabber.c:
-  TRACE ("Keys changed, regrabbing");
+  DBG ("Keys changed, regrabbing");
The line
"DBG[xfce-shortcuts-grabber.c:168] xfce_shortcuts_grabber_keys_changed(): Keys changed, regrabbing"
is repeated 50 times in xfsettingsd's output when I launch it like this: (XFSETTINGSD_DEBUG=1 xfsettingsd --no-daemon --replace &> /home/igor/Documents/tmp/xfsettingsd-git.log &). The same line is repeated 525 times in the output when I connect an external USB keyboard.

Any ideas why the GDK keys-changed signal is emitted so many times? If it is not possible to stop GDK from emitting the signal repeatedly, perhaps a workaround should be implemented in libxfce4ui that handles this signal at most once each 5 seconds.
For example, store the timestamp of the last call to xfce_shortcuts_grabber_keys_changed. If the next call happens before 5 seconds elapse, schedule executing xfce_shortcuts_grabber_keys_changed in 5 seconds time and return from it immediately. Then return immediately from the future calls to this function until the 5 seconds pass and xfce_shortcuts_grabber_keys_changed is called by the 5s-timer.

In fact, even a much simpler workaround - simply ignoring xfce_shortcuts_grabber_keys_changed calls for 5 seconds after its last full execution - works for me: the high CPU usage practically disappears, shortcuts work without interruptions. One downside of the simple workaround is that without knowing what exactly triggers repeated keys-changed signals, there is a risk of some configuration loss. Also if genuine configuration changes happen twice in the course of 5 seconds, the second one won't be handled. The simple workaround patch is attached to this issue for illustration and experimentation purposes.
Comment 1 Igor Kushnir 2019-01-13 17:08:31 CET
I reported the repeating GDK keys-changed signal issue here: https://gitlab.gnome.org/GNOME/gtk/issues/1582.
Comment 2 Igor Kushnir 2019-01-25 15:12:49 CET
Created attachment 8263 
Simple test application
Comment 3 Igor Kushnir 2019-01-25 15:13:52 CET
I have done some more testing and think that this issue is probably caused by xfsettingsd or libxfce4ui. I don't think that GDK should be blamed. Turns out that GTK applications (such as gnome-system-monitor and gtk3-demo) don't receive any keys-changed signals in KDE Plasma 5 session when I disconnect and connect a USB keyboard. My simple Test_xfce_shortcuts_grabber_new application (https://bugzilla.xfce.org/attachment.cgi?id=8263) creates XfceShortcutsGrabber with xfce_shortcuts_grabber_new(), but does not receive these signals in the KDE session either. However when I launch xfsettingsd in the KDE session, all of the aforementioned applications (including xfsettingsd itself) start receiving hundreds of keys-changed signals upon keyboard reconnection.

I can't figure out how xfsettingsd causes all GTK applications to receive hundreds of these signals. Unless someone can help me debug this, I'll resort to implementing the 5s-timer workaround from the penultimate paragraph in the issue description.
Comment 4 Igor Kushnir 2019-02-14 11:44:12 CET
Created attachment 8297 
A proper 300ms timer workaround

This patch implements the workaround outlined above properly. 300ms timeout turned out to be sufficient. This time interval is small enough to go unnoticed by a user, which allowed me to simplify and optimize the implementation. The patch works perfectly on my system.
Comment 5 inactive 2020-04-23 00:25:56 CEST
Thanks for this patch, it mitigates my issue https://bugzilla.xfce.org/show_bug.cgi?id=16737
Comment 6 Git Bot editbugs 2020-05-25 23:02:03 CEST
-- GitLab Migration Automatic Message --

This bug has been migrated to xfce.org'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.xfce.org/xfce/libxfce4ui/-/issues/9.

Please create an account or use an existing account on one of our supported OAuth providers. 

If you want to fork to submit patches and merge requests please continue reading here: https://docs.xfce.org/contribute/dev/git/start#gitlab_forks_and_merge_requests

Also feel free to reach out to us on the mailing list https://mail.xfce.org/mailman/listinfo/xfce4-dev

Bug #15032

Reported by:
Igor Kushnir
Reported on: 2019-01-10
Last modified on: 2020-05-25

People

Assignee:
Nick Schermer
CC List:
5 users

Version

Attachments

Simple workaround for repeating xfce_shortcuts_grabber_keys_changed calls (878 bytes, patch)
2019-01-10 15:41 CET , Igor Kushnir
no flags
Simple test application (1.08 KB, application/zip)
2019-01-25 15:12 CET , Igor Kushnir
no flags
A proper 300ms timer workaround (4.83 KB, patch)
2019-02-14 11:44 CET , Igor Kushnir
igorkuo : review+

Additional information