/src/qtbase/src/gui/kernel/qguiapplication_p.h
Line | Count | Source |
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 | | |
43 | | QT_BEGIN_NAMESPACE |
44 | | |
45 | | Q_DECLARE_LOGGING_CATEGORY(lcPopup) |
46 | | Q_DECLARE_LOGGING_CATEGORY(lcVirtualKeyboard) |
47 | | |
48 | | class QColorTrcLut; |
49 | | class QPlatformIntegration; |
50 | | class QPlatformTheme; |
51 | | class QPlatformDragQtResponse; |
52 | | #if QT_CONFIG(draganddrop) |
53 | | class QDrag; |
54 | | #endif // QT_CONFIG(draganddrop) |
55 | | class QInputDeviceManager; |
56 | | #ifndef QT_NO_ACTION |
57 | | class QActionPrivate; |
58 | | #endif |
59 | | #if QT_CONFIG(shortcut) |
60 | | class QShortcutPrivate; |
61 | | #endif |
62 | | class QThreadPool; |
63 | | |
64 | | class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate |
65 | | { |
66 | 0 | Q_DECLARE_PUBLIC(QGuiApplication) |
67 | 0 | public: |
68 | 0 | QGuiApplicationPrivate(int &argc, char **argv); |
69 | 0 | ~QGuiApplicationPrivate(); |
70 | 0 |
|
71 | 0 | void init(); |
72 | 0 |
|
73 | 0 | void createPlatformIntegration(); |
74 | 0 | void createEventDispatcher() override; |
75 | 0 | void eventDispatcherReady() override; |
76 | 0 |
|
77 | 0 | virtual void notifyLayoutDirectionChange(); |
78 | 0 | virtual void notifyActiveWindowChange(QWindow *previous); |
79 | 0 |
|
80 | 0 | #if QT_CONFIG(commandlineparser) |
81 | 0 | void addQtOptions(QList<QCommandLineOption> *options) override; |
82 | 0 | #endif |
83 | 0 | bool canQuitAutomatically() override; |
84 | 0 | void quit() override; |
85 | 0 |
|
86 | 0 | void maybeLastWindowClosed(); |
87 | 0 | bool lastWindowClosed() const; |
88 | 0 | static bool quitOnLastWindowClosed; |
89 | 0 |
|
90 | 0 | static void captureGlobalModifierState(QEvent *e); |
91 | 0 | static Qt::KeyboardModifiers modifier_buttons; |
92 | 0 | static Qt::MouseButtons mouse_buttons; |
93 | 0 |
|
94 | 0 | static QPlatformIntegration *platform_integration; |
95 | 0 |
|
96 | 0 | static QPlatformIntegration *platformIntegration() |
97 | 1.18M | { return platform_integration; } |
98 | | |
99 | | static QPlatformTheme *platform_theme; |
100 | | |
101 | | static QPlatformTheme *platformTheme() |
102 | 1.43M | { return platform_theme; } |
103 | | |
104 | | static QAbstractEventDispatcher *qt_qpa_core_dispatcher() |
105 | 0 | { |
106 | 0 | if (QCoreApplication::instance()) |
107 | 0 | return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed(); |
108 | 0 | else |
109 | 0 | return nullptr; |
110 | 0 | } |
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 | 252k | { |
179 | 252k | if (!(alignment & Qt::AlignHorizontal_Mask)) |
180 | 0 | alignment |= Qt::AlignLeft; |
181 | 252k | if (!(alignment & Qt::AlignAbsolute) && (alignment & (Qt::AlignLeft | Qt::AlignRight))) { |
182 | 252k | if (direction == Qt::RightToLeft) |
183 | 0 | alignment ^= (Qt::AlignLeft | Qt::AlignRight); |
184 | 252k | alignment |= Qt::AlignAbsolute; |
185 | 252k | } |
186 | 252k | return alignment; |
187 | 252k | } |
188 | | |
189 | | QPixmap getPixmapCursor(Qt::CursorShape cshape); |
190 | | |
191 | | void _q_updateFocusObject(QObject *object); |
192 | | |
193 | 14.9M | 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 | 0 | 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 | 198k | constexpr inline QLastCursorPosition() noexcept : thePoint(1 << 23, 1 << 23) {} |
219 | 0 | constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {} |
220 | 0 | constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; } |
221 | 0 | constexpr inline qreal x() const noexcept{ return thePoint.x(); } |
222 | 0 | constexpr inline qreal y() const noexcept{ return thePoint.y(); } |
223 | | Q_GUI_EXPORT QPoint toPoint() const noexcept; |
224 | | |
225 | 198k | 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 | 0 | { |
233 | 0 | return QtPrivate::fuzzyCompare(float(p1.x()), float(p2.x())) |
234 | 0 | && QtPrivate::fuzzyCompare(float(p1.y()), float(p2.y())); |
235 | 0 | } |
236 | | friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept |
237 | 0 | { |
238 | 0 | return !(p1 == p2); |
239 | 0 | } |
240 | | friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept |
241 | 0 | { |
242 | 0 | return p2 == p1; |
243 | 0 | } |
244 | | friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept |
245 | 0 | { |
246 | 0 | return !(p2 == p1); |
247 | 0 | } |
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 | 0 | 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 | 0 | : 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 | 0 | 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 | | |
355 | | protected: |
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 | | |
366 | | private: |
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 | | |
388 | | class QWindowsMimeConverter; |
389 | | |
390 | | namespace QNativeInterface::Private { |
391 | | |
392 | | #if defined(Q_OS_WIN) || defined(Q_QDOC) |
393 | | |
394 | | |
395 | | struct Q_GUI_EXPORT QWindowsApplication |
396 | | { |
397 | | QT_DECLARE_NATIVE_INTERFACE(QWindowsApplication, 1, QGuiApplication) |
398 | | |
399 | | enum WindowActivationBehavior { |
400 | | DefaultActivateWindow, |
401 | | AlwaysActivateWindow |
402 | | }; |
403 | | |
404 | | enum TouchWindowTouchType { |
405 | | NormalTouch = 0x00000000, |
406 | | FineTouch = 0x00000001, |
407 | | WantPalmTouch = 0x00000002 |
408 | | }; |
409 | | |
410 | | Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType) |
411 | | |
412 | | enum DarkModeHandlingFlag { |
413 | | DarkModeWindowFrames = 0x1, |
414 | | DarkModeStyle = 0x2 |
415 | | }; |
416 | | |
417 | | Q_DECLARE_FLAGS(DarkModeHandling, DarkModeHandlingFlag) |
418 | | |
419 | | virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0; |
420 | | virtual TouchWindowTouchTypes touchWindowTouchType() const = 0; |
421 | | |
422 | | virtual WindowActivationBehavior windowActivationBehavior() const = 0; |
423 | | virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0; |
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; |
433 | | virtual void setDarkModeHandling(DarkModeHandling handling) = 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 | | |
440 | | virtual HWND createMessageWindow(const QString &classNameTemplate, |
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) |
457 | | Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes) |
458 | | Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling) |
459 | | #endif |
460 | | |
461 | | QT_END_NAMESPACE |
462 | | |
463 | | #endif // QGUIAPPLICATION_P_H |