-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplaymenu
executable file
·115 lines (103 loc) · 2.99 KB
/
displaymenu
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
#! /bin/bash
set -e
#TODO: do xrandr queries only once and reuse the results.
command="xrandr"
function connectedDisplays {
xrandr | grep " connected" | cut -d " " -f 1
}
# List available resolutions for display identifier
# given as a first parameter
function resolutions {
local dp="$(xrandr | grep -i "$1" -A 40 | grep -v "$1")"
if [ "$(echo "$dp" | grep connected | wc -l)" -eq 0 ]; then
# Display was the last one listed
echo "$dp"
else
# Display was not the last one. Cut out the rest of the lines
echo "$dp" | grep -B 40 -m 1 connected | grep -v connected
fi
}
# TODO: Find a better way to do this.
noOfActiveDisplays="$( \
xrandr --listactivemonitors \
| grep -i 'Monitors:' \
| sed -e 's/Monitors: //' \
)"
function isOn {
xrandr --listactivemonitors | grep $1 | wc -l
}
display=$(connectedDisplays | dmenu -i -l 10)
command="$command --output $display"
another=false
if [ "$noOfActiveDisplays" -eq 2 ]; then
another="$( \
xrandr --listactivemonitors \
| grep -vi 'Monitors:' \
| grep -v $display \
| rev \
| cut -d ' ' -f 1 \
| rev \
)"
fi
# Select another display.
# echo $another if it has value, othervise perform a dmenu prompt
function selectAnother {
if [ "$another" ]; then
echo "$another"
else
connectedDisplays | grep -v "$display" | dmenu -i -l 10
fi
}
options="cancel"
if [ "$(isOn $display)" -eq 1 ]; then
options="set resolution\nrotate left\nrotate right\ninvert\n$options"
if [ "$noOfActiveDisplays" -gt 1 ]; then
if [ "$noOfActiveDisplays" -gt 2 ]; then
options="mirror ...\n$options"
options="move above ...\n$options"
options="move bellow ...\n$options"
options="move left of ...\n$options"
options="move right of ...\n$options"
else
options="mirror $another \n$options"
options="move above $another \n$options"
options="move bellow $another \n$options"
options="move left of $another \n$options"
options="move right of $another \n$options"
fi
options="turn off\n$options"
fi
else
options="turn on\n$options"
fi
opt=$(echo -e $options | dmenu -l 10)
case "$opt" in
"cancel")
exit 0 ;;
"turn on")
command="$command --auto" ;;
"turn off")
command="$command --off" ;;
"rotate left")
command="$command --rotate left" ;;
"rotate right")
command="$command --rotate right" ;;
"invert")
command="$command --rotate inverted" ;;
"set resolution")
resolution="$(resolutions $display | dmenu -l 10 | cut -d " " -f 4)"
command="$command --mode $resolution" ;;
"move right of"*)
command="$command --right-of $(selectAnother)" ;;
"move left of"*)
command="$command --left-of $(selectAnother)" ;;
"move above"*)
command="$command --above $(selectAnother)" ;;
"move bellow"*)
command="$command --bellow $(selectAnother)" ;;
"mirror"*)
command="$command --same-as $(selectAnother)" ;;
esac
if [ "$(echo -e "no\nyes" | dmenu -i -p "run: $command")" == "yes" ]; then
echo "$command" | sh
fi