You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何永久保存startx的屏幕分辨率?

如何永久保存startx的屏幕分辨率?

看起来你在树莓派4B搭配Ubuntu Server 24.04.1和USB触摸屏跑Python GUI的场景里,卡在了startx分辨率永久设置的问题上对吧?结合你的环境,我给你几个实用的解决办法:

方法1:通过Xorg配置文件全局持久化(最推荐)

startx会自动读取Xorg的配置文件,这是最稳定的全局生效方案:

  • 先创建Xorg配置目录(如果不存在的话):
    sudo mkdir -p /etc/X11/xorg.conf.d
    
  • 创建自定义显示器配置文件:
    sudo nano /etc/X11/xorg.conf.d/90-monitor.conf
    
  • 写入以下内容(针对1024x600@60Hz分辨率,Modeline是标准参数,也可以用cvt 1024 600命令自己生成):
    Section "Monitor"
        Identifier "USB Touchscreen"
        # 生成1024x600@60Hz的标准模式参数
        Modeline "1024x600_60.00"  54.00  1024 1072 1176 1328  600 603 609 625 -hsync +vsync
        Option "PreferredMode" "1024x600_60.00"
        # 如果USB屏没有EDID识别,加上这行强制忽略系统自动检测
        Option "IgnoreEDID" "true"
    EndSection
    
    Section "Screen"
        Identifier "Default Screen"
        Monitor "USB Touchscreen"
        SubSection "Display"
            Modes "1024x600_60.00"
        EndSubSection
    EndSection
    
  • 保存退出后,重启你的systemd服务或直接重启系统测试效果。

方法2:直接在startx启动参数中指定分辨率

如果你不想修改全局配置,可以直接在你的systemd服务的ExecStart行里添加分辨率参数:
把原来的:

ExecStart=/usr/bin/startx /home/enes/cp/env/bin/python /home/enes/cp/main.py -- :0 vt7

修改为:

ExecStart=/usr/bin/startx /home/enes/cp/env/bin/python /home/enes/cp/main.py -- :0 vt7 -screen 0 1024x600

修改后记得重新加载systemd配置并重启服务:

sudo systemctl daemon-reload
sudo systemctl restart CPApp.service

额外排查小技巧

  1. 先手动测试分辨率是否能生效:在终端执行startx -- :0 -screen 0 1024x600,确认屏幕能正常显示目标分辨率后再修改配置
  2. 用xrandr命令查看系统识别的屏幕设备名称(比如可能是HDMI-1或USB-1),如果Xorg配置里的Identifier不对,换成xrandr输出的设备名
  3. 如果xrandr看不到1024x600模式,可以手动添加:
    xrandr --newmode "1024x600_60.00"  54.00  1024 1072 1176 1328  600 603 609 625 -hsync +vsync
    xrandr --addmode <你的屏幕设备名> 1024x600_60.00
    
    测试生效后再写入Xorg配置或startx参数里。

备注:内容来源于stack exchange,提问作者Muhammed Enes Aytemiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 14:05:32