Hyprland: switch from swayidle to hypridle

this has some cool things including media inhibits by default
This commit is contained in:
NullBite 2024-03-26 02:38:22 -04:00
parent 067557b72f
commit 2a5744d45f
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A
5 changed files with 110 additions and 11 deletions

View File

@ -93,6 +93,8 @@
inputs.rust-overlay.overlays.default
inputs.nixfiles-assets.overlays.default
inputs.nix-minecraft.overlays.default
# inputs.hypridle.overlays.default
(final: prev: { inherit (inputs.hypridle.packages.${prev.system}) hypridle; })
];
### Configuration

View File

@ -1,4 +1,4 @@
{ pkgs, config, lib, options, osConfig ? { }, nixpkgs, home-manager, ... }@args:
{ pkgs, config, lib, options, osConfig ? { }, nixpkgs, home-manager, inputs, ... }@args:
let
isStandalone = with builtins; !( (typeOf osConfig == "set") && hasAttr "home-manager" osConfig );
cfg = config.nixfiles;
@ -11,6 +11,8 @@ in
./profile
./programs
./sessions
inputs.hypridle.homeManagerModules.default
];
config = {};
options.nixfiles = {

View File

@ -3,5 +3,6 @@
imports = [
./comma.nix
./mopidy.nix
./hypridle.nix
];
}

View File

@ -0,0 +1,90 @@
{ pkgs, config, lib, ... }:
let
cfg = config.nixfiles.services.hypridle;
inherit (lib.types) str int;
in
{
options.nixfiles.services.hypridle = {
enable = lib.mkEnableOption "the hypridle configuration";
timeouts = let
mkTimeout = timeout: desc: lib.mkOption {
description = "${desc}";
type = int;
default = timeout;
};
in {
dpms = mkTimeout (300) "DPMS timeout";
lock = mkTimeout (360) "Lock timeout";
locked-dpms = mkTimeout (10) "DPMS timeout while locked";
};
commands = {
dpms-off = lib.mkOption {
description = "DPMS off command";
default = "hyprctl dispatch dpms off";
type = str;
};
dpms-on = lib.mkOption {
description = "DPMS on command";
default = "hyprctl dispatch dpms on";
type = str;
};
# lock = lib.mkOption {
# description = "Lock command";
# default = "${pkgs.swaylock}/bin/swaylock";
# type = str;
# };
# unlock = lib.mkOption {
# description = "Unlock command";
# default = "${pkgs.procps}/bin/pkill -USR1 swaylock";
# type = str;
# };
};
};
config = lib.mkMerge [
(lib.mkIf cfg.enable {
services.hypridle = {
enable = true;
listeners = let
dpms-wrapped = pkgs.writeShellScript "dpms-wrapped" ''
exec ${cfg.commands.dpms-off}
'';
lock-dpms = pkgs.writeShellScript "lock-dpms" ''
${pkgs.procps}/bin/pgrep swaylock > /dev/null && "${dpms-wrapped}"
'';
in [
{
timeout = cfg.timeouts.dpms;
onTimeout = cfg.commands.dpms-off;
onResume = cfg.commands.dpms-on;
}
{
timeout = cfg.timeouts.locked-dpms;
onTimeout = "${lock-dpms}";
onResume = cfg.commands.dpms-on;
}
{
timeout = cfg.timeouts.lock;
onTimeout = "${config.programs.swaylock.package}/bin/swaylock";
}
{
timeout = cfg.timeouts.lock + cfg.timeouts.locked-dpms;
onTimeout = cfg.commands.dpms-off;
onResume = cfg.commands.dpms-on;
}
];
lockCmd = "${config.programs.swaylock.package}";
unlockCmd = "${pkgs.procps}/bin/pkill -x -USR1 swaylock";
beforeSleepCmd = "${config.programs.swaylock.package}";
};
})
# why isn't this handled automatically??
(lib.mkIf config.services.hypridle.enable {
home.packages = with pkgs; [
hypridle
];
})
];
}

View File

@ -13,23 +13,26 @@ let
polkit-agent = "${pkgs.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1";
grimblast = "${inputs.hyprwm-contrib.packages.${pkgs.system}.grimblast}/bin/grimblast";
swayidle = "${pkgs.swayidle}/bin/swayidle";
swaylock = "${pkgs.swaylock}/bin/swaylock";
swaylock = "${config.programs.swaylock.package}/bin/swaylock";
hyprctl = "${hyprland-pkg}/bin/hyprctl";
pkill = "${pkgs.procps}/bin/pkill";
swaybg = "${pkgs.swaybg}/bin/swaybg";
hypridle = "${config.services.hypridle.package}/bin/hypridle";
# lock-cmd = "${swaylock}";
lock-cmd = "${swaylock}";
lock-cmd = let
cmd = pkgs.writeShellScript "lock-script" ''
${swayidle} -w timeout 10 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' &
${swaylock}
kill %%
'';
in "${cmd}";
# lock-cmd = let
# cmd = pkgs.writeShellScript "lock-script" ''
# ${swayidle} -w timeout 10 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' &
# ${swaylock}
# kill %%
# '';
# in "${cmd}";
# idle-cmd = "${swayidle} -w timeout 315 '${lock-cmd}' timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' before-sleep '${lock-cmd}' lock '${lock-cmd}' unlock '${pkill} -USR1 -x swaylock'";
idle-cmd = "${swayidle} -w timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'";
# idle-cmd = "${swayidle} -w timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'";
idle-cmd = "${hypridle}";
hypr-dispatcher-package = pkgs.callPackage ./dispatcher { hyprland = hyprland-pkg; };
hypr-dispatcher = "${hypr-dispatcher-package}/bin/hypr-dispatcher";
@ -76,6 +79,7 @@ in
};
config = lib.mkIf cfg.enable {
nixfiles.services.hypridle.enable = true;
nixfiles.common.wm.enable = true;
home.packages = with pkgs; [
kitty