1

I'm using a US keyboard layout, but occasionally need to type German umlauts. So far I used .Xmodmap with definitions like this

keycode 133 = Mode_switch NoSymbol Mode_switch
keycode  38 = a A adiaeresis Adiaeresis aacute Aacute
keycode  39 = s S ssharp ssharp ssharp section

where I can reach the umlauts and the sharp s via the Windows key plus a/o/u/s. How can I achieve exactly (really got used to it...) the same behavior with the new xkb system (config file /usr/share/X11/xkb/symbols/pc). It looks even more complicated than Xmodmap.

I would appreciate any help.

ThunderBird
  • 1,955
Ralf
  • 181
  • I'd go with Compose Key + a + ". – pLumo Oct 18 '18 at 10:47
  • You can also use the US keyboard international variant, which has some dead keys. Settings > Country and language > add English (US, international variant). – Johannes Lemonde Oct 18 '18 at 11:46
  • 1
    One more thing you could do is modifying your keyboard's file in following folder /usr/share/X11/xkb/symbols/, then reboot. You could, this way add third level keys (triggered with AltGr). Obviously, these files may get overwritten by release upgrades. – Johannes Lemonde Oct 18 '18 at 11:50
  • 1
    @JohannesLemonde: I can't make it work under Ubuntu 18.04. I tried to select English (US, intl. with dead keys)' andEnglish (US, alt. intl.)' and others with `intl.' in it, but I can't produce German umlauts. How is it supposed to work, I thought with AltGr+a/o/u/s? – Ralf Oct 18 '18 at 16:32
  • 1
    I tried this one https://askubuntu.com/a/968758/883344, but then the umlauts are not at the corresponding non-umlaut characters, also not so useful. – Ralf Oct 18 '18 at 16:33
  • 1
    I seem to have found a version with AltGr, see https://blog.florianheinle.de/englische-tastatur-umlaute (in German), start gnome-tweaks -> Keyboard&Mouse -> Additional Layout Options -> Key to choose the 3rd level: select "right alt", then change /usr/share/X11/xkb/symbols/us like this: key <AD07> { [u, U, udiaeresis, Udiaeresis ] }; – Ralf Oct 18 '18 at 17:36
  • 1
    @Ralf : Actually no, you can't use AltGr+a/o/u with the international keyboard. The international keyboard only adds dead keys. That means that you have to trigger the dead key first, using AltGr, and type a/o/u then. You can find a whole representation of your currently selected keyboard when you click in the panel bar on the button which shows which keyboard is selected, then "show keyboard disposition" (or similarly translated). – Johannes Lemonde Oct 18 '18 at 17:45
  • 1
    @Ralf : using myself several languages, I think however that the other solution, modifying /usr/share/X11/xkb/symbols/us, is more satisfying for performance users. But think to save a copy of the file after you modified it because it might get replaced by the original one after some updates (happens 2 or 3 times a year, usually after Ubuntu release). – Johannes Lemonde Oct 18 '18 at 17:48
  • 1
    I just found this method for using local keyboard descriptions (in your home): https://askubuntu.com/a/896298/883344 and https://askubuntu.com/a/896297/883344 but didn't test it yet. – Ralf Oct 18 '18 at 18:20
  • 1
    This answer shows an example of how the us symbols file can be edited (even if the question was about Swedish extra letters): https://askubuntu.com/questions/873933/using-ctrl-as-modifier-to-produce-swedish-letters-%C3%A5-%C3%A4-%C3%B6-on-us-keyboard-while – Gunnar Hjalmarsson Oct 18 '18 at 23:44

1 Answers1

1

