跨屏幕
跨越屏幕是一个演示如何让 Wayland 客户端跨越多个屏幕的示例。
简介
跨屏是一个 Wayland 合成器示例,它能最大化跨顶部和底部屏幕的客户端。
有关使用 Qt 创建 Qt Wayland Compositor的基本原理,请参阅Minimal QML 示例。
支持多屏幕
在 Qt Wayland Compositor中,一个屏幕由WaylandOutput 表示,一个窗口用于包含 Qt Quick场景代表客户端和合成器的用户界面。
在本示例中,通过在主屏幕上创建两个窗口来模拟多屏幕设置,但代码可以很容易地修改为针对多个物理屏幕。
// Enable the following to make the output target an actual screen, // for example when running on eglfs in a multi-display embedded system. // screen: Qt.application.screens[0]
由于每个窗口代表一个独立的 Qt Quick场景,这就意味着我们需要一个技巧,让相同的客户端内容同时显示在两个窗口中。在 Qt Wayland Compositor中实现这一目的的方法是为相同的客户端内容创建两个视图:一个用于 "顶部 "窗口,另一个用于 "底部 "窗口。这些视图共享对相同底层图形缓冲区的引用。这样,我们就可以将客户端表面的不同区域复制到每个窗口上。
const topItem = chromeComponent.createObject(topSurfaceArea, { shellSurface }); const bottomItem = chromeComponent.createObject(bottomSurfaceArea, { shellSurface, y: Qt.binding(function() { return -topSurfaceArea.height;}) });
当客户端连接到shell 扩展程序XdgShell 时,我们会创建两个曲面引用。其中一个被添加到 "顶部 "输出,第二个被添加到 "底部 "输出。底部输出上的项目也会获得与顶部输出高度相对应的偏移量。这样可以确保在底部输出中显示的客户端表面部分从顶部输出结束的地方开始。
const height = topSurfaceArea.pixelHeight + bottomSurfaceArea.pixelHeight; const width = Math.max(bottomSurfaceArea.pixelWidth, topSurfaceArea.pixelWidth); const size = Qt.size(width, height); toplevel.sendFullscreen(size);
此外,我们还告诉客户端调整其表面大小,使其填满顶部和底部窗口。最终的结果是一个跨越两个窗口或 "屏幕 "的客户端。
从多个项目中引用同一个客户端表面是一种可以用于多种用途的工具。如需演示可在屏幕间移动窗口的桌面式合成器,请参阅多屏幕示例。
多输出示例展示了如何在具有不同尺寸和其他属性的多个输出上显示客户端表面。
注: 为了在同一合成器中支持多个 Wayland 输出,必须在构建QGuiApplication 对象前设置Qt::AA_ShareOpenGLContexts 属性。
© 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.