Linux Compton设置:如何优化多显示器环境
导读:Linux Compton 多显示器优化指南 一 基础准备与多屏配置原则 使用 xrandr 先完成显示器的连接、分辨率与相对位置设置(如扩展、镜像),Compton 只负责窗口合成,不负责显示器拓扑。示例:xrandr --output...
Linux Compton 多显示器优化指南
一 基础准备与多屏配置原则
- 使用 xrandr 先完成显示器的连接、分辨率与相对位置设置(如扩展、镜像),Compton 只负责窗口合成,不负责显示器拓扑。示例:
xrandr --output HDMI-1 --auto --right-of eDP-1。完成后用xrandr --query确认输出名称(如 eDP-1、HDMI-1、DP-1)。 - 安装 Compton(示例):Debian/Ubuntu 系
sudo apt-get install compton;RHEL/CentOS 系sudo yum/dnf install compton。 - 创建配置文件:
mkdir -p ~/.config & & nano ~/.config/compton.conf,后续通过compton -c ~/.config/compton.conf测试启动。
二 推荐的多显示器配置示例
- 目标:启用 OpenGL 加速、减少跨屏重绘、按显示器特性设置刷新率、对特定应用优化阴影与透明。
- 示例
~/.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";
- 要点说明:
- 使用 backend = “glx” 获取 GPU 加速;
glx-damage与use-damage减少不必要的全屏重绘。 vsync取值可为 “opengl-swc”/“opengl”/false,不同驱动/显卡表现不同,建议逐一测试。refresh-rate可为每个输出单独指定,避免多屏不同刷新率下的卡顿与撕裂。- 通过
shadow-exclude、blur-exclude、opacity-rule对全屏视频、终端、浏览器等进行差异化处理,兼顾观感与性能。
- 使用 backend = “glx” 获取 GPU 加速;
三 启动与自启动方式
- 会话/窗口管理器自启动:将
compton -c ~/.config/compton.conf加入 Openbox、i3、bspwm 等的启动脚本或 autostart 文件。 - systemd 用户服务(推荐,避免与登录会话不同步):
- 创建服务:
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
- 如需系统级服务(不推荐,易与用户会话不同步),可将 User= 指定为实际用户名并 WantedBy=multi-user.target。
四 性能优化与常见问题处理
- 性能优先项:
- 关闭或简化阴影/模糊(如
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/驱动)。
- 先确保显示器物理刷新率与
- 多屏不同 DPI/缩放:
- 使用
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查看运行状态与错误。
- 临时开启日志:
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Linux Compton设置:如何优化多显示器环境
本文地址: https://pptw.com/jishu/752429.html
