kovidgoyal / kitty

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

Ctrl+- does not work #6211

Closed wolfsage closed 1 year ago

wolfsage commented 1 year ago

Describe the bug

Hi, I'm using a Microsoft Sculpt Ergonomic keyboard (https://www.microsoft.com/en/accessories/products/keyboards/sculpt-ergonomic-desktop?activetab=pivot:overviewtab)

The key combination ctrl - does not work, it outputs -. It seems like --debug-keyboard confirms this even though it shows a ctrl modifier?

To Reproduce

~/kitty$ ./kitty/launcher/kitty --version
kitty 0.28.1 created by Kovid Goyal
~/kitty$ ./kitty/launcher/kitty --debug-keyboard
Loading new XKB keymaps
Modifier indices alt: 0x3 super: 0x6 hyper: 0xffffffff meta: 0xffffffff numlock: 0x4 shift: 0x0 capslock: 0x1
Move x: 38.0 y: 541.0 grabbed: 0
on_focus_change: window id: 0x1 focused: 1
ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust
Press xkb_keycode: 0x25 clean_sym: Control_L composed_sym: Control_L mods: none glfw_key: 57442 (LEFT_CONTROL) xkb_key: 65507 (Control_L)
on_key_input: glfw key: 0xe062 native_code: 0xffe3 action: PRESS mods: none text: '' state: 0 ignoring as keyboard mode does not support encoding this event
Press xkb_keycode: 0x14 clean_sym: minus composed_sym: minus mods: ctrl glfw_key: 45 (-) xkb_key: 45 (minus)
on_key_input: glfw key: 0x2d native_code: 0x2d action: PRESS mods: ctrl text: '' state: 0 sent encoded key to child: - 
Release xkb_keycode: 0x14 clean_sym: minus mods: ctrl glfw_key: 45 (-) xkb_key: 45 (minus)
on_key_input: glfw key: 0x2d native_code: 0x2d action: RELEASE mods: ctrl text: '' state: 0 ignoring as keyboard mode does not support encoding this event
Release xkb_keycode: 0x25 clean_sym: Control_L mods: ctrl glfw_key: 57442 (LEFT_CONTROL) xkb_key: 65507 (Control_L)
on_key_input: glfw key: 0xe062 native_code: 0xffe3 action: RELEASE mods: ctrl text: '' state: 0 ignoring as keyboard mode does not support encoding this event

Environment details

kitty 0.28.1 (07bcc5ba61) created by Kovid Goyal
Linux emondsfield 5.15.0-67-generic #74~20.04.1-Ubuntu SMP Wed Feb 22 14:52:34 UTC 2023 x86_64
Ubuntu 20.04.4 LTS emondsfield /dev/tty

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
Running under: X11
Frozen: False
Paths:
  kitty: /home/alh/kitty/kitty/launcher/kitty
  base dir: /home/alh/kitty
  extensions dir: /home/alh/kitty/kitty
  system shell: /bin/bash
Loaded config files:
  /etc/xdg/kitty/kitty.conf
  /home/alh/.config/kitty/kitty.conf

Config options different from defaults:
background_image        /home/alh/zelda-background.png
background_image_layout scaled
background_tint         0.99
update_check_interval   0.0

Important environment variables seen by the kitty process:
        PATH                                /home/alh/kitty/kitty/launcher:/home/alh/go/bin/:/usr/go/bin/:/home/alh/.plenv/shims:/home/alh/.plenv/bin:/hom>
        LANG                                en_US.UTF-8
        SHELL                               /bin/bash
        DISPLAY                             :0.0
        USER                                alh
        XDG_CONFIG_DIRS                     /etc/xdg/xdg-fluxbox:/etc/xdg
        XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session0
        XDG_SEAT                            seat0
        XDG_SESSION_DESKTOP                 fluxbox
        XDG_SESSION_TYPE                    x11
        XDG_GREETER_DATA_DIR                /var/lib/lightdm-data/alh
        XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
        XDG_SESSION_CLASS                   user
        XDG_VTNR                            7
        XDG_SESSION_ID                      c2
        XDG_RUNTIME_DIR                     /run/user/1000
        XDG_DATA_DIRS                       /usr/share/fluxbox:/usr/local/share:/usr/share:/var/lib/snapd/desktop

Additional context

empty config triggers this as well

Thanks

kovidgoyal commented 1 year ago

Legacy terminal keyboard encoding cannot represent ctrl+- you need to use a program that supports kitty's enhanced keyboard protocol.

kitty +kitten show_key -m kitty

for example

wolfsage commented 1 year ago
LEFT_CONTROL PRESS 
CSI 57442 u

Ctrl+- PRESS 
CSI 45 ; 5 u

Ctrl+- RELEASE 
CSI 45 ; 5 : 3 u

Ctrl+LEFT_CONTROL RELEASE 
CSI 57442 ; 5 : 3 u

is what I get with that.

alternateved commented 1 year ago

@wolfsage This snippet in kitty.conf works for me:

map ctrl+' send_text all \x1b[39;5u
map ctrl+( send_text all \x1b[40;5u
map ctrl+) send_text all \x1b[41;5u
map ctrl+, send_text all \x1b[44;5u
map ctrl+- send_text all \x1b[45;5u
map ctrl+. send_text all \x1b[46;5u
map ctrl+; send_text all \x1b[59;5u
map ctrl+= send_text all \x1b[61;5u

There is an entry in regards to this on kitty webpage: Comprehensive keyboard handling in terminals This might explain those escape codes a bit: ANSI Escape Sequences

wolfsage commented 1 year ago

That doesn't work for me but did give me a hint. I decided to see how other terminal emulators solve this, and rxvt-unicode does:

      else if (ctrl && keysym == XK_minus)
        {
          len = 1;
          kbuf[0] = '\037';     /* Ctrl-Minus generates ^_ (31) */
        }

\037 = \x1f So I did:

map ctrl+minus send_text all \x1f

And now it works. Cheers

wolfsage commented 1 year ago

It seems like emitting 1f for ctrl+- is fairly common, but kitty only does that for ctrl+shift+-, but I don't understand all of this stuff, just what my setup is doing

alternateved commented 1 year ago

What do you have set for TERM? I have xterm-kitty or xterm-direct, both works with bindings from snippet above.