Overview of swaylock
masterext-session-lock-v1 Wayland protocol.repository·master·Indexed 22 days ago
https://github.com/swaywm/swaylockA screen locking utility for Wayland compositors that implement the ext-session-lock-v1 protocol. It features customizable appearance via CLI flags or configuration files, including support for background images, colors, and indicator styling.
ext-session-lock-v1 Wayland protocol.swaylock using your distribution's package manager.To build swaylock from source, ensure you have the necessary dependencies installed and then use meson and ninja to build and install the binary.
meson (Compile-time)waylandwayland-protocols (Compile-time)libxkbcommoncairogdk-pixbuf2 (Optional: required for background images other than PNG)pam (Optional)scdoc (Optional: for man pages) (Compile-time)git (Compile-time)meson build
ninja -C build
sudo ninja -C build installOn systems without PAM, swaylock uses shadow.h. If your system stores user passwords in /etc/shadow (and does not use a tcb-like setup via musl or glibc+[tcb]), you must set specific permissions for swaylock to function correctly.
Set the binary to be SUID so it can read /etc/shadow:
sudo chmod a+s /usr/local/bin/swaylockIf /etc/shadow is owned by the shadow group, you can use SGID instead:
sudo chgrp shadow /usr/local/bin/swaylock
sudo chmod g+s /usr/local/bin/swaylockNote: swaylock will drop root permissions shortly after startup.
swaylock searches for configuration files in the following order:
-C, --config <config_file> flag.$HOME/.swaylock/config (with shell expansion applied).$XDG_CONFIG_HOME/swaylock/config (or $HOME/.config/swaylock/config if $XDG_CONFIG_HOME is not set).SYSCONFDIR/swaylock/config.Config files use a one-option-per-line format where each line is treated as a command-line flag (e.g., a line containing color ff0000 is interpreted as --color ff0000).
The following flags are available for swaylock:
| Flag | Long Flag | Description |
|---|---|---|
-C | --config <file> | Path to the config file |
-c | --color <color> | Turn the screen into the given color instead of light gray |
-d | --debug | Enable debugging output |
-e | --ignore-empty-password | When an empty password is provided, do not validate it |
-F | --show-failed-attempts | Show current count of failed authentication attempts |
-f | --daemonize | Detach from the controlling terminal after locking |
-R | --ready-fd <fd> | File descriptor to send readiness notifications to |
-h | --help | Show help message and quit |
-i | --image [[<output>]:]<path> | Display the given image, optionally only on the given output |
-k | --show-keyboard-layout | Display the current xkb layout while typing |
-K | --hide-keyboard-layout | Hide the current xkb layout while typing |
-L | --disable-caps-lock-text | Disable the Caps Lock text |
-l | --indicator-caps-lock | Show the current Caps Lock state also on the indicator |
-n | --line-uses-inside | Use the inside color for the line between the inside and ring |
-r | --line-uses-ring | Use the ring color for the line between the inside and ring |
-s | --scaling <mode> | Image scaling mode: stretch, fill, fit, center, tile, solid_color |
-t | --tiling | Same as --scaling=tile |
-u | --no-unlock-indicator | Disable the unlock indicator |
-v | --version | Show the version number and quit |
--bs-hl-color <color> | Sets the color of backspace highlight segments | |
--caps-lock-bs-hl-color <color> | Sets the color of backspace highlight segments when Caps Lock is active | |
--caps-lock-key-hl-color <color> | Sets the color of the key press highlight segments when Caps Lock is active | |
--font <font> | Sets the font of the text | |
--font-size <size> | Sets a fixed font size for the indicator text | |
--indicator-idle-visible | Sets the indicator to show even if idle | |
--indicator-radius <radius> | Sets the indicator radius | |
--indicator-thickness <thick> | Sets the indicator thickness | |
--indicator-x-position <x> | Sets the horizontal position of the indicator | |
--indicator-y-position <y> | Sets the vertical position of the indicator | |
--inside-color <color> | Sets the color of the inside of the indicator | |
--inside-clear-color <color> | Sets the color of the inside of the indicator when cleared | |
--inside-caps-lock-color <color> | Sets the color of the inside of the indicator when Caps Lock is active | |
--inside-ver-color <color> | Sets the color of the inside of the indicator when verifying | |
--inside-wrong-color <color> | Sets the color of the inside of the indicator when invalid | |
--key-hl-color <color> | Sets the color of the key press highlight segments | |
--layout-bg-color <color> | Sets the background color of the box containing the layout text | |
--layout-border-color <color> | Sets the color of the border of the box containing the layout text | |
--layout-text-color <color> | Sets the color of the layout text | |
--line-color <color> | Sets the color of the line between the inside and ring | |
--line-clear-color <color> | Sets the color of the line between the inside and ring when cleared | |
--line-caps-lock-color <color> | Sets the color of the line between the inside and ring when Caps Lock is active | |
--line-ver-color <color> | Sets the color of the line between the inside and ring when verifying | |
--line-wrong-color <color> | Sets the color of the line between the inside and ring when invalid | |
--ring-color <color> | Sets the color of the ring of the indicator | |
--ring-clear-color <color> | Sets the color of the ring of the indicator when cleared | |
--ring-caps-lock-color <color> | Sets the color of the ring of the indicator when Caps Lock is active | |
--ring-ver-color <color> | Sets the color of the ring of the indicator when verifying | |
--ring-wrong-color <color> | Sets the color of the ring of the indicator when invalid | |
--separator-color <color> | Sets the color of the lines that separate highlight segments | |
--text-color <color> | Sets the color of the text | |
--text-clear-color <color> | Sets the color of the text when cleared | |
--text-caps-lock-color <color> | Sets the color of the text when Caps Lock is active | |
--text-ver-color <color> | Sets the color of the text when verifying | |
--text-wrong-color <color> | Sets the color of the text when invalid |
swaylock can be configured via command-line arguments to customize the appearance and behavior of the lockscreen. Options include setting background colors, images, fonts, indicator dimensions, and visibility of UI elements like the keyboard layout or failed attempt counts.
All color options follow the <rrggbb[aa]> format (e.g., FF0000 for red, FF0000AA for semi-transparent red).
# Example: Set a solid blue background and a specific image for an output
swaylock -c 0000FF -i output_name:/path/to/image.png
# Example: Customize indicator appearance
swaylock --indicator-radius 80 --indicator-thickness 15 --font "Fira Code"