1 | #!/bin/bash
|
2 |
|
3 | export DISPLAY=:0
|
4 |
|
5 | tvservice=`which tvservice >/dev/null ; echo $?`
|
6 | vcgencmd=`which vcgencmd >/dev/null ; echo $?`
|
7 |
|
8 | case "$1" in
|
9 | root-on)
|
10 | if [ $tvservice = 0 ]; then
|
11 |
|
12 | /opt/vc/bin/tvservice --preferred || echo "no tvservice"
|
13 |
|
14 | chvt 6
|
15 | chvt 7
|
16 | sleep 1
|
17 | fi
|
18 | ;;
|
19 | on)
|
20 |
|
21 | if [ $vcgencmd = 0 ]; then
|
22 |
|
23 | vcgencmd display_power 1 || echo "no vcgencmd"
|
24 | else
|
25 | for screen in `xrandr | awk '/ connected/{print $1}'`; do
|
26 | xrandr --output "$screen" --auto
|
27 | done
|
28 | fi
|
29 |
|
30 |
|
31 | xset dpms force on
|
32 |
|
33 |
|
34 | echo "on 0" | cec-client -s > /dev/null
|
35 | NOT_CEC_COMPATIBLE=$?
|
36 | if [ $NOT_CEC_COMPATIBLE -ne 0 ]; then
|
37 | ( sleep 5 ; echo "as" | cec-client -s > /dev/null ) &
|
38 | fi
|
39 | ;;
|
40 |
|
41 | off)
|
42 |
|
43 | echo "standby 0" | cec-client -s > /dev/null
|
44 |
|
45 |
|
46 | xset dpms force off
|
47 |
|
48 |
|
49 | if [ $vcgencmd = 0 ]; then
|
50 | vcgencmd display_power 0 || echo "no vcgencmd"
|
51 | else
|
52 | for screen in `xrandr | awk '/ connected/{print $1}'`; do
|
53 | xrandr --output "$screen" --off
|
54 | done
|
55 | fi
|
56 | ;;
|
57 | state)
|
58 | powerstate=`vcgencmd display_power 2>&1`
|
59 |
|
60 | if [[ $? != 0 ]] ; then
|
61 | listmonitors=`xrandr --listmonitors`
|
62 | if [[ $? != 0 ]]; then
|
63 | echo 'unavailable'
|
64 | elif [[ $listmonitors == "Monitors: 0" ]] ; then
|
65 | echo 'off'
|
66 | elif [[ $listmonitors == *"Monitors:"* ]] ; then
|
67 | echo 'on'
|
68 | else
|
69 | echo 'unavailable'
|
70 | fi
|
71 | elif [[ $powerstate == "display_power=0" ]] ; then
|
72 | echo 'off'
|
73 | else
|
74 | echo 'on'
|
75 | fi
|
76 | ;;
|
77 | subscribe)
|
78 | /opt/vc/bin/tvservice -M
|
79 | ;;
|
80 | screens)
|
81 | xrandr | awk '/ connected/{print $1}'
|
82 | ;;
|
83 | screens-on)
|
84 | for screen in ${@:2}; do
|
85 | xrandr --output "$screen" --auto
|
86 | done
|
87 | ;;
|
88 | screens-off)
|
89 | for screen in ${@:2}; do
|
90 | xrandr --output "$screen" --off
|
91 | done
|
92 | ;;
|
93 | screen-off)
|
94 | xrandr --output "$2" --off
|
95 | ;;
|
96 | screen-on)
|
97 | xrandr --output "$2" --auto ${@:3}
|
98 | ;;
|
99 | reverse-screen)
|
100 | xrandr --output "$2" --auto --rotate inverted
|
101 | if [ -z "$3" ]; then
|
102 | echo "No xinput device provided"
|
103 | else
|
104 | xinput set-prop "$3" "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
|
105 | fi
|
106 | ;;
|
107 | displays)
|
108 | ps -u $(id -u) -o pid= | \
|
109 | while read pid; do
|
110 | cat /proc/$pid/environ 2>/dev/null | tr '\0' '\n' | grep '^DISPLAY=:'
|
111 | done | grep -o ':[0-9]*' | sort -u
|
112 | ;;
|
113 | screenshot)
|
114 | if [ "$BOARD_ID" = 'rpi' ]; then
|
115 | nice -19 raspi2png --stdout -h 100
|
116 | else
|
117 | nice -19 scrot -t 20 -q 50 /tmp/screenshot.jpg || exit 1
|
118 | rm /tmp/screenshot.jpg
|
119 | cat /tmp/screenshot-thumb.jpg
|
120 | fi
|
121 | ;;
|
122 | waitForX)
|
123 | MAX=120
|
124 | CT=0
|
125 | while ! xdpyinfo >/dev/null 2>&1; do
|
126 | sleep 0.50s
|
127 | CT=$(( CT + 1 ))
|
128 | if [ "$CT" -ge "$MAX" ]; then
|
129 | echo "FATAL: $0: Gave up waiting for X server $DISPLAY"
|
130 | exit 1
|
131 | fi
|
132 | done
|
133 | ;;
|
134 | *)
|
135 | echo "Usage screen.sh {on|off|state|subscribe|screenshot|waitForX}"
|
136 | exit 1
|
137 | ;;
|
138 | esac
|
139 |
|
140 | exit 0
|