forked from marcan/blitzloop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblitz_mirrored.sh
More file actions
executable file
·70 lines (63 loc) · 2.42 KB
/
blitz_mirrored.sh
File metadata and controls
executable file
·70 lines (63 loc) · 2.42 KB
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
#!/bin/bash
# a wrapper script to run blitzloop on a multi-monitor systems
# where all monitors show the same output (mpv window). it is
# assumed that the browser window (to show and manipulate the
# playlist) is opened on external computer/smartphone
#
# requires X11 as it uses xrandr
#
# things it does:
# - save current monitor layout
# - mirror all monitors (according to the one with greatest resolution)
# - start blitzloop
# - when blitzloop quits: restore the original layout
#
shopt -s lastpipe
echo "Saving current screen layout.."
original_layout=$(
xrandr | awk 'BEGIN {printf "xrandr"
orientation="normal"}
$2 != "connected" { next }
{if ($3 == "primary") {output=$1" --primary"
modepan=$4
if ($5 ~ /^(left|right|inverted)/) { orientation=$5 }
}
else
{output=$1
modepan=$3
if ($4 ~ /^(left|right|inverted)/) { orientation=$4 }
}}
{mode=modepan
sub(/\+.*/, "", mode)
# strip offset from mode
}
{printf " --output %s --mode %s --scale 1 --panning %s --rotate %s",
output, mode, modepan, orientation}
END {print ""}'
)
# monitor with largest number of pixels will be used as a "master"
# others will mirror it
xrandr | sed 's/ primary / /' | grep connected | \
perl -lane 'next unless @F[1] eq "connected";
$res=$area=@F[2];
$area =~ s/([0-9]+)x([0-9]+)\+.*/$1*$2/e;
$res =~ s/\+.*//;
printf "%s %s %s\n", $area, $res, @F[0]' | \
sort -nrk 1 | head -1 | read _ master_resolution master_output
echo "master out: ${master_output} ($master_resolution)"
blitzloop_layout=$(
xrandr | sed 's/ primary / /' | awk -v master_out="${master_output}" -v master_res="${master_resolution}" '
BEGIN {printf "xrandr "}
$2 != "connected" || $1 == master_out { next }
{ output=$1
printf " --output %s --same-as %s --scale-from %s",
output, master_out, master_res
}
END {print ""}
'
)
${blitzloop_layout}
# add options if required (run blitzloop -h to list them)
blitzloop
echo "Restoring original screen layout.."
${original_layout}