{ lib, config, pkgs, ... }: with lib; let cfg = config.modules.desktop.hypridle; in { options.modules.desktop.hypridle = { enable = mkEnableOption "Enable hypridle, a wayland idle daemon"; package = mkOption { type = types.package; default = pkgs.hypridle; example = "pkgs.hypridle"; }; }; config = mkIf cfg.enable { hm.home.packages = [ cfg.package ]; hm.services.hypridle = { enable = true; package = cfg.package; settings = { general = { lock_cmd = "${pkgs.procps}/bin/pidof hyprlock || ${lib.getExe config.modules.desktop.hyprlock.package}"; unlock_cmd = "${pkgs.procps}/bin/pkill -USR1 hyprlock"; before_sleep_cmd = "${pkgs.systemd}/bin/loginctl lock-session"; }; listener = [ { timeout = if config.modules.core.laptop then 60 * 2 # 2 min else 60 * 35; # 35 min on-timeout = "${pkgs.systemd}/bin/loginctl lock-session"; # lock computer } ] ++ optionals (config.modules.core.laptop) [ { timeout = 60; # 1 min on-timeout = "${lib.getExe pkgs.brightnessctl} -c backlight -s set 20"; # dim screen, save brightness state on-resume = "${lib.getExe pkgs.brightnessctl} -c backlight -r"; # restore previous screen brightness state } { timeout = 60; # 1 min on-timeout = "${lib.getExe pkgs.brightnessctl} -d '*:kbd_backlight' -s set 0"; # turn off keyboard backlight, save state on-resume = "${lib.getExe pkgs.brightnessctl} -d '*:kbd_backlight' -r"; # restore previous keyboard backlight state } { timeout = 60 * 15; # 15 min on-timeout = "${pkgs.systemd}/bin/systemctl suspend"; # sleep/suspend } ] ++ optional config.modules.desktop.niri.enable { timeout = if config.modules.core.laptop then 90 # 1.5 min else 30 * 60; # 30 min on-timeout = "niri msg action power-off-monitors"; }; }; }; }; }