一、准备工作:更新系统并安装依赖
在安装Compton前,需确保系统为最新状态,并安装编译工具及必要依赖。打开终端执行以下命令:
sudo yum update -y # 更新系统包
sudo yum groupinstall -y "Development Tools" # 安装编译工具链(gcc、make等)
若使用CentOS 8及以上版本,建议用dnf替代yum(命令格式类似)。
二、安装Compton:选择仓库安装或源码编译
Compton的安装方式分为两种,根据需求选择:
若系统仓库包含Compton(如EPEL仓库),可直接安装:
# 安装EPEL仓库(若未安装)
sudo yum install epel-release -y
# 安装Compton
sudo yum install compton -y # CentOS 7及以下
sudo dnf install compton -y # CentOS 8及以上
此方式安装的Compton版本较稳定,适合大多数用户。
若仓库中没有所需版本,可从GitHub下载源码编译:
# 安装编译依赖
sudo yum install cmake git mesa-libGL-devel mesa-libEGL-devel libX11-devel libXext-devel libXinerama-devel libXrandr-devel libXcursor-devel libXdamage-devel libXcomposite-devel -y
# 下载并编译源码
git clone https://github.com/Compton/Compton.git
cd Compton
mkdir build && cd build
cmake .. # 生成Makefile
make -j$(nproc) # 编译(使用多核加速)
sudo make install # 安装到系统目录
编译过程需联网,耗时取决于网络速度和硬件性能。
三、配置Compton:创建并修改配置文件
Compton的配置文件通常位于用户目录下的.config文件夹中,需手动创建或修改:
mkdir -p ~/.config # 若目录不存在则创建
cp /etc/compton.conf ~/.config/compton.conf # 复制默认配置(若有)
使用文本编辑器(如nano)打开配置文件,修改常用参数:
nano ~/.config/compton.conf
示例配置(开启阴影、模糊效果):
backend = "glx"; # 使用OpenGL后端(需显卡支持)
shadow = true; # 开启窗口阴影
shadow-exclude = "[class='^Firefox$']"; # 排除Firefox窗口的阴影
shadow-opacity = 0.5; # 阴影透明度(0-1)
bg-blur = true; # 开启背景模糊
blur-background-exclude = ["window_type = 'dock'", "window_type = 'desktop'"]; # 排除Dock和桌面模糊
fade = true; # 开启窗口淡入淡出效果
fade-delta = 30; # 淡化速度(毫秒)
保存并退出(Ctrl+O→Enter→Ctrl+X)。
四、启动Compton:手动运行或设置开机自启
通过命令行启动Compton,并指定配置文件:
compton --config ~/.config/compton.conf
若配置文件路径为默认的/etc/compton.conf,可简化为:
compton --config /etc/compton.conf
若需Compton随系统启动,需创建systemd服务文件:
sudo nano /etc/systemd/system/compton.service
写入以下内容(根据安装方式调整ExecStart路径,源码安装为/usr/local/bin/compton,仓库安装为/usr/bin/compton):
[Unit]
Description=Compton Compositor
After=display-manager.service # 在显示管理器启动后运行
[Service]
ExecStart=/usr/bin/compton --config ~/.config/compton.conf
Restart=on-failure # 失败时自动重启
User=你的用户名 # 替换为实际用户名
[Install]
WantedBy=graphical.target # 图形界面目标
保存后执行以下命令启用并启动服务:
sudo systemctl daemon-reload # 重新加载systemd配置
sudo systemctl enable compton # 设置开机自启
sudo systemctl start compton # 立即启动Compton
五、验证安装:检查Compton运行状态
查看版本信息:
compton --version
若显示Compton版本号(如compton 0.1~beta2+20230101-1),说明安装成功。
检查服务状态(若设置了开机自启):
sudo systemctl status compton
若状态为active (running),表示Compton正在运行。
观察视觉效果:
打开应用程序窗口,查看是否有阴影、模糊或淡入淡出效果(根据配置文件设置)。
注意事项
journalctl -u compton.service查看日志排查问题(如权限不足、配置文件错误)。