33

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"
EndSection

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...
Success.
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)

kolen
  • 443
  • 1
  • 5
  • 10
  • Have you tried setting the layout correctly in gnome and then adding the two setxkbmap commands to your ~/.profile? That way, they will be run each time you log in and since the same settings are there in Gnome, it should not change anything if it resets. – terdon Apr 21 '14 at 12:52
  • 1
    @terdon it resets even after screen lock. And it resets to "us-only, no switch" state, not to settings defined in org.gnome.desktop.input-sources. – kolen Apr 21 '14 at 13:29
  • Strange. Are you sure you are using Gnome and not Unity? Have you tried changing the settings through the normal GUI instead of dconf-editor? – terdon Apr 21 '14 at 13:33
  • @terdon yes, it is unity, but it uses lost of gnome's stuff, like gnome-settings-daemon, which possily resets keymap. – kolen Apr 22 '14 at 15:34
  • So, have you tried setting the correct settings from the Unity GUI? – terdon Apr 22 '14 at 23:25
  • @terdon unity GUI does not set xkbmap correctly, it uses its own switcher that intercepts keypresses and switch keyboard. It is slow and causes focus to being loss when key is pressed. – kolen Apr 23 '14 at 07:58
  • +1 for the question. This is a really annoying (and ignored) bug. I ended up designing my own layout to avoid switching layout; but I understand that it is viable for me because I need just a couple of keys but not a general solution. By the way, have you checked if disabling ibus helps? See https://bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/1246272 – Rmano Sep 02 '14 at 14:17
  • Sorry, the correct bug should be https://bugs.launchpad.net/ubuntu/+source/indicator-keyboard/+bug/1240198 – Rmano Sep 02 '14 at 14:23
  • Something not related with your problem: Which theme is this? – Pigeonaras Sep 07 '14 at 10:42
  • Setting the xkb-options field to ['altwin:swap_alt_win'] in dconf-editor works in ubuntu 14.10 (unity) to have this xkboption remain after switching the keyboard layout (e.g. english -> french etc). In contrast, setxkbmap -option does't work for that, this cmd has to be re-issued each time. Not quite sure if this helps your problem - this is just to say that it appears that org.gnome.desktop.input-sources is what matters when the keyboard layout is switched (at least on unity) – armando.sano Dec 05 '14 at 12:31
  • xmodmap is possible solution although is certainly reset on restart. This should set it to Dvorak wget -qO- http://pastebin.com/raw.php?i=t2Ndf1Zw | xmodmap - – William Jul 22 '15 at 19:41
  • Found localectl but it doesn't persist, either. Did you find a solution that persists after reboot and lock screen? I am looking for a command line, scriptable one myself. – Nickolai Leschov Oct 12 '15 at 21:51

5 Answers5

21

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.

Iasha102
  • 321
6

I've been going nuts over this just like you, but with Ubuntu 14.04 (LTS), Xubuntu, xfce 4.12 and xkbd (from xfce goodies). Ctrl+Space to change the keyboard layout worked, but Alt+Shift didn't (modifier-only keys).

Finally managed to make things work-

1. Run ibus-setup (Keyboard Input Methods application).
2. Goto Advanced tab.
3. Check 'Use system keyboard layout'.
4. Click 'Close'

5. Run xfce4-keyboard-settings (Keyboard application).
6. Goto Layout tab.
7. Uncheck 'Use system defaults'
8. Select 'Keyboard model' (typically 'Generic 105-key (Intl) PC' will do)
9. Set 'Change layout option' to your required switching keys combination (typically Alt+Shift will do).
10. Add languages to 'Keyboard layout'.
11. Click 'Close'.
12. Restart the computer

You're done! Use Alt+Shift to change keyboard layout.

Oron Port
  • 161
2

I just read this article on screenlocking, which may be related. According to the article, screenlocking has the intended consequence of blocking input devices and manipulating locales. Seems like you have a few options:

  1. Stop locking the screen, probably this includes the greeting screen as well which serves a similar function
  2. Use different power management tools
  3. Stop using ibus for im-switching (Perhaps FCITX?)
  4. Create a hook for screen unlock events as described here.

There is an interesting discussion of this and related events which can be found on the ubuntu-dev mailing list: https://lists.ubuntu.com/archives/ubuntu-devel/2013-November/037768.html

Hawk
  • 191
1

Workaround by user wof in Ubuntu bug tracker, for Ubuntu 14.10 using gxkb:

https://bugs.launchpad.net/gnome-settings-daemon/+bug/1244090/comments/39

this workaround worked for ubuntu 14.10:

  • in Settings->Text entry remove all input sources, leave only english
  • install gxkb (layout switcher): sudo apt-get install gxkb
  • add gxkb to startup applications via gnome-tweak-tool
  • setup gxkb hotkeys in ~/.config/gxkb (default is alt_shift, but in 14.10 it doesn't work. ctrl_shift works ok)

p.s. new version of gxkb has appindicator for ubuntu. can be installed via ppa:zen-root/gxkb-stable

kolen
  • 443
  • 1
  • 5
  • 10
-1

First, just executing setxkbmap:

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

But it works only:

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

Well as far as Gnome "resetting" it i dunno. I do know how you can get to stay every reboot though as I had to do the exact same type of thing for my Logitech mouse. It has multiple buttons which I wanted remapped a certain way and I had to have that set at restart.

So what you do for that is create a text file. Then in that text file type:

#!/bin/bash

and right below that put in your commands. As example my mouse looks like this:

#!/bin/bash
xinput set-button-map "Logitech USB-PS/2 Optical Mouse" 1 2 3 4 5 8 9 6 7 10 11 12 13 14 15 16

next you would save that as whatever name you want and move it to some place like your home directory. it has to stay there "forever".

then just open up your Startup Applications and Add the file to your startup and then you dont have to worry about it lasting only for the session. it will be ok to reboot your computer because your settings will come back through the file you just added.

David
  • 146
  • 10