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 nullptr;
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#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
176 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
177#else
178 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
179#endif
180
181 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
182
183 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
184 {
185 if (!(alignment & Qt::AlignHorizontal_Mask))
186 alignment |= Qt::AlignLeft;
187 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
188 if (direction == Qt::RightToLeft)
189 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
190 alignment |= Qt::AlignAbsolute;
191 }
192 return alignment;
193 }
194
195 static void emitLastWindowClosed();
196
197 QPixmap getPixmapCursor(Qt::CursorShape cshape);
198
199 void _q_updateFocusObject(QObject *object);
200
201 static QGuiApplicationPrivate *instance() { return self; }
202
203 static QIcon *app_icon;
204 static QString *platform_name;
205 static QString *displayName;
206 static QString *desktopFileName;
207
208 QWindowList modalWindowList;
209 static void showModalWindow(QWindow *window);
210 static void hideModalWindow(QWindow *window);
211 static void updateBlockedStatus(QWindow *window);
212 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
213 virtual bool popupActive() { return false; }
214
215 static ulong mousePressTime;
216 static Qt::MouseButton mousePressButton;
217 static int mousePressX;
218 static int mousePressY;
219 static int mouse_double_click_distance;
220 static QPointF lastCursorPosition;
221 static QWindow *currentMouseWindow;
222 static QWindow *currentMousePressWindow;
223 static Qt::ApplicationState applicationState;
224 static bool highDpiScalingUpdated;
225 static QPointer<QWindow> currentDragWindow;
226
227 struct TabletPointData {
228 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
229 qint64 deviceId;
230 Qt::MouseButtons state;
231 QWindow *target;
232 };
233 static QVector<TabletPointData> tabletDevicePoints;
234 static TabletPointData &tabletDevicePoint(qint64 deviceId);
235
236#ifndef QT_NO_CLIPBOARD
237 static QClipboard *qt_clipboard;
238#endif
239
240 static QPalette *app_pal;
241
242 static QWindowList window_list;
243 static QWindow *focus_window;
244
245#ifndef QT_NO_CURSOR
246 QList<QCursor> cursor_list;
247#endif
248 static QList<QScreen *> screen_list;
249
250 static QFont *app_font;
251
252 static QString styleOverride;
253 static QStyleHints *styleHints;
254 static bool obey_desktop_settings;
255 QInputMethod *inputMethod;
256
257 QString firstWindowTitle;
258 QIcon forcedWindowIcon;
259
260 static QList<QObject *> generic_plugin_list;
261#ifndef QT_NO_SHORTCUT
262 QShortcutMap shortcutMap;
263#endif
264
265#ifndef QT_NO_SESSIONMANAGER
266 static bool is_fallback_session_management_enabled;
267 QSessionManager *session_manager;
268 bool is_session_restored;
269 bool is_saving_session;
270 void commitData();
271 void saveState();
272#endif
273
274 struct ActiveTouchPointsKey {
275 ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
276 QTouchDevice *device;
277 int touchPointId;
278 };
279 struct ActiveTouchPointsValue {
280 QPointer<QWindow> window;
281 QPointer<QObject> target;
282 QTouchEvent::TouchPoint touchPoint;
283 };
284 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
285 QEvent::Type lastTouchType;
286 struct SynthesizedMouseData {
287 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
288 : pos(p), screenPos(sp), window(w) { }
289 QPointF pos;
290 QPointF screenPos;
291 QPointer<QWindow> window;
292 };
293 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
294
295 static int mouseEventCaps(QMouseEvent *event);
296 static QVector2D mouseEventVelocity(QMouseEvent *event);
297 static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
298
299 static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
300 static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
301
302 static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
303 static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
304
305 static QInputDeviceManager *inputDeviceManager();
306
307 const QColorTrcLut *colorProfileForA8Text();
308 const QColorTrcLut *colorProfileForA32Text();
309
310 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
311 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
312
313 virtual void notifyWindowIconChanged();
314
315 static void applyWindowGeometrySpecificationTo(QWindow *window);
316
317 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
318
319 static void resetCachedDevicePixelRatio();
320
321protected:
322 virtual void notifyThemeChanged();
323 virtual void sendApplicationPaletteChange(bool toAllWidgets = false, const char *className = nullptr);
324 bool tryCloseRemainingWindows(QWindowList processedWindows);
325#if QT_CONFIG(draganddrop)
326 virtual void notifyDragStarted(const QDrag *);
327#endif // QT_CONFIG(draganddrop)
328
329private:
330 friend class QDragManager;
331
332 static QGuiApplicationPrivate *self;
333 static QTouchDevice *m_fakeTouchDevice;
334 static int m_fakeMouseSourcePointId;
335 QSharedPointer<QColorTrcLut> m_a8ColorProfile;
336 QSharedPointer<QColorTrcLut> m_a32ColorProfile;
337
338 bool ownGlobalShareContext;
339
340 static QInputDeviceManager *m_inputDeviceManager;
341
342 // Cache the maximum device pixel ratio, to iterate through the screen list
343 // only the first time it's required, or when devices are added or removed.
344 static qreal m_maxDevicePixelRatio;
345};
346
347Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
348
349Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
350 const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
351
352QT_END_NAMESPACE
353
354#endif // QGUIAPPLICATION_P_H
355