Skip to content

Instantly share code, notes, and snippets.

@OsoianMarcel
Last active July 22, 2024 13:49
Show Gist options
  • Save OsoianMarcel/b3dd8a38eaa2ddc81b2629f4d0921dce to your computer and use it in GitHub Desktop.
Save OsoianMarcel/b3dd8a38eaa2ddc81b2629f4d0921dce to your computer and use it in GitHub Desktop.

Installing i3wm on Ubuntu 22.04 LTS

This guide details my experience of installing i3wm on Ubuntu 22.04 LTS.

Note: My Ubuntu Desktop environment was already set up. All the apps available in the default Ubuntu window manager will also be accessible in i3wm, which is amazing because you can switch back to the default Ubuntu window manager anytime.

Install the i3wm

Open the terminal and run the following command:

sudo apt install i3

Then log out, and during login choose the i3 interface.

During initial setup, I chose the WIN (windows) key as my i3 MOD ($mod) key.

Changing the font size of the i3wm

If the current font size does not suit you, edit the ~/.config/i3/config file and change the font line accordingly.

Vim binding for the i3mw

Make the following changes in the ~/.config/i3/config:

# change focus
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right
# move focused window
bindsym $mod+Shift+h move left 
bindsym $mod+Shift+j move down 
bindsym $mod+Shift+k move up 
bindsym $mod+Shift+l move right 
# split in horizontal orientation
bindsym $mod+Mod1+h split h

# split in vertical orientation
bindsym $mod+Mod1+v split v
# 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 h resize shrink width 10 px or 10 ppt
bindsym j resize grow height 10 px or 10 ppt
bindsym k resize shrink height 10 px or 10 ppt
bindsym l resize grow width 10 px or 10 ppt

Change the i3status bar

Create the i3status config folder:

mkdir ~/.config/i3status 

Copy the default config file to the user's home config folder:

cp /etc/i3status.conf ~/.config/i3status/config 

Now you can make all the changes you want in the ~/.config/i3status/config file.

Here is my config file:

general {
        colors = true
        interval = 5
}

#order += "ipv6"
order += "wireless _first_"
#order += "ethernet _first_"
order += "battery all"
order += "volume master"
order += "disk /"
order += "load"
order += "memory"
order += "tztime local"

wireless _first_ {
        format_up = "W: (%quality at %essid) %ip"
        format_down = "W: down"
}

ethernet _first_ {
        format_up = "E: %ip (%speed)"
        format_down = "E: down"
}

battery all {
        format = "%status %percentage %remaining"
}

disk "/" {
        format = "DISK: %avail"
}

load {
        format = "LOAD: %1min"
}

memory {
        format = "MEM: %used / %available"
        threshold_degraded = "1G"
        format_degraded = "MEMORY < %available"
}

tztime local {
        format = "%Y-%m-%d %H:%M:%S"
}

volume master {
        format = "VOL: %volume"
        format_muted = "VOL: muted (%volume)"
        device = "default"
}

Add a custom keyboard binding for locking screen via i3lock

For calling the i3lock I'm using the combination Mod+Shift+x.

Add the following lines to the end of the ~/.config/i3/config file:

# i3lock binding
bindsym $mod+Shift+x exec i3lock --color 222222

Special fixes for my ThinkPad T14

All the fixes are done in the file .config/i3/config.

Fixing the ThinkPad volume hotkeys

By default, the volume buttons work fine, but the volume up goes above 100%, then the sound goes bad.

Find the lines by searching for XF86Audio, and replace all 4 bindings with those lines:

# adjust volume hotkeys
bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -q -D pulse sset Master 5%+ && $refresh_i3status
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -q -D pulse sset Master 5%- && $refresh_i3status
bindsym XF86AudioMute exec --no-startup-id amixer -q -D pulse sset Master toggle && $refresh_i3status
bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle && $refresh_i3status

Fix the screen brightness hotkeys

Install the light utility for changing the screen brightness from the CLI:

sudo apt install light

Add the current user to the video group, so the light utility can change the brightness without the sudo command:

sudo usermod -aG video $USER

Set the minimum settable brightness value to 1, so the screen never becomes black:

light -N 1

Add the hotkey bindings to the i3 config file:

# screen brightness hotkeys
bindsym XF86MonBrightnessUp exec --no-startup-id light -A 10
bindsym XF86MonBrightnessDown exec --no-startup-id light -U 10

Set the natural scrolling behavior and set the tap to click mode

Create a folder scripts inside the i3 config folder ~/.config/i3.

Add the following two bash files inside:

tap-to-click.bash

#!/bin/bash

# Get id of touchpad and the id of the field corresponding to
# tapping to click
id=`xinput list | grep -i "Touchpad" | cut -d'=' -f2 | cut -d'[' -f1`
tap_to_click_id=`xinput list-props $id | \
                      grep -i "Tapping Enabled (" \
                      | cut -d'(' -f2 | cut -d')' -f1`

# Set the property to true
xinput --set-prop $id $tap_to_click_id 1

inverse-scroll.bash

#!/bin/bash

# Get id of touchpad and the id of the field corresponding to
# natural scrolling
id=`xinput list | grep -i "Touchpad" | cut -d'=' -f2 | cut -d'[' -f1`
natural_scrolling_id=`xinput list-props $id | \
                      grep -i "Natural Scrolling Enabled (" \
                      | cut -d'(' -f2 | cut -d')' -f1`

# Set the property to true
xinput --set-prop $id $natural_scrolling_id 1

Set the execute permission for the bash files:

chmod +x scripts/tap-to-click.bash
chmod +x scripts/inverse-scroll.bash

Add the following lines to the end of the i3 config file:

# enable the touchpad tap-to-click feature
exec ~/.config/i3/scripts/tap-to-click.bash
# setup the natural scroll to inverse scroll
exec ~/.config/i3/scripts/inverse-scroll.bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment