kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.36k stars 979 forks source link

Shifted keypresses getting dropped in Wayland / Fcitx #7258

Closed JeffDess closed 7 months ago

JeffDess commented 7 months ago

Describe the bug Using Kitty in Hyprland, Fcitx as IME and programmable keyboard results in one of the following:

This has been a problem for quite some time, I've checked with ZMK and Fcitx some time ago. A lot of context could be found in this Fcitx issue.

The same happens in X11 but the GLFW_IM_MODULE=ibus env solves it. Running Kitty under XWayland in Hyprland is not an option as the window is not handled/tiled correctly, but the bug doesn't occur if I do so. I believe I could not reproduce the issue in KDE Plasma Wayland using the Fcitx option/hack described below, but haven't being using Plasma for some time.

To Reproduce Steps to reproduce the behavior:

  1. Open an Hyprland session and connect a wireless programmable keyboard (ZMK)
  2. Launch fcitx5 if not started with the new session.
  3. Launch Kitty
  4. Type a key that sends &RPAR character a couple of times (https://zmk.dev/docs/codes)
  5. The output in the terminal will be a mix of right parenthesis and zeros (i.e. "0)00)0"). The first character will always be 0, only a quick double tap will render a parenthesis (with a leading 0).
  6. Close Kitty
  7. Launch Fcitx settings
  8. In "Wayland Input Interface Method", uncheck "Forward Key event instead of committing text if it is not handled". (this is actually a hack implemented by Fcitx to fix the original issue. It works everywhere except for Kitty.)
  9. Launch a new instance of Kitty
  10. Type the same key as in step 4 a couple of times and count the keystrokes.
  11. The terminal will display exactly one out of 2 characters that were being typed. No matter the time interval between the keypress, the "even" will register and the "odd" will get dropped.

Notes:

Screenshots If applicable, add screenshots to help explain your problem.

Not a screenshot but, if that helpful kitten show-key outputs one key out two keypresses with the fcitx option uncheck:

Press any keys - Ctrl+D will terminate this program
UNIX            send_text
)               )
)               )

and this with the option checked:

Press any keys - Ctrl+D will terminate this program
UNIX            send_text
0               0
0               0
)               )

Environment details

kitty 0.33.0 created by Kovid Goyal
Linux [host] 6.8.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 16 Mar 2024 17:15:35 +0000 x86_64
Arch Linux 6.8.1-arch1-1 (/dev/tty)

DISTRIB_ID=ArcoLinux
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="ArcoLinux"
Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /bin/zsh
Loaded config files:
  /home/[user]/.config/kitty/kitty.conf

Config options different from defaults:
bold_font               CaskaydiaCove Nerd Font,CaskaydiaCove NF:style=Bold
bold_italic_font        CaskaydiaCove Nerd Font Bold Italic
confirm_os_window_close 0
enable_audio_bell       False
font_family             CaskaydiaCove Nerd Font
font_size               13.0
italic_font             CaskaydiaCove Nerd Font Italic
startup_session         /home/[user]/.config/kitty/startup_session.conf
window_padding_width    FloatEdges(left=15.0, top=5.0, right=15.0, bottom=5.0)
Added shortcuts:
    ctrl+y →  debug_config
Colors:
    active_tab_background   #614a82   
    active_tab_foreground   #ddd8bb   
    background              #1f1f28   
    color0                  #1f1f28   
    color1                  #e46a78   
    color10                 #9ec967   
    color11                 #f1c982   
    color12                 #7bc2df   
    color13                 #a98fd2   
    color14                 #7bc2df   
    color15                 #a8a48d   
    color2                  #98bc6d   
    color3                  #e5c283   
    color4                  #7eb3c9   
    color5                  #957fb8   
    color6                  #7eb3c9   
    color7                  #ddd8bb   
    color8                  #3c3c51   
    color9                  #ec818c   
    cursor                  #e6e0c2   
    cursor_text_color       #1f1f28   
    foreground              #ddd8bb   
    inactive_tab_background #363644   
    inactive_tab_foreground #ddd8bb   
    selection_background    #49473e   
    selection_foreground    #ddd8bb   

Important environment variables seen by the kitty process:
    PATH                                [path]
    LANG                                fr_CA.UTF-8
    VISUAL                              nvim
    EDITOR                              nvim
    SHELL                               /bin/zsh
    GLFW_IM_MODULE                      ibus
    DISPLAY                             :1
    WAYLAND_DISPLAY                     wayland-1
    USER                                [user]
    XCURSOR_SIZE                        24
    LC_ADDRESS                          fr_CA.UTF-8
    LC_ALL                              fr_CA.UTF-8
    LC_IDENTIFICATION                   fr_CA.UTF-8
    LC_MEASUREMENT                      fr_CA.UTF-8
    LC_MONETARY                         fr_CA.UTF-8
    LC_NAME                             fr_CA.UTF-8
    LC_NUMERIC                          fr_CA.UTF-8
    LC_PAPER                            fr_CA.UTF-8
    LC_TELEPHONE                        fr_CA.UTF-8
    LC_TIME                             fr_CA.UTF-8
    XDG_BACKEND                         wayland
    XDG_CONFIG_HOME                     /home/[user]/.config
    XDG_CURRENT_DESKTOP                 Hyprland
    XDG_RUNTIME_DIR                     /run/user/1000
    XDG_SEAT                            seat0
    XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
    XDG_SESSION_CLASS                   user
    XDG_SESSION_DESKTOP                 hyprland
    XDG_SESSION_ID                      4
    XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session3
    XDG_SESSION_TYPE                    wayland
    XDG_VTNR                            1

Additional context Try to reproduce the problem with kitty --config NONE: Reproduced Reproduced on 3 Arch Linux installs: Arco, Endeavour and Vanilla Arch

My ZMK firmware source code: https://github.com/JeffDess/zmk-config

Env config of Hyprland:

env = XDG_CURRENT_DESKTOP,Hyprland
env = XDG_SESSION_TYPE,wayland
env = XDG_SESSION_DESKTOP,hyprland
env = CLUTTER_BACKEND,wayland
env = GDK_BACKEND,wayland
env = GTK_THEME,Breeze-Dark
env = SDL_VIDEODRIVER,wayland
env = SDL_IM_MODULE,fcitx5
env = QT_QPA_PLATFORM,wayland;xcb
env = QT_QPA_PLATFORMTHEME,qt5ct
env = QT_WAYLAND_DISABLE_WINDOWDECORATION,1
env = QT_AUTO_SCREEN_SCALE_FACTOR,1
env = XMODIFIERS,@im=fcitx
env = GTK_IM_MODULE,fcitx
env = QT_IM_MODULE,fcitx
env = GLFW_IM_MODULE,ibus # No effect in Wayland
env = XIM,fcitx
env = XIM_PROGRAM,fcitx
env = WLR_NO_HARDWARE_CURSORS,1
env = XCURSOR_SIZE,24
env = XCURSOR_THEME,Bibata-Modern-Ice
env = MOZ_ENABLE_WAYLAND,1
kovidgoyal commented 7 months ago

This will be a race between the IME and the compositor updating modifier states. This needs to be fixed in one of those as far as I can tell. If you feel differently, a PR is welcome with an accompanying justification. I might accept it if I judge it to fix more things than it breaks. Relevant code is in wl_text_input.c and xkb_glfw.c

Given this requires special hardware and a particular IME to reproduce, it's not possible for me to investigate it myself.

JeffDess commented 7 months ago

Ok thanks for pointing out the relevant files, I might give it a try. Other terminals having the original issue now behave correctly with the Fcitx fix, so that gives me hope it can be fixed in Kitty itself.