From 81e981a704116ca7b1b619a2c1e8db837046d2cf Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@digia.com>
Date: Tue, 28 May 2013 10:17:32 +0200
Subject: [PATCH] Fix QPlatformWindow::initialGeometry() to not touch large
 windows.

Do not touch windows whose geometry (including the  unknown frame
size) is likely to be larger than the screen.

Remove fix-up in the Windows plugin.

Task-number: QTBUG-30142
Task-number: QTBUG-31071
Change-Id: I13a8ffb9fb9d8c71d35de75094275388fa427f2c
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
---
 src/gui/kernel/qplatformwindow.cpp            | 24 ++++++++++++-------
 .../platforms/windows/qwindowswindow.cpp      |  9 -------
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index d23cfde1723..4c0d68e7c15 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -510,15 +510,21 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w,
         }
     }
     if (w->isTopLevel() && qt_window_private(const_cast<QWindow*>(w))->positionAutomatic) {
-        const QWindow *tp = w->transientParent();
-        if (tp) {
-            // A transient window should be centered w.r.t. its transient parent.
-            rect.moveCenter(tp->geometry().center());
-        } else {
-            // Center the window on the screen.  (Only applicable on platforms
-            // which do not provide a better way.)
-            QPlatformScreen *scr = QPlatformScreen::platformScreenForWindow(w);
-            rect.moveCenter(scr->availableGeometry().center());
+        if (const QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(w)) {
+            const QRect availableGeometry = platformScreen->availableGeometry();
+            // Center unless the geometry ( + unknown window frame) is too large for the screen).
+            if (rect.height() < (availableGeometry.height() * 8) / 9
+                && rect.width() < (availableGeometry.width() * 8) / 9) {
+                const QWindow *tp = w->transientParent();
+                if (tp) {
+                    // A transient window should be centered w.r.t. its transient parent.
+                    rect.moveCenter(tp->geometry().center());
+                } else {
+                    // Center the window on the screen.  (Only applicable on platforms
+                    // which do not provide a better way.)
+                    rect.moveCenter(availableGeometry.center());
+                }
+            }
         }
     }
     return rect;
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 8ce6dcc9e77..9d817c2043b 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -503,15 +503,6 @@ QWindowsWindow::WindowData
     const QWindowCreationContextPtr context(new QWindowCreationContext(w, rect, data.customMargins, style, exStyle));
     QWindowsContext::instance()->setWindowCreationContext(context);
 
-    QRect screenGeometry;
-    if (QScreen *screen = w->screen())
-        screenGeometry = screen->availableVirtualGeometry();
-
-    if (context->frameX < screenGeometry.left())
-        context->frameX = screenGeometry.left();
-    if (context->frameY < screenGeometry.top())
-        context->frameY = screenGeometry.top();
-
     if (QWindowsContext::verboseWindows)
         qDebug().nospace()
                 << "CreateWindowEx: " << w << *this
-- 
GitLab