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
86 void maybeLastWindowClosed();
87 bool lastWindowClosed() const;
88 static bool quitOnLastWindowClosed;
89
90 static void captureGlobalModifierState(QEvent *e);
91 static Qt::KeyboardModifiers modifier_buttons;
92 static Qt::MouseButtons mouse_buttons;
93
94 static QPlatformIntegration *platform_integration;
95
96 static QPlatformIntegration *platformIntegration()
97 { return platform_integration; }
98
99 static QPlatformTheme *platform_theme;
100
101 static QPlatformTheme *platformTheme()
102 { return platform_theme; }
103
104 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
105 {
106 if (QCoreApplication::instance())
107 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
108 else
109 return nullptr;
110 }
111
112 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
113 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
114 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
115 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
116
117 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
118
119 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
120
121 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
122 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
123
124 static void processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e);
125
126 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
127 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
128 static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e);
129
130 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
131
132 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
133
134 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
135
136 static void updateFilteredScreenOrientation(QScreen *screen);
137 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
138 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
139 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
140 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
141 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
142
143 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
144 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
145
146 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
147
148 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
149 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
150 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
151
152#ifndef QT_NO_GESTURES
153 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
154#endif
155
156 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
157#ifndef QT_NO_CONTEXTMENU
158 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
159#endif
160
161#if QT_CONFIG(draganddrop)
162 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
163 const QPoint &p, Qt::DropActions supportedActions,
164 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
165 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
166 const QPoint &p, Qt::DropActions supportedActions,
167 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
168#endif
169
170 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
171
172 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
173
174 static bool maybeForwardEventToVirtualKeyboard(QEvent *e);
175 static bool isUsingVirtualKeyboard();
176
177 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
178 {
179 if (!(alignment & Qt::AlignHorizontal_Mask))
180 alignment |= Qt::AlignLeft;
181 if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
182 if (direction == Qt::RightToLeft)
183 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
184 alignment |= Qt::AlignAbsolute;
185 }
186 return alignment;
187 }
188
189 QPixmap getPixmapCursor(Qt::CursorShape cshape);
190
191 void _q_updateFocusObject(QObject *object);
192
193 static QGuiApplicationPrivate *instance() { QT_IGNORE_DEPRECATIONS(return self;) }
194
195 static QIcon *app_icon;
196 static QString *platform_name;
197 static QString *displayName;
198 static QString *desktopFileName;
199
200 QWindowList modalWindowList;
201 static void showModalWindow(QWindow *window);
202 static void hideModalWindow(QWindow *window);
203 static void updateBlockedStatus(QWindow *window);
204
205 virtual Qt::WindowModality defaultModality() const;
206 virtual bool windowNeverBlocked(QWindow *window) const;
207 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
208 static qsizetype popupCount() { return QGuiApplicationPrivate::popup_list.size(); }
209 static QWindow *activePopupWindow();
210 static void activatePopup(QWindow *popup);
211 static bool closePopup(QWindow *popup);
212 static bool closeAllPopups();
213
214 static Qt::MouseButton mousePressButton;
215 static struct QLastCursorPosition {
216 // Initialize to a far-offscreen position. 2^23 is small enough for accurate arithmetic
217 // (even manhattanLength()) even when stored in the mantissa of a 32-bit float.
218 constexpr inline QLastCursorPosition() noexcept : thePoint(1 << 23, 1 << 23) {}
219 constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {}
220 constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; }
221 constexpr inline qreal x() const noexcept{ return thePoint.x(); }
222 constexpr inline qreal y() const noexcept{ return thePoint.y(); }
223 Q_GUI_EXPORT QPoint toPoint() const noexcept;
224
225 constexpr void reset() noexcept { *this = QLastCursorPosition{}; }
226
227 // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection
228 // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise
229 // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here
230 // to use single-point precision.
231 friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
232 {
233 return QtPrivate::fuzzyCompare(float(p1.x()), float(p2.x()))
234 && QtPrivate::fuzzyCompare(float(p1.y()), float(p2.y()));
235 }
236 friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
237 {
238 return !(p1 == p2);
239 }
240 friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
241 {
242 return p2 == p1;
243 }
244 friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
245 {
246 return !(p2 == p1);
247 }
248
249 private:
250 QPointF thePoint;
251 } lastCursorPosition;
252 static QWindow *currentMouseWindow;
253 static QWindow *currentMousePressWindow;
254 static Qt::ApplicationState applicationState;
255 static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
256 static QPointer<QWindow> currentDragWindow;
257
258 // TODO remove this: QPointingDevice can store what we need directly
259 struct TabletPointData {
260 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
261 qint64 deviceId;
262 Qt::MouseButtons state;
263 QWindow *target;
264 };
265 static QList<TabletPointData> tabletDevicePoints;
266 static TabletPointData &tabletDevicePoint(qint64 deviceId);
267
268#ifndef QT_NO_CLIPBOARD
269 static QClipboard *qt_clipboard;
270#endif
271
272 static QPalette *app_pal;
273
274 static QWindowList window_list;
275 static QWindowList popup_list;
276 static const QWindow *active_popup_on_press;
277 static QWindow *focus_window;
278
279#ifndef QT_NO_CURSOR
280 QList<QCursor> cursor_list;
281#endif
282 static QList<QScreen *> screen_list;
283
284 static QFont *app_font;
285
286 static QString styleOverride;
287 static QStyleHints *styleHints;
288 static bool obey_desktop_settings;
289 static bool popup_closed_on_press;
290 QInputMethod *inputMethod;
291
292 QString firstWindowTitle;
293 QIcon forcedWindowIcon;
294
295 static QList<QObject *> generic_plugin_list;
296#if QT_CONFIG(shortcut)
297 QShortcutMap shortcutMap;
298#endif
299
300#ifndef QT_NO_SESSIONMANAGER
301 QSessionManager *session_manager;
302 bool is_session_restored;
303 bool is_saving_session;
304 void commitData();
305 void saveState();
306#endif
307
308 QEvent::Type lastTouchType;
309 struct SynthesizedMouseData {
310 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
311 : pos(p), screenPos(sp), window(w) { }
312 QPointF pos;
313 QPointF screenPos;
314 QPointer<QWindow> window;
315 };
316 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
317
318 static QInputDeviceManager *inputDeviceManager();
319
320 const QColorTrcLut *colorProfileForA8Text();
321 const QColorTrcLut *colorProfileForA32Text();
322
323 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
324 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
325
326 virtual void notifyWindowIconChanged();
327
328 static void applyWindowGeometrySpecificationTo(QWindow *window);
329
330 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
331
332 static void resetCachedDevicePixelRatio();
333
334#ifndef QT_NO_ACTION
335 virtual QActionPrivate *createActionPrivate() const;
336#endif
337#ifndef QT_NO_SHORTCUT
338 virtual QShortcutPrivate *createShortcutPrivate() const;
339#endif
340
341 static void updatePalette();
342
343 static QEvent::Type contextMenuEventType();
344
345 static QThreadPool *qtGuiThreadPool();
346
347#ifndef QT_NO_OPENGL
348 bool ownGlobalShareContext = false;
349#endif
350
351 void _q_updatePrimaryScreenDpis();
352 static QBasicAtomicInt m_primaryScreenDpis;
353
354protected:
355 virtual void handleThemeChanged();
356
357 static bool setPalette(const QPalette &palette);
358 virtual QPalette basePalette() const;
359 virtual void handlePaletteChanged(const char *className = nullptr);
360
361#if QT_CONFIG(draganddrop)
362 virtual void notifyDragStarted(const QDrag *);
363#endif // QT_CONFIG(draganddrop)
364
365private:
366 static void clearPalette();
367
368 friend class QDragManager;
369 friend class QWindowPrivate;
370
371 static QGuiApplicationPrivate *self;
372 static int m_fakeMouseSourcePointId;
373#ifdef Q_OS_WIN
374 std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
375#endif
376 std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
377
378 static QInputDeviceManager *m_inputDeviceManager;
379
380 // Cache the maximum device pixel ratio, to iterate through the screen list
381 // only the first time it's required, or when devices are added or removed.
382 static qreal m_maxDevicePixelRatio;
383};
384
385// ----------------- QNativeInterface -----------------
386
387class QWindowsMimeConverter;
388
389namespace QNativeInterface::Private {
390
391#if defined(Q_OS_WIN) || defined(Q_QDOC)
392
393
395{
397
401 };
402
404 NormalTouch = 0x00000000,
405 FineTouch = 0x00000001,
406 WantPalmTouch = 0x00000002
407 };
408
410
413 DarkModeStyle = 0x2
414 };
415
417
420
423
424 virtual void setHasBorderInFullScreenDefault(bool border) = 0;
425
426 virtual bool isTabletMode() const = 0;
427
428 virtual bool isWinTabEnabled() const = 0;
429 virtual bool setWinTabEnabled(bool enabled) = 0;
430
431 virtual DarkModeHandling darkModeHandling() const = 0;
433
434 virtual void registerMime(QWindowsMimeConverter *mime) = 0;
435 virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
436
437 virtual int registerMimeType(const QString &mime) = 0;
438
440 const QString &windowName,
441 QFunctionPointer eventProc = nullptr) const = 0;
442
443 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
444 virtual void setAsyncExpose(bool value) = 0;
445
446 virtual QVariant gpu() const = 0; // internal, used by qtdiag
447 virtual QVariant gpuList() const = 0;
448
449 virtual void populateLightSystemPalette(QPalette &pal) const = 0;
450};
451#endif // Q_OS_WIN
452
453} // QNativeInterface::Private
454
455#if defined(Q_OS_WIN)
456Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
457Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
458#endif
459
460QT_END_NAMESPACE
461
462#endif // QGUIAPPLICATION_P_H
\inmodule QtGui
Combined button and popup list for selecting options.