使用autorandr完成笔记本电脑外接显示器后自动调整分辨率

The commands are all in archlinux.

使用autorandr完成笔记本电脑外接显示器后自动调整分辨率

如果在安装plasma时选择plasma-desktop,而不安装kde-applications,也就是轻量安装,我们可以通过使用一个软件去解决这一需求。
本节记录 笔记本电脑进行以上安装方案后外接显示器不能正常显示 的一种可用的解决方案,并略微记录xrandr手动临时设置方案。
本方案配置完成后开机自动加载配置。

大致思路

autorandr可以记录下当前硬件状态下的显示模式,并在下次开机的时候自动根据硬件状态加载对应的xrandr配置。

需求:不连接外接显示器则使用笔记本原显示器的最大分辨率显示,外接显示器关盖使用1920x1080_60hz的模式显示。

确认你需要设置的分辨率

Xwindow会自适应屏幕,笔记本屏幕默认的分辨率模式通常不需要修改,如果你希望更改分辨率,可以使用

1
$ xrandr

显示所有已经添加的显示模式,如果对这些方案全部都不满意,可以参考archwiki的xrandr手动添加。

解决第二显示器连接后不显示

在连接外接显示器后,你可能会遇到外接显示器不能显示的情况,需要通过xrandr设置打开,可能默认是关闭的,使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
leejk% xrandr
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
eDP-1-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 275mm x 183mm
   2160x1440     60.00 +
   1920x1440     60.00  
   1856x1392     60.01  
   1792x1344     60.01  
   2048x1152     59.99    59.98    59.90    59.91  
   1920x1200     59.88    59.95  
   1920x1080     60.01    59.97    59.96*   59.93  
DP-1-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 293mm
   1920x1080     60.00*+  74.99    50.00    59.94  
   1920x1080i    60.00    50.00    59.94  
   1680x1050     59.88  
   1600x900      60.00  
HDMI-1-1 disconnected (normal left inverted right x axis y axis)

可以看到原显示器为eDP-1-1,外接显示器为DP-1-1,并且显示外接显示器connected,也就是说是连接了的,只是没有显示,需要通过

1
$ xrandr --output DP-1-1 --auto

--auto打开关闭的设备并以首选的最大分辨率模式显示,如果想关闭使用--off

安装autorandr

使用

1
$ sudo pacman -S autorandr

安装,或者从github下载。 github后面附带详细的配置教程。

配置autorandr

配置没有外接显示器的状态

1
$ autorandr --save mobile

配置外接显示器时的状态

打开第二显示器的显示,调整原屏幕为1920x1080的模式,第二显示器复制模式,执行

1
$ xrandr --output eDP-1-1 --auto --mode 1920x1080 --output DP-1-1 --same-as eDP-1-1

--same-as表示复制模式。 此时直接执行

1
$ autorandr --save double_screen

保存两个显示器都打开的模式为double_screen。
如果报错:

1
2
3
4
5
6
[ljk@leejk ~]$ autorandr --save double_screen
Cannot save current configuration as profile 'double_screen':
`eDP-1-1' is not off (has a mode configured) but is disconnected (does not have an EDID).
This typically means that it has been recently unplugged and then not properly disabled
by the user. Please disable it (e.g. using `xrandr --output eDP-1-1 --off`) and then rerun
this command.

笔记本未开盖,eDP-1-1没有连接,将笔记本开盖后再保存。

再配置关盖模式的配置,执行

1
2
$ xrandr --output eDP-1-1 --off
$ autorandr --save only_extra

将仅第二屏幕显示的模式保存为only_extra。

显示已加载的配置

通过

1
$ autorandr

列出已保存的配置和检测到的配置(detected)并显示当前状态(current)

1
2
3
4
[ljk@leejk ~]$ autorandr
double_screen (detected) (current)
only_extra
mobile

若未显示,可能是关盖下使用双屏显示模式,但是检测的是仅第二屏幕连接,所以不显示current和detected。请按照上面步骤完成配置。

根据硬件状态自动加载配置

使用

1
$ autorandr --change

自动按照当前硬件状态加载配置,一般开机自动加载配置 或者你可以直接使用

1
$ autorandr <profile>

加载你所需的配置,比如$ autorandr only_extra

Remove

如果不需要该模式的配置文件,直接使用

1
$ autorandr -r <profile>

删除配置

新增的内容

使用plasma桌面的话可以直接安装包kscreen,然后在设置中就可以找到对应的分辨率设置。

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy