温馨提示×

怎么在centos配compton

小樊
37
2026-10-20 19:15:58
栏目: 智能运维

在 CentOS 上配置 compton(现在社区更常用的是它的分支 picom)一般步骤如下。下面以 CentOS 7 / 8 为例,假设你使用的是 X11 桌面环境(如 GNOME、XFCE、MATE 等)。


一、确认环境

compton 只支持 X11,不支持 Wayland。

echo $XDG_SESSION_TYPE

输出应为:

x11

如果是 wayland,需要先切换到 X11 会话。


二、安装 compton

方式 1:EPEL 安装(推荐,简单)

CentOS 7

sudo yum install -y epel-release
sudo yum install -y compton

CentOS 8 / Stream

sudo dnf install -y epel-release
sudo dnf install -y compton

如果仓库中没有 compton,建议直接装 picom(见下文)。


方式 2:安装 picom(compton 的活跃分支,推荐)

sudo dnf install -y picom

或者从源码编译(功能更新):

sudo dnf install -y git meson ninja-build gcc make \
  libconfig-devel dbus-devel pixman-devel xcb-util-devel \
  xcb-util-image-devel xcb-util-renderutil-devel

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

三、创建配置文件

配置文件通常位于:

~/.config/compton.conf
# 或 picom
~/.config/picom.conf

基础示例(compton.conf)

backend = "glx";
vsync = true;

shadow = true;
shadow-radius = 12;
shadow-opacity = 0.5;
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 = 'Firefox'",
  "80:class_g = 'URxvt'"
];

unredir-if-possible = true;

四、启动 compton

手动启动

compton --config ~/.config/compton.conf -b
# 或 picom
picom --config ~/.config/picom.conf -b

-b 表示后台运行。


开机自启

GNOME / XFCE

把启动命令加到「启动应用程序」:

compton --config ~/.config/compton.conf -b

systemd 用户服务(推荐)

mkdir -p ~/.config/systemd/user

创建:

~/.config/systemd/user/compton.service

内容:

[Unit]
Description=Compton compositor
After=graphical-session.target

[Service]
ExecStart=/usr/bin/compton --config %h/.config/compton.conf -b
Restart=on-failure

[Install]
WantedBy=default.target

启用:

systemctl --user enable compton
systemctl --user start compton

五、常见问题

1. 黑屏 / 卡顿

  • 关闭 vsync
  • 改用 backend = "xrender"

2. NVIDIA 显卡

建议使用:

backend = "xrender";
vsync = false;

3. 全屏游戏卡顿

unredir-if-possible = true;

六、检查是否运行

ps aux | grep compton

如果你能告诉我:

  • CentOS 版本
  • 桌面环境(GNOME / XFCE / KDE)
  • 显卡型号

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

0 踩