You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ublinux-init/ublinux/rc.xorg/02-xrandr

74 lines
3.7 KiB

#!/usr/bin/env bash
ENABLED=yes
[[ ${ENABLED} == "yes" ]] || exit 0
DEBUGMODE=no
. /usr/lib/ublinux/functions
. /usr/lib/ublinux/default
debug_mode "$0" "$@"
SOURCE=${SYSCONF}/config; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
SOURCE=${SYSCONF}/video; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
SOURCE=${SYSCONF}/desktop; [ -f ${SOURCE} ] && . ${SOURCE} 2>/dev/null
[[ ${DISPLAYMANAGER} == "none" ]] && exit 0
## Parametrs:
## cvt , gtf , reduced|r , auto , preferred , off , primary , mode:1920x1080
## lo|LeftOf:{name} , ro|RightOf:{name} , ab|Above:{name} , be|Below:{name} , rotate:normal|left|right|invert
[[ -z "${XRANDR_MONITOR[@]}" ]] || for VIDEO_PORT in "${!XRANDR_MONITOR[@]}"; do
SOFT_MODELINE="gtf"
SOFT_MODELINE_R=
while read VIDEO_PORT_PARAM; do
MODELINE=
if grep -Eiq "^[0-9]*x[0-9]*$|^[0-9]*x[0-9]*x[0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
if [[ -n ${SOFT_MODELINE_R} ]]; then
MODELINE=$(cvt -r $(sed 's/\([0-9]* [0-9]*\) .*/\1/' <<< ${VIDEO_PORT_PARAM//x/ }) | sed '/^\s*$/d ; /^\s*#/d ; s/\s*Modeline //')
SOFT_MODELINE_R=
elif [[ ${SOFT_MODELINE} == "cvt" ]]; then
MODELINE=$(cvt ${VIDEO_PORT_PARAM//x/ } | sed '/^\s*$/d ; /^\s*#/d ; s/\s*Modeline //')
else
if grep -Eiq "^[0-9]*x[0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
MODELINE=$(gtf ${VIDEO_PORT_PARAM//x/ } 60 | sed '/^\s*$/d ; /^\s*#/d ; s/\s*Modeline //')
else
MODELINE=$(gtf ${VIDEO_PORT_PARAM//x/ } | sed '/^\s*$/d ; /^\s*#/d ; s/\s*Modeline //')
fi
fi
elif grep -Eiq "^cvt$" <<< "${VIDEO_PORT_PARAM}"; then
SOFT_MODELINE="cvt"
elif grep -Eiq "^gtf$" <<< "${VIDEO_PORT_PARAM}"; then
SOFT_MODELINE="gtf"
elif grep -Eiq "^reduced|r$" <<< "${VIDEO_PORT_PARAM}"; then
SOFT_MODELINE_R="reduced"
elif grep -Eiq "^auto$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --auto
elif grep -Eiq "^preferred$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --preferred
elif grep -Eiq "^off$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --off
elif grep -Eiq "^primary$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --primary
elif grep -Eiq "^mode:[0-9x_]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --mode $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM})
elif grep -Eiq "^mode:[0-9x_]*:[0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --mode $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM}) --rate $(cut -d: -f3 <<< ${VIDEO_PORT_PARAM})
elif grep -Eiq "^lo:[A-z0-9]*$|^LeftOf:[A-z0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --left-of $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM^^})
elif grep -Eiq "^ro:[A-z0-9]*$|^RightOf:[A-z0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --right-of $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM^^})
elif grep -Eiq "^ab:[A-z0-9]*$|^Above:[A-z0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --above $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM^^})
elif grep -Eiq "^be:[A-z0-9]*$|^Below:[A-z0-9]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --below $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM^^})
elif grep -Eiq "^Rotate:[A-z]*$" <<< "${VIDEO_PORT_PARAM}"; then
xrandr --output ${VIDEO_PORT^^} --rotate $(cut -d: -f2 <<< ${VIDEO_PORT_PARAM^^})
fi
if [[ -n ${MODELINE} ]]; then
xrandr --newmode ${MODELINE}
xrandr --addmode ${VIDEO_PORT^^} $(cut -d" " -f1 <<< ${MODELINE})
xrandr --output ${VIDEO_PORT^^} --mode $(cut -d" " -f1 <<< ${MODELINE})
fi
done < <(tr ',' '\n' <<< "${XRANDR_MONITOR[${VIDEO_PORT}]}")
done