-
Notifications
You must be signed in to change notification settings - Fork 115
/
check-monitors
executable file
·54 lines (47 loc) · 1.76 KB
/
check-monitors
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
#!/bin/sh
# Check monitors and use xrandr to turn on the appropriate one(s).
# Ideally, this would be run from /etc/pm/sleep.d/check-monitors
# upon resume from suspend., something like this:
# case "${1}" in
# resume|thaw)
# check-monitors
# ;;
# esac
# Unfortunately, /etc/pm/sleep.d/check-monitors isn't called reliably
# on resume, and neither is any other script. So it might be best
# to bind this to a key so that if you dock your laptop then wake it up,
# you can call it with a function key even if you can't see the screen
# to put focus in a window.
#
# This leaves debugging info in /tmp/check-monitors
# because if it fails, you won't be able to see any error output
# but maybe you can shell in and read what happened.
DEBUGFILE=/tmp/check-monitors
date >>$DEBUGFILE
getmonitor() {
xrandr | grep $1 | sed 's/ .*$//'
}
# Check whether an HDMI monitor is connected: returns 0 on success
xrandr | grep HDMI | grep " connected " >>$DEBUGFILE 2>&1
if [ $? -eq 0 ]; then
echo "==== Choosing HDMI" >>$DEBUGFILE
xrandr --output $(getmonitor LVDS) --off
xrandr --output $(getmonitor VGA) --off
xrandr --output $(getmonitor HDMI) --auto
else
xrandr | grep VGA | grep " connected " >>$DEBUGFILE
if [ $? -eq 0 ]; then
echo "==== Choosing VGA" >>$DEBUGFILE 2>&1
xrandr --output $(getmonitor HDMI) --off
xrandr --output $(getmonitor LVDS) --off
xrandr --output $(getmonitor VGA) --auto
else
# Fall back on the built-in laptop display, LVDS1
echo "==== Choosing built-in display" >>$DEBUGFILE
xrandr --output $(getmonitor VGA) --off
xrandr --output $(getmonitor HDMI) --off
xrandr --output $(getmonitor LVDS) --auto
fi
fi
xrandr >>$DEBUGFILE
echo "=====" >>$DEBUGFILE