在 CentOS 上安装和配置 compton(现在社区更多用 picom,compton 已停止维护)一般分为以下几步:
一、安装 compton
1. 启用 EPEL 源(CentOS 7)
sudo yum install -y epel-release
2. 安装 compton
sudo yum install -y compton
CentOS 8 / Stream 可用 dnf:
sudo dnf install -y compton
如果仓库没有,可以用源码或 picom 替代:
sudo dnf install -y picom
二、基本配置文件
compton 默认读取:
~/.config/compton.conf
如果没有,就新建:
mkdir -p ~/.config
touch ~/.config/compton.conf
最简配置示例
backend = "glx";
glx-no-stencil = true;
opacity-rule = [
"90:class_g = 'URxvt'"
];
shadow = true;
shadow-radius = 8;
shadow-opacity = 0.4;
fade = true;
fade-in-step = 0.03;
fade-out-step = 0.03;
vsync = true;
三、启动 compton
手动测试
compton --config ~/.config/compton.conf &
开机自启(无 systemd 桌面)
加入 ~/.xinitrc 或 ~/.xprofile:
compton --config ~/.config/compton.conf &
四、常见桌面环境配置
1. GNOME(不推荐)
GNOME 默认用 Mutter,compton 不兼容
✅ 建议改用:
- XFCE
- i3
- Openbox
2. i3 / Openbox
直接在配置里启动即可:
exec compton
五、常见问题
❌ 透明无效
- 确保窗口管理器支持 compositing
- 使用
backend = "glx"或xrender
❌ 黑屏 / 卡顿
vsync = false;
backend = "xrender";
❌ 没有阴影
shadow = true;
shadow-exclude = [
"name = 'Notification'"
];
六、推荐:用 picom 替代 compton
sudo dnf install -y picom
picom --config ~/.config/picom.conf &
picom 配置兼容 compton,但功能更全。
如果你告诉我:
- CentOS 版本(7 / 8 / Stream)
- 桌面环境(i3 / XFCE / GNOME)
我可以给你精准配置。