温馨提示×

Compton配置Ubuntu时如何调整参数

小樊
41
2025-12-10 09:39:49
栏目: 智能运维

Ubuntu下Compton参数调整指南

一 安装与准备

  • 在基于 Debian/Ubuntu 的系统上安装:sudo apt update && sudo apt install compton。安装后可用 ps -e | grep compton 检查是否已在运行。配置文件通常位于 ~/.config/compton.conf/etc/xdg/compton.conf,如不存在可新建。修改配置后需重启 Compton 生效。

二 配置文件结构与常用参数

  • 全局开关与渲染
    • backend:渲染后端,常用 glx(OpenGL,通常性能更好)或 xrender(兼容性更好);部分环境也支持 wayland
    • vsync:垂直同步,设为 true/false 以平衡撕裂与输入延迟(与显示器刷新率、驱动相关)。
    • shadow:窗口阴影,设为 true/false;关闭可提升性能。
    • opacity / alpha:窗口透明度;全局或按规则设置,过多透明会增加开销。
    • ignore_root:设为 true 可避免根窗口透明引发的问题。
  • 模糊与背景
    • 背景模糊:使用 blur 段配置,如 method gaussian、size、deviation。
    • 屏幕边缘模糊:screen_edge_blur(部分版本/构建支持)。
  • 透明度规则示例
    • [opacity-rule]:按窗口类/名称设置透明度,如 90:class_g ‘Firefox’、95:name ‘Terminal’。
  • 备注
    • 某些桌面或构建中,部分选项名可能为命令行风格(如 bg_blur、screen_edge_blur 等);以实际配置样本与版本为准。

三 性能优化与常见问题处理

  • 提升性能
    • 优先使用 backend glx 并确保显卡驱动正确;必要时切换 vsync 开/关测试撕裂与延迟。
    • 关闭不必要特效:如 shadow false、减少/移除透明与模糊。
    • 限制资源占用:用 cpulimit -l 50 -p $(pidof compton) 限制 CPU 使用率(示例为 50%)。
  • 启动慢或卡顿
    • 精简特效(阴影、透明、模糊),优先用 glx 后端;必要时改用更轻量的合成器(如 xcompmgr)进行对比排查。
  • 兼容性提示
    • 若出现黑屏、撕裂或卡顿,尝试切换 backend(glx/xrender)、关闭 vsync 或暂时关闭 shadow/blur 定位问题。

四 应用与开机自启

  • 手动重启
    • killall compton 后执行 compton &;或使用 compton --config ~/.config/compton.conf -f 前台运行以便观察日志与报错。
  • 使用 systemd 自启(会话级)
    • 创建服务文件 /etc/systemd/user/compton.service(用户级)或 /etc/systemd/system/compton.service(系统级),示例:
      • [Unit] Description=Compton Compositor;After=graphical.target
      • [Service] ExecStart=/usr/bin/compton --config /etc/compton.conf;Restart=on-failure
      • [Install] WantedBy=graphical.target(用户级用 default.target)
    • 启用:systemctl --user daemon-reload && systemctl --user enable --now compton(用户级);或 systemctl daemon-reload && systemctl enable --now compton(系统级)。

五 可直接使用的示例配置

  • 目标:优先性能、减少撕裂、保留适度阴影与终端透明
    • backend = glx
    • vsync = true
    • shadow = true
    • shadow-exponent = 3
    • shadow-color = “#00000080”
    • opacity = 0.95
    • frame-rate = 60
    • dpr = 1
    • background-opacity = 1
    • ignore_root = true
    • [blur]
      • method = gaussian
      • size = 10
      • deviation = 5.0
    • [opacity-rule]
      • 90:class_g ‘Firefox’
      • 95:name ‘Terminal’
  • 使用方式:将以上内容保存为 ~/.config/compton.conf,执行 killall compton && compton --config ~/.config/compton.conf & 观察效果;如需自启,按第四节配置 systemd。

0