64

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.

8 Answers8

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

tomsal
  • 976
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

Yurii
  • 211
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"
Brikowski
  • 101
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

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

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

0

for some reason, the other solutions didn't work for me.

I use this bash script instead

LAYOUT=$(setxkbmap -query | grep layout | awk '{print $2}')
case $LAYOUT in
    us)
        setxkbmap br
        ;;
    br)
        setxkbmap us
        ;;
esac

Just change the case statement for the languages you want to use.

and then in your i3config add

bindsym <YOUR_KEYBIND> exec <PATH_TO_SCRIPT>
yuri
  • 1