implement xrandr script framework

This commit is contained in:
mykola2312 2024-09-15 07:36:08 +03:00
parent 4552266682
commit e6439f09ac
10 changed files with 115 additions and 0 deletions

View file

@ -12,6 +12,7 @@ dirs=(
"/var/unbound:."
"$HOME/bhyve:."
"$HOME/ansible:."
"$HOME/xrandr:."
"$HOME/.config/i3:i3wm"
"$HOME/.config/i3status:i3wm"
)

23
xrandr/README.md Normal file
View file

@ -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

2
xrandr/config.sh Normal file
View file

@ -0,0 +1,2 @@
export primary="LVDS-1"
export defalt_res="1366x768"

8
xrandr/default.sh Executable file
View file

@ -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

9
xrandr/enum-res.sh Executable file
View file

@ -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"

16
xrandr/extend-right.sh Executable file
View file

@ -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

16
xrandr/max-res.sh Executable file
View file

@ -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

17
xrandr/same-res.sh Executable file
View file

@ -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

15
xrandr/unify.sh Executable file
View file

@ -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

8
xrandr/vga-or-hdmi.sh Executable file
View file

@ -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