After some unsuccessful attempts to add my own local xkb/symbols file (see https://askubuntu.com/a/896298/883344 and https://askubuntu.com/a/896297/883344), I went for the solution from https://stackoverflow.com/a/45042841/3852630. By running

% setxkbmap -query

I see that my current layout is us. I dump this layout to my own file and make a copy

% mkdir $HOME/XKB
% cd $HOME/XKB
% xkbcomp -xkb $DISPLAY us.xkb
% cp us.xkb us-altgr-umlaut.xkb

and modified the copy as seen here

% diff us.xkb us-altgr-umlaut.xkb
1224,1225c1224,1225
<         type= "ALPHABETIC",
<         symbols[Group1]= [               u,               U ]
---
>         type= "FOUR_LEVEL_ALPHABETIC",
>         symbols[Group1]= [               u,               U,      udiaeresis,      Udiaeresis ]
1232,1233c1232,1233
<         type= "ALPHABETIC",
<         symbols[Group1]= [               o,               O ]
---
>         type= "FOUR_LEVEL_ALPHABETIC",
>         symbols[Group1]= [               o,               O,      odiaeresis,      Odiaeresis ]
1244,1245c1244,1245
<         type= "ALPHABETIC",
<         symbols[Group1]= [               a,               A ]
---
>         type= "FOUR_LEVEL_ALPHABETIC",
>         symbols[Group1]= [               a,               A,      adiaeresis,      Adiaeresis ]
1248,1249c1248,1249
<         type= "ALPHABETIC",
<         symbols[Group1]= [               s,               S ]
---
>         type= "FOUR_LEVEL_SEMIALPHABETIC",
>         symbols[Group1]= [               s,               S,          ssharp,          ssharp ]

I wrote a small shell script which is located somewhere in my search path which contains the line

xkbcomp -w 0 $HOME/XKB/us-altgr-umlaut.xkb $DISPLAY

Whenever I want to switch to my layout with German umlauts, I run this script. I switch back to the default keyboard mapping by

setxkbmap us

As mentioned in my comment above, I now use AltGr to switch a/o/u/s to ä/ö/ü/ß (decided to reprogram my brain to use AltGr instead of the Windows key which seems to have a special meaning in the Gnome 3 desktop). As described in https://blog.florianheinle.de/englische-tastatur-umlaute (in German), AltGr can be used for switching by starting gnome-tweaks, then going to Keyboard&Mouse -> Additional Layout Options -> Key to choose the 3rd level, and selecting right alt.

The alternative is of course to modify the file us in /usr/share/X11/xkb/symbols, but this may get overwritten at the next update. Anyhow, that would be the diff between the new us file and the old (same name):

26c26
<     key <AD07> {  [     u,    U, udiaeresis, Udiaeresis ] };
---
>     key <AD07> {  [     u,    U       ]   };
28c28
<     key <AD09> {  [     o,    O, odiaeresis, Odiaeresis ] };
---
>     key <AD09> {  [     o,    O       ]   };
33,34c33,34
<     key <AC01> {  [     a,    A, adiaeresis, Adiaeresis ] };
<     key <AC02> {  [     s,    S, ssharp, ssharp ] };
---
>     key <AC01> {  [     a,    A       ]   };
>     key <AC02> {  [     s,    S       ]   };
Ralf
  • 181
  • I'm having the same problem. Does diff us.xkb us-altgr-umlaut.xkb print the differences between the files - and that's all the text that you've added to the file? I'm not sure how exactly I need to modify us-altgr-umlaut.xkb... – parsecer Apr 19 '20 at 20:09
  • Yes, that's just the differences. Try to replace the lines marked by '>' with the lines marked by '<' (or just add the two *diaeresis / ssharp entries to the lines). You should better make a backup of the original file in case something goes wrong. – Ralf Apr 21 '20 at 05:16
  • Thank you for answering, I figured out the diff function, I think. I made the same changes to the us-altgr-umlaut.xkb file and saved your script in the same folder: script.sh. Then I used chmod +x script.sh and then ./script.sh to run it. I also opened gnome-tweaks and set the 3rd level key. But after running the script and Trying to Alt gr + u it still typed the normal u, not the dotted one ; ( Did I miss something? – parsecer Apr 21 '20 at 22:17
  • DIfficult to say from afar. Some ideas: (1) You should use the first diff listed above, not the second one, is that ok? (2) The .xkb file has to be in the same path as specified in the script ($HOME/XKB). (3) What happens if you type the line from the script into the command line of your shell (xkbcomp...)? – Ralf Apr 23 '20 at 09:22
  • @parsecer: Another idea when you run xkbcomp from the command line: increase the warning level and check whether there's something wrong: -w 10 is the maximum according to the manpage. However, even in my case (where the Umlauts are working) I get some warnings. – Ralf Apr 23 '20 at 10:07