-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path,monitor-setup
executable file
·132 lines (102 loc) · 3.54 KB
/
,monitor-setup
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# I run 3 displays across 2 video adapters. Getting them all to work as I want (one of them is generally powered down, but not disconnected) was a struggle, but now works flawlessly and I tend to forget about the work involved.
#
# The key things I needed to find out:
#
# 1. figuring out how to run a script when a display was connected or disconnected. This needed to be in a udev .rules file somewhere
#
# ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/local/bin/monitor-hotplug.sh"
#
# 2. how to enumerate all possible video display names:
#
# DEVICES=$(find /sys/class/drm/*/status)
#
# 3. Writing the rest of the script.
#
# The last step is mostly left as an exercise for the reader. There are some good examples online; I'll put my current version here https://pastebin.com/V5yGgCbh for a couple of weeks.
#Adapt this script to your needs.
#
# HINT: use xrandr -q to discover xrandr's device names, which do not map trivially to the device names in /sys/class/drm/*
#
DEVICES=$(find /sys/class/drm/*/status)
#inspired by /etc/acpd/lid.sh and the function it sources
displaynum=`ls /tmp/.X11-unix/* | sed s#/tmp/.X11-unix/X##`
display=":$displaynum.0"
export DISPLAY=":$displaynum.0"
# from https://wiki.archlinux.org/index.php/Acpid#Laptop_Monitor_Power_Off
export XAUTHORITY=$(ps -C Xorg -f --no-header | sed -n 's/.*-auth //; s/ -[^ ].*//; p')
#this while loop declare the $HDMI1 $DVID2 $HDMI2 and others if they are plugged in
while read l
do
dir=$(dirname $l);
status=$(cat $l);
dev=$(echo $dir | cut -d\- -f 2-);
echo "Device: $dev"
if [ $(expr match $dev "HDMI") != "0" ]
then
# REMOVE THE -X- part from HDMI-X-n
dev=HDMI${dev#HDMI-?-}
elif [ $(expr match $dev "DVI") != "0" ]
then
# REMOVE THE -X- part from HDMI-X-n
dev=DVI${dev#DVI-?-}
else
dev=$(echo $dev | tr -d '-')
fi
if [ "connected" == "$status" ]
then
echo $dev "connected"
declare $dev="yes";
fi
done <<< "$DEVICES"
logmsg() {
logger --rfc5424=notq,notime,nohost --msgid MHOT "$*"
}
# There are 3 possible monitors:
#
# HDMI-1 -> right hand
# DVI-D-2 -> left hand ASUS monitor
# HDMI-1-0 -> TV
#
if [ -z "$DVI2" -a -z "$HDMI2" ] ; then
#
# wierd scenario ... ASUS monitors not connected
#
if [ ! -z "$HDMI1" ] ; then
#
# TV is connected
#
logmsg tv no asus
else
logmsg no tv no asus
fi
elif [ -z "$DVI2" -a ! -z "$HDMI2" ] ; then
# left ASUS connected
if [ ! -z "$HDMI1" ] ; then
logmsg left and tv
xrandr --setprovideroutputsource 1 0
xrandr --output HDMI-1 --auto --primary --output HDMI-1-0 --auto --right-of HDMI-2
logmsg left right with tv
else
logmsg left
fi
elif [ ! -z "$DVI2" -a -z "$HDMI2" ] ; then
# right ASUS connected
if [ ! -z "$HDMI1" ] ; then
logmsg right
else
logmsg right and tv
fi
elif [ ! -z "$DVI2" -a ! -z "$HDMI2" ] ; then
# both left and right ASUS connected
if [ -z "$HDMI1" ] ; then
xrandr --output HDMI-1-0 --auto --primary --output DVI-1 --auto --right-of HDMI-1
logmsg left right no tv
else
xrandr --setprovideroutputsource 1 0
#xrandr --newmode "1920x1200_60.00" 154.00 1920 1968 2000 2080 1200 1203 1209 1235 +hsync -vsync
#xrandr --output DVI-D-2 --mode "1920x1200_60.00"
xrandr --output HDMI-1-0 --auto --output DVI-1 --auto --left-of HDMI-1-0 --output HDMI-1 --primary --auto --left-of DVI-1
logmsg left right with tv
fi
fi