aboutsummaryrefslogtreecommitdiffstats
path: root/bin/adjust_dpms
blob: 0f56b466762ffb51e0fd1afb4f6cf200fbcddee3 (plain)
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
#!/bin/bash
# Script to adjust dpms settings when running certain programs,
# that don't use fullscreen, but should not be "blanked" in between.
# Run as timed script with systemd from /etc/systemd/system/timer-minutely.target.wants

export DISPLAY=:0

config="/home/dave/.config/dpms"
blankoff=0

# check for config file existence
if [[ -f $config ]];then
  . /home/dave/.config/dpms
else
  echo "Config file not readable $config"
  exit 1
fi

# loop all pre-compiled programs and check for running instances
for i in "${programs[@]}"
do
  pid=$(pidof $i)
  re='^[0-9]+$'
  if  [[ $pid =~ $re ]]; then
    echo "$i running ($pid)"
    blankoff=1
  fi
done

# loop all python2 run programs and check for running instances
for i in "${python2[@]}"
do
  pid=$(pidof python2 $i)
  re='^[0-9]+$'
  if [[ $pid =~ $re ]]; then
    echo "$i running ($pid)"
    blankoff=1
  fi
done

# if valuable programs are running, don't use screen blanking
if [ $blankoff -gt 0 ]; then
  echo "Some program requires screensaver to be off."
  # print currently set values for screensaver timeout to tmp file
  echo "$(xset q|grep timeout|awk '{print $2}') $(xset q|grep timeout|awk '{print $4}')" > /tmp/xset_screensaver
  echo "$(xset q|grep Standby|awk '{print $2}') $(xset q|grep Standby|awk '{print $4}') $(xset q|grep Standby|awk '{print $6}')" > /tmp/xset_dpms
  # disable screensaver and dpms
  xset s off
  xset -dpms
# else set 360 seconds as blank time
else
  xsetq=$(xset q|grep timeout|awk '{print $2}')
  # if the timeout is still 0, set it to its former value, or just switch on screensaver/dpms again
  if [ $xsetq -eq 0 ];then
    if [[ -f /tmp/xset_screensaver && -f /tmp/xset_dpms ]];then
      xset s $(cat /tmp/xset_screensaver)
      xset dpms $(cat /tmp/xset_dpms)
      rm -rf /tmp/xset_screensaver /tmp/xset_dpms
    else
      xset +dpms
      xset s on
    fi
  fi
fi