温馨提示×

linux compton如何透明

小樊
50
2026-09-09 18:36:59
栏目: 智能运维

在 Linux 上让 Compton(或已更名为 Picom) 实现窗口/桌面透明,通常分为三类:窗口透明、桌面背景透明、整体效果透明。下面按常见用法说明。


一、安装 Compton / Picom

# Debian / Ubuntu
sudo apt install compton

# 或使用 picom(新版本)
sudo apt install picom

# Arch
sudo pacman -S picom

现代系统推荐直接用 picom,compton 已停止维护。


二、基础配置文件

配置文件一般位于:

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

最小配置示例:

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

三、实现窗口透明(重点)

1️⃣ 全局窗口透明度(不推荐太狠)

opacity-rule = [
  "0.9"
];

这样所有窗口都是 90% 不透明。


2️⃣ 按窗口类型透明(推荐)

opacity-rule = [
  "90:class_g = 'URxvt'",
  "80:class_g = 'Alacritty'",
  "70:class_g = 'Termite'",
  "95:class_g = 'Firefox'"
];

含义:

  • URxvt → 90% 不透明
  • Alacritty → 80%
  • Firefox → 95%

3️⃣ 聚焦/失焦窗口透明(很常见)

inactive-opacity = 0.8;
active-opacity = 1.0;
  • 当前窗口:100%
  • 非当前窗口:80%

四、桌面透明(伪透明)

如果你用的是 i3 / bspwm / openbox 等,没有原生桌面:

方法 1:透明终端 + 壁纸

opacity-rule = [
  "85:class_g = 'URxvt' || class_g = 'Alacritty'"
];

方法 2:用 feh 设置壁纸

feh --bg-scale ~/wallpaper.png

五、真正“桌面透明”(Composite 透明)

Compton 本身不能让桌面容器透明,只能让窗口透明。

如果你想要:

  • 桌面图标透明
  • 面板透明
  • 整体毛玻璃

需要:

  • KDE(KWin)
  • GNOME(Mutters)
  • 或 xcompmgr

六、毛玻璃 / 模糊透明(高级)

blur:
{
  method = "gaussian";
  size = 10;
  deviation = 5.0;
};

opacity-rule = [
  "90:class_g = 'Alacritty'"
];

效果:

  • 窗口后面模糊
  • 类似 macOS

七、启动 Compton

compton &
# 或
picom &

写入 ~/.xinitrc 或 i3 配置:

exec --no-startup-id picom

八、常见问题

❌ 透明无效?

  • 确认窗口管理器支持 compositing
  • 确认没有多个 compositor 冲突(如 xcompmgr)

❌ 全屏游戏黑屏?

unredir-if-possible = true;

如果你告诉我:

  • 用的 桌面环境 / 窗口管理器
  • 想要 终端透明 / 面板透明 / 毛玻璃

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

0 踩