多重输出

多重输出(Multi Output)是一个演示具有多重输出的合成器的示例。

简介

多输出示例演示了如何通过不同类型的合成在不同的WaylandOutputs 上显示相同的客户端。一种输出以统一的网格显示客户端,并按比例缩放至相同大小。另一种输出则是普通桌面风格的交互式合成窗口。

如需了解使用 Qt 创建合成器的基本原理,请参阅 "最小化合成器"。 Qt Wayland Compositor基本原理,请参阅Minimal QML 示例

多重输出

该示例创建了两个不同的窗口,每个输出窗口一个。对于网格视图,我们连接到surfaceRequested 信号。客户端创建的每个表面都会发出该信号。这允许应用程序覆盖对请求的默认响应,并创建自定义的WaylandSurface

onSurfaceRequested: (client, id, version) => {
    var surface = surfaceComponent.createObject(comp, { } );
    surface.initialize(comp, client, id, version);
}

接收到信号后,示例会创建一个WaylandQuickItem 作为表面的视图。它可以像其他项目一样添加到Qt Quick 场景中。在示例中,我们将其添加到GridView 中。

对于桌面风格的窗口,我们使用了XdgShell 扩展的功能。曲面创建完成后,XdgShell 会发出toplevelCreated 信号。

XdgShell {
    onToplevelCreated: (toplevel, xdgSurface) => {
        var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": xdgSurface } );
        item.surface.activated.connect(item.raise);
    }
}

我们创建一个ShellSurfaceItem ,将XdgToplevel 添加到第二个输出中。这样就能与表面进行桌面风格的交互。

完成这些步骤后,客户端的内容在两个窗口中均可见。包含客户端内容的缓冲区在两个输出窗口中都是相同的,但以两种不同的方式可视化,并为用户提供了不同的交互方式。

注: 为了在同一合成器中支持多个 Wayland 输出,必须在构建QGuiApplication 对象前设置Qt::AA_ShareOpenGLContexts 属性。

示例项目 @ code.qt.io

另请参阅 "多屏幕"和 "概览合成器"。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.