在 Linux 中让 compton(窗口合成器)开机自启,取决于你使用的桌面环境 / 窗口管理器以及 显示管理器。下面按常见情况说明。
~/.xprofile如果你是通过 LightDM / SDDM / GDM + startx 登录:
nano ~/.xprofile
加入:
compton &
保存后重启即可。
~/.xinitrc(startx / 手动启动 X)如果你用 startx:
nano ~/.xinitrc
在启动 WM 前加:
compton &
exec dwm # 或其他 WM
使用自启动程序:
设置管理器 → 会话和启动 → 应用程序自启动 → 添加
命令:compton
系统设置 → 开机和关机 → 自动启动 → 添加程序 → compton
mkdir -p ~/.config/autostart
nano ~/.config/autostart/compton.desktop
内容:
[Desktop Entry]
Type=Application
Exec=compton
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Compton
⚠️ 不推荐用于普通桌面用户(容易黑屏)
nano ~/.config/systemd/user/compton.service
[Unit]
Description=Compton Compositor
After=graphical.target
[Service]
ExecStart=/usr/bin/compton
Restart=on-failure
[Install]
WantedBy=default.target
启用:
systemctl --user enable compton
systemctl --user start compton
which compton
~/.config/compton.conf
picom &
echo "compton &" >> ~/.xprofile
reboot
如果你告诉我:
我可以给你精确的一条命令方案。