Commit 85d8d390 authored by Jan Ziak's avatar Jan Ziak Committed by Andre Miranda

Avoid redundant key re-grabbing

XFCE desktop shortcuts are unusable for about 30-40 seconds
after switching from tty to Xorg if there exists a .Xmodmap
file in $HOME. Without a .Xmodmap file, the delay is about 10
seconds. Similar behavior gets triggered when a keyboard is
reconnected to an USB port. With this patch, desktop shortcuts
are usable immediately (likely in less than 0.25 seconds after
switching from tty to Xorg).

An issue not fixed by this patch is that /usr/bin/xmodmap
can be executed about 30 times after switching to Xorg.
However, on the tested machine with a relatively small .Xmodmap
this does not pose a performance issue which would be noticeable
by the user.

Closes: xfce/libxfce4ui#9
Closes: xfce/xfce4-settings#168
Closes: xfce/xfce4-settings#228
Mitigates: xfce/xfce4-settings#167
See also: xfce/xfce4-settings#93

parent 5f133f27
Pipeline #3536 passed with stages
in 2 minutes and 14 seconds
......@@ -70,11 +70,19 @@ struct _XfceShortcutsGrabberPrivate
GHashTable *keys;
typedef enum
UNDEFINED_GRAB_STATE = 0, /* Initial value after g_new0(XfceKey) */
} XfceKeyGrabState;
struct _XfceKey
guint keyval;
guint modifiers;
GArray *keycodes;
guint keyval;
guint modifiers;
GArray *keycodes;
XfceKeyGrabState grab_state;
......@@ -172,7 +180,6 @@ xfce_shortcuts_grabber_keys_changed (GdkKeymap *keymap,
TRACE ("Keys changed, regrabbing");
xfce_shortcuts_grabber_ungrab_all (grabber);
  • On FreeBSD many users are reporting problems with keyboard (usually with the up arrow key) and shortcuts that seem to be fixed by adding back this line.

    I understand this change was made to avoid some high CPU and delay issues, but I was wandering if it could be be put back, maybe with some condition around it?

    I can add a patch in the FreeBSD port, but I'd like to be aligned with official XFCE, Any suggestion on how to handle this?

  • Thanks for reporting this. Unfortunately, I am unable to install FreeBSD in VirtualBox (in particular FreeBSD-13.0-CURRENT-amd64-20210107-f2b794e1e90-255641-disc1.iso) - any suggestion about how to install FreeBSD in VirtualBox would be helpful.

    I don't recommend reverting the line xfce_shortcuts_grabber_ungrab_all(grabber); in FreeBSD without checking whether adding the line causes 30-40 seconds delay when switching from tty to Xorg.

  • For installing FreeBSD I'd try with a release ISO, 12.2 is the latest official release, should be easier.

    For guidance on how to install in virtualbox you can reference the handbook:

    Unluckily I'm unable to properly test this because I'm not experiencing the issue. I'm quite sure FreeBSD has a consle switching mechanism different than linux though. I'll try to investigate this.

  • On my machine, which was not experiencing the key binding issue though, I am able to switch from vty (which are FreeBSD text consoles) to X11 without any delay even with the xfce_shortcuts_grabber_ungrab_all() call. Also bound keys work immediately after the switch.

    This could be due to FreeBSD virtual vty (virtual terminal) code being different than the linux one. I'm just guessing.

    I'm going to test this a little more and propose a patch to reintroduce the xfce_shortcuts_grabber_ungrab_all() call for FreeBSD only, via an #ifdef.

    Edited by Guido Falsi
Please register or sign in to reply
xfce_shortcuts_grabber_grab_all (grabber);
......@@ -242,6 +249,12 @@ xfce_shortcuts_grabber_grab (XfceShortcutsGrabber *grabber,
g_return_if_fail (XFCE_IS_SHORTCUTS_GRABBER (grabber));
g_return_if_fail (key != NULL);
if (key->grab_state == (grab ? GRABBED : NOT_GRABBED)) {
TRACE (grab ? "Key already grabbed" : "Key already ungrabbed");
key->grab_state = UNDEFINED_GRAB_STATE;
display = gdk_display_get_default ();
screens = 1;
keymap = gdk_keymap_get_for_display (display);
......@@ -253,11 +266,7 @@ xfce_shortcuts_grabber_grab (XfceShortcutsGrabber *grabber,
/* Debugging information */
shortcut_name = gtk_accelerator_name (key->keyval, modifiers);
if (grab)
TRACE ("Grabbing %s", shortcut_name);
TRACE ("Ungrabbing %s", shortcut_name);
TRACE (grab ? "Grabbing %s" : "Ungrabbing %s", shortcut_name);
TRACE ("Keyval: %d", key->keyval);
TRACE ("Modifiers: 0x%x", modifiers);
......@@ -289,6 +298,7 @@ xfce_shortcuts_grabber_grab (XfceShortcutsGrabber *grabber,
numlock_modifier =
XkbKeysymToModifiers (GDK_DISPLAY_XDISPLAY (display), GDK_KEY_Num_Lock);
key->grab_state = (grab ? GRABBED : NOT_GRABBED);
for (i = 0; i < n_keys; i ++)
/* Grab all hardware keys generating keyval */
......@@ -349,10 +359,8 @@ xfce_shortcuts_grabber_grab (XfceShortcutsGrabber *grabber,
if (gdk_x11_display_error_trap_pop (display))
if (grab)
TRACE ("Failed to grab");
TRACE ("Failed to ungrab");
TRACE (grab ? "Failed to grab" : "Failed to ungrab");
key->grab_state = UNDEFINED_GRAB_STATE;
/* Remember the old keycode, as we need it to ungrab. */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment