-
Notifications
You must be signed in to change notification settings - Fork 1
/
.dual-monitor
executable file
·96 lines (90 loc) · 3.01 KB
/
.dual-monitor
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
#!/bin/bash
set -e
# Default mutable values. Change it if you need
WIDTH=1280
HEIGHT=800
REFRESH=60
PRIMARY_OUTPUT=LVDS-1
VIRTUAL_OUTPUT=VGA-1
# Default immutable values. Don't touch it!
CREATE=false
ENABLE=false
DISABLE=false
# Get custom initial parameters
while getopts "cdeh:p:r:v:w:" option; do
case "${option}" in
c) CREATE=true;;
d) DISABLE=true;;
e) ENABLE=true;;
h) HEIGHT=${OPTARG};;
p) PRIMARY_OUTPUT=${OPTARG};;
r) REFRESH=${OPTARG};;
v) VIRTUAL_OUTPUT=${OPTARG};;
w) WIDTH=${OPTARG};;
esac
done
NAME="${WIDTH}x${HEIGHT}"
if [ ${CREATE} == true ]; then
echo "Creating a virtual display..."
# Extract and output generated modeline parameters
MODELINE="$(gtf ${WIDTH} ${HEIGHT} ${REFRESH} \
| sed -n 's/.*Modeline ".\+" \(.*\)/\1/p')"
printf "
Name: ${NAME}
Primary output: ${PRIMARY_OUTPUT}
Virtual output: ${VIRTUAL_OUTPUT}
Modeline: ${MODELINE}\n\n"
# Generate new mode based on the modeline
echo "[1/3] - Creating a mode with modeline args"
xrandr --newmode "${NAME}" ${MODELINE}
# Add the desired mode to our disconnected output
echo "[2/3] - Adding the mode to the output"
xrandr --addmode "${VIRTUAL_OUTPUT}" "${NAME}"
# Enable the virtual monitor using the newly added mode
echo "[3/3] - Enabling the newly created mode"
xrandr --output "${VIRTUAL_OUTPUT}" \
--mode "${NAME}" \
--right-of "${PRIMARY_OUTPUT}"
echo "Successfully created!"
elif [ ${DISABLE} == true ]; then
echo "Disabling the virtual output..."
# Disconnect the output to be able to delete a mode if any
echo "[1/3] - Disconnecting the output"
xrandr --output "${VIRTUAL_OUTPUT}" --off
# Deleting the mode of the disconnected output
echo "[2/3] - Deleting the output mode"
xrandr --delmode "${VIRTUAL_OUTPUT}" "${NAME}" || :
# Deleting the display port which was using by the mode
echo "[3/3] - Deleting the display port"
xrandr --rmmode "${NAME}" || :
echo "Successfully disabled!"
elif [ ${ENABLE} == true ]; then
echo "Starting the VNC server..."
HOST_IP="$(hostname -I | head -n1 | awk '{print $1;}')"
x11vnc -listen "${HOST_IP}" \
-clip "xinerama1" \
-nocursorpos \
-nocursorshape
else
printf "
PRIMARY COMMANDS (without args):
-c – create a mode for a virtual output
-e – enable a mode of a virtual output
-d – disable a mode of a virtual output
CONFIGURATION:
-h – height of a virtual screen
default '800'
used with the '-c' and '-d' flags
-p – primary output name
default 'LVDS-1'
used with the '-c' flag
-r – refresh frequency of a virtual screen
default '60'
used with the '-c' flag
-v – virtual output name
default 'VGA-1'
used with the '-c' and '-d' flags
-w – width of a virtual screen
default '1280'
used with the '-c' and '-d' flags\n\n"
fi