Skip to content

Race condition with rapid modifier key press/release on Wayland #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sifmelcara opened this issue Apr 21, 2025 · 0 comments
Open

Race condition with rapid modifier key press/release on Wayland #1332

sifmelcara opened this issue Apr 21, 2025 · 0 comments

Comments

@sifmelcara
Copy link

Summary

On Wayland (Hyprland), I use KMonad (https://github.com/kmonad/kmonad) to rebind some keys on my keyboard to sequence of key events. For example, rebind tab key to ctrl-z (which is, "left ctrl down", "z down", "z up", "left ctrl up", without any delay inbetween). Sometimes in some programs they simply receives z key event without modifier key (ctrl) applied.

I have seen this bug happen various programs: chromium (native wayland), Qt programs (XWayland), xev, and alacritty. But not able to repro on gedit (wayland mode) and wev. When it happens, it's 100% reproducible on all the programs that's vulnerable, even after restarting fcitx.

I think it likely is a fcitx issue as the bug immediately disappears if I shutdown fcitx, and reappear after lunching fcitx again. It could also potentially be a bug of Hyprland though.

I believe it's a race condition as the bug can be workaround by inserting 5ms delay between key events (tap-macro (press-only lctl) z (release-only lctl) :delay 5).

Here is a trace of wl_keyboard events on alacritty when the bug happen:

20.6463 A: [email protected](serial=61799, time=16498316, key=29, state=1:pressed) ↲
20.6463 A: [email protected](serial=61798, time=16498316, key=29, state=1:pressed) ↲
20.6463 A: [email protected](serial=61801, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6463 A: [email protected](serial=61803, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6463 A: [email protected](serial=61800, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6463 A: [email protected](serial=61802, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6463 A: [email protected](serial=61804, time=16498316, key=20, state=1:pressed) ↲
20.6463 A: [email protected](serial=61805, time=16498316, key=20, state=1:pressed) ↲
20.6464 A: [email protected](serial=61807, time=16498316, key=20, state=0:released) ↲
20.6464 A: [email protected](serial=61809, time=16498316, key=29, state=0:released) ↲
20.6464 A: [email protected](serial=61811, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6464 A: [email protected](serial=61813, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6464 A: [email protected](serial=61806, time=16498316, key=20, state=0:released) ↲
20.6464 A: [email protected](serial=61808, time=16498316, key=29, state=0:released) ↲
20.6464 A: [email protected](serial=61810, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲
20.6464 A: [email protected](serial=61812, mods_depressed=0, mods_latched=0, mods_locked=0, group=0) ↲

The program does receive key down / key up events in correct order, but mods_depressed is not updated properly.

Steps to Reproduce

  1. Make sure fcitx is running. Input method (english/chewing/mozc) doesn't matter.
  2. Press a key that rebind to ctrl-z with KMonad (For example, ctrl-z, written as #(C-z) in KMonad).
  3. Some programs sometimes would only receives "z", without modifier key applied properly

Expected Behavior

Modifier key is applied correctly

Output of fcitx5-diagnose command

System Info:

  1. uname -a:

    Linux 6.14.1-zen1 #1-NixOS ZEN SMP PREEMPT_DYNAMIC Tue Jan  1 00:00:00 UTC 1980 x86_64 GNU/Linux
    
  2. lsb_release:

    lsb_release not found.

  3. /etc/lsb-release:

    DISTRIB_CODENAME=warbler
    DISTRIB_DESCRIPTION="NixOS 25.05 (Warbler)"
    DISTRIB_ID=nixos
    DISTRIB_RELEASE="25.05"
    LSB_VERSION="25.05 (Warbler)"
    
  4. /etc/os-release:

    ANSI_COLOR="0;38;2;126;186;228"
    BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
    BUILD_ID="25.05.20250417.b024ced"
    CPE_NAME="cpe:/o:nixos:nixos:25.05"
    DEFAULT_HOSTNAME=nixos
    DOCUMENTATION_URL="https://nixos.org/learn.html"
    HOME_URL="https://nixos.org/"
    ID=nixos
    ID_LIKE=""
    IMAGE_ID=""
    IMAGE_VERSION=""
    LOGO="nix-snowflake"
    NAME=NixOS
    PRETTY_NAME="NixOS 25.05 (Warbler)"
    SUPPORT_URL="https://nixos.org/community.html"
    VARIANT=""
    VARIANT_ID=""
    VENDOR_NAME=NixOS
    VENDOR_URL="https://nixos.org/"
    VERSION="25.05 (Warbler)"
    VERSION_CODENAME=warbler
    VERSION_ID="25.05"
    
  5. Desktop Environment:

    Cannot determine desktop environment.

  6. XDG SESSION TYPE:

    XDG_SESSION_TYPE='wayland'
    
  7. Bash Version:

    BASH_VERSION='5.2.37(1)-release'
    

Environment:

  1. DISPLAY:

    DISPLAY=':0'
    
    
    WAYLAND_DISPLAY='wayland-1'
    
  2. Keyboard Layout:

    1. setxkbmap:

      WARNING: Running setxkbmap against an Xwayland server
      xkb_keymap {
          xkb_keycodes  { include "evdev+aliases(qwerty)" };
          xkb_types     { include "complete"      };
          xkb_compat    { include "complete"      };
          xkb_symbols   { include "pc+us+inet(evdev)"     };
          xkb_geometry  { include "pc(pc105)"     };
      };
      
    2. xprop:

      _XKB_RULES_NAMES(STRING) = "evdev", "pc105", "us", "", ""
      
  3. Locale:

    1. All locales:

      C
      C.utf8
      en_US.utf8
      POSIX
      
    2. Current locale:

      LANG=en_US.UTF-8
      LC_CTYPE="en_US.UTF-8"
      LC_NUMERIC="en_US.UTF-8"
      LC_TIME="en_US.UTF-8"
      LC_COLLATE="en_US.UTF-8"
      LC_MONETARY="en_US.UTF-8"
      LC_MESSAGES="en_US.UTF-8"
      LC_PAPER="en_US.UTF-8"
      LC_NAME="en_US.UTF-8"
      LC_ADDRESS="en_US.UTF-8"
      LC_TELEPHONE="en_US.UTF-8"
      LC_MEASUREMENT="en_US.UTF-8"
      LC_IDENTIFICATION="en_US.UTF-8"
      LC_ALL=
      
  4. Directories:

    1. Home:

      /home/user
      
    2. ${XDG_CONFIG_HOME}:

      Environment variable XDG_CONFIG_HOME is set to /home/user/.config.

      Current value of XDG_CONFIG_HOME is ~/.config (/home/user/.config).

    3. Fcitx5 Settings Directory:

      Current fcitx5 settings directory is ~/.config/fcitx5 (/home/user/.config/fcitx5).

  5. Current user:

    The script is run as user (1000).

Fcitx State:

  1. executable:

    Found fcitx5 at /etc/profiles/per-user/user/bin/fcitx5.

  2. version:

    Fcitx version: 5.1.12

  3. process:

    Found 1 fcitx5 process:

       4068 .fcitx5-wrapped
    
  4. fcitx5-remote:

    fcitx5-remote works properly.

  5. DBus interface:

    Using dbus-send to check dbus.

    Owner of DBus name org.fcitx.Fcitx5 is :1.14.

    PID of DBus name org.fcitx.Fcitx5 owner is 4068.

    Debug information from dbus:

    <redacted>
    
    Input Context without group
    

Frontends setup:

The environment variable checked by this script only shows the environment under current shell. It is still possible that you did not set the environment to the whole graphic desktop session. You may inspect the actual environment variable of a certain process by using xargs -0 -L1 /proc/$PID/environ for a certain process that you find not working.

Xim:

  1. ${XMODIFIERS}:

    Environment variable XMODIFIERS is set to "@im=fcitx" correctly.
    Xim Server Name from Environment variable is fcitx.

  2. XIM_SERVERS on root window:

    Xim server name is the same with that set in the environment variable.

Qt:

  1. qt4 - ${QT4_IM_MODULE}:

    Environment variable QT_IM_MODULE is set to "fcitx" correctly.

    fcitx5-qt4-immodule-probing not found.

  2. qt5 - ${QT_IM_MODULE}:

    Environment variable QT_IM_MODULE is set to "fcitx" correctly.

    Using fcitx5-qt5-immodule-probing to check the actual im module to be used under current environment:

    QT_QPA_PLATFORM=wayland
    QT_IM_MODULE=fcitx
    IM_MODULE_CLASSNAME=fcitx::QFcitxPlatformInputContext
    
  3. qt6 - ${QT_IM_MODULE}:

    Environment variable QT_IM_MODULE is set to "fcitx" correctly.

    Using fcitx5-qt6-immodule-probing to check the actual im module to be used under current environment:

    QT_QPA_PLATFORM=wayland
    QT_IM_MODULE=fcitx
    IM_MODULE_CLASSNAME=fcitx::QFcitxPlatformInputContext
    
  4. Qt IM module files:

    Following error may not be accurate because guessing Qt version from path depends on how your distribution packages Qt. It is not a critical error if you do not use any Qt application with certain version of Qt or you are using text-input support by Qt under Wayland.
    Cannot find fcitx5 input method module for Qt4.
    Cannot find fcitx5 input method module for Qt5.
    Cannot find fcitx5 input method module for Qt6.

Gtk:

  1. gtk - ${GTK_IM_MODULE}:

    Environment variable GTK_IM_MODULE is set to "fcitx" correctly.

    fcitx5-gtk2-immodule-probing not found.

    Using fcitx5-gtk3-immodule-probing to check the actual im module to be used under current environment:

    GTK_IM_MODULE=fcitx
    

    Using fcitx5-gtk4-immodule-probing to check the actual im module to be used under current environment:

    GTK_IM_MODULE=fcitx
    
  2. gtk-query-immodules:

    1. gtk 2:

      Cannot find gtk-query-immodules for gtk 2

      Cannot find fcitx5 im module for gtk 2.

    2. gtk 3:

      Cannot find gtk-query-immodules for gtk 3

      Cannot find fcitx5 im module for gtk 3.

  3. Gtk IM module cache:

    1. gtk 2:

      Cannot find immodules cache for gtk 2

      Cannot find fcitx5 im module for gtk 2 in cache.

    2. gtk 3:

      Cannot find immodules cache for gtk 3

      Cannot find fcitx5 im module for gtk 3 in cache.

  4. Gtk IM module files:

    1. gtk 2:

      All found Gtk 2 immodule files exist.

    2. gtk 3:

      All found Gtk 3 immodule files exist.

    3. gtk 4:

      All found Gtk 4 immodule files exist.

Configuration:

Fcitx Addons:

  1. Addon Config Dir:

    Found fcitx5 addon config directory: /nix/store/h2c7l00j9w4c6cvn2s8gf9i81dbcc74i-fcitx5-5.1.12/share/fcitx5/addon.

  2. Addon List:

    1. Found 20 enabled addons:

      Classic User Interface 5.1.12
      Clipboard 5.1.12
      DBus 5.1.12
      DBus Frontend 5.1.12
      Emoji 5.1.12
      Fcitx4 Frontend 5.1.12
      IBus Frontend 5.1.12
      Input method selector 5.1.12
      Keyboard 5.1.12
      KDE Input Method Panel 5.1.12
      Status Notifier 5.1.12
      Notification 5.1.12
      Quick Phrase 5.1.12
      Spell 5.1.12
      Unicode 5.1.12
      DBus Virtual Keyboard 5.1.12
      Wayland 5.1.12
      Wayland Input method frontend 5.1.12
      XCB 5.1.12
      X Input Method Frontend 5.1.12
      
    2. Found 0 disabled addons:

  3. Addon Libraries:

    All libraries for all addons are found.

  4. User Interface:

    Found 3 enabled user interface addons:

    Classic User Interface
    KDE Input Method Panel
    DBus Virtual Keyboard
    

Input Methods:

  1. /home/user/.config/fcitx5/profile:

    [Groups/0]
    # Group Name
    Name=Default
    # Layout
    Default Layout=us
    # Default Input Method
    DefaultIM=chewing
    
    [Groups/0/Items/0]
    # Name
    Name=keyboard-us
    # Layout
    Layout=
    
    [Groups/0/Items/1]
    # Name
    Name=chewing
    # Layout
    Layout=
    
    [Groups/0/Items/2]
    # Name
    Name=mozc
    # Layout
    Layout=
    
    [GroupOrder]
    0=Default
    

Log:

  1. date:

    Mon Apr 21 11:07:34 AM CST 2025
    
  2. /home/user/.config/fcitx5/crash.log:

    /home/user/.config/fcitx5/crash.log not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant