Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
42
43class QColorTrcLut;
45class QPlatformTheme;
47#if QT_CONFIG(draganddrop)
48class QDrag;
49#endif // QT_CONFIG(draganddrop)
51#ifndef QT_NO_ACTION
52class QActionPrivate;
53#endif
54#if QT_CONFIG(shortcut)
56#endif
57
59{
60 Q_DECLARE_PUBLIC(QGuiApplication)
61public:
62 QGuiApplicationPrivate(int &argc, char **argv);
64
65 void init();
66
67 void createPlatformIntegration();
68 void createEventDispatcher() override;
69 void eventDispatcherReady() override;
70
71 virtual void notifyLayoutDirectionChange();
72 virtual void notifyActiveWindowChange(QWindow *previous);
73
74#if QT_CONFIG(commandlineparser)
75 void addQtOptions(QList<QCommandLineOption> *options) override;
76#endif
77 bool canQuitAutomatically() override;
78 void quit() override;
79
80 void maybeLastWindowClosed();
81 bool lastWindowClosed() const;
83
84 static void captureGlobalModifierState(QEvent *e);
85 static Qt::KeyboardModifiers modifier_buttons;
86 static Qt::MouseButtons mouse_buttons;
87
89
91 { return platform_integration; }
92
94
96 { return platform_theme; }
97
99 {
101 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
102 else
103 return nullptr;
104 }
105
106 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
107 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
108 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
110
111 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
112
113 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
114
115 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
116 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
117
118 static void processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e);
119
120 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
121 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
122 static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e);
123
124 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
125
127
128 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
129
131 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
132 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
133 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
134 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
135 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
136
137 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
138 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
139
140 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
141
142 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
143 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
144 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
145
146#ifndef QT_NO_GESTURES
147 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
148#endif
149
150 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
151#ifndef QT_NO_CONTEXTMENU
152 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
153#endif
154
155#if QT_CONFIG(draganddrop)
156 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
157 const QPoint &p, Qt::DropActions supportedActions,
158 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
159 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
160 const QPoint &p, Qt::DropActions supportedActions,
161 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
162#endif
163
164 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
165
166 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
167
179
180 QPixmap getPixmapCursor(Qt::CursorShape cshape);
181
182 void _q_updateFocusObject(QObject *object);
183
184 static QGuiApplicationPrivate *instance() { return self; }
185
190
192 static void showModalWindow(QWindow *window);
193 static void hideModalWindow(QWindow *window);
194 static void updateBlockedStatus(QWindow *window);
195
196 virtual Qt::WindowModality defaultModality() const;
197 virtual bool windowNeverBlocked(QWindow *window) const;
198 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
199 virtual bool popupActive() { return false; }
200 virtual bool closeAllPopups() { return false; }
201
203 static struct QLastCursorPosition {
204 constexpr inline QLastCursorPosition() noexcept : thePoint(qt_inf(), qt_inf()) {}
205 constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {}
206 constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; }
207 constexpr inline qreal x() const noexcept{ return thePoint.x(); }
208 constexpr inline qreal y() const noexcept{ return thePoint.y(); }
209 Q_GUI_EXPORT QPoint toPoint() const noexcept;
210
211 constexpr void reset() noexcept { *this = QLastCursorPosition{}; }
212
213 // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection
214 // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise
215 // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here
216 // to use single-point precision.
217 friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
218 {
219 return qFuzzyCompare(float(p1.x()), float(p2.x()))
220 && qFuzzyCompare(float(p1.y()), float(p2.y()));
221 }
222 friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
223 {
224 return !(p1 == p2);
225 }
226 friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
227 {
228 return p2 == p1;
229 }
230 friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
231 {
232 return !(p2 == p1);
233 }
234
235 private:
236 QPointF thePoint;
237 } lastCursorPosition;
242 static QPointer<QWindow> currentDragWindow;
243
244 // TODO remove this: QPointingDevice can store what we need directly
246 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
248 Qt::MouseButtons state;
250 };
251 static QList<TabletPointData> tabletDevicePoints;
252 static TabletPointData &tabletDevicePoint(qint64 deviceId);
253
254#ifndef QT_NO_CLIPBOARD
256#endif
257
259
262
263#ifndef QT_NO_CURSOR
264 QList<QCursor> cursor_list;
265#endif
266 static QList<QScreen *> screen_list;
267
269
274
277
278 static QList<QObject *> generic_plugin_list;
279#if QT_CONFIG(shortcut)
280 QShortcutMap shortcutMap;
281#endif
282
283#ifndef QT_NO_SESSIONMANAGER
287 void commitData();
288 void saveState();
289#endif
290
294 : pos(p), screenPos(sp), window(w) { }
297 QPointer<QWindow> window;
298 };
299 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
300
301 static QInputDeviceManager *inputDeviceManager();
302
303 const QColorTrcLut *colorProfileForA8Text();
304 const QColorTrcLut *colorProfileForA32Text();
305
306 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
307 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
308
309 virtual void notifyWindowIconChanged();
310
311 static void applyWindowGeometrySpecificationTo(QWindow *window);
312
313 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
314
315 static void resetCachedDevicePixelRatio();
316
317#ifndef QT_NO_ACTION
318 virtual QActionPrivate *createActionPrivate() const;
319#endif
320#ifndef QT_NO_SHORTCUT
321 virtual QShortcutPrivate *createShortcutPrivate() const;
322#endif
323
324 static void updatePalette();
325
326 static QEvent::Type contextMenuEventType();
327
328protected:
329 virtual void handleThemeChanged();
330
331 static bool setPalette(const QPalette &palette);
332 virtual QPalette basePalette() const;
333 virtual void handlePaletteChanged(const char *className = nullptr);
334
335#if QT_CONFIG(draganddrop)
336 virtual void notifyDragStarted(const QDrag *);
337#endif // QT_CONFIG(draganddrop)
338
339private:
340 static void clearPalette();
341
342 friend class QDragManager;
343
344 static QGuiApplicationPrivate *self;
345 static int m_fakeMouseSourcePointId;
346#ifdef Q_OS_WIN
347 std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
348#endif
349 std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
350
351 bool ownGlobalShareContext;
352
353 static QInputDeviceManager *m_inputDeviceManager;
354
355 // Cache the maximum device pixel ratio, to iterate through the screen list
356 // only the first time it's required, or when devices are added or removed.
357 static qreal m_maxDevicePixelRatio;
358};
359
360// ----------------- QNativeInterface -----------------
361
363
365
366#if defined(Q_OS_WIN) || defined(Q_QDOC)
367
368
369struct Q_GUI_EXPORT QWindowsApplication
370{
372
373 enum WindowActivationBehavior {
374 DefaultActivateWindow,
375 AlwaysActivateWindow
376 };
377
378 enum TouchWindowTouchType {
379 NormalTouch = 0x00000000,
380 FineTouch = 0x00000001,
381 WantPalmTouch = 0x00000002
382 };
383
384 Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
385
387 DarkModeWindowFrames = 0x1,
388 DarkModeStyle = 0x2
389 };
390
392
393 virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
394 virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
395
396 virtual WindowActivationBehavior windowActivationBehavior() const = 0;
397 virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
398
399 virtual void setHasBorderInFullScreenDefault(bool border) = 0;
400
401 virtual bool isTabletMode() const = 0;
402
403 virtual bool isWinTabEnabled() const = 0;
404 virtual bool setWinTabEnabled(bool enabled) = 0;
405
406 virtual DarkModeHandling darkModeHandling() const = 0;
407 virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
408
409 virtual void registerMime(QWindowsMimeConverter *mime) = 0;
410 virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
411
412 virtual int registerMimeType(const QString &mime) = 0;
413
414 virtual HWND createMessageWindow(const QString &classNameTemplate,
415 const QString &windowName,
416 QFunctionPointer eventProc = nullptr) const = 0;
417
418 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
419 virtual void setAsyncExpose(bool value) = 0;
420
421 virtual QVariant gpu() const = 0; // internal, used by qtdiag
422 virtual QVariant gpuList() const = 0;
423
424 virtual void populateLightSystemPalette(QPalette &pal) const = 0;
425};
426#endif // Q_OS_WIN
427
428} // QNativeInterface::Private
429
430#if defined(Q_OS_WIN)
431Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
432Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
433#endif
434
436
437#endif // QGUIAPPLICATION_P_H
\inmodule QtCore
Definition qbytearray.h:57
The QClipboard class provides access to the window system clipboard.
Definition qclipboard.h:20
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\inmodule QtGui
Definition qdrag.h:22
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
\reentrant
Definition qfont.h:22
static Qt::ApplicationState applicationState
static QPointer< QWindow > currentDragWindow
QHash< QWindow *, SynthesizedMouseData > synthesizedMousePoints
QSessionManager * session_manager
static QWindow * currentMousePressWindow
static Qt::KeyboardModifiers modifier_buttons
static QPlatformIntegration * platformIntegration()
static QWindowList window_list
static QList< TabletPointData > tabletDevicePoints
QList< QCursor > cursor_list
static QStyleHints * styleHints
static QList< QObject * > generic_plugin_list
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
static QList< QScreen * > screen_list
static QPalette * app_pal
static QAbstractEventDispatcher * qt_qpa_core_dispatcher()
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static QClipboard * qt_clipboard
static void updateFilteredScreenOrientation(QScreen *screen)
static QGuiApplicationPrivate * instance()
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy
static QString * desktopFileName
static Qt::MouseButtons mouse_buttons
static QWindow * currentMouseWindow
static QPlatformTheme * platform_theme
static QString * platform_name
static QWindow * focus_window
static Qt::MouseButton mousePressButton
virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const
static QString * displayName
static QPlatformIntegration * platform_integration
static QPlatformTheme * platformTheme()
\macro qGuiApp
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
The QInputMethod class provides access to the active text input method.
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
Definition qobject.h:103
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
The QPlatformTheme class allows customizing the UI based on themes.
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
The QSessionManager class provides access to the session manager.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
\inmodule QtCore
Definition qvariant.h:65
\inmodule QtGui
Definition qwindow.h:63
The QWindowsMimeConverter class maps open-standard MIME to Window Clipboard formats.
EGLImageKHR int int EGLuint64KHR * modifiers
QPixmap p2
QPixmap p1
[0]
uint alignment
direction
else opt state
[0]
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ AlignRight
Definition qnamespace.h:146
@ AlignHorizontal_Mask
Definition qnamespace.h:151
@ AlignAbsolute
Definition qnamespace.h:150
@ AlignLeft
Definition qnamespace.h:144
MouseButton
Definition qnamespace.h:56
WindowModality
LayoutDirection
@ RightToLeft
CursorShape
ApplicationState
Definition qnamespace.h:262
HighDpiScaleFactorRoundingPolicy
#define Q_IMPLICIT
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
#define QT_DECLARE_NATIVE_INTERFACE(...)
constexpr static Q_DECL_CONST_FUNCTION double qt_inf() noexcept
Definition qnumeric_p.h:83
GLfloat GLfloat GLfloat w
[0]
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLenum target
GLuint GLsizei const GLchar * message
struct _cl_event * event
GLboolean reset
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define sp
QNativeInterface::Private::QWindowsApplication::DarkModeHandlingFlag DarkModeHandlingFlag
QNativeInterface::Private::QWindowsApplication::DarkModeHandling DarkModeHandling
QScreen * screen
[1]
Definition main.cpp:29
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
ptrdiff_t qintptr
Definition qtypes.h:166
const char className[16]
[1]
Definition qwizard.cpp:100
application x qt windows mime
[2]
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]
void processTouchEvent()
[toString-overload]
friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
constexpr Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept
SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)