一、安裝Compton
Compton是一款輕量級窗口合成器,能有效提升Linux桌面圖形性能。安裝前需更新系統包列表,再根據發行版選擇對應命令:
sudo apt install compton
sudo dnf install compton
sudo pacman -S compton
二、配置Compton(關鍵性能優化參數)
Compton的配置文件通常位于~/.config/compton.conf
(用戶級)或/etc/xdg/compton.conf
(系統級)。若文件不存在,可手動創建。以下是核心性能優化參數:
后端決定了Compton的渲染方式,優先選擇glx
(OpenGL)或wayland
(現代桌面協議),避免使用xrender
(性能較差)。在配置文件中添加:
backend = "glx"
確保顯卡驅動已正確安裝(如NVIDIA/AMD專有驅動),以充分發揮GPU加速優勢。
視覺特效(如陰影、模糊、透明度)會增加GPU負載,降低幀率。根據需求調整:
shadow = false
opacity = false
blur-background = false
ignore-root = true
。垂直同步可防止畫面撕裂,但會引入輸入延遲并降低幀率。若追求高幀率,可關閉VSync:vsync = false
;若需平衡流暢度與撕裂,可開啟:vsync = true
。需根據顯示器刷新率(如60Hz、144Hz)和顯卡性能調整。
通過fps-limit
參數限制Compton的最大幀率,避免不必要的GPU計算。例如,設置為顯示器原生刷新率(如60):fps-limit = 60
,可減少GPU負載。
通過shadow-exclude
參數排除不需要陰影的窗口(如對話框、工具窗口),減少合成負擔。例如:
shadow-exclude = ["class_g = 'confirm'", "class_g = 'dialog'", "class_g = 'download'", "class_g = 'error'", "class_g = 'notification'"]
該配置會忽略常見對話框和通知窗口的陰影,提升合成效率。
三、啟動與自動運行
配置完成后,需重啟Compton使更改生效:
# 停止當前運行的Compton
killall compton
# 使用新配置啟動
compton -b --config ~/.config/compton.conf
若需Compton隨系統啟動自動運行,可創建Systemd服務:
sudo nano /etc/systemd/system/compton.service
[Unit]
Description=Compton Window Composer
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton -b --config /etc/compton.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable compton
sudo systemctl start compton
四、注意事項
killall compton
)或調整配置(如關閉glx-no-stencil
:glx-no-stencil = true
)。htop
或glances
監控Compton的CPU/GPU占用率,若占用過高,可進一步禁用特效(如關閉fps-limit
或調整shadow-exclude
規則)。cp ~/.config/compton.conf ~/.config/compton.conf.bak
),以便出現問題時恢復。