如何在Linux上用Compton配置镜像显示
在配置镜像显示前,需先确保系统已安装Compton。根据发行版选择以下命令:
sudo apt update && sudo apt install comptonsudo dnf install comptonsudo pacman -S comptonCompton的配置文件通常位于~/.config/compton.conf(用户级)或/etc/xdg/compton.conf(系统级)。若文件不存在,可通过以下命令创建:
mkdir -p ~/.config
nano ~/.config/compton.conf
使用文本编辑器(如nano)打开文件,后续需添加镜像相关的核心配置。
镜像显示的本质是让多个显示器显示相同内容,需通过Compton的xrandr-output参数指定显示器同步关系。操作步骤如下:
xrandr命令,输出会列出所有连接的显示器(如HDMI-1、eDP-1)及当前分辨率。记下需要镜像的显示器名称(例如HDMI-1和eDP-1)。compton.conf的[composite] section(若无则新建)中,添加以下内容:[composite]
xrandr-output = "HDMI-1 eDP-1"; # 替换为你的显示器名称,用空格分隔
此参数会告知Compton将HDMI-1和eDP-1的内容同步显示(镜像)。为提升镜像显示的效果和性能,可调整以下参数:
shadow = false;
vsync = true;
glx后端提升渲染性能(需显卡支持OpenGL):backend = "glx";
glx-no-stencil = true; # 禁用GLX模板缓冲区,减少资源占用
shadow-exclude = ["class_g = 'Desktop'", "class_g = 'Dunst'"]; # 排除桌面和通知窗口
这些参数可根据实际需求添加到compton.conf中。compton -c ~/.config/compton.conf
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
xrandr-output参数是否正确,或查看Compton日志排查问题:journalctl -u compton -f # 实时查看Compton日志
xrandr-output中的显示器名称与xrandr命令输出一致,且显示器已通过系统设置正确连接。shadow = false)、降低刷新率(vsync = false)或使用更轻量的后端(如backend = "xrender",但性能提升有限)。-c ~/.config/compton.conf),或检查systemd服务文件中的路径是否正确。通过以上步骤,即可在Linux上使用Compton配置镜像显示,实现多个显示器同步输出相同内容的需求。