Client: Fail gracefully when wl_display_connect fails

[ChangeLog][QPA plugin] If we're unable to create a connection to the Wayland
display, fail gracefully so other platform integrations can be tried instead.

This also adds QWaylandIntegration::hasFailed() which can later be extended to
report that the platform plugin is unusable for other reasons. I.e. no
compatible shell extensions or similar.

Task-number: QTBUG-59762
Change-Id: I0f1ae73982e2860814235c1a189741d130e1db3e
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2018-02-14 16:22:25 +01:00 committed by Johan Helsing
parent bf18cfcd84
commit ef99cac249
3 changed files with 12 additions and 4 deletions

View File

@ -142,9 +142,9 @@ QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration)
qRegisterMetaType<uint32_t>("uint32_t");
mDisplay = wl_display_connect(nullptr);
if (mDisplay == nullptr) {
qErrnoWarning(errno, "Failed to create display");
::exit(1);
if (!mDisplay) {
qErrnoWarning(errno, "Failed to create wl_display");
return;
}
struct ::wl_registry *registry = wl_display_get_registry(mDisplay);
@ -170,6 +170,7 @@ QWaylandDisplay::~QWaylandDisplay(void)
#if QT_CONFIG(wayland_datadevice)
delete mDndSelectionHandler.take();
#endif
if (mDisplay)
wl_display_disconnect(mDisplay);
}

View File

@ -134,6 +134,10 @@ QWaylandIntegration::QWaylandIntegration()
{
initializeInputDeviceIntegration();
mDisplay.reset(new QWaylandDisplay(this));
if (!mDisplay->isInitialized()) {
mFailed = true;
return;
}
#if QT_CONFIG(clipboard)
mClipboard.reset(new QWaylandClipboard(mDisplay.data()));
#endif

View File

@ -73,6 +73,8 @@ public:
QWaylandIntegration();
~QWaylandIntegration();
bool hasFailed() { return mFailed; }
bool hasCapability(QPlatformIntegration::Capability cap) const override;
QPlatformWindow *createPlatformWindow(QWindow *window) const override;
#if QT_CONFIG(opengl)
@ -144,6 +146,7 @@ private:
#if QT_CONFIG(accessibility)
QScopedPointer<QPlatformAccessibility> mAccessibility;
#endif
bool mFailed = false;
bool mClientBufferIntegrationInitialized;
bool mServerBufferIntegrationInitialized;
bool mShellIntegrationInitialized;