Add toggle-idle script

This commit is contained in:
ItsDrike 2024-06-22 06:56:38 +02:00
parent b3f457340d
commit 083dc759d1
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
5 changed files with 35 additions and 0 deletions

View file

@ -36,6 +36,7 @@
# TODO: Requires programs
"SUPER_SHIFT, L, exec, wlogout -p layer-shell"
"SUPER_CTRL, L, exec, loginctl lock-session"
"SUPER_SHIFT, T, exec, toggle-idle"
#
# Screenshots

View file

@ -21,6 +21,7 @@ in {
hyprPkgs.quick-record
hyprPkgs.toggle-fake-fullscreen
hyprPkgs.toggle-notifications
hyprPkgs.toggle-idle
hyprPkgs.brightness
pkgs.brightnessctl
pkgs.hyprpicker

View file

@ -9,6 +9,7 @@
quick-record = pkgs.callPackage ./quick-record {};
toggle-fake-fullscreen = pkgs.callPackage ./toggle-fake-fullscreen {};
toggle-notifications = pkgs.callPackage ./toggle-notifications {};
toggle-idle = pkgs.callPackage ./toggle-idle {};
};
in
packages

View file

@ -0,0 +1,14 @@
{pkgs, ...}:
pkgs.writeShellApplication {
name = "toggle-idle";
runtimeInputs = with pkgs; [
coreutils
gnugrep
procps
libnotify
hypridle
];
text = ''
${builtins.readFile ./toggle-idle.sh}
'';
}

View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
idleprog="hypridle" # or swayidle
pid="$(pidof "$idleprog" || true)"
if [ -n "$pid" ]; then
# is process suspended?
if ps -o stat= -p "$pid" | grep T >/dev/null; then
kill -CONT "$pid"
notify-send "Idle-Toggle" "Idle timeouts enabled"
else
kill -STOP "$pid"
notify-send "Idle-Toggle" "Idle timeouts disabled"
fi
else
notify-send "Idle-Toggle" "$idleprog not running!"
fi