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/QSharedPointer>
59#include <QtCore/private/qcoreapplication_p.h>
60
61#include <QtCore/private/qthread_p.h>
62
63#include <qpa/qwindowsysteminterface.h>
64#include <qpa/qwindowsysteminterface_p.h>
65#include "private/qshortcutmap_p.h"
66#include <qicon.h>
67
68QT_BEGIN_NAMESPACE
69
70class QColorTrcLut;
71class QPlatformIntegration;
72class QPlatformTheme;
73class QPlatformDragQtResponse;
74#if QT_CONFIG(draganddrop)
75class QDrag;
76#endif // QT_CONFIG(draganddrop)
77class QInputDeviceManager;
78
79class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
80{
81 Q_DECLARE_PUBLIC(QGuiApplication)
82public:
83 QGuiApplicationPrivate(int &argc, char **argv, int flags);
84 ~QGuiApplicationPrivate();
85
86 void init();
87
88 void createPlatformIntegration();
89 void createEventDispatcher() override;
90 void eventDispatcherReady() override;
91
92 virtual void notifyLayoutDirectionChange();
93 virtual void notifyActiveWindowChange(QWindow *previous);
94
95 virtual bool shouldQuit() override;
96
97 bool shouldQuitInternal(const QWindowList &processedWindows);
98 virtual bool tryCloseAllWindows();
99
100 static Qt::KeyboardModifiers modifier_buttons;
101 static Qt::MouseButtons mouse_buttons;
102
103 static QPlatformIntegration *platform_integration;
104
105 static QPlatformIntegration *platformIntegration()
106 { return platform_integration; }
107
108 static QPlatformTheme *platform_theme;
109
110 static QPlatformTheme *platformTheme()
111 { return platform_theme; }
112
113 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
114 {
115 if (QCoreApplication::instance())
116 return QCoreApplication::instance()->d_func()->threadData->eventDispatcher.load();
117 else
118 return 0;
119 }
120
121 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
122 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
123 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
124 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
125
126 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
127
128 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
129
130 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
131 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
132
133 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
134 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
135 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
136
137 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
138
139 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
140
141 static void updateFilteredScreenOrientation(QScreen *screen);
142 static void reportScreenOrientationChange(QScreen *screen);
143 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
144 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
145 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
146 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
147 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
148
149 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
150
151 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
152
153 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
154 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
155 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
156
157#ifndef QT_NO_GESTURES
158 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
159#endif
160
161 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
162#ifndef QT_NO_CONTEXTMENU
163 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
164#endif
165
166#if QT_CONFIG(draganddrop)
167 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
168 const QPoint &p, Qt::DropActions supportedActions,
169 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
170 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
171 const QPoint &p, Qt::DropActions supportedActions,
172 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
173#endif
174
175 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
176
177 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
178
179 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
180 {
181 if (!(alignment & Qt::AlignHorizontal_Mask))
182 alignment |= Qt::AlignLeft;
183 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
184 if (direction == Qt::RightToLeft)
185 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
186 alignment |= Qt::AlignAbsolute;
187 }
188 return alignment;
189 }
190
191 static void emitLastWindowClosed();
192
193 QPixmap getPixmapCursor(Qt::CursorShape cshape);
194
195 void _q_updateFocusObject(QObject *object);
196
197 static QGuiApplicationPrivate *instance() { return self; }
198
199 static QIcon *app_icon;
200 static QString *platform_name;
201 static QString *displayName;
202 static QString *desktopFileName;
203
204 QWindowList modalWindowList;
205 static void showModalWindow(QWindow *window);
206 static void hideModalWindow(QWindow *window);
207 static void updateBlockedStatus(QWindow *window);
208 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
209 virtual bool popupActive() { return false; }
210
211 static ulong mousePressTime;
212 static Qt::MouseButton mousePressButton;
213 static int mousePressX;
214 static int mousePressY;
215 static int mouse_double_click_distance;
216 static QPointF lastCursorPosition;
217 static QWindow *currentMouseWindow;
218 static QWindow *currentMousePressWindow;
219 static Qt::ApplicationState applicationState;
220 static bool highDpiScalingUpdated;
221 static QPointer<QWindow> currentDragWindow;
222
223 struct TabletPointData {
224 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
225 qint64 deviceId;
226 Qt::MouseButtons state;
227 QWindow *target;
228 };
229 static QVector<TabletPointData> tabletDevicePoints;
230 static TabletPointData &tabletDevicePoint(qint64 deviceId);
231
232#ifndef QT_NO_CLIPBOARD
233 static QClipboard *qt_clipboard;
234#endif
235
236 static QPalette *app_pal;
237
238 static QWindowList window_list;
239 static QWindow *focus_window;
240
241#ifndef QT_NO_CURSOR
242 QList<QCursor> cursor_list;
243#endif
244 static QList<QScreen *> screen_list;
245
246 static QFont *app_font;
247
248 static QString styleOverride;
249 static QStyleHints *styleHints;
250 static bool obey_desktop_settings;
251 QInputMethod *inputMethod;
252
253 QString firstWindowTitle;
254 QIcon forcedWindowIcon;
255
256 static QList<QObject *> generic_plugin_list;
257#ifndef QT_NO_SHORTCUT
258 QShortcutMap shortcutMap;
259#endif
260
261#ifndef QT_NO_SESSIONMANAGER
262 static bool is_fallback_session_management_enabled;
263 QSessionManager *session_manager;
264 bool is_session_restored;
265 bool is_saving_session;
266 void commitData();
267 void saveState();
268#endif
269
270 struct ActiveTouchPointsKey {
271 ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
272 QTouchDevice *device;
273 int touchPointId;
274 };
275 struct ActiveTouchPointsValue {
276 QPointer<QWindow> window;
277 QPointer<QObject> target;
278 QTouchEvent::TouchPoint touchPoint;
279 };
280 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
281 QEvent::Type lastTouchType;
282 struct SynthesizedMouseData {
283 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
284 : pos(p), screenPos(sp), window(w) { }
285 QPointF pos;
286 QPointF screenPos;
287 QPointer<QWindow> window;
288 };
289 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
290
291 static int mouseEventCaps(QMouseEvent *event);
292 static QVector2D mouseEventVelocity(QMouseEvent *event);
293 static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
294
295 static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
296 static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
297
298 static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
299 static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
300
301 static QInputDeviceManager *inputDeviceManager();
302
303 const QColorTrcLut *colorProfileForA8Text();
304 const QColorTrcLut *colorProfileForA32Text();
305
306 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
307 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
308
309 virtual void notifyWindowIconChanged();
310
311 static void applyWindowGeometrySpecificationTo(QWindow *window);
312
313 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
314
315 static void resetCachedDevicePixelRatio();
316
317protected:
318 virtual void notifyThemeChanged();
319 virtual void sendApplicationPaletteChange(bool toAllWidgets = false, const char *className = nullptr);
320 bool tryCloseRemainingWindows(QWindowList processedWindows);
321#if QT_CONFIG(draganddrop)
322 virtual void notifyDragStarted(const QDrag *);
323#endif // QT_CONFIG(draganddrop)
324
325private:
326 friend class QDragManager;
327
328 static QGuiApplicationPrivate *self;
329 static QTouchDevice *m_fakeTouchDevice;
330 static int m_fakeMouseSourcePointId;
331 QSharedPointer<QColorTrcLut> m_a8ColorProfile;
332 QSharedPointer<QColorTrcLut> m_a32ColorProfile;
333
334 bool ownGlobalShareContext;
335
336 static QInputDeviceManager *m_inputDeviceManager;
337
338 // Cache the maximum device pixel ratio, to iterate through the screen list
339 // only the first time it's required, or when devices are added or removed.
340 static qreal m_maxDevicePixelRatio;
341};
342
343Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
344
345Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
346 const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
347
348QT_END_NAMESPACE
349
350#endif // QGUIAPPLICATION_P_H
351