From fb97044847decfc4a0c4f0b79ceb6357f17e5610 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 22 Nov 2024 19:05:16 -0500 Subject: [PATCH] desktop: set hyprland to use hypridle + hyprlock --- .../desktop/hyprland/settings.nix | 2 +- homeManagerModules/desktop/sway/settings.nix | 2 +- .../desktop/wayland/default.nix | 3 +- homeManagerModules/options.nix | 1 + homeManagerModules/services/default.nix | 1 + .../services/hypridle/default.nix | 81 +++++++++++++++++++ .../services/swayidle/default.nix | 21 ++--- 7 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 homeManagerModules/services/hypridle/default.nix diff --git a/homeManagerModules/desktop/hyprland/settings.nix b/homeManagerModules/desktop/hyprland/settings.nix index d31cc4f6..86ec5cd2 100644 --- a/homeManagerModules/desktop/hyprland/settings.nix +++ b/homeManagerModules/desktop/hyprland/settings.nix @@ -29,7 +29,7 @@ in { [ ''$mod,M,exec,${lib.getExe config.programs.rofi.package} -show power-menu -modi "power-menu:${lib.getExe pkgs.rofi-power-menu} --choices=logout/lockscreen/suspend/shutdown/reboot"'' ",PRINT,exec,${helpers.screenshot}" - "$mod CTRL,L,exec,${lib.getExe pkgs.swaylock}" + "$mod CTRL,L,exec,${lib.getExe' pkgs.systemd "loginctl"} lock-session" "$mod SHIFT,backslash,togglesplit" "$mod SHIFT,comma,exec,${lib.getExe pkgs.hyprnome} --previous --move" "$mod SHIFT,G,togglegroup" diff --git a/homeManagerModules/desktop/sway/settings.nix b/homeManagerModules/desktop/sway/settings.nix index 2fc76062..855f18af 100644 --- a/homeManagerModules/desktop/sway/settings.nix +++ b/homeManagerModules/desktop/sway/settings.nix @@ -87,7 +87,7 @@ in { "${modifier}+B" = "exec ${lib.getExe cfg.defaultApps.webBrowser}"; "${modifier}+C" = "kill"; "${modifier}+Comma" = "workspace prev"; - "${modifier}+Control+L" = "exec ${lib.getExe pkgs.swaylock}"; + "${modifier}+Control+L" = "exec ${lib.getExe' pkgs.systemd "loginctl"} lock-session"; "${modifier}+E" = "exec ${lib.getExe cfg.defaultApps.editor}"; "${modifier}+F" = "exec ${lib.getExe cfg.defaultApps.fileManager}"; "${modifier}+F11" = "exec pkill -SIGUSR1 waybar"; # Show/hide waybar diff --git a/homeManagerModules/desktop/wayland/default.nix b/homeManagerModules/desktop/wayland/default.nix index d54e4943..bfd29e04 100644 --- a/homeManagerModules/desktop/wayland/default.nix +++ b/homeManagerModules/desktop/wayland/default.nix @@ -13,9 +13,10 @@ }; services = { + hypridle.enable = lib.mkDefault config.ar.home.desktop.hyprland.enable; mako.enable = lib.mkDefault true; pipewire-inhibit.enable = lib.mkDefault true; - swayidle.enable = lib.mkDefault true; + swayidle.enable = lib.mkDefault config.ar.home.desktop.sway.enable; swayosd.enable = lib.mkDefault true; waybar.enable = lib.mkDefault true; }; diff --git a/homeManagerModules/options.nix b/homeManagerModules/options.nix index 3dc8544e..f622cddb 100644 --- a/homeManagerModules/options.nix +++ b/homeManagerModules/options.nix @@ -186,6 +186,7 @@ in { }; gammastep.enable = lib.mkEnableOption "Gammastep redshift daemon."; + hypridle.enable = lib.mkEnableOption "Hypridle idle daemon."; mako.enable = lib.mkEnableOption "Mako notification daemon."; mpd = { diff --git a/homeManagerModules/services/default.nix b/homeManagerModules/services/default.nix index 15e8c979..839d52e4 100644 --- a/homeManagerModules/services/default.nix +++ b/homeManagerModules/services/default.nix @@ -2,6 +2,7 @@ imports = [ ./easyeffects ./gammastep + ./hypridle ./mako ./mpd ./pipewire-inhibit diff --git a/homeManagerModules/services/hypridle/default.nix b/homeManagerModules/services/hypridle/default.nix new file mode 100644 index 00000000..993e37e0 --- /dev/null +++ b/homeManagerModules/services/hypridle/default.nix @@ -0,0 +1,81 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.services.hypridle.enable { + programs.hyprlock.enable = true; + + services.hypridle = { + enable = true; + + settings = { + general = { + after_sleep_cmd = "hyprctl dispatch dpms on"; + lock_cmd = "hyprlock"; + before_sleep_cmd = "hyprlock --immediate --no-fade-in"; + }; + + listener = + [ + { + timeout = 30; + on-timeout = "brightnessctl -sd chromeos::kbd_backlight set 0"; + on-resume = "brightnessctl -rd chromeos::kbd_backlight"; + } + { + timeout = 120; + on-timeout = "brightnessctl -s set 10"; + on-resume = "brightnessctl -r"; + } + ] + ++ lib.optional (!cfg.desktop.autoSuspend) { + timeout = 600; + on-timeout = "hyprlock"; + } + ++ lib.optional cfg.desktop.autoSuspend { + timeout = 600; + command = "systemctl suspend"; + } + ++ lib.optional + (!cfg.desktop.autoSuspend) { + timeout = 600; + on-timeout = "hyprlock"; + } + ++ lib.optional (!cfg.desktop.autoSuspend && cfg.desktop.hyprland.enable) + { + timeout = 630; + on-timeout = "hyprctl dispatch dpms off"; + on-resume = "hyprctl dispatch dpms on"; + }; + }; + }; + + systemd.user.services.hypridle = { + Install.WantedBy = lib.mkForce (lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target"); + + Service = { + Environment = lib.mkForce [ + "PATH=${ + lib.makeBinPath ( + (with pkgs; [ + bash + brightnessctl + coreutils + hyprlock + systemd + ]) + ++ lib.optional (cfg.desktop.hyprland.enable) config.wayland.windowManager.hyprland.package + ) + }" + ]; + Restart = lib.mkForce "no"; + }; + + Unit.BindsTo = lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target"; + }; + }; +} diff --git a/homeManagerModules/services/swayidle/default.nix b/homeManagerModules/services/swayidle/default.nix index c1c35f8a..866c07a5 100644 --- a/homeManagerModules/services/swayidle/default.nix +++ b/homeManagerModules/services/swayidle/default.nix @@ -11,10 +11,6 @@ in { enable = true; events = [ - { - event = "before-sleep"; - command = "playerctl pause"; - } { event = "before-sleep"; command = "swaylock && sleep 2"; @@ -27,6 +23,11 @@ in { timeouts = [ + { + timeout = 30; + command = "brightnessctl -sd chromeos::kbd_backlight set 0"; + resumeCommand = "brightnessctl -rd chromeos::kbd_backlight"; + } { timeout = 120; command = "brightnessctl -s set 10"; @@ -42,12 +43,6 @@ in { timeout = 600; command = "swaylock"; } - ++ lib.optional (!cfg.desktop.autoSuspend && cfg.desktop.hyprland.enable) - { - timeout = 630; - command = "hyprctl dispatch dpms off"; - resumeCommand = "hyprctl dispatch dpms on"; - } ++ lib.optional (!cfg.desktop.autoSuspend && cfg.desktop.sway.enable) { timeout = 630; @@ -57,7 +52,7 @@ in { }; systemd.user.services.swayidle = { - Install.WantedBy = lib.mkForce (lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target" ++ lib.optional (cfg.desktop.sway.enable) "sway-session.target"); + Install.WantedBy = lib.mkForce (lib.optional (cfg.desktop.sway.enable) "sway-session.target"); Service = { Environment = lib.mkForce [ @@ -66,18 +61,16 @@ in { bash brightnessctl coreutils - playerctl swaylock systemd ]) - ++ lib.optional (cfg.desktop.hyprland.enable) config.wayland.windowManager.hyprland.package ++ lib.optional (cfg.desktop.sway.enable) config.wayland.windowManager.sway.package) }" ]; Restart = lib.mkForce "no"; }; - Unit.BindsTo = lib.optional (cfg.desktop.hyprland.enable) "hyprland-session.target" ++ lib.optional (cfg.desktop.sway.enable) "sway-session.target"; + Unit.BindsTo = lib.optional (cfg.desktop.sway.enable) "sway-session.target"; }; }; }