From 650ce2c546b7a85baefbacbc27d76187591263cc Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 2 Aug 2024 14:33:18 -0400 Subject: [PATCH] home: switch hyprland and sway to new swayidle systemd service --- homeManagerModules/apps/default.nix | 1 + homeManagerModules/apps/swayidle/default.nix | 63 +++++++++++++++++++ .../desktop/hyprland/scripts.nix | 22 ------- .../desktop/hyprland/settings.nix | 1 - homeManagerModules/desktop/sway/scripts.nix | 31 --------- homeManagerModules/desktop/sway/settings.nix | 2 - .../desktop/wayland/default.nix | 1 + homeManagerModules/options.nix | 1 + 8 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 homeManagerModules/apps/swayidle/default.nix delete mode 100644 homeManagerModules/desktop/sway/scripts.nix diff --git a/homeManagerModules/apps/default.nix b/homeManagerModules/apps/default.nix index 395e2eb6..1dae49d1 100644 --- a/homeManagerModules/apps/default.nix +++ b/homeManagerModules/apps/default.nix @@ -15,6 +15,7 @@ ./mako ./nemo ./rofi + ./swayidle ./swaylock ./thunar ./tmux diff --git a/homeManagerModules/apps/swayidle/default.nix b/homeManagerModules/apps/swayidle/default.nix new file mode 100644 index 00000000..10b359c5 --- /dev/null +++ b/homeManagerModules/apps/swayidle/default.nix @@ -0,0 +1,63 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.ar.home; + hyprctl = lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"; + swaymsg = lib.getExe' config.wayland.windowManager.sway.package "swaymsg"; + +in { + config = lib.mkIf config.ar.home.apps.swayidle.enable { + services.swayidle = { + enable = true; + + events = [ + { + event = "before-sleep"; + command = "${lib.getExe pkgs.playerctl} pause"; + } + { + event = "before-sleep"; + command = "${pkgs.swaylock}/bin/swaylock"; + } + { + event = "lock"; + command = "${pkgs.swaylock}/bin/swaylock"; + } + ]; + + timeouts = + [ + { + timeout = 120; + command = "${lib.getExe pkgs.brightnessctl} -s set 10' resume '${lib.getExe pkgs.brightnessctl} -r"; + } + { + timeout = 600; + command = "${pkgs.swaylock}/bin/swaylock"; + } + ] + ++ lib.optional cfg.desktop.autoSuspend { + timeout = 600; + command = "sleep 2 && ${lib.getExe' pkgs.systemd "systemctl"} suspend'"; + } + ++ lib.optional (!cfg.desktop.autoSuspend) + { + timeout = 600; + command = "${pkgs.swaylock}/bin/swaylock"; + } + ++ lib.optional (!cfg.desktop.autoSuspend && cfg.desktop.hyprland.enable) + { + timeout = 630; + command = "${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'"; + } + ++ lib.optional (!cfg.desktop.autoSuspend && cfg.desktop.sway.enable) + { + timeout = 630; + command = "${swaymsg} \"output * dpms off\"' resume '${swaymsg} \"output * dpms on\""; + }; + }; + }; +} diff --git a/homeManagerModules/desktop/hyprland/scripts.nix b/homeManagerModules/desktop/hyprland/scripts.nix index 2430e0f7..4e3e4df1 100644 --- a/homeManagerModules/desktop/hyprland/scripts.nix +++ b/homeManagerModules/desktop/hyprland/scripts.nix @@ -26,28 +26,6 @@ in { fi ''; - idleD = let - timeouts = - ["timeout 120 '${lib.getExe pkgs.brightnessctl} -s set 10' resume '${lib.getExe pkgs.brightnessctl} -r'"] - ++ ( - if cfg.desktop.autoSuspend - then ["timeout 600 'sleep 2 && ${lib.getExe' pkgs.systemd "systemctl"} suspend'"] - else [ - "timeout 600 '${lib.getExe pkgs.swaylock}'" - "timeout 630 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'" - ] - ); - - beforeSleeps = - lib.optionals cfg.desktop.autoSuspend - [ - "before-sleep '${lib.getExe pkgs.playerctl} pause'" - "before-sleep '${lib.getExe pkgs.swaylock}'" - ]; - in - pkgs.writeShellScript "hyprland-idled" - "${lib.getExe pkgs.swayidle} -w lock '${lib.getExe pkgs.swaylock}' ${lib.strings.concatStringsSep " " (timeouts ++ beforeSleeps)}"; - tablet = pkgs.writeShellScript "hyprland-tablet" '' STATE=`${lib.getExe pkgs.dconf} read /org/gnome/desktop/a11y/applications/screen-keyboard-enabled` diff --git a/homeManagerModules/desktop/hyprland/settings.nix b/homeManagerModules/desktop/hyprland/settings.nix index ec7a722f..5ed863d6 100644 --- a/homeManagerModules/desktop/hyprland/settings.nix +++ b/homeManagerModules/desktop/hyprland/settings.nix @@ -131,7 +131,6 @@ in { (lib.getExe pkgs.wayland-pipewire-idle-inhibit) (lib.getExe' pkgs.playerctl "playerctld") (lib.getExe' pkgs.swayosd "swayosd-server") - scripts.idleD ] ++ lib.lists.optional (cfg.desktop.redShift) "${lib.getExe pkgs.gammastep} -l 33.74:-84.38" diff --git a/homeManagerModules/desktop/sway/scripts.nix b/homeManagerModules/desktop/sway/scripts.nix deleted file mode 100644 index 6e3d68db..00000000 --- a/homeManagerModules/desktop/sway/scripts.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - cfg = config.ar.home; - swaymsg = lib.getExe' config.wayland.windowManager.sway.package "swaymsg"; -in { - idleD = let - timeouts = - ["timeout 120 '${lib.getExe pkgs.brightnessctl} -s set 10' resume '${lib.getExe pkgs.brightnessctl} -r'"] - ++ ( - if cfg.desktop.autoSuspend - then ["timeout 600 'sleep 2 && ${lib.getExe' pkgs.systemd "systemctl"} suspend'"] - else [ - "timeout 600 '${lib.getExe pkgs.swaylock}'" - "timeout 630 '${swaymsg} \"output * dpms off\"' resume '${swaymsg} \"output * dpms on\"'" - ] - ); - - beforeSleeps = - lib.optionals cfg.desktop.autoSuspend - [ - "before-sleep '${lib.getExe pkgs.playerctl} pause'" - "before-sleep '${lib.getExe pkgs.swaylock}'" - ]; - in - pkgs.writeShellScript "sway-idled" - "${lib.getExe pkgs.swayidle} -w lock '${lib.getExe pkgs.swaylock}' ${lib.strings.concatStringsSep " " (timeouts ++ beforeSleeps)}"; -} diff --git a/homeManagerModules/desktop/sway/settings.nix b/homeManagerModules/desktop/sway/settings.nix index 888c9655..9f1523da 100644 --- a/homeManagerModules/desktop/sway/settings.nix +++ b/homeManagerModules/desktop/sway/settings.nix @@ -5,7 +5,6 @@ ... }: let cfg = config.ar.home; - scripts = import ./scripts.nix {inherit config lib pkgs;}; helpers = import ../wayland/helpers.nix {inherit config lib pkgs;}; modifier = "Mod4"; in { @@ -159,7 +158,6 @@ in { startup = [ {command = "${pkgs.mate.mate-polkit}/libexec/polkit-mate-authentication-agent-1";} - {command = "${scripts.idleD}";} {command = lib.getExe pkgs.autotiling;} {command = lib.getExe pkgs.mako;} {command = lib.getExe pkgs.wayland-pipewire-idle-inhibit;} diff --git a/homeManagerModules/desktop/wayland/default.nix b/homeManagerModules/desktop/wayland/default.nix index a2c40223..fca1a5d5 100644 --- a/homeManagerModules/desktop/wayland/default.nix +++ b/homeManagerModules/desktop/wayland/default.nix @@ -9,6 +9,7 @@ kitty.enable = lib.mkDefault true; mako.enable = lib.mkDefault true; rofi.enable = lib.mkDefault true; + swayidle.enable = lib.mkDefault true; swaylock.enable = lib.mkDefault true; waybar.enable = lib.mkDefault true; }; diff --git a/homeManagerModules/options.nix b/homeManagerModules/options.nix index a6dbb8fe..03c78858 100644 --- a/homeManagerModules/options.nix +++ b/homeManagerModules/options.nix @@ -62,6 +62,7 @@ in { }; rofi.enable = lib.mkEnableOption "Rofi launcher."; + swayidle.enable = lib.mkEnableOption "Swayidle idle daemon."; swaylock.enable = lib.mkEnableOption "Swaylock screen locker."; thunar.enable = lib.mkOption {