The Computer Oracle

How to change keyboard layout in i3?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping

--

Chapters
00:00 How To Change Keyboard Layout In I3?
00:23 Accepted Answer Score 86
00:49 Answer 2 Score 11
01:05 Answer 3 Score 10
01:28 Answer 4 Score 2
02:35 Answer 5 Score 1
02:48 Thank you

--

Full question
https://superuser.com/questions/1147320/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #keyboardlayout #i3windowmanager

#avk47



ACCEPTED ANSWER

Score 86


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




ANSWER 2

Score 11


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




ANSWER 3

Score 10


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"



ANSWER 4

Score 2


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




ANSWER 5

Score 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