From 7a9b39efc8e6ead46cce9d9535d0e1c5197cd49d Mon Sep 17 00:00:00 2001 From: Oliver Tosky Date: Sat, 21 Sep 2024 10:35:38 -0400 Subject: [PATCH] add swayidle --- .../desktop/common/wayland-wm/default.nix | 1 + .../desktop/common/wayland-wm/swayidle.nix | 45 +++++++++++++++++++ homes/_modules/desktop/hyprland.nix | 1 + 3 files changed, 47 insertions(+) create mode 100644 homes/_modules/desktop/common/wayland-wm/swayidle.nix diff --git a/homes/_modules/desktop/common/wayland-wm/default.nix b/homes/_modules/desktop/common/wayland-wm/default.nix index 92b0631..6864cc2 100644 --- a/homes/_modules/desktop/common/wayland-wm/default.nix +++ b/homes/_modules/desktop/common/wayland-wm/default.nix @@ -1,6 +1,7 @@ {pkgs, ...}: { imports = [ ./swaylock.nix + ./swayidle.nix ./waybar.nix ./wofi.nix ./swaync.nix diff --git a/homes/_modules/desktop/common/wayland-wm/swayidle.nix b/homes/_modules/desktop/common/wayland-wm/swayidle.nix new file mode 100644 index 0000000..27e4254 --- /dev/null +++ b/homes/_modules/desktop/common/wayland-wm/swayidle.nix @@ -0,0 +1,45 @@ +{ + pkgs, + lib, + config, + ... +}: let + swaylock = "${config.programs.swaylock.package}/bin/swaylock"; + hyprctl = "${config.wayland.windowManager.hyprland.package}/bin/hyprctl"; + lockTime = 1 * 60; # TODO: configurable desktop (10 min)/laptop (4 min) +in { + services.swayidle = { + enable = true; + systemdTarget = "graphical-session.target"; + extraArgs = [ + "-d" + ]; + timeouts = + # Lock screen + [ + { + timeout = lockTime; + command = "${swaylock} -defF"; + } + { + timeout = 180; + command = "${hyprctl} dispatch dpms off"; + resumeCommand = "${hyprctl} dispatch dpms on"; + } + ]; + events = [ + { + event = "lock"; + command = "${swaylock} -defF"; + } + { + event = "after-resume"; + command = "${hyprctl} dispatch dpms on"; + } + { + event = "before-sleep"; + command = "${swaylock} -defF"; + } + ]; + }; +} diff --git a/homes/_modules/desktop/hyprland.nix b/homes/_modules/desktop/hyprland.nix index cc6961f..8a268d5 100644 --- a/homes/_modules/desktop/hyprland.nix +++ b/homes/_modules/desktop/hyprland.nix @@ -30,6 +30,7 @@ in { package = hyprland; systemd = { enable = true; + variables = ["--all"]; # Same as default, but stop graphical-session too extraCommands = lib.mkBefore [ "systemctl --user stop graphical-session.target"