温馨提示×

linux compton如何开启配置

小樊
45
2026-10-12 14:18:30
栏目: 智能运维

在 Linux 上,Compton 是一个常用的 X11 合成器(现在多被 picom 取代,但配置方式几乎一样)。下面从「安装 → 写配置 → 启动 → 开机自启」一步步说明。


一、安装 Compton

根据不同发行版:

# Debian / Ubuntu
sudo apt install compton

# Arch / Manjaro
sudo pacman -S compton

# Fedora
sudo dnf install compton

如果你是新系统,建议直接用 picom(兼容 compton 配置):

sudo apt install picom

二、创建配置文件

Compton 默认读取:

~/.config/compton.conf

如果没有就新建:

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

示例配置(常用)

# 透明与阴影
shadow = true;
shadow-radius = 12;
shadow-opacity = 0.5;
shadow-offset-x = -2;
shadow-offset-y = -2;

# 窗口透明
opacity-rule = [
  "90:class_g = 'URxvt'",
  "95:class_g = 'Firefox'"
];

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

# 性能
backend = "glx";
vsync = true;

三、手动启动 Compton

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

或(picom):

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

测试是否正常:

  • 窗口阴影
  • 透明
  • 动画

四、开机自动启动

1️⃣ 使用桌面环境(推荐)

在「启动应用程序」中添加:

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

2️⃣ i3 / bspwm 用户

在 ~/.config/i3/config 或 bspwmrc 中加:

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

3️⃣ systemd 用户服务(高级)

mkdir -p ~/.config/systemd/user

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

[Unit]
Description=Compton Compositor

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

[Install]
WantedBy=default.target

启用:

systemctl --user enable --now compton

五、常见问题

❌ 黑屏 / 卡顿

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

❌ Wayland 不支持

Compton 只支持 X11,Wayland 请用:

  • wayfire
  • hyprland
  • sway

如果你告诉我:

  • 用什么桌面(i3 / KDE / GNOME)
  • 发行版
  • 想要效果(透明 / 阴影 / 毛玻璃)

我可以直接给你一份可用配置。

0 踩