温馨提示×

如何在Debian上使用Compton进行多显示器配置

小樊
41
2026-01-01 11:48:06
栏目: 智能运维

在 Debian 上使用 Compton 配置多显示器

一 安装与准备

  • 更新系统并安装 Compton(若已安装可跳过):
    • sudo apt update && sudo apt install compton -y
  • 确认显示器连接与命名:
    • 运行 xrandr 查看输出名称(如:eDP-1HDMI-1DP-1),并调整相对位置与分辨率,例如:
      • xrandr --output HDMI-1 --mode 1920x1080 --right-of eDP-1
      • xrandr --output DP-1 --auto --right-of HDMI-1
  • 说明:Compton 对多显示器是开箱即用的,关键在于显示器已被 X11 正确识别与布局(由 xrandr 完成),随后 Compton 会作用于所有已连接的屏幕。

二 创建基础配置文件

  • 生成配置文件:
    • mkdir -p ~/.config && nano ~/.config/compton.conf
  • 建议的最小可用配置(按需增删):
    • backend = “glx” # 或 “xrender”,glx 通常性能更好
    • vsync = true # 减少撕裂(根据驱动与显示器支持度选择)
    • shadow = true # 窗口阴影
    • shadow-exclude = [ “class_g = ‘Conky’”, “class_g = ‘Polybar’” ] # 避免面板/桌面组件产生阴影
    • opacity-rule = [ “90:class_g = ‘Firefox’”, “0.95:class_g = ‘Gnome-terminal’” ] # 示例:按应用设置透明度
    • mark-wmwin-focused = true # 更好地区分焦点窗口
    • mark-ovredir-focused = true
    • use-ewmh-active-win = true
    • focus-exclude = [ “class_g = ‘Conky’” ]
  • 保存后可用以下命令前台试运行,便于观察日志与效果:
    • compton --config ~/.config/compton.conf --log-level 2

三 多显示器关键设置与调优

  • 全局配置即可覆盖多屏:Compton 默认会在所有 Xinerama 屏幕(即所有已连接显示器)上生效,无需为每个显示器单独写配置段。
  • 性能与外观的常用取舍:
    • 选择后端:优先尝试 glx;若出现黑屏/撕裂/高占用,可改用 xrender
    • 避免不必要的重绘与特效:对常驻不透明面板/托盘(如 ConkyPolybar)使用 shadow-exclude、focus-exclude,减少阴影与合成开销。
    • 多屏阴影与跨屏一致性:若出现跨屏阴影断裂或阴影错位,可尝试调整 shadow-offset、shadow-radius,或在 shadow-exclude 中对特定类/标题禁用阴影。
    • 透明度与模糊:使用 opacity-rule 精确控制窗口透明度;若启用背景模糊(如 blur-background),在低性能 GPU 上建议关闭或降低强度。
  • 故障排查思路:
    • 先停用所有特效(shadow/fade/blur)定位问题;再逐项恢复。
    • 使用前台运行与日志级别(–log-level 2)观察警告与错误。
    • 切换后端(glx/xrender)对比行为差异。

四 开机自启动与常用命令

  • 使用 systemd 用户服务(推荐,避免权限与登录会话问题):
    • mkdir -p ~/.config/systemd/user
    • nano ~/.config/systemd/user/compton.service
    • 写入:
      • [Unit]
        • Description=Compton Compositor
        • After=graphical-session.target
      • [Service]
        • ExecStart=/usr/bin/compton --config %h/.config/compton.conf --log-level 2
        • Restart=on-failure
      • [Install]
        • WantedBy=graphical-session.target
    • 启用并启动:
      • systemctl --user daemon-reload
      • systemctl --user enable --now compton.service
  • 使用会话自启动(备选,适用于不使用 systemd 用户会话的环境):
    • 将 compton --config ~/.config/compton.conf 加入窗口管理器/桌面环境的自启动脚本(如 Openbox 的 autostart、i3 的 config、Xfce 的会话与启动项)。
  • 常用命令:
    • 前台调试:compton --config ~/.config/compton.conf --log-level 2
    • 热重载:systemctl --user restart compton.service
    • 查看状态:systemctl --user status compton.service
  • 注意:若使用显示管理器(如 LightDM/GDM),确保服务在图形会话之后启动(After=graphical-session.target),并在登录后再拉起 Compton。

0