Tips and Tricks for i3

These are a few tips and tricks I have come up with for i3

Here is a cheat sheet for the different key combinations which comes in handy when learning i3
Here is the cheat sheet
To set it as your background:
copy the desired background image file to ~/Pictures
Ensure feh is installed, if not
# pacman -S feh

Then vi ~/.config/i3/config and add the following two lines
# Set background
exec_always --no-startup-id feh - -bg-scale /home/$USER/Pictures/CheatSheet.png

Then you have to reboot for it to take affect.
Now if you’re doing something and just can’t remember the key combination, press $mod+ any unused workspace, and there is our cheat sheet. Then switch back to the workspace you were in.


i3 doesn’t have any default key combinations that start with $mod+Ctrl. So we have a blank canvas here. I feel any modifications made by the user should be as a $mod+Ctrl+something combination just to keep things organized. So here goes:

Instead of Mod+Shift+e then get the nag bar and click on “Yes, exit i3” to logout, and these lines to ~/.config/i3/config for an instant log-out

# Instant log out
bindsym $mod+Crtl+l exec i3-msg exit

That’s $mod+Crtl+lower case letter L I chose the letter L for logout. Choose what you want.


dmenu ($mod+d) output is rather cluttered. i3-dmenu-desktop only lists applications that have a corresponding .desktop file. These are generally the most used apps. Add the following to ~.config/i3/conf

# enables i3-dmenu-desktop which only list apps with a .desktop file
bindsym $mod+Ctrl+d exec i3-dmenu-desktop

How to open a application (or more) in a specified window.
From the i3 guide https://i3wm.org/docs/layout-saving.html
Quote
Layout saving/restoring allows you to load a JSON layout file so that you can have a base layout to start working with after powering on your computer. Dynamic use-cases also come to mind: if you frequently need a grid layout of terminals with ping/traceroute commands to diagnose network issues, you can easily automate opening these windows in just the right layout.

i3-save-tree is a tool to save the layout. It will print a JSON representation of i3’s internal layout data structures to stdout. Typically, you may want to take a quick look at the output, then save it to a file and tweak it a little bit:
End quote

Just a reminder, json syntax requires a comma at the end of each statement, and anything after // is a comment.

To do this:
install the anyevent module
# pacman -S perl-anyevent-i3

First, launch the desired app (or apps) in the desired workspace. I’ll use FirefoxNightly in workspace 8 as an example. Once FirefoxNightly is opened in workspace 8

$ i3-save-tree - -workspace 8 > ~/.config/i3/workspace_8.json

This will give the following pseudo json file.
// vim:ts=4:sw=4:et
{
“border”: “normal”,
“current_border_width”: 2,
“floating”: “auto_off”,
“geometry”: {
“height”: 691,
“width”: 1224,
“x”: 0,
“y”: 0
},
“name”: “i3: Layout saving in i3 - Nightly”,
“percent”: 1,
“swallows”: [
{
// “class”: “^Nightly$”,
// “instance”: “^Navigator$”,
// “title”: “^i3\:\ Layout\ saving\ in\ i3\ \-\ Nightly$”,
// “window_role”: “^browser$”
}
],
“type”: “con”
}

