温馨提示×

如何在Linux上安装Compton并配置

小樊
45
2025-08-11 03:48:53
栏目: 智能运维

安装Compton

根据不同的Linux发行版,使用相应的包管理器进行安装:

  • Debian/Ubuntusudo apt updatesudo apt install compton
  • Fedora/CentOS/RHELsudo dnf install compton(CentOS需先启用EPEL仓库)。
  • Arch Linuxsudo pacman -S compton
  • 从源码安装(可选):git clone https://github.com/compton-compositor/compton.git,进入目录后mkdir build && cd buildcmake ..makesudo make install

配置Compton

创建或编辑配置文件~/.config/compton.conf

  • 常用配置选项
    • backend:选择渲染后端,如glxwayland
    • shadow-exclude:排除不需要阴影的窗口,如shadow-exclude = [ "class_g = 'Firefox'" ]
    • opacity-rule:设置窗口透明度规则,如opacity-rule = [ "class_g = 'Gtk' window_opacity = 0.9" ]
    • fade:启用或禁用淡入淡出效果。
    • vsync:启用或禁用垂直同步。
  • 示例配置
backend = "glx";
shadow-exclude = "*.menu,*.notification";
fade = true;
opacity-rule = [ "class_g = 'Firefox' window_opacity = 0.9" ];

启动Compton

  • 手动启动:在终端中输入compton
  • 设置开机自启动:可创建systemd服务文件/etc/systemd/system/compton.service,内容如下:
[Unit]
Description=Compton Compositor
After=display-manager.service

[Service]
ExecStart=/usr/local/bin/compton --config ~/.config/compton.conf
Restart=always

[Install]
WantedBy=multi-user.target

然后执行sudo systemctl enable comptonsudo systemctl start compton

0