diff --git a/_sync.sh b/_sync.sh index 348389b..f55d6aa 100755 --- a/_sync.sh +++ b/_sync.sh @@ -12,6 +12,7 @@ dirs=( "/var/unbound:." "$HOME/bhyve:." "$HOME/ansible:." + "$HOME/xrandr:." "$HOME/.config/i3:i3wm" "$HOME/.config/i3status:i3wm" ) diff --git a/xrandr/README.md b/xrandr/README.md new file mode 100644 index 0000000..caa4ad7 --- /dev/null +++ b/xrandr/README.md @@ -0,0 +1,23 @@ +# xrandr + +framework of bash scripts to implement KDE's display configurator. + +## config + +```config.sh``` - set here your primary output and default resoluton + +## commands + +```default.sh``` - turn off external outputs and revert back to default resolution + +```extend-right.sh``` - create "right" monitor with its maximum resolution available + +```unify.sh``` - set both primary and external (secondary) outputs to same resolution, and output contents from primary to secondary (xrandr's --same-as option) + +## utils + +```vga-or-hdmi.sh``` - will output VGA or HDMI output that is available. + +```max-res.sh``` - determine biggest resolution available given by output name + +```same-res.sh``` - find equal resolution of two outputs \ No newline at end of file diff --git a/xrandr/config.sh b/xrandr/config.sh new file mode 100644 index 0000000..98841a9 --- /dev/null +++ b/xrandr/config.sh @@ -0,0 +1,2 @@ +export primary="LVDS-1" +export defalt_res="1366x768" \ No newline at end of file diff --git a/xrandr/default.sh b/xrandr/default.sh new file mode 100755 index 0000000..0037a96 --- /dev/null +++ b/xrandr/default.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +source config.sh + +xrandr --output VGA-1 --off +xrandr --output HDMI-1 --off +xrandr --output DP-1 --off + +xrandr --output $primary --mode $defalt_res \ No newline at end of file diff --git a/xrandr/enum-res.sh b/xrandr/enum-res.sh new file mode 100755 index 0000000..1ad5b12 --- /dev/null +++ b/xrandr/enum-res.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +device="$1" +output=$(xrandr) + +begin=$(echo "$output" | awk '$1=="'$device'" { print NR }') +end=$(echo "$output" | awk 'NR>'$begin' { if ($1 ~ /\d*x\d*/) {} else { print NR; exit } }') + +echo "$output" | awk "NR > $begin && NR < $end" diff --git a/xrandr/extend-right.sh b/xrandr/extend-right.sh new file mode 100755 index 0000000..866a61c --- /dev/null +++ b/xrandr/extend-right.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +source config.sh +secondary=$(./vga-or-hdmi.sh) +if [ $? -ne 0 ]; then + >&2 echo "no VGA or HDMI output is present!" + exit 1 +fi + +secondary_res=$(./max-res.sh "$secondary") +if [ -z "$secondary_res" ]; then + >&2 echo "max res for secondary $secondary not found!" + exit 1 +fi + +xrandr --output $primary --output $secondary --mode $secondary_res --right-of $primary diff --git a/xrandr/max-res.sh b/xrandr/max-res.sh new file mode 100755 index 0000000..41a33e9 --- /dev/null +++ b/xrandr/max-res.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +device="$1" + +max_res="" +max_area=0 + +while read res x y; do + area=$(( $x*$y )) + if [ $area -ge $max_area ]; then + max_area=$area + max_res="$res" + fi +done< <(./enum-res.sh "$device" | gawk 'match ($1, /([0-9]*)x([0-9]*)/, res) {print $1, res[1], res[2]}') + +echo $max_res diff --git a/xrandr/same-res.sh b/xrandr/same-res.sh new file mode 100755 index 0000000..495f11c --- /dev/null +++ b/xrandr/same-res.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +device1="$1" +device2="$2" + +while read res1 x1 y1; do + area1=$(( $x1*$y1 )) + while read res2 x2 y2; do + area2=$(( $x2*$y2 )) + if [ $area1 -eq $area2 ]; then + echo $res2 + exit + fi + done< <(./enum-res.sh "$device2" | gawk 'match ($1, /([0-9]*)x([0-9]*)/, res) {print $1, res[1], res[2]}') +done< <(./enum-res.sh "$device1" | gawk 'match ($1, /([0-9]*)x([0-9]*)/, res) {print $1, res[1], res[2]}') + +exit 1 \ No newline at end of file diff --git a/xrandr/unify.sh b/xrandr/unify.sh new file mode 100755 index 0000000..c2ac36f --- /dev/null +++ b/xrandr/unify.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +source config.sh + +secondary=$(./vga-or-hdmi.sh) +if [ -z "$secondary" ]; then + >&2 echo "no VGA or HDMI output is present!" +fi + +same_res=$(./same-res.sh "$primary" "$secondary") +if [ $? -ne 0 ]; then + >&2 echo "equal resolution for $primary and $secondary was not found" + exit 1 +fi + +xrandr --output $primary --mode $same_res --primary --output $secondary --mode $same_res --same-as $primary diff --git a/xrandr/vga-or-hdmi.sh b/xrandr/vga-or-hdmi.sh new file mode 100755 index 0000000..9269cdb --- /dev/null +++ b/xrandr/vga-or-hdmi.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +output=$(xrandr | awk '$2=="connected" { if ($1 ~ /VGA|HDMI/) { print $1 } }') +if [ -z "$output" ]; then + exit 1; +else + echo $output +fi