在 Debian 中自定义 Compton 的完整步骤
一 安装与配置文件位置
- 安装 Compton:
- sudo apt update
- sudo apt install compton
- 配置文件默认路径:
- 用户级:~/.config/compton.conf
- 系统级:/etc/xdg/compton.conf
- 若文件不存在可手动创建:
- mkdir -p ~/.config && touch ~/.config/compton.conf
- 说明:多数桌面会话不会默认启用 Compton,需要按你的会话方式手动启动或在登录后启动。
二 启动方式与自动运行
- 手动前台启动(便于查看日志与排查):
- compton --config ~/.config/compton.conf -b
- 手动后台启动:
- compton --config ~/.config/compton.conf --daemon
- 使用自定义配置路径:
- compton --config /path/to/your/compton.conf
- 在登录后自动启动(按你的会话选择其一):
- 如果使用 startx / ~/.xinitrc:在 ~/.xinitrc 的 exec 前加入 compton --config ~/.config/compton.conf -b
- 如果使用显示管理器(如 LightDM/GDM):创建或编辑文件 ~/.xprofile,加入 compton --config ~/.config/compton.conf -b
- 注意:
- 不建议使用 systemd --user 在图形会话外直接管理 Compton;若确需 systemd 管理,请确保会话环境已就绪(如 DISPLAY、XAUTHORITY 等)。
三 常用配置项与示例
- 建议先备份再修改:cp ~/.config/compton.conf ~/.config/compton.conf.bak
- 示例配置(保存为 ~/.config/compton.conf):
- 全局与渲染
- backend = “glx” # 可选:glx、xrender;glx 通常更现代,xrender 兼容性更好
- vsync = “opengl-swc” # 垂直同步:opengl、opengl-swc、false
- refresh-rate = 0 # 0 表示自动检测
- 透明度与淡化
- active-opacity = 1.0
- inactive-opacity = 0.90
- frame-opacity = 0.7
- fading = true
- fade-delta = 5
- fade-in-step = 0.03
- fade-out-step = 0.03
- 阴影
- shadow = true
- shadow-radius = 12
- shadow-offset-x = -15
- shadow-offset-y = -15
- shadow-opacity = 0.5
- shadow-exclude = [
“name = ‘Notification’”,
“class_g = ‘Conky’”,
“class_g ?= ‘Notify-osd’”,
“class_g = ‘Cairo-clock’”
]
- 背景模糊
- blur-background = true
- blur-background-frame = true
- blur-background-fixed = true
- blur-kern = “3x3box”
- blur-background-exclude = [
“window_type = ‘dock’”,
“window_type = ‘desktop’”
]
- 窗口特定透明度规则
- opacity-rule = [
“90:class_g ‘Firefox’”,
“95:name ‘Terminal’”,
“100:class_g ‘Xephyr’”
]
- 应用与热重载
- 修改后重启:pkill compton && compton --config ~/.config/compton.conf -b
- 若通过登录脚本启动,注销并重新登录即可生效。
四 故障排查与性能优化
- 查看启动日志:前台运行 compton 可直接看到报错;或在启动时加上 –log-level debug 获取详细信息
- 性能与兼容性建议:
- 显卡驱动支持良好时优先 backend = glx;出现撕裂或异常可尝试 xrender
- 不需要时关闭 blur/opacity/fading 可显著提升性能
- 根据显示器刷新率设置 refresh-rate;vsync 选择 opengl-swc 或关闭测试效果
- 使用 shadow-exclude 排除通知、面板、桌面等不需要阴影的窗口
- 常见现象与处理:
- 屏幕撕裂:开启 vsync(如 opengl-swc),或降低/关闭模糊
- 卡顿或高占用:关闭模糊/淡入淡出,切换 backend,减少重绘区域
- 某些应用透明异常:用 opacity-rule 为其设定固定不透明度