Detect best resolution, Fix #31

parent d4a58e35
......@@ -24,6 +24,14 @@ then
export XAUTHORITY="/home/$user/.Xauthority"
fi
# show max between two res
max_res(){
[ -z "$2" ] && echo $1 && return
first=$(echo $1 | sed 's/x/*/' | bc)
second=$(echo $2 | sed 's/x/*/' | bc)
[ $first -ge $second ] && echo $1 || echo $2
}
# Default main screens (external VGA or internal screen)
MAIN_SCREENS="DP-3 VGA-1 LVDS-1 eDP1"
......@@ -49,43 +57,51 @@ screens=$(xrandr | grep " connected" | cut -f 1 -d ' ' \
# Auto detect best resolution
for m in $(xrandr | awk -v pattern="^$MAIN_SCREEN" '/^.* connected/{IN=0} $0 ~ pattern {IN=1} /^ /{if(IN==1){print $1}}')
do
# echo "testing mode $m"
for line in $(xrandr | awk -v pattern="^$MAIN_SCREEN" '/^.* connected/{IN=1} $0 ~ pattern {IN=0} {if(IN==1){print $1}}')
do
# echo "line $line"
if [[ $line =~ [0-9]* ]]
then
# New mode
if [ "$line" == "$m" ]
then
found=1
fi
else
# New screen
if [ $found == 0 ]
then
break
fi
found=0
fi
# echo "Found ? $found"
done
if [ $found == 1 ]
then
mode="--mode $m"
break
fi
# echo "testing mode $m"
OTHERS=$(xrandr | awk -v pattern="^$MAIN_SCREEN" '/^.* connected/{IN=1} $0 ~ pattern {IN=0} {if(IN==1){print $1}}')
if [ -z "$OTHERS" ]
then
# one screen look for best common resolution
mode=$(max_res $m $mode)
else
# Several screen look for best common resolution
for line in $OTHERS
do
# echo "line $line"
if [[ $line =~ [0-9]* ]]
then
# New mode
if [ "$line" == "$m" ]
then
found=1
fi
else
# New screen
if [ "$found" == 0 ]
then
break
fi
found=0
fi
# echo "Found ? $found"
done
if [ "$found" == 1 ]
then
mode="$m"
break
fi
fi
done
# echo "mode $mode"
# Primary screen
cmd="xrandr --output $MAIN_SCREEN --auto $mode --rotate normal --primary"
cmd="xrandr --output $MAIN_SCREEN --auto --mode $mode --rotate normal --primary"
# Add all connected as copy
prev_s=$MAIN_SCREEN
for s in $(echo -e $screens)
do
cmd="$cmd --output $s --auto $mode --same-as $prev_s --rotate normal"
cmd="$cmd --output $s --auto --mode $mode --same-as $prev_s --rotate normal"
prev_s="$s"
done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment