Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qguiapplication_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QGUIAPPLICATION_P_H
6#define QGUIAPPLICATION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <QtGui/qguiapplication.h>
21#include <QtGui/qicon.h>
22
23#include <QtCore/QHash>
24#include <QtCore/QPointF>
25#include <QtCore/private/qcoreapplication_p.h>
26#include <QtCore/qbasicatomic.h>
27
28#include <QtCore/qnativeinterface.h>
29#include <QtCore/private/qnativeinterface_p.h>
30#include <QtCore/private/qnumeric_p.h>
31#include <QtCore/private/qthread_p.h>
32
33#include <qpa/qwindowsysteminterface.h>
34#include <qpa/qwindowsysteminterface_p.h>
35#if QT_CONFIG(shortcut)
36# include "private/qshortcutmap_p.h"
37#endif
38
39#include <QtCore/qpointer.h>
40
41#include <memory>
42
43QT_BEGIN_NAMESPACE
44
45Q_DECLARE_LOGGING_CATEGORY(lcPopup)
46Q_DECLARE_LOGGING_CATEGORY(lcVirtualKeyboard)
47
48class QColorTrcLut;
49class QPlatformIntegration;
50class QPlatformTheme;
51class QPlatformDragQtResponse;
52#if QT_CONFIG(draganddrop)
53class QDrag;
54#endif // QT_CONFIG(draganddrop)
55class QInputDeviceManager;
56#ifndef QT_NO_ACTION
57class QActionPrivate;
58#endif
59#if QT_CONFIG(shortcut)
60class QShortcutPrivate;
61#endif
62class QThreadPool;
63
64class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
65{
66 Q_DECLARE_PUBLIC(QGuiApplication)
67public:
68 QGuiApplicationPrivate(int &argc, char **argv);
69 ~QGuiApplicationPrivate();
70
71 void init();
72
73 void createPlatformIntegration();
74 void createEventDispatcher() override;
75 void eventDispatcherReady() override;
76
77 virtual void notifyLayoutDirectionChange();
78 virtual void notifyActiveWindowChange(QWindow *previous);
79
80#if QT_CONFIG(commandlineparser)
81 void addQtOptions(QList<QCommandLineOption> *options) override;
82#endif
83 bool canQuitAutomatically() override;
84 void quit() override;
85 bool handleQuitEvent() override;
86
87 void maybeLastWindowClosed();
88 bool lastWindowClosed() const;
89 static bool quitOnLastWindowClosed;
90
91 static void captureGlobalModifierState(QEvent *e);
92 static Qt::KeyboardModifiers modifier_buttons;
93 static Qt::MouseButtons mouse_buttons;
94
95 static QPlatformIntegration *platform_integration;
96
97 static QPlatformIntegration *platformIntegration()
98 { return platform_integration; }
99
100 static QPlatformTheme *platform_theme;
101
102 static QPlatformTheme *platformTheme()
103 { return platform_theme; }
104
105 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
106 {
107 if (QCoreApplication::instance())
108 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
109 else
110 return nullptr;
111 }
112
113 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
114 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
115 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
116 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
117
118 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
119
120 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
121
122 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
123 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
124
125 static void processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e);
126
127 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
128 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
129 static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e);
130
131 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
132
133 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
134
135 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
136
137 static void updateFilteredScreenOrientation(QScreen *screen);
138 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
139 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
140 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
141 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
142 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
143
144 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
145 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
146
147 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
148
149 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
150 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
151 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
152
153#ifndef QT_NO_GESTURES
154 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
155#endif
156
157 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
158#ifndef QT_NO_CONTEXTMENU
159 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
160#endif
161
162#if QT_CONFIG(draganddrop)
163 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
164 const QPoint &p, Qt::DropActions supportedActions,
165 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
166 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
167 const QPoint &p, Qt::DropActions supportedActions,
168 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
169#endif
170
171 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
172
173 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
174
175 static bool maybeForwardEventToVirtualKeyboard(QEvent *e);
176 static bool isUsingVirtualKeyboard();
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 QPixmap getPixmapCursor(Qt::CursorShape cshape);
191
192 void _q_updateFocusObject(QObject *object);
193
194 static QGuiApplicationPrivate *instance() { QT_IGNORE_DEPRECATIONS(return self;) }
195
196 static QIcon *app_icon;
197 static QString *platform_name;
198 static QString *displayName;
199 static QString *desktopFileName;
200
201 QWindowList modalWindowList;
202 static void showModalWindow(QWindow *window);
203 static void hideModalWindow(QWindow *window);
204 static void updateBlockedStatus(QWindow *window);
205
206 virtual Qt::WindowModality defaultModality() const;
207 virtual bool windowNeverBlocked(QWindow *window) const;
208 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
209 static qsizetype popupCount() { return QGuiApplicationPrivate::popup_list.size(); }
210 static QWindow *activePopupWindow();
211 static void activatePopup(QWindow *popup);
212 static bool closePopup(QWindow *popup);
213 static bool closeAllPopups();
214
215 static Qt::MouseButton mousePressButton;
216 static struct QLastCursorPosition {
217 // Initialize to a far-offscreen position. 2^23 is small enough for accurate arithmetic
218 // (even manhattanLength()) even when stored in the mantissa of a 32-bit float.
219 constexpr inline QLastCursorPosition() noexcept : thePoint(1 << 23, 1 << 23) {}
220 constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {}
221 constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; }
222 constexpr inline qreal x() const noexcept{ return thePoint.x(); }
223 constexpr inline qreal y() const noexcept{ return thePoint.y(); }
224 Q_GUI_EXPORT QPoint toPoint() const noexcept;
225
226 constexpr void reset() noexcept { *this = QLastCursorPosition{}; }
227
228 // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection
229 // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise
230 // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here
231 // to use single-point precision.
232 friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
233 {
234 return QtPrivate::fuzzyCompare(float(p1.x()), float(p2.x()))
235 && QtPrivate::fuzzyCompare(float(p1.y()), float(p2.y()));
236 }
237 friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
238 {
239 return !(p1 == p2);
240 }
241 friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
242 {
243 return p2 == p1;
244 }
245 friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
246 {
247 return !(p2 == p1);
248 }
249
250 private:
251 QPointF thePoint;
252 } lastCursorPosition;
253 static QWindow *currentMouseWindow;
254 static QWindow *currentMousePressWindow;
255 static Qt::ApplicationState applicationState;
256 static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
257 static QPointer<QWindow> currentDragWindow;
258
259 // TODO remove this: QPointingDevice can store what we need directly
260 struct TabletPointData {
261 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
262 qint64 deviceId;
263 Qt::MouseButtons state;
264 QWindow *target;
265 };
266 static QList<TabletPointData> tabletDevicePoints;
267 static TabletPointData &tabletDevicePoint(qint64 deviceId);
268
269#ifndef QT_NO_CLIPBOARD
270 static QClipboard *qt_clipboard;
271#endif
272
273 static QPalette *app_pal;
274
275 static QWindowList window_list;
276 static QWindowList popup_list;
277 static const QWindow *active_popup_on_press;
278 static QWindow *focus_window;
279
280#ifndef QT_NO_CURSOR
281 QList<QCursor> cursor_list;
282#endif
283 static QList<QScreen *> screen_list;
284
285 static QFont *app_font;
286
287 static QString styleOverride;
288 static QStyleHints *styleHints;
289 static bool obey_desktop_settings;
290 static bool popup_closed_on_press;
291 QInputMethod *inputMethod;
292
293 QString firstWindowTitle;
294 QIcon forcedWindowIcon;
295 qint64 badgeNumber = 0;
296
297 static QList<QObject *> generic_plugin_list;
298#if QT_CONFIG(shortcut)
299 QShortcutMap shortcutMap;
300#endif
301
302#ifndef QT_NO_SESSIONMANAGER
303 QSessionManager *session_manager;
304 bool is_session_restored;
305 bool is_saving_session;
306 void commitData();
307 void saveState();
308#endif
309
310 QEvent::Type lastTouchType;
311 struct SynthesizedMouseData {
312 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
313 : pos(p), screenPos(sp), window(w) { }
314 QPointF pos;
315 QPointF screenPos;
316 QPointer<QWindow> window;
317 };
318 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
319
320 static QInputDeviceManager *inputDeviceManager();
321
322 const QColorTrcLut *colorProfileForA8Text();
323 const QColorTrcLut *colorProfileForA32Text();
324
325 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
326 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
327
328 virtual void notifyWindowIconChanged();
329
330 static void applyWindowGeometrySpecificationTo(QWindow *window);
331
332 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
333
334 static void resetCachedDevicePixelRatio();
335
336#ifndef QT_NO_ACTION
337 virtual QActionPrivate *createActionPrivate() const;
338#endif
339#ifndef QT_NO_SHORTCUT
340 virtual QShortcutPrivate *createShortcutPrivate() const;
341#endif
342
343 static void updatePalette();
344
345 static QEvent::Type contextMenuEventType();
346
347 static QThreadPool *qtGuiThreadPool();
348
349#ifndef QT_NO_OPENGL
350 bool ownGlobalShareContext = false;
351#endif
352
353 void _q_updatePrimaryScreenDpis();
354 static QBasicAtomicInt m_primaryScreenDpis;
355
356protected:
357 virtual void handleThemeChanged();
358
359 static bool setPalette(const QPalette &palette);
360 virtual QPalette basePalette() const;
361 virtual void handlePaletteChanged(const char *className = nullptr);
362
363#if QT_CONFIG(draganddrop)
364 virtual void notifyDragStarted(const QDrag *);
365#endif // QT_CONFIG(draganddrop)
366
367private:
368 static void clearPalette();
369
370 friend class QDragManager;
371 friend class QWindowPrivate;
372
373 static QGuiApplicationPrivate *self;
374 static int m_fakeMouseSourcePointId;
375#ifdef Q_OS_WIN
376 std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
377#endif
378 std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
379
380 static QInputDeviceManager *m_inputDeviceManager;
381
382 // Cache the maximum device pixel ratio, to iterate through the screen list
383 // only the first time it's required, or when devices are added or removed.
384 static qreal m_maxDevicePixelRatio;
385};
386
387// ----------------- QNativeInterface -----------------
388
389class QWindowsMimeConverter;
390
391namespace QNativeInterface::Private {
392
393#if defined(Q_OS_WIN) || defined(Q_QDOC)
394
395
397{
399
403 };
404
406 NormalTouch = 0x00000000,
407 FineTouch = 0x00000001,
408 WantPalmTouch = 0x00000002
409 };
410
412
415 DarkModeStyle = 0x2
416 };
417
419
422
425
426 virtual void setHasBorderInFullScreenDefault(bool border) = 0;
427
428 virtual bool isTabletMode() const = 0;
429
430 virtual bool isWinTabEnabled() const = 0;
431 virtual bool setWinTabEnabled(bool enabled) = 0;
432
433 virtual DarkModeHandling darkModeHandling() const = 0;
435
436 virtual void registerMime(QWindowsMimeConverter *mime) = 0;
437 virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
438
439 virtual int registerMimeType(const QString &mime) = 0;
440
442 const QString &windowName,
443 QFunctionPointer eventProc = nullptr) const = 0;
444
445 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
446 virtual void setAsyncExpose(bool value) = 0;
447
448 virtual QVariant gpu() const = 0; // internal, used by qtdiag
449 virtual QVariant gpuList() const = 0;
450
451 virtual void populateLightSystemPalette(QPalette &pal) const = 0;
452};
453#endif // Q_OS_WIN
454
455} // QNativeInterface::Private
456
457#if defined(Q_OS_WIN)
458Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
459Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
460#endif
461
462QT_END_NAMESPACE
463
464#endif // QGUIAPPLICATION_P_H
\inmodule QtGui
Combined button and popup list for selecting options.