[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

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.

If you usually switch between two keyboard layouts and you don't need to display the current layout in the status bar, you might also place the following code in your ~/.i3/config file:
setxkbmap -layout de,gb
setxkbmap -option 'grp:ctrl_alt_toggle'

This will let you toggle between the two layouts using Ctrl+Alt.

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 -query | awk '/layout/{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.

Using JSON output format (colors)

The method above uses the simplest output mode (text only). Although easier to use, it lacks color support. For that, you'll need JSON.

Add the following property in your .i3status.conf

general {
    output_format = i3bar

And replace your i3script.sh for the code below. It displays your default language in green (in the example, br) and any other language in red.


i3status --config ~/.i3status.conf | while :
    read line
    LG=$(setxkbmap -query | awk '/layout/{print $2}')
    if [ $LG == "br" ]
        dat="[{ \"full_text\": \"LANG: $LG\", \"color\":\"#009E00\" },"
        dat="[{ \"full_text\": \"LANG: $LG\", \"color\":\"#C60101\" },"
    echo "${line/[/$dat}" || exit 1


  • Originally written by sycamorex
  • Contributions by Anonymous

 howtos:window_managers:keyboard_layout_in_i3 ()