xmodmap is depreciated and does not work with gsettings, doing this here disables my xmodmap etc sudo vi /etc/default/keyboard > XKBOPTIONS="ctrl:nocaps" and sudo setxkbmap dvorak '' ctrl:nocaps

gsettings set org.gnome.desktop.input-sources xkb-options "['compose:ralt']"

I would like to do the change of capslock to Ctrl by gsettings. However, I do not find such a possibility in the settings. I think this change can be reached by Keyboard > Shortcuts > Custom Shortcuts > + but I am not sure how it could be done with gnome.

How can you change capslock to Ctrl by gnome-settings?

  • 1
    Did you try gsettings set org.gnome.desktop.input-sources xkb-options "['compose:ralt','ctrl:nocaps']"? – user.dz Jun 7 '16 at 17:39

Add 'caps:ctrl_modifier' to the value of org.gnome.desktop.input-sources xkb-options in gsettings, for example

 gsettings set org.gnome.desktop.input-sources xkb-options "['compose:ralt', 'caps:ctrl_modifier']"

You can use

gsettings set org.gnome.desktop.input-sources xkb-options "$(gsettings get org.gnome.desktop.input-sources xkb-options | sed "s/]/, 'caps:ctrl_modifier']/")"

to append on to the current value of xkb-options. You can find more possible option in the "OPTIONS" section of the xkeyboard-config manpage

To change your keyboard layout you need to set the value of org.gnome.desktop.input-sources sources, e.g.

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

if you want to only use Dvorak or

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

if you want to be able to switch between Dvorak and standard layout.

See the "LAYOUTS" section of the xkeyboard-config manpage for more layouts. You need to substitute the parents so that e.g. us(dvorak) becomes us+dvorak.

The XKB settings from gsettings are loaded by GNOME at startup and overwrite any previous settings. To use setxkbmap you need to make sure that your setxkbmap are run after the GNOME settings are applied. I don't know how to do this.

  • Great! Very good! It works! Can you please tell your source for caps:ctrl_modifiel? I want to know where to look later for improvements. Do you understand why gsettings replaces the command of setxkbmap? How can you add here too that make Dvorak your keyboard layout? I think it is just sudo setxkbmap dvorak '', since your command does not replace it. – Léo Léopold Hertz 준영 Jun 7 '16 at 17:47
  • 2
    Running man xkeyboard-config gives you a huge list of mapping possibilities. It is also available online here – wjandrea Jun 7 '16 at 18:45
  • 1
    @Masi I've added that to my answer. – Florian Diesch Jun 7 '16 at 19:12
  • Assume you the user has empty configs like gsettings set org.gnome.desktop.input-sources xkb-options "[]". Running your second command will fail and give output @as [, 'compose:ralt'] ^. I do not want to run the first command because it replaces all user things. How can you fix the situation here? – Léo Léopold Hertz 준영 Jun 19 '16 at 9:16

@florian-diesch's answer is great, but I thought it would be worth adding a version that will also work in the case that the user has an empty config:

# Map Caps Lock to Ctrl.
XKB_OPTIONS="$(gsettings get org.gnome.desktop.input-sources xkb-options)"
[ "$(echo ${XKB_OPTIONS} | grep -v '\[\]')" ] && gsettings set org.gnome.desktop.input-sources xkb-options "$(echo ${XKB_OPTIONS} | sed "s/\[\]/['caps:ctrl_modifier']/")"
[ "$(echo ${XKB_OPTIONS} | grep -v 'caps:ctrl_modifier')" ] && gsettings set org.gnome.desktop.input-sources xkb-options "$(echo ${XKB_OPTIONS} | sed "s/\]/, 'caps:ctrl_modifier']/")"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.