wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Wezterm seems to forget the current keymap randomly on Gnome Wayland

Open adwaymalhotra opened this issue 2 years ago • 3 comments

Sometimes, when I have Colemak layout enabled on Gnome, Wezterm will read keys corresponding to the QWERTY layout instead.

I have to toggle the layout to English(US) and back for it work correctly in Wezterm again.

This only happens when I switch to a different app and come back to Wezterm, never while continuously using Wezterm.

Running in wayland mode btw.

> wezterm --version
wezterm 20220807-113146-c2fee766

> gnome-shell --version
GNOME Shell 42.2

adwaymalhotra avatar Aug 10 '22 15:08 adwaymalhotra

Can you list out the precise steps required to reproduce this? I understand that it is intermittent, but I want to make sure that I understand what tends to trigger it so that it is easier to verify that it has been resolved.

wez avatar Aug 10 '22 22:08 wez

Okay, I think I have a pretty fool proof way of reproducing this.

  1. Add two input sources other than the default one in Settings > Keyboard. I have English (UK) and English (Colemak-DH) added to the default: English (US). English US is the default.
  2. Run Wezterm, switch to Colemak using win+space. Notice that Wezterm thinks the keyboard layout is Colemak.
  3. Open Chrome, keyboard layout is still Colemak.
  4. Switch to Wezterm using Alt+Tab. Notice that Wezterm thinks that the keyboard layout is QWERTY.
  5. Switch to US layout and back to Colemak, now Wezterm thinks the layout is Colemak.

This is happening each time I switch between Chrome and Wezterm.

adwaymalhotra avatar Aug 11 '22 09:08 adwaymalhotra

Oh! I just figured out that this only happens when I have the "Always on Visible Workspace" option enabled by right clicking on the title bar!

It's only reproduceable with this option enabled + switching apps. If I also enable "Always on Top", I am unable to reproduce the issue, presumably because Wezterm doesn't lose focus.

adwaymalhotra avatar Aug 11 '22 09:08 adwaymalhotra

Glad I am not the only one who use Wezterm and Colemak. However, I use Leftwm and don't have(use) title bar that does "Always on Top" :(

seungjin avatar Jun 26 '23 05:06 seungjin

BTW, I use wezterm + colemak on X11 (with LeftWM).

I use self-build(my own compiled) wezterm and it works fine with my colemak keylayout but when I do Ctrl+key.. It does not use colemak keymap but querty.

seungjin avatar Jun 26 '23 05:06 seungjin

Reproduces reliably for me after waking from systemctl suspend. A reliable way to reset the keymap for me is to press the SHIFT key. Hope that gives some hints.

$ wezterm --version
wezterm 20230712-072601-f4abf8fd
$ rpm -q gnome-shell
gnome-shell-45.0-1.fc39.x86_64
$ rpm -q wayland-devel
wayland-devel-1.22.0-2.fc39.x86_64

Also happens with config.use_ime = false.

`wezterm --config debug_key_events=true` output

yzäyzÄyz Notice raw_code 52 switching from z to y after pressing SHIFT``ä.

