你提到的 Compton 一般是指 Linux 下的 X11 compositor(窗口合成器,用于透明、阴影、淡入淡出等效果)。在 CentOS 上配置 Compton 主要有几个关键点:安装、写配置文件、启动方式。下面按步骤说明。
一、确认环境
Compton 只适用于 X11,不适用于纯 Wayland。
echo $XDG_SESSION_TYPE
如果是 x11 就可以继续;如果是 wayland,需要切换会话或改用其它合成器(如 wayfire / mutter)。
二、安装 Compton
CentOS 7
默认仓库里通常没有 compton,可以用 EPEL + 编译,或者直接装 compton 的 fork(见下)。
yum install -y epel-release
yum install -y compton
如果找不到:
yum install -y xorg-x11-server-Xorg xcompmgr
或手动编译。
CentOS 8 / Stream
dnf install -y epel-release
dnf install -y compton
若仓库无 compton,可安装 fork 版 picom(推荐):
dnf install -y picom
注:现在社区多用 picom(compton 的活跃分支),配置方式几乎一致。
三、基础配置文件
Compton 默认读取:
~/.config/compton.conf
示例最小配置(常用):
# ~/.config/compton.conf
backend = "glx";
glx-no-stencil = true;
shadow = true;
shadow-radius = 12;
shadow-offset-x = -2;
shadow-offset-y = -2;
shadow-opacity = 0.5;
fade = true;
fade-in-step = 0.03;
fade-out-step = 0.03;
opacity-rule = [
"90:class_g = 'URxvt'",
"95:class_g = 'Firefox'"
];
vsync = "opengl-swc";
unredir-if-possible = true;
如果你用的是 picom,文件名相同,内容兼容。
四、启动 Compton
手动启动
compton --config ~/.config/compton.conf -b
或 picom:
picom --config ~/.config/compton.conf -b
-b 表示后台运行。
开机自启(X11)
方法 1:~/.xinitrc
vim ~/.xinitrc
加入:
compton -b &
exec startxfce4 # 或你的窗口管理器
方法 2:桌面环境自启
- GNOME:Settings → Startup Applications
- XFCE:Settings → Session and Startup → Autostart
添加命令:
compton --config ~/.config/compton.conf
五、常见问题
1. 透明无效
- 确保窗口管理器支持 RGBA
- 启动参数加:
compton --use-glx --vsync opengl
2. 视频闪烁
尝试:
vsync = "none";
unredir-if-possible = true;
3. CentOS 老显卡
用 xrender 后端更稳定:
backend = "xrender";
六、推荐替代(新系统)
如果你用的是 CentOS 8/Stream 或新发行版,建议直接用 picom:
dnf install picom
picom --config ~/.config/compton.conf -b
如果你能告诉我:
- CentOS 版本(7 / 8 / Stream)
- 桌面环境(GNOME / XFCE / 无桌面)
- 是否是虚拟机
我可以给你一套可直接用的配置。