Handle QEventLoop::ExcludeUserInputEvents in QWindowSystemInterface.
[profile/ivi/qtbase.git] / src / gui / kernel / qwindowsysteminterface_p.h
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 #ifndef QWINDOWSYSTEMINTERFACE_P_H
42 #define QWINDOWSYSTEMINTERFACE_P_H
43
44 //
45 //  W A R N I N G
46 //  -------------
47 //
48 // This file is not part of the Qt API.  It exists purely as an
49 // implementation detail.  This header file may change from version to
50 // version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54
55 #include "qwindowsysteminterface.h"
56
57 #include <QElapsedTimer>
58 #include <QPointer>
59 #include <QMutex>
60 #include <QList>
61
62 QT_BEGIN_HEADER
63
64 QT_BEGIN_NAMESPACE
65
66 class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
67 public:
68     enum EventType {
69         UserInputEvent = 0x100,
70         Close = UserInputEvent | 0x01,
71         GeometryChange = 0x02,
72         Enter = UserInputEvent | 0x03,
73         Leave = UserInputEvent | 0x04,
74         ActivatedWindow = 0x05,
75         WindowStateChanged = 0x06,
76         Mouse = UserInputEvent | 0x07,
77         FrameStrutMouse = UserInputEvent | 0x08,
78         Wheel = UserInputEvent | 0x09,
79         Key = UserInputEvent | 0x0a,
80         Touch = UserInputEvent | 0x0b,
81         ScreenOrientation = 0x0c,
82         ScreenGeometry = 0x0d,
83         ScreenAvailableGeometry = 0x0e,
84         ScreenLogicalDotsPerInch = 0x0f,
85         ScreenRefreshRate = 0x10,
86         ThemeChange = 0x11,
87         Expose = 0x12,
88         FileOpen = UserInputEvent | 0x13,
89         Tablet = UserInputEvent | 0x14,
90         TabletEnterProximity = UserInputEvent | 0x15,
91         TabletLeaveProximity = UserInputEvent | 0x16,
92         PlatformPanel = UserInputEvent | 0x17,
93         ContextMenu = UserInputEvent | 0x18
94     };
95
96     class WindowSystemEvent {
97     public:
98         explicit WindowSystemEvent(EventType t)
99             : type(t), synthetic(false) { }
100         virtual ~WindowSystemEvent() { }
101         EventType type;
102         bool synthetic;
103     };
104
105     class CloseEvent : public WindowSystemEvent {
106     public:
107         explicit CloseEvent(QWindow *w)
108             : WindowSystemEvent(Close), window(w) { }
109         QPointer<QWindow> window;
110     };
111
112     class GeometryChangeEvent : public WindowSystemEvent {
113     public:
114         GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
115             : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
116         { }
117         QPointer<QWindow> tlw;
118         QRect newGeometry;
119     };
120
121     class EnterEvent : public WindowSystemEvent {
122     public:
123         explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
124             : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
125         { }
126         QPointer<QWindow> enter;
127         const QPointF localPos;
128         const QPointF globalPos;
129     };
130
131     class LeaveEvent : public WindowSystemEvent {
132     public:
133         explicit LeaveEvent(QWindow *leave)
134             : WindowSystemEvent(Leave), leave(leave)
135         { }
136         QPointer<QWindow> leave;
137     };
138
139     class ActivatedWindowEvent : public WindowSystemEvent {
140     public:
141         explicit ActivatedWindowEvent(QWindow *activatedWindow)
142             : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
143         { }
144         QPointer<QWindow> activated;
145     };
146
147     class WindowStateChangedEvent : public WindowSystemEvent {
148     public:
149         WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
150             : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
151         { }
152
153         QPointer<QWindow> window;
154         Qt::WindowState newState;
155     };
156
157     class UserEvent : public WindowSystemEvent {
158     public:
159         UserEvent(QWindow * w, ulong time, EventType t)
160             : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
161         QPointer<QWindow> window;
162         bool nullWindow;
163         unsigned long timestamp;
164     };
165
166     class InputEvent: public UserEvent {
167     public:
168         InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods)
169             : UserEvent(w, time, t), modifiers(mods) {}
170         Qt::KeyboardModifiers modifiers;
171     };
172
173     class MouseEvent : public InputEvent {
174     public:
175         MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global,
176                    Qt::MouseButtons b, Qt::KeyboardModifiers mods)
177             : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b) { }
178         MouseEvent(QWindow * w, ulong time, EventType t, const QPointF & local, const QPointF & global,
179                    Qt::MouseButtons b, Qt::KeyboardModifiers mods)
180             : InputEvent(w, time, t, mods), localPos(local), globalPos(global), buttons(b) { }
181         QPointF localPos;
182         QPointF globalPos;
183         Qt::MouseButtons buttons;
184     };
185
186     class WheelEvent : public InputEvent {
187     public:
188         WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
189                    Qt::KeyboardModifiers mods)
190             : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global) { }
191         QPoint pixelDelta;
192         QPoint angleDelta;
193         int qt4Delta;
194         Qt::Orientation qt4Orientation;
195         QPointF localPos;
196         QPointF globalPos;
197     };
198
199     class KeyEvent : public InputEvent {
200     public:
201         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
202             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
203              repeatCount(count), keyType(t),
204              nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
205         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
206                  quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
207                  const QString & text = QString(), bool autorep = false, ushort count = 1)
208             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
209              repeatCount(count), keyType(t),
210              nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
211         int key;
212         QString unicode;
213         bool repeat;
214         ushort repeatCount;
215         QEvent::Type keyType;
216         quint32 nativeScanCode;
217         quint32 nativeVirtualKey;
218         quint32 nativeModifiers;
219     };
220
221     class TouchEvent : public InputEvent {
222     public:
223         TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev,
224                    const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
225             :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { }
226         QTouchDevice *device;
227         QList<QTouchEvent::TouchPoint> points;
228         QEvent::Type touchType;
229     };
230
231     class ScreenOrientationEvent : public WindowSystemEvent {
232     public:
233         ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
234             : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
235         QPointer<QScreen> screen;
236         Qt::ScreenOrientation orientation;
237     };
238
239     class ScreenGeometryEvent : public WindowSystemEvent {
240     public:
241         ScreenGeometryEvent(QScreen *s, const QRect &g)
242             : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
243         QPointer<QScreen> screen;
244         QRect geometry;
245     };
246
247     class ScreenAvailableGeometryEvent : public WindowSystemEvent {
248     public:
249         ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
250             : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
251         QPointer<QScreen> screen;
252         QRect availableGeometry;
253     };
254
255     class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
256     public:
257         ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
258             : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
259         QPointer<QScreen> screen;
260         qreal dpiX;
261         qreal dpiY;
262     };
263
264     class ScreenRefreshRateEvent : public WindowSystemEvent {
265     public:
266         ScreenRefreshRateEvent(QScreen *s, qreal r)
267             : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
268         QPointer<QScreen> screen;
269         qreal rate;
270     };
271
272     class ThemeChangeEvent : public WindowSystemEvent {
273     public:
274         explicit ThemeChangeEvent(QWindow * w)
275             : WindowSystemEvent(ThemeChange), window(w) { }
276         QPointer<QWindow> window;
277     };
278
279     class ExposeEvent : public WindowSystemEvent {
280     public:
281         ExposeEvent(QWindow *exposed, const QRegion &region);
282         QPointer<QWindow> exposed;
283         bool isExposed;
284         QRegion region;
285     };
286
287     class FileOpenEvent : public WindowSystemEvent {
288     public:
289         FileOpenEvent(const QString& fileName)
290             : WindowSystemEvent(FileOpen), fileName(fileName)
291         { }
292         QString fileName;
293     };
294
295     class TabletEvent : public InputEvent {
296     public:
297         static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
298                                       int device, int pointerType, qreal pressure, int xTilt, int yTilt,
299                                       qreal tangentialPressure, qreal rotation, int z, qint64 uid,
300                                       Qt::KeyboardModifiers modifiers = Qt::NoModifier);
301
302         TabletEvent(QWindow *w, ulong time, bool down, const QPointF &local, const QPointF &global,
303                     int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tpressure,
304                     qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods)
305             : InputEvent(w, time, Tablet, Qt::NoModifier),
306               down(down), local(local), global(global), device(device), pointerType(pointerType),
307               pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
308               rotation(rotation), z(z), uid(uid), mods(mods) { }
309         bool down;
310         QPointF local;
311         QPointF global;
312         int device;
313         int pointerType;
314         qreal pressure;
315         int xTilt;
316         int yTilt;
317         qreal tangentialPressure;
318         qreal rotation;
319         int z;
320         qint64 uid;
321         Qt::KeyboardModifiers mods;
322     };
323
324     class TabletEnterProximityEvent : public InputEvent {
325     public:
326         TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid)
327             : InputEvent(0, time, TabletEnterProximity, Qt::NoModifier),
328               device(device), pointerType(pointerType), uid(uid) { }
329         int device;
330         int pointerType;
331         qint64 uid;
332     };
333
334     class TabletLeaveProximityEvent : public InputEvent {
335     public:
336         TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid)
337             : InputEvent(0, time, TabletLeaveProximity, Qt::NoModifier),
338               device(device), pointerType(pointerType), uid(uid) { }
339         int device;
340         int pointerType;
341         qint64 uid;
342     };
343
344     class PlatformPanelEvent : public WindowSystemEvent {
345     public:
346         explicit PlatformPanelEvent(QWindow *w)
347             : WindowSystemEvent(PlatformPanel), window(w) { }
348         QPointer<QWindow> window;
349     };
350
351 #ifndef QT_NO_CONTEXTMENU
352     class ContextMenuEvent : public WindowSystemEvent {
353     public:
354         explicit ContextMenuEvent(QWindow *w, bool mouseTriggered, const QPoint &pos,
355                                   const QPoint &globalPos, Qt::KeyboardModifiers modifiers)
356             : WindowSystemEvent(ContextMenu), window(w), mouseTriggered(mouseTriggered), pos(pos),
357               globalPos(globalPos), modifiers(modifiers) { }
358         QPointer<QWindow> window;
359         bool mouseTriggered;
360         QPoint pos;       // Only valid if triggered by mouse
361         QPoint globalPos; // Only valid if triggered by mouse
362         Qt::KeyboardModifiers modifiers;
363     };
364 #endif
365
366     class WindowSystemEventList {
367         QList<WindowSystemEvent *> impl;
368         mutable QMutex mutex;
369     public:
370         WindowSystemEventList() : impl(), mutex() {}
371         ~WindowSystemEventList()
372         { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
373
374         void prepend(WindowSystemEvent *e)
375         { const QMutexLocker locker(&mutex); impl.prepend(e); }
376         WindowSystemEvent *takeFirstOrReturnNull()
377         { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); }
378         WindowSystemEvent *takeFirstNonUserInputOrReturnNull()
379         {
380             const QMutexLocker locker(&mutex);
381             for (int i = 0; i < impl.size(); ++i)
382                 if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
383                     return impl.takeAt(i);
384             return 0;
385         }
386         void append(WindowSystemEvent *e)
387         { const QMutexLocker locker(&mutex); impl.append(e); }
388         int count() const
389         { const QMutexLocker locker(&mutex); return impl.count(); }
390         WindowSystemEvent *peekAtFirstOfType(EventType t) const
391         {
392             const QMutexLocker locker(&mutex);
393             for (int i = 0; i < impl.size(); ++i) {
394                 if (impl.at(i)->type == t)
395                     return impl.at(i);
396             }
397             return 0;
398         }
399         void remove(const WindowSystemEvent *e)
400         {
401             const QMutexLocker locker(&mutex);
402             for (int i = 0; i < impl.size(); ++i) {
403                 if (impl.at(i) == e) {
404                     impl.removeAt(i);
405                     break;
406                 }
407             }
408         }
409     private:
410         Q_DISABLE_COPY(WindowSystemEventList);
411     };
412
413     static WindowSystemEventList windowSystemEventQueue;
414
415     static int windowSystemEventsQueued();
416     static WindowSystemEvent *getWindowSystemEvent();
417     static WindowSystemEvent *getNonUserInputWindowSystemEvent();
418     static WindowSystemEvent *peekWindowSystemEvent(EventType t);
419     static void removeWindowSystemEvent(WindowSystemEvent *event);
420     static void handleWindowSystemEvent(WindowSystemEvent *ev);
421
422     static QElapsedTimer eventTime;
423     static bool synchronousWindowsSystemEvents;
424
425     static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);
426 };
427
428 QT_END_HEADER
429 QT_END_NAMESPACE
430
431 #endif // QWINDOWSYSTEMINTERFACE_P_H