From ae0e007ba28c6855c90d81954a887a8dfd92ddf0 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Tue, 23 Jul 2024 17:04:23 -0400 Subject: [PATCH] home: nixify swayidle (#60) * home/hyprland: nixify idled * home/hyprland: don't pass before-sleep commands if autosuspend is disabled * home/hyprland: simplify idled options * home/sway: mirror hyprland idleD improvements --- .../desktop/hyprland/scripts.nix | 36 +++++++++++-------- homeManagerModules/desktop/sway/scripts.nix | 36 +++++++++++-------- homeManagerModules/desktop/sway/settings.nix | 7 ++-- hosts/petalburg/default.nix | 2 +- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/homeManagerModules/desktop/hyprland/scripts.nix b/homeManagerModules/desktop/hyprland/scripts.nix index 71c30c1b..819c91b2 100644 --- a/homeManagerModules/desktop/hyprland/scripts.nix +++ b/homeManagerModules/desktop/hyprland/scripts.nix @@ -26,21 +26,27 @@ in { fi ''; - idleD = pkgs.writeShellScript "hyprland-idled" '' - ${lib.getExe pkgs.swayidle} -w \ - before-sleep '${lib.getExe pkgs.playerctl} pause' \ - before-sleep '${lib.getExe pkgs.swaylock}' \ - timeout 240 '${lib.getExe pkgs.brightnessctl} -s set 10' \ - resume '${lib.getExe pkgs.brightnessctl} -r' \ - timeout 300 '${lib.getExe pkgs.swaylock}' \ - timeout 330 '${hyprctl} dispatch dpms off' \ - resume '${hyprctl} dispatch dpms on' \ - ${ - if cfg.desktop.hyprland.autoSuspend - then ''timeout 900 'sleep 2 && ${lib.getExe' pkgs.systemd "systemctl"} suspend' \'' - else ''\'' - } - ''; + idleD = let + timeouts = + ["timeout 120 '${lib.getExe pkgs.brightnessctl} -s set 10' resume '${lib.getExe pkgs.brightnessctl} -r'"] + ++ ( + if cfg.desktop.hyprland.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.hyprland.autoSuspend + [ + "before-sleep '${lib.getExe pkgs.playerctl} pause'" + "before-sleep '${lib.getExe pkgs.swaylock}'" + ]; + in + pkgs.writeShellScript "hyprland-idled" + "${lib.getExe pkgs.swayidle} -w ${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/sway/scripts.nix b/homeManagerModules/desktop/sway/scripts.nix index 96c29f57..606af31a 100644 --- a/homeManagerModules/desktop/sway/scripts.nix +++ b/homeManagerModules/desktop/sway/scripts.nix @@ -7,21 +7,27 @@ cfg = config.ar.home; swaymsg = lib.getExe' config.wayland.windowManager.sway.package "swaymsg"; in { - idleD = pkgs.writeShellScript "sway-idled" '' - ${lib.getExe pkgs.swayidle} -w \ - before-sleep '${lib.getExe pkgs.playerctl} pause' \ - before-sleep '${lib.getExe pkgs.swaylock}' \ - timeout 240 '${lib.getExe pkgs.brightnessctl} -s set 10' \ - resume '${lib.getExe pkgs.brightnessctl} -r' \ - timeout 300 '${lib.getExe pkgs.swaylock}' \ - timeout 330 '${swaymsg} "output * dpms off"' \ - resume '${swaymsg} "output * dpms on"' \ - ${ - if cfg.desktop.sway.autoSuspend - then ''timeout 900 '${lib.getExe' pkgs.systemd "systemctl"} suspend' \'' - else ''\'' - } - ''; + idleD = let + timeouts = + ["timeout 120 '${lib.getExe pkgs.brightnessctl} -s set 10' resume '${lib.getExe pkgs.brightnessctl} -r'"] + ++ ( + if cfg.desktop.sway.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.sway.autoSuspend + [ + "before-sleep '${lib.getExe pkgs.playerctl} pause'" + "before-sleep '${lib.getExe pkgs.swaylock}'" + ]; + in + pkgs.writeShellScript "sway-idled" + "${lib.getExe pkgs.swayidle} -w ${lib.strings.concatStringsSep " " (timeouts ++ beforeSleeps)}"; randomWallpaper = pkgs.writeShellScript "sway-randomWallpaper" '' kill `pidof swaybg` diff --git a/homeManagerModules/desktop/sway/settings.nix b/homeManagerModules/desktop/sway/settings.nix index b2bc3e72..ce25b995 100644 --- a/homeManagerModules/desktop/sway/settings.nix +++ b/homeManagerModules/desktop/sway/settings.nix @@ -10,8 +10,9 @@ modifier = "Mod4"; in { enable = true; - wrapperFeatures.gtk = true; checkConfig = false; + package = lib.mkDefault pkgs.swayfx; + wrapperFeatures.gtk = true; config = { bars = [{command = lib.getExe pkgs.waybar;}]; @@ -162,8 +163,8 @@ in { "${modifier}+Shift+S" = "move scratchpad"; # Screenshots - "PRINT" = "exec ${helpers.screenshot.screen}"; - "${modifier}+PRINT" = "exec ${helpers.screenshot.region}"; + "PRINT" = "exec ${helpers.screenshot}"; + "Control+F12" = "exec ${helpers.screenshot}"; # Show/hide waybar "${modifier}+F11" = "exec pkill -SIGUSR1 waybar"; diff --git a/hosts/petalburg/default.nix b/hosts/petalburg/default.nix index 35ae2755..08336b36 100644 --- a/hosts/petalburg/default.nix +++ b/hosts/petalburg/default.nix @@ -57,7 +57,7 @@ autologin = "aly"; }; - gnome.enable = true; + hyprland.enable = true; }; users.aly = {