linux

Linux Compton在虚拟机中如何配置

小樊
35
2025-08-03 01:34:47
栏目: 云计算

在Linux虚拟机中配置Compton窗口合成器,可以按照以下步骤进行:

安装Compton

  1. 更新系统软件包列表

    sudo apt update
    
  2. 安装Compton: 根据你的Linux发行版,使用相应的包管理器进行安装。例如,在基于Debian的系统(如Ubuntu)上:

    sudo apt install compton
    

    在基于Arch的系统上:

    sudo pacman -S compton
    

配置Compton

  1. 找到配置文件: Compton的配置文件通常位于~/.config/compton.conf。如果该文件不存在,你可以手动创建它。

  2. 编辑配置文件: 使用文本编辑器(如nanovim)打开配置文件:

    nano ~/.config/compton.conf
    
  3. 基本配置示例: 以下是一个基本的Compton配置示例,适用于多显示器设置:

    # Compton configuration file
    # Enable or disable compositing
    enable = true
    # Backend to use (xrender, glx, xwayland)
    backend = "glx"
    # Shadow properties
    shadow-exclude = [
        "class_g = 'Compton'",
        "class_g = 'Firefox'",
        "class_g = 'Thunderbird'"
    ]
    # Output device
    output = "eDP-1"
    # Input devices
    input-devices = [
        "eDP-1",
        "pointer:Logitech USB Receiver"
    ]
    # Refresh rate
    refresh-rate = 60
    # Additional options
    shader = "none"
    
    • enable:启用或禁用Compton。
    • backend:选择使用的后端(例如glxxrenderxwayland)。
    • shadow-exclude:排除某些窗口不显示阴影。
    • output:指定输出设备。
    • input-devices:指定要监视的输入设备。
    • refresh-rate:设置刷新率。
    • shader:选择阴影效果。
  4. 启动Compton: 配置完成后,你可以通过以下命令启动Compton:

    compton -c ~/.config/compton.conf
    

    如果你希望Compton在系统启动时自动运行,可以将其添加到你的启动脚本中。例如,在基于systemd的系统上,你可以创建一个服务单元文件:

    sudo nano /etc/systemd/system/compton.service
    

    添加以下内容:

    [Unit]
    Description=Compton Compositor
    After=display-manager.service
    
    [Service]
    ExecStart=/usr/bin/compton -c ~/.config/compton.conf
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    然后启用并启动服务:

    sudo systemctl enable compton
    sudo systemctl start compton
    

注意事项

通过以上步骤,你应该能够在Linux虚拟机中成功配置Compton并为其指定输入设备。如果有任何问题,请检查配置文件的语法和选项是否正确,并确保你的系统支持Compton所需的所有依赖项。

0
看了该问题的人还看了