一、安装Compton
Compton的安装需根据Linux发行版选择对应包管理器,常见命令如下:
sudo apt update && sudo apt install comptonsudo dnf install comptonsudo pacman -S comptoncompton --version验证是否安装成功。二、配置Compton
Compton的主配置文件通常位于~/.config/compton.conf(用户级)或/etc/compton.conf(系统级)。若文件不存在,可通过以下命令创建:
touch ~/.config/compton.conf
使用文本编辑器(如nano、vim)打开配置文件:
nano ~/.config/compton.conf
配置文件中的参数可根据需求调整,以下是常用选项及示例:
基础设置:
backend:指定渲染后端(glx或xrender),glx性能更优但需显卡支持,xrender兼容性更好,默认xrender。vsync:启用垂直同步(true/false),防止画面撕裂,默认false。shadow:启用窗口阴影(true/false),默认false。opacity:全局窗口透明度(0.0~1.0,1.0为不透明),默认1.0。ignore_root:忽略根窗口透明度(避免桌面背景透明导致的问题),建议设为true。阴影效果(需shadow=true):
shadow-radius:阴影半径(像素),默认10。shadow-offset-x/y:阴影偏移量(像素),默认3/3。shadow-opacity:阴影透明度(0.0~1.0),默认0.3。背景模糊(需手动添加):
blur-background:启用背景模糊(true/false),默认false。blur-method:模糊算法(gaussian/box),gaussian效果更自然。blur-size:模糊范围(像素),默认10。blur-deviation:模糊强度(0.0~10.0),默认5.0。透明度规则(可选):
通过opacity-rule为特定窗口设置透明度,格式为"CLASS='窗口类名', opacity=数值;",例如:
opacity-rule = [ "CLASS='Firefox', opacity=0.9;", // Firefox透明度90% "CLASS='GIMP', opacity=0.8;" // GIMP透明度80% ]; 示例配置(启用GLX后端、阴影、背景模糊):
backend = "glx"; vsync = true; shadow = true; shadow-radius = 5; shadow-offset-x = 1; shadow-offset-y = 1; shadow-opacity = 0.3; opacity = 0.8; ignore_root = true; blur-background = true; blur-method = "gaussian"; blur-size = 10; blur-deviation = 5.0; 三、启动Compton
配置完成后,可通过以下命令启动Compton:
compton &compton --config ~/.config/compton.conf &killall compton终止进程,再重新运行上述命令。四、设置开机自启动
为了让Compton随系统启动自动运行,需创建Systemd服务文件:
sudo nano /etc/systemd/system/compton.serviceExecStart):[Unit] Description=Compton Window Composer After=display-manager.service [Service] ExecStart=/usr/bin/compton --config ~/.config/compton.conf Restart=on-failure [Install] WantedBy=multi-user.target sudo systemctl daemon-reload sudo systemctl enable compton sudo systemctl start compton 此后,Compton将在系统启动时自动运行。
五、调试与优化
若Compton运行异常(如窗口闪烁、卡顿),可通过以下方法调试:
compton --log-file=/tmp/compton.log,日志会输出到/tmp/compton.log,帮助定位问题。backend(如xrender)、禁用阴影(shadow=false)或背景模糊(blur-background=false)。disable-gpu-compositing=true,但会降低性能。