/
repomenue_randr
executable file
·134 lines (121 loc) · 3.43 KB
/
repomenue_randr
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
#!/usr/bin/env bash
# -*-coding:utf-8 -*-
# Auto updated?
# Yes
#File :
# repomenue_randr
#Author:
# The-Repo-Club [wayne6324@gmail.com]
#Github:
# https://github.com/The-Repo-Club/
#
# Created:
# Wed 10 March 2021, 12:34:47 PM [GMT]
# Modified:
# Fri 21 January 2022, 02:29:56 PM [GMT]
#
# Description:
# <Todo>
#
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 | repomenu -c -l 10 -w -600 -i -h -1 -bw 4)
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 repomenu prompt
function selectAnother {
if [ "$another" ]; then
echo "$another"
else
connectedDisplays | grep -v "$display" | repomenu -c -l 10 -w -600 -i -h -1 -bw 4
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 below ...\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 below $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 | repomenu -c -l 10 -w -600 -i -h -1 -bw 4)
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 | repomenu -c -l 10 -w -600 -i -h -1 -bw 4 | 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 below"*)
command="$command --below $(selectAnother)" ;;
"mirror"*)
command="$command --same-as $(selectAnother)" ;;
esac
if [ "$(echo -e "no\nyes" | repomenu -c -l 10 -w -600 -i -h -1 -bw 4 -q "run: $command")" == "yes" ]; then
echo "$command" | sh
fi