Installing Compton on CentOS
Before using Compton, you need to install it on your CentOS system. For CentOS 7 and earlier, use yum; for CentOS 8 and later, use dnf. If Compton is not available in the default repositories, install the EPEL repository first:
sudo yum install epel-release -y # For CentOS 7
sudo dnf install epel-release -y # For CentOS 8+
sudo yum install compton -y # Install Compton
This ensures you have the latest version of Compton compatible with your system.
Configuring Compton
The main configuration file for Compton is located at ~/.config/compton.conf (create it if it doesn’t exist). A basic configuration for multi-monitor setups with performance optimizations looks like this:
backend "glx" # Use GLX for better performance (alternative: xrender)
shadow-exclude [".*", "[class'.*Firefox']", "[title'.*Firefox']"] # Exclude Firefox from shadows
alpha-mode "none" # Disable alpha blending for better performance
alpha-ignores [".*", "[class'.*Firefox']", "[title'.*Firefox']"] # Ignore Firefox for alpha effects
glx-no-stencil true # Disable stencil buffer for improved performance
glx-copy-from-front true # Optimize front buffer copying
shader-file null # Disable shaders for simplicity
shader-frag null
shader-vert null
xrandr-args "" # Pass additional arguments to xrandr if needed
Key options:
backend: Chooseglxfor hardware acceleration (recommended for modern GPUs) orxrenderfor compatibility.shadow-exclude: Prevents shadows on resource-heavy windows (e.g., Firefox) to improve performance.alpha-mode "none": Disables transparency effects to reduce CPU/GPU load.
Starting Compton
You can start Compton manually with your configuration file:
compton -c ~/.config/compton.conf
To ensure Compton starts automatically on boot, create a systemd service file (/etc/systemd/system/compton.service):
[Unit]
Description=Compton Window Composer
After=display-manager.service # Start after the display manager
[Service]
ExecStart=/usr/bin/compton -c ~/.config/compton.conf
Restart=on-failure # Restart if it crashes
[Install]
WantedBy=multi-user.target # Enable for all users
Reload systemd, enable the service, and start it:
sudo systemctl daemon-reload
sudo systemctl enable compton.service
sudo systemctl start compton.service
Check the status with systemctl status compton.service to confirm it’s running.
Optimizing Performance
Compton can consume significant resources, especially with effects like shadows and transparency. To optimize:
- Disable Unnecessary Effects: Set
shadow falseoropacity 0.8(reduces transparency) in the config file. - Use GPU Acceleration: Ensure
backend "glx"is set (requires a compatible GPU driver). - Limit Resource Usage: Use
cpulimitto cap CPU usage (e.g., limit to 50%):cpulimit -l 50 -p $(pgrep compton) - Adjust Refresh Rate: Add
vsync trueandframe_rate 30to the config file to balance smoothness and performance.
Advanced Tips
- Multi-Monitor Support: Ensure your monitors are configured with
xrandr(e.g.,xrandr --output HDMI-1 --auto --right-of eDP-1). Compton will automatically adapt to the layout. - Background Blur: Enable background blur for a modern look (use with caution—may impact performance):
blur-background true blur-kern "3x3box" # Use a simple blur kernel for better performance - Logging: Enable logging to debug issues (add
--log /path/to/compton.logto the command line or config file).
以上就是关于“compton在centos上的使用技巧”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm