9

I have a US keyboard and layout but sometimes I need german special keys (äÄöÖüÜß). Of course I could switch keyboard layouts when I need it but I used to abuse that uttery useless caps lock key to access the characters I need with the following ~/.Xmodmap:

keycode 66 = Mode_switch Multi_key
keycode 20 = minus underscore ssharp
keycode 34 = bracketleft braceleft udiaeresis Udiaeresis
keycode 47 = semicolon colon odiaeresis Odiaeresis
keycode 48 = apostrophe quotedbl adiaeresis Adiaeresis

For some strange reason the keyboard behavior has changed when Fedora switched to Wayland. Now my (magic) keyboard mapping only works sometimes and the caps lock key acts als case locker again :(

Is there a Wayland aware approach to make (german) special characters available on a US keyboard? (Or alternatively make []{}|<> available with one key stroke on a german keyboard)

frans
  • 1,057
  • 2
  • 14
  • 27

2 Answers2

15

Wayland uses XKB, but how to specify your layout varies based on your compositor (you can't use setxkbmap or xkbcomp as in Xorg). You'll probably want the altgr-intl variant of the standard us layout (US international layout) and possibly some options: Compose (aka Multi_key), perhaps on a Menu key? AltGr on the right Alt key? (The intl variant is similar but includes deadkeys on level 1; altgr-intl puts deadkeys on level 3, so they're out of the way but still accessible.)

Under this layout and variant, most of the symbols you've listed are available handily under the AltGr or Compose keys:

AltGr+q = ä   AltGr+Shift+a = Ä    Compose+",a = ä    Compose+",A = Ä
AltGr+p = ö   AltGr+Shift+p = Ö    Compose+",o = ö    Compose+",O = Ö
AltGr+y = ü   AltGr+Shift+y = Ü    Compose+",u = ü    Compose+",U = Ü
AltGr+s = ß                        Compose+s,s = ß

For Weston, you'd add settings to $HOME/.config/weston.ini:

[keyboard]
keymap_rules=evdev
keymap_layout=us
keymap_variant=altgr-intl
keymap_options=compose:menu,level3:ralt_switch

For sway (an i3-alike), you need to set environment variables before execution, either chained together on the commandline or in a helper script:

#!/bin/sh
export XKB_DEFAULT_LAYOUT=us
export XKB_DEFAULT_VARIANT=altgr-intl
export XKB_DEFAULT_OPTIONS=compose:menu,level3:ralt_switch
sway

Under GNOME, you'll have to consult your favorite gsettings or dconf frontend. You can specify XKB options in /org/gnome/desktop/input-sources/xkb-options and specific layouts in /org/gnome/desktop/input-sources/sources. (These may have changed since the post; check your existing settings.)

gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us+altgr-intl')]"
gsettings set org.gnome.desktop.input-sources xkb-options "['compose:menu','lv3:ralt_switch']"

KDE uses its own graphical control panel; you'll find it in System Settings > Hardware > Input Devices > Keyboard. The Layouts tab will allow you to configure the altgr-intl variant (it's listed as "English (international AltGr dead keys)"), and the XKB options are listed on the Advanced tab.

On current KDE Frameworks 5, this control panel stores settings in $HOME/.config/kxkbrc.


If your system uses systemd's localectl you might try setting that to what you'd want, and GNOME/KDE might be able to pick it up from there. That may only set things for Xorg at present, but I like having it as a fallback, and I hope Wayland compositors will use it in future releases to pick up systemwide preferences.

sudo localectl set-x11-keymap us pc105 altgr-intl compose:menu,level3:ralt_switch
(format:                  [layout] [model] [variant] [options])
quixotic
  • 849
  • 6
  • 11
  • Modding `org.gnome.desktop.input-sources.xkb-options` w/ `compose:menu` via dconf editor worked for me, tyvm – lkraav Sep 14 '17 at 14:59
  • Thank you. I would prefer "Windows style" composing, where there is no need to press a compose key. However this will do, and I could learn to use the 3rd level key. – Rolf Feb 17 '18 at 12:43
  • @Rolf i'm not sure what you mean by "windows style", sorry. if you're referring to "deadkeys" (ie press `'` then `e` to get `é`), that's the `intl` rather than `altgr-intl` variant. with deadkeys you have to press the deadkey twice to get the actual symbol, which is cumbersome for my use. – quixotic Feb 17 '18 at 18:53
  • following this answer, adding `xkb_variant altgr-intl` in my `input "type:keyboard" {}` section of my sway config file works to activate the altgr as a compose key. – Bastian May 11 '23 at 22:21
0

One possibility might be to change your default keyboard from English (US) to English (International). I do this on all the computers I have sufficient control over, and it lets me use some punctuation as "dead key" accents to get common non-English characters.

On Windows, this converts the right Alt key into AltGr, and combining this with certain keystrokes gets me related non-English characters, such as AltGr+s for sharp-s, AltGr+t for the Icelandic thorn, AltGr+d for the Icelandic edh, and others.

For "dead-key", most punctuation doubles as accents - to get e-acute, type ' then e; o-acute ' then o, a-grave ` then a, u-umlaut " then u, and so on. To get the punctuation, either press a character that it doesn't combine with as an accent, or press space - an apostrophe is ' then space; a double-quote/inch mark is " then space, and so on. It's a little bit of an adjustment, but a lot easier than memorizing alt-codes (on Windows) or continually switching between layouts.

(I've since done this in 'out-of-the-box' Linux Mint; modulo some minor differences in where some of the AltGr characters are located, ithas the same effect - but it's noy Wayland).

Jeff Zeitlin
  • 4,416
  • 2
  • 16
  • 30