diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index cae9760..a597f4e 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -53,6 +53,35 @@ QMutex QWindowSystemInterfacePrivate::flushEventMutex;
 QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
 QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
 
+QDebug operator<<(QDebug d, const QWindowSystemInterfacePrivate::WindowSystemEvent *e)
+{
+    QDebugStateSaver saver(d);
+    d.nospace();
+    d << "WindowSystemEvent(";
+    if (e) {
+        d << e->type;
+        if (e->nullWindow())
+            d << ", nullWindow";
+        if (e->synthetic())
+            d << ", synthetic";
+        if (const QWindowSystemInterfacePrivate::UserEvent *ue = dynamic_cast<const QWindowSystemInterfacePrivate::UserEvent *>(e)) {
+            d << ", " << ue->window.data();
+            if (const QWindowSystemInterfacePrivate::MouseEvent *me = dynamic_cast<const QWindowSystemInterfacePrivate::MouseEvent *>(ue))
+                d << ", " << me->buttons << ", " << me->source;
+        } else if (const QWindowSystemInterfacePrivate::GeometryChangeEvent *ge = dynamic_cast<const QWindowSystemInterfacePrivate::GeometryChangeEvent *>(e)) {
+            d << ", " << ge->tlw.data() << ", " << ge->newGeometry;
+        } else if (const QWindowSystemInterfacePrivate::EnterEvent *ee = dynamic_cast<const QWindowSystemInterfacePrivate::EnterEvent *>(e)) {
+            d << ", " << ee->enter.data();
+        } else if (const QWindowSystemInterfacePrivate::LeaveEvent *le = dynamic_cast<const QWindowSystemInterfacePrivate::LeaveEvent *>(e)) {
+            d << ", " << le->leave.data();
+        }
+    } else {
+        d << '0';
+    }
+    d << ')';
+    return d;
+}
+
 //------------------------------------------------------------
 //
 // Callback functions for plugins:
@@ -631,12 +660,14 @@ bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFl
 bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
 {
     int nevents = 0;
+    qDebug() << __FUNCTION__ << '>' << flags;
 
     while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
         QWindowSystemInterfacePrivate::WindowSystemEvent *event =
             (flags & QEventLoop::ExcludeUserInputEvents) ?
                 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
                 QWindowSystemInterfacePrivate::getWindowSystemEvent();
+        qDebug() << __FUNCTION__ << event;
         if (!event)
             break;
 
@@ -657,6 +688,8 @@ bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFla
         delete event;
     }
 
+    qDebug() << __FUNCTION__ << '<' << nevents;
+
     return (nevents > 0);
 }
 
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index b3c6d0d..85b64b9 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -58,6 +58,7 @@ QT_BEGIN_NAMESPACE
 class QWindowSystemEventHandler;
 
 class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
+    Q_GADGET
 public:
     enum EventType {
         UserInputEvent = 0x100,
@@ -93,10 +94,11 @@ public:
         FlushEvents = 0x20,
         WindowScreenChanged = 0x21
     };
+    Q_ENUM(EventType)
 
     class WindowSystemEvent {
     public:
-        enum {
+        enum Flags {
             Synthetic = 0x1,
             NullWindow = 0x2
         };
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 9c6cb53..cea2881 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -1579,8 +1579,11 @@ bool QWindowsWindow::handleWmPaint(HWND hwnd, UINT message,
     // we still need to send isExposed=true, for compatibility.
     // Our tests depend on it.
     fireExpose(QRegion(qrectFromRECT(ps.rcPaint)), true);
-    if (!QWindowsContext::instance()->asyncExpose())
-        QWindowSystemInterface::flushWindowSystemEvents();
+    if (!QWindowsContext::instance()->asyncExpose()) {
+        qDebug("handleWmPaint: flush>");
+        QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
+        qDebug("handleWmPaint: flush<");
+    }
 
     EndPaint(hwnd, &ps);
     return true;
