xremap / xremap

Key remapper for X11 and Wayland
MIT License
1.5k stars 83 forks source link

Cannot remap vscode terminal on Sway #490

Open paolomainardi opened 4 months ago

paolomainardi commented 4 months ago

I am facing a strange issue on the Vscode Terminal that behaves differently from Vscode itself, even though I cannot see it as a separate process or window when dumping the tree.

I am running this config:

# Key names: https://github.com/emberian/evdev/blob/master/src/scancodes.rs#L26-L572
# Aliases: https://github.com/k0kubun/xremap/blob/master/src/config/key.rs

keypress_delay_ms: 20

keymap:
  # Order is important, first match wins, so global always goes last.
  # https://github.com/k0kubun/xremap?tab=readme-ov-file#application-specific-key-overrides
  - name: Swith alt in all chrome based apps
    application:
      only: ["/google-chrome/", "/code/", "/Slack/"]
    remap:
      KEY_RIGHTALT-KEY_RIGHT: KEY_END
      KEY_RIGHTALT-KEY_LEFT: KEY_HOME
      # This is needed to make alt-gr + backtick work in chrome, i need this to make accents
      # using dead key.
      KEY_LEFTALT-KEY_GRAVE: KEY_RIGHTALT-KEY_GRAVE
  - name: Print
    remap:
      WIN-KEY_P: KEY_PRINT
  - name: Global
    exact_match: true
    remap:
      # Taking inspiration from here: https://github.com/rvaiya/keyd/blob/master/examples/macos.conf
      KEY_LEFTALT-KEY_RIGHT: KEY_END
      KEY_LEFTALT-KEY_LEFT: KEY_HOME
      WIN-KEY_C: KEY_LEFTCTRL-KEY_INSERT
      WIN-KEY_V: KEY_LEFTSHIFT-KEY_INSERT
      WIN-KEY_Z: KEY_LEFTCTRL-KEY_Z
      WIN-KEY_S: KEY_LEFTCTRL-KEY_S
      WIN-KEY_X: KEY_LEFTCTRL-KEY_X
      WIN-KEY_MINUS: KEY_LEFTCTRL-KEY_MINUS
      WIN-KEY_EQUAL: KEY_LEFTCTRL-KEY_EQUAL
    device:
      not: ["LogiOps Virtual Input", "Logitech USB Receiver"]

modmap:
  - name: Swith alt in all chrome based apps
    application:
      only: ["/google-chrome/", "/code/", "/Slack/"]
    remap:
      KEY_LEFTALT: KEY_RIGHTALT
      KEY_RIGHTALT: KEY_LEFTALT

What I want to achieve here is:

  1. Alt + left/right = home/end
  2. As on Linux, LeftAlt on Electron apps is used to open menus. I flip it with the right alt that I basically never use.
  3. Remap the RightAlt for Home/End as point 1.

It works basically everywhere (Chrome, Slack, Electron) but not in the Vscode Terminal, which seems to be handled as a separate process, and I cannot find it either on swaymsg -t get_tree, I see just code-url-handler.

I even tried to debug it, and everything seems to work correctly from the remap side.

Working from the Vscode editor debug:

[2024-06-04T22:28:54Z DEBUG xremap::event_handler] => 1: KEY_LEFTALT
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 1: KEY_RIGHTALT
[2024-06-04T22:28:54Z DEBUG xremap::event_handler] => 1: KEY_RIGHT
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHTALT
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 1: KEY_END
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 0: KEY_END
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 1: KEY_RIGHTALT
[2024-06-04T22:28:54Z DEBUG xremap::event_handler] => 0: KEY_RIGHT
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHT
[2024-06-04T22:28:54Z DEBUG xremap::event_handler] => 0: KEY_LEFTALT
[2024-06-04T22:28:54Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHTALT

Vscode terminal (not working):

[2024-06-04T22:30:00Z DEBUG xremap::event_handler] => 1: KEY_LEFTALT
[2024-06-04T22:30:00Z DEBUG xremap::action_dispatcher] 1: KEY_RIGHTALT
[2024-06-04T22:30:01Z DEBUG xremap::event_handler] => 2: KEY_LEFTALT
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 2: KEY_RIGHTALT
[2024-06-04T22:30:01Z DEBUG xremap::event_handler] => 1: KEY_RIGHT
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHTALT
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 1: KEY_END
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 0: KEY_END
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 1: KEY_RIGHTALT
[2024-06-04T22:30:01Z DEBUG xremap::event_handler] => 0: KEY_RIGHT
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHT
[2024-06-04T22:30:01Z DEBUG xremap::event_handler] => 0: KEY_LEFTALT
[2024-06-04T22:30:01Z DEBUG xremap::action_dispatcher] 0: KEY_RIGHTALT

Do you have any idea what is going on here ? I even tried to configure some custom keybindings on vscode:

// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "ctrl+-",
        "command": "workbench.action.zoomOut"
    },
    {
        "key": "ctrl+-",
        "command": "-workbench.action.zoomOut"
    },
    {
        "key": "ctrl+0",
        "command": "workbench.action.zoomReset"
    },
    {
        "key": "ctrl+numpad0",
        "command": "-workbench.action.zoomReset"
    },
    {
        "key": "ctrl+=",
        "command": "-workbench.action.zoomIn"
    },
    {
        "key": "ctrl+e",
        "command": "cursorLineEnd",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+a",
        "command": "cursorLineStart",
        "when": "terminalFocus"
    },
    {
        "key": "alt+right",
        "command": "cursorLineEnd",
        "when": "terminalFocus"
    },
    {
        "key": "alt+left",
        "command": "cursorLineStart",
        "when": "terminalFocus"
    },
]

But only ctrl+a/e works correctly; the alt+let/right does not work.

joetoth commented 3 months ago

I have the same issue but running as sudo works. All my keybindings everywhere else, as non-root, after setting up udevices.