1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #include "qwindowsysteminterface_qpa.h"
42 #include "qwindowsysteminterface_qpa_p.h"
43 #include "private/qguiapplication_p.h"
44 #include <QAbstractEventDispatcher>
50 QTime QWindowSystemInterfacePrivate::eventTime;
52 //------------------------------------------------------------
54 // Callback functions for plugins:
57 QList<QWindowSystemInterfacePrivate::WindowSystemEvent *> QWindowSystemInterfacePrivate::windowSystemEventQueue;
58 QMutex QWindowSystemInterfacePrivate::queueMutex;
60 extern QPointer<QWindow> qt_last_mouse_receiver;
63 void QWindowSystemInterface::handleEnterEvent(QWindow *tlw)
66 QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw);
67 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
71 void QWindowSystemInterface::handleLeaveEvent(QWindow *tlw)
73 QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(tlw);
74 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
77 void QWindowSystemInterface::handleWindowActivated(QWindow *tlw)
79 QWindowSystemInterfacePrivate::ActivatedWindowEvent *e = new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw);
80 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
83 void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowState newState)
85 QWindowSystemInterfacePrivate::WindowStateChangedEvent *e =
86 new QWindowSystemInterfacePrivate::WindowStateChangedEvent(tlw, newState);
87 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
90 void QWindowSystemInterface::handleGeometryChange(QWindow *tlw, const QRect &newRect)
92 QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw,newRect);
93 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
96 void QWindowSystemInterface::handleSynchronousGeometryChange(QWindow *tlw, const QRect &newRect)
98 QWindowSystemInterfacePrivate::GeometryChangeEvent *e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(tlw,newRect);
99 QGuiApplicationPrivate::processWindowSystemEvent(e); // send event immediately.
102 void QWindowSystemInterface::handleCloseEvent(QWindow *tlw)
105 QWindowSystemInterfacePrivate::CloseEvent *e =
106 new QWindowSystemInterfacePrivate::CloseEvent(tlw);
107 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
113 \a tlw == 0 means that \a ev is in global coords only
117 void QWindowSystemInterface::handleMouseEvent(QWindow *w, const QPointF & local, const QPointF & global, Qt::MouseButtons b) {
118 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
119 handleMouseEvent(w, time, local, global, b);
122 void QWindowSystemInterface::handleMouseEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, Qt::MouseButtons b)
124 QWindowSystemInterfacePrivate::MouseEvent * e =
125 new QWindowSystemInterfacePrivate::MouseEvent(tlw, timestamp, local, global, b);
126 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
129 void QWindowSystemInterface::handleKeyEvent(QWindow *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) {
130 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
131 handleKeyEvent(w, time, t, k, mods, text, autorep, count);
134 void QWindowSystemInterface::handleKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count)
136 QWindowSystemInterfacePrivate::KeyEvent * e =
137 new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, t, k, mods, text, autorep, count);
138 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
141 void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *w, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
142 quint32 nativeScanCode, quint32 nativeVirtualKey,
143 quint32 nativeModifiers,
144 const QString& text, bool autorep,
147 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
148 handleExtendedKeyEvent(w, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
149 text, autorep, count);
152 void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, int key,
153 Qt::KeyboardModifiers modifiers,
154 quint32 nativeScanCode, quint32 nativeVirtualKey,
155 quint32 nativeModifiers,
156 const QString& text, bool autorep,
159 QWindowSystemInterfacePrivate::KeyEvent * e =
160 new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, type, key, modifiers,
161 nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
162 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
165 void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o) {
166 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
167 handleWheelEvent(w, time, local, global, d, o);
170 void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o)
172 QWindowSystemInterfacePrivate::WheelEvent *e =
173 new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, d, o);
174 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
177 int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
180 int ret = windowSystemEventQueue.count();
185 QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
188 QWindowSystemInterfacePrivate::WindowSystemEvent *ret;
189 if (windowSystemEventQueue.isEmpty())
192 ret = windowSystemEventQueue.takeFirst();
197 void QWindowSystemInterfacePrivate::queueWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *ev)
200 windowSystemEventQueue.append(ev);
203 QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher();
205 dispatcher->wakeUp();
208 void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points) {
209 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
210 handleTouchEvent(w, time, type, devType, points);
213 void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points)
215 if (!points.size()) // Touch events must have at least one point
218 QList<QTouchEvent::TouchPoint> touchPoints;
219 Qt::TouchPointStates states;
220 QTouchEvent::TouchPoint p;
222 QList<struct TouchPoint>::const_iterator point = points.constBegin();
223 QList<struct TouchPoint>::const_iterator end = points.constEnd();
224 while (point != end) {
226 p.setPressure(point->pressure);
227 states |= point->state;
228 Qt::TouchPointStates state = point->state;
229 if (point->isPrimary) {
230 state |= Qt::TouchPointPrimary;
233 p.setRect(point->area);
234 p.setScreenPos(point->area.center());
235 p.setNormalizedPos(point->normalPosition);
237 touchPoints.append(p);
241 QWindowSystemInterfacePrivate::TouchEvent *e =
242 new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, devType, touchPoints);
243 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
246 void QWindowSystemInterface::handleScreenGeometryChange(int screenIndex)
248 QWindowSystemInterfacePrivate::ScreenGeometryEvent *e =
249 new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screenIndex);
250 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
253 void QWindowSystemInterface::handleScreenAvailableGeometryChange(int screenIndex)
255 QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e =
256 new QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent(screenIndex);
257 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
260 void QWindowSystemInterface::handleScreenCountChange(int count)
262 QWindowSystemInterfacePrivate::ScreenCountEvent *e =
263 new QWindowSystemInterfacePrivate::ScreenCountEvent(count);
264 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
267 void QWindowSystemInterface::handleMapEvent(QWindow *tlw)
269 QWindowSystemInterfacePrivate::MapEvent *e = new QWindowSystemInterfacePrivate::MapEvent(tlw);
270 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
273 void QWindowSystemInterface::handleUnmapEvent(QWindow *tlw)
275 QWindowSystemInterfacePrivate::UnmapEvent *e = new QWindowSystemInterfacePrivate::UnmapEvent(tlw);
276 QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
279 void QWindowSystemInterface::handleSynchronousExposeEvent(QWindow *tlw, const QRegion ®ion)
281 QWindowSystemInterfacePrivate::ExposeEvent *e = new QWindowSystemInterfacePrivate::ExposeEvent(tlw, region);
282 QGuiApplicationPrivate::processWindowSystemEvent(e); // send event immediately.
285 bool QWindowSystemInterface::sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags)
289 // handle gui and posted events
290 QCoreApplication::sendPostedEvents();
293 QWindowSystemInterfacePrivate::WindowSystemEvent *event;
294 if (!(flags & QEventLoop::ExcludeUserInputEvents)
295 && QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) {
296 // process a pending user input event
297 event = QWindowSystemInterfacePrivate::getWindowSystemEvent();
304 if (eventDispatcher->filterEvent(event)) {
311 QGuiApplicationPrivate::processWindowSystemEvent(event);
315 return (nevents > 0);
318 int QWindowSystemInterface::windowSystemEventsQueued()
320 return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
323 Qt::DropAction QWindowSystemInterface::handleDrag(QWindow *w, QMimeData *dropData, const QPoint &p)
325 return QGuiApplicationPrivate::processDrag(w, dropData, p);
328 Qt::DropAction QWindowSystemInterface::handleDrop(QWindow *w, QMimeData *dropData, const QPoint &p)
330 return QGuiApplicationPrivate::processDrop(w, dropData, p);