Handle QEventLoop::ExcludeUserInputEvents in QWindowSystemInterface.
[profile/ivi/qtbase.git] / src / gui / kernel / qwindowsysteminterface.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include "qwindowsysteminterface.h"
42 #include <qpa/qplatformwindow.h>
43 #include "qwindowsysteminterface_p.h"
44 #include "private/qguiapplication_p.h"
45 #include "private/qevent_p.h"
46 #include "private/qtouchdevice_p.h"
47 #include <QAbstractEventDispatcher>
48 #include <qpa/qplatformdrag.h>
49 #include <qdebug.h>
50
51 QT_BEGIN_NAMESPACE
52
53
54 QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
55 bool QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = false;
56
57 //------------------------------------------------------------
58 //
59 // Callback functions for plugins:
60 //
61
62 QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue;
63
64 extern QPointer<QWindow> qt_last_mouse_receiver;
65
66 /*!
67     \class QWindowSystemInterface
68     \since 5.0
69     \internal
70     \preliminary
71     \ingroup qpa
72     \brief The QWindowSystemInterface provides an event queue for the QPA platform.
73
74     The platform plugins call the various functions to notify about events. The events are queued
75     until sendWindowSystemEvents() is called by the event dispatcher.
76 */
77
78 void QWindowSystemInterface::handleEnterEvent(QWindow *tlw, const QPointF &local, const QPointF &global)
79 {
80     if (tlw) {
81         QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global);
82         QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
83     }
84 }
85
86 void QWindowSystemInterface::handleLeaveEvent(QWindow *tlw)
87 {
88     QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(tlw);
89     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
90 }
91
92 /*!
93     This method can be used to ensure leave and enter events are both in queue when moving from
94     one QWindow to another. This allows QWindow subclasses to check for a queued enter event
95     when handling the leave event (\c QWindowSystemInterfacePrivate::peekWindowSystemEvent) to
96     determine where mouse went and act accordingly. E.g. QWidgetWindow needs to know if mouse
97     cursor moves between windows in same window hierarchy.
98 */
99 void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local, const QPointF& global)
100 {
101     bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents;
102     if (wasSynchronous)
103         setSynchronousWindowsSystemEvents(false);
104     handleLeaveEvent(leave);
105     handleEnterEvent(enter, local, global);
106     if (wasSynchronous) {
107         flushWindowSystemEvents();
108         setSynchronousWindowsSystemEvents(true);
109     }
110 }
111
112 void QWindowSystemInterface::handleWindowActivated(QWindow *tlw)
113 {
114     QWindowSystemInterfacePrivate::ActivatedWindowEvent *e = new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw);
115     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
116 }
117
118 void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowState newState)
119 {
120     QWindowSystemInterfacePrivate::WindowStateChangedEvent *e =
121         new QWindowSystemInterfacePrivate::WindowStateChangedEvent(tlw, newState);
122     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
123 }
124
125 void QWindowSystemInterface::handleGeometryChange(QWindow *tlw, const QRect &newRect)
126 {
127     QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw,newRect);
128     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
129 }
130
131 void QWindowSystemInterface::handleCloseEvent(QWindow *tlw)
132 {
133     if (tlw) {
134         QWindowSystemInterfacePrivate::CloseEvent *e =
135                 new QWindowSystemInterfacePrivate::CloseEvent(tlw);
136         QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
137     }
138 }
139
140 /*!
141
142 \a w == 0 means that the event is in global coords only, \a local will be ignored in this case
143
144 */
145 void QWindowSystemInterface::handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
146 {
147     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
148     handleMouseEvent(w, time, local, global, b, mods);
149 }
150
151 void QWindowSystemInterface::handleMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
152 {
153     QWindowSystemInterfacePrivate::MouseEvent * e =
154             new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp, local, global, b, mods);
155     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
156 }
157
158 void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
159 {
160     const unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
161     handleFrameStrutMouseEvent(w, time, local, global, b, mods);
162 }
163
164 void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
165 {
166     QWindowSystemInterfacePrivate::MouseEvent * e =
167             new QWindowSystemInterfacePrivate::MouseEvent(w, timestamp,
168                                                           QWindowSystemInterfacePrivate::FrameStrutMouse,
169                                                           local, global, b, mods);
170     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
171 }
172
173 bool QWindowSystemInterface::tryHandleShortcutEvent(QWindow *w, int k, Qt::KeyboardModifiers mods,
174                                                                const QString & text, bool autorep, ushort count)
175 {
176     unsigned long timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
177     return tryHandleShortcutEvent(w, timestamp, k, mods, text, autorep, count);
178 }
179
180 bool QWindowSystemInterface::tryHandleShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods,
181                                                                const QString & text, bool autorep, ushort count)
182 {
183 #ifndef QT_NO_SHORTCUT
184     QGuiApplicationPrivate::modifier_buttons = mods;
185
186     QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count);
187     qevent.setTimestamp(timestamp);
188     return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent);
189 #else
190     Q_UNUSED(w)
191     Q_UNUSED(timestamp)
192     Q_UNUSED(k)
193     Q_UNUSED(mods)
194     Q_UNUSED(text)
195     Q_UNUSED(autorep)
196     Q_UNUSED(count)
197     return false;
198 #endif
199 }
200
201 bool QWindowSystemInterface::tryHandleExtendedShortcutEvent(QWindow *w, int k, Qt::KeyboardModifiers mods,
202                                                                        quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
203                                                                        const QString &text, bool autorep, ushort count)
204 {
205     unsigned long timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
206     return tryHandleExtendedShortcutEvent(w, timestamp, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
207 }
208
209 bool QWindowSystemInterface::tryHandleExtendedShortcutEvent(QWindow *w, ulong timestamp, int k, Qt::KeyboardModifiers mods,
210                                                                        quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
211                                                                        const QString &text, bool autorep, ushort count)
212 {
213 #ifndef QT_NO_SHORTCUT
214     QGuiApplicationPrivate::modifier_buttons = mods;
215
216     QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
217     qevent.setTimestamp(timestamp);
218     return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent);
219 #else
220     Q_UNUSED(w)
221     Q_UNUSED(timestamp)
222     Q_UNUSED(k)
223     Q_UNUSED(mods)
224     Q_UNUSED(nativeScanCode)
225     Q_UNUSED(nativeVirtualKey)
226     Q_UNUSED(nativeModifiers)
227     Q_UNUSED(text)
228     Q_UNUSED(autorep)
229     Q_UNUSED(count)
230     return false;
231 #endif
232 }
233
234
235 void QWindowSystemInterface::handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) {
236     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
237     handleKeyEvent(w, time, t, k, mods, text, autorep, count);
238 }
239
240 void QWindowSystemInterface::handleKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count)
241 {
242     QWindowSystemInterfacePrivate::KeyEvent * e =
243             new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, t, k, mods, text, autorep, count);
244     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
245 }
246
247 void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
248                                                     quint32 nativeScanCode, quint32 nativeVirtualKey,
249                                                     quint32 nativeModifiers,
250                                                     const QString& text, bool autorep,
251                                                     ushort count)
252 {
253     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
254     handleExtendedKeyEvent(w, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
255                            text, autorep, count);
256 }
257
258 void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, int key,
259                                                     Qt::KeyboardModifiers modifiers,
260                                                     quint32 nativeScanCode, quint32 nativeVirtualKey,
261                                                     quint32 nativeModifiers,
262                                                     const QString& text, bool autorep,
263                                                     ushort count)
264 {
265     QWindowSystemInterfacePrivate::KeyEvent * e =
266             new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, type, key, modifiers,
267                 nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
268     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
269 }
270
271 void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) {
272     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
273     handleWheelEvent(w, time, local, global, d, o, mods);
274 }
275
276 void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods)
277 {
278     QPoint point = (o == Qt::Vertical) ? QPoint(0, d) : QPoint(d, 0);
279     handleWheelEvent(tlw, timestamp, local, global, QPoint(), point, mods);
280 }
281
282 void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods)
283 {
284     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
285     handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods);
286 }
287
288 void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods)
289 {
290     // Qt 4 sends two separate wheel events for horizontal and vertical
291     // deltas. For Qt 5 we want to send the deltas in one event, but at the
292     // same time preserve source and behavior compatibility with Qt 4.
293     //
294     // In addition high-resolution pixel-based deltas are also supported.
295     // Platforms that does not support these may pass a null point here.
296     // Angle deltas must always be sent in addition to pixel deltas.
297     QWindowSystemInterfacePrivate::WheelEvent *e;
298
299     if (angleDelta.isNull())
300         return;
301
302     // Simple case: vertical deltas only:
303     if (angleDelta.y() != 0 && angleDelta.x() == 0) {
304         e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods);
305         QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
306         return;
307     }
308
309     // Simple case: horizontal deltas only:
310     if (angleDelta.y() == 0 && angleDelta.x() != 0) {
311         e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods);
312         QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
313         return;
314     }
315
316     // Both horizontal and vertical deltas: Send two wheel events.
317     // The first event contains the Qt 5 pixel and angle delta as points,
318     // and in addition the Qt 4 compatibility vertical angle delta.
319     e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods);
320     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
321
322     // The second event contains null pixel and angle points and the
323     // Qt 4 compatibility horizontal angle delta.
324     e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods);
325     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
326 }
327
328
329 QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *exposed, const QRegion &region)
330     : WindowSystemEvent(Expose)
331     , exposed(exposed)
332     , isExposed(exposed && exposed->handle() ? exposed->handle()->isExposed() : false)
333     , region(region)
334 {
335 }
336
337 int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
338 {
339     return windowSystemEventQueue.count();
340 }
341
342 QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
343 {
344     return windowSystemEventQueue.takeFirstOrReturnNull();
345 }
346
347 QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
348 {
349     return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
350 }
351
352 QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
353 {
354     return windowSystemEventQueue.peekAtFirstOfType(t);
355 }
356
357 void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
358 {
359     windowSystemEventQueue.remove(event);
360 }
361
362 void QWindowSystemInterfacePrivate::handleWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *ev)
363 {
364     if (synchronousWindowsSystemEvents) {
365         QGuiApplicationPrivate::processWindowSystemEvent(ev);
366     } else {
367         windowSystemEventQueue.append(ev);
368         QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher();
369         if (dispatcher)
370             dispatcher->wakeUp();
371     }
372 }
373
374 void QWindowSystemInterface::registerTouchDevice(QTouchDevice *device)
375 {
376     QTouchDevicePrivate::registerDevice(device);
377 }
378
379 void QWindowSystemInterface::handleTouchEvent(QWindow *w, QTouchDevice *device,
380                                               const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
381 {
382     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
383     handleTouchEvent(w, time, device, points, mods);
384 }
385
386 QList<QTouchEvent::TouchPoint> QWindowSystemInterfacePrivate::convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type)
387 {
388     QList<QTouchEvent::TouchPoint> touchPoints;
389     Qt::TouchPointStates states;
390     QTouchEvent::TouchPoint p;
391
392     QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
393     QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
394     while (point != end) {
395         p.setId(point->id);
396         p.setPressure(point->pressure);
397         states |= point->state;
398         p.setState(point->state);
399
400         const QPointF screenPos = point->area.center();
401         p.setScreenPos(screenPos);
402         p.setScreenRect(point->area);
403
404         // The local pos and rect are not set, they will be calculated
405         // when the event gets processed by QGuiApplication.
406
407         p.setNormalizedPos(point->normalPosition);
408         p.setVelocity(point->velocity);
409         p.setFlags(point->flags);
410         p.setRawScreenPositions(point->rawPositions);
411
412         touchPoints.append(p);
413         ++point;
414     }
415
416     // Determine the event type based on the combined point states.
417     if (type) {
418         *type = QEvent::TouchUpdate;
419         if (states == Qt::TouchPointPressed)
420             *type = QEvent::TouchBegin;
421         else if (states == Qt::TouchPointReleased)
422             *type = QEvent::TouchEnd;
423     }
424
425     return touchPoints;
426 }
427
428 void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QTouchDevice *device,
429                                               const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
430 {
431     if (!points.size()) // Touch events must have at least one point
432         return;
433
434     if (!QTouchDevicePrivate::isRegistered(device)) // Disallow passing bogus, non-registered devices.
435         return;
436
437     QEvent::Type type;
438     QList<QTouchEvent::TouchPoint> touchPoints = QWindowSystemInterfacePrivate::convertTouchPoints(points, &type);
439
440     QWindowSystemInterfacePrivate::TouchEvent *e =
441             new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, device, touchPoints, mods);
442     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
443 }
444
445 void QWindowSystemInterface::handleTouchCancelEvent(QWindow *w, QTouchDevice *device,
446                                                     Qt::KeyboardModifiers mods)
447 {
448     unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
449     handleTouchCancelEvent(w, time, device, mods);
450 }
451
452 void QWindowSystemInterface::handleTouchCancelEvent(QWindow *w, ulong timestamp, QTouchDevice *device,
453                                                     Qt::KeyboardModifiers mods)
454 {
455     QWindowSystemInterfacePrivate::TouchEvent *e =
456             new QWindowSystemInterfacePrivate::TouchEvent(w, timestamp, QEvent::TouchCancel, device,
457                                                          QList<QTouchEvent::TouchPoint>(), mods);
458     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
459 }
460
461 void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
462 {
463     QWindowSystemInterfacePrivate::ScreenOrientationEvent *e =
464             new QWindowSystemInterfacePrivate::ScreenOrientationEvent(screen, orientation);
465     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
466 }
467
468 void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const QRect &geometry)
469 {
470     QWindowSystemInterfacePrivate::ScreenGeometryEvent *e =
471             new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screen, geometry);
472     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
473 }
474
475 void QWindowSystemInterface::handleScreenAvailableGeometryChange(QScreen *screen, const QRect &availableGeometry)
476 {
477     QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e =
478             new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screen, availableGeometry);
479     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
480 }
481
482 void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
483 {
484     QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e =
485             new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, dpiX, dpiY);
486     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
487 }
488
489 void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
490 {
491     QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e =
492             new QWindowSystemInterfacePrivate::ScreenRefreshRateEvent(screen, newRefreshRate);
493     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
494 }
495
496 void QWindowSystemInterface::handleThemeChange(QWindow *tlw)
497 {
498     QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(tlw);
499     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
500 }
501
502 void QWindowSystemInterface::handleExposeEvent(QWindow *tlw, const QRegion &region)
503 {
504     QWindowSystemInterfacePrivate::ExposeEvent *e = new QWindowSystemInterfacePrivate::ExposeEvent(tlw, region);
505     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
506 }
507
508 void QWindowSystemInterface::flushWindowSystemEvents()
509 {
510     sendWindowSystemEventsImplementation(QEventLoop::AllEvents);
511 }
512
513 bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
514 {
515     QCoreApplication::sendPostedEvents(); // handle gui and posted events
516     return sendWindowSystemEventsImplementation(flags);
517 }
518
519 void QWindowSystemInterface::setSynchronousWindowsSystemEvents(bool enable)
520 {
521     QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents = enable;
522 }
523
524 bool QWindowSystemInterface::sendWindowSystemEventsImplementation(QEventLoop::ProcessEventsFlags flags)
525 {
526     int nevents = 0;
527
528     while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
529         QWindowSystemInterfacePrivate::WindowSystemEvent *event =
530             (flags & QEventLoop::ExcludeUserInputEvents) ?
531                 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
532                 QWindowSystemInterfacePrivate::getWindowSystemEvent();
533         if (!event)
534             break;
535         nevents++;
536         QGuiApplicationPrivate::processWindowSystemEvent(event);
537         delete event;
538     }
539
540     return (nevents > 0);
541 }
542
543 int QWindowSystemInterface::windowSystemEventsQueued()
544 {
545     return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
546 }
547
548 #ifndef QT_NO_DRAGANDDROP
549 QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
550 {
551     return QGuiApplicationPrivate::processDrag(w, dropData, p,supportedActions);
552 }
553
554 QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions)
555 {
556     return QGuiApplicationPrivate::processDrop(w, dropData, p,supportedActions);
557 }
558 #endif // QT_NO_DRAGANDDROP
559
560 /*!
561     \fn static QWindowSystemInterface::handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result)
562     \brief Passes a native event identified by \a eventType to the \a window.
563
564     \note This function can only be called from the GUI thread.
565 */
566
567 bool QWindowSystemInterface::handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result)
568 {
569     return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
570 }
571
572 void QWindowSystemInterface::handleFileOpenEvent(const QString& fileName)
573 {
574     QWindowSystemInterfacePrivate::FileOpenEvent e(fileName);
575     QGuiApplicationPrivate::processWindowSystemEvent(&e);
576 }
577
578 void QWindowSystemInterface::handleTabletEvent(QWindow *w, ulong timestamp, bool down, const QPointF &local, const QPointF &global,
579                                                int device, int pointerType, qreal pressure, int xTilt, int yTilt,
580                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
581                                                Qt::KeyboardModifiers modifiers)
582 {
583     QWindowSystemInterfacePrivate::TabletEvent *e =
584             new QWindowSystemInterfacePrivate::TabletEvent(w, timestamp, down, local, global, device, pointerType, pressure,
585                                                            xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
586     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
587 }
588
589 void QWindowSystemInterface::handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
590                                                int device, int pointerType, qreal pressure, int xTilt, int yTilt,
591                                                qreal tangentialPressure, qreal rotation, int z, qint64 uid,
592                                                Qt::KeyboardModifiers modifiers)
593 {
594     ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
595     handleTabletEvent(w, time, down, local, global, device, pointerType, pressure,
596                       xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
597 }
598
599 void QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid)
600 {
601     QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e =
602             new QWindowSystemInterfacePrivate::TabletEnterProximityEvent(timestamp, device, pointerType, uid);
603     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
604 }
605
606 void QWindowSystemInterface::handleTabletEnterProximityEvent(int device, int pointerType, qint64 uid)
607 {
608     ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
609     handleTabletEnterProximityEvent(time, device, pointerType, uid);
610 }
611
612 void QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid)
613 {
614     QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e =
615             new QWindowSystemInterfacePrivate::TabletLeaveProximityEvent(timestamp, device, pointerType, uid);
616     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
617 }
618
619 void QWindowSystemInterface::handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid)
620 {
621     ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
622     handleTabletLeaveProximityEvent(time, device, pointerType, uid);
623 }
624
625 void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
626 {
627     QWindowSystemInterfacePrivate::PlatformPanelEvent *e =
628             new QWindowSystemInterfacePrivate::PlatformPanelEvent(w);
629     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
630 }
631
632 #ifndef QT_NO_CONTEXTMENU
633 void QWindowSystemInterface::handleContextMenuEvent(QWindow *w, bool mouseTriggered,
634                                                     const QPoint &pos, const QPoint &globalPos,
635                                                     Qt::KeyboardModifiers modifiers)
636 {
637     QWindowSystemInterfacePrivate::ContextMenuEvent *e =
638             new QWindowSystemInterfacePrivate::ContextMenuEvent(w, mouseTriggered, pos,
639                                                                 globalPos, modifiers);
640     QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
641 }
642 #endif
643
644 Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier) {
645     QWindowSystemInterface::handleMouseEvent(w, local, global,  b,  mods);
646 }
647
648 Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
649 {
650     QWindowSystemInterface::handleKeyEvent(w, t, k, mods, text, autorep, count);
651 }
652
653 static QWindowSystemInterface::TouchPoint touchPoint(const QTouchEvent::TouchPoint& pt)
654 {
655     QWindowSystemInterface::TouchPoint p;
656     p.id = pt.id();
657     p.flags = pt.flags();
658     p.normalPosition = pt.normalizedPos();
659     p.area = pt.screenRect();
660     p.pressure = pt.pressure();
661     p.state = pt.state();
662     p.velocity = pt.velocity();
663     p.rawPositions = pt.rawScreenPositions();
664     return p;
665 }
666 static QList<struct QWindowSystemInterface::TouchPoint> touchPointList(const QList<QTouchEvent::TouchPoint>& pointList)
667 {
668     QList<struct QWindowSystemInterface::TouchPoint> newList;
669
670     Q_FOREACH (QTouchEvent::TouchPoint p, pointList)
671     {
672         newList.append(touchPoint(p));
673     }
674     return newList;
675 }
676
677 Q_GUI_EXPORT  void qt_handleTouchEvent(QWindow *w, QTouchDevice *device,
678                                 const QList<QTouchEvent::TouchPoint> &points,
679                                 Qt::KeyboardModifiers mods = Qt::NoModifier)
680 {
681     QWindowSystemInterface::handleTouchEvent(w, device, touchPointList(points), mods);
682 }
683
684 QT_END_NAMESPACE