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 qint64 badgeNumber = 0;
295
296 static QList<QObject *> generic_plugin_list;
297#if QT_CONFIG(shortcut)
298 QShortcutMap shortcutMap;
299#endif
300
301#ifndef QT_NO_SESSIONMANAGER
302 QSessionManager *session_manager;
303 bool is_session_restored;
304 bool is_saving_session;
305 void commitData();
306 void saveState();
307#endif
308
309 QEvent::Type lastTouchType;
310 struct SynthesizedMouseData {
311 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
312 : pos(p), screenPos(sp), window(w) { }
313 QPointF pos;
314 QPointF screenPos;
315 QPointer<QWindow> window;
316 };
317 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
318
319 static QInputDeviceManager *inputDeviceManager();
320
321 const QColorTrcLut *colorProfileForA8Text();
322 const QColorTrcLut *colorProfileForA32Text();
323
324 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
325 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
326
327 virtual void notifyWindowIconChanged();
328
329 static void applyWindowGeometrySpecificationTo(QWindow *window);
330
331 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
332
333 static void resetCachedDevicePixelRatio();
334
335#ifndef QT_NO_ACTION
336 virtual QActionPrivate *createActionPrivate() const;
337#endif
338#ifndef QT_NO_SHORTCUT
339 virtual QShortcutPrivate *createShortcutPrivate() const;
340#endif
341
342 static void updatePalette();
343
344 static QEvent::Type contextMenuEventType();
345
346 static QThreadPool *qtGuiThreadPool();
347
348#ifndef QT_NO_OPENGL
349 bool ownGlobalShareContext = false;
350#endif
351
352 void _q_updatePrimaryScreenDpis();
353 static QBasicAtomicInt m_primaryScreenDpis;
354
355protected:
356 virtual void handleThemeChanged();
357
358 static bool setPalette(const QPalette &palette);
359 virtual QPalette basePalette() const;
360 virtual void handlePaletteChanged(const char *className = nullptr);
361
362#if QT_CONFIG(draganddrop)
363 virtual void notifyDragStarted(const QDrag *);
364#endif // QT_CONFIG(draganddrop)
365
366private:
367 static void clearPalette();
368
369 friend class QDragManager;
370 friend class QWindowPrivate;
371
372 static QGuiApplicationPrivate *self;
373 static int m_fakeMouseSourcePointId;
374#ifdef Q_OS_WIN
375 std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
376#endif
377 std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
378
379 static QInputDeviceManager *m_inputDeviceManager;
380
381 // Cache the maximum device pixel ratio, to iterate through the screen list
382 // only the first time it's required, or when devices are added or removed.
383 static qreal m_maxDevicePixelRatio;
384};
385
386// ----------------- QNativeInterface -----------------
387
388class QWindowsMimeConverter;
389
390namespace QNativeInterface::Private {
391
392#if defined(Q_OS_WIN) || defined(Q_QDOC)
393
394
396{
398
402 };
403
405 NormalTouch = 0x00000000,
406 FineTouch = 0x00000001,
407 WantPalmTouch = 0x00000002
408 };
409
411
414 DarkModeStyle = 0x2
415 };
416
418
421
424
425 virtual void setHasBorderInFullScreenDefault(bool border) = 0;
426
427 virtual bool isTabletMode() const = 0;
428
429 virtual bool isWinTabEnabled() const = 0;
430 virtual bool setWinTabEnabled(bool enabled) = 0;
431
432 virtual DarkModeHandling darkModeHandling() const = 0;
434
435 virtual void registerMime(QWindowsMimeConverter *mime) = 0;
436 virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
437
438 virtual int registerMimeType(const QString &mime) = 0;
439
441 const QString &windowName,
442 QFunctionPointer eventProc = nullptr) const = 0;
443
444 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
445 virtual void setAsyncExpose(bool value) = 0;
446
447 virtual QVariant gpu() const = 0; // internal, used by qtdiag
448 virtual QVariant gpuList() const = 0;
449
450 virtual void populateLightSystemPalette(QPalette &pal) const = 0;
451};
452#endif // Q_OS_WIN
453
454} // QNativeInterface::Private
455
456#if defined(Q_OS_WIN)
457Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
458Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
459#endif
460
461QT_END_NAMESPACE
462
463#endif // QGUIAPPLICATION_P_H
\inmodule QtGui
Combined button and popup list for selecting options.