Skip to content

Instantly share code, notes, and snippets.

@rometsch
Last active October 6, 2024 08:00
Show Gist options
  • Save rometsch/6b35524bcc123deb7cd30b293f2088d8 to your computer and use it in GitHub Desktop.
Save rometsch/6b35524bcc123deb7cd30b293f2088d8 to your computer and use it in GitHub Desktop.
Configure lockscreen for i3 window manager.

The i3-wm does not come with a keybinding to lock the screen or a preconfigured auto lockscreen. This gist describes how to setup both using i3lock and xautolock. i3lock is a minimalistic lockscreen and xautolock monitors mouse and keyboard activities to automatically lock the screen after a certain time of beiing inactive.

First get the tools if neccessary. E.g. sudo apt install i3lock xautolock.

To setup the keybinding Ctrl+Alt+l (last one is a lowercase L) to lock the screen append the following lines to the i3 configuration file located at ~/.config/i3/config.

# keybinding to lock screen
bindsym Control+Mod1+l exec "i3lock -c 000000"

-c 000000 makes the screen turn black instead of the default white after the screen is locked.

Then add a line to the same config file to run xautolock at startup.

# auto lock the screen
exec "xautolock -detectsleep -time 3 -locker \"i3lock -c 000000\""

-detectsleep locks the screen properly when the computer goes to sleep, -time 3 sets the time after which to lock to 3 minutes and -locker "..." sets up i3lock as the command to lock.

Finally reload the config file via $mod+Shift+r.

@koowyzrk
Copy link

The Image in the lockscreen did not use the right resolution, I want to set it 1920x1080 how to do that??

You can use betterlockscreen, it uses ImageMagick for manipulate the images.

https://github.com/betterlockscreen/betterlockscreen - you need to install few more dependencies and imagemagick to get this work well
https://imagemagick.org/

So the code will look like this

betterlockscreen

bindsym $mod+i exec betterlockscreen -l dim

Auto Lock

exec "xautolock -detectsleep -time 1 -locker "betterlockscreen -l dim""

@arsxhy
Copy link

arsxhy commented Jul 30, 2023

Ohh, Thank You

@TheCheddarCheese
Copy link

the keybind worked for me, auto detection didn't. it still shows a white screen

@TheCheddarCheese
Copy link

the keybind worked for me, auto detection didn't. it still shows a white screen

okay nevermind reboot did it

@chiragdhunna
Copy link

chiragdhunna commented Apr 14, 2024

is it possbile to change the white screen with my own

Setting a png image is supported by i3lock according to their github repository. I don't have i3lock installed anymore, so I can't check the options with -help, but at in the source code it looks like i3lock -i yourimage.png is the right syntax.

So just change exec "xautolock -detectsleep -time 3 -locker \"i3lock -c 000000\"" to exec "xautolock -detectsleep -time 3 -locker \"i3lock -i yourimage.png\""

I did following to my kali config, and it is not showing any image on the lockscreen. Any help?

# auto lock the screen
exec "xautolock -detectsleep -time 3 -locker \"i3lock -i /home/chiggy/Downloads/luca-bravo-TaCk3NspYe0-unsplash.png\""

All I see is a blank screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment