Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Forked from rometsch/i3autolock.md
Created June 24, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethagnawl/f8d0aa0bbcefe0258f2e7c0db15923fb to your computer and use it in GitHub Desktop.
Save ethagnawl/f8d0aa0bbcefe0258f2e7c0db15923fb 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.

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