How to setup i3 on Arch Linux

Introduction

i3 is an awesome tiling windows manager for GNU/Linux. ArchLinux is a GNU/Linux distribution that gives you a lot of freedom on how you want your system to behave.

For this freedom you pay the price that you need to configure everything by yourself and this can be a lot of work!

I used i3 and ArchLinux already for a long time but never had everything working 100%. I’m talking about things like a proper keychain and properly working Polkit. Recently I took the time to setup all this stuff properly and I’m now very statisfied with it. I decided to document this setup for my future self.

Also note that I wrote this guide right from my head. There is properly missing a detail.

If you follow this guide and use my dotfiles you could end up with something like that:

Install Arch Linux

The ArchWiki as an awesome install guide that you can follow to setup a base system and there is not much to say about it. If you installed a base system, continue with the next step.

Install i3 and dependencies

After you rebooted into your fresh installed system, install the following packages. Note that you could get along with less packages.

sudo pacman -S \
  lightdm \ # Display manager
  lightdm-gtk-greeter \ # Display manager theme
  xorg \ # XServer with applications
  i3 \ # i3 window manager
  i3blocks \ # Status bar generator for i3
  rofi \ # Application launcher
  dunst \ # Notification manager
  redshift \ # Reduce blue light at night
  pulseaudio \ # Audio
  yad \ # Calendar for status bar
  acpi \ # Check battery status from status bar
  feh \ # Need to set a background image
  dex \ # Starts automatically applications
  noto-fonts noto-fonts-cjk noto-fonts-emoji noto-fonts-extra \ # Fonts
  brightnessctl \ # Needed to make brightness keys work
  scrot \ # For screenshots
  gnome-keyring libsecret \ # Keyring
  polkit-gnome \ # Authentication agent for Polkit
  playerctl \ # Needed to control audio applications via multimedia keys
  alacritty \ # Terminal emulator
  emacs \ # Best text editor in the world ;) (Optional)
  qutebrowser \ # Keyboard focused webbrowser (Optional)
  fish # User friendly shell

If you want to have fancy screen locking install i3lock-fancy-rapid-git from the AUR.

Configure the system

Now the interesting part.

Enable some services

# Start the display manager on boot
sudo systemctl enable lightdm

# Start redshift on boot
sudo systemctl enable redshift-gtk

Using my dotfiles

You can clone my dotfiles from https://github.com/FlexW/dotfiles and then simply change into the cloned repository and execute the update script.

Disclaimer: Inspect the update script before executing it.

Do it manual

If you don’t want to use my dotfiles, then I highlight here the important things that need to be configured.

i3

Create the i3 config with mkdir -p ~/.config/i3 and create the file ~/.config/i3/config with the following content:

# Set Windows key as Mod key
set $mod Mod4

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:Noto 12

# Lock screen
bindsym $mod+Shift+x exec "i3lock-fancy-rapid 5 3"

# Mark windows for quick jumping
# Read 1 character and mark the current window with this character
bindsym $mod+m exec i3-input -F 'mark %s' -l 1 -P 'Mark: '
# Read 1 character and go to the window with the character
bindsym $mod+g exec i3-input -F '[con_mark="%s"] focus' -l 1 -P 'Goto: '

# Use pactl to adjust volume in PulseAudio.
set $refresh_i3status killall -SIGUSR1 i3status
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% && $refresh_i3status
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle && $refresh_i3status
bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status

# Manage brightness
bindsym XF86MonBrightnessDown exec "brightnessctl set 2%-"
bindsym XF86MonBrightnessUp exec "brightnessctl set +2%"

# Manage audio with playerctl
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioPause exec playerctl play-pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous

# Make screenshots with scrot
bindsym Print exec "scrot --quality 100--overwrite -e 'mv $f ~/Pictures/' '%d.%m.%Y_%H:%M:%S_$wx$h_screenshot.png'"
bindsym --release $mod+Print exec "scrot --quality 100 --select --overwrite -e 'mv $f ~/Pictures/' '%d.%m.%Y_%H:%M:%S_$wx$h_screenshot.png'"

# Flash active window
bindsym $mod+n exec --no-startup-id flash_window


# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# Start a terminal
bindsym $mod+Return exec --no-startup-id "alacritty -e fish"

# Kill focused window
bindsym $mod+Shift+q kill

# Start applications and other things
bindsym $mod+d exec --no-startup-id "rofi -show combi"
# bindsym $mod+Shift+d exec --no-startup-id "rofi -show find"

# Change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+odiaeresis focus right

# Alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# Move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+odiaeresis move right

# Alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# Split in horizontal orientation
bindsym $mod+h split h

# Split in vertical orientation
bindsym $mod+v split v

# Enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# Change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# Toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# Change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# Focus the parent container
bindsym $mod+a focus parent

# Focus the child container
bindsym $mod+c focus child

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
set $ws1 "1"
set $ws2 "2"
set $ws3 "3"
set $ws4 "4"
set $ws5 "5"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws10 "10"

