-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvoid-xrandr
executable file
·254 lines (227 loc) · 7.49 KB
/
void-xrandr
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
#shellcheck disable=SC2145,SC2001,SC2188,SC2015,SC2155,SC2317,SC2320,SC2291,SC2034,SC2120,SC2086,SC2319
#shellcheck disable=SC2016,SC2154,SC2207,SC2166,SC2128,SC2059,SC2140,SC2031,SC2030,SC2036,SC2119,SC2027
# void-install
# Created: 2022/12/24
# Altered: 2024/03/08
#
# Copyright (c) 2022-2024, Vilmar Catafesta <vcatafesta@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
############################################################################
#export LANGUAGE=pt_BR
export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN=void-xrandr
#debug
export PS4='${red}${0##*/}${green}[$FUNCNAME]${pink}[$LINENO]${reset} '
#set -x
#set -e
shopt -s extglob
#system
readonly APP="${0##*/}"
readonly _VERSION_='1.0.18-20240308'
readonly distro=$(uname -n)
readonly DEPENDENCIES=(xrandr cvt tput dialog awk grep sed gettext)
readonly sep='\xe2\x94\x82'
readonly ccabec="$APP v${_VERSION_} - https://github.com/voidlinux-br/void-installer"
sh_setconf() {
COL_NC='\e[0m' # No Color
COL_LIGHT_GREEN='\e[1;32m'
COL_LIGHT_RED='\e[1;31m'
TICK="${white}[${COL_LIGHT_GREEN}✓${COL_NC}${white}]"
CROSS="${white}[${COL_LIGHT_RED}✗${COL_NC}${white}]"
INFO="[i]"
# shellcheck disable=SC2034
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
OVER="\\r\\033[K"
DOTPREFIX=" ${black}::${reset} "
}
inkey() {
read -t "$1" -n1 -r -p "" lastkey
}
sh_checkDependencies() {
local d
local errorFound=0
declare -a missing
for d in "${DEPENDENCIES[@]}"; do
[[ -n $(command -v "$d") ]] && { :; } || {
log_msg "$(gettext "ERRO: Não foi possível encontrar o comando") ${cyan}'$d'${reset}"
missing+=("$d")
errorFound=1
}
done
if ((errorFound)); then
echo "${yellow}$(gettext "---------------IMPOSSÍVEL CONTINUAR---------------")"
echo "${red}$(gettext "Este script precisa dos comandos listados acima")"
echo "$(gettext "Instale-os e/ou certifique-se de que estejam em seu") \$PATH"
echo "${yellow}$(gettext "---------------IMPOSSÍVEL CONTINUAR---------------")"
die "Aborted!"
fi
}
sh_setvarcolors() {
if tput setaf 1 &>/dev/null; then
tput sgr0 # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
rst=$(tput sgr0)
rs=$(tput sgr0)
blue=$(tput setaf 33)
cyan=$(tput setaf 37)
green=$(tput setaf 2)
orange=$(tput setaf 166)
purple=$(tput setaf 125)
red=$(tput setaf 124)
violet=$(tput setaf 61)
white=$(tput setaf 15)
yellow=$(tput setaf 136)
pink=$(tput setaf 129)
black=$(tput setaf 0)
fi
}
log_msg() {
local retval="${PIPESTATUS[0]}"
local pcount=$#
((pcount >= 2)) && {
retval=$1
shift
}
[[ $retval -eq 0 ]] && printf " %b %s\\n" "${TICK}" "${*}" || printf " %b %s\\n" "${CROSS}" "${*}"
}
die() {
local msg=$1
shift
printf " %b %s\\n" "${CROSS}" "${bold}${red}${msg}"
exit 1
}
sh_setdevboy() {
umc 2560 1080 50 --rbt
# 2560x1080x49.94 @ 55.239kHz
#Modeline "2560x1080x49.94" 150.250000 2560 2608 2640 2720 1080 1083 1087 1106 +HSync -VSync
xrandr --verbose --newmode "2560x1080x49.94-umc" 150.250000 2560 2608 2640 2720 1080 1083 1087 1106 +HSync -VSync
xrandr --verbose --addmode HDMI-1 "2560x1080x49.94-umc"
umc 2560 1050 50 --rbt
# 2560x1050x49.93 @ 53.676kHz
#Modeline "2560x1050x49.93" 146.000000 2560 2608 2640 2720 1050 1053 1057 1075 +HSync -VSync
xrandr --verbose --newmode "2560x1050x49.93-umc" 146.000000 2560 2608 2640 2720 1050 1053 1057 1075 +HSync -VSync
xrandr --verbose --addmode HDMI-1 "2560x1050x49.93-umc"
#umc 2560 1050 75 --rbt
# 2560x1050x74.93 @ 81.526kHz
# Modeline "2560x1050x74.93" 221.750000 2560 2608 2640 2720 1050 1053 1057 1088 +HSync -VSync
#xrandr --verbose --newmode "2560x1050x74.93" 221.750000 2560 2608 2640 2720 1050 1053 1057 1088 +HSync -VSync
#xrandr --verbose --addmode HDMI-1 "2560x1050x74.93"
umc 2560 1080 50 -d
# 2560x1080x50.00 @ 111.300kHz
#Modeline "2560x1080x50.00" 391.776000 2560 2760 3040 3520 1080 1082 1084 1113 -HSync +VSync doublescan
xrandr --verbose --newmode "2560x1080x50.00-umc" 391.776000 2560 2760 3040 3520 1080 1082 1084 1113 -HSync +VSync doublescan
xrandr --verbose --addmode HDMI-1 "2560x1080x50.00-umc"
}
sh_getoutput() {
local -a arr=()
local -a aOutput
local -a aConnect
local nchoice nExit
local x
declare -g output
# aOutput=('VGA-1' 'DVI-1' 'HDMI-1')
# mapfile -t aOutput <<< "$(xrandr | grep " connected " | awk '{ print$1 }')" #conectado
mapfile -t aOutput <<<"$(xrandr | grep "connected " | awk '{ print$1 }')" #todos
mapfile -t aConnect <<<"$(xrandr | grep "connected " | awk '{ print$2 }')" #todos
for x in "${aOutput[@]}"; do
arr[n++]="$x"
arr[n++]=$(printf "$sep%-30s" "${aConnect[nc]}")
((++nc))
done
while :; do
output=$(dialog \
--stdout \
--colors \
--clear \
--backtitle "$ccabec" \
--title "$APP $(getttext "resolução")" \
--cancel-label "$(gettext "Cancelar")" \
--ok-label "$(gettext "Aceitar")" \
--menu "\n$(gettext "Escolha o dispositivo para configuração"):" \
0 0 0 \
"${arr[@]}")
nExit=$?
if ((nExit)); then
die "$(gettext "Cancelado!")"
fi
break
done
}
sh_setrand() {
local -a arr=()
local -a aHmode
local -a aVmode
local -a aRefresh
local modeline mode
local nchoice nExit
local x y
# aVmode=('1080' '1080' '1080')
aHmode=('2560 1080' '1920 1080' '1680 1080')
aRefresh=('33' '44' '50' '60' '75')
for x in "${aHmode[@]}"; do
for y in "${aRefresh[@]}"; do
arr[n++]="$x $y"
arr[n++]=$(printf "$sep%-8s$sep%s" "$output" "$(cvt $x $y)")
done
done
while :; do
nchoice=$(dialog \
--stdout \
--colors \
--clear \
--backtitle "$ccabec" \
--title "$APP $(getttext "resolução")" \
--ok-label "$(gettext "Adicionar")" \
--cancel-label "$(gettext "Cancelar")" \
--menu "\n$(gettext "Escolha o dispositivo para configuração"):" \
0 0 0 \
"${arr[@]}")
nExit=$?
[[ "$nExit" -eq 1 ]] && die "$(gettext "Cancelado!")"
modeline=$(cvt $nchoice | grep Modeline | sed 's/Modeline //')
modeline="${modeline%%_*}-custom ${modeline#* }"
mode=$(awk '{print $1}' <<<"$modeline")
modeline="${modeline//\"/}"
mode="${mode//\"/}"
echo "Modeline : $modeline"
echo "Mode : $mode"
case $nExit in
0) #add
xrandr --verbose --newmode $modeline
xrandr --verbose --addmode $output $mode
inkey 2
;;
3) # remove
xrandr --verbose --delmode $output $mode
inkey 2
;;
esac
done
}
sh_setconf
sh_setvarcolors
sh_checkDependencies
sh_getoutput
sh_setrand