-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_setscreens.sh
executable file
·44 lines (41 loc) · 1.21 KB
/
make_setscreens.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
#!/usr/bin/env bash
source "$(dirname "$0")/commons.sh" || exit 1
[[ -x "${GET_AVAIL_SCREENS:=$(dirname "$0")/availscreens.sed}" ]] \
|| { error 'availscreen.sed script not found beside setscreens.sh.' && exit 1; }
BLACKLISTED="VGA-1-2"
BLACKLISTED=${BLACKLISTED:+"(${BLACKLISTED//,/|})"}
THRESH=${THRESH:-.75}
POS=${POS:-"--left-of"}
command xrandr \
| $GET_AVAIL_SCREENS \
| sed 's/ *+\?$//' \
| awk '{ $5 = $4; $4 = $2*$3 } 1' \
| sort -rnk2 \
| awk -v T="$THRESH" -v P="$POS" \
'NR == 1 {
N = P " " $1
M = $4
$4 = ""
print
}
NR != 1 {
if ($4 < T*M) {
$4 = "--off"
print
next
} else {
$4 = N
N = P " " $1
}
print
}' \
| sed -E '1i\command xrandr
/--off/!{
s/ /x/2
s/ / --mode /
}
s/^/--output /
s/ [0-9]+ [0-9]+ / /' \
| sed -zE 's/\n/ /g
s/$/\n/
s/--output [^ ]+ /&--primary /'