-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightson
executable file
·80 lines (66 loc) · 1.59 KB
/
lightson
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
if [[ $(pgrep -c xscreensaver) -ge 1 ]]; then
delay_screensaver() { xscreensaver-command -deactivate >&- 2>&-; }
# delay_screensaver() { xdotool key shift; }
else
delay_screensaver() { xset -dpms && xset +dpms; }
fi
get_class() {
local value=$(xprop -id $active_win_id -notype 8s '=$0+' WM_CLASS | cut -d= -f 2)
IFS=', ' read -a data <<< $value
echo ${data[@]//\"}
}
check_fs_apps() {
local classes=(
"plugin-container"
"Navigator"
"Chromium"
"vlc"
"Wine"
)
for class in ${classes[@]}; do
[[ ${active_win_class[0]} == $class ]] && return 0
done
local instances=(
"mpv"
)
for instance in ${instances[@]}; do
[[ ${active_win_class[1]} == $instance ]] && return 0
done
return 1
}
check_non_fs_apps() {
local classes=(
"phoenix"
"totem"
)
for class in ${classes[@]}; do
[[ ${active_win_class[0]} == $class ]] && return 0
done
return 1
}
delay=$1
if [[ -z "$1" ]];then
delay=3m
fi
while true; do
active_win_id=$(xprop -root _NET_ACTIVE_WINDOW)
if [[ -z "$active_win_id" ]]; then
sleep $delay
continue
fi
active_win_id=${active_win_id:40:9}
active_win_class=($(get_class))
if [[ $active_win_id == 0x0 ]]; then
continue
fi
if xprop -id $active_win_id | grep -qE "(_NET_WM_STATE_FULLSCREEN|plugin-container)"; then
if check_fs_apps; then
delay_screensaver
fi
fi
if check_non_fs_apps; then
delay_screensaver
fi
sleep $delay
done