Ubuntu – Permanently set keyboard layout options with setxkbmap in gnome/unity


Ubuntu 13.101 (and maybe upstream gnome) introduced very annoying bug: pressing keyboard layout switch shortcut makes focus go away to some system window, then back to window where shortcut was pressed. Some applications have some actions bound to change of focus, for example twitter (in browser) closes reply text input field when losing focus, etc. So ubuntu's native keyboard switcher isn't suitable for me, until fixed.

X has builtin switching mechanism, and it is much better, in addition to that it does not involve focus switching, it switches immediately (gnome switcher also sometimes lags).

How can I set up xkbmap options so settings will remain after reboot and will not be reset by Gnome?

What I've tried:

First, just executing setxkbmap:

setxkbmap -layout "us,ru"
setxkbmap -option "grp:caps_toggle,grp_led:scroll,compose:ralt"

But it works only:

  1. For current session
  2. Until Gnome will overwrite it (for example touching something in gconf's org.gnome.desktop.input-sources triggers reset).

Second, adding xkb options to Xorg config:

Another option is to add following to xorg config:

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us,ru"
        Option "XkbModel" "pc105"
        Option "XkbVariant" "pc105"
        Option "XkbOptions" "grp:rctrl_toggle,grp_led:scroll"

Xorg understands that during startup:

[    33.791] (**) Option "xkb_rules" "evdev"
[    33.791] (**) Option "xkb_model" "pc105"
[    33.791] (**) Option "xkb_layout" "us,ru"
[    33.791] (**) Option "xkb_variant" "pc105"
[    33.791] (**) Option "xkb_options" "grp:rctrl_toggle,grp_led:scroll"

But switching configuration still resets later, likely by gnome.

Third, gconf

enter image description here

I have xkb-options and sources set in org.gnome.desktop.input-sources, but Gnome still sets xkb to single English layout:

$ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     us
options:    grp_led:scroll
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete+ledscroll(group_lock)
symbols:    pc+us+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete+ledscroll(group_lock)"    };
    xkb_symbols   { include "pc+us+inet(evdev)" };
    xkb_geometry  { include "pc(pc105)" };

Fourth, another option in gconf

enter image description here

Setting org.gnome.settings-daemon.peripherals.keyboard also does not work for me. Nothing changes.

Upd 1: There is discussion recommending to remove /usr/lib/gnome-settings-daemon-3.0/libkeyboard.so. At least this fixes some resets of xkbmap (i.e. after lock screen).

1 I use 14.04, but problem with losing focus is still not fixed. (Unconfirmed report in upstream Gnome)

Best Answer

To prevent gnome resetting keyboard setting in X i use this command:

gsettings set org.gnome.settings-daemon.plugins.keyboard active false

This works for me.