Ubuntu下Compton设置技巧:从基础到优化
在Ubuntu系统中,通过APT包管理器快速安装Compton:
sudo apt update && sudo apt install compton
安装完成后,可通过compton --version验证安装是否成功。
Compton的主配置文件默认位于~/.config/compton.conf(若不存在可手动创建)。以下是常用基础参数及说明:
backend = glx(优先选择,性能优于xrender,需显卡支持OpenGL);shadow = true(启用窗口阴影),可进一步调整阴影参数(如shadow-radius = 5、shadow-opacity = 0.3);opacity = 0.8(全局透明度,0.0~1.0,1.0为不透明);ignore_root = true(避免桌面背景出现不必要的透明度问题);vsync = true(减少画面撕裂,提升流畅度)。通过[blur]模块启用背景模糊,提升视觉层次感:
[blur]
method = gaussian # 模糊算法(可选gaussian/fast)
size = 10 # 模糊范围(像素)
deviation = 5.0 # 模糊强度(数值越大越模糊)
适用于追求现代感的桌面风格。
通过[shadow]模块细化阴影设置,避免遮挡重要内容:
[shadow]
no-dnd-shadow = true # 禁用拖放操作的阴影
no-dock-shadow = true # 禁用Dock/面板阴影
shadow-offset-x = 1 # 阴影水平偏移(正值向右)
shadow-offset-y = 1 # 阴影垂直偏移(正值向下)
shadow-opacity = 0.3 # 阴影透明度(0.0~1.0)
可有效减少阴影对窗口内容的干扰。
将backend设置为glx(或wayland,若系统支持),替代默认的xrender,可显著提升渲染性能。
shadow = false(若不需要阴影效果);opacity = false(若不需要窗口透明,能大幅降低CPU占用)。确保显卡驱动已正确安装(如NVIDIA专有驱动),并在配置文件中启用backend = glx,充分利用GPU提升合成性能。
使用cpulimit工具限制Compton的CPU使用率(例如限制为50%):
cpulimit -l 50 -p $(pgrep compton)
避免Compton占用过多系统资源,影响其他应用运行。
让Compton随系统启动自动运行,可通过以下两种方式实现:
在~/.xprofile文件末尾添加(需根据输入法调整,如Fcitx):
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
compton -b --config ~/.config/compton.conf
创建服务文件/etc/systemd/system/compton.service,内容如下:
[Unit]
Description=Compton Window Composer
After=xorg.service
[Service]
ExecStart=/usr/bin/compton --config /etc/compton.conf
RestartOnFailure=yes
[Install]
WantedBy=multi-user.target
启用并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
确保Compton开机自启,无需手动操作。
通过opacity-rule参数为不同应用设置个性化透明度,提升实用性:
opacity-rule = [
"95:class_g = 'Code'", # VS Code及其Insiders版本透明度95%
"66:class_g = 'Dmenu'", # Dmenu菜单透明度66%
"99:class_g = 'Firefox'", # Firefox浏览器透明度99%
"50:class_g = 'Dunst'" # 通知中心Dunst透明度50%
]
可根据应用类型调整透明度,例如工具类应用(如Dmenu)降低透明度以避免遮挡,娱乐类应用(如Firefox)保持较高透明度。
通过exclude参数排除不需要特效的窗口(如通知、输入框),提升稳定性:
exclude = [
"name = 'Notification'", # 排除系统通知
"class_g = 'Dunst'", # 排除Dunst通知
"class_g = 'i3-frame'" # 排除i3窗口管理器的框架窗口
]
避免特效对特定窗口造成干扰(如通知窗口的阴影可能影响可读性)。
通过以上技巧,可根据自身需求调整Compton的视觉效果与性能,在Ubuntu系统上打造流畅、个性化的桌面体验。修改配置文件后,需重启Compton(killall compton && compton &)使更改生效。