Qt Wayland client wait for Wayland Compositor
-
I am creating my own wayland compositor and client program.
In an ideal world, the compositor will be loaded before the client application. I have encountered a situation where this is not true.
However, I was wondering if there was a way for the client app to wait programmatically for the compositor before running.
-
Hi and welcome to devnet,
Can you describe the situation when it happens ?
-
Yes, I get the following message when I try to run my wayland client.
Failed to create wl_display (No such file or directory)
qt.qpa.plugin: Could not load the Qt platform plugin "wayland" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: wayland-egl, wayland.I know this is a pretty standard message. In my situation I know it is because the wayland compositor hasn't fully initialized yet. If I manually wait a second or two to launch the wayland client everything works fine. However, adding in wasted time is undesired as boot time is critical.
-
How are you starting the compositor ?
-
You could use the wayland-client library like this before your instantiate your QApplication:
#include <QApplication> #include <wayland-client.h> #include <unistd.h> int main(int argc, char *argv[]) { struct wl_display *display = NULL; while(!display) { // Return NULL if no compositor avaliable in wayland-0 display = wl_display_connect(NULL); // Wait 200 ms so you dont overuse your CPU usleep(200000); } // Disconnect because QApplication will stablish its own connection wl_display_disconnect(display); // Start the app QApplication app(argc,argv); ... }
Its a bit ugly but it should work.