在 Linux 下使用 Compton(现在多被 fork 为 picom)实现窗口/桌面透明,主要分几种情况。下面按常见需求说明。
# Debian / Ubuntu
sudo apt install compton
# 或使用 picom(推荐)
sudo apt install picom
# Arch
sudo pacman -S picom
创建配置文件:
mkdir -p ~/.config/compton
nano ~/.config/compton/compton.conf
示例配置(透明窗口):
opacity-rule = [
"90:class_g = 'URxvt'",
"85:class_g = 'Firefox'",
"80:class_g = 'Chromium'"
];
或统一透明:
opacity-rule = [
"90:!focused"
];
意思是:非聚焦窗口 90% 不透明度(10% 透明)
compton --config ~/.config/compton/compton.conf &
或 picom:
picom --config ~/.config/compton/compton.conf &
可加入 .xinitrc 或 autostart。
比如 urxvt:
urxvt -depth 32 -bg rgba:0000/0000/0000/cccc
或 .Xresources:
URxvt.depth: 32
URxvt.background: rgba:0000/0000/0000/aa00
opacity-rule = [
"85:class_g = 'URxvt'"
];
Compton 本身不负责桌面背景透明,需要:
feh + comptonfeh --bg-scale wallpaper.jpg
compton &
opacity-rule = [
"90:class_g = 'Polybar'",
"90:class_g = 'Tint2'"
];
opacity-rule = [
"100:fullscreen"
];
picom,不是旧 comptonxprop | grep WM_CLASS
backend = "glx";
opacity-rule = [
"90:!focused",
"100:fullscreen",
"85:class_g = 'URxvt'"
];
shadow = true;
fade = true;
如果你用的是 i3 / bspwm / Openbox / KDE / GNOME,或者想要特定软件透明,可以告诉我,我给你精确配置。