松鼠Mike的树洞 -- Make Each Day Count
  • 排序
  • 选择时间

Ubuntu 14.04更改Lightdm登录界面分辨率

发布日期: 2015-12-25更新日期:2015-12-25

Ubuntu的系统设置里设置的分辨率只有在用户登录以后才能生效。也就是说,如果屏幕支持的最高分辨率很高的话,即便登录进系统后设置了分辨率,登录界面的字仍然需要使用放大镜才能看清。
虽然对于只有自己一个账户的电脑来说这也不是个事,反正在登录界面也不需要看什么,只需要敲个密码+回车就行,但是作为强迫症患者我还是对此不能忍受。在多方查询以后终于在AskUbuntu论坛里一个没有标注为solved的问题(What's causing my login resolution to reset incorrectly?)的comment里找到了解决方法解决了这个问题。
下面简要做个笔记
Ubuntu 14.04的启动器用的是Lightdm。根据Ubuntu Wiki相关章节的说法,

LightDM configuration is provided by the following files:

/usr/share/lightdm/lightdm.conf.d/*.conf
/etc/lightdm/lightdm.conf.d/*.conf
/etc/lightdm/lightdm.conf

System provided configuration is stored in /usr/share/lightdm/lightdm.conf.d/*.conf and is not user editable. System administrators can override this configuration in /etc/lightdm/lightdm.conf.d/*.conf and /etc/lightdm/lightdm.conf. Files are read in the above order and combined together to make the LightDM configuration.

...

Adding System Hooks

If you need some special behaviour when X servers and user sessions start/stop you can set commands to be run with the following configuration:
[SeatDefaults]
display-setup-script=command
display-stopped-script=command (Not in Ubuntu 12.04 LTS)
greeter-setup-script=command
session-setup-script=command
session-cleanup-script=command
session-wrapper=command
greeter-wrapper=command (Not in Ubuntu 12.04 LTS)
display-setup-script is run after the X server starts but before the user session / greeter is run. Set this if you need to configure anything special in the X server. It is run as root. If this command returns an error code the X server is stopped.
display-stopped-script is run after an X server exits. It is run as root.
greeter-setup-script is run before a greeter starts. It is run as root. If this command returns an error code the greeter fails to start (which will cause LightDM to stop).
session-setup-script is run before a user session starts. If this command returns an error the session will not start (user is returned to a greeter).
session-cleanup-script is run after a greeter or user session stops. It is run as root.
session-wrapper is a the command to run for a session. This command is run as the user and needs to exec the command passed in the arguments to complete running the session. Use this if you need to do special setup for a user session. Note the default is 'lightdm-session' so you should chain to this if you need to override this setting.
greeter-wrapper is a the command to run a greeter. It is the equivalent of session-wrapper for greeters.

由上文可知,如果在lightdm.conf中指定display-setup-script和greeter-setup-script就可以设置分辨率了。因为Lightdm的配置文件读取顺序,所以可以在/etc/lightdm中创建lightdm.conf然后添加这两个命令。
# /etc/lightdm/lightdm.conf
[SeatDefaults]
display-setup-script=/usr/bin/lightdmxrandr.sh
greeter-setup-script=/usr/bin/lightdmxrandr.sh
session-setup-script=/usr/bin/lightdmxrandr.sh
指定的命令/usr/bin/lightdmxrandr.sh内容如下
#!/bin/bash

# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
xrandr --addmode eDP1 1920x1080_60.00
xrandr --output eDP1 --primary --mode 1920x1080_60.00
xrandr的这些参数可以通过执行下面的命令得到
~$ xrandr -q
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
   3840x2160      60.0 +   48.0  
   2048x1536      60.0  
   1920x1440      60.0  
   1856x1392      60.0  
   1792x1344      60.0  
   1920x1200      60.0  
   1920x1080      59.9* 
   1600x1200      60.0  
   1680x1050      60.0     59.9  
   1600x1024      60.2  
   1400x1050      60.0  
   1280x1024      60.0  
   1440x900       59.9  
   1280x960       60.0  
   1360x768       59.8     60.0  
   1152x864       60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
   1920x1080_60.00   60.0  
HDMI1 disconnected (normal left inverted right x axis y axis)
~$ cvt 1920 1080
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

到这里重启系统的话会发现刚刚进入Lightdm Greeter的时候分辨率是在lightdmxrandr.sh中指定的那个,但是很快在显示登录界面的时候会又变回屏幕的最高分辨率。
解决这个问题的办法在What's causing my login resolution to reset incorrectly?这个提问的comment里,总结如下
~$ sudo chmod 755 /var/lib/lightdm/
~$ cd /var/lib/lightdm/.config
~$ sudo ln -s ~/.config/monitors.xml
~$ sudo chmod 750 /var/lib/lightdm/
~$ sudo reboot
DONE! Enjoy your Lightdm Greeter in your desired resolution.