kovidgoyal / kitty

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

Incorrect key handling on sway #4706

Closed p00f closed 2 years ago

p00f commented 2 years ago

Describe the bug kitty +kitten show_key -m kitty shows the wrong keys - any keypress is prefixed with a NumLock even though I don't I have a NumLock key on my keyboard.

Pressing and releasing h shows:

NumLock+h PRESS h
CSI 104 ; 129 ; 104 u

NumLock+h RELEASE 
CSI 104 ; 129 : 3 u

Pressing and releasing ctrl shows:

NumLock+LEFT_CONTROL PRESS 
CSI 57442 ; 129 u

Ctrl+NumLock+LEFT_CONTROL RELEASE 
CSI 57442 ; 133 : 3 u

Pressing and releasing shift shows:

NumLock+LEFT_SHIFT PRESS 
CSI 57441 ; 129 u

Shift+NumLock+LEFT_SHIFT RELEASE 
CSI 57441 ; 130 : 3 u

Pressing and releasing ctrl-tab shows:

NumLock+LEFT_CONTROL PRESS 
CSI 57442 ; 129 u

Ctrl+NumLock+LEFT_CONTROL RELEASE 
CSI 57442 ; 133 : 3 u

This causes <C-Tab> to not work in neovim. Specifically,

:nmap <Tab> <cmd>echo 'tab'<CR> | nmap <C-Tab> <cmd>echo 'c-tab'<CR> | nmap <C-S-Tab> <cmd>echo 'c-s-tab'<CR>

