1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
41 #ifndef QWINDOWSYSTEMINTERFACE_P_H
42 #define QWINDOWSYSTEMINTERFACE_P_H
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.
55 #include "qwindowsysteminterface.h"
57 #include <QElapsedTimer>
66 class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
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,
88 FileOpen = UserInputEvent | 0x13,
89 Tablet = UserInputEvent | 0x14,
90 TabletEnterProximity = UserInputEvent | 0x15,
91 TabletLeaveProximity = UserInputEvent | 0x16,
92 PlatformPanel = UserInputEvent | 0x17,
93 ContextMenu = UserInputEvent | 0x18
96 class WindowSystemEvent {
98 explicit WindowSystemEvent(EventType t)
99 : type(t), synthetic(false) { }
100 virtual ~WindowSystemEvent() { }
105 class CloseEvent : public WindowSystemEvent {
107 explicit CloseEvent(QWindow *w)
108 : WindowSystemEvent(Close), window(w) { }
109 QPointer<QWindow> window;
112 class GeometryChangeEvent : public WindowSystemEvent {
114 GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
115 : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
117 QPointer<QWindow> tlw;
121 class EnterEvent : public WindowSystemEvent {
123 explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
124 : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
126 QPointer<QWindow> enter;
127 const QPointF localPos;
128 const QPointF globalPos;
131 class LeaveEvent : public WindowSystemEvent {
133 explicit LeaveEvent(QWindow *leave)
134 : WindowSystemEvent(Leave), leave(leave)
136 QPointer<QWindow> leave;
139 class ActivatedWindowEvent : public WindowSystemEvent {
141 explicit ActivatedWindowEvent(QWindow *activatedWindow)
142 : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
144 QPointer<QWindow> activated;
147 class WindowStateChangedEvent : public WindowSystemEvent {
149 WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
150 : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
153 QPointer<QWindow> window;
154 Qt::WindowState newState;
157 class UserEvent : public WindowSystemEvent {
159 UserEvent(QWindow * w, ulong time, EventType t)
160 : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
161 QPointer<QWindow> window;
163 unsigned long timestamp;
166 class InputEvent: public UserEvent {
168 InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods)
169 : UserEvent(w, time, t), modifiers(mods) {}
170 Qt::KeyboardModifiers modifiers;
173 class MouseEvent : public InputEvent {
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) { }
183 Qt::MouseButtons buttons;
186 class WheelEvent : public InputEvent {
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) { }
194 Qt::Orientation qt4Orientation;
199 class KeyEvent : public InputEvent {
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) { }
215 QEvent::Type keyType;
216 quint32 nativeScanCode;
217 quint32 nativeVirtualKey;
218 quint32 nativeModifiers;
221 class TouchEvent : public InputEvent {
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;
231 class ScreenOrientationEvent : public WindowSystemEvent {
233 ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
234 : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
235 QPointer<QScreen> screen;
236 Qt::ScreenOrientation orientation;
239 class ScreenGeometryEvent : public WindowSystemEvent {
241 ScreenGeometryEvent(QScreen *s, const QRect &g)
242 : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
243 QPointer<QScreen> screen;
247 class ScreenAvailableGeometryEvent : public WindowSystemEvent {
249 ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
250 : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
251 QPointer<QScreen> screen;
252 QRect availableGeometry;
255 class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
257 ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
258 : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
259 QPointer<QScreen> screen;
264 class ScreenRefreshRateEvent : public WindowSystemEvent {
266 ScreenRefreshRateEvent(QScreen *s, qreal r)
267 : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
268 QPointer<QScreen> screen;
272 class ThemeChangeEvent : public WindowSystemEvent {
274 explicit ThemeChangeEvent(QWindow * w)
275 : WindowSystemEvent(ThemeChange), window(w) { }
276 QPointer<QWindow> window;
279 class ExposeEvent : public WindowSystemEvent {
281 ExposeEvent(QWindow *exposed, const QRegion ®ion);
282 QPointer<QWindow> exposed;
287 class FileOpenEvent : public WindowSystemEvent {
289 FileOpenEvent(const QString& fileName)
290 : WindowSystemEvent(FileOpen), fileName(fileName)
295 class TabletEvent : public InputEvent {
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);
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) { }
317 qreal tangentialPressure;
321 Qt::KeyboardModifiers mods;
324 class TabletEnterProximityEvent : public InputEvent {
326 TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid)
327 : InputEvent(0, time, TabletEnterProximity, Qt::NoModifier),
328 device(device), pointerType(pointerType), uid(uid) { }
334 class TabletLeaveProximityEvent : public InputEvent {
336 TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid)
337 : InputEvent(0, time, TabletLeaveProximity, Qt::NoModifier),
338 device(device), pointerType(pointerType), uid(uid) { }
344 class PlatformPanelEvent : public WindowSystemEvent {
346 explicit PlatformPanelEvent(QWindow *w)
347 : WindowSystemEvent(PlatformPanel), window(w) { }
348 QPointer<QWindow> window;
351 #ifndef QT_NO_CONTEXTMENU
352 class ContextMenuEvent : public WindowSystemEvent {
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;
360 QPoint pos; // Only valid if triggered by mouse
361 QPoint globalPos; // Only valid if triggered by mouse
362 Qt::KeyboardModifiers modifiers;
366 class WindowSystemEventList {
367 QList<WindowSystemEvent *> impl;
368 mutable QMutex mutex;
370 WindowSystemEventList() : impl(), mutex() {}
371 ~WindowSystemEventList()
372 { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); }
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()
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);
386 void append(WindowSystemEvent *e)
387 { const QMutexLocker locker(&mutex); impl.append(e); }
389 { const QMutexLocker locker(&mutex); return impl.count(); }
390 WindowSystemEvent *peekAtFirstOfType(EventType t) const
392 const QMutexLocker locker(&mutex);
393 for (int i = 0; i < impl.size(); ++i) {
394 if (impl.at(i)->type == t)
399 void remove(const WindowSystemEvent *e)
401 const QMutexLocker locker(&mutex);
402 for (int i = 0; i < impl.size(); ++i) {
403 if (impl.at(i) == e) {
410 Q_DISABLE_COPY(WindowSystemEventList);
413 static WindowSystemEventList windowSystemEventQueue;
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);
422 static QElapsedTimer eventTime;
423 static bool synchronousWindowsSystemEvents;
425 static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);
431 #endif // QWINDOWSYSTEMINTERFACE_P_H