Bug 432750 - No generic way to re-map keys on Wayland
Summary: No generic way to re-map keys on Wayland
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: input (show other bugs)
Version: git master
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-10 18:16 UTC by Nate Graham
Modified: 2021-04-15 22:26 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
PrintScreen key configure (59.09 KB, image/png)
2021-02-10 20:55 UTC, Andrey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2021-02-10 18:16:16 UTC
I have a ThinkPad Laptop, whose disadvantages include a somewhat unconventional keyboard layout, including a PrintScreen key which is in between the right Alt and Ctrl keys. I always hit it by accident and launch Spectacle when I don't mean to.

On X11, I have re-maped the keys such that the PrintScreen key is a second Meta key, which is super handy, and I turn the useless Insert key at the top of the keyboard into a PrintScreen key. I use XModMap for this on X11:

$  cat ~/.Xmodmap
! Print Screen => Meta
keycode 107 = Super_L
! Insert => PrintScreen
keycode 118 = Print

However this obviously doesn't work on Wayland, and I haven't found another way to do it. It would be nice if KWin somehow supported this officially, in its capacity as an input-handling compositor.
Comment 1 Andrey 2021-02-10 20:55:23 UTC
Created attachment 135578 [details]
PrintScreen key configure
Comment 2 Andrey 2021-02-10 20:58:08 UTC
Nate, Xmodmap is deprecated even on X11 nowadays.
XKB is a platform-agnostic way to go.

Basically, you create custom keymap and then select it in keyboard KCM's Keyboard model listbox. Also you could try existing models there.
There are some pre-ready keyboard options in Advanced tab of the KCM you could look at, see the bottom of screenshot for Print key.
Comment 3 Nate Graham 2021-02-11 03:15:14 UTC
Thanks.

Those pre-existing options don't cut it, because there's no way for me to make the Insert key into PrintScreen. Without that, I won't have a PrintScreen key.

I spent 3 hours of web searching and trial and error and did not succeed in creating a custom keyboard layout to reverse these two keys. Using xmodmap is easy, but this xkb thing is torture. This is desperately crying out for a GUI so it can take 30 seconds and always work rather than gobbling up an afternoon and making you feel like a failure.
Comment 4 Nate Graham 2021-02-11 04:26:58 UTC
One of the oldest bugs is requesting this feature: Bug 30481.
Comment 5 Andrey 2021-02-11 13:28:01 UTC
I understand you.
I did a long way before I could do something useful with XKB, and that knowledge quickly wipes from my head every time :)
Still, I managed to do some mapping for remote of my Kodi box (make use of colored buttons). I'll share my config if I find that box again.

XKB is very powerful but complicated by nature. That is probably why GUI for it still doesn't exist.
It's out of topic here but maybe you faced solutions like this:
https://unix.stackexchange.com/a/572878/249796
Feel free to ping me if you need my help with it.
Comment 6 Andrey 2021-02-11 14:09:16 UTC
Yet another HOWTO (it says Gnome but it's actually irrelevant):
https://www.beatworm.co.uk/blog/keyboards/gnome-wayland-xkb
Comment 7 Andrey 2021-03-05 18:15:46 UTC
For "trivial" tasks as remapping physical keys one may consider a more low-level approach of overriding key codes in udev hwdb instead of relying on XKB:
https://www.freedesktop.org/software/systemd/man/hwdb.html
https://wiki.archlinux.org/index.php/Map_scancodes_to_keycodes
Comment 8 Andrey 2021-04-15 22:18:08 UTC
Just realized we don't even have current layout and physical keyboard visualization.
See what Gnome and xkbprint can do:
https://superuser.com/questions/1293956/show-keyboard-geometry-model-in-gnome

Gnome even allows to interactively test your layout, which is extremely useful.
Comment 9 Andrey 2021-04-15 22:26:13 UTC
Oh, sorry.. We have it too!
There is Preview button in the KCM :)