Qt 6.x
The Qt SDK
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 <memory>
38
40
41class QColorTrcLut;
43class QPlatformTheme;
45#if QT_CONFIG(draganddrop)
46class QDrag;
47#endif // QT_CONFIG(draganddrop)
49#ifndef QT_NO_ACTION
50class QActionPrivate;
51#endif
52#if QT_CONFIG(shortcut)
54#endif
55
57{
58 Q_DECLARE_PUBLIC(QGuiApplication)
59public:
60 QGuiApplicationPrivate(int &argc, char **argv);
62
63 void init();
64
65 void createPlatformIntegration();
66 void createEventDispatcher() override;
67 void eventDispatcherReady() override;
68
69 virtual void notifyLayoutDirectionChange();
70 virtual void notifyActiveWindowChange(QWindow *previous);
71
72#if QT_CONFIG(commandlineparser)
73 void addQtOptions(QList<QCommandLineOption> *options) override;
74#endif
75 bool canQuitAutomatically() override;
76 void quit() override;
77
78 void maybeLastWindowClosed();
79 bool lastWindowClosed() const;
81
82 static void captureGlobalModifierState(QEvent *e);
83 static Qt::KeyboardModifiers modifier_buttons;
84 static Qt::MouseButtons mouse_buttons;
85
87
89 { return platform_integration; }
90
92
94 { return platform_theme; }
95
97 {
99 return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
100 else
101 return nullptr;
102 }
103
104 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
105 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
106 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
108
109 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
110
111 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
112
113 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
114 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
115
116 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
117 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
118 static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
119 static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e);
120
121 static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
122
124
125 static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
126
128 static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
129 static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
130 static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
131 static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
132 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
133
134 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
135 static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
136
137 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
138
139 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
140 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
141 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
142
143#ifndef QT_NO_GESTURES
144 static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
145#endif
146
147 static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
148#ifndef QT_NO_CONTEXTMENU
149 static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e);
150#endif
151
152#if QT_CONFIG(draganddrop)
153 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData,
154 const QPoint &p, Qt::DropActions supportedActions,
155 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
156 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData,
157 const QPoint &p, Qt::DropActions supportedActions,
158 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
159#endif
160
161 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
162
163 static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
164
165 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
166 {
173 }
174 return alignment;
175 }
176
177 QPixmap getPixmapCursor(Qt::CursorShape cshape);
178
179 void _q_updateFocusObject(QObject *object);
180
181 static QGuiApplicationPrivate *instance() { return self; }
182
187
189 static void showModalWindow(QWindow *window);
190 static void hideModalWindow(QWindow *window);
191 static void updateBlockedStatus(QWindow *window);
192
193 virtual Qt::WindowModality defaultModality() const;
194 virtual bool windowNeverBlocked(QWindow *window) const;
195 bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
196 virtual bool popupActive() { return false; }
197 virtual bool closeAllPopups() { return false; }
198
200 static struct QLastCursorPosition {
201 constexpr inline QLastCursorPosition() noexcept : thePoint(qt_inf(), qt_inf()) {}
202 constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {}
203 constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; }
204 constexpr inline qreal x() const noexcept{ return thePoint.x(); }
205 constexpr inline qreal y() const noexcept{ return thePoint.y(); }
206 Q_GUI_EXPORT QPoint toPoint() const noexcept;
207
208 constexpr void reset() noexcept { *this = QLastCursorPosition{}; }
209
210 // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection
211 // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise
212 // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here
213 // to use single-point precision.
214 friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
215 {
216 return qFuzzyCompare(float(p1.x()), float(p2.x()))
217 && qFuzzyCompare(float(p1.y()), float(p2.y()));
218 }
219 friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
220 {
221 return !(p1 == p2);
222 }
223 friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
224 {
225 return p2 == p1;
226 }
227 friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
228 {
229 return !(p2 == p1);
230 }
231
232 private:
233 QPointF thePoint;
234 } lastCursorPosition;
240
241 // TODO remove this: QPointingDevice can store what we need directly
243 TabletPointData(qint64 devId = 0) : deviceId(devId), state(Qt::NoButton), target(nullptr) {}
245 Qt::MouseButtons state;
247 };
249 static TabletPointData &tabletDevicePoint(qint64 deviceId);
250
251#ifndef QT_NO_CLIPBOARD
253#endif
254
256
259
260#ifndef QT_NO_CURSOR
262#endif
264
266
271
274
276#if QT_CONFIG(shortcut)
277 QShortcutMap shortcutMap;
278#endif
279
280#ifndef QT_NO_SESSIONMANAGER
284 void commitData();
285 void saveState();
286#endif
287
291 : pos(p), screenPos(sp), window(w) { }
295 };
297
298 static QInputDeviceManager *inputDeviceManager();
299
300 const QColorTrcLut *colorProfileForA8Text();
301 const QColorTrcLut *colorProfileForA32Text();
302
303 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
304 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
305
306 virtual void notifyWindowIconChanged();
307
308 static void applyWindowGeometrySpecificationTo(QWindow *window);
309
310 static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
311
312 static void resetCachedDevicePixelRatio();
313
314#ifndef QT_NO_ACTION
315 virtual QActionPrivate *createActionPrivate() const;
316#endif
317#ifndef QT_NO_SHORTCUT
318 virtual QShortcutPrivate *createShortcutPrivate() const;
319#endif
320
321 static void updatePalette();
322
323 static Qt::ColorScheme colorScheme();
324
325protected:
326 virtual void handleThemeChanged();
327
328 static bool setPalette(const QPalette &palette);
329 virtual QPalette basePalette() const;
330 virtual void handlePaletteChanged(const char *className = nullptr);
331
332#if QT_CONFIG(draganddrop)
333 virtual void notifyDragStarted(const QDrag *);
334#endif // QT_CONFIG(draganddrop)
335
336private:
337 static void clearPalette();
338
339 friend class QDragManager;
340
341 static QGuiApplicationPrivate *self;
342 static int m_fakeMouseSourcePointId;
343#ifdef Q_OS_WIN
344 std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
345#endif
346 std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
347
348 bool ownGlobalShareContext;
349
350 static QInputDeviceManager *m_inputDeviceManager;
351
352 // Cache the maximum device pixel ratio, to iterate through the screen list
353 // only the first time it's required, or when devices are added or removed.
354 static qreal m_maxDevicePixelRatio;
355};
356
357// ----------------- QNativeInterface -----------------
358
360
362
363#if defined(Q_OS_WIN) || defined(Q_QDOC)
364
365
366struct Q_GUI_EXPORT QWindowsApplication
367{
369
370 enum WindowActivationBehavior {
371 DefaultActivateWindow,
372 AlwaysActivateWindow
373 };
374
375 enum TouchWindowTouchType {
376 NormalTouch = 0x00000000,
377 FineTouch = 0x00000001,
378 WantPalmTouch = 0x00000002
379 };
380
381 Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
382
384 DarkModeWindowFrames = 0x1,
385 DarkModeStyle = 0x2
386 };
387
389
390 virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
391 virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
392
393 virtual WindowActivationBehavior windowActivationBehavior() const = 0;
394 virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
395
396 virtual void setHasBorderInFullScreenDefault(bool border) = 0;
397
398 virtual bool isTabletMode() const = 0;
399
400 virtual bool isWinTabEnabled() const = 0;
401 virtual bool setWinTabEnabled(bool enabled) = 0;
402
403 virtual bool isDarkMode() const = 0;
404
405 virtual DarkModeHandling darkModeHandling() const = 0;
406 virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
407
408 virtual void registerMime(QWindowsMimeConverter *mime) = 0;
409 virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
410
411 virtual int registerMimeType(const QString &mime) = 0;
412
413 virtual HWND createMessageWindow(const QString &classNameTemplate,
414 const QString &windowName,
415 QFunctionPointer eventProc = nullptr) const = 0;
416
417 virtual bool asyncExpose() const = 0; // internal, used by Active Qt
418 virtual void setAsyncExpose(bool value) = 0;
419
420 virtual QVariant gpu() const = 0; // internal, used by qtdiag
421 virtual QVariant gpuList() const = 0;
422
423 virtual void populateLightSystemPalette(QPalette &pal) const = 0;
424};
425#endif // Q_OS_WIN
426
427} // QNativeInterface::Private
428
429#if defined(Q_OS_WIN)
430Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
431Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
432#endif
433
435
436#endif // QGUIAPPLICATION_P_H
\inmodule QtCore
Definition qbytearray.h:57
The QClipboard class provides access to the window system clipboard.
Definition qclipboard.h:20
virtual void eventDispatcherReady()
virtual void createEventDispatcher()
static QAbstractEventDispatcher * eventDispatcher()
Returns a pointer to the event dispatcher object for the main thread.
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:20
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
\inmodule QtCore
Definition qhash.h:818
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.
Definition qlist.h:74
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
Definition qobject.h:90
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:214
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore
Definition qpointer.h:18
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:127
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
\inmodule QtCore
Definition qvariant.h:64
\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]
double e
uint alignment
direction
else opt state
[0]
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:49
@ AlignRight
Definition qnamespace.h:145
@ AlignHorizontal_Mask
Definition qnamespace.h:150
@ AlignAbsolute
Definition qnamespace.h:149
@ AlignLeft
Definition qnamespace.h:143
MouseButton
Definition qnamespace.h:55
WindowModality
LayoutDirection
@ RightToLeft
CursorShape
ApplicationState
Definition qnamespace.h:261
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:287
bool isDarkMode()
#define QT_DECLARE_NATIVE_INTERFACE(...)
constexpr static Q_DECL_CONST_FUNCTION double qt_inf() noexcept
Definition qnumeric_p.h:77
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:55
double qreal
Definition qtypes.h:92
ptrdiff_t qintptr
Definition qtypes.h:71
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)