{ pkgs, config, lib, osConfig, ... }: let cfg = config.my.graphical.wayland.swayidle; in { options.my.graphical.wayland.swayidle = { enable = lib.mkEnableOption null // { default = osConfig.my.laptop.enable; }; lockCommand = lib.mkOption { type = lib.types.str; }; }; config = lib.mkIf cfg.enable { services.swayidle = { enable = true; systemdTarget = "hyprland-session.target"; timeouts = let inherit (pkgs) brightnessctl acpi gnugrep systemd; withBat = command: "${acpi}/bin/acpi -b | ${gnugrep}/bin/grep -q 'Discharging' && ${command}"; in [ { timeout = 60; command = withBat "${brightnessctl}/bin/brightnessctl -s s 0"; resumeCommand = withBat "${brightnessctl}/bin/brightnessctl -r"; } { timeout = 300; command = withBat "${systemd}/bin/systemctl suspend"; } ]; events = [ { event = "before-sleep"; command = "${cfg.lockCommand}"; } ]; }; }; }