Enjoy Slackware 15.0!

Welcome to the Slackware Documentation Project

This is an old revision of the document!

Keyboard Layout in i3

i3 Window Manager

i3wm does not come with stock Slackware. If you want to install this extremely configurable tiling window manager, please visit SlackBuilds. Make sure you also install i3status, which will let you display all sorts of useful information in a panel.

Setting the Keyboard Layout

i3 does not come with any built-in keyboard setting mechanism. The setxkbmap command, however, does the job well. If you've set the keyboard layout system-wide and do not need to switch between layouts, you do not need to do anything. If you'd like to set the layout just for i3, you can edit its .xinitrc file. If you change a graphical environment often and you do not want the keymap to be overwritten, you need to modify /etc/X11/xinit/xinitrc.i3.

# nano /etc/X11/xinit/xinitrc.i3

Just before the Start i3 section you can specify the desired keymap (eg. gb):

setxkbmap gb

Save the file and run (as a standard user) xwmconfig and choose i3 to copy the xinitrc file to your home directory. If you are in X, you might need to restart it.

Changing the Keyboard Layout

If you need to switch between different layouts, you can map some keybindings to perform those functions.

1. Open the i3 config file

nano ~/.i3/config

2. Add the following (it's just an example):

Assign Mod4 to the Microsoft key (I use the Microsoft key a lot to avoid clashes with default i3 keybindings):

set $ms Mod4
bindsym $ms+d exec setxkbmap de
bindsym $ms+g exec setxkbmap gb

Now MS+D and MS+G let me switch between the UK and German keyboard layouts.

Displaying the Active Layout in the Panel

i3status comes with a lot of built-in functions. Unfortunately, the current keyboard layout is not one of them. For that reason, you need to write a short script to display the layout in the panel. The default i3status invocation is as follows:

bar {
    status_command i3status

Here all the built-in functionality is configured in ~/.i3status.conf. We want to add some more on top of that and change it to:

bar {
    status_command /path/to/your/i3script.sh

The contents of i3script.sh


# shell scipt to prepend i3status with more stuff

i3status --config ~/.i3status.conf | while :
        read line
        LG=$(setxkbmap -print | grep xkb_symbols | awk -F"+" '{print $2}') 
        echo "LG: $LG | $line" || exit 1

The above will display the current keyboard layout before the standard i3status functions. Obviously you can add much more to i3status.


In Other Languages
Translations of this page?:
QR Code
QR Code howtos:window_managers:keyboard_layout_in_i3 (generated for current page)