hypridle

repository·main·Indexed 20 days ago

https://github.com/hyprwm/hypridle

An idle daemon for Hyprland that manages idle timeouts and session state changes, such as locking or sleeping, based on the ext-idle-notify-v1 Wayland protocol. It supports custom configuration via hypridle.conf using hyprlang syntax, allowing for general session commands and specific listener blocks to trigger actions based on idle time.

Tokens
1.9K
Snippets
7
Records
8
Agent score
72%

What's inside hypridle

  1. Build and Install hypridle

    main

    To build hypridle from source, use cmake. Ensure you have the required dependencies installed (wayland, wayland-protocols, hyprland-protocols, hyprlang >= 0.4.0, sdbus-c++, and hyprwayland-scanner).

    Build Steps

    1. Configure the build directory with Release type and install prefix /usr.
    2. Compile using all available CPU cores.
    3. Install the resulting binaries.

    Installation Commands

    cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
    cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
    sudo cmake --install build
  2. Launch hypridle automatically

    main

    Hypridle should be launched after login. You can automate this via your compositor or systemd.

    Via Hyprland

    Add the following line to your hyprland.conf:

    exec-once = hypridle

    Via systemd

    Enable and start the user service:

    systemctl --user enable --now hypridle.service
  3. Configure hypridle via hypridle.conf

    main

    Configuration is managed through a file located at ~/.config/hypr/hypridle.conf using standard hyprlang syntax. The configuration is divided into general settings and multiple listener blocks.

    General Settings

    The general block defines commands for session state changes and how to handle inhibitors:

    • lock_cmd: Command to run for locking the session (e.g., loginctl lock-session).
    • unlock_cmd: Command to run when the session is unlocked.
    • before_sleep_cmd: Command to run before the system enters sleep.
    • after_sleep_cmd: Command to run after the system wakes from sleep.
    • ignore_dbus_inhibit: If true, hypridle will ignore idle-inhibit requests sent via DBus (e.g., from Firefox or Steam).
    • ignore_systemd_inhibit: If true, hypridle will ignore systemd-inhibit --what=idle inhibitors.

    Listeners

    You can define multiple listener blocks to trigger actions based on idle time. If on-timeout or on-resume are omitted or empty, those specific events are ignored.

    • timeout: Time in seconds before the idle event triggers.
    • on-timeout: Command to run when the timeout is reached.
    • on-resume: Command to run when activity is detected after a timeout has fired.
    • condition_cmd: An optional command to run before on-timeout. If it exits with 0, the timeout proceeds; if non-zero, the timeout is deferred.
    • condition_retry: The interval in seconds to retry the condition_cmd when it defers (defaults to 0, meaning no retry).
    general {
        lock_cmd = notify-send "lock!"
        unlock_cmd = notify-send "unlock!"
        before_sleep_cmd = notify-send "Zzz"
        after_sleep_cmd = notify-send "Awake!"
        ignore_dbus_inhibit = false
        ignore_systemd_inhibit = false
    }
    
    listener {
        timeout = 500
        on-timeout = notify-send "You are idle!"
        on-resume = notify-send "Welcome back!"
        condition_cmd = 
        condition_retry = 0
    }
  4. Configure hypridle timeout rules

    main

    hypridle uses timeout rules to define actions that occur when the system is idle. Each rule consists of a timeout duration and associated commands or behaviors.

    Key fields for a timeout rule include:

    • timeout: The idle duration in seconds.
    • onTimeout: The command to execute when the timeout is reached.
    • onResume: The command to execute when activity is detected after a timeout.
    • ignoreInhibit: A boolean flag to determine if the rule should ignore inhibition signals.
    • conditionCmd: An optional command used to check a specific condition before executing the rule.
    • conditionRetry: The number of times to retry the conditionCmd if it fails.
    // Conceptual representation of a timeout rule structure
    struct STimeoutRule {
        uint64_t    timeout        = 0;
        std::string onTimeout      = "";
        std::string onResume       = "";
        bool        ignoreInhibit  = false;
        std::string conditionCmd   = "";
        int64_t     conditionRetry = 0;
    };
  5. Use hypridle CLI flags

    main

    When running hypridle manually, you can use the following flags to specify configuration or change verbosity:

    • -c <config_path>, --config <config_path>: Specify a custom configuration path. If not provided, it defaults to ${XDG_CONFIG_HOME}/hypr/hypridle.conf.
    • -q, --quiet: Run in quiet mode.
    • -v, --verbose: Enable verbose output.
  6. Retrieve configuration values using getValue()

    main

    To access specific configuration settings from the hypridle.conf file, use the getValue<T>(name) template method. This method returns a Hyprlang::CSimpleConfigValue<T> object for the specified configuration key. You can use this to retrieve typed values (such as strings, integers, or booleans) directly from the parsed configuration.

    // Example of retrieving a configuration value
    auto myValue = g_pConfigManager->getValue<std::string>("some_config_key");
  7. Reference: hypridle CLI flags

    main

    The following flags are available for the hypridle command line interface:

    FlagLong FormDescription
    -v--verboseEnable verbose logging
    -q--quietSuppress all output except errors
    -V--versionShow version information
    -c--config <path>Specify a custom config file path
    -h--helpShow this help message
    Usage: hypridle [options]
    Options:
      -v, --verbose       Enable verbose logging
      -q, --quiet         Suppress all output except errors
      -V, --version       Show version information
      -c, --config <path> Specify a custom config file path
      -h, --help          Show this help message
  8. Run hypridle with CLI options

    main

    The hypridle executable can be run with several flags to control logging verbosity, display version information, or specify a custom configuration file path. If no configuration file is specified, hypridle searches standard locations including $XDG_CONFIG_HOME/hypr/, ~/.config/hypr/, [XDG_CONFIG_DIRS]/hypr/, and /etc/xdg/hypr/.

    # Show version
    hypridle --version
    
    # Use a custom configuration file
    hypridle --config /path/to/your/hypridle.conf
    
    # Enable verbose logging
    hypridle --verbose
    
    # Suppress output except errors
    hypridle --quiet