dotfiles/modules/home/graphical/wayland/swayidle.nix
eriedaberrie 696d2d17d9 Initial commit
Note: not the actual initial commit.

I swear I will stop repeatedly force pushing to this single commit eventually
ok.
2025-02-23 01:52:35 +00:00

43 lines
1.1 KiB
Nix

{ 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}'";
}
];
};
};
}