Ubuntu – How to specify keyboard layout vairant in org.gnome.desktop.input-sources

gnomexkb

I have a Thinkpad laptop with an external Apple keyboard. I like to remap the keys for the external keyboard so I have adjusted the relevant parts (the section for mac) in xkb/symbols/us and xkb/symbols/de as I type both in German and English. Ultimately I would like to be able to have an English and a German keyboard with remapped keys available when the Apple keyboard is plugged in and a basic English and German keyboard available when the external keyboard is not attached.

I wanted to use gsettings set org.gnome.desktop.input-sources to switch the available keyboards. This works fine for basic keyboards, e.g.
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'),('xkb'),'de')]"
provides the choice between the basic English and German keyboard.

The problem however is this. Running
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'de(mac)')]" does not seem to work. So the variant de(mac) for some reason cannot be added like this. Switching with setxkmap, however, works setxkbmap -layout "de(mac)".

Say I started with the us(mac) keyboard

setxkbmap -layout "us(mac)"
setxkbmap -print
xkb_keymap {
xkb_keycodes  { include "evdev+aliases(qwerty)" };
xkb_types     { include "complete"  };
xkb_compat    { include "complete"  };
xkb_symbols   { include "pc+us(mac)+inet(evdev)+terminate(ctrl_alt_bksp)"   };
xkb_geometry  { include "pc(pc105)" };
};

Then I try to switch but the keyboard remains on us(mac).

gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'de(mac)')]"`
setxkbmap -print
xkb_keymap {
xkb_keycodes  { include "evdev+aliases(qwerty)" };
xkb_types     { include "complete"  };
xkb_compat    { include "complete"  }; 
xkb_symbols   { include "pc+us(mac)+inet(evdev)+terminate(ctrl_alt_bksp)"        };
xkb_geometry  { include "pc(pc105)" };
};

Anybody know how to reference a variant in org.gnome.desktop.input-sources?

Thanks a lot!

Best Answer

The correct syntax seems to be 'us+mac' instead of 'us(mac)':

gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us+mac'),('xkb','de+mac')]"

See also this post

Related Question