home: switch hyprland and sway to new swayidle systemd service

This commit is contained in:
Aly Raffauf 2024-08-02 14:33:18 -04:00
parent 78491e655c
commit 650ce2c546
8 changed files with 66 additions and 56 deletions

View file

@ -15,6 +15,7 @@
./mako ./mako
./nemo ./nemo
./rofi ./rofi
./swayidle
./swaylock ./swaylock
./thunar ./thunar
./tmux ./tmux

View file

@ -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\"";
};
};
};
}

View file

@ -26,28 +26,6 @@ in {
fi 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" '' tablet = pkgs.writeShellScript "hyprland-tablet" ''
STATE=`${lib.getExe pkgs.dconf} read /org/gnome/desktop/a11y/applications/screen-keyboard-enabled` STATE=`${lib.getExe pkgs.dconf} read /org/gnome/desktop/a11y/applications/screen-keyboard-enabled`

View file

@ -131,7 +131,6 @@ in {
(lib.getExe pkgs.wayland-pipewire-idle-inhibit) (lib.getExe pkgs.wayland-pipewire-idle-inhibit)
(lib.getExe' pkgs.playerctl "playerctld") (lib.getExe' pkgs.playerctl "playerctld")
(lib.getExe' pkgs.swayosd "swayosd-server") (lib.getExe' pkgs.swayosd "swayosd-server")
scripts.idleD
] ]
++ lib.lists.optional (cfg.desktop.redShift) ++ lib.lists.optional (cfg.desktop.redShift)
"${lib.getExe pkgs.gammastep} -l 33.74:-84.38" "${lib.getExe pkgs.gammastep} -l 33.74:-84.38"

View file

@ -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)}";
}

View file

@ -5,7 +5,6 @@
... ...
}: let }: let
cfg = config.ar.home; cfg = config.ar.home;
scripts = import ./scripts.nix {inherit config lib pkgs;};
helpers = import ../wayland/helpers.nix {inherit config lib pkgs;}; helpers = import ../wayland/helpers.nix {inherit config lib pkgs;};
modifier = "Mod4"; modifier = "Mod4";
in { in {
@ -159,7 +158,6 @@ in {
startup = startup =
[ [
{command = "${pkgs.mate.mate-polkit}/libexec/polkit-mate-authentication-agent-1";} {command = "${pkgs.mate.mate-polkit}/libexec/polkit-mate-authentication-agent-1";}
{command = "${scripts.idleD}";}
{command = lib.getExe pkgs.autotiling;} {command = lib.getExe pkgs.autotiling;}
{command = lib.getExe pkgs.mako;} {command = lib.getExe pkgs.mako;}
{command = lib.getExe pkgs.wayland-pipewire-idle-inhibit;} {command = lib.getExe pkgs.wayland-pipewire-idle-inhibit;}

View file

@ -9,6 +9,7 @@
kitty.enable = lib.mkDefault true; kitty.enable = lib.mkDefault true;
mako.enable = lib.mkDefault true; mako.enable = lib.mkDefault true;
rofi.enable = lib.mkDefault true; rofi.enable = lib.mkDefault true;
swayidle.enable = lib.mkDefault true;
swaylock.enable = lib.mkDefault true; swaylock.enable = lib.mkDefault true;
waybar.enable = lib.mkDefault true; waybar.enable = lib.mkDefault true;
}; };

View file

@ -62,6 +62,7 @@ in {
}; };
rofi.enable = lib.mkEnableOption "Rofi launcher."; rofi.enable = lib.mkEnableOption "Rofi launcher.";
swayidle.enable = lib.mkEnableOption "Swayidle idle daemon.";
swaylock.enable = lib.mkEnableOption "Swaylock screen locker."; swaylock.enable = lib.mkEnableOption "Swaylock screen locker.";
thunar.enable = lib.mkOption { thunar.enable = lib.mkOption {