diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qevent.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 31 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 9 |
3 files changed, 31 insertions, 13 deletions
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index fb72c561ab..93374b2299 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -537,8 +537,8 @@ public: }; class Attribute { public: - Attribute(AttributeType t, int s, int l, QVariant val) : type(t), start(s), length(l), value(qMove(val)) {} - Attribute(AttributeType t, int s, int l) : type(t), start(s), length(l), value() {} + Attribute(AttributeType typ, int s, int l, QVariant val) : type(typ), start(s), length(l), value(qMove(val)) {} + Attribute(AttributeType typ, int s, int l) : type(typ), start(s), length(l), value() {} AttributeType type; int start; diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index e45a1d61ba..bcd3e830dd 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -581,6 +581,20 @@ void QPlatformWindow::invalidateSurface() { } +static QSize fixInitialSize(QSize size, const QWindow *w, + int defaultWidth, int defaultHeight) +{ + if (size.width() == 0) { + const int minWidth = w->minimumWidth(); + size.setWidth(minWidth > 0 ? minWidth : defaultWidth); + } + if (size.height() == 0) { + const int minHeight = w->minimumHeight(); + size.setHeight(minHeight > 0 ? minHeight : defaultHeight); + } + return size; +} + /*! Helper function to get initial geometry on windowing systems which do not do smart positioning and also do not provide a means of centering a @@ -593,19 +607,18 @@ void QPlatformWindow::invalidateSurface() QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeometry, int defaultWidth, int defaultHeight) { + if (!w->isTopLevel()) { + const qreal factor = QHighDpiScaling::factor(w); + const QSize size = fixInitialSize(QHighDpi::fromNative(initialGeometry.size(), factor), + w, defaultWidth, defaultHeight); + return QRect(initialGeometry.topLeft(), QHighDpi::toNative(size, factor)); + } const QScreen *screen = effectiveScreen(w); if (!screen) return initialGeometry; QRect rect(QHighDpi::fromNativePixels(initialGeometry, w)); - if (rect.width() == 0) { - const int minWidth = w->minimumWidth(); - rect.setWidth(minWidth > 0 ? minWidth : defaultWidth); - } - if (rect.height() == 0) { - const int minHeight = w->minimumHeight(); - rect.setHeight(minHeight > 0 ? minHeight : defaultHeight); - } - if (w->isTopLevel() && qt_window_private(const_cast<QWindow*>(w))->positionAutomatic + rect.setSize(fixInitialSize(rect.size(), w, defaultWidth, defaultHeight)); + if (qt_window_private(const_cast<QWindow*>(w))->positionAutomatic && w->type() != Qt::Popup) { const QRect availableGeometry = screen->availableGeometry(); // Center unless the geometry ( + unknown window frame) is too large for the screen). diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index fa26fd77a3..f061a2bf50 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -402,7 +402,7 @@ void QWindowPrivate::create(bool recursive) q->parent()->create(); platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q); - Q_ASSERT(platformWindow); + Q_ASSERT(platformWindow || q->type() == Qt::ForeignWindow); if (!platformWindow) { qWarning() << "Failed to create platform window for" << q << "with flags" << q->flags(); @@ -2432,7 +2432,8 @@ QWindow *QWindowPrivate::topLevelWindow() const This can be used, on platforms which support it, to embed a QWindow inside a native window, or to embed a native window inside a QWindow. - If foreign windows are not supported, this function returns 0. + If foreign windows are not supported or embedding the native window + failed in the platform plugin, this function returns 0. \note The resulting QWindow should not be used to manipulate the underlying native window (besides re-parenting), or to observe state changes of the @@ -2453,6 +2454,10 @@ QWindow *QWindow::fromWinId(WId id) window->setFlags(Qt::ForeignWindow); window->setProperty("_q_foreignWinId", QVariant::fromValue(id)); window->create(); + if (!window->handle()) { + delete window; + return nullptr; + } return window; } |