Add ability to inhibit sleep when plugged in
All checks were successful
Buill NixOS Configurations / build (carbon) (push) Successful in 1m21s
Buill NixOS Configurations / build (git) (push) Successful in 1m13s
Buill NixOS Configurations / build (gospel) (push) Successful in 1m28s
Buill NixOS Configurations / build (node) (push) Successful in 1m18s
All checks were successful
Buill NixOS Configurations / build (carbon) (push) Successful in 1m21s
Buill NixOS Configurations / build (git) (push) Successful in 1m13s
Buill NixOS Configurations / build (gospel) (push) Successful in 1m28s
Buill NixOS Configurations / build (node) (push) Successful in 1m18s
This commit is contained in:
parent
7ba4796758
commit
259c75204d
2 changed files with 26 additions and 2 deletions
|
|
@ -4,7 +4,6 @@ let
|
|||
internal_display_settings = "eDP-1,preferred,auto,1.6";
|
||||
clamshell_script = pkgs.writeShellScriptBin "clamshell" ''
|
||||
if ${pkgs.hyprland}/bin/hyprctl monitors | ${pkgs.ripgrep}/bin/rg -q '\sDP-'; then
|
||||
echo "Detected external monitor..."
|
||||
if [[ "$1" == "open" ]]; then
|
||||
${pkgs.hyprland}/bin/hyprctl keyword monitor ${internal_display_settings}
|
||||
else
|
||||
|
|
@ -25,6 +24,7 @@ in
|
|||
",preferred,auto,1"
|
||||
];
|
||||
};
|
||||
aa.services.hypridle.suspendInhibitWhenPluggedIn = true;
|
||||
aa.windowManagers.sway.enable = lib.mkForce false;
|
||||
|
||||
wayland.windowManager.hyprland.settings.bindl = [
|
||||
|
|
|
|||
|
|
@ -14,6 +14,18 @@ let
|
|||
;
|
||||
|
||||
cfg = config.${namespace}.services.hypridle;
|
||||
|
||||
# Script that suspends only when on battery power.
|
||||
# When plugged in, uses systemd-inhibit to block suspend.
|
||||
suspendScript = pkgs.writeShellScript "hypridle-suspend" ''
|
||||
if [ "$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/AC/online)" = "1" ]; then
|
||||
# Plugged in - inhibit suspend
|
||||
${pkgs.systemd}/bin/systemd-inhibit --what=sleep --who=hypridle --why="AC power connected" --mode=block ${pkgs.coreutils}/bin/sleep infinity &
|
||||
else
|
||||
# On battery - suspend
|
||||
${pkgs.systemd}/bin/systemctl suspend
|
||||
fi
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.${namespace}.services.hypridle = {
|
||||
|
|
@ -49,6 +61,14 @@ in
|
|||
Whether or not to automatically suspend
|
||||
'';
|
||||
};
|
||||
suspendInhibitWhenPluggedIn = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to inhibit suspend when AC power is connected.
|
||||
Useful for laptops that should only suspend on battery.
|
||||
'';
|
||||
};
|
||||
|
||||
brightnessTimeout = mkOption {
|
||||
type = types.int;
|
||||
|
|
@ -108,7 +128,11 @@ in
|
|||
# Suspend system
|
||||
(lib.mkIf cfg.suspendEnable {
|
||||
timeout = cfg.suspendTimeout;
|
||||
on-timeout = "systemctl suspend";
|
||||
on-timeout =
|
||||
if cfg.suspendInhibitWhenPluggedIn then
|
||||
"${suspendScript}"
|
||||
else
|
||||
"${pkgs.systemd}/bin/systemctl suspend";
|
||||
})
|
||||
];
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue