From 0ec489057210675801dbe91d47c0ee55f4fcf7fa Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Dec 2024 10:08:25 -0600 Subject: [PATCH] hypridle: switch to systemd-lock-handler for lockscreen Signed-off-by: Myned --- options/custom/default.nix | 1 + options/custom/services/hypridle.nix | 65 +++++++++++----------------- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/options/custom/default.nix b/options/custom/default.nix index 0b8ecb5..8483fdb 100644 --- a/options/custom/default.nix +++ b/options/custom/default.nix @@ -36,6 +36,7 @@ in { rounding = mkOption {default = 15;}; ### Misc + lockscreen = mkOption {default = "hyprlock";}; wallpaper = mkOption {default = false;}; browser = { diff --git a/options/custom/services/hypridle.nix b/options/custom/services/hypridle.nix index e62b794..7e171a4 100644 --- a/options/custom/services/hypridle.nix +++ b/options/custom/services/hypridle.nix @@ -7,16 +7,25 @@ with lib; let grep = "${pkgs.gnugrep}/bin/grep"; hyprctl = "${config.programs.hyprland.package}/bin/hyprctl"; - hyprlock = "${config.home-manager.users.${config.custom.username}.programs.hyprlock.package}/bin/hyprlock"; loginctl = "${pkgs.systemd}/bin/loginctl"; niri = "${config.programs.niri.package}/bin/niri"; - pgrep = "${pkgs.procps}/bin/pgrep"; pw-cli = "${pkgs.pipewire}/bin/pw-cli"; systemctl = "${pkgs.systemd}/bin/systemctl"; cfg = config.custom.services.hypridle; in { - options.custom.services.hypridle.enable = mkOption {default = false;}; + options.custom.services.hypridle = { + enable = mkOption {default = false;}; + + dpms = mkOption { + default = + if config.custom.desktop == "hyprland" + then "${hyprctl} dispatch dpms off" + else if config.custom.desktop == "niri" + then "${niri} msg action power-off-monitors" + else ""; + }; + }; config.home-manager.users.${config.custom.username} = mkIf cfg.enable { # https://github.com/hyprwm/hypridle @@ -24,44 +33,22 @@ in { services.hypridle = { enable = true; - settings = let - # Workaround for red background immediately showing while lockscreen starts - # https://github.com/YaLTeR/niri/issues/808 - do-screen-transition = "${niri} msg action do-screen-transition --delay-ms 1000 &&"; - in { - general = let - lock = "${pgrep} hyprlock || ${ - if config.custom.desktops.desktop == "niri" - then do-screen-transition - else "" - } ${hyprlock}"; - in { - before_sleep_cmd = "${lock} --immediate"; - lock_cmd = lock; - }; + settings.listener = [ + { + timeout = 15 * 60; # Seconds + on-timeout = cfg.dpms; + } - listener = [ - { - timeout = 15 * 60; # Seconds - on-timeout = "${loginctl} lock-session"; - } + { + timeout = 20 * 60; # Seconds + on-timeout = "${loginctl} lock-session"; + } - { - timeout = 20 * 60; # Seconds - on-timeout = - if config.custom.desktops.desktop == "hyprland" - then "${hyprctl} dispatch dpms off" - else if config.custom.desktops.desktop == "niri" - then "${niri} msg action power-off-monitors" - else ""; - } - - { - timeout = 60 * 60; # Seconds - on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} suspend-then-hibernate"; # Suspend if no audio - } - ]; - }; + { + timeout = 60 * 60; # Seconds + on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} suspend-then-hibernate"; # Suspend if no audio + } + ]; }; # BUG: graphical-session-pre.target may not have WAYLAND_DISPLAY set, so service is skipped