-
Notifications
You must be signed in to change notification settings - Fork 81
/
monitor_layout.sh
executable file
·99 lines (75 loc) · 1.96 KB
/
monitor_layout.sh
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
#!/bin/bash
XRANDR=$(which xrandr)
MONITORS=( $( ${XRANDR} | awk '( $2 == "connected" ){ print $1 }' ) )
NUM_MONITORS=${#MONITORS[@]}
TITLES=()
COMMANDS=()
function gen_xrandr_only()
{
selected=$1
cmd="xrandr --output ${MONITORS[$selected]} --auto "
for entry in $(seq 0 $((${NUM_MONITORS}-1)))
do
if [ $selected != $entry ]
then
cmd="$cmd --output ${MONITORS[$entry]} --off"
fi
done
echo $cmd
}
declare -i index=0
TILES[$index]="Cancel"
COMMANDS[$index]="true"
index+=1
for entry in $(seq 0 $((${NUM_MONITORS}-1)))
do
TILES[$index]="Only ${MONITORS[$entry]}"
COMMANDS[$index]=$(gen_xrandr_only $entry)
index+=1
done
##
# Dual screen options
##
for entry_a in $(seq 0 $((${NUM_MONITORS}-1)))
do
for entry_b in $(seq 0 $((${NUM_MONITORS}-1)))
do
if [ $entry_a != $entry_b ]
then
TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}"
COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \
--output ${MONITORS[$entry_b]} --auto --left-of ${MONITORS[$entry_a]}"
index+=1
fi
done
done
##
# Clone monitors
##
for entry_a in $(seq 0 $((${NUM_MONITORS}-1)))
do
for entry_b in $(seq 0 $((${NUM_MONITORS}-1)))
do
if [ $entry_a != $entry_b ]
then
TILES[$index]="Clone Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}"
COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \
--output ${MONITORS[$entry_b]} --auto --same-as ${MONITORS[$entry_a]}"
index+=1
fi
done
done
##
# Generate entries, where first is key.
##
function gen_entries()
{
for a in $(seq 0 $(( ${#TILES[@]} -1 )))
do
echo $a ${TILES[a]}
done
}
# Call menu
SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -a 0 -no-custom | awk '{print $1}' )
# Call xrandr
$( ${COMMANDS[$SEL]} )