多屏幕
Multi Screen 是一款适用于多屏幕环境的桌面风格 Wayland 合成器。
简介
Multi-screen 是一个适用于多屏幕环境的桌面风格 Wayland 合成器示例。

有关使用 Qt 创建 Qt Wayland Compositor ,请参阅“Minimal Qml”示例。
支持多屏幕
对于系统上的每个可用屏幕,该示例都会创建一个 `CompositorScreen`,它是 `WaylandOutput` 的子类。如果只有一个物理屏幕可用,该示例会使用虚拟数据模拟三个屏幕。
Instantiator {
id: screens
model: emulated ? emulatedScreens : Qt.application.screens
delegate: CompositorScreen {
surfaceArea.color: "lightsteelblue"
text: name
compositor: comp
screen: emulated ? Qt.application.screens[0] : modelData
Component.onCompleted: if (!comp.defaultOutput) comp.defaultOutput = this
position: Qt.point(virtualX, virtualY)
windowed: emulated
}
}每个WaylandOutput 都包含一个Window,用于容纳客户端内容,这与 Qt Wayland Compositor的标准设置。由于每个Window彼此隔离,因此无法在它们之间共享任何Qt Quick 项目。因此,当客户端连接并创建ShellSurface 时,每个屏幕上都会创建一个ShellSurfaceItem 。
for (var i = 0; i < screens.count; ++i)
createShellSurfaceItem(shellSurface, moveItem, screens.objectAt(i));这些项作为同一客户端内容的视图存在。客户端的表面本身仅会被创建一次,并将由这些表面项共享。
顶级表面项作为每个输出中背景Rectangle 的子项被创建。这些视图会被存储以备后用;如果客户端生成任何子窗口,这些子窗口将被归属于顶级窗口的项之下。
var parentSurfaceItem = output.viewsBySurface[shellSurface.parentSurface];
var parent = parentSurfaceItem || output.surfaceArea;客户端内容每次仅在一至两个屏幕上可见。ShellSurfaceItem 的位置会进行同步,因此当窗口进入一个屏幕时,会同时从另一个屏幕移出。这使得内容看起来像是一个在屏幕之间无缝移动的单一项目。 客户端的全局位置存储在共享的moveItem 中,每个屏幕的ShellSurfaceItem 的相对位置是基于此计算得出的。如果moveItem 当前位于某个屏幕的边界之外,其坐标将反映这一状态,且在该屏幕上将不可见。
x: surfaceItem.moveItem.x - surfaceItem.output.geometry.x
y: surfaceItem.moveItem.y - surfaceItem.output.geometry.y最后,会在适当的时候调用WaylandQuickItem::setPrimary() 来设置ShellSurface 的主视图,当客户端请求最大化或全屏时,将使用该视图。主ShellSurfaceItem 的选择基于其当前可见的范围。
注意:为了 支持同一合成器中的多个 Wayland 输出,必须在构建QGuiApplication 对象之前设置Qt::AA_ShareOpenGLContexts 属性。在示例中,我们是在main() 函数的开头进行的此操作。
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);另请参阅 “多输出”。
© 2026 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.