-
Notifications
You must be signed in to change notification settings - Fork 23
/
display
executable file
·193 lines (166 loc) · 4.42 KB
/
display
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
declare INTEL_FILE="/usr/share/X11/xorg.conf.d/20-intel.conf"
declare XORG_FILE="/usr/share/X11/xorg.conf.d/01-dummy-monitor.conf"
main() {
case $1 in
create)
createDummyDisplayIntel ${@:2}
;;
editIntel)
editIntel
;;
setRes)
setRes ${@:2}
;;
calcRes)
calcRes ${@:2}
;;
clean)
clean ${@:2}
;;
*)
help
;;
esac
}
createDummyDisplayIntel() {
count=$1
if [ -z "$count" ];then
count=1
fi
if [ "$EUID" -ne 0 ]; then
echo We may need sudo permissions to write the following file \"$INTEL_FILE\"
echo
fi
sudo tee $INTEL_FILE > /dev/null <<TEXT
Section "Device"
Identifier "intelgpu0"
Driver "intel"
Option "VirtualHeads" "$count"
EndSection
TEXT
echo -e "Result\033[0;33m"
cat $INTEL_FILE
echo -e "\033[0m"
echo Restart is needed to apply changes.
}
createDummyDisplayXorg() {
count=$1
if [ -z "$count" ];then
count=1
fi
if [ "$EUID" -ne 0 ]; then
echo We may need sudo permissions to write the following file \"$XORG_FILE\"
echo
fi
sudo tee $XORG_FILE > /dev/null <<TEXT
Section "Device"
Identifier "Configured Video Device"
Driver "dummy"
EndSection
Section "Monitor"
Identifier "Configured Monitor"
HorizSync 31.5-48.5
VertRefresh 50-70
EndSection
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1024x800"
EndSubSection
EndSection
TEXT
echo -e "Result\033[0;33m"
cat $XORG_FILE
echo -e "\033[0m"
echo Restart is needed to apply changes.
}
editIntel() {
sudo vim $INTEL_FILE
}
setRes() {
virtual=$1
width=$2
height=$3
modeline=$(cvt $width $height 20 | grep "Modeline" | cut -d' ' -f 2-17)
modeName=$(echo $modeline | cut -d' ' -f 1)
modeline=${modeline//\"}
modeName=${modeName//\"}
newModeName=$(echo $modeName | cut -d'_' -f1)
modeline=${modeline/$modeName/$newModeName}
modeName=$newModeName
primary=$(xrandr| grep primary | cut -d ' ' -f 1)
echo Creating \"$modeName\" on \"$virtual\"
xrandr --newmode $modeline
xrandr --addmode $virtual $modeName
xrandr --output $virtual --mode $modeName --auto --right-of $primary
}
calcRes() {
w_width=$1
w_height=$2
w_inches=$3
f_xrandr=$(xrandr | grep primary)
f_res=$(echo $f_xrandr | cut -d' ' -f 4)
f_res=(${f_res//[+x]/ })
f_dimens=$(echo $f_xrandr | cut -d' ' -f 13,15)
f_dimens=(${f_dimens//m/})
f_width=${f_res[0]}
f_height=${f_res[1]}
f_inches=$(bc <<< "scale=2; (sqrt( ${f_dimens[0]}^2 + ${f_dimens[1]}^2 ) * 0.0393701)/1")
proportion=$(bc <<< "scale=4; $w_inches / $f_inches")
v_width=$(bc <<< "scale=0; ($w_width * $proportion)/1")
v_height=$(bc <<< "scale=0; ($w_height * $proportion)/1")
rv_vert_width=$f_width
rv_vert_height=$(bc <<< "scale=0; ($f_height + $v_height)/1")
rv_hori_width=$(bc <<< "scale=0; ($f_width + $v_width)/1")
rv_hori_height=$f_height
echo Proportion $proportion
echo " Width x Height Inches"
echo " fisical ${f_width}x${f_height} $f_inches"
echo " wanted ${w_width}x${w_height} $w_inches"
echo "---------------------------- Virtual"
echo " virtual ${v_width}x${v_height}"
echo "---------------------------- Resize + virtual"
echo " vertical ${rv_vert_width}x${rv_vert_height}"
echo "horizontal ${rv_hori_width}x${rv_hori_height}"
}
clean() {
display=VIRTUAL$1
mode=$(xrandr | grep -A 1 $display | grep -Po "\d+x\d+")
if [ -z "$mode" ]; then
echo "Can't find a valid mode"
exit 1
fi
echo "display $display"
echo " mode $mode"
for m in $mode ; do
echo "Try to remove $m"
xrandr --output $display --off
xrandr --delmode $display $m
xrandr --rmmode $m
done
xrandr -s 0
}
help() {
cat <<TEXT
Virtual Display
Commands
create <n>
- creates n virtual displays
example: $0 create 4
setRes <display> <width> <height>
- set resolution for a virtual display
example: $0 setRes VIRTUAL1 800 600
calcRes <width> <heigh> <inches>
- calculate possible resolutions for a device.
As devices may have same or even greater resolutions compared to a normal display, de idea is to use a lower resolution for this device. This leads to a better visualization and performance.
clean <virtual display number>
- clean modes and resolution, also turns virtual display off
example: $0 clean 1
TEXT
}
main $@