1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #ifndef QWINDOWSYSTEMINTERFACE_P_H
42 #define QWINDOWSYSTEMINTERFACE_P_H
44 #include "qwindowsysteminterface.h"
46 #include <QElapsedTimer>
55 class QWindowSystemInterfacePrivate {
71 ScreenAvailableGeometry,
72 ScreenLogicalDotsPerInch,
82 class WindowSystemEvent {
84 explicit WindowSystemEvent(EventType t)
85 : type(t), synthetic(false) { }
86 virtual ~WindowSystemEvent() { }
91 class CloseEvent : public WindowSystemEvent {
93 explicit CloseEvent(QWindow *w)
94 : WindowSystemEvent(Close), window(w) { }
95 QPointer<QWindow> window;
98 class GeometryChangeEvent : public WindowSystemEvent {
100 GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
101 : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
103 QPointer<QWindow> tlw;
107 class EnterEvent : public WindowSystemEvent {
109 explicit EnterEvent(QWindow *enter)
110 : WindowSystemEvent(Enter), enter(enter)
112 QPointer<QWindow> enter;
115 class LeaveEvent : public WindowSystemEvent {
117 explicit LeaveEvent(QWindow *leave)
118 : WindowSystemEvent(Leave), leave(leave)
120 QPointer<QWindow> leave;
123 class ActivatedWindowEvent : public WindowSystemEvent {
125 explicit ActivatedWindowEvent(QWindow *activatedWindow)
126 : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
128 QPointer<QWindow> activated;
131 class WindowStateChangedEvent : public WindowSystemEvent {
133 WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
134 : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
137 QPointer<QWindow> window;
138 Qt::WindowState newState;
141 class UserEvent : public WindowSystemEvent {
143 UserEvent(QWindow * w, ulong time, EventType t)
144 : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
145 QPointer<QWindow> window;
147 unsigned long timestamp;
150 class InputEvent: public UserEvent {
152 InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods)
153 : UserEvent(w, time, t), modifiers(mods) {}
154 Qt::KeyboardModifiers modifiers;
157 class MouseEvent : public InputEvent {
159 MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global,
160 Qt::MouseButtons b, Qt::KeyboardModifiers mods)
161 : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b) { }
162 MouseEvent(QWindow * w, ulong time, EventType t, const QPointF & local, const QPointF & global,
163 Qt::MouseButtons b, Qt::KeyboardModifiers mods)
164 : InputEvent(w, time, t, mods), localPos(local), globalPos(global), buttons(b) { }
167 Qt::MouseButtons buttons;
170 class WheelEvent : public InputEvent {
172 WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
173 Qt::KeyboardModifiers mods)
174 : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global) { }
178 Qt::Orientation qt4Orientation;
183 class KeyEvent : public InputEvent {
185 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
186 :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
187 repeatCount(count), keyType(t),
188 nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
189 KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
190 quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
191 const QString & text = QString(), bool autorep = false, ushort count = 1)
192 :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
193 repeatCount(count), keyType(t),
194 nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
199 QEvent::Type keyType;
200 quint32 nativeScanCode;
201 quint32 nativeVirtualKey;
202 quint32 nativeModifiers;
205 class TouchEvent : public InputEvent {
207 TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev,
208 const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
209 :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { }
210 QTouchDevice *device;
211 QList<QTouchEvent::TouchPoint> points;
212 QEvent::Type touchType;
215 class ScreenOrientationEvent : public WindowSystemEvent {
217 ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
218 : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
219 QPointer<QScreen> screen;
220 Qt::ScreenOrientation orientation;
223 class ScreenGeometryEvent : public WindowSystemEvent {
225 ScreenGeometryEvent(QScreen *s, const QRect &g)
226 : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
227 QPointer<QScreen> screen;
231 class ScreenAvailableGeometryEvent : public WindowSystemEvent {
233 ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
234 : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
235 QPointer<QScreen> screen;
236 QRect availableGeometry;
239 class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
241 ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
242 : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
243 QPointer<QScreen> screen;
248 class ScreenRefreshRateEvent : public WindowSystemEvent {
250 ScreenRefreshRateEvent(QScreen *s, qreal r)
251 : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
252 QPointer<QScreen> screen;
256 class ThemeChangeEvent : public WindowSystemEvent {
258 explicit ThemeChangeEvent(QWindow * w)
259 : WindowSystemEvent(ThemeChange), window(w) { }
260 QPointer<QWindow> window;
263 class ExposeEvent : public WindowSystemEvent {
265 ExposeEvent(QWindow *exposed, const QRegion ®ion);
266 QPointer<QWindow> exposed;
271 class FileOpenEvent : public WindowSystemEvent {
273 FileOpenEvent(const QString& fileName)
274 : WindowSystemEvent(FileOpen), fileName(fileName)
279 class TabletEvent : public InputEvent {
281 static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
282 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
283 qreal tangentialPressure, qreal rotation, int z, qint64 uid,
284 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
286 TabletEvent(QWindow *w, ulong time, bool down, const QPointF &local, const QPointF &global,
287 int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tpressure,
288 qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods)
289 : InputEvent(w, time, Tablet, Qt::NoModifier),
290 down(down), local(local), global(global), device(device), pointerType(pointerType),
291 pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
292 rotation(rotation), z(z), uid(uid), mods(mods) { }
301 qreal tangentialPressure;
305 Qt::KeyboardModifiers mods;
308 class TabletEnterProximityEvent : public InputEvent {
310 TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid)
311 : InputEvent(0, time, TabletEnterProximity, Qt::NoModifier),
312 device(device), pointerType(pointerType), uid(uid) { }
318 class TabletLeaveProximityEvent : public InputEvent {
320 TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid)
321 : InputEvent(0, time, TabletLeaveProximity, Qt::NoModifier),
322 device(device), pointerType(pointerType), uid(uid) { }
328 class WindowSystemEventList {
329 QList<WindowSystemEvent *> impl;
330 mutable QMutex mutex;
332 WindowSystemEventList() : impl(), mutex() {}
333 ~WindowSystemEventList()
334 { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
336 void prepend(WindowSystemEvent *e)
337 { const QMutexLocker locker(&mutex); impl.prepend(e); }
338 WindowSystemEvent *takeFirstOrReturnNull()
339 { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); }
340 void append(WindowSystemEvent *e)
341 { const QMutexLocker locker(&mutex); impl.append(e); }
343 { const QMutexLocker locker(&mutex); return impl.count(); }
345 Q_DISABLE_COPY(WindowSystemEventList);
348 static WindowSystemEventList windowSystemEventQueue;
350 static int windowSystemEventsQueued();
351 static WindowSystemEvent * getWindowSystemEvent();
352 static void queueWindowSystemEvent(WindowSystemEvent *ev);
354 static QElapsedTimer eventTime;
356 static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);
362 #endif // QWINDOWSYSTEMINTERFACE_P_H