Fix QSplashScreen on X11.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 16 Jul 2012 10:22:04 +0000 (12:22 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 16 Jul 2012 12:22:55 +0000 (14:22 +0200)
Use code from QTestLib to wait for the Window to show up.

Change-Id: Ib674f3eb7a6c32cad1d502caefe7d4b073754e73
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
src/widgets/widgets/qsplashscreen.cpp

index f3a19c8..b640c78 100644 (file)
 #include "qpixmap.h"
 #include "qtextdocument.h"
 #include "qtextcursor.h"
+#include <QtGui/qwindow.h>
 #include <QtCore/qdebug.h>
+#include <QtCore/qelapsedtimer.h>
 #include <private/qwidget_p.h>
 
+#ifdef Q_OS_WIN
+#  include <QtCore/qt_windows.h>
+#else
+#  include <time.h>
+#endif
+
 QT_BEGIN_NAMESPACE
 
 class QSplashScreenPrivate : public QWidgetPrivate
@@ -217,18 +225,37 @@ void QSplashScreen::clearMessage()
     repaint();
 }
 
+// A copy of QTestLib's qWaitForWindowExposed() and qSleep().
+inline static bool waitForWindowExposed(QWindow *window, int timeout = 1000)
+{
+    enum { TimeOutMs = 10 };
+    QElapsedTimer timer;
+    timer.start();
+    while (!window->isExposed()) {
+        const int remaining = timeout - int(timer.elapsed());
+        if (remaining <= 0)
+            break;
+        QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
+        QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+#ifdef Q_OS_WIN
+        Sleep(uint(TimeOutMs));
+#else
+        struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 };
+        nanosleep(&ts, NULL);
+#endif
+    }
+    return window->isExposed();
+}
+
 /*!
     Makes the splash screen wait until the widget \a mainWin is displayed
     before calling close() on itself.
 */
+
 void QSplashScreen::finish(QWidget *mainWin)
 {
-    if (mainWin) {
-#if defined(Q_WS_X11)
-        extern void qt_x11_wait_for_window_manager(QWidget *mainWin, bool);
-        qt_x11_wait_for_window_manager(mainWin, false);
-#endif
-    }
+    if (mainWin && mainWin->windowHandle())
+        waitForWindowExposed(mainWin->windowHandle());
     close();
 }