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#if QT_CONFIG(draganddrop)
74class QDrag;
75#endif // QT_CONFIG(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 processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
143 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
144 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
145 static void processScreenRefreshRateChange(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#if QT_CONFIG(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 static QPointer<QWindow> currentDragWindow;
221
222 struct TabletPointData {
223 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
224 qint64 deviceId;
225 Qt::MouseButtons state;
226 QWindow *target;
227 };
228 static QVector<TabletPointData> tabletDevicePoints;
229 static TabletPointData &tabletDevicePoint(qint64 deviceId);
230
231#ifndef QT_NO_CLIPBOARD
232 static QClipboard *qt_clipboard;
233#endif
234
235 static QPalette *app_pal;
236
237 static QWindowList window_list;
238 static QWindow *focus_window;
239
240#ifndef QT_NO_CURSOR
241 QList<QCursor> cursor_list;
242#endif
243 static QList<QScreen *> screen_list;
244
245 static QFont *app_font;
246
247 static QString styleOverride;
248 static QStyleHints *styleHints;
249 static bool obey_desktop_settings;
250 QInputMethod *inputMethod;
251
252 QString firstWindowTitle;
253 QIcon forcedWindowIcon;
254
255 static QList<QObject *> generic_plugin_list;
256#ifndef QT_NO_SHORTCUT
257 QShortcutMap shortcutMap;
258#endif
259
260#ifndef QT_NO_SESSIONMANAGER
261 static bool is_fallback_session_management_enabled;
262 QSessionManager *session_manager;
263 bool is_session_restored;
264 bool is_saving_session;
265 void commitData();
266 void saveState();
267#endif
268
269 struct ActiveTouchPointsKey {
270 ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
271 QTouchDevice *device;
272 int touchPointId;
273 };
274 struct ActiveTouchPointsValue {
275 QPointer<QWindow> window;
276 QPointer<QObject> target;
277 QTouchEvent::TouchPoint touchPoint;
278 };
279 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
280 QEvent::Type lastTouchType;
281 struct SynthesizedMouseData {
282 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
283 : pos(p), screenPos(sp), window(w) { }
284 QPointF pos;
285 QPointF screenPos;
286 QPointer<QWindow> window;
287 };
288 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
289
290 static int mouseEventCaps(QMouseEvent *event);
291 static QVector2D mouseEventVelocity(QMouseEvent *event);
292 static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
293
294 static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
295 static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
296
297 static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
298 static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
299
300 static QInputDeviceManager *inputDeviceManager();
301
302 const QColorProfile *colorProfileForA8Text();
303 const QColorProfile *colorProfileForA32Text();
304
305 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
306 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
307
308 virtual void notifyWindowIconChanged();
309
310 static void applyWindowGeometrySpecificationTo(QWindow *window);
311
312 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
313
314protected:
315 virtual void notifyThemeChanged();
316 bool tryCloseRemainingWindows(QWindowList processedWindows);
317#if QT_CONFIG(draganddrop)
318 virtual void notifyDragStarted(const QDrag *);
319#endif // QT_CONFIG(draganddrop)
320
321private:
322 friend class QDragManager;
323
324 static QGuiApplicationPrivate *self;
325 static QTouchDevice *m_fakeTouchDevice;
326 static int m_fakeMouseSourcePointId;
327 QAtomicPointer<QColorProfile> m_a8ColorProfile;
328 QAtomicPointer<QColorProfile> m_a32ColorProfile;
329
330 bool ownGlobalShareContext;
331
332 static QInputDeviceManager *m_inputDeviceManager;
333};
334
335Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
336
337Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
338 const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
339
340QT_END_NAMESPACE
341
342#endif // QGUIAPPLICATION_P_H
343