如何通过Compton实现多屏显示优化
小樊
32
2025-12-20 01:29:08
多屏显示优化的总体思路
- 使用 xrandr 先完成显示器的物理连接、分辨率与相对位置(扩展/镜像)的正确设置;Compton 作为 X11 的窗口合成器只负责合成与特效,不会替你配置显示器,这一步是前提与基础。
- 在多屏下优先启用 OpenGL 加速,合理设置 刷新率 与 帧率限制,并对阴影、模糊、不透明度等效果按屏幕与窗口类型做精细化排除,避免跨屏性能浪费与视觉割裂。
安装与快速验证
- 在 Ubuntu/Debian 系:
- 安装:sudo apt update && sudo apt install compton
- 验证:compton --version
- 在 CentOS/RHEL/Fedora 系:
- 安装:sudo yum install compton 或 sudo dnf install compton
- 快速前台试运行(便于观察日志与效果):compton -b(后台)或 compton(前台)。如提示找不到命令,请确认已安装并在 PATH 中。
多显示器配置步骤
- 用 xrandr 正确布局
- 查看输出:xrandr --query
- 典型扩展示例(按你的实际接口名如 HDMI-1/DP-1/eDP-1 调整):
- xrandr --output HDMI-1 --auto --right-of eDP-1
- xrandr --output DP-1 --auto --right-of HDMI-1
- 创建或编辑配置文件
- 路径:~/.config/compton.conf(不存在则创建)
- 建议以“最小可用 + 针对性优化”为原则,逐步开启特效,逐项验证跨屏表现与性能。
关键配置示例与说明
- 建议将后端设为 glx,开启 vsync 与 fps-limit,并按各显示器实际刷新率设置;对已知重绘频繁或不需要阴影/模糊的应用进行排除,减少跨屏开销与撕裂风险。
- 示例(按需取用与微调):
- backend = “glx”;
- vsync = “opengl”;
- fps-limit = 60;
- refresh-rate = 0; # 0 表示自动,若某屏为 144Hz 可对该屏单独设置更高值
- shadow = true;
- shadow-radius = 5;
- shadow-opacity = 0.35;
- shadow-exclude = [
“class_g = ‘gnome-terminal’”,
“class_g = ‘konsole’”,
“class_g = ‘xterm’”,
“class_g = ‘Firefox’ && argb”
];
- blur-background = false; # 多屏下常关闭,显著降低 GPU 负载
- opacity-rule = [
“90:class_g = ‘Gnome-terminal’”,
“95:class_g = ‘Firefox’”
];
- focus-exclude = [ “class_g = ‘Conky’” ];
- detect-rounded-corners = true;
- detect-client-leader = true;
- mark-wmwin-focused = true;
- mark-ovredir-focused = true;
- use-ewmh-active-win = true;
- unredir-if-possible = true;
- glx-no-stencil = true;
- glx-copy-from-front = false;
- glx-swap-method = 0; # 0=自动, 1=拷贝, 2=交换, 3=损坏区重绘
- backend = “glx”;
- vsync = “opengl”;
- refresh-rate = 0;
- fps-limit = 60;
- shadow = true;
- shadow-radius = 5;
- shadow-opacity = 0.35;
- shadow-exclude = [
“class_g = ‘gnome-terminal’”,
“class_g = ‘konsole’”,
“class_g = ‘xterm’”,
“class_g = ‘Firefox’ && argb”
];
- blur-background = false;
- opacity-rule = [
“90:class_g = ‘Gnome-terminal’”,
“95:class_g = ‘Firefox’”
];
- focus-exclude = [ “class_g = ‘Conky’” ];
- detect-rounded-corners = true;
- detect-client-leader = true;
- mark-wmwin-focused = true;
- mark-ovredir-focused = true;
- use-ewmh-active-win = true;
- unredir-if-possible = true;
- glx-no-stencil = true;
- glx-copy-from-front = false;
- glx-swap-method = 0;
- 说明
- 多屏下建议关闭或降低 blur-background,对 视频播放器/全屏游戏 使用窗口规则进行不渲染/直通,避免不必要的合成与功耗。
- 若遇到卡顿或撕裂,优先检查 vsync 与 fps-limit 是否与显示器刷新率匹配;必要时将 glx-swap-method 调整为 1/2/3 测试稳定性。
自启动与验证
- 使用 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
- [Install]
- 启用与启动:
- systemctl --user daemon-reload
- systemctl --user enable --now compton.service
- 使用系统级服务(如确需)
- 创建:sudo nano /etc/systemd/system/compton.service
- 内容要点:
- ExecStart=/usr/bin/compton -c /home/你的用户名/.config/compton.conf
- User=你的用户名
- After=display-manager.service
- 启用与启动:
- sudo systemctl enable --now compton.service
- 验证与排错
- 状态:systemctl --user status compton.service(或 systemctl status compton.service)
- 日志:journalctl --user -u compton.service -b(或去掉 --user 查看系统级日志)
- 前台试运行:compton -b 观察终端输出;如需调试可加 --log-level=debug 并将日志重定向到文件。