08:14:08.355  INFO   wezterm_gui::termwindow::keyevent > key_event RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:08.355  INFO   wezterm_gui::termwindow::keyevent > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:08.355  INFO   wezterm_gui::termwindow::keyevent > send to pane DOWN key=Char('z') mods=NONE
08:14:08.355  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "z", Char('z') NONE
08:14:08.431  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:08.431  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('z') mods=NONE
08:14:11.440  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:11.440  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:11.440  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('y') mods=NONE
08:14:11.440  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "y", Char('y') NONE
08:14:11.515  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:11.515  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('y') mods=NONE
08:14:13.080  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('ä'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: None }
08:14:13.080  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('ä') mods=NONE
08:14:13.080  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "ä", Char('ä') NONE
08:14:13.141  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(Quote), modifiers: NONE, leds: (empty), phys_code: Some(Quote), raw_code: 48, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:13.141  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('\'') mods=NONE
08:14:17.743  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:17.744  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:17.744  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('z') mods=NONE
08:14:17.745  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "z", Char('z') NONE
08:14:17.817  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: (empty), phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:17.817  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('z') mods=NONE
08:14:19.426  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:19.426  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:19.426  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('y') mods=NONE
08:14:19.426  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "y", Char('y') NONE
08:14:19.491  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: (empty), phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:19.491  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('y') mods=NONE
08:14:21.143  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(LeftShift), modifiers: NONE, leds: (empty), phys_code: Some(LeftShift), raw_code: 50, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:21.143  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: LeftShift, modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(LeftShift), modifiers: NONE, leds: (empty), phys_code: Some(LeftShift), raw_code: 50, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:21.143  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=LeftShift mods=NONE
08:14:21.386  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('Ä'), modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: None }
08:14:21.386  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('Ä') mods=NONE
08:14:21.386  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "Ä", Char('Ä') NONE
08:14:21.447  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('Ä'), modifiers: SHIFT, leds: NUM_LOCK, repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Quote), modifiers: SHIFT, leds: NUM_LOCK, phys_code: Some(Quote), raw_code: 48, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:21.448  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('Ä') mods=SHIFT
08:14:21.527  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: LeftShift, modifiers: SHIFT, leds: NUM_LOCK, repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(LeftShift), modifiers: SHIFT, leds: NUM_LOCK, phys_code: Some(LeftShift), raw_code: 50, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:21.528  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=LeftShift mods=SHIFT
08:14:22.902  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:22.902  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: NUM_LOCK, repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:22.902  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('y') mods=NONE
08:14:22.902  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "y", Char('y') NONE
08:14:23.000  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('y'), modifiers: NONE, leds: NUM_LOCK, repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Z), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Z), raw_code: 52, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:23.000  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('y') mods=NONE
08:14:24.259  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }
08:14:24.259  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: NUM_LOCK, repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
08:14:24.260  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('z') mods=NONE
08:14:24.260  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "z", Char('z') NONE
08:14:24.329  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('z'), modifiers: NONE, leds: NUM_LOCK, repeat_count: 1, key_is_down: false, raw: Some(RawKeyEvent { key: Physical(Y), modifiers: NONE, leds: NUM_LOCK, phys_code: Some(Y), raw_code: 29, repeat_count: 1, key_is_down: false, handled: Handled(false) }) }
08:14:24.330  INFO   wezterm_gui::termwindow::keyevent     > send to pane UP key=Char('z') mods=NONE

MartinNowak avatar Sep 27 '23 09:09 MartinNowak

Another way to reliably reproduce this for me is to open diffuse from my shell and use the mouse or keyboard with the app, afterwards my keymap is en till again pressing the SHIFT key.

MartinNowak avatar Sep 30 '23 11:09 MartinNowak

I noticed during debugging that the xcb selected state is partly incorrect (signified by empty leds/missing NUM_LOCK) and that pressing SHIFT seems to "repair" that state.

  1. cargo run --bin wezterm-gui starts with an incorrect state https://github.com/wez/wezterm/blob/11dec45f08e3c7a611f59b030d4a9bd391807604/window/src/os/x11/keyboard.rs#L150
  2. Pressing SHIFT (or NUM_LOCK) "repairs" the incorrect state (and apparently the keymap)
  3. Opening diffuse as child process and closing it with keyboard from within the app (CTRL+w) breaks the state
  4. Pressing SHIFT again "repairs" the state

While I don't think it will help with the confused NUM_LOCK state, wezterm/libxcbcommon seem to inadvertently pickup the first keyboard layout of gnome settings/ibus. image So reordering them might be a way to partially workaround this issue for now.

MartinNowak avatar Oct 06 '23 05:10 MartinNowak

I've noticed a new extremely annoying behavior with neovim. The layout changes each time I exit insert mode, and then do a dd to delete a line. After this the layout changes to default.

I'm using PaperWM now, and not doing anything with the "always on visible workspace". The current behavior makes wezterm basically unusable with the custom layout.

wezterm --config debug_key_events=true output attached starting at the escape key (which I have mapped to caps lock using gnome settings).

wezterm-dump.txt

adwaymalhotra avatar Dec 14 '23 01:12 adwaymalhotra