Debian中Compton的设置技巧
在Debian系统上,首先需要安装Compton及其依赖项。确保系统已更新,然后执行以下命令:
sudo apt update && sudo apt upgrade -y
sudo apt install compton x11-xserver-utils wmctrl -y
创建/编辑配置文件
Compton的默认配置文件位于~/.config/compton.conf
,若不存在则手动创建:
mkdir -p ~/.config
touch ~/.config/compton.conf
使用文本编辑器(如nano
)打开配置文件:
nano ~/.config/compton.conf
关键基础参数设置
backend
决定渲染性能,推荐优先尝试glx
(OpenGL加速),兼容性较好;若遇问题可换为xwayland
(适用于Wayland)或xrender
(传统Xorg)。shadow
设为true
启用阴影,可通过shadow-radius
(模糊半径,默认2)、shadow-dx
/shadow-dy
(偏移量,默认±2)调整;若需排除特定窗口(如GTK应用),可添加shadow-exclude
规则:shadow-exclude = ["class_g 'GtkWindow'", "class_g 'GtkDialog'"];
opacity
设为0.8
(80%透明)或false
(禁用);可通过ignore_root
设为true
避免根窗口透明导致的桌面环境兼容问题。vsync
设为true
开启,减少画面撕裂(需显卡支持)。性能优化
shadow
设为false
、opacity
设为false
,可显著降低CPU/GPU占用。backend
为glx
,并安装对应显卡驱动(如NVIDIA专有驱动),提升渲染性能。cpulimit
工具限制Compton的CPU占用(例如限制为50%):cpulimit -l 50 -p $(pgrep compton)
自定义透明度规则
通过opacity-rule
参数针对不同窗口设置透明度,格式为"条件: 透明度值"
(0.0~1.0)。例如:
opacity-rule = [
"90:name *? 'Typora'", // Typora窗口聚焦时90%透明
"60:name *? 'Typora' && !focused", // Typora非聚焦时60%透明
"95:name *? 'firefox'", // Firefox窗口95%透明
"0:_NET_WM_STATE@:32a * '_NET_WM_STATE_HIDDEN'" // 隐藏窗口完全不透明
];
背景模糊效果
启用blur-background
并设置模糊核(blur-kern
),例如3x3盒式模糊:
blur-background = true
blur-kern = "3x3box"
注意:模糊效果对性能有一定消耗,建议在高性能设备上使用。
若需要Compton随系统启动,可创建systemd服务:
sudo nano /etc/systemd/system/compton.service
你的用户名
为实际用户名):[Unit]
Description=Compton Compositor
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton --config ~/.config/compton.conf
Restart=always
User=你的用户名
[Install]
WantedBy=multi-user.target
sudo systemctl enable compton
sudo systemctl start compton
保存配置文件后,重启Compton使设置生效:
pkill compton
compton --config ~/.config/compton.conf &
测试效果:
htop
或glances
监控系统资源占用,确保Compton未导致性能瓶颈;backend
(如换为xrender
)或禁用部分特效(如阴影、模糊)。