Ubuntu双显示屏如何设置竖屏
引言
笔者因为需要使用外接一个竖屏显示屏来敲代码,另一块主屏用于看其他内容,但Ubuntu原生的图形化设置面板里并没有这个调节功能,因此使用命令行方式进行调节,以下为调节方法,在笔记本内置屏幕与HDMI外接的显示屏上尝试成功。
案例
xrandr --output HDMI-0 --auto --output DP-0 --auto --left-of HDMI-0 --rotate left
解释:HDMI-0为主屏,DP-0为副屏,将副屏在主屏左侧,并旋转90度
方法步骤
1. 查询当前存在的显示屏
xrandr
结果:
hermanye@hermanye-Dell-G16-7630:~$ xrandr
Screen 0: minimum 320 x 200, current 4480 x 1600, maximum 16384 x 16384
eDP-1 connected primary 2560x1600+0+0 (normal left inverted right x axis y axis) 345mm x 215mm
2560x1600 60.00*+ 60.00
2560x1440 60.00
2048x1536 60.00
1920x1440 60.00
1856x1392 60.00
1792x1344 60.00
2048x1152 60.00
1920x1200 60.00
1920x1080 60.00
1600x1200 60.00
1680x1050 60.00
1400x1050 60.00
1600x900 60.00
1280x1024 60.00
1400x900 60.00
1280x960 60.00
1440x810 60.00
1368x768 60.00
1280x800 60.00
1280x720 60.00
1024x768 60.00
960x720 60.00
928x696 60.00
896x672 60.00
1024x576 60.00
960x600 60.00
960x540 60.00
800x600 60.00
840x525 60.00
864x486 60.00
700x525 60.00
800x450 60.00
640x512 60.00
700x450 60.00
640x480 60.00
720x405 60.00
684x384 60.00
640x360 60.00
512x384 60.00
512x288 60.00
480x270 60.00
400x300 60.00
432x243 60.00
320x240 60.00
360x202 60.00
320x180 60.00
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1-0 connected 1920x1080+2560+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00*+ 74.97 59.94 50.00
1600x900 60.00
1280x1024 75.02 60.02
1280x720 60.00 59.94 50.00
1152x864 75.00
1024x768 75.03 60.00
800x600 75.00 60.32
720x576 50.00
720x480 59.94
640x480 75.00 59.94 59.93
DP-1-0 disconnected (normal left inverted right x axis y axis)
由结果可知,HDMI-1-0
为外接的需要旋转的屏幕
2. 旋转屏幕
将屏幕向左旋转
xrandr --output HDMI-1-0 --rotate left
结果: 外置的屏幕正常旋转为竖屏
3. 开机自启动[经过测试不可用]
经测试,开机无法自启动,可能由于设置时机不正确,需要在完全启动后再启用
sudo touch /tmp/screen_rotate.sh # Create bash script
sudo chmod 777 /tmp/screen_rotate.sh # Grant permission
sudo echo "xrandr --output HDMI-1-0 --rotate left" >> /tmp/screen_rotate.sh # Write to script
sudo mv /tmp/screen_rotate.sh /etc/init.d/
sudo update-rc.d screen_rotate.sh defaults 90
sudo reboot # reboot
如果要移除:sudo update-rc.d -f <your_script.sh> remove
4. 开机手动启用
sudo touch ~/screen_rotate.sh # Create bash script
sudo chmod 777 ~/screen_rotate.sh # Grant permission
sudo echo "xrandr --output HDMI-1-0 --rotate left" >> ~/screen_rotate.sh # Write to script
. ~/screen_rotate.sh
也可尝试将该脚本放入~/.bashrc
中,在每次终端启动时执行旋转,经测试,只会旋转一次,不会反复旋转
echo "source ~/screen_rotate.sh" >> ~/.bashrc