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#if QT_CONFIG(shortcut)
66# include "private/qshortcutmap_p.h"
67#endif
68
69#include <qicon.h>
70
71QT_BEGIN_NAMESPACE
72
73class QColorTrcLut;
74class QPlatformIntegration;
75class QPlatformTheme;
76class QPlatformDragQtResponse;
77#if QT_CONFIG(draganddrop)
78class QDrag;
79#endif // QT_CONFIG(draganddrop)
80class QInputDeviceManager;
81#ifndef QT_NO_ACTION
82class QActionPrivate;
83#endif
84#if QT_CONFIG(shortcut)
85class QShortcutPrivate;
86#endif
87
88class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
89{
90 Q_DECLARE_PUBLIC(QGuiApplication)
91public:
92 QGuiApplicationPrivate(int &argc, char **argv, int flags);
93 ~QGuiApplicationPrivate();
94
95 void init();
96
97 void createPlatformIntegration();
98 void createEventDispatcher() override;
99 void eventDispatcherReady() override;
100
101 virtual void notifyLayoutDirectionChange();
102 virtual void notifyActiveWindowChange(QWindow *previous);
103
104#if QT_CONFIG(commandlineparser)
105 void addQtOptions(QList<QCommandLineOption> *options) override;
106#endif
107 virtual bool shouldQuit() override;
108 void quit() override;
109
110 bool shouldQuitInternal(const QWindowList &processedWindows);
111
112 static void captureGlobalModifierState(QEvent *e);
113 static Qt::KeyboardModifiers modifier_buttons;
114 static Qt::MouseButtons mouse_buttons;
115
116 static QPlatformIntegration *platform_integration;
117
118 static QPlatformIntegration *platformIntegration()
119 { return platform_integration; }
120
121 static QPlatformTheme *platform_theme;
122
123 static QPlatformTheme *platformTheme()
124 { return platform_theme; }
125
126 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
127 {
128 if (QCoreApplication::instance())
129 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
130 else
131 return nullptr;
132 }
133
134 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
135 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
136 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
137 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
138
139 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
140
141 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
142
143 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
144 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
145
146 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
147 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
148 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
149
150 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
151
152 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
153
154 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
155
156 static void updateFilteredScreenOrientation(QScreen *screen);
157 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
158 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
159 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
160 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
161 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
162
163 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
164 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
165
166 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
167
168 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
169 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
170 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
171
172#ifndef QT_NO_GESTURES
173 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
174#endif
175
176 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
177#ifndef QT_NO_CONTEXTMENU
178 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
179#endif
180
181#if QT_CONFIG(draganddrop)
182 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
183 const QPoint &p, Qt::DropActions supportedActions,
184 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
185 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
186 const QPoint &p, Qt::DropActions supportedActions,
187 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
188#endif
189
190#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
191 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
192#else
193 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
194#endif
195
196 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
197
198 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
199 {
200 if (!(alignment & Qt::AlignHorizontal_Mask))
201 alignment |= Qt::AlignLeft;
202 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
203 if (direction == Qt::RightToLeft)
204 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
205 alignment |= Qt::AlignAbsolute;
206 }
207 return alignment;
208 }
209
210 static void emitLastWindowClosed();
211
212 QPixmap getPixmapCursor(Qt::CursorShape cshape);
213
214 void _q_updateFocusObject(QObject *object);
215
216 static QGuiApplicationPrivate *instance() { return self; }
217
218 static QIcon *app_icon;
219 static QString *platform_name;
220 static QString *displayName;
221 static QString *desktopFileName;
222
223 QWindowList modalWindowList;
224 static void showModalWindow(QWindow *window);
225 static void hideModalWindow(QWindow *window);
226 static void updateBlockedStatus(QWindow *window);
227 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
228 virtual bool popupActive() { return false; }
229
230 static Qt::MouseButton mousePressButton;
231 static QPointF lastCursorPosition;
232 static QWindow *currentMouseWindow;
233 static QWindow *currentMousePressWindow;
234 static Qt::ApplicationState applicationState;
235 static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
236 static bool highDpiScalingUpdated;
237 static QPointer<QWindow> currentDragWindow;
238
239 // TODO remove this: QPointingDevice can store what we need directly
240 struct TabletPointData {
241 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
242 qint64 deviceId;
243 Qt::MouseButtons state;
244 QWindow *target;
245 };
246 static QList<TabletPointData> tabletDevicePoints;
247 static TabletPointData &tabletDevicePoint(qint64 deviceId);
248
249#ifndef QT_NO_CLIPBOARD
250 static QClipboard *qt_clipboard;
251#endif
252
253 static QPalette *app_pal;
254
255 static QWindowList window_list;
256 static QWindow *focus_window;
257
258#ifndef QT_NO_CURSOR
259 QList<QCursor> cursor_list;
260#endif
261 static QList<QScreen *> screen_list;
262
263 static QFont *app_font;
264
265 static QString styleOverride;
266 static QStyleHints *styleHints;
267 static bool obey_desktop_settings;
268 QInputMethod *inputMethod;
269
270 QString firstWindowTitle;
271 QIcon forcedWindowIcon;
272
273 static QList<QObject *> generic_plugin_list;
274#if QT_CONFIG(shortcut)
275 QShortcutMap shortcutMap;
276#endif
277
278#ifndef QT_NO_SESSIONMANAGER
279 QSessionManager *session_manager;
280 bool is_session_restored;
281 bool is_saving_session;
282 void commitData();
283 void saveState();
284#endif
285
286 QEvent::Type lastTouchType;
287 struct SynthesizedMouseData {
288 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
289 : pos(p), screenPos(sp), window(w) { }
290 QPointF pos;
291 QPointF screenPos;
292 QPointer<QWindow> window;
293 };
294 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
295
296 static QInputDeviceManager *inputDeviceManager();
297
298 const QColorTrcLut *colorProfileForA8Text();
299 const QColorTrcLut *colorProfileForA32Text();
300
301 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
302 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
303
304 virtual void notifyWindowIconChanged();
305
306 static void applyWindowGeometrySpecificationTo(QWindow *window);
307
308 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
309
310 static void resetCachedDevicePixelRatio();
311
312#ifndef QT_NO_ACTION
313 virtual QActionPrivate *createActionPrivate() const;
314#endif
315#ifndef QT_NO_SHORTCUT
316 virtual QShortcutPrivate *createShortcutPrivate() const;
317#endif
318
319 static void updatePalette();
320 QEvent *cloneEvent(QEvent *e) override;
321
322protected:
323 virtual void notifyThemeChanged();
324
325 static bool setPalette(const QPalette &palette);
326 virtual QPalette basePalette() const;
327 virtual void handlePaletteChanged(const char *className = nullptr);
328
329#if QT_CONFIG(draganddrop)
330 virtual void notifyDragStarted(const QDrag *);
331#endif // QT_CONFIG(draganddrop)
332
333private:
334 static void clearPalette();
335
336 friend class QDragManager;
337
338 static QGuiApplicationPrivate *self;
339 static QPointingDevice *m_fakeTouchDevice;
340 static int m_fakeMouseSourcePointId;
341 QSharedPointer<QColorTrcLut> m_a8ColorProfile;
342 QSharedPointer<QColorTrcLut> m_a32ColorProfile;
343
344 bool ownGlobalShareContext;
345
346 static QInputDeviceManager *m_inputDeviceManager;
347
348 // Cache the maximum device pixel ratio, to iterate through the screen list
349 // only the first time it's required, or when devices are added or removed.
350 static qreal m_maxDevicePixelRatio;
351};
352
353// ----------------- QNativeInterface -----------------
354
355namespace QNativeInterface::Private {
356
357#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
358
359class QWindowsMime;
360
361struct Q_GUI_EXPORT QWindowsApplication
362{
363 QT_DECLARE_NATIVE_INTERFACE(QWindowsApplication)
364
365 enum WindowActivationBehavior {
366 DefaultActivateWindow,
367 AlwaysActivateWindow
368 };
369
370 enum TouchWindowTouchType {
371 NormalTouch = 0x00000000,
372 FineTouch = 0x00000001,
373 WantPalmTouch = 0x00000002
374 };
375
376 Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
377
378 enum DarkModeHandlingFlag {
379 DarkModeWindowFrames = 0x1,
380 DarkModeStyle = 0x2
381 };
382
383 Q_DECLARE_FLAGS(DarkModeHandling, DarkModeHandlingFlag)
384
385 virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
386 virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
387
388 virtual WindowActivationBehavior windowActivationBehavior() const = 0;
389 virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
390
391 virtual bool isTabletMode() const = 0;
392
393 virtual bool isWinTabEnabled() const = 0;
394 virtual bool setWinTabEnabled(bool enabled) = 0;
395
396 virtual bool isDarkMode() const = 0;
397
398 virtual DarkModeHandling darkModeHandling() const = 0;
399 virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
400
401 virtual void registerMime(QWindowsMime *mime) = 0;
402 virtual void unregisterMime(QWindowsMime *mime) = 0;
403
404 virtual int registerMimeType(const QString &mime) = 0;
405
406 virtual HWND createMessageWindow(const QString &classNameTemplate,
407 const QString &windowName,
408 QFunctionPointer eventProc = nullptr) const = 0;
409
410 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
411 virtual void setAsyncExpose(bool value) = 0;
412
413 virtual QVariant gpu() const = 0; // internal, used by qtdiag
414 virtual QVariant gpuList() const = 0;
415};
416#endif // Q_OS_WIN
417
418} // QNativeInterface::Private
419
420#if defined(Q_OS_WIN)
421Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
422Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
423#endif
424
425QT_END_NAMESPACE
426
427#endif // QGUIAPPLICATION_P_H
428