We have to modify it into a syntax correct json file.
In your favorite text editor
delete line 1 // vim:ts=4:sw=4:et
delete the line “name”: “i3: Layout saving in i3 – Nightly”,
delete the line // “title”: “^i3\:\ Layout\ saving\ in\ i3\ \-\ Nightly$”,
remove the comment ( // ) from
“class”: “^Nightly$”,
“instance”: “^Navigator$”,
“window_role”: “^browser$”

You should end up with this

{
“border”: “normal”,
“current_border_width”: 2,
“floating”: “auto_off”,
“geometry”: {
“height”: 691,
“width”: 1224,
“x”: 0,
“y”: 0
},
“percent”: 1,
“swallows”: [
{
“class”: “^Nightly$”,
“instance”: “^Navigator$”,
“window_role”: “^browser$”
}
],
“type”: “con”
}

Next create a script in ~/.config/i3

$ vi start_w8.sh

#!  /bin/bash
i3-msg -q "workspace 8; append_layout ~/.config/i3/workspace_8.json"

# and finally we fill the containers with the programs they had
(flatpak run org.mozilla.FirefoxNightly &)

save the start_w8.sh file and make it executable.

The above start_w8.sh file shows how to start FirefoxNightly, which is a flatpak.
To start regular Firefox that’s from the Arch repository, change to
(firefox &)
Use whatever you type in to run it from the terminal plus & to run it in the background

Now, edit the ~/.config/i3/config file, and add the following:

# bind App to a specific workspace
bindsym $mod+Ctrl+f  exec ~/.config/i3/start_w8.sh

and Firefox will start in workspace 8. I chose $mod+Ctrl+f so I can remember f for Firefox, you can choose whatever key you want.

I have also done $mod+Ctrl+v for VLC in workspace 7
and $mod+Ctrl+c for Visual Studio Code in workspace 9
and the json files were fairly similar, I had to play around with one of them but a little trial and error got it.

Enjoy playing with i3

7 Likes

Certain programs cannot be set to open to a specific workspace (they ignore the command). Instead, use the “catch and move” command for those.
I had to do that for Spotify when I ran i3, for example.

Aka use the “for_window” rule instead of the “assign” rule.

Install nitrogen $sudo pacman -S nitrogen

Use nitrogen to set a background image and in your i3 conf add the following line

exec --no-startup-id nitrogen --restore

3 Likes

awesome wm inspired auto layout script for i3wm

2 Likes

:pray: for share . That show wonder of linux ( you build what fit you ) i more simple and like control how + where window open ( that me ) That why i stay with i3 or sway :blush: simple ,easy + get job done . in past i use near all type WM + enjoy all ( there no best ) now day i just want get up + run fast + minimal setup.

EDit … @Pudge dark horse !! i shock see i3 post by you + long ago

2 Likes

What is the different between awesome-auto-layout and autotiling.

I am used to autotiling. Using xfce at the moment. Planning to configure i3 again.
Should i switch to awesome-auto-layout …

like awesomewm

awesome-auto-layout

Like bspwm

autotiling

ps: i use alternating_layouts instead of autotiling

1 Like

if you like awesome layout then awesome-auto-layout

if you like bspwm layout then autotiling

but i like awesome so i choice awesome-auto-layout it is very cool :slightly_smiling_face:

1 Like

It looks like I need to test them all for a while.
Although autotiling seems pretty ok for me.

:penguin:

1 Like

Tiny script to show your i3wm keybindings with dmenu

#!/bin/bash
I3_CONFIG=$HOME/.config/i3/config
mod_key=$(sed -nre 's/^set \$mod (.*)/\1/p' ${I3_CONFIG})
grep "^bindsym" ${I3_CONFIG} \
    | sed "s/-\(-\w\+\)\+//g;s/\$mod/${mod_key}/g;s/Mod1/Alt/g;s/exec //;s/bindsym //;s/^\s\+//;s/^\([^ ]\+\) \(.\+\)$/\2: \1/;s/^\s\+//" \
    | tr -s ' ' \
    | dmenu
1 Like

Tiny script to show your i3wm keybindings with rofi

I3_CONFIG=$HOME/.config/i3/config
mod_key=$(sed -nre 's/^set \$mod (.*)/\1/p' ${I3_CONFIG})
grep "^bindsym" ${I3_CONFIG} \
    | sed "s/-\(-\w\+\)\+//g;s/\$mod/${mod_key}/g;s/Mod1/Alt/g;s/exec //;s/bindsym //;s/^\s\+//;s/^\([^ ]\+\) \(.\+\)$/\2: \1/;s/^\s\+//" \
    | tr -s ' ' \
    | rofi -dmenu -i -markup-rows -no-show-icons -width 1000 -lines 15 -yoffset 40
1 Like

or mod +f1 ( think Endeavouros still use it ) again you make your system simple or complicated for your needs :+1: that the wonder of linux :vulcan_salute:

3 Likes

Still there.

2 Likes

are Endeavouros using yad to this???

1 Like

If you mean the mod + F1 thing it’s in the config to exec a xed file.

1 Like

not everyone uses Endeavouros
therefore I would put it on for those who can use it
and I’m not using Endeavouros right now
that’s the beauty of linux you can do almost anything you want

2 Likes

yes now i remember with xed
but I prefer with rofi or dmenu
since I do not have xed installed

1 Like

I no using endeavour i3 for main just my own i3 arch but do same way :+1: no right or wrong way in linux

2 Likes

like this

3 Likes

perfect ! both way work ( if you need ) choice is good :vulcan_salute:

1 Like