wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
15.05k stars 682 forks source link

karabiner rules not playing well (caps lock == escape key alone/control if chord) #4394

Open esn89 opened 9 months ago

esn89 commented 9 months ago

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

macOS

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

MacOS

WezTerm version

wezterm 20230712-072601-f4abf8fd

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

I have this in my Karabiner Elements to turn my capslock into Escape by itself, or Ctrl with pressed with another key:

          {
            "description": "Change caps_lock to control if pressed with other keys, to escape if pressed alone.",
            "manipulators": [
              {
                "from": {
                  "key_code": "caps_lock",
                  "modifiers": {
                    "optional": [
                      "any"
                    ]
                  }
                },
                "to": [
                  {
                    "key_code": "left_control"
                  }
                ],
                "to_if_alone": [
                  {
                    "key_code": "escape"
                  }
                ],
                "type": "basic"
              }
            ]
          },

In Wezterm, I have:

-- this allows me to have "capslock + c" to terminate running processes
    {
        key = 'c',
        mods = 'SUPER',
        action = wezterm.action.SendKey({ key = 'c', mods = 'CTRL' }),
    },
    {
        key = 'c',
        mods = 'CMD',
        action = wezterm.action.CopyTo('Clipboard'),
    },

This doesn't seem to work for me, as I can no longer "ctrl+c" to quit running processes.

I understand that in the docs it says:

SUPER, CMD, WIN - these are all equivalent: on macOS the Command key, on Windows the Windows key, on Linux this can also be the Super or Hyper key. Left and right are equivalent.

But how come, when I do "capslock + c", it shows:

20:18:08.509  INFO   wezterm_gui::termwindow::keyevent > key_event RawKeyEvent { key: Char('c'), modifiers: SUPER, leds: (empty), phys_code: Some(C), raw_code: 8, repeat_count: 1, key_is_down: true, handled: Handled(false) }
20:18:08.510  INFO   wezterm_gui::termwindow::keyevent > Char('c') SUPER -> perform SendKey(KeyNoAction { key: Either { physical: Physical(C), mapped: Char('c'), original: "c" }, mods: CTRL })
20:18:08.510  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "\u{3}", Char('c') CTRL
20:18:09.413  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Char('c'), modifiers: SUPER, leds: (empty), phys_code: Some(C), raw_code: 8, repeat_count: 1, key_is_down: true, handled: Handled(false) }
20:18:09.414  INFO   wezterm_gui::termwindow::keyevent     > Char('c') SUPER -> perform SendKey(KeyNoAction { key: Either { physical: Physical(C), mapped: Char('c'), original: "c" }, mods: CTRL })
20:18:09.414  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "\u{3}", Char('c') CTRL

It shows that my modifier is "SUPER", instead of "ctrl"? I thought Karabiner made it so that CapsLock == Ctrl and not SUPER.

Essentially, what I want to achieve is:

CapsLock + C is equivalent to "ctrl+c". MacCommand + C is copy to clipboard.

To Reproduce

No response

Configuration

    {
        key = 'c',
        mods = 'SUPER',
        action = wezterm.action.SendKey({ key = 'c', mods = 'CTRL' }),
    },
    {
        key = 'c',
        mods = 'ALT',
        action = wezterm.action.CopyTo('Clipboard'),
    },

And in Karabiner elements:

          {
            "description": "Change caps_lock to control if pressed with other keys, to escape if pressed alone.",
            "manipulators": [
              {
                "from": {
                  "key_code": "caps_lock",
                  "modifiers": {
                    "optional": [
                      "any"
                    ]
                  }
                },
                "to": [
                  {
                    "key_code": "left_control"
                  }
                ],
                "to_if_alone": [
                  {
                    "key_code": "escape"
                  }
                ],
                "type": "basic"
              }
            ]
          },

Expected Behavior

CapsLock + C is equivalent to "ctrl+c". MacCommand + C is copy to clipboard.

Logs

No response

Anything else?

No response

wez commented 9 months ago

I think you may have something else happening in your configuration; I run karabiner with capslock rebound as you describe. I'm not sure what the actual config looks like in karabiner, but the description matches. When I hold capslock and press C it sends ctrl-c. There's no wezterm configuration required for that, because karabiner takes care of it.

For the wezterm configuration, note that CMD and SUPER are the same thing; what you posted in the initial part of this report shows rebinding CMD+c and SUPER+c as two different things. The behavior of wezterm in that case may not be what you expect. I can see that later you use ALT-c for one of the keybindings.

From what you described, this sounds like a karabiner or other keyboard remapping issue, as the logs show that wezterm is receiving SUPER-c from something on your system.

esn89 commented 9 months ago

Alright, give me a week to play around with a bit more. Do you mind if you show me you ~/.config/karabiner/karabiner.json?

esn89 commented 8 months ago

Alright, give me a week to play around with a bit more. Do you mind if you show me you ~/.config/karabiner/karabiner.json?

Bump for visibility, @wez :)

bitboxer commented 1 month ago

I sadly see the same problem for me.

bitboxer commented 1 month ago

Forgot to post a link to my karabiner config: karabiner.json . It is a bit more complex because I map a lot of keys 😅.