温馨提示×

怎样给centos配compton

小樊
41
2026-10-23 20:22:30
栏目: 智能运维

在 CentOS 上配置 compton(一个轻量级 X11 合成管理器,常用于 i3 / openbox 等窗口管理器实现透明和阴影)大致步骤如下。下面以 CentOS 7/8 为例,CentOS 9 也基本类似(但仓库可能更偏 EPEL)。


一、安装 compton

1. 启用 EPEL 仓库

sudo yum install -y epel-release
# CentOS 8 用 dnf
sudo dnf install -y epel-release

2. 安装 compton

sudo yum install -y compton
# 或
sudo dnf install -y compton

如果仓库里没有 compton,可以考虑用 picom(compton 的 fork):

sudo dnf install -y picom

二、基础配置

1. 创建配置文件

mkdir -p ~/.config/compton
vi ~/.config/compton/compton.conf

2. 示例配置(常用)

backend = "glx";
glx-no-stencil = true;

shadow = true;
shadow-radius = 8;
shadow-opacity = 0.4;
shadow-offset-x = -2;
shadow-offset-y = -2;

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";

三、启动 compton

方式一:手动启动(测试)

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

方式二:开机自启(i3 示例)

在 ~/.config/i3/config 中加入:

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

如果是 Openbox:

echo "compton --config ~/.config/compton/compton.conf &" >> ~/.config/openbox/autostart

四、常见问题排查

1. 透明无效

  • 确保使用的是 X11(不是 Wayland)
  • 窗口管理器支持 compositing
  • 显卡驱动正常(尤其是 NVIDIA)

2. GLX 报错

尝试改为:

backend = "xrender";

3. CentOS 9 无 compton

直接用 picom:

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

五、检查是否运行

ps aux | grep compton

如果你能告诉我:

  • CentOS 版本
  • 使用的桌面 / 窗口管理器(GNOME / KDE / i3 / Openbox)
  • 是否 NVIDIA 显卡

我可以给你更精确的配置。

0 踩