在 Debian 上使用 Compton 进行主题定制
一 安装与准备
- 在 Debian 上安装 Compton:sudo apt update && sudo apt install compton。安装完成后可先运行 compton --version 确认版本。Compton 主要服务于 X11 会话,适合与 Openbox、i3 等窗口管理器搭配使用;若使用 Wayland 会话,Compton 将不生效。
二 配置文件与关键选项
- 配置文件位置:创建或编辑用户目录下的 ~/.config/compton.conf。该文件不存在时可自行新建。
- 常用全局选项(示例):
- backend = glx 或 xrender(显卡支持较好时优先 glx,兼容性可选 xrender)
- vsync = true(减少撕裂)
- shadow = true(窗口阴影)
- opacity = 0.9(全局不透明度,0.0–1.0)
- ignore_root = true(忽略根窗口透明度)
- 阴影细节(示例):
- shadow-radius = 5
- shadow-offset-x = 1
- shadow-offset-y = 1
- shadow-opacity = 0.3
- 背景模糊(示例):
- [blur]
- method = gaussian
- size = 10
- deviation = 5.0
- 按窗口设置透明度(示例):
- [opacity-rule]
- 90:class_g ‘Firefox’
- 95:name ‘Terminal’
- 应用配置:保存后可用命令 compton --config ~/.config/compton.conf -f 前台启动,或先 killall compton 再启动以应用新配置。
三 主题切换与自动启动
- 多主题文件切换:将不同主题保存为多个配置文件(如 ~/.config/compton-dark.conf、~/.config/compton-light.conf),通过环境变量指定配置启动:COMPTON_CONFIG=~/.config/compton-dark.conf compton。
- 登录会话自动启动:
- 如果使用显示管理器(如 LightDM/GDM),可在 ~/.xprofile 或 ~/.xinitrc 中加入:export COMPTON_CONFIG=~/.config/compton-dark.conf && compton --daemon。注意路径使用绝对路径更稳妥。
- 若使用会话级 systemd 用户服务(推荐):创建 ~/.config/systemd/user/compton.service,内容示例:
- [Unit]
- Description=Compton compositor
- After=graphical-session.target
- [Service]
- ExecStart=/usr/bin/compton --config %h/.config/compton-dark.conf --daemon
- Restart=always
- [Install]
- WantedBy=graphical-session.target
- 启用并启动:systemctl --user daemon-reload && systemctl --user enable --now compton。若之前用 sudo systemctl 启动了系统级服务,建议先停止以免冲突。
四 常见问题与优化
- 撕裂与性能:开启 vsync(或根据驱动/硬件尝试 opengl-sync 等选项);显卡较弱或遇到问题时可改用 xrender 后端以提升稳定性。
- 模糊与透明:模糊对性能更敏感,笔记本或低功耗设备可降低模糊 size 或关闭;使用 [opacity-rule] 为特定应用设置更高不透明度以保证可读性。
- 与桌面环境配合:在 KDE Plasma 中可将其作为合成器使用(系统设置 → 工作区 → 窗口管理 → 窗口合成器,选择 Compton);在 GNOME 上通常不建议与 Mutter 内置合成器同时启用,以免冲突。
- 调试技巧:前台运行 compton(compton --config ~/.config/compton.conf -f)可直接观察日志与报错;遇到异常先 killall compton 再启动,逐步排除配置项。