在 Ubuntu 上启用 Compton 的完整步骤
一 准备与安装
sudo apt update
sudo apt install compton
compton --version
以上步骤适用于 Ubuntu 20.04/22.04/24.04 等常见版本。
二 快速启用
compton --config ~/.config/compton.conf &
若没有配置文件,可直接运行 compton 使用默认设置。pkill compton
compton -c ~/.config/compton.conf &
-b 后台常驻(守护)-c 指定配置文件--backend=glx 使用 GLX 后端(也可尝试 xrender)--vsync 开启垂直同步-f 前台运行(便于调试)--log-level 与 --log-file 输出日志便于排错
以上命令可直接在终端执行,便于快速验证效果。三 开机自启动
~/.config/autostart/compton.desktop:[Desktop Entry]
Type=Application
Exec=compton -b --config ~/.config/compton.conf
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Compton
Comment=Lightweight X11 compositor
~/.config/systemd/user/compton.service:[Unit]
Description=Compton Window Composer
After=graphical-session.target
[Service]
Type=simple
ExecStart=/usr/bin/compton -b --config %h/.config/compton.conf
Restart=always
Environment=XDG_RUNTIME_DIR=/run/user/%U
[Install]
WantedBy=graphical-session.target
systemctl --user daemon-reload
systemctl --user enable --now compton.service
sudo tee /etc/systemd/system/compton.service >/dev/null <<'EOF'
[Unit]
Description=Compton Window Composer
After=display-manager.service
[Service]
Type=simple
ExecStart=/usr/bin/compton -b --config /etc/xdg/compton.conf
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now compton.service
以上自启方式覆盖会话级与系统级两种常见做法,优先使用会话级或用户级服务以减少与桌面会话的冲突。
四 桌面环境集成要点
autostart 或用户级 systemd 启动 Compton。五 配置与排错
~/.config/compton.conf(用户级),或 /etc/xdg/compton.conf(系统级)。backend = "glx"
vsync = true
shadow = true
fade = true
unredirect-translucent-windows = true
[shadow]
shadow-radius = 5
shadow-offset-x = 1
shadow-offset-y = 1
shadow-opacity = 0.3
[blur]
method = gaussian
size = 10
deviation = 5.0
pkill compton
compton -b --config ~/.config/compton.conf &
compton -b --config ~/.config/compton.conf --log-level=debug --log-file=/tmp/compton.log
glx ↔ xrender)、关闭/开启 vsync、关闭 unredirect-translucent-windows,并确认显卡驱动为最新版本。
以上配置与排错方法覆盖了常用参数、热重载与日志定位,便于快速优化体验。