温馨提示×

CentOS Compton图形界面设置

小樊
37
2025-10-17 19:45:53
栏目: 智能运维

Installing Compton on CentOS
Before configuring Compton, you need to install it on your CentOS system. Use the following commands to set it up:

  • Update your system packages: sudo yum update -y (for CentOS 7) or sudo dnf update -y (for CentOS 8/Stream).
  • Install Compton: For CentOS 7, run sudo yum install epel-release -y followed by sudo yum install compton -y. For CentOS 8/Stream, use sudo dnf install compton -y.
    These steps ensure you have the latest version of Compton and its dependencies.

Configuring Compton
Compton’s configuration is managed via a config file, typically located at ~/.config/compton.conf (user-specific) or /etc/compton.conf (system-wide). If the file doesn’t exist, create it using a text editor like nano or vim. Below are key parameters to customize:

  • Backend: Choose between glx (OpenGL, better performance) or xrender (software-based, more compatible). Example: backend = "glx";.
  • Shadows: Enable shadows with shadow = true; and exclude specific windows (e.g., Firefox) to avoid unnecessary rendering. Example: shadow-exclude = ["class='.*Firefox'"];.
  • Transparency: Adjust window transparency with alpha-mode = "screen"; and alpha-ignores = ["class='.*Firefox'"]; (excludes Firefox from transparency).
  • Fade Effects: Enable fading for window open/close/minimize with fade = true; and set the fade duration with fade-delta = 30;.
  • Background: Set a desktop background image with bg.use_desktop_bg = true; and specify the image path: bg.desktop_bg_image = "/path/to/image.jpg";.

Example minimal config for performance:

backend = "glx";
shadow-exclude = [".*"];
glx-no-stencil = true;
glx-copy-from-front = true;

Save the file after editing.

Starting Compton
You can start Compton in two ways:

  • Manual Start: Run compton --config ~/.config/compton.conf & to start it in the background. The & ensures it runs without blocking your terminal.
  • Systemd Service: For automatic startup on login, create a systemd service file:
    1. Run sudo nano /etc/systemd/system/compton.service.
    2. Add the following content (adjust the config path if needed):
      [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
      
    3. Save the file, then run:
      sudo systemctl daemon-reload
      sudo systemctl enable compton.service
      sudo systemctl start compton.service
      
    This ensures Compton starts automatically when you log in.

Verifying and Troubleshooting
To confirm Compton is running, use:

  • ps aux | grep compton: Look for a compton process.
  • systemctl status compton.service: Check the service status (should show “active (running)”).

If you encounter issues (e.g., no shadows, high CPU usage), check the Compton log (enable logging by adding log-file = "/var/log/compton.log"; to the config) or run journalctl -u compton.service -e to view systemd logs. Common fixes include adjusting the backend (glx vs xrender) or excluding problematic applications from shadows/transparency.

Performance Optimization Tips

  • Backend Choice: Use glx for NVIDIA/AMD GPUs (better performance) and xrender for Intel integrated graphics (more compatibility).
  • Reduce Overhead: Enable vsync = true; to sync with your monitor’s refresh rate and frame-rate = 30; to limit rendering to 30 FPS.
  • Exclude Unnecessary Windows: Add more entries to shadow-exclude (e.g., "[class='.*Chrome']") to reduce rendering load.
  • Cache Size: Increase the cache with cache-size = 100M; (default is 50M) to improve performance for complex windows.

0