Wayland is a display protocol, a protocol (and accompanying C library) spoken by a graphical application with a display server in order to communicate about both input to the application (keyboard, mouse, ...) and about output from the application -- that is, the rendered window. Wayland was developed to replace the X11 server on the Linux system. After quite a few years of incubation, it's becoming much more common. It's a far simpler and more attractive protocol compared to X11, allowing much more flexibility in developing custom compositors and control in the display compositor on how the client applications are shown and with less decades-old baggage to keep around and take into account.
So, what's the problem?
Qt provides both a Wayland platform allowing you to run Qt applications as Wayland clients in a Wayland compositor and a library to build a Wayland compositor, both using QML or not, in the Qt Wayland module. However, that and Wayland, in general, are only available on Linux, which may prove to be a problem for many. Many projects that target a Linux embedded platform but are developed on Windows because of some tooling that is only available there or for any other reason end up using a Linux virtual machine, which is a far less than optimal solution. It has several disadvantages: worse performance, an OS and environment that you are not used to, possibly bad or no hardware support for some devices, and a clunky user experience.
A Better Solution
There is a better solution. With the WSL subsystem on Windows, it is actually possible to run directly (albeit through an X server and so far unfortunately only OpenGL software) a Wayland compositor and clients. By running a Wayland compositor directly in your Windows machine, you avoid all the aforementioned problems. In this blog post, I'll explain how to do it.
First, you need to setup WSL2, following the guide at https://docs.microsoft.com/en-us/windows/wsl/install-win10.
After that, you need to install an X server for Windows. I've successfully tried both VcxSrv and Xming. Launch it, but make sure to disable access control. If you're using VcxSrv or Xming, there is an option in the XLaunch utility for that.
Now open the terminal of the Linux distribution you installed from the Start menu (I'm using Ubuntu 20.04, but any distribution should work) and run these commands:
sudo apt update && sudo apt upgrade
sudo apt install weston
If you picked another distribution, you may need to adapt these commands, but it should not be difficult.
We are almost there. Now we need to tell the compositor the location of the X server. To do that, you need to open the PowerShell from the Start menu, run the ipconfig
command, and locate IPv4 address in the section about the WSL adapter (usually the last one). In the Linux terminal, that's the address we need to use to connect to the X server:
export DISPLAY=<address>:0
Wayland also needs the XDG_RUNTIME_DIR
environment variable to know where to put the socket file:
mkdir /tmp/xdg
export XDG_RUNTIME_DIR=/tmp/xdg
We are going to add this export
line also at the end of the .bashrc
file so that it's run automatically every time a terminal is opened.
Now if you run weston
, you should see it open a window. To then run a Wayland client, open another Linux terminal and run a Wayland client. Weston provides a few, such as weston-terminal
. But you can also install and run any Qt application by using the -platform wayland
command line parameter or exporting the QT_QPA_PLATFORM=wayland
environment variable beforehand, provided you've installed the QtWayland module. On Ubuntu, that is only a sudo apt install qtwayland5
away.
4 Comments
20 - Oct - 2021
Sacha Refshauge
If you install WSLg (to be default in future I assume), it comes with wayland/weston already and you can just run wayland apps out of the box.
https://github.com/microsoft/wslg
20 - Oct - 2021
Giulio Camuffo
Yes, but for that you need Windows 11, and you need to opt into the Windows Insider Program.
20 - Feb - 2022
hubbert smith
The article is about running a GUI from WSL, OK. is it possible to run a Win10 or Win11 client accessing the Linux app from a different machine via wayland? just like you'd run an X11 client on Win10 and access a Linux app on another machine hubbert@hubbertsmith.com
25 - Nov - 2024
UEPH
Good day, The information is incomplete, but looks like a good website for this free tutorial. More detailed procedure, with Output Terminal, with Path environment, files installed, etc. ... is needed. The procedure is lost when one install VcxSrv or Xming, but then "weston" happen. Where come all this from? Where is the Windows Advanced User security after installation? ... Official Microsoft has nodetailed information available in the Website to check if there is a "break binary". What was the porpuse to this procedure, was also not included. As the technical level of the forum, as the source of the information, etc.
The tutorial "OpenGL in Qt 5.1 – Part 1" and Part 2 are too incomplete.
I'd like you have information on Youtube, I check it later, I hope is full of detailed informaiton, and complete steps.
Microsoft Support in my location is not as good European-Standards, so don't take it loosy.
See you in Germany!
Regards, LG!