# Switch to workspace
bindsym $mod+1 workspace number $ws1
bindsym $mod+2 workspace number $ws2
bindsym $mod+3 workspace number $ws3
bindsym $mod+4 workspace number $ws4
bindsym $mod+5 workspace number $ws5
bindsym $mod+6 workspace number $ws6
bindsym $mod+7 workspace number $ws7
bindsym $mod+8 workspace number $ws8
bindsym $mod+9 workspace number $ws9
bindsym $mod+0 workspace number $ws10

# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number $ws1
bindsym $mod+Shift+2 move container to workspace number $ws2
bindsym $mod+Shift+3 move container to workspace number $ws3
bindsym $mod+Shift+4 move container to workspace number $ws4
bindsym $mod+Shift+5 move container to workspace number $ws5
bindsym $mod+Shift+6 move container to workspace number $ws6
bindsym $mod+Shift+7 move container to workspace number $ws7
bindsym $mod+Shift+8 move container to workspace number $ws8
bindsym $mod+Shift+9 move container to workspace number $ws9
bindsym $mod+Shift+0 move container to workspace number $ws10

# Toggle i3bar
bindsym $mod+Shift+b bar mode toggle

# Resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        # Pressing left will shrink the window’s width.
        # Pressing right will grow the window’s width.
        # Pressing up will shrink the window’s height.
        # Pressing down will grow the window’s height.
        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym odiaeresis resize grow width 10 px or 10 ppt

        # Same bindings, but for the arrow keys
        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Down resize grow height 10 px or 10 ppt
        bindsym Up resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # Back to normal: Enter or Escape or $mod+r
        bindsym Return mode "default"
        bindsym Escape mode "default"
        bindsym $mod+r mode "default"
}

bindsym $mod+r mode "resize"

set $mode_system System: (l) lock, (e) logout, (s) suspend, (r) reboot, (S) shutdown, (R) UEFI
mode "$mode_system" {
    bindsym l exec $lock, mode "default"
    bindsym e exit
    bindsym s exec --no-startup-id systemctl suspend, mode "default"
    bindsym r exec --no-startup-id systemctl reboot, mode "default"
    bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"
    bindsym Shift+r exec --no-startup-id systemctl reboot --firmware-setup, mode "default"

    # return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Shift+e mode "$mode_system"

set $mode_i3 i3: (r) reload, (R) restart, (e) exit
mode "$mode_i3" {
    bindsym r reload
    bindsym Shift+r restart
    bindsym e exit

    # return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Shift+c mode "$mode_i3"

# Manual management of external displays
set $mode_display (1) config 1, (2) config 2, (3) config 3
mode "$mode_display" {
    bindsym 1 exec --no-startup-id ~/.screenlayout/config1.sh
    bindsym 2 exec --no-startup-id ~/.screenlayout/config2.sh
    bindsym 3 exec --no-startup-id ~/.screenlayout/config3.sh

    # back to normal
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Shift+d mode "$mode_display"

# Programs
bindsym $mod+x exec --no-startup-id "emacsclient -c -a emacs"
bindsym $mod+i exec --no-startup-id "qutebrowser"
bindsym XF86Tools exec --no-startup-id "alacritty -e cmus"
bindsym XF86Calculator exec --no-startup-id "alacritty -e calc"

# Start i3bar to display information
bar {
    position bottom
    status_command SCRIPT_DIR=~/.config/i3blocks/scripts i3blocks
    modifier none

    colors {
        background #282A36
        statusline #F8F8F2
        separator  #44475A

        focused_workspace  #44475A #44475A #F8F8F2
        active_workspace   #282A36 #44475A #F8F8F2
        inactive_workspace #282A36 #282A36 #BFBFBF
        urgent_workspace   #FF5555 #FF5555 #F8F8F2
        binding_mode       #FF5555 #FF5555 #F8F8F2
    }
}

# Colors
# class                 border  bground text    indicator child_border
client.focused          #6272A4 #6272A4 #F8F8F2 #6272A4   #6272A4
client.focused_inactive #44475A #44475A #F8F8F2 #44475A   #44475A
client.unfocused        #282A36 #282A36 #BFBFBF #282A36   #282A36
client.urgent           #44475A #FF5555 #F8F8F2 #FF5555   #FF5555
client.placeholder      #282A36 #282A36 #F8F8F2 #282A36   #282A36

client.background       #F8F8F2

# Disable screen saver and sleeping
exec --no-startup-id "xset s off"
exec --no-startup-id "xset -dpms"

# Set background
exec --no-startup-id "feh --bg-fill .background-image"

# Startup programs
exec --no-startup-id "nm-applet"
exec --no-startup-id "dunst"

# Start programs from autostart directory
exec --no-startup-id "dex -ae i3"

To get a wallpaper simply rename your wished wallpaper to ~/.background-image.

Gnome keyring and Gnome polkit

To get gnome-keyring and the Polkit authentication agent to work properly put the following into ~/.profile

# Start the gnome keyring
if [ "$DESKTOP_SESSION" = "i3" ]; then
    # Start Gnome keyring
    export $(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg)

    # Start polkit authentication agent
    /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
fi

Other things

To get a nice status bar have a look at files/config/i3blocks in my dotfiles. For notifications have a look at files/config/dunst

Reboot

Now everything should work as expected.

Reboot your system.

After you log into your i3 session you can open a terminal with Super+Enter. Inspect ~/.config/i3/config to find out other keybindings.