Задать разрешение экрана в bash скрипте при включенной опции дробное масштабирование в Linux
У меня включена опция дробного масштабирования в pop_os! на 125%. Скрипт при запуске определяет мое разрешение как 3072x1728 (на самом деле мой лэптом поддерживает только 1920x1080). Из за этого игра которую я запускают открывается в разрешении 3072x1728 больше чем на пол экрана моего лэптопа. При запуске скрипт определяет мое разрешение как: Current desktop resolution: 3072x1728, а мне нужно что бы было 1920x1080. Вот кусок кода, который я так понимаю отвечает за это:
get_desktop_res()
{
if (type xrandr &>/dev/null) ; then
local NUM_CONNECTED_OUTPUTS=0
DESKTOP_RES=$(xrandr -q | awk -F'current|,' 'NR==1 {gsub(" ","");print $3}')
echo "Current desktop resolution: $DESKTOP_RES"
local TEMPSTR=$(xrandr -q | grep 'connected')
DISPLAY_OUTPUTS=($(awk '{print $1}' <<<"$TEMPSTR"))
DISPLAY_RESLIST=($(awk '{print $2}' <<<"$TEMPSTR"))
for ((X=0 ; X < ${#DISPLAY_OUTPUTS[@]} ; X++)) ; do
if [ "${DISPLAY_RESLIST[$X]}" == "connected" ] ; then
DISPLAY_RESLIST[$X]=$(grep "^${DISPLAY_OUTPUTS[$X]}" <<<"$TEMPSTR" | grep -o "[0-9]\{3,\}x[0-9]\{3,\}")
((NUM_CONNECTED_OUTPUTS++))
else
DISPLAY_RESLIST[$X]=""
fi
done
echo "Detected $X display output(s). Connected outputs:"
for ((X=0 ; X < ${#DISPLAY_OUTPUTS[@]} ; X++)) ; do
if [ "${DISPLAY_RESLIST[$X]}" != "" ] ; then
printf "${DISPLAY_OUTPUTS[$X]}: ${DISPLAY_RESLIST[$X]}"
if [ "$CURRENT_RES" == "" ] && ([[ "$(awk NR==$((X+1)) <<< "$TEMPSTR")" =~ "primary" ]] || [ "$NUM_CONNECTED_OUTPUTS" == "1" ]) ; then
printf " (primary)\n"
CURRENT_RES=${DISPLAY_RESLIST[$X]}
else
printf "\n"
fi
fi
done
if [ "$CURRENT_RES" == "" ] ; then
if [ "$DESKTOP_RES" != "" ] ; then
echo "WARNING: Could not determine the primary display resolution. Using desktop resolution as fallback."
CURRENT_RES=$DESKTOP_RES
fi
fi
CURRENT_RES_X=$(awk -F'x' '{print $1}' <<<"$CURRENT_RES")
CURRENT_RES_Y=$(awk -F'x' '{print $2}' <<<"$CURRENT_RES")
else
echo "ERROR: Unable to read the display information."
return 1
fi
}
Возможно это тоже нужно править...
check_res()
{
if [ "$DESKTOP_RES" != "" ] ; then
if [ "$(xrandr -q | awk -F'current|,' 'NR==1 {gsub(" ","");print $3}')" != "$DESKTOP_RES" ] ; then
echo "Discrepancy between current and original desktop resolution. Attempting to restore..." >&2
xrandr -s $DESKTOP_RES
fi
local TEMPSTR=$(xrandr -q | grep 'connected')
local DISPLAY_OUTPUTS_TMP=($(awk '{print $1}' <<<"$TEMPSTR"))
local DISPLAY_RESLIST_TMP=($(awk '{print $2}' <<<"$TEMPSTR"))
for ((X=0 ; X < ${#DISPLAY_OUTPUTS[@]} ; X++)) ; do
if [ "${DISPLAY_OUTPUTS_TMP[$X]}" == "${DISPLAY_OUTPUTS[$X]}" ] ; then
if [ "${DISPLAY_RESLIST[$X]}" != "" ] && [ "${DISPLAY_RESLIST_TMP[$X]}" == "connected" ] && [ "$(grep "${DISPLAY_OUTPUTS_TMP[$X]}" <<<"$TEMPSTR" | grep -o "[0-9]\{3,\}x[0-9]\{3,\}")" != "${DISPLAY_RESLIST[$X]}" ] ; then
echo "Discrepancy between current and original setting for display output ${DISPLAY_OUTPUTS[$X]}. Attempting to restore..." >&2
xrandr --output ${DISPLAY_OUTPUTS[$X]} --mode ${DISPLAY_RESLIST[$X]}
fi
else
echo "Display output mismatch: cannot check/restore ${DISPLAY_OUTPUTS[$X]}" >&2
fi
done
fi
}
xrandr -q
Screen 0: minimum 320 x 200, current 3072 x 1728, maximum 16384 x 16384
eDP connected primary 3072x1728+0+0 (normal left inverted right x axis y axis) 309mm x 173mm
1920x1080 60.00*+
1680x1050 60.00
1280x1024 60.00
1440x900 60.00
1280x800 60.00
1280x720 60.00
1024x768 60.00
800x600 60.00
640x480 60.00
HDMI-A-0 disconnected (normal left inverted right x axis y axis)