Humble Collection of i3wm Lifehacks: Part I

Lifehack 1: Locking the Screen

This is kinda a nobrainer, but me myself sometimes look for a place, where to
copy some of the syntax (I’m lazy and don’t always keep that in my head), so
let’s start with this one. i3wm ships with beautiful and robust screen locker
i3lock, which can be launched like this:

i3lock -c 000000

It will lock the screen with black overlay. The problem is, that you wouldn’t
be typing this command every time you want to lock the screen. We need to add a
shortcut to i3 config file:

bindsym $mod+Shift+Tab exec"i3lock -c 000000"

Now when we press the combination of mod-button (Win in my case) and
Shift+Tab - our screen gets locked.

Lifehack 2: Activating/Disactivating the Second Screen

If you use i3wm on daily basis, you probably know, that the second screen is
not enabled automatically. You should manage displays manually with xrandr
command. If we run this command without attributes, we’re gonna get something
like this:

On some rare occasion writing something like this would not be a problem:

xrandr --output VGA1 --right-of LVDS1 --auto

Well, I know you’re probably well aware of howxrandrworks. Just in case.

It may get pretty redundant if you use second screen on daily basis and
regularly unplug it from your laptop. The best way to go would be to add script
shortcut to your /usr/bin/ or /bin/ directory. Run the following lines:

We can use screenswitch command which doesn’t make it much easier. What would
certainly help us is a key shortcut, so let’s add a line similar to one in the
previous hack to our i3 configuration:

bindsym XF86Display exec"screenswitch"

Now when you press on your special key combo (Fn+F7 on my ThinkPad), you
enable/disable the second screen. Try some other key combination if you have no
special display button. Of course the script itself is pretty basic and it
would work only if your screen works well in auto and you use the same second
screen daily. However, there are more complex scripts available all over the
web (example).

Lifehack 3: Locking the Screen on Wake

If you use pm-utils with your i3wm setup, you’ve probably noticed that the
screen is not locked, when the laptop is awakened after suspend or hibernate.
It’s very insecure. Let’s try to fix it. Create file
cat /etc/pm/sleep.d/91blocker and add the following lines to it:

Don’t forget to change youruser to your username. Now let’s make sure we have
all the right permissions:

chmod 755 /etc/pm/sleep.d/91blocker

Now, if we run pm-suspend or pm-hibernate our screen is going to be locked
on wake. This script has one shortcoming though: it doesn’t lock the screen
instantly, so you may see stuff for a couple of seconds before it gets locked.
If it is not a critical issue to you, feel free to use it, othrewise you may
need to work on it or find a different solution altogether. If you have any
ideas how to improve it, let me know.