首页主机资讯如何在Linux上安装并配置Compton

如何在Linux上安装并配置Compton

时间2025-12-04 08:20:04发布访客分类主机资讯浏览732
导读:在 Linux 上安装并配置 Compton 一 安装 Compton 基于 Debian/Ubuntu: 更新索引并安装:sudo apt update && sudo apt install compton 基于...

在 Linux 上安装并配置 Compton

一 安装 Compton

  • 基于 Debian/Ubuntu
    • 更新索引并安装:sudo apt update & & sudo apt install compton
  • 基于 Arch Linux
    • 安装:sudo pacman -S compton
  • 基于 Fedora/RHEL/CentOS(若仓库提供):
    • 安装:sudo dnf install compton
  • 若发行版仓库无可用版本,可从源码编译(示例):
    • 安装依赖(Debian/Ubuntu 示例):sudo apt install git cmake build-essential libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxtst-dev libxi-dev libgl1-mesa-glx libcairo2-dev libsqlite3-dev libboost-dev libboost-thread-dev libjsoncpp-dev
    • 编译安装:
      git clone https://github.com/chcg/compton.git
      cd compton
      mkdir build &
          &
           cd build
      cmake ..
      make
      sudo make install
      

以上为常见发行版与源码安装方式,适用于大多数 X11 桌面环境。

二 配置 Compton

  • 配置文件位置与创建:
    • 推荐:~/.config/compton.conf
    • 备选:/etc/xdg/compton.conf
    • 若不存在可创建:touch ~/.config/compton.conf
  • 基本示例(写入到上述配置文件):
    # 后端:glx 通常性能更好;xrender 兼容性更强
    backend = "glx"
    
    # 垂直同步:开可减少撕裂,关可降输入延迟(按显示器与驱动选择)
    vsync = true
    
    # 阴影
    shadow = true
    
    # 窗口透明度(示例:全局 0.9;可按应用覆盖)
    opacity = 0.9
    
    # 忽略根窗口透明度(部分桌面环境需要)
    ignore_root = true
    
  • 常用开关说明:
    • backend:渲染后端,常用 glx / xrender
    • vsync:垂直同步,取值 true/false
    • shadow:窗口阴影,取值 true/false
    • opacity / alpha:透明度相关
    • ignore_root:是否忽略根窗口透明度 以上路径与示例覆盖了大多数使用场景。

三 启动与自启动

  • 手动前台启动(便于查看日志与调试):
    • compton --config ~/.config/compton.conf
  • Systemd 用户级服务(推荐,用户登录即启动):
    1. 创建服务文件:~/.config/systemd/user/compton.service
    2. 写入内容:
      [Unit]
      Description=Compton Window Composer
      After=xorg.target
      
      [Service]
      ExecStart=/usr/bin/compton --config %h/.config/compton.conf
      Restart=on-failure
      
      [Install]
      WantedBy=default.target
      
    3. 启用并启动:
      systemctl --user daemon-reload
      systemctl --user enable --now compton
      
  • Systemd 系统级服务(全局启动,需 root):
    • 创建:/etc/systemd/system/compton.service
    • 写入内容(按需调整路径):
      [Unit]
      Description=Compton Window Composer
      After=xorg.service
      
      [Service]
      ExecStart=/usr/bin/compton --config /etc/compton.conf
      Restart=on-failure
      
      [Install]
      WantedBy=multi-user.target
      
    • 启用并启动:
      sudo systemctl daemon-reload
      sudo systemctl enable --now compton
      
  • 会话集成(不使用 systemd 时):
    • compton --config ~/.config/compton.conf 加入窗口管理器或桌面会话的自动启动脚本(如 Openbox 的 autostart、i3 的 config、Xfce 会话启动等)。 以上方式覆盖手动、用户级与系统级自启动,适配多数桌面与窗口管理器。

四 常见问题与优化

  • 性能优化建议:
    • 优先选择 backend=glx(需驱动支持),必要时退回 xrender
    • 不需要时关闭 shadow、减少 opacity/alpha 使用
    • 根据显示器与显卡驱动选择 vsync true/false
    • 确保启用 GPU 加速 的驱动与库已正确安装
  • 依赖与驱动:
    • 常见基础依赖:libx11-dev、libxrandr-dev、libxcursor-dev、libxdamage-dev、libxext-dev、libxinerama-dev、libxi-dev、libgl1-mesa-dev
    • 确保图形驱动为最新稳定版,以获得更好的合成与 VSync 体验
  • 会话与兼容性:
    • Compton 仅适用于 Xorg 会话,不适用于 Wayland 会话
    • 在部分桌面环境(如 GNOME/KDE)中,系统自带合成器可能与 Compton 冲突,建议仅在使用 Openbox/i3 等轻量 WM 时启用 以上优化与注意事项可显著提升稳定性与流畅度。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: 如何在Linux上安装并配置Compton
本文地址: https://pptw.com/jishu/763172.html
Linux Compton配置中多显示器如何设置 Yum软件包签名验证怎么操作

游客 回复需填写必要信息