-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaybar-idle
executable file
·64 lines (56 loc) · 1.38 KB
/
waybar-idle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# Copyright 2024 Raffaele Mancuso
# SPDX-License-Identifier: MIT
# Requires hypridle
SIGNAL=6
pidf="/tmp/waybar-idle"
procname=hypridle
if [ "$1" == "status" ]; then
# -s FILE -> file exists and has a size greater than 0
if [ -s "$pidf" ]; then
printf '{\"text\":\"\", \"tooltip\":\"Running\\nName: %s\\nPID: ' "$procname"
awk 'NR==1{printf $0}' "$pidf"
printf '\"}\n'
else
printf '{"text":"", "tooltip":"Stopped"}\n'
fi
elif [ "$1" == "toggle" ]; then
if [ -s "$pidf" ]; then
"$0" off
else
"$0" on
fi
elif [ "$1" == "on" ]; then
if [ -s "$pidf" ]; then
exit 1
fi
# For swayidle
if [ "${procname}" = "swayidle" ]; then
swayidle -w\
timeout 600 "swaylock -f -c 000000"\
timeout 900 "hyprctl dispatch dpms off"\
resume "hyprctl dispatch dpms on"\
before-sleep "swaylock -f -c 000000"\
1>/dev/null 2>&1 &
elif [ "${procname}" = "hypridle" ]; then
# For hypridle
hypridle 1>/dev/null 2>&1 &
printf "%d" "$!" >"$pidf"
pkill -RTMIN+$SIGNAL waybar
else
printf "ERROR: procname %s not implemented" "${procname}"
fi
elif [ "$1" == "off" ]; then
if [ ! -s "$pidf" ]; then
exit 1
fi
pid=$(awk 'NR==1' "$pidf")
if [ -z "$pid" ]; then
exit 2
fi
kill "$pid"
printf "" >"$pidf"
pkill -RTMIN+$SIGNAL waybar
else
printf "ERROR: Argument %s not valid\n" "$1"
fi