QtWayland: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
m (Removed now unused dependency)
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{LangSwitch}}
{{LangSwitch}}


= What is QtWayland? =
== What is QtWayland? ==


QtWayland is a Qt 5 module that wraps the functionality of Wayland. QtWayland is separated into a client and server side. The client side is the wayland platform plugin, and provides a way to run Qt applications as Wayland clients. The server side is the QtCompositor API, and allows users to write their own Wayland compositors.
QtWayland is a Qt 5 module that wraps the functionality of Wayland. QtWayland is separated into a client and server side. The client side is the wayland platform plugin, and provides a way to run Qt applications as Wayland clients. The server side is the Qt Wayland Compositor API, and allows users to write their own Wayland compositors.


== What is Wayland ==
== What is Wayland ==
Line 9: Line 9:
Wayland is a protocol for a compositor to talk to its clients as well as a C library implementation of that protocol. For more detailed information you should visit the [http://wayland.freedesktop.org/ Wayland project homepage]
Wayland is a protocol for a compositor to talk to its clients as well as a C library implementation of that protocol. For more detailed information you should visit the [http://wayland.freedesktop.org/ Wayland project homepage]


= Where can I find the code for QtWayland? =
== How can I get binaries for Qt Wayland? ==
Starting with Qt 5.11. the Qt installer should include binaries for Qt Wayland.
 
If you are using Qt provided by your Linux distribution there is most likely a separate package for Qt Wayland, i.e. qt5-wayland (Arch Linux), or two separate packages, i.e. qtwaylandclient5 and qtwaylandcompositor5-dev (Ubuntu 17.10). Beware that distros may ship really old versions of Qt though, and the compositor API was first released as stable with Qt 5.8.
 
You can however also build it from source yourself in case you want to use the development version or apply custom patches. See section below.
 
== Where can I find the code for QtWayland? ==


[http://code.qt.io/cgit/qt/qtwayland.git/tree/ Qt Wayland Repo]
[http://code.qt.io/cgit/qt/qtwayland.git/tree/ Qt Wayland Repo]


= How do I build QtWayland? =
== How do I build QtWayland? ==
 
== Desktop build instructions ==


=== Ubuntu 14.04 ===
==== Ubuntu 14.04 ====


Ubuntu 14.04 contains all necessary dependencies, so it is no longer necessary to build Wayland yourself. The old instructions are available below.
Ubuntu 14.04 contains all necessary dependencies, so it is no longer necessary to build Wayland yourself.


The following packages are required (list may be incomplete)
The following packages are required (list may be incomplete)
Line 28: Line 33:
* libxkbcommon-dev
* libxkbcommon-dev


qtbase needs to be configured with OpenGL ES2
==== Qt dependency ====
<code>configure -developer-build -opengl es2 [...]</code>
 
The compositor API is still experimental, and not built by default. To enable it, add <tt>wayland-compositor</tt> to the configuration:
<code>
cd qtwayland
qmake CONFIG+=wayland-compositor
</code>
 
=== Setup build environment Ubuntu 12.04 ===
 
The first step is to start with a reasonably modern Linux distribution. I use Ubuntu 12.04, so anything newer is just gravy.
The following instructions are based off of the tips on: http://wayland.freedesktop.org/building.html
 
The first thing I do is start by creating an install directory for my Wayland dependencies and create an environment file to source:
 
So if I wanted to install my Wayland dependencies into the folder $HOME/Apps/Wayland I would create the folder, and then create the file: <br>
''~/Apps/Wayland/wayland.sourceme_
 
<code>#wayland.sourceme
WLD=$HOME/Apps/Wayland # change this to another location if you prefer
LD_LIBRARY_PATH=$WLD/lib
PKG_CONFIG_PATH=$WLD/lib/pkgconfig/:$WLD/share/pkgconfig/
ACLOCAL="aclocal -I $WLD/share/aclocal"
PATH=$WLD/bin:$PATH
XDG_RUNTIME_DIR=/tmp
 
export WLD LD_LIBRARY_PATH PKG_CONFIG_PATH ACLOCAL PATH XDG_RUNTIME_DIR</code>
 
So then source that file to set up your work environment: <br>
''source~/Apps/Wayland/wayland.sourceme''
 
=== Build dependencies ===
 
Most of the dependencies you need are released, but not yet available in the latest Linux distributions, so you will need to build them. Here are the instructions for each in the order that they need to be built:


==== wayland ====
You need Qt5.8 or newer for the compositor API. The modules you need at the very least are: <br>
 
<code>git clone git://anongit.freedesktop.org/wayland/wayland
cd wayland
#this prevents autogen.sh to fail while testing for exiting folders
mkdir -p $WLD/share/aclocal
./autogen.sh —prefix=$WLD
make
make install</code>
 
==== drm ====
 
<code>git clone git://anongit.freedesktop.org/git/mesa/drm
cd drm
./autogen.sh —prefix=$WLD
make && make install</code>
 
==== mesa ====
 
<code>git clone git://anongit.freedesktop.org/mesa/mesa
cd mesa
./autogen.sh —prefix=$WLD —enable-gles2 —disable-gallium-egl \
—with-egl-platforms=x11,wayland,drm —enable-gbm —enable-shared-glapi \
—with-gallium-drivers=r300,r600,swrast,nouveau
make && make install</code>
 
==== libxkbcommon ====
 
<code>git clone git://people.freedesktop.org/xorg/lib/libxkbcommon.git
cd libxkbcommon/
./autogen.sh —prefix=$WLD —with-xkb-config-root=/usr/share/X11/xkb
make && make install</code>
 
==== weston (optional) ====
 
<code>git clone git://anongit.freedesktop.org/wayland/weston
cd weston
./autogen.sh —prefix=$WLD
make
make install -k</code>
 
=== Qt dependency ===
 
Currently, you need to build the latest Qt (stable branch) (see http://lists.qt-project.org/pipermail/development/2013-December/014789.html ) WITHOUT using the wayland.sourceme environment. The modules you need at the very least are: <br>
qtbase <br>
qtbase <br>
qtdeclarative
qtdeclarative


If you face linker errors related to libGL and undefined references, it may be necessary to compile Qt5 and link it with the self compiled mesa. Maybe due to the way that mesa was compiled and installed, the configure script will require to explicitly define the version of OpenGL to be used with: ./configure -opengl es2
==== Building the QtWayland module ====


=== Building the QtWayland module ===
Once you have a working build of Qt 5, then pull down the latest QtWayland module code and configure with "qmake". Make sure that you use the version of qmake that you get with Qt 5 here.


Once you have a working build of Qt 5, then pull down the latest QtWayland module code and configure with "qmake" this time using the wayland.sourceme environment. Make sure that you use the version of qmake that you get with Qt 5 here. This will make sure that the Wayland platform plugin and QtCompositor API are build using your special versions of OpenGL and Wayland.
<code>git clone git://code.qt.io/qt/qtwayland.git
 
<code>source ~/Apps/Wayland/wayland.sourceme
git clone git://code.qt.io/qt/qtwayland.git
cd qtwayland
cd qtwayland
git checkout v5.10.0 # replace with your qt version
qmake
qmake
make
make
make install</code>
make install</code>


== Raspberry Pi build instructions ==
== How do I use QtWayland? ==


Coming soon…
=== Run Qt applications as Wayland clients ===


= How do I use QtWayland? =
When you build the QtWayland module, you should get a new platform plugin for wayland. To use it you must first already have a Wayland compositor running. This could be either the Weston reference compositor provided by the Wayland project, or a Qt example compositor provided by QtWayland. Regardless the only thing you need to do as an application developer to run your GUI application as a wayland client is tell the application to use the right platform plugin:


== Run Qt applications as Wayland clients ==
<code>./application -platform wayland</code>or:<code>export QT_QPA_PLATFORM=wayland
./application</code>


When you build the QtWayland module, you should get a new platform plugin for wayland. To use it you must first already have a Wayland compositor running. This could be either the Weston reference compositor provided by the Wayland project, or a Qt example compositor provided by QtWayland. Regardless the only thing you need to do as an application developer to run your GUI application as a wayland client is:
=== Create and Run your own Wayland Compositor with Qt5 ===


<code>source~/Apps/Wayland/wayland.sourceme
==== Running example compositors ====
./application -platform wayland</code>


== Create and Run your own Wayland Compositor with Qt5 ==
The QtWayland module provides a couple of example compositors that demonstrate how the Qt Wayland Compositor API works. These are built in the examples folder of the QtWayland module. You may need to explicitly build them (depending on how you configured Qt):
<code>cd qtwayland
make sub-examples</code>


=== Running example compositors ===
These examples represent the server side of Wayland, so they do not use the wayland platform plugin, but rather whatever platform you need to run on. Generally this is going to be either ''eglfs'', ''kms'', or if you want to run in X11 ''xcb''. You can also run a nested compositor if you run the compositor on the ''wayland'' platform plugin.


The QtWayland module provides a couple of example compositors that demonstrate how the QtCompositor API works. These are built in the examples folder of the QtWayland module if you add "wayland-compositor" to the CONFIG variable when starting qmake, as in :
If you wanted to run the pure-qml compositor in X11 you would run the following:
<code>qmake CONFIG+=wayland-compositor</code>


These examples represent the server side of Wayland, so they do not use the wayland platform plugin, but rather whatever platform you need to run on. Generally this is going to be either ''eglfs'', ''kms'', or if you want to run in X11 ''xcb''.
<code>cd qtwayland/examples/wayland/pure-qml
 
./pure-qml -platform xcb</code>
If you wanted to run the qml-compositor in X11 you would run the following:
 
<code>source ~/Apps/Wayland/wayland.sourceme
cd qtwayland/examples/qml-compositor
./qml-compositor -platform xcb</code>


And now that you have a Wayland compositor running, you can connect and display Wayland clients.
And now that you have a Wayland compositor running, you can connect and display Wayland clients.


=== Creating your own compositor ===
==== Creating your own compositor ====


The API to create a Wayland compositor and control associated events (e.g. a new client connected) is exposed through the QtWayland class WaylandCompositor. Its constructor expects as the primary parameter a pointer to a QWindow object, which allows some flexibility when implementing your compositor.
Compositors can be implemented using QML, or you can use the C++ API if you need more low-level control.


Thanks to this, there are 3 different approaches while implementing a compositor:
* QML-based: See minimal-qml and pure-qml. [https://www.youtube.com/watch?v=9vWMUTvFgdU Tutorial], [https://www.youtube.com/watch?v=mIg1P3i2ZfI talk]
* C++-based: See the minimal-cpp and qwindow-compositor examples.


* QWindow based: the instance will be used to setup the WaylandCompositor object.
The project file will need to use the compositor module (i.e. add in the .pro file '''QT += waylandcompositor''').


* QWidget based: in this case, the base widget window handle will be used.
== Troubleshooting ==


* QML based: your C++ application will use a QQuickView object to setup the WaylandCompositor. At the time of writing, there is no way to create a compositor using only QML.
=== libGL linker issues ===
 
If you face linker errors related to libGL and undefined references, it may be necessary to compile Qt5 and link it with the self compiled mesa. Maybe due to the way that mesa was compiled and installed, the configure script will require to explicitly define the version of OpenGL to be used with: ./configure -opengl es2
WaylandCompositor is a pure abstract virtual class, which means that it is not possible to create instances of it. A common pattern while implementing a compositor is inherit from WaylandCompositor and implement the function method *void surfaceCreated(WaylandSurface '''surface)'''.
 
This method will be executed every time a new client connects (i.e. an application was started and requests the services of the compositor), being represented as a WaylandSurface object. There are some signals that this object can generate and must be treated by the compositor, namely:
 
* mapped(): emitted when the client has connected to the compositor.
 
* damaged(): TODO
 
* destroyed(): emitted when the client quits (i.e. the application has exited)
 
* unmapped(): TODO
 
* extendedSurfaceReady(): TODO
 
The project file will need to use the compositor module (i.e. add in the .pro file '''QT += compositor'''). It is interesting to comment that at time of writing, there are some QML related APIs only available by adding a define in the project file (i.e. '''DEFINES += QT_COMPOSITOR_QUICK''').
 
=== Starting the compositor standalone ===

Latest revision as of 13:14, 28 March 2019

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

What is QtWayland?

QtWayland is a Qt 5 module that wraps the functionality of Wayland. QtWayland is separated into a client and server side. The client side is the wayland platform plugin, and provides a way to run Qt applications as Wayland clients. The server side is the Qt Wayland Compositor API, and allows users to write their own Wayland compositors.

What is Wayland

Wayland is a protocol for a compositor to talk to its clients as well as a C library implementation of that protocol. For more detailed information you should visit the Wayland project homepage

How can I get binaries for Qt Wayland?

Starting with Qt 5.11. the Qt installer should include binaries for Qt Wayland.

If you are using Qt provided by your Linux distribution there is most likely a separate package for Qt Wayland, i.e. qt5-wayland (Arch Linux), or two separate packages, i.e. qtwaylandclient5 and qtwaylandcompositor5-dev (Ubuntu 17.10). Beware that distros may ship really old versions of Qt though, and the compositor API was first released as stable with Qt 5.8.

You can however also build it from source yourself in case you want to use the development version or apply custom patches. See section below.

Where can I find the code for QtWayland?

Qt Wayland Repo

How do I build QtWayland?

Ubuntu 14.04

Ubuntu 14.04 contains all necessary dependencies, so it is no longer necessary to build Wayland yourself.

The following packages are required (list may be incomplete)

  • libwayland-dev
  • libwayland-egl1-mesa
  • libwayland-server0
  • libgles2-mesa-dev
  • libxkbcommon-dev

Qt dependency

You need Qt5.8 or newer for the compositor API. The modules you need at the very least are:
qtbase
qtdeclarative

Building the QtWayland module

Once you have a working build of Qt 5, then pull down the latest QtWayland module code and configure with "qmake". Make sure that you use the version of qmake that you get with Qt 5 here.

git clone git://code.qt.io/qt/qtwayland.git
cd qtwayland
git checkout v5.10.0 # replace with your qt version
qmake
make
make install

How do I use QtWayland?

Run Qt applications as Wayland clients

When you build the QtWayland module, you should get a new platform plugin for wayland. To use it you must first already have a Wayland compositor running. This could be either the Weston reference compositor provided by the Wayland project, or a Qt example compositor provided by QtWayland. Regardless the only thing you need to do as an application developer to run your GUI application as a wayland client is tell the application to use the right platform plugin:

./application -platform wayland

or:

export QT_QPA_PLATFORM=wayland
./application

Create and Run your own Wayland Compositor with Qt5

Running example compositors

The QtWayland module provides a couple of example compositors that demonstrate how the Qt Wayland Compositor API works. These are built in the examples folder of the QtWayland module. You may need to explicitly build them (depending on how you configured Qt):

cd qtwayland
make sub-examples

These examples represent the server side of Wayland, so they do not use the wayland platform plugin, but rather whatever platform you need to run on. Generally this is going to be either eglfs, kms, or if you want to run in X11 xcb. You can also run a nested compositor if you run the compositor on the wayland platform plugin.

If you wanted to run the pure-qml compositor in X11 you would run the following:

cd qtwayland/examples/wayland/pure-qml
./pure-qml -platform xcb

And now that you have a Wayland compositor running, you can connect and display Wayland clients.

Creating your own compositor

Compositors can be implemented using QML, or you can use the C++ API if you need more low-level control.

  • QML-based: See minimal-qml and pure-qml. Tutorial, talk
  • C++-based: See the minimal-cpp and qwindow-compositor examples.

The project file will need to use the compositor module (i.e. add in the .pro file QT += waylandcompositor).

Troubleshooting

libGL linker issues

If you face linker errors related to libGL and undefined references, it may be necessary to compile Qt5 and link it with the self compiled mesa. Maybe due to the way that mesa was compiled and installed, the configure script will require to explicitly define the version of OpenGL to be used with: ./configure -opengl es2