画面のスパニング

Spanning ScreensはWaylandクライアントが複数のスクリーンにまたがる方法を示す例です。

はじめに

Spanning ScreensはWaylandコンポジターの例で、上下のスクリーンにまたがってクライアントを最大化します。

Qtを使った Qt Wayland CompositorをQtで作成する基本な原理については、Minimal QMLの例を参照してください。

複数スクリーンのサポート

Qt では Qt Wayland Compositorでは、スクリーンはWaylandOutput で表現され、クライアントとコンポジターの両方を表現するシーンを含むためにウィンドウが使われます。 Qt Quickのシーンが含まれます。

この例では、プライマリスクリーン上に2つのウィンドウを作成することで、マルチスクリーンのセットアップをエミュレートしていますが、複数の物理的なスクリーンをターゲットにするようにコードを簡単に変更することができます。

// 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でこれを行う方法は、同じクライアント・コンテンツの2つのビューを作成することです:ひとつは "上 "ウィンドウ用、もうひとつは "下 "ウィンドウ用です。ビューは、同じグラフィック・バッファへの参照を共有します。これにより、クライアントの表面の異なる領域をそれぞれのウィンドウにコピーすることができます。

const topItem = chromeComponent.createObject(topSurfaceArea, {
    shellSurface
});

const bottomItem = chromeComponent.createObject(bottomSurfaceArea, {
    shellSurface,
    y: Qt.binding(function() { return -topSurfaceArea.height;})
});

クライアントがシェル拡張 XdgShell に接続すると、サーフェスへの参照を2つ作成します。そのうちの1つは "top "出力に追加され、もう1つは "bottom "に追加される。ボトム出力上のアイテムは、トップ出力の高さに対応するオフセットも取得する。これにより、下の出力に表示されるクライアントサーフェスの一部が、上の出力が終わったところから始まるようになります。

const height = topSurfaceArea.pixelHeight + bottomSurfaceArea.pixelHeight;
const width = Math.max(bottomSurfaceArea.pixelWidth, topSurfaceArea.pixelWidth);
const size = Qt.size(width, height);
toplevel.sendFullscreen(size);

さらに、上下のウィンドウの両方を埋めるように、クライアントの表面のサイズを変更するように指示します。最終的な結果は、2つのウィンドウ、つまり「スクリーン」にまたがるクライアントです。

複数のアイテムから同じクライアント・サーフェスを参照することは、いろいろなことに使えるツールだ。ウィンドウをスクリーンからスクリーンへ移動できるデスクトップスタイルのコンポジターのデモについては、マルチスクリーンの例を見てください。

Multi Outputの例では、クライアントサーフェスをサイズやその他のプロパティが異なる複数の出力に表示する方法を示しています。

注意: 同じコンポジターで複数の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.