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