Alacritty stopped accepting keyboard input on X11 due to a wedged fcitx XIM context

One of my Alacritty windows on Linux Mint (X11/Cinnamon) suddenly stopped accepting keyboard input while holding an active tmux and SSH session. Other Alacritty windows on the same desktop kept working normally.

The terminal itself was not frozen: the tmux status clock kept ticking, the SSH connection stayed alive, and Alacritty’s IPC socket answered immediately. A wedged fcitx XIM context for that single window was swallowing every X11 KeyPress before it reached Alacritty’s keyboard handler. Restarting fcitx (fcitx -r -d) recovered the window in place without closing it, and launching Alacritty with XMODIFIERS=@im=none prevents the freeze from coming back.

Problem 1: One Alacritty window silently drops all keystrokes

Before touching the session, I checked each layer in the input path from another terminal:

  1. Alacritty process & event loop: alacritty msg --socket /run/user/1000/Alacritty-:0-<pid>.sock get-config returned immediately with exit code 0, and the tmux clock inside the window continued updating every second.
  2. PTY & tmux: stty -a -F /dev/pts/<N> showed no ixon / Ctrl-S flow-control freeze; tmux list-clients and tmux display-message showed the pane was not dead, not in copy/Vi mode, and not read-only.
  3. SSH: ss -tipn showed Recv-Q=0, Send-Q=0, and active keepalive traffic on the TCP socket.

With tmux and SSH ruled out, the drop had to be inside X11 / winit / IME. Comparing the stuck Alacritty instance against a healthy one exposed the exact point of failure:

  • Tracing recvmsg on the stuck Alacritty’s X11 socket (strace -e trace=recvmsg -x -p <pid>) showed that X11 KeyPress events did arrive at the window, and Alacritty forwarded them to fcitx over _XIM_PROTOCOL ClientMessage events.
  • However, fcitx never sent XIM_FORWARD_EVENT back for that window’s XIM input context.
  • In winit on X11 (winit/src/platform_impl/linux/x11/event_processor.rs), key events are passed through XFilterEvent:
1
2
3
4
let filtered = forward_to_ime && self.filter_event(xev);
if filtered {
    return;
}

When fcitx’s XIM state gets wedged for a window, XFilterEvent consumes the KeyPress (True) and fcitx never forwards it back. Setting a breakpoint on Alacritty’s keyboard entry point (alacritty/src/input/keyboard.rs:22) and sending a harmless Shift_L key event confirmed it:

  • Working Alacritty window: 2 hits (press + release)
  • Stuck Alacritty window: 0 hits

Because each window has its own XIM input context (XIC), one Alacritty window can freeze completely while other Alacritty windows keep working.

Solution 1: Recover the stuck window in place

Reloading fcitx config alone is not enough—fcitx-remote -r keeps the same fcitx process and its wedged XIM context. You need to restart the fcitx daemon so winit tears down the stale XIM connection and creates a fresh one:

1
fcitx -r -d

After restarting fcitx:

  • strace immediately showed fcitx returning XIM_FORWARD_EVENT (0x2c) for KeyPress and KeyRelease on the previously stuck window.
  • The Shift_L probe hit alacritty/src/input/keyboard.rs:22 2/2 times, matching the working window.
  • No terminal windows, tmux sessions, or SSH connections had to be closed.

Solution 2: Prevent the freeze permanently

All running Alacritty instances inherited XMODIFIERS=@im=fcitx from the desktop session. If you don’t need Chinese/IME input inside Alacritty, disable XIM for Alacritty in ~/.local/share/applications/Alacritty.desktop:

1
2
3
4
5
6
7
8
9
[Desktop Entry]
Type=Application
TryExec=/home/william/.local/bin/alacritty
Exec=env XMODIFIERS=@im=none /home/william/.local/bin/alacritty
...

[Desktop Action New]
Name=New Terminal
Exec=env XMODIFIERS=@im=none /home/william/.local/bin/alacritty

Important: Keep TryExec= set to the plain binary path (/home/william/.local/bin/alacritty), not env .... TryExec checks whether a single executable exists; putting env XMODIFIERS=... there marks the .desktop entry invalid.

Validate the file and update the desktop database:

1
2
desktop-file-validate ~/.local/share/applications/Alacritty.desktop
update-desktop-database ~/.local/share/applications

Any new Alacritty window launched from the menu (and any window spawned from it via Ctrl+Shift+Return) will inherit XMODIFIERS=@im=none and bypass fcitx XIM. Existing Alacritty processes keep their old environment until reopened.

(If you do need IME inside Alacritty, keep fcitx -r -d handy as an in-place recovery command, or consider migrating from fcitx4 to fcitx5.)

Problem 2 (Gotcha): Alacritty disappears from the Linux Mint menu after editing .desktop

If Alacritty.desktop is ever saved in an invalid state even briefly (for example, if TryExec= is accidentally changed while editing Exec=), Cinnamon’s CMenu library can cache a null app_info entry for that file. Even after you fix the file and run touch + update-desktop-database, searching ala in the Mint system menu will stop matching Alacritty.

Fix: Evict Cinnamon’s CMenu cache and reload the menu applet

  1. Remove and recreate the .desktop file so Cinnamon’s file monitor sees a delete + create event:
1
2
3
4
5
mv ~/.local/share/applications/Alacritty.desktop /tmp/Alacritty.desktop.tmp
sleep 1
cp /tmp/Alacritty.desktop.tmp ~/.local/share/applications/Alacritty.desktop
rm -f /tmp/Alacritty.desktop.tmp
update-desktop-database ~/.local/share/applications
  1. Reload the Cinnamon menu applet so its search index picks up the refreshed entry:
1
2
dbus-send --session --dest=org.Cinnamon --type=method_call --print-reply \
  /org/Cinnamon org.Cinnamon.ReloadXlet string:'menu@cinnamon.org' string:'APPLET'
  1. Optionally verify directly inside the running Cinnamon session that AppSystem and menu@cinnamon.org both have Alacritty:
1
2
3
dbus-send --session --dest=org.Cinnamon --type=method_call --print-reply \
  /org/Cinnamon org.Cinnamon.Eval \
  string:'(function(){ let s = imports.gi.Cinnamon.AppSystem.get_default(); let a = s.lookup_app("Alacritty.desktop"); return a ? a.get_app_info().get_commandline() : "NOT_FOUND"; })()'

Expected output:

1
"env XMODIFIERS=@im=none /home/william/.local/bin/alacritty"

相关内容

william 支付宝支付宝
william 微信微信
0%