diff options
author | sinanmohd <sinan@sinanmohd.com> | 2025-06-10 15:55:54 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2025-06-10 22:55:04 +0530 |
commit | a41037ef644dbacb3d577933fb3d93c210439b38 (patch) | |
tree | a262750bcb1357785ad8cb68b232a5ca242ee671 /home/wayland/modules/sway/swayidle.nix | |
parent | cfccbd1e4026d568e23a47c060ae3ae042cceb4c (diff) |
chore(repo): reformat with nixfmt-rfc-style
Diffstat (limited to 'home/wayland/modules/sway/swayidle.nix')
-rw-r--r-- | home/wayland/modules/sway/swayidle.nix | 110 |
1 files changed, 61 insertions, 49 deletions
diff --git a/home/wayland/modules/sway/swayidle.nix b/home/wayland/modules/sway/swayidle.nix index fd23f41..d9ff473 100644 --- a/home/wayland/modules/sway/swayidle.nix +++ b/home/wayland/modules/sway/swayidle.nix @@ -1,4 +1,10 @@ -{ config, lib, pkgs, ... }: let +{ + config, + lib, + pkgs, + ... +}: +let swaylock = lib.getExe config.programs.swaylock.package; brightnessctl = lib.getExe pkgs.brightnessctl; swaymsg = "${pkgs.sway}/bin/swaymsg"; @@ -7,34 +13,42 @@ suspend_timeout = minute * 60; suspend_on_battery = pkgs.writeShellApplication { name = "suspend_on_battery"; - runtimeInputs = with pkgs; [ gnugrep systemd sudo coreutils ]; - text = let - sudo = "/run/wrappers/bin/sudo"; - in '' - is_discharging() { - grep -qFx \ - 'POWER_SUPPLY_STATUS=Discharging' \ - /sys/class/power_supply/*/uevent - } + runtimeInputs = with pkgs; [ + gnugrep + systemd + sudo + coreutils + ]; + text = + let + sudo = "/run/wrappers/bin/sudo"; + in + '' + is_discharging() { + grep -qFx \ + 'POWER_SUPPLY_STATUS=Discharging' \ + /sys/class/power_supply/*/uevent + } - was_charging=false - while true; do - if is_discharging; then - if [ $was_charging = true ]; then - sleep ${builtins.toString suspend_timeout} - fi + was_charging=false + while true; do + if is_discharging; then + if [ $was_charging = true ]; then + sleep ${builtins.toString suspend_timeout} + fi - if is_discharging; then - ${sudo} systemctl suspend-then-hibernate - fi - fi + if is_discharging; then + ${sudo} systemctl suspend-then-hibernate + fi + fi - was_charging=true - sleep 10 - done - ''; + was_charging=true + sleep 10 + done + ''; }; -in { +in +{ systemd.user.services.suspend_on_battery = { Unit.Description = "Suspend on battery"; Service.ExecStart = lib.getExe suspend_on_battery; @@ -44,42 +58,40 @@ in { enable = true; systemdTarget = "sway-session.target"; - events = [{ - event = "before-sleep"; - command = swaylock; - }]; + events = [ + { + event = "before-sleep"; + command = swaylock; + } + ]; timeouts = [ { - timeout = minute * 30; - command = - "${brightnessctl} --save; " - + "${brightnessctl} set 10%-"; - resumeCommand = "${brightnessctl} --restore"; + timeout = minute * 30; + command = "${brightnessctl} --save; " + "${brightnessctl} set 10%-"; + resumeCommand = "${brightnessctl} --restore"; } { - timeout = minute * 31; - command = swaylock; + timeout = minute * 31; + command = swaylock; } { - timeout = minute * 32; - command = - "${swaymsg} --type command 'output * dpms off'; " - + "${brightnessctl} -c leds -d platform::kbd_backlight --save; " - + "${brightnessctl} -c leds -d platform::kbd_backlight set 0"; - resumeCommand = - "${brightnessctl} -c leds -d platform::kbd_backlight --restore; " - + "${swaymsg} --type command 'output * dpms on'"; + timeout = minute * 32; + command = + "${swaymsg} --type command 'output * dpms off'; " + + "${brightnessctl} -c leds -d platform::kbd_backlight --save; " + + "${brightnessctl} -c leds -d platform::kbd_backlight set 0"; + resumeCommand = + "${brightnessctl} -c leds -d platform::kbd_backlight --restore; " + + "${swaymsg} --type command 'output * dpms on'"; } { - timeout = suspend_timeout; - command = - "${pkgs.systemd}/bin/systemctl --user start suspend_on_battery"; - resumeCommand = - "${pkgs.systemd}/bin/systemctl --user stop suspend_on_battery"; + timeout = suspend_timeout; + command = "${pkgs.systemd}/bin/systemctl --user start suspend_on_battery"; + resumeCommand = "${pkgs.systemd}/bin/systemctl --user stop suspend_on_battery"; } ]; }; |