Function key shortcuts stuck in repeat with permanent focus loss
System
- Hardware: Lenovo ThinkPad T14, BIOS 1.30
- OS: Arch Linux, kernel 5.11.12-arch1-1
- Display server: Xorg 10.20.10
- Desktop environment: XFCE 4.16
Issue
Using the shortcuts Fn+{F1,F2,F3} to mute, lower or raise the volume occasionally results in a loop of the used shortcut and permanent focus loss, preventing any other keyboard input. This mode can only be exited by using the same shortcut once more.
Expected behavior
The shortcut is issued once without repeating and permanently stealing focus.
Additional information
- using acpid to handle these shortcuts on a lower level works well
- Ubuntu 20.10 with Xorg is affected but not with Wayland
Interestingly F1,F2,F3 are affected only with Xorg, while H,L,M keep repeating without a focus loss both with Xorg and Wayland. These seem to be the only misbehaving Fn key combinations.
Reproduction
- Hold Fn and one of the previously mentioned function keys
- release Fn first
- release the function key last
Focus is now permanently lost and occasionally the shortcut is stuck in a repeat loop.
Minimal working example
#include <stdio.h>
#include <X11/Xutil.h>
void main()
{
Display* display = XOpenDisplay(0);
Window window = DefaultRootWindow(display);
XEvent ev;
int keycode;
keycode = 121; // XF86AudioMute
//keycode = 122; // XF86AudioLowerVolume
//keycode = 123; // XF86AudioRaiseVolume
XGrabKey(display, keycode, 0, window, 0, GrabModeAsync, GrabModeAsync);
while(1) {
XNextEvent(display, &ev);
switch(ev.type) {
case KeyPress:
printf("hotkey grabbed\n");
default:
break;
}
}
XCloseDisplay(display);
}