1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QGUIAPPLICATION_P_H
41#define QGUIAPPLICATION_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtGui/private/qtguiglobal_p.h>
55#include <QtGui/qguiapplication.h>
56
57#include <QtCore/QPointF>
58#include <QtCore/private/qcoreapplication_p.h>
59
60#include <QtCore/private/qthread_p.h>
61
62#include <qpa/qwindowsysteminterface.h>
63#include <qpa/qwindowsysteminterface_p.h>
64#include "private/qshortcutmap_p.h"
65#include <qicon.h>
66
67QT_BEGIN_NAMESPACE
68
69class QColorProfile;
70class QPlatformIntegration;
71class QPlatformTheme;
72class QPlatformDragQtResponse;
73#ifndef QT_NO_DRAGANDDROP
74class QDrag;
75#endif // QT_NO_DRAGANDDROP
76class QInputDeviceManager;
77
78class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
79{
80 Q_DECLARE_PUBLIC(QGuiApplication)
81public:
82 QGuiApplicationPrivate(int &argc, char **argv, int flags);
83 ~QGuiApplicationPrivate();
84
85 void init();
86
87 void createPlatformIntegration();
88 void createEventDispatcher() override;
89 void eventDispatcherReady() override;
90
91 virtual void notifyLayoutDirectionChange();
92 virtual void notifyActiveWindowChange(QWindow *previous);
93
94 virtual bool shouldQuit() override;
95
96 bool shouldQuitInternal(const QWindowList &processedWindows);
97 virtual bool tryCloseAllWindows();
98
99 static Qt::KeyboardModifiers modifier_buttons;
100 static Qt::MouseButtons mouse_buttons;
101
102 static QPlatformIntegration *platform_integration;
103
104 static QPlatformIntegration *platformIntegration()
105 { return platform_integration; }
106
107 static QPlatformTheme *platform_theme;
108
109 static QPlatformTheme *platformTheme()
110 { return platform_theme; }
111
112 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
113 {
114 if (QCoreApplication::instance())
115 return QCoreApplication::instance()->d_func()->threadData->eventDispatcher.load();
116 else
117 return 0;
118 }
119
120 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
121 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
122 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
123 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
124
125 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
126
127 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
128
129 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
130 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
131
132 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
133 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
134 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
135
136 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
137
138 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
139
140 static void updateFilteredScreenOrientation(QScreen *screen);
141 static void reportScreenOrientationChange(QScreen *screen);
142 static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
143 static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
144 static void reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
145 static void reportRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
146 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
147
148 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
149
150 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
151
152 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
153 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
154 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
155
156#ifndef QT_NO_GESTURES
157 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
158#endif
159
160 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
161#ifndef QT_NO_CONTEXTMENU
162 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
163#endif
164
165#ifndef QT_NO_DRAGANDDROP
166 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
167 const QPoint &p, Qt::DropActions supportedActions,
168 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
169 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
170 const QPoint &p, Qt::DropActions supportedActions,
171 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
172#endif
173
174 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
175
176 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
177
178 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
179 {
180 if (!(alignment & Qt::AlignHorizontal_Mask))
181 alignment |= Qt::AlignLeft;
182 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
183 if (direction == Qt::RightToLeft)
184 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
185 alignment |= Qt::AlignAbsolute;
186 }
187 return alignment;
188 }
189
190 static void emitLastWindowClosed();
191
192 QPixmap getPixmapCursor(Qt::CursorShape cshape);
193
194 void _q_updateFocusObject(QObject *object);
195
196 static QGuiApplicationPrivate *instance() { return self; }
197
198 static QIcon *app_icon;
199 static QString *platform_name;
200 static QString *displayName;
201 static QString *desktopFileName;
202
203 QWindowList modalWindowList;
204 static void showModalWindow(QWindow *window);
205 static void hideModalWindow(QWindow *window);
206 static void updateBlockedStatus(QWindow *window);
207 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
208 virtual bool popupActive() { return false; }
209
210 static ulong mousePressTime;
211 static Qt::MouseButton mousePressButton;
212 static int mousePressX;
213 static int mousePressY;
214 static int mouse_double_click_distance;
215 static QPointF lastCursorPosition;
216 static QWindow *currentMouseWindow;
217 static QWindow *currentMousePressWindow;
218 static Qt::ApplicationState applicationState;
219 static bool highDpiScalingUpdated;
220
221 struct TabletPointData {
222 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
223 qint64 deviceId;
224 Qt::MouseButtons state;
225 QWindow *target;
226 };
227 static QVector<TabletPointData> tabletDevicePoints;
228 static TabletPointData &tabletDevicePoint(qint64 deviceId);
229
230#ifndef QT_NO_CLIPBOARD
231 static QClipboard *qt_clipboard;
232#endif
233
234 static QPalette *app_pal;
235
236 static QWindowList window_list;
237 static QWindow *focus_window;
238
239#ifndef QT_NO_CURSOR
240 QList<QCursor> cursor_list;
241#endif
242 static QList<QScreen *> screen_list;
243
244 static QFont *app_font;
245
246 static QString styleOverride;
247 static QStyleHints *styleHints;
248 static bool obey_desktop_settings;
249 QInputMethod *inputMethod;
250
251 QString firstWindowTitle;
252 QIcon forcedWindowIcon;
253
254 static QList<QObject *> generic_plugin_list;
255#ifndef QT_NO_SHORTCUT
256 QShortcutMap shortcutMap;
257#endif
258
259#ifndef QT_NO_SESSIONMANAGER
260 static bool is_fallback_session_management_enabled;
261 QSessionManager *session_manager;
262 bool is_session_restored;
263 bool is_saving_session;
264 void commitData();
265 void saveState();
266#endif
267
268 struct ActiveTouchPointsKey {
269 ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
270 QTouchDevice *device;
271 int touchPointId;
272 };
273 struct ActiveTouchPointsValue {
274 QPointer<QWindow> window;
275 QPointer<QObject> target;
276 QTouchEvent::TouchPoint touchPoint;
277 };
278 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
279 QEvent::Type lastTouchType;
280 struct SynthesizedMouseData {
281 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
282 : pos(p), screenPos(sp), window(w) { }
283 QPointF pos;
284 QPointF screenPos;
285 QPointer<QWindow> window;
286 };
287 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
288
289 static int mouseEventCaps(QMouseEvent *event);
290 static QVector2D mouseEventVelocity(QMouseEvent *event);
291 static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
292
293 static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
294 static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
295
296 static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
297 static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
298
299 static QInputDeviceManager *inputDeviceManager();
300
301 const QColorProfile *colorProfileForA8Text();
302 const QColorProfile *colorProfileForA32Text();
303
304 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
305 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
306
307 virtual void notifyWindowIconChanged();
308
309 static void applyWindowGeometrySpecificationTo(QWindow *window);
310
311 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
312
313protected:
314 virtual void notifyThemeChanged();
315 bool tryCloseRemainingWindows(QWindowList processedWindows);
316#ifndef QT_NO_DRAGANDDROP
317 virtual void notifyDragStarted(const QDrag *);
318#endif // QT_NO_DRAGANDDROP
319
320private:
321 friend class QDragManager;
322
323 static QGuiApplicationPrivate *self;
324 static QTouchDevice *m_fakeTouchDevice;
325 static int m_fakeMouseSourcePointId;
326 QAtomicPointer<QColorProfile> m_a8ColorProfile;
327 QAtomicPointer<QColorProfile> m_a32ColorProfile;
328
329 bool ownGlobalShareContext;
330
331 static QInputDeviceManager *m_inputDeviceManager;
332};
333
334Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
335
336Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
337 const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
338
339QT_END_NAMESPACE
340
341#endif // QGUIAPPLICATION_P_H
342