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

Custom keyboard layouts does not works properly on ozone wayland only mode #127932

Open
dashezup opened this issue Jul 3, 2021 · 13 comments
Open
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux wayland Issue related to wayland display server
Milestone

Comments

@dashezup
Copy link

dashezup commented Jul 3, 2021

Issue Type: Bug

I'm using Programmer Dvorak keyboard layout, keybindings only works fine on Xorg with default keyboard dispatch (code).

  1. Enable Programmer Dvorak keyboard layout on Linux (setxkbmap us dvp for Xorg)
  2. launch in wayland mode ./code-insiders --enable-features=UseOzonePlatform --ozone-platform=wayland --no-sandbox or change keyboard dispatch to keyCode
  3. Press shortcut Ctrl+Shift+[backtick] (create new integrated terminal, the last key is located at the left side of BACKSPACE key), it will zoom in instead (because it actually think the user inputed Ctrl+#).

I've tried Troubleshooting as well, and I find that it does not follow one single keymap. such like Ctrl+Shift+e works, but it shows strange keys (maybe from QWERTY) for most of combined keys especially those ones involves to the keys on number row.

Programmer Dvorak keyboard layout:
Programmer Dvorak keyboard layout

VS Code version: Code - Insiders 1.58.0-insider (9056b40, 2021-07-03T07:56:06.848Z)
OS version: Linux x64 5.10.27-gentoo
Restricted Mode: No

System Info
Item Value
CPUs Pentium(R) Dual-Core CPU E5700 @ 3.00GHz (2 x 2992)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: disabled_off
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 0, 1, 1
Memory (System) 3.84GB (0.09GB free)
Process Argv --enable-features=UseOzonePlatform --ozone-platform=wayland --no-sandbox
Screen Reader no
VM 0%
DESKTOP_SESSION undefined
XDG_CURRENT_DESKTOP undefined
XDG_SESSION_DESKTOP undefined
XDG_SESSION_TYPE wayland
Extensions: none
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
pythonvspyt602:30291494
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30291487
pythontb:30258533
vsc_aa:30263845
vspre833:30321513
pythonptprofiler:30281269
vshan820:30294714
pythondataviewer:30285072
vscus158:30321503
pythonvsuse255:30319630
vscorehov:30301224
vscod805cf:30301675
pythonvspyt200:30323110
vscextlang:30310088
vsccppwt:30312692
bridge0702cf:30333156

I tried to build vscodium as well, would also appropriate if someone could tell a dirty workaround by patching something to get programmer dvorak works for me on wayland. so far I've only notice vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/ but idk what should I edit.

@dashezup
Copy link
Author

dashezup commented Jul 3, 2021

I just compared the log while pressing the same key Ctrl+Shift+[backtick] with Programmer Dvorak between using code and keyCode as dispatch under Xorg. It shows the same Received keydown event and Converted keydown event but has different behavior.

diff <(cut -c27- code-works-properly-open-integrated-terminal.txt) <(cut -c27- keycode-unexpected-behavior-zoom-in.txt)

9,12c9,10
< [renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+[Equal]
< [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.terminal.toggleTerminal, when: terminal.active, source: built-in.
< [renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+[Equal]
< [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.terminal.toggleTerminal, when: terminal.active, source: built-in.
---
> [renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+=
> [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.zoomIn, when: no when condition, source: built-in.

The logs on wayland are also different.

@dashezup
Copy link
Author

dashezup commented Jul 3, 2021

I just read this on Keybinding issues

On Windows, VS Code dispatches on e.keyCode.
On macOS and Linux, VS Code dispatches on e.code.

So seems this rely on vscode to deal with vscode keybinging handling on wayland. using keyCode with custom keyboard layout patches wouldn't work properly.

So here is the comparison of the log of using vscode under Xorg and Wayland.

$ colordiff -u300 <(cut -c27- code-dispatch-works-properly-open-integrated-terminal.txt) <(cut -c27- wayland-code-unexpected-behavior-zoom-in.txt)
--- /proc/self/fd/14	2021-07-03 19:43:04.652710167 +0000
+++ /proc/self/fd/16	2021-07-03 19:43:04.652710167 +0000
@@ -1,14 +1,12 @@
 [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
 [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
 [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
 [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 16, key: Shift
 [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 4 ('Shift')
 [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
-[renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl,shift], code: Equal, keyCode: 187, key: `
+[renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl,shift], code: Equal, keyCode: 187, key: Unidentified
 [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: Equal, keyCode: 81 ('=')
-[renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+[Equal]
-[renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.terminal.toggleTerminal, when: terminal.active, source: built-in.
-[renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+[Equal]
-[renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.terminal.toggleTerminal, when: terminal.active, source: built-in.
-[renderer1] [info] [KeybindingService]: + Storing single modifier for possible chord ctrl.
+[renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+=
+[renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, matched workbench.action.zoomIn, when: no when condition, source: built-in.
+[renderer1] [info] [KeybindingService]: + Storing single modifier for possible chord shift.
 [renderer1] [info] [KeybindingService]: + Clearing single modifier due to 300ms elapsed.

@dashezup
Copy link
Author

dashezup commented Jul 3, 2021

Not sure if this could help, here is the ouput of libinput debug events for pressing Ctrl+Shift+[backtick] on sway WM.

libinput debug-events --show-keycodes --verbose
> 
libinput version: 1.17.2
event1  - Power Button: is tagged by udev as: Keyboard
event1  - Power Button: device is a keyboard
event0  - Power Button: is tagged by udev as: Keyboard
event0  - Power Button: device is a keyboard
event2  - HDA ATI HDMI HDMI: is tagged by udev as: Switch
event2  - not using input device '/dev/input/event2'
event3  - HDA Intel Front Mic: is tagged by udev as: Switch
event3  - not using input device '/dev/input/event3'
event4  - HDA Intel Rear Mic: is tagged by udev as: Switch
event4  - not using input device '/dev/input/event4'
event5  - HDA Intel Line: is tagged by udev as: Switch
event5  - not using input device '/dev/input/event5'
event6  - HDA Intel Line Out: is tagged by udev as: Switch
event6  - not using input device '/dev/input/event6'
event7  - HDA Intel Front Headphone: is tagged by udev as: Switch
event7  - not using input device '/dev/input/event7'
event8  - USB OPTICAL MOUSE: is tagged by udev as: Mouse
event8  - USB OPTICAL MOUSE: device set to 1000 DPI
event8  - USB OPTICAL MOUSE: device is a pointer
event9  - HID 046a:0011: is tagged by udev as: Keyboard
event9  - HID 046a:0011: device is a keyboard
-event1   DEVICE_ADDED     Power Button                      seat0 default group1  cap:k
-event0   DEVICE_ADDED     Power Button                      seat0 default group2  cap:k
-event8   DEVICE_ADDED     USB OPTICAL MOUSE                 seat0 default group3  cap:p left scroll-nat scroll-button
-event9   DEVICE_ADDED     HID 046a:0011                     seat0 default group4  cap:k
 event9   KEYBOARD_KEY     +0.000s	KEY_LEFTCTRL (29) pressed
 event9   KEYBOARD_KEY     +0.000s	KEY_LEFTSHIFT (42) pressed
 event9   KEYBOARD_KEY     +0.256s	KEY_EQUAL (13) pressed
^@ event9   KEYBOARD_KEY     +0.320s	KEY_EQUAL (13) released
 event9   KEYBOARD_KEY     +0.392s	KEY_LEFTCTRL (29) released
 event9   KEYBOARD_KEY     +0.400s	KEY_LEFTSHIFT (42) released
 event9   KEYBOARD_KEY     +12.704s	KEY_LEFTCTRL (29) pressed
 event9   KEYBOARD_KEY     +12.848s	KEY_I (23) pressed
^C
event1  - Power Button: device removed
event0  - Power Button: device removed
event8  - USB OPTICAL MOUSE: device removed
event9  - HID 046a:0011: device removed

@dashezup
Copy link
Author

dashezup commented Jul 4, 2021

I guess this requires wayland support for node-native-keymap

microsoft/node-native-keymap#17

I still wonder if there is a way to workaround this for me by something like hard-code programmer dvorak to my vscode build.

@alexdima
Copy link
Member

alexdima commented Jul 5, 2021

@dashezup Dispatching on e.code should work out of the box. But that one suffers from #24166 and #23690. What is the output of setxkbmap -query? If you would make sure the output of that command would return first your desired keyboard layout, then vscode will pick that one up.

@alexdima alexdima added keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux info-needed Issue requires more information from poster labels Jul 5, 2021
@dashezup
Copy link
Author

dashezup commented Jul 5, 2021

@alexdima vscode works properly with e.code with X11 or xwayland. But I want to use vscode on wayland-only mode, since this is the only software and the only issue that I need to use in wayland only mode.

I've read this on Keybinding Issues, and I can confirm e.keyCode does not works properly in any circumstance for me (with Programmer Dvorak keyboard layout).

What's wrong with e.keyCode

macOS and Linux do not have an Operating System level correspondant for e.keyCode. Keyboard layouts on macOS and Linux consist of a single mapping. Chromium does a somewhat decent job at coming up with values for e.keyCode, but all the values are fabricated, and any piece of code that ends up depending on e.keyCode will ultimately be incorrect on various keyboard layouts on macOS/Linux.

setxkbmap simply won't work on wayland only mode.

user@hostname ~ $ setxkbmap -query  # X11, works properly with e.code
rules:      evdev
model:      pc104
layout:     us
variant:    dvp
user@hostname ~ $ setxkbmap -query  # wayland with xwayland, works properly with e.code
rules:      evdev
model:      pc105
layout:     us
user@hostname ~ $ setxkbmap -query  # wayland-only, no X11. e.code or e.keyCode, lots of keybindings does not work
Cannot open display "default display"

To use vscode in wayland-only mode, I need to launch vscode with this arguments --enable-features=UseOzonePlatform --ozone-platform=wayland (may need to disable xwayland in a wayland desktop environment or window manager as well)

Since node-native-keymap only support X11 for linux, it's probably that vscode can't get proper keymap on wayland-only mode (mostly only letter keys works properly for keybindings)

@dashezup dashezup changed the title Custom keyboard layouts does not works properly on wayland or with keyCode dispatch Custom keyboard layouts does not works properly on ozone wayland only mode Jul 5, 2021
@dashezup
Copy link
Author

dashezup commented Jul 5, 2021

keyboard input is usually handled by libinput under wayland. but I haven't find related API for querying layout variant or keymap.

anyway for now I just want to have a temporary solution by patching and build vscode to hard-code programmer dvorak keyboard layout, so that it could work for me under wayland only mode. could you tell me how to do so? I'm unable to find the exact code which I need to edit.

so far I've only found this

// Ensure letters are mapped
_registerLetterIfMissing(CharCode.A, ScanCode.KeyA, 'a', 'A');
_registerLetterIfMissing(CharCode.B, ScanCode.KeyB, 'b', 'B');

and vscode/src/vs/workbench/services/keybinding/browser/keyboardLayouts/en.linux.ts but maybe this one is not used for my case? I tired to replace it with programmer dvorak and it does not change anything.

@alexdima
Copy link
Member

alexdima commented Jul 5, 2021

setxkbmap simply won't work on wayland only mode.

Thank you, that clarifies things, so I understand now.

I'm real sorry, but I don't think we have anything short of a code change to help here. The en.linux.ts file you found is only used when running on the web. If you don't mind patching things, you can try to look for this in the generated .js, at vs/code/electron-main/main.js and returning there something cooked. You can find the data format if you open an editor and run F1 > Inspect Key Mappings (JSON).

A possible user workaround (that might be costly to author) would be for you to manually define the keybindings you care about using the code format in your keybindings.json file e.g.

{ "key": "ctrl+[Semicolon]", "command": "workbench.action.files.save" },
// ...

You can potentially extract them and then copy-paste from when running with X enabled F1 > Open Default Keyboard Shortcuts (JSON).

@alexdima alexdima added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jul 5, 2021
@dashezup
Copy link
Author

dashezup commented Jul 5, 2021

Thanks I did what you suggested, patched and built vscodium with Programmer Dvorak as keyboard layout, it works properly.

dashezup added a commit to dashezup/vscodium that referenced this issue Jul 6, 2021
dashezup added a commit to dashezup/vscodium that referenced this issue Jul 12, 2021
microsoft/vscode#127932

- workflow linux: remove scheduled events
- remove macos and windows workflows
@intentionally-left-nil
Copy link

I similarly am having an issue with the dvorak layout. For now, I worked around this by adding the following to my settings.json:
"keyboard.dispatch": "keyCode" taken from
#23964

@ch3n9w
Copy link

ch3n9w commented Apr 12, 2023

Same issue here, I use custom keyboard layout to map ESC to Backquote, all wayland application can input Backquote by pressing ESC except chromium, vscode and chrome, which just recognize ESC as ESC. However, other remapped key is able to work. Setting keyboard:Dispatch to KeyCode didn't work for me.

related content in Inspect Key Mappings (JSON) output:

"Escape": {
	"value": "`",
	"withShift": "~",
	"withAltGr": "`",
	"withShiftAltGr": "~",
	"withLevel5": "`",
	"withLevel3Level5": "`"
},

@ulugbekna ulugbekna added this to the Backlog milestone Dec 6, 2023
@septatrix
Copy link

This also happens with popular layouts like e.g. the german layout

@manuelbb-upb
Copy link

I am experiencing issues as well in Wayland.
I have installed this version (trough Home-Manager on Nixos):

Version: 1.94.1
Commit: e10f2369d0d9614a452462f2e01cdc4aa9486296
Date: 2024-10-05T05:44:32.189Z
Electron: 30.5.1
ElectronBuildId: 10262041
Chromium: 124.0.6367.243
Node.js: 20.16.0
V8: 12.4.254.20-electron.0
OS: Linux x64 6.6.54

I am using the German Neo2 layout for a pc105 keyboard.
Like in the above comment the layout is not detected by setxkbmap in Wayland sessions (tested on Hyprland and Plasma6).
Likewise, Developer: Inspect Keymappings (JSON) is wrong, it contains:

"layout": {
		"model": "pc105",
		"group": 0,
		"layout": "us",
		"variant": "",
		"options": "",
		"rules": "evdev"
	},

This leads to a very annoying issue:
When hitting AltGr (an important modifier in the Neo2 layout) on its own, VSCode thinks this is Alt.
It still works as a modifier, e.g., for accessing arrow keys etc.
But if I am a tiny bit too slow, VSCode thinks its Alt and I loose focus -- because the menubar is focused and I am in danger of accidentally messing with it.

I could not provoke the issue in Plasma6 X11, where VSCode detects the right layout.
Thus, it does not seem to be an issue caused by extensions (vim etc.)

I already have "keyboard.dispatch": "keyCode" since forever.

For now, I am hoping that disabling menubar mnemonics somewhat mitigates my particular issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug keyboard-layout Keyboard layout issues linux Issues with VS Code on Linux wayland Issue related to wayland display server
Projects
None yet
Development

No branches or pull requests

7 participants