From 2b34aefcf02f09253473b096eb4faffd3e62b5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 10 Feb 2017 16:15:03 +0100 Subject: [PATCH] Lazily create QPlatformWindow for Qt::Desktop windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QDesktopWidget only needs a QWindow to access its screen, and has no use for the platform window. To keep old code working that may have called winId() on the QDekstopWidget we still ensure it gets created lazily, even if that will just create hidden fake windows on many platforms. Change-Id: I2d05b96dfeebeaf3f1278cfef6301ef4cb855a57 Reviewed-by: Jan Arve Sæther --- src/widgets/kernel/qwidget.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index d35ad87c8d2..dc55c2d5d96 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1477,10 +1477,12 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ? QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive; - win->create(); - // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing. - if ((flags & Qt::Desktop) == Qt::Window) + + if (q->windowType() != Qt::Desktop || q->testAttribute(Qt::WA_NativeWindow)) { + win->create(); + // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing. win->handle()->setFrameStrutEventsEnabled(true); + } data.window_flags = win->flags(); if (!win->isTopLevel()) // In a Widget world foreign windows can only be top level @@ -1501,10 +1503,13 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO } setWindowModified_helper(); - WId id = win->winId(); - // See the QPlatformWindow::winId() documentation - Q_ASSERT(id != WId(0)); - setWinId(id); + + if (win->handle()) { + WId id = win->winId(); + // See the QPlatformWindow::winId() documentation + Q_ASSERT(id != WId(0)); + setWinId(id); + } // Check children and create windows for them if necessary q_createNativeChildrenAndSetParent(q);