温馨提示×

CentOS如何使用Compton进行屏幕缩放

小樊
34
2026-01-02 09:12:30
栏目: 智能运维

Compton在CentOS中的定位与屏幕缩放的正确做法

一、核心结论

  • ComptonX11 的窗口合成器,职责是阴影、透明度、淡入淡出、VSync 等合成效果,不负责设置或改变显示器的分辨率/缩放。因此要实现“屏幕缩放”,应使用 xrandr 或桌面环境的显示设置;Compton 只需在缩放后正常启用即可。

二、用 xrandr 完成缩放或分辨率设置(X11 会话)

  • 查看当前输出与可用模式:
    • 命令:xrandr -q
  • 若需缩放输出(保持物理分辨率,仅改变逻辑 DPI/缩放比例),为输出设置缩放因子(示例将 eDP-1 缩放为 1.25×):
    • 命令:xrandr --output eDP-1 --scale 1.25x1.25
    • 还原:xrandr --output eDP-1 --scale 1x1
  • 若需添加自定义分辨率并应用(示例添加 1920×1080_60.00Virtual1):
    • 生成模式行(可用 cvt 生成):cvt 1920 1080 60
    • 添加新模式:xrandr --newmode “1920x1080_60.00” 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
    • 绑定到输出:xrandr --addmode Virtual1 “1920x1080_60.00”
    • 启用模式:xrandr --output Virtual1 --mode “1920x1080_60.00”
  • 持久化
    • 将上述 xrandr 命令加入会话启动脚本(如 ~/.xprofile~/.xinitrc),以便登录后自动应用。

三、在缩放后正确启动或重启 Compton

  • 配置文件位置与示例(仅示意,可按需精简):
    • 文件:~/.config/compton.conf
    • 内容:
      • backend = “glx
      • vsync = true
      • shadow = true
      • fade = true
  • 手动前台调试(便于观察日志与效果):
    • 命令:compton --config ~/.config/compton.conf -f
  • 通过 systemd 用户服务随会话自启(推荐,避免以 root 运行):
    • 创建服务:~/.config/systemd/user/compton.service
      • [Unit]
        • Description=Compton Compositor
        • After=graphical-session.target
      • [Service]
        • ExecStart=/usr/bin/compton --config %h/.config/compton.conf
        • Restart=on-failure
      • [Install]
        • WantedBy=graphical-session.target
    • 启用并启动:
      • systemctl --user daemon-reload
      • systemctl --user enable --now compton.service
  • 说明
    • 使用 glx 后端可获得更好的 OpenGL 合成性能;如使用 Wayland 会话,Compton 不适用(Wayland 的合成由会话自身负责)。

四、常见问题与排查

  • 缩放后字体发虚或锯齿
    • 优先使用整数缩放(如 1x2x);若必须非整数缩放,可尝试微调缩放因子(如 1.25x),并结合桌面环境的字体 DPI 设置。
  • 缩放后部分程序窗口渲染异常
    • 尝试切换后端(如在配置中将 backend 改为 xrender),或在 ~/.config/compton.confshadow-exclude 中对特定窗口类排除阴影/合成,减少边缘伪影。
  • 需要确认 Compton 是否已生效
    • 前台运行 compton -f 观察输出;或查看日志:journalctl --user -u compton.service -f

0