gives the desired behaviour in foot (which implements kitty's keyboard protocol) i.e. all 3 key combinations echo distinct messages, but in kitty only <Tab> works

Environment details

sway 1.7 on wlroots 0.15.1

kitty 0.24.2 created by Kovid Goyal
Linux zeus 5.16.8-arch1-1 #1 SMP PREEMPT Tue, 08 Feb 2022 21:21:08 +0000 x86_64
Arch Linux 5.16.8-arch1-1 (/dev/tty)

Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /bin/bash
Loaded config files:
  /home/p00f/.config/kitty/kitty.conf

Config options different from defaults:
adjust_line_height   1.05
allow_remote_control y
font_family          JetBrains Mono
font_size            12.6
linux_display_server wayland
listen_on            unix:/tmp/mykitty
shell_integration    frozenset({'disabled'})
symbol_map:
    U+ea60 - U+ebd0 → codicon
    U+f101 - U+f208 → nonicon
Added shortcuts:
    ctrl+- → change_font_size all -1.0
    ctrl+= → change_font_size all +1.0
Colors:
    background           #0e1415   
    color1               #d2322d   
    color10              #95cb82   
    color11              #dfdf8e   
    color12              #71aed7   
    color13              #cc8bc9   
    color14              #47bea9   
    color2               #6abf40   
    color3               #cd974b   
    color4               #217ebc   
    color5               #9b3596   
    color6               #178f79   
    color7               #cecece   
    color8               #333333   
    color9               #c33c33   
    cursor               #cd974b   
    foreground           #cecece   
    selection_background #293334   
    selection_foreground #cecece   

Environment variable names seen by the kitty process:
    CARGO_HOME
    CLOJURE_HOME
    CLUTTER_BACKEND
    DBUS_SESSION_BUS_ADDRESS
    DEBUGINFOD_URLS
    DIFFPROG
    ELINKS_CONFDIR
    GREETD_SOCK
    HG
    HOME
    I3SOCK
    INPUTRC
    KITTY_ENABLE_WAYLAND
    KITTY_LISTEN_ON
    LANG
    LIBVA_DRIVER_NAME
    LOGNAME
    MAIL
    MOTD_SHOWN
    MOZ_DBUS_REMOTE
    MOZ_ENABLE_WAYLAND
    NMBGIT
    NOTMUCH_CONFIG
    NPM_CONFIG_STORE_DIR
    OCTAVE_HISTFILE
    PASSWORD_STORE_DIR
    PATH
    PWD
    QT_QPA_PLATFORM
    QT_QPA_PLATFORMTHEME
    RUSTUP_HOME
    SDL_VIDEODRIVER
    SHELL
    SHLVL
    SSH_AUTH_SOCK
    SWAYSOCK
    SYSTEMD_HOME
    SYSTEMD_HOME_SUSPEND
    TERM
    USER
    VDPAU_DRIVER
    VOLTA_HOME
    WAYLAND_DISPLAY
    WINEPREFIX
    XCURSOR_SIZE
    XCURSOR_THEME
    XDG_CACHE_HOME
    XDG_CONFIG_HOME
    XDG_CURRENT_DESKTOP
    XDG_DATA_HOME
    XDG_RUNTIME_DIR
    XDG_SEAT
    XDG_SESSION_CLASS
    XDG_SESSION_DESKTOP
    XDG_SESSION_ID
    XDG_SESSION_TYPE
    XDG_STATE_HOME
    XDG_VTNR
    _
    _JAVA_AWT_WM_NONREPARENTING
    npm_config_cache
    npm_config_prefix
    npm_config_tmp
    npm_config_userconfig

Additional context This can be reproduced with kitty --config NONE

p00f commented 2 years ago

This happens even after installing xwayland and setting linux_display_server x11

kovidgoyal commented 2 years ago

Run kitty --debug-input presumably the algorithm for modifier detection on wayland is failing on your machine. It's @orki code so hopefully he can help.

p00f commented 2 years ago

kitty --debug-input:

small letter L, backspace, tab, esc, ctrl-tab,ctrl-shift-tab,shift-tab: https://paste.rs/6Fa

presumably the algorithm for modifier detection on wayland is failing on your machine

it happens after installing xwayland and setting linux_display_server x11 too btw

kovidgoyal commented 2 years ago

Looks OK to me. According to that your numlock key is actually pressed. If it's just ctrl+tab you care about simply override it in kitty.conf using send_text, see the kitty FAQ.

p00f commented 2 years ago

I don't even have a numlock key. Also, show_key sees ctrl and ctrl-tab as the same

kovidgoyal commented 2 years ago

libxkbcommon thinks you do. And I cannot replicate your issue with ctrl+tab. Indeed given that ctrl+tab is a shortcut mapped to next_tab by default, I dont even understand how you are getting it in showkey without map ctrl+tab no-op which your debug output says you dont have. Not to mention your --debug-input output is missing any on_key_input lines indicating it isnt even from kitty version 0.24.2 which is the version your debug output says you are running. So Ihave no clue what is going on in your system, but youhave bigger issues than ctrl+tab not working. Multiple kitty installs would be my guess.

p00f commented 2 years ago

Oh sorry I redirected stdout to a file, I didn't know that would be incomplete. Here's the full output copy-pasted from the terminal:

The default keybinding works - ctrl-tab changes the tab when a tab is open when it is not mapped to no-op. But it doesn't send ctrl-tab to neovim when it is mapped to no-op either

I don't have multiple kitty installs either, just the one from https://archlinux.org/packages/community/x86_64/kitty/

youhave bigger issues than ctrl+tab not working

oof

kovidgoyal commented 2 years ago

You will need to solve the numlock issue for that. Or like I said before, just map ctrl+tab using send_text in kitty.conf.

kovidgoyal commented 2 years ago

Oh and another thing you can try is setting the env var KITTY_WAYLAND_DETECT_MODIFIERS=1

p00f commented 2 years ago

Yes but using send_text requires me to find out what bytes to send to look like ctrl-tab. The documentation says to look at the output of show_key which doesn't show ctrl-tab

KITTY_WAYLAND_DETECT_MODIFIERS=1 doesn't fix it

nvm, thanks for looking into this 👍🏽 . This is not super important to me

kovidgoyal commented 2 years ago

The bytes are

\x1b[9;5u

p00f commented 2 years ago

Thanks