60

I am using 'i3` window manager on Fedora 25. I've already uninstalled GNOME Desktop. I want to change keyboard layout and set it to languages other than English, and desirably also to set it as Alt+Shift shortcut for easy access.

7 Answers7

85

You can use setxkbmap:

setxkbmap -layout us,de
setxkbmap -option 'grp:alt_shift_toggle'

Just change the keyboard layouts us,de to what ever you prefer. If you want i3 to run these commands on startup, just add them to your config file "~/.i3/config" and prepend "exec".

exec "setxkbmap -layout us,de"
exec "setxkbmap -option 'grp:alt_shift_toggle'"

Checkout http://docs.slackware.com/howtos:window_managers:keyboard_layout_in_i3

tomsal
  • 966
  • 7
  • 3
  • 4
    Thanks, is it possible to add an indication of it on i3bar as well? –  Dec 01 '16 at 14:07
  • 4
    Yes, it is. See http://docs.slackware.com/howtos:window_managers:keyboard_layout_in_i3#displaying_the_active_layout_in_the_panel – tomsal Jan 13 '17 at 10:28
  • this just doesn't work, nothing changes when using alt-shift =( – Yurii Aug 19 '17 at 16:59
  • 2
    Have you tried using the setxkbmap commands from the command line (without the i3 config)? What does it say when you run `setxkbmap -query`? – tomsal Aug 20 '17 at 19:50
  • It is important to add these lines into config in it's top, otherwise come short keys might be broken – keddad Jan 02 '20 at 17:19
  • I'm not seeing in the documentation where if any the language codes are specified. Is there a list? I don't see where the Windows key is specified either. Is there a way to specify a toggle using it? – haleonj Jan 19 '20 at 11:51
  • Maybe you can find the possible options of setxkbmap in "/usr/share/X11/xkb/rules/base.lst". On my system, for example, there's a line in that file for "grp:win_space_toggle" which you could use to use the windows key. More options are listed there. In the same file you might also find the available language codes (search for the line "! layout"). – tomsal Jan 24 '20 at 10:46
  • Language 2 letter codes are at `/usr/share/X11/xkb/rules/base.lst` . It may be different from windows/web 2 letter codes – Zeta.Investigator Mar 22 '20 at 13:38
  • 1
    Beware that due to a bug, if you use Alt+Shift to swtich, all other shortcuts containing this sequence would be disabled (like tty mode shortcut). https://gitlab.freedesktop.org/xorg/xserver/issues/258 – Zeta.Investigator Mar 23 '20 at 11:54
  • thank you! how can I make an indicator in my status bar? – SdSaati May 09 '20 at 08:06
  • `setxkbmap -option 'grp:win_space_toggle'` for toggling with `Super+Space`. – anatoly techtonik Oct 25 '20 at 19:36
  • Add `--no-startup-id` to the `exec` if you get a spinning mouse cursor during startup. – jasal Jun 05 '23 at 10:47
9

For me only the following worked in Manjaro + i3:

exec_always "setxkbmap -model pc104 -layout us,ru,ua -variant ,, -option grp:alt_shift_toggle"

I specified this in ~/.config/i3/config file

Yurii
  • 191
  • 1
  • 3
  • 1
    Be sure to find out which ```-model``` you got by running ```setxbmap -query``` in your terminal prior. Mine turned out to be ```pc105```. Worked for me. – rtviii Nov 09 '20 at 08:55
9

It indeed seems that everything must be written inside a single command in the i3 config file in order for setxkbmap to work as desired, at least on Arch linux.

Example: English + Czech qwerty keyboard, ALT+SHIFT toggle:

exec "setxkbmap -option 'grp:alt_shift_toggle' -layout us,cz -variant ,qwerty"
Brikowski
  • 91
  • 1
  • 2
1

insert into your .config/i3/config

# switch keymap

bindsym $mod+Ctrl+Shift+F11 exec setxkbmap -layout ch -variant fr
bindsym $mod+Ctrl+Shift+F12 exec setxkbmap -layout ru -variant phonetic
1

The desired shortcut set by XKB option grp:alt_shift_toggle


But using setxkbmap -option in ~/.i3/config for configuring keyboard layouts is not the best approach.

  • Bluetooth keyboards can go to sleep to save battery then reconnect. In that case layout configuration will be reset to default.
  • There is no way to configure keyboards separate. For example, my Bluetooth keyboard has no Right Alt so I am using Caps Lock on it.

If this is your case consider using /etc/X11/xorg.conf.d/00-keyboard.conf (man xorg.conf DESCRIPTION for all available paths):

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us,ru"
        Option "XkbOptions" "grp:toggle"
EndSection

Section "InputClass"
        Identifier "Bluetooth Keyboard"
        MatchIsKeyboard "on"
        MatchProduct "Bluetooth 3.0 Keyboard"
        Option "XkbLayout" "us,ru"
        Option "XkbOptions" "grp:alt_shift_toggle,grp_led:caps"
EndSection

See man xkeyboard-config

  • LAYOUTS for language codes in XkbLayout
  • OPTIONS for switching to another layout hotkeys (all grp:*)

Or: https://unix.stackexchange.com/a/45499/384576


See xinput list for MatchProduct

More: https://unix.stackexchange.com/a/220082/384576

Victor S.
  • 11
  • 2
0

"exec setxkbmap" didn't work for me. Through frustrated keyboard smashing, I accidentally pulled up the display settings (Super+D since I installed from Regolith-desktop), and from there I could open up "Region & Language" to set the keyboard layout. I guess i3 "Ubuntu" keyboard layout settings are store separate from "Kubuntu" keyboard layout settings.

Stephen
  • 123
  • 6
0

my setup: gnome manjaro + i3 default
1 step - cd ~/.config/i3/ and edit config (example vi or nvim confif)
2 step past this line exec_always "setxkbmap -model pc104 -layout us,ru,ua -variant ,, -option grp:alt_shift_toggle" if you need to change language

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 29 '22 at 08:47