hyprlock Documentation

repository·main·Indexed 23 days ago

https://github.com/hyprwm/hyprlock

A lightweight, GPU-accelerated screen locking utility for the Hyprland ecosystem. It leverages the ext-session-lock protocol and supports multi-threaded resource acquisition, fractional-scale, and native fingerprint authentication via libfprint. The utility features highly customizable widgets including Background, Image, Shape, and Password Input Field, supporting visual effects like gradient borders, blur, and animations.

Tokens
2.4K
Snippets
3
Records
15
Agent score
82%

What's inside hyprlock

  1. Overview of hyprlock features

    main

    hyprlock is a multi-threaded and GPU-accelerated screen locking utility for Hyprland. Key features include:

    • Uses the ext-session-lock protocol.
    • Support for fractional-scale.
    • Fully GPU accelerated.
    • Multi-threaded resource acquisition.
    • Blurred screenshot as the background.
    • Native fingerprint support (via libfprint's dbus interface).
    • Hyprland visual effects: gradient borders, blur, animations, shadows, etc.
  2. Build hyprlock from source

    main

    To build hyprlock from source, use cmake to configure the build directory and then compile the target. Ensure you have all necessary dependencies installed first.

    cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build
    cmake --build ./build --config Release --target hyprlock -j`nproc 2>/dev/null || getconf _NPROCESSORS_CONF`
    
    # To install:
    sudo cmake --install build
  3. Install hyprlock on Arch Linux

    main

    You can install hyprlock on Arch Linux using either the pre-compiled binary or by compiling the latest source from the AUR.

    pacman -S hyprlock # binary x86 tagged release
    # or
    yay -S hyprlock-git # compiles from latest source
  4. Configure the Image widget

    main

    The CImage widget is used to display images on the lockscreen. While the implementation is internal C++, the widget is configured via a property map (std::unordered_map<std::string, std::any>). Based on the class members, the following properties are available for configuration:

    • path: The file path to the image.
    • size: The size of the image.
    • rounding: The corner rounding value.
    • border: The border thickness.
    • angle: The rotation angle.
    • halign: Horizontal alignment (e.g., left, center, right).
    • valign: Vertical alignment (e.g., top, center, bottom).
    • pos: The position of the image.
    • color: Gradient or color data for the image.
    • reloadTime: Interval in seconds to reload the image.
    • reloadCommand: A shell command to run to trigger an image reload.
    • onclickCommand: A shell command to execute when the image is clicked.
    • stringPort: A string port used for dynamic updates.
  5. Configure the Background widget

    main

    The CBackground widget is used to render background images or screenshots in hyprlock. While the implementation is internal, the widget is configured via a properties map (std::unordered_map<std::string, std::any>) during the configure phase.

    Based on the class members, the following parameters are relevant for background configuration:

    • path: A string representing the file path to the background image.
    • isScreenshot: A boolean indicating if the background should be a screenshot.
    • blurSize: Integer defining the blur intensity (default: 10).
    • blurPasses: Integer defining the number of blur passes (default: 3).
    • noise: Float for adding noise to the background (default: 0.0117).
    • contrast: Float for adjusting contrast (default: 0.8916).
    • brightness: Float for adjusting brightness (default: 0.8172).
    • vibrancy: Float for adjusting vibrancy (default: 0.1696).
    • vibrancy_darkness: Float for adjusting vibrancy darkness (default: 0.0).
    • reloadTime: Integer specifying how often to check for file changes (default: -1).
    • reloadCommand: A string command to execute when reloading the background.
    • transform: An enum/type defining the transformation applied to the asset.
  6. Configure gradients with colors and angles

    main

    Gradients in hyprlock are defined by a collection of colors and a rotation angle.

    • Colors: A list of CHyprColor values.
    • Angle: The rotation of the gradient, expressed in degrees (deg) in the configuration string.

    When serialized to a string for configuration purposes, the format follows: [hex_color_1] [hex_color_2] ... [angle]deg.

  7. Configure layout values with absolute or relative units

    main

    In hyprlock configuration, layout values (such as positions or sizes) can be defined using either absolute pixels (px) or relative percentages (%).

    • Absolute units: Represented as raw numbers (e.g., 100).
    • Relative units: Represented using the % suffix (e.g., 50%).

    When using relative units, the value is calculated as a percentage of the viewport dimensions.

  8. Configure the Password Input Field widget

    main

    The CPasswordInputField widget is used to handle password entry during the lock screen. It can be configured via a property map. Key configuration parameters include:

    Layout and Text

    • halign: Horizontal alignment.
    • valign: Vertical alignment.
    • fontFamily: The font family to use for the input.
    • configPlaceholderText: The text displayed when the input is empty.
    • configCheckText: Text displayed upon successful validation.
    • configFailText: Text displayed upon failed validation.

    Visual Styling

    • outThick: Thickness of the outer border.
    • rounding: Corner rounding value.
    • colorConfig: A complex structure for defining colors and gradients:
      • outer: Gradient for the outer border.
      • inner: Color for the inner area.
      • font: Color for the text.
      • fail: Gradient for the failure state.
      • check: Gradient for the success state.
      • caps: Gradient for caps lock state.
      • num: Gradient for numeric state.
      • both: Gradient for both caps and numeric states.
      • hiddenBase: Base color when the input is in hidden mode.
      • invertNum: Boolean to invert numeric state colors.
      • swapFont: Boolean to swap font colors.

    Behavior and Timing

    • configFailTimeoutMs: Duration in milliseconds to show the failure state (defaults to 2000).
    • fadeOnEmpty: Whether to fade the widget when empty.
    • fadeTimeoutMs: Timeout for the fade effect.
    • dots: Configuration for the password dots (character indicators):
      • center: Whether dots are centered.
      • size: Size of the dots.
      • spacing: Spacing between dots.
      • rounding: Rounding of the dots.
  9. Configure the Shape widget

    main

    The CShape widget is used to render geometric shapes in hyprlock. It can be configured via the configuration file using properties that control its appearance, position, and behavior.

    Key properties include:

    • Geometry: size (Vector2D), pos (Vector2D), rounding (int), border (double), and angle (double).
    • Styling: color (CHyprColor), borderGrad (gradient data), and xray (bool).
    • Alignment: halign and valign (strings) to control positioning within the viewport.
    • Interaction: onclickCommand (string) allows executing a shell command when the shape is clicked.
    • Shadows: Supports shadow effects via the CShadowable interface.
  10. Dependencies for building hyprlock

    main

    The following dependencies are required to build hyprlock. Note that some distributions may require the development versions of these packages (e.g., suffixed with -devel or -dev).

    • cairo
    • hyprgraphics
    • hyprlang
    • hyprutils
    • hyprwayland-scanner
    • mesa (requires libgbm, libdrm and the opengl runtime)
    • pam
    • pango
    • sdbus-cpp (>= 2.0.0)
    • wayland-client
    • wayland-protocols
    • xkbcommon
  11. Use the CAuth class to manage authentication

    main

    The CAuth class is the primary interface for managing authentication processes in hyprlock. It handles multiple authentication implementations (like PAM and Fingerprint) and manages the state of failed attempts and prompts.

    Key capabilities:

    • Starting/Stopping: Use start() to begin the auth process and terminate() to end it.
    • Submitting Input: Use submitInput(const std::string& input) to pass credentials (like passwords) to the active authentication implementation.
    • Status Checking: checkWaiting() returns true if an authentication implementation is currently processing an request.
    • Error Handling: Retrieve error messages via getFailText(eAuthImplementations implType) or getCurrentFailText(). You can also track the number of failed attempts using getFailedAttempts().
    • Prompts: Retrieve implementation-specific prompts using getPrompt(eAuthImplementations implType).
    • Unlock Queue: enqueueUnlock() can be used to queue an unlock event.
  12. Implement a custom authentication method with IAuthImplementation

    main

    To extend hyprlock with a new authentication method, implement the IAuthImplementation interface. This interface defines the lifecycle and interaction requirements for an authentication provider.

    Required methods to implement:

    • getImplType(): Returns the eAuthImplementations type associated with this implementation.
    • init(): Initializes the authentication provider.
    • handleInput(const std::string& input): Processes the provided input (e.g., a password string).
    • checkWaiting(): Returns true if the provider is currently busy/waiting for a response.
    • getLastFailText(): Returns an optional error message string if the last attempt failed.
    • getLastPrompt(): Returns an optional prompt string provided by the implementation.
    • terminate(): Cleans up the implementation resources.