{ 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 = let inherit (pkgs) brightnessctl acpi gnugrep systemd; hyprland = config.wayland.windowManager.hyprland.package; withBat = command: "${acpi}/bin/acpi -b | ${gnugrep}/bin/grep -q 'Discharging' && ${command}"; in { enable = true; systemdTarget = "hyprland-session.target"; timeouts = [ { 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 = "${hyprland}/bin/hyprctl dispatch exec '${cfg.lockCommand}'"; } ]; }; }; }