QPlatformWindow::initialGeometry(): Do not touch child window positions

Child window positions should not be mapped back and forth by High DPI
scaling as this can cause them to change screens or be moved to invalid
locations.

Introduce a separate branch for child windows applying only size
constraints.

Task-number: QTBUG-54420
Change-Id: I4f86666952a49ed6fa03234a04031bc406281c45
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Friedemann Kleint 2016-06-29 12:50:01 +02:00
parent 726c8ca0de
commit 65cdffeaea

View File

@ -572,6 +572,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
@ -584,19 +598,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).