Skip to content
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

Unable to type a caret ('^') with kitty keyboard enabled #4916

Open
Canop opened this issue Jan 31, 2024 · 5 comments
Open

Unable to type a caret ('^') with kitty keyboard enabled #4916

Canop opened this issue Jan 31, 2024 · 5 comments
Labels
bug Something isn't working keyboard Keyboard mapping/handling

Comments

@Canop
Copy link

Canop commented Jan 31, 2024

What Operating System(s) are you seeing this problem on?

Linux X11

Which Wayland compositor or X11 Window manager(s) are you using?

wayland-0

WezTerm version

20240128-202157-1e552d76

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

With the kitty keyboard protocol, I'm unable to type a caret, while it works on Kitty.

To Reproduce

With crossterm 0.27:

use crossterm::{event::*, *};

pub fn main() {
    let mut stdout = std::io::stdout();
    execute!(
        stdout,
        PushKeyboardEnhancementFlags(
            KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
                | KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES
                | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
                | KeyboardEnhancementFlags::REPORT_EVENT_TYPES
        )
    )
    .unwrap();
    println!("Type keys (esc to quit)");
    loop {
        terminal::enable_raw_mode().unwrap();
        let e = read();
        terminal::disable_raw_mode().unwrap();
        match e {
            Ok(Event::Key(key_event)) => {
                if key_event.code == KeyCode::Esc {
                    break;
                }
                dbg!(key_event);
            }
            e => {
                // any other event, for example a resize, we quit
                eprintln!("Quitting on {:?}", e);
                break;
            }
        }
    }
    let mut stdout = std::io::stdout();
    execute!(stdout, PopKeyboardEnhancementFlags).unwrap();
}

If I run the program, type the caret (which involves pressing the '^' key then eg a space, I get this:

Type keys (esc to quit)
[src/main.rs:25] key_event = KeyEvent {
    code: Char(
        '6',
    ),
    modifiers: KeyModifiers(
        0x0,
    ),
    kind: Press,
    state: KeyEventState(
        0x0,
    ),
}
[src/main.rs:25] key_event = KeyEvent {
    code: Char(
        ' ',
    ),
    modifiers: KeyModifiers(
        0x0,
    ),
    kind: Release,
    state: KeyEventState(
        CAPS_LOCK,
    ),
}

Doing the same on Kitty:

Type keys (esc to quit)
[src/main.rs:25] key_event = KeyEvent {
    code: Char(
        '^',
    ),
    modifiers: KeyModifiers(
        0x0,
    ),
    kind: Press,
    state: KeyEventState(
        0x0,
    ),
}

Configuration

config.enable_kitty_keyboard = true

Expected Behavior

I expect to get the same sequence with wezterm and kitty. Or at least one which makes it possible to recognize the caret key.

Logs

nothing during action

Anything else?

Keyboard layout is Azerty.

@Canop Canop added the bug Something isn't working label Jan 31, 2024
@Canop
Copy link
Author

Canop commented Jan 31, 2024

This might be a duplicate of #4785 but is more specific

@wez wez added the keyboard Keyboard mapping/handling label Jan 31, 2024
@wez
Copy link
Owner

wez commented Jan 31, 2024

Please run through https://wezfurlong.org/wezterm/troubleshooting.html#debugging-keyboard-related-issues and include the debug output here

@wez wez added the waiting-on-op Waiting for more information from the original poster label Jan 31, 2024
@Canop
Copy link
Author

Canop commented Jan 31, 2024

15:21:36.814  INFO   wezterm_gui::termwindow               > DeadKeyStatus now: Composing("^")
15:21:37.293  INFO   wezterm_gui::termwindow               > DeadKeyStatus now: None
15:21:37.294  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('^'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: None } 
15:21:37.294  INFO   wezterm_gui::termwindow::keyevent     > kitty: Encoded input as "\u{1b}[54:94;1u"
15:21:37.294  INFO   wezterm_gui::termwindow               > DeadKeyStatus now: None
15:21:37.300  INFO   wezterm_gui::termwindow               > DeadKeyStatus now: None
15:21:37.366  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char(' '), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Space), modifiers: NONE, leds: (empty), phys_code: Some(Space), raw_code: 65, repeat_count: 1, key_is_down: false, handled: Handled(false) }) } 
15:21:37.366  INFO   wezterm_gui::termwindow::keyevent     > kitty: Encoded input as "\u{1b}[32;1:3u"
15:21:38.669  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(CapsLock), modifiers: NONE, leds: (empty), phys_code: Some(CapsLock), raw_code: 66, repeat_count: 1, key_is_down: true, handled: Handled(false) } 
15:21:38.669  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('\u{1b}'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(CapsLock), modifiers: NONE, leds: (empty), phys_code: Some(CapsLock), raw_code: 66, repeat_count: 1, key_is_down: true, handled: Handled(false) }) } 
15:21:38.669  INFO   wezterm_gui::termwindow::keyevent     > kitty: Encoded input as "\u{1b}[27;1u"
15:21:38.692  INFO   wezterm_gui::termwindow               > DeadKeyStatus now: None
15:21:38.765  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('\u{1b}'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(CapsLock), modifiers: NONE, leds: (empty), phys_code: Some(CapsLock), raw_code: 66, repeat_count: 1, key_is_down: false, handled: Handled(false) }) } 
15:21:38.765  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Escape mods=NONE

@github-actions github-actions bot removed the waiting-on-op Waiting for more information from the original poster label Jan 31, 2024
@cstrahan
Copy link

As I mentioned over in a similar issue here:

The kitten executable bundled with kitty might be helpful for debugging. When I run kitten show_key -m kitty in kitty and hold shift, tap 6 (shift+6 is ^ on my US keyboard layout), and release shift, I see:

shift+LEFT_SHIFT PRESS 
CSI 57441 ; 2 u

shift+6 PRESS ^
CSI 54 : 94 ; 2 ; 94 u
Shifted key: ^ 

shift+6 RELEASE 
CSI 54 : 94 ; 2 : 3 u
Shifted key: ^ 

LEFT_SHIFT RELEASE 
CSI 57441 ; 1 : 3 u

@cstrahan
Copy link

The "\u{1b}[54:94;1u" should read "\u{1b}[54:94;2u" (1={}, 2={SHIFT}).

The problem can be traced to here:

15:21:37.294  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('^'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: None } 

This is very similar to the issue I'm seeing in macOS with config.use_ime = true:

The kitty input encoder needs to get the raw modifiers from the raw key code, but in your case raw: None. Consequently, the the the empty set of modifiers is output by the kitty input encoder (i.e. you get 1 instead of the expected 2).

If we can figure out why raw: None under X11 (and any relevant wezterm config), then we can fix the kitty encoding problem there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working keyboard Keyboard mapping/handling
Projects
None yet
Development

No branches or pull requests

3 participants