温馨提示×

怎么在CentOS配置Compton

小樊
44
2026-08-19 14:24:14
栏目: 智能运维

CentOS 上配置 Compton(现在多称为 picom) 主要用于实现窗口透明、阴影、淡入淡出等合成特效。下面按 CentOS 7 / 8 / Stream 的常见情况说明。


一、确认环境

Compton 是 X11 下的合成器,不适用于 Wayland。

echo $XDG_SESSION_TYPE
  • 输出 x11 ✅ 可以继续
  • 输出 wayland ❌ 需要切换会话

二、安装 Compton / Picom

1️⃣ CentOS 7

CentOS 7 默认仓库没有 compton,需要 EPEL + 编译安装

安装依赖

sudo yum install -y epel-release
sudo yum groupinstall -y "Development Tools"
sudo yum install -y \
  libX11-devel libXcomposite-devel libXdamage-devel \
  libXrandr-devel libXrender-devel libconfig-devel \
  dbus-devel mesa-libGL-devel pcre-devel

编译安装 compton

git clone https://github.com/chjj/compton.git
cd compton
make
sudo make install

2️⃣ CentOS 8 / Stream

推荐使用 picom(compton 的继任者)

方法 1:从 EPEL 安装(推荐)

sudo dnf install -y epel-release
sudo dnf install -y picom

方法 2:编译最新版(可选)

sudo dnf install -y git meson ninja-build gcc \
  libX11-devel libXcomposite-devel libXdamage-devel \
  libXrandr-devel libXrender-devel libconfig-devel \
  dbus-devel mesa-libGL-devel pcre-devel

git clone https://github.com/yshui/picom.git
cd picom
meson setup build
ninja -C build
sudo ninja -C build install

三、创建配置文件

1️⃣ 创建配置目录

mkdir -p ~/.config/compton

2️⃣ 创建配置文件

vim ~/.config/compton/compton.conf

3️⃣ 基础配置示例(适合大多数桌面)

# 开启阴影
shadow = true;
shadow-radius = 12;
shadow-offset-x = -15;
shadow-offset-y = -15;
shadow-opacity = 0.5;

# 透明度
opacity-rule = [
  "80:class_g = 'URxvt'",
  "90:class_g = 'Alacritty'"
];

# 淡入淡出
fading = true;
fade-in-step = 0.03;
fade-out-step = 0.03;

# 避免全屏撕裂
vsync = true;

# 后端
backend = "glx";

# 排除某些窗口
unredir-if-possible = true;

四、启动 Compton

1️⃣ 手动测试

compton --config ~/.config/compton/compton.conf &

或(picom):

picom --config ~/.config/compton/compton.conf &

2️⃣ 开机自启(i3 / Openbox / XFCE)

i3

~/.i3/config 中加:

exec --no-startup-id compton --config ~/.config/compton/compton.conf

Openbox

~/.config/openbox/autostart 中加:

compton --config ~/.config/compton/compton.conf &

XFCE

xfce4-session-settings

→ 应用程序自启动 → 添加 compton


五、常见问题

❓ 透明无效

  • 确认使用的是 终端 / 应用支持透明
  • 确认不是 Wayland
  • 使用 picom 而不是旧版 compton

❓ 屏幕闪烁 / 撕裂

vsync = true;
backend = "glx";

六、Compton vs Picom

项目 Compton Picom
维护状态 ❌ 停止 ✅ 活跃
推荐 旧系统 ✅ 新系统
性能 一般 更好

如果你愿意,可以告诉我:

  • CentOS 版本
  • 桌面环境(i3 / XFCE / GNOME)

我可以给你 完全定制的配置方案

0