根据这个在现在,它自动在登录部分,我已经作出了自己的脚本45custom_xrandr-settings
,并使其进入/etc/X11/Xsession.d/
。在Ubuntu 14.04 LTS下,它对我来说很好用。您可以将代码case
放在该部分中描述的命令之后。
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'Modeline\K.*') && #grep evrything after 'Modline'
myNewModeName=\"$(echo $myNewMode | grep -oP '"\K[^"\047]+(?=["\047])' )\" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
我相信以上就是您要寻找的。您只需运行xrandr
命令即可查看可用的输出。该输出可以是VGA
,VGA-0
,DVI-0
,TMDS-1
或DisplayPort-0
。
这是我制作的完整脚本。
# To configure xrandr automatically during the first login,
# save this script to your computer as /etc/X11/Xsession.d/45custom_xrandr-settings:
# If an external monitor is connected, place it with xrandr
# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
# More info at http://www.thinkwiki.org/wiki/Xorg_RandR_1.2
PRI_OUTPUT="DVI-0";
SEC_OUTPUT="DisplayPort-0";
SEC_LOCATION="left"; # SEC_LOCATION may be one of: left, right, above, or below
case "$SEC_LOCATION" in
left|LEFT)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
right|RIGHT)
SEC_LOCATION="--right-of $PRI_OUTPUT"
;;
top|TOP|above|ABOVE)
SEC_LOCATION="--above $PRI_OUTPUT"
;;
bottom|BOTTOM|below|BELOW)
SEC_LOCATION="--below $PRI_OUTPUT"
;;
*)
SEC_LOCATION="--left-of $PRI_OUTPUT"
;;
esac
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'Modeline\K.*') && #grep evrything after 'Modline'
myNewModeName=\"$(echo $myNewMode | grep -oP '"\K[^"\047]+(?=["\047])' )\" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
# Activate secondary out (display port)
xrandr | grep $SEC_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
# xrandr --output $SEC_OUTPUT --auto $SEC_LOCATION
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --auto $SEC_LOCATION
else
xrandr --output $PRI_OUTPUT --mode $myNewModeName --output $SEC_OUTPUT --off
fi