From 0a1ea270b6d7d886f6f8ab39faeeeb5b24e045b3 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Tue, 5 Jan 2016 23:45:18 +0100 Subject: Allow headless compositors and avoid crashes Setting a null window used to crash the compositor, but is a supported use case so we shouldn't make any assumption on the window being always available. Change-Id: I9d7cd763427e3910cd36b38ac098cdf217f6b41b Reviewed-by: Paul Olav Tvete --- src/compositor/compositor_api/qwaylandoutput.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/compositor/compositor_api/qwaylandoutput.cpp') diff --git a/src/compositor/compositor_api/qwaylandoutput.cpp b/src/compositor/compositor_api/qwaylandoutput.cpp index 4fb9b3cdc..081393a2c 100644 --- a/src/compositor/compositor_api/qwaylandoutput.cpp +++ b/src/compositor/compositor_api/qwaylandoutput.cpp @@ -249,15 +249,19 @@ void QWaylandOutput::initialize() Q_ASSERT(!d->initialized); Q_ASSERT(d->compositor); Q_ASSERT(d->compositor->isCreated()); - Q_ASSERT(d->window); - d->mode.size = d->window->size(); + if (d->window) + d->mode.size = d->window->size(); + else + d->sizeFollowsWindow = false; QWaylandCompositorPrivate::get(d->compositor)->addOutput(this); - QObject::connect(d->window, &QWindow::widthChanged, this, &QWaylandOutput::setWidth); - QObject::connect(d->window, &QWindow::heightChanged, this, &QWaylandOutput::setHeight); - QObject::connect(d->window, &QObject::destroyed, this, &QWaylandOutput::handleWindowDestroyed); + if (d->window) { + QObject::connect(d->window, &QWindow::widthChanged, this, &QWaylandOutput::setWidth); + QObject::connect(d->window, &QWindow::heightChanged, this, &QWaylandOutput::setHeight); + QObject::connect(d->window, &QObject::destroyed, this, &QWaylandOutput::handleWindowDestroyed); + } d->init(d->compositor->display(), 2); @@ -726,7 +730,7 @@ void QWaylandOutput::setScaleFactor(int scale) * This property controls whether the size of the WaylandOutput matches the * size of its window. * - * The default is true. + * The default is true if this WaylandOutput has a window. */ /*! @@ -735,7 +739,7 @@ void QWaylandOutput::setScaleFactor(int scale) * This property controls whether the size of the QWaylandOutput matches the * size of its window. * - * The default is true. + * The default is true if this QWaylandOutput has a window. */ bool QWaylandOutput::sizeFollowsWindow() const { @@ -745,6 +749,12 @@ bool QWaylandOutput::sizeFollowsWindow() const void QWaylandOutput::setSizeFollowsWindow(bool follow) { Q_D(QWaylandOutput); + + if (!d->window) { + qWarning("Setting QWaylandOutput::sizeFollowsWindow without a window has no effect"); + return; + } + if (follow != d->sizeFollowsWindow) { if (follow) { QObject::connect(d->window, &QWindow::widthChanged, this, &QWaylandOutput::setWidth); -- cgit v1.2.3