配置 Compton 实现透明效果
一 安装与准备
sudo apt update && sudo apt install comptonsudo dnf install comptonsudo pacman -S comptoncompton --version二 创建基础配置
mkdir -p ~/.config && touch ~/.config/compton.conf~/.config/compton.conf):# 渲染后端:优先 glx(需 OpenGL/GLX),不行再试 xrender
backend = "glx";
# 全局不透明度(0.0~1.0,1.0 为不透明)
opacity = 0.9;
# 活动/非活动窗口透明度(更直观的聚焦高亮)
active-opacity = 0.95;
inactive-opacity = 0.8;
# 让菜单、弹出层等覆盖层保持不透明
focus-exclude = "x 0 && y 0 && override_redirect true";
# 性能与渲染
vsync = true;
shadow = true;
frame-rate = 60;
opacity 是全局默认;active-opacity/inactive-opacity 会覆盖默认,便于实现“聚焦更清晰、非聚焦更透明”。focus-exclude 常用于排除 dmenu、rofi 等覆盖层,避免被非活动规则透明化。三 按应用与状态设置透明规则
opacity-rule 精确控制不同窗口/状态的透明度(数组,每项格式为 “透明度:匹配条件”):opacity-rule = [
"90:class_g 'Firefox'",
"90:name 'Terminal'",
"100:class_g 'Xephyr'",
# 终端:聚焦 90%,非聚焦 60%
"90:name *? 'alacritty' && focused",
"60:name *? 'alacritty' && !focused",
# 编辑器:聚焦 90%,非聚焦 60%
"90:name *? 'VIM' && focused",
"60:name *? 'VIM' && !focused",
# 特定应用保持高不透明
"95:class_g 'Typora'",
"95:class_g 'Spyder'"
];
*?)、以及 _NET_WM_STATE 等 EWMH 属性;可按需增减规则。四 启动与自启动
compton --config ~/.config/compton.confcompton --config ~/.config/compton.conf -bnano ~/.config/systemd/user/compton.service[Unit]
Description=Compton Compositor
After=graphical-session.target
[Service]
ExecStart=/usr/bin/compton --config %h/.config/compton.conf
Restart=always
[Install]
WantedBy=graphical-session.target
systemctl --user daemon-reloadsystemctl --user enable --now compton.servicecompton --config ~/.config/compton.conf -b 加入会话的“启动应用程序”。五 常见问题与优化
focus-exclude = "x 0 && y 0 && override_redirect true" 保持可读性。blur-background = true; 等参数;若选项不存在请升级或更换构建版本。log-level = "debug"; 写入配置,通过日志定位匹配规则或渲染问题。