Linux Compton 多显示器优化指南
一 基础准备与多屏配置原则
xrandr --output HDMI-1 --auto --right-of eDP-1。完成后用 xrandr --query 确认输出名称(如 eDP-1、HDMI-1、DP-1)。sudo apt-get install compton;RHEL/CentOS 系 sudo yum/dnf install compton。mkdir -p ~/.config && nano ~/.config/compton.conf,后续通过 compton -c ~/.config/compton.conf 测试启动。二 推荐的多显示器配置示例
~/.config/compton.conf:# 渲染与同步
backend = "glx";
glx-no-stencil = true;
glx-copy-from-front = false;
glx-damage = true;
use-damage = true;
vsync = "opengl-swc"; # 如仍有撕裂,可改为 "opengl" 或 false 测试
fps-limit = 0; # 0 表示不限制;多屏高刷可设为 120/144/165
# 多显示器:按各自刷新率运行(需与 xrandr 一致)
refresh-rate = [
"eDP-1: 60",
"HDMI-1: 144",
"DP-1: 60"
];
# 阴影与性能
shadow = true;
shadow-radius = 12;
shadow-offset-x = -8;
shadow-offset-y = -8;
shadow-opacity = 0.35;
shadow-exclude = [
"class_g = 'gnome-terminal'",
"class_g = 'konsole'",
"class_g = 'xterm'",
"class_g = 'Firefox' && argb && !override_redirect",
"_NET_WM_WINDOW_TYPE@:a = 'desktop'",
"_NET_WM_WINDOW_TYPE@:a = 'dock'",
"_NET_WM_WINDOW_TYPE@:a = 'tooltip'",
"_NET_WM_WINDOW_TYPE@:a = 'notification'"
];
# 透明与模糊
opacity-rule = [
"90:class_g = 'Gnome-terminal'",
"95:class_g = 'Firefox' && argb && !override_redirect"
];
inactive-opacity-override = false;
blur-background = true;
blur-background-frame = true;
blur-kern = "7x7box";
blur-radius = 3;
blur-exclude = [
"class_g = 'Gnome-terminal'",
"class_g = 'Firefox' && argb && !override_redirect"
];
# 重绘与裁剪优化
mark-wwin-focused = true;
mark-osd-focused = true;
detect-rounded-corners = true;
detect-client-leader = true;
unredir-if-possible = true;
unredir-if-possible-exclude = [
"class_g = 'slop'"
];
focus-exclude = [
"class_g = 'slop'"
];
# 调试(排障时启用,稳定后关闭)
# log-level = "debug";
# log-file = "/tmp/compton.log";
glx-damage 与 use-damage 减少不必要的全屏重绘。vsync 取值可为 “opengl-swc”/“opengl”/false,不同驱动/显卡表现不同,建议逐一测试。refresh-rate 可为每个输出单独指定,避免多屏不同刷新率下的卡顿与撕裂。shadow-exclude、blur-exclude、opacity-rule 对全屏视频、终端、浏览器等进行差异化处理,兼顾观感与性能。三 启动与自启动方式
compton -c ~/.config/compton.conf 加入 Openbox、i3、bspwm 等的启动脚本或 autostart 文件。nano ~/.config/systemd/user/compton.service[Unit]
Description=Compton Compositor
After=graphical-session.target
[Service]
ExecStart=/usr/bin/compton -c %h/.config/compton.conf
Restart=on-failure
Environment=DISPLAY=:0
[Install]
WantedBy=graphical-session.target
systemctl --user daemon-reload
systemctl --user enable --now compton.service
四 性能优化与常见问题处理
shadow = false 或仅对顶层窗口启用)。unredir-if-possible = true 并在 unredir-if-possible-exclude 中排除录屏/叠加工具。focus-exclude 忽略不需要参与焦点特效的窗口(如 slop)。mark-wwin-focused/mark-osd-focused 减少误伤的重绘。refresh-rate 一致;再切换 vsync 三种取值测试。fps-limit 设为显示器刷新率或 0(无上限,取决于 GPU/驱动)。xrandr --scale 或桌面环境缩放后,保持 backend = "glx" 与 glx-damage 开启,必要时适度提高 shadow-radius 与 blur-radius 以适配视觉一致性。log-level = "debug"; log-file = "/tmp/compton.log"; 复现问题后检查日志。systemctl --user status compton.service 或 journalctl --user -u compton.service 查看运行状态与错误。