问题
如何在启动时运行以下xrandr
命令?
xrandr
cvt 1368 768
xrandr --newmode"1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
答案1
向启动应用程序添加复杂的命令
Dash > Startup Applications > Add. > Startup Applications > Add.
有两种选择:
编写单独的脚本:
#!/bin/bash
cvt 1368 768
# xrandr only works in X11 sessions, not Wayland
["$XDG_SESSION_TYPE" = x11 ] || exit 0
xrandr --newmode"1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60.00
xrandr --output VGA1 --mode 1368x768_60.00
将脚本复制到空文件中,将它另存为set_monitor.sh
,并将以下命令添加到启动应用程序,如上所述。
/bin/bash /path/to/set_monitor.sh
将命令链接到一个(非常长)命令:
/bin/bash -c"cvt 1368 768&&xrandr --newmode"1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
重要说明:向启动应用程序添加xrandr命令
将xrandr
命令添加到启动可能比较棘手;在桌面完全加载之前,有时它们会崩溃,
/bin/bash -c"sleep 15&&cvt 1368 768&&xrandr --newmode"1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync&&xrandr --addmode VGA1 1368x768_60.00&&xrandr --output VGA1 --mode 1368x768_60.00"
你需要对sleep 15
进行一些操作,以找到最佳时间。
注意
我省略了第一行:
xrandr
答案2
在Ubuntu 14.04 LTS下对我有用,可以将代码放在该节中描述的case
命令之后。
PRI_OUTPUT="DVI-0";
# Make and force resolution
myNewMode=$(cvt 1366 768 60 | grep -oP 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #grep everything inside quotes
xrandr --newmode $myNewMode;
sleep 15;
xrandr --addmode $PRI_OUTPUT $myNewModeName;
可以通过运行xrandr
命令查看可用的输出,输出可以是VGA
,VGA-0
,DVI-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 'ModelineK.*') && #grep evrything after 'Modline'
myNewModeName="$(echo $myNewMode | grep -oP '"K[^"47]+(?=["47])' )" && #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
答案3
创建文件~/.xprofile
,并放置内容,在xuser会话的开头运行。
相关文章