Debian下自定义 Compton 主题
一 概念与准备
sudo apt update && sudo apt install compton。配置文件默认路径为 ~/.config/compton.conf。二 创建与编辑配置文件
mkdir -p ~/.config && nano ~/.config/compton.conf。也可从系统示例复制:cp /etc/compton.conf ~/.config/compton.conf(若文件存在)。建议以“主题”思路维护多个配置,例如:~/.config/compton-dark.conf、~/.config/compton-light.conf、~/.config/compton-fast.conf。backend = "glx"; # 或 "xrender"
vsync = "opengl-swc"; # 或 "none"/"opengl"
# 透明度
inactive-opacity = 0.90;
active-opacity = 1.0;
frame-opacity = 0.7;
# 阴影
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'"
];
# 淡入淡出
fading = true;
fade-delta = 5;
fade-in-step = 0.03;
fade-out-step = 0.03;
保存后按需调整参数,以在观感与性能间取得平衡。三 应用与切换主题
pkill compton && compton --config ~/.config/compton.conf -b(-b 为后台运行)。export COMPTON_CONFIG=~/.config/compton-dark.conf && compton --config "$COMPTON_CONFIG" -b。[Unit]
Description=Compton Compositor
After=graphical-session.target
[Service]
ExecStart=/usr/bin/compton --config /home/你的用户名/.config/compton-dark.conf -b
Restart=always
[Install]
WantedBy=default.target
启用并启动:systemctl --user daemon-reload && systemctl --user enable --now compton。如需全局服务,可改为系统级 unit 并在 [Install] 中使用 WantedBy=multi-user.target(注意路径与权限)。四 主题切换脚本与性能建议
#!/usr/bin/env bash
set -e
THEME_DIR="$HOME/.config"
CFG="$THEME_DIR/compton-$1.conf"
if [[ ! -f "$CFG" ]]; then
echo "未找到配置: $CFG" >&2
exit 1
fi
pkill compton || true
export COMPTON_CONFIG="$CFG"
compton --config "$COMPTON_CONFIG" -b
echo "已切换到: $1"
使用:chmod +x ~/.local/bin/switch-compton && switch-compton dark。