monitor-setup: Support resolution and refresh rate
Also place multiple monitors side-by-side.
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Small script using `xrandr` and `fzf` to quickly select connected monitors.
|
||||
#
|
||||
# TODO:
|
||||
# - Add possibility to not only mirror onto all outputs but use the total
|
||||
# screen space.
|
||||
################################################################################
|
||||
# monitor setup script using xrandr and fzf to manage multiple monitors and/or
|
||||
# set resolutions and refresh rates.
|
||||
|
||||
command -v xrandr &>/dev/null || exit 1
|
||||
command -v fzf &>/dev/null || exit 1
|
||||
@@ -62,9 +56,51 @@ primary="$(<<<"$formatted" \
|
||||
# Build the `xrandr` command
|
||||
xrandr_cmd=(xrandr)
|
||||
|
||||
# Keep track of width to place the outputs side-by-side
|
||||
width=0
|
||||
|
||||
for out in "${selected[@]}"; do
|
||||
xrandr_cmd+=(--output "$out" --rotate normal --auto)
|
||||
xrandr_cmd+=(--output "$out" --rotate normal)
|
||||
[[ $out != $primary ]] || xrandr_cmd+=(--primary)
|
||||
|
||||
all_res="$(<<<"$xrandr_q" sed -En "
|
||||
# all resolution lines for selected output (+ junk lines first and last)
|
||||
/$out/,/^[^ ]/ {
|
||||
# on lines that contain a resolution
|
||||
/^ / {
|
||||
# only print the resolution
|
||||
s/^ *([^ ]*).*/\1/p
|
||||
}
|
||||
}"
|
||||
)"
|
||||
res="$(<<<"$all_res" fzf --cycle --header "Select resolution for $out")"
|
||||
[[ $res ]] || exit 1
|
||||
|
||||
xrandr_cmd+=(--mode "$res")
|
||||
|
||||
rates="$(<<<"$xrandr_q" sed -En "
|
||||
# all resolution lines for selected output
|
||||
/$out/,/^[^ ]/ {
|
||||
# on line with the selected resolution
|
||||
/^ *$res/ {
|
||||
# remove resolution and whitespace
|
||||
s/^ *$res *//
|
||||
# fix formatting when preferred mode is not the current one
|
||||
s/ \+/+/
|
||||
# put each rate on a new line
|
||||
s/ +/\n/g
|
||||
|
||||
p
|
||||
}
|
||||
}"
|
||||
)"
|
||||
rate="$(<<<"$rates" fzf --cycle --header "Select refresh rate for $out")"
|
||||
[[ $rate ]] || exit 1
|
||||
rate="${rate%%[*+]*}" # remove current and preferred mode indicator
|
||||
xrandr_cmd+=(--rate "$rate")
|
||||
|
||||
xrandr_cmd+=(--pos "${width}x0")
|
||||
: "$((width+=${res%%x*}))"
|
||||
done
|
||||
|
||||
for out in "${non_selected[@]}"; do
|
||||
|
||||
Reference in New Issue
Block a user