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.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qguiapplication.h"
6
7#include "private/qguiapplication_p.h"
8#include "private/qabstractfileiconprovider_p.h"
9#include <qpa/qplatformintegrationfactory_p.h>
10#include "private/qevent_p.h"
11#include "private/qeventpoint_p.h"
12#include "private/qiconloader_p.h"
13#include "qfont.h"
14#include "qpointingdevice.h"
15#include <qpa/qplatformfontdatabase.h>
16#include <qpa/qplatformwindow.h>
17#include <qpa/qplatformnativeinterface.h>
18#include <qpa/qplatformtheme.h>
19#include <qpa/qplatformintegration.h>
20#include <qpa/qplatformkeymapper.h>
21
22#include <QtCore/QAbstractEventDispatcher>
23#include <QtCore/QFileInfo>
24#include <QtCore/QStandardPaths>
25#include <QtCore/QVariant>
26#include <QtCore/private/qcoreapplication_p.h>
27#include <QtCore/private/qabstracteventdispatcher_p.h>
28#include <QtCore/private/qminimalflatset_p.h>
29#include <QtCore/qmutex.h>
30#include <QtCore/private/qthread_p.h>
31#include <QtCore/private/qlocking_p.h>
32#include <QtCore/private/qflatmap_p.h>
33#include <QtCore/qdir.h>
34#include <QtCore/qlibraryinfo.h>
35#include <QtCore/private/qnumeric_p.h>
36#include <QtDebug>
37#if QT_CONFIG(accessibility)
38#include "qaccessible.h"
39#endif
40#include <qpalette.h>
41#include <qscreen.h>
42#include "qsessionmanager.h"
43#include <private/qcolortrclut_p.h>
44#include <private/qscreen_p.h>
45
46#include <QtGui/qgenericpluginfactory.h>
47#include <QtGui/qstylehints.h>
48#include <QtGui/private/qstylehints_p.h>
49#include <QtGui/qinputmethod.h>
50#include <QtGui/qpixmapcache.h>
51#include <qpa/qplatforminputcontext.h>
52#include <qpa/qplatforminputcontext_p.h>
53
54#include <qpa/qwindowsysteminterface.h>
55#include <qpa/qwindowsysteminterface_p.h>
56#include "private/qwindow_p.h"
57#include "private/qicon_p.h"
58#include "private/qcursor_p.h"
59#if QT_CONFIG(opengl)
60# include "private/qopenglcontext_p.h"
61#endif
62#include "private/qinputdevicemanager_p.h"
63#include "private/qinputmethod_p.h"
64#include "private/qpointingdevice_p.h"
65
66#include <qpa/qplatformthemefactory_p.h>
67
68#if QT_CONFIG(draganddrop)
69#include <qpa/qplatformdrag.h>
70#include <private/qdnd_p.h>
71#endif
72
73#ifndef QT_NO_CURSOR
74#include <qpa/qplatformcursor.h>
75#endif
76
77#include <QtGui/QPixmap>
78
79#ifndef QT_NO_CLIPBOARD
80#include <QtGui/QClipboard>
81#endif
82
83#if QT_CONFIG(library)
84#include <QtCore/QLibrary>
85#endif
86
87#if defined(Q_OS_MAC)
88# include "private/qcore_mac_p.h"
89#elif defined(Q_OS_WIN)
90# include <QtCore/qt_windows.h>
91# include <QtCore/QLibraryInfo>
92#endif // Q_OS_WIN
93
94#ifdef Q_OS_WASM
95#include <emscripten.h>
96#endif
97
98#if QT_CONFIG(vulkan)
99#include <private/qvulkandefaultinstance_p.h>
100#endif
101
102#include <qtgui_tracepoints_p.h>
103
104#include <private/qtools_p.h>
105
106#include <limits>
107
109
110using namespace Qt::StringLiterals;
111using namespace QtMiscUtils;
112
113// Helper macro for static functions to check on the existence of the application class.
114#define CHECK_QAPP_INSTANCE(...) \
115 if (Q_LIKELY(QCoreApplication::instance())) { \
116 } else { \
117 qWarning("Must construct a QGuiApplication first."); \
118 return __VA_ARGS__; \
119 }
120
121Q_CORE_EXPORT void qt_call_post_routines();
122Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app = false;
123
124Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
125Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
126
128
130
132
134
137
138Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
139
140Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints; // TODO remove
141
144
145Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
146
151
152Q_CONSTINIT static unsigned applicationResourceFlags = 0;
153
154Q_CONSTINIT QIcon *QGuiApplicationPrivate::app_icon = nullptr;
155
157Q_CONSTINIT QString *QGuiApplicationPrivate::displayName = nullptr;
159
160Q_CONSTINIT QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
161
163
164Q_CONSTINIT static int mouseDoubleClickDistance = 0;
165Q_CONSTINIT static int touchDoubleTapDistance = 0;
166
168
171Q_CONSTINIT static bool force_reverse = false;
172
173Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
174Q_CONSTINIT int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
175
176#ifndef QT_NO_CLIPBOARD
178#endif
179
180Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
181
183Q_CONSTINIT QWindow *QGuiApplicationPrivate::focus_window = nullptr;
184
186Q_CONSTINIT QFont *QGuiApplicationPrivate::app_font = nullptr;
189
190Q_CONSTINIT QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
191
192Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
193
194Q_CONSTINIT static qreal fontSmoothingGamma = 1.7;
195
197
198extern void qRegisterGuiVariant();
199#if QT_CONFIG(animation)
200extern void qRegisterGuiGetInterpolator();
201#endif
202
204{
205 return force_reverse ^
206 (QGuiApplication::tr("QT_LAYOUT_DIRECTION",
207 "Translate this string to the string 'LTR' in left-to-right"
208 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
209 " and Arabic) to get proper widget layout.") == "RTL"_L1);
210}
211
223
224static inline void clearFontUnlocked()
225{
228}
229
235
237{
238#if QT_CONFIG(dbus)
239 return QFileInfo::exists("/.flatpak-info"_L1) || qEnvironmentVariableIsSet("SNAP");
240#else
241 return false;
242#endif // QT_CONFIG(dbus)
243}
244
245// Using aggregate initialization instead of ctor so we can have a POD global static
246#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1, -1, -1, -1 }
247
248// Geometry specification for top level windows following the convention of the
249// -geometry command line arguments in X11 (see XParseGeometry).
261
262// Parse a token of a X11 geometry specification "200x100+10-20".
263static inline int nextGeometryToken(const QByteArray &a, int &pos, char *op)
264{
265 *op = 0;
266 const qsizetype size = a.size();
267 if (pos >= size)
268 return -1;
269
270 *op = a.at(pos);
271 if (*op == '+' || *op == '-' || *op == 'x')
272 pos++;
273 else if (isAsciiDigit(*op))
274 *op = 'x'; // If it starts with a digit, it is supposed to be a width specification.
275 else
276 return -1;
277
278 const int numberPos = pos;
279 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
280
281 bool ok;
282 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
283 return ok ? result : -1;
284}
285
287{
289 int pos = 0;
290 for (int i = 0; i < 4; ++i) {
291 char op;
292 const int value = nextGeometryToken(a, pos, &op);
293 if (value < 0)
294 break;
295 switch (op) {
296 case 'x':
297 (result.width >= 0 ? result.height : result.width) = value;
298 break;
299 case '+':
300 case '-':
301 if (result.xOffset >= 0) {
302 result.yOffset = value;
303 if (op == '-')
305 } else {
306 result.xOffset = value;
307 if (op == '-')
308 result.corner = Qt::TopRightCorner;
309 }
310 }
311 }
312 return result;
313}
314
316{
317 QRect windowGeometry = window->frameGeometry();
318 QSize size = windowGeometry.size();
319 if (width >= 0 || height >= 0) {
320 const QSize windowMinimumSize = window->minimumSize();
321 const QSize windowMaximumSize = window->maximumSize();
322 if (width >= 0)
323 size.setWidth(qBound(windowMinimumSize.width(), width, windowMaximumSize.width()));
324 if (height >= 0)
325 size.setHeight(qBound(windowMinimumSize.height(), height, windowMaximumSize.height()));
326 window->resize(size);
327 }
328 if (xOffset >= 0 || yOffset >= 0) {
329 const QRect availableGeometry = window->screen()->virtualGeometry();
330 QPoint topLeft = windowGeometry.topLeft();
331 if (xOffset >= 0) {
333 xOffset :
334 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
335 }
336 if (yOffset >= 0) {
338 yOffset :
339 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
340 }
341 window->setFramePosition(topLeft);
342 }
343}
344
346
634#ifdef Q_QDOC
635QGuiApplication::QGuiApplication(int &argc, char **argv)
636#else
637QGuiApplication::QGuiApplication(int &argc, char **argv, int)
638#endif
639 : QCoreApplication(*new QGuiApplicationPrivate(argc, argv))
640{
641 d_func()->init();
642
644}
645
653
658{
659 Q_D(QGuiApplication);
660
662
663 d->eventDispatcher->closingDown();
664 d->eventDispatcher = nullptr;
665
666#ifndef QT_NO_CLIPBOARD
669#endif
670
671#ifndef QT_NO_SESSIONMANAGER
672 delete d->session_manager;
673 d->session_manager = nullptr;
674#endif //QT_NO_SESSIONMANAGER
675
676 QGuiApplicationPrivate::clearPalette();
678
679#ifndef QT_NO_CURSOR
680 d->cursor_list.clear();
681#endif
682
689 delete QGuiApplicationPrivate::m_inputDeviceManager;
690 QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
701}
702
704 : QCoreApplicationPrivate(argc, argv),
705 inputMethod(nullptr),
706 lastTouchType(QEvent::TouchEnd),
707 ownGlobalShareContext(false)
708{
709 self = this;
711#ifndef QT_NO_SESSIONMANAGER
712 is_session_restored = false;
713 is_saving_session = false;
714#endif
715}
716
746
748{
750}
751
775
793{
797 if (name.endsWith(QLatin1String(".desktop"))) { // ### Qt 7: remove
799 if (!filePath.isEmpty()) {
800 qWarning("QGuiApplication::setDesktopFileName: the specified desktop file name "
801 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
802 "be removed. Please specify a desktop file name without .desktop suffix");
803 (*QGuiApplicationPrivate::desktopFileName).chop(8);
804 }
805 }
806}
807
809{
811}
812
828{
829 CHECK_QAPP_INSTANCE(nullptr)
830 if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
831 return nullptr;
832 return QGuiApplicationPrivate::self->modalWindowList.constFirst();
833}
834
835static void updateBlockedStatusRecursion(QWindow *window, bool shouldBeBlocked)
836{
838 if (p->blockedByModalWindow != shouldBeBlocked) {
839 p->blockedByModalWindow = shouldBeBlocked;
842 for (QObject *c : window->children()) {
843 if (c->isWindowType())
844 updateBlockedStatusRecursion(static_cast<QWindow *>(c), shouldBeBlocked);
845 }
846 }
847}
848
850{
851 bool shouldBeBlocked = false;
852 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
853 if (!popupType && !self->modalWindowList.isEmpty())
854 shouldBeBlocked = self->isWindowBlocked(window);
855 updateBlockedStatusRecursion(window, shouldBeBlocked);
856}
857
858// Return whether the window needs to be notified about window blocked events.
859// As opposed to QGuiApplication::topLevelWindows(), embedded windows are
860// included in this list (QTBUG-18099).
861static inline bool needsWindowBlockedEvent(const QWindow *w)
862{
863 return w->isTopLevel() && w->type() != Qt::Desktop;
864}
865
867{
868 self->modalWindowList.prepend(modal);
869
870 // Send leave for currently entered window if it should be blocked
872 bool shouldBeBlocked = self->isWindowBlocked(currentMouseWindow);
873 if (shouldBeBlocked) {
874 // Remove the new window from modalWindowList temporarily so leave can go through
875 self->modalWindowList.removeFirst();
878 currentMouseWindow = nullptr;
879 self->modalWindowList.prepend(modal);
880 }
881 }
882
883 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
884 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
886 }
887
888 updateBlockedStatus(modal);
889}
890
892{
893 self->modalWindowList.removeAll(window);
894
895 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
896 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
898 }
899}
900
905
907{
909 return false;
910}
911
912/*
913 Returns \c true if \a window is blocked by a modal window. If \a
914 blockingWindow is non-zero, *blockingWindow will be set to the blocking
915 window (or to zero if \a window is not blocked).
916*/
918{
919 Q_ASSERT_X(window, Q_FUNC_INFO, "The window must not be null");
920
921 QWindow *unused = nullptr;
922 if (!blockingWindow)
923 blockingWindow = &unused;
924 *blockingWindow = nullptr;
925
927 return false;
928
929 for (int i = 0; i < modalWindowList.size(); ++i) {
930 QWindow *modalWindow = modalWindowList.at(i);
931
932 // A window is not blocked by another modal window if the two are
933 // the same, or if the window is a child of the modal window.
934 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
935 return false;
936
937 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
938 : modalWindow->modality()) {
940 *blockingWindow = modalWindow;
941 return true;
942 case Qt::WindowModal: {
943 // Find the nearest ancestor of window which is also an ancestor of modal window to
944 // determine if the modal window blocks the window.
945 auto *current = window;
946 do {
947 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
948 *blockingWindow = modalWindow;
949 return true;
950 }
951 current = current->parent(QWindow::IncludeTransients);
952 } while (current);
953 break;
954 }
955 default:
956 Q_ASSERT_X(false, "QGuiApplication", "internal error, a modal widget cannot be modeless");
957 break;
958 }
959 }
960 return false;
961}
962
973
997{
998 if (focusWindow())
999 return focusWindow()->focusObject();
1000 return nullptr;
1001}
1002
1016
1025{
1028 for (int i = 0; i < list.size(); ++i) {
1029 QWindow *window = list.at(i);
1030 if (!window->isTopLevel())
1031 continue;
1032
1033 // Desktop windows are special, as each individual desktop window
1034 // will report that it's a top level window, but we don't want to
1035 // include them in the application wide list of top level windows.
1036 if (window->type() == Qt::Desktop)
1037 continue;
1038
1039 // Windows embedded in native windows do not have QWindow parents,
1040 // but they are not true top level windows, so do not include them.
1041 if (window->handle() && window->handle()->isEmbedded())
1042 continue;
1043
1044 topLevelWindows.prepend(window);
1045 }
1046
1047 return topLevelWindows;
1048}
1049
1051{
1053 return nullptr;
1055}
1056
1062{
1064}
1065
1078{
1079 QVarLengthArray<const QScreen *, 8> visitedScreens;
1080 for (const QScreen *screen : QGuiApplication::screens()) {
1081 if (visitedScreens.contains(screen))
1082 continue;
1083
1084 // The virtual siblings include the screen itself, so iterate directly
1085 for (QScreen *sibling : screen->virtualSiblings()) {
1086 if (sibling->geometry().contains(point))
1087 return sibling;
1088
1089 visitedScreens.append(sibling);
1090 }
1091 }
1092
1093 return nullptr;
1094}
1095
1140{
1141 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1142 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1143
1144 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0; // make sure we never return 0.
1145 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1146 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1147
1148 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1149}
1150
1152{
1153 m_maxDevicePixelRatio = 0.0;
1154}
1155
1160{
1161 if (QScreen *windowScreen = screenAt(pos)) {
1162 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1163 return windowScreen->handle()->topLevelAt(devicePosition);
1164 }
1165 return nullptr;
1166}
1167
1206{
1208#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1209 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1210#else
1211 return QString();
1212#endif
1213 } else {
1216 }
1217}
1218
1219Q_LOGGING_CATEGORY(lcQpaPluginLoading, "qt.qpa.plugin");
1220Q_LOGGING_CATEGORY(lcQpaTheme, "qt.qpa.theme");
1221Q_LOGGING_CATEGORY(lcPtrDispatch, "qt.pointer.dispatch");
1222
1223static void init_platform(const QString &pluginNamesWithArguments, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv)
1224{
1225 qCDebug(lcQpaPluginLoading) << "init_platform called with"
1226 << "pluginNamesWithArguments" << pluginNamesWithArguments
1227 << "platformPluginPath" << platformPluginPath
1228 << "platformThemeName" << platformThemeName;
1229
1230 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1231 QStringList platformArguments;
1232 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1233 for (const auto &pluginArgument : plugins) {
1234 // Split into platform name and arguments
1235 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1236 if (arguments.isEmpty())
1237 continue;
1238 const QString name = arguments.takeFirst().toLower();
1239 QString argumentsKey = name;
1240 if (name.isEmpty())
1241 continue;
1242 argumentsKey[0] = argumentsKey.at(0).toUpper();
1244
1245 qCDebug(lcQpaPluginLoading) << "Attempting to load Qt platform plugin" << name << "with arguments" << arguments;
1246
1247 // Create the platform integration.
1250 if (availablePlugins.contains(name)) {
1252 qCWarning(lcQpaPluginLoading).nospace().noquote()
1253 << "From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1254 }
1255 qCInfo(lcQpaPluginLoading).nospace().noquote()
1256 << "Could not load the Qt platform plugin \"" << name << "\" in \""
1257 << QDir::toNativeSeparators(platformPluginPath) << "\" even though it was found.";
1258 } else {
1259 qCWarning(lcQpaPluginLoading).nospace().noquote()
1260 << "Could not find the Qt platform plugin \"" << name << "\" in \""
1261 << QDir::toNativeSeparators(platformPluginPath) << "\"";
1262 }
1263 } else {
1264 qCDebug(lcQpaPluginLoading) << "Successfully loaded Qt platform plugin" << name;
1266 platformArguments = arguments;
1267 break;
1268 }
1269 }
1270
1272 QString fatalMessage = QStringLiteral("This application failed to start because no Qt platform plugin could be initialized. "
1273 "Reinstalling the application may fix this problem.\n");
1274
1275 if (!availablePlugins.isEmpty())
1276 fatalMessage += "\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(", "_L1));
1277
1278#if defined(Q_OS_WIN)
1279 // Windows: Display message box unless it is a console application
1280 // or debug build showing an assert box.
1281 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1282 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1283#endif // Q_OS_WIN
1284 qFatal("%s", qPrintable(fatalMessage));
1285
1286 return;
1287 }
1288
1289 // Create the platform theme:
1290
1291 // 1) Fetch the platform name from the environment if present.
1293 if (!platformThemeName.isEmpty()) {
1294 qCDebug(lcQpaTheme) << "Adding" << platformThemeName << "from environment to list of theme names";
1295 themeNames.append(platformThemeName);
1296 }
1297
1298 // 2) Special case - check whether it's a flatpak or snap app to use xdg-desktop-portal platform theme for portals support
1299 if (checkNeedPortalSupport()) {
1300 qCDebug(lcQpaTheme) << "Adding xdgdesktopportal to list of theme names";
1301 themeNames.append(QStringLiteral("xdgdesktopportal"));
1302 }
1303
1304 // 3) Ask the platform integration for a list of theme names
1305 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1306 qCDebug(lcQpaTheme) << "Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1307 themeNames += platformIntegrationThemeNames;
1308 // 4) Look for a theme plugin.
1309 for (const QString &themeName : std::as_const(themeNames)) {
1310 qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via QPlatformThemeFactory::create";
1313 qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
1314 break;
1315 }
1316 }
1317
1318 // 5) If no theme plugin was found ask the platform integration to
1319 // create a theme
1321 for (const QString &themeName : std::as_const(themeNames)) {
1322 qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via createPlatformTheme";
1325 qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
1326 break;
1327 }
1328 }
1329 // No error message; not having a theme plugin is allowed.
1330 }
1331
1332 // 6) Fall back on the built-in "null" platform theme.
1334 qCDebug(lcQpaTheme) << "Failed to create platform theme; using \"null\" platform theme";
1336 }
1337
1338 // Set arguments as dynamic properties on the native interface as
1339 // boolean 'foo' or strings: 'foo=bar'
1340 if (!platformArguments.isEmpty()) {
1341 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1342 for (const QString &argument : std::as_const(platformArguments)) {
1343 const qsizetype equalsPos = argument.indexOf(u'=');
1344 const QByteArray name =
1345 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1346 const QVariant value =
1347 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(true);
1348 nativeInterface->setProperty(name.constData(), value);
1349 }
1350 }
1351 }
1352
1353 const auto platformIntegration = QGuiApplicationPrivate::platformIntegration();
1354 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1356 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1357}
1358
1359static void init_plugins(const QList<QByteArray> &pluginList)
1360{
1361 for (int i = 0; i < pluginList.size(); ++i) {
1362 QByteArray pluginSpec = pluginList.at(i);
1363 qsizetype colonPos = pluginSpec.indexOf(':');
1364 QObject *plugin;
1365 if (colonPos < 0)
1367 else
1368 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1369 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1370 if (plugin)
1372 else
1373 qWarning("No such plugin for spec \"%s\"", pluginSpec.constData());
1374 }
1375}
1376
1377#if QT_CONFIG(commandlineparser)
1378void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1379{
1380 QCoreApplicationPrivate::addQtOptions(options);
1381
1382#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1383 const QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
1384 const bool x11 = sessionType == "x11";
1385 // Technically the x11 aliases are only available if platformName is "xcb", but we can't know that here.
1386#else
1387 const bool x11 = false;
1388#endif
1389
1390 options->append(QCommandLineOption(QStringLiteral("platform"),
1391 QGuiApplication::tr("QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral("platformName[:options]")));
1392 options->append(QCommandLineOption(QStringLiteral("platformpluginpath"),
1393 QGuiApplication::tr("Path to the platform plugins."), QStringLiteral("path")));
1394 options->append(QCommandLineOption(QStringLiteral("platformtheme"),
1395 QGuiApplication::tr("Platform theme."), QStringLiteral("theme")));
1396 options->append(QCommandLineOption(QStringLiteral("plugin"),
1397 QGuiApplication::tr("Additional plugins to load, can be specified multiple times."), QStringLiteral("plugin")));
1398 options->append(QCommandLineOption(QStringLiteral("qwindowgeometry"),
1399 QGuiApplication::tr("Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral("geometry")));
1400 options->append(QCommandLineOption(QStringLiteral("qwindowicon"),
1401 QGuiApplication::tr("Default window icon."), QStringLiteral("icon")));
1402 options->append(QCommandLineOption(QStringLiteral("qwindowtitle"),
1403 QGuiApplication::tr("Title of the first window."), QStringLiteral("title")));
1404 options->append(QCommandLineOption(QStringLiteral("reverse"),
1405 QGuiApplication::tr("Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1406 options->append(QCommandLineOption(QStringLiteral("session"),
1407 QGuiApplication::tr("Restores the application from an earlier session."), QStringLiteral("session")));
1408
1409 if (x11) {
1410 options->append(QCommandLineOption(QStringLiteral("display"),
1411 QGuiApplication::tr("Display name, overrides $DISPLAY."), QStringLiteral("display")));
1412 options->append(QCommandLineOption(QStringLiteral("name"),
1413 QGuiApplication::tr("Instance name according to ICCCM 4.1.2.5."), QStringLiteral("name")));
1414 options->append(QCommandLineOption(QStringLiteral("nograb"),
1415 QGuiApplication::tr("Disable mouse grabbing (useful in debuggers).")));
1416 options->append(QCommandLineOption(QStringLiteral("dograb"),
1417 QGuiApplication::tr("Force mouse grabbing (even when running in a debugger).")));
1418 options->append(QCommandLineOption(QStringLiteral("visual"),
1419 QGuiApplication::tr("ID of the X11 Visual to use."), QStringLiteral("id")));
1420 // Not using the "QStringList names" solution for those aliases, because it makes the first column too wide
1421 options->append(QCommandLineOption(QStringLiteral("geometry"),
1422 QGuiApplication::tr("Alias for --qwindowgeometry."), QStringLiteral("geometry")));
1423 options->append(QCommandLineOption(QStringLiteral("icon"),
1424 QGuiApplication::tr("Alias for --qwindowicon."), QStringLiteral("icon")));
1425 options->append(QCommandLineOption(QStringLiteral("title"),
1426 QGuiApplication::tr("Alias for --qwindowtitle."), QStringLiteral("title")));
1427 }
1428}
1429#endif // QT_CONFIG(commandlineparser)
1430
1432{
1434
1435 // Load the platform integration
1436 QString platformPluginPath = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH"));
1437
1438
1439 QByteArray platformName;
1440#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1441 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1442#endif
1443#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1444 QList<QByteArray> platformArguments = platformName.split(':');
1445 QByteArray platformPluginBase = platformArguments.first();
1446
1447 const bool hasWaylandDisplay = qEnvironmentVariableIsSet("WAYLAND_DISPLAY");
1448 const bool isWaylandSessionType = qgetenv("XDG_SESSION_TYPE") == "wayland";
1449
1450 QVector<QByteArray> preferredPlatformOrder;
1451 const bool defaultIsXcb = platformPluginBase == "xcb";
1452 const QByteArray xcbPlatformName = defaultIsXcb ? platformName : "xcb";
1453 if (qEnvironmentVariableIsSet("DISPLAY")) {
1454 preferredPlatformOrder << xcbPlatformName;
1455 if (defaultIsXcb)
1456 platformName.clear();
1457 }
1458
1459 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith("wayland");
1460 const QByteArray waylandPlatformName = defaultIsWayland ? platformName : "wayland";
1461 if (hasWaylandDisplay || isWaylandSessionType) {
1462 preferredPlatformOrder.prepend(waylandPlatformName);
1463
1464 if (defaultIsWayland)
1465 platformName.clear();
1466 }
1467
1468 if (!platformName.isEmpty())
1469 preferredPlatformOrder.append(platformName);
1470
1471 platformName = preferredPlatformOrder.join(';');
1472#endif
1473
1474 bool platformExplicitlySelected = false;
1475 QByteArray platformNameEnv = qgetenv("QT_QPA_PLATFORM");
1476 if (!platformNameEnv.isEmpty()) {
1477 platformName = platformNameEnv;
1478 platformExplicitlySelected = true;
1479 }
1480
1481 QString platformThemeName = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORMTHEME"));
1482
1483 // Get command line params
1484
1485 QString icon;
1486
1487 int j = argc ? 1 : 0;
1488 for (int i=1; i<argc; i++) {
1489 if (!argv[i])
1490 continue;
1491 if (*argv[i] != '-') {
1492 argv[j++] = argv[i];
1493 continue;
1494 }
1495 const bool xcbIsDefault = platformName.startsWith("xcb");
1496 const char *arg = argv[i];
1497 if (arg[1] == '-') // startsWith("--")
1498 ++arg;
1499 if (strcmp(arg, "-platformpluginpath") == 0) {
1500 if (++i < argc)
1501 platformPluginPath = QFile::decodeName(argv[i]);
1502 } else if (strcmp(arg, "-platform") == 0) {
1503 if (++i < argc) {
1504 platformExplicitlySelected = true;
1505 platformName = argv[i];
1506 }
1507 } else if (strcmp(arg, "-platformtheme") == 0) {
1508 if (++i < argc)
1509 platformThemeName = QString::fromLocal8Bit(argv[i]);
1510 } else if (strcmp(arg, "-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg, "-geometry") == 0)) {
1511 if (++i < argc)
1513 } else if (strcmp(arg, "-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg, "-title") == 0)) {
1514 if (++i < argc)
1516 } else if (strcmp(arg, "-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg, "-icon") == 0)) {
1517 if (++i < argc) {
1519 }
1520 } else {
1521 argv[j++] = argv[i];
1522 }
1523 }
1524
1525 if (j < argc) {
1526 argv[j] = nullptr;
1527 argc = j;
1528 }
1529
1530 Q_UNUSED(platformExplicitlySelected);
1531
1532 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1533 if (const QPlatformTheme *theme = platformTheme())
1534 QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(theme->colorScheme());
1535
1536 if (!icon.isEmpty())
1538}
1539
1547{
1549
1550 if (platform_integration == nullptr)
1552
1553 // The platform integration should not result in creating an event dispatcher
1554 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher, "QGuiApplication",
1555 "Creating the platform integration resulted in creating an event dispatcher");
1556
1557 // Nor should it mess with the QCoreApplication's event dispatcher
1559
1560 eventDispatcher = platform_integration->createEventDispatcher();
1561}
1562
1564{
1565 if (platform_integration == nullptr)
1567
1568 platform_integration->initialize();
1569}
1570
1572{
1573 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1574
1575#if defined(Q_OS_MACOS)
1577#endif
1578
1580
1581 QCoreApplicationPrivate::is_app_running = false; // Starting up.
1582
1583 bool loadTestability = false;
1584 QList<QByteArray> pluginList;
1585 // Get command line params
1586#ifndef QT_NO_SESSIONMANAGER
1587 QString session_id;
1588 QString session_key;
1589# if defined(Q_OS_WIN)
1590 wchar_t guidstr[40];
1591 GUID guid;
1592 CoCreateGuid(&guid);
1593 StringFromGUID2(guid, guidstr, 40);
1594 session_id = QString::fromWCharArray(guidstr);
1595 CoCreateGuid(&guid);
1596 StringFromGUID2(guid, guidstr, 40);
1597 session_key = QString::fromWCharArray(guidstr);
1598# endif
1599#endif
1600 QString s;
1601 int j = argc ? 1 : 0;
1602 for (int i=1; i<argc; i++) {
1603 if (!argv[i])
1604 continue;
1605 if (*argv[i] != '-') {
1606 argv[j++] = argv[i];
1607 continue;
1608 }
1609 const char *arg = argv[i];
1610 if (arg[1] == '-') // startsWith("--")
1611 ++arg;
1612 if (strcmp(arg, "-plugin") == 0) {
1613 if (++i < argc)
1614 pluginList << argv[i];
1615 } else if (strcmp(arg, "-reverse") == 0) {
1616 force_reverse = true;
1617#ifdef Q_OS_MAC
1618 } else if (strncmp(arg, "-psn_", 5) == 0) {
1619 // eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder.
1620 // special hack to change working directory (for an app bundle) when running from finder
1621 if (QDir::currentPath() == "/"_L1) {
1622 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1623 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1624 kCFURLPOSIXPathStyle));
1625 if (qbundlePath.endsWith(".app"_L1))
1626 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1627 }
1628#endif
1629#ifndef QT_NO_SESSIONMANAGER
1630 } else if (strcmp(arg, "-session") == 0 && i < argc - 1) {
1631 ++i;
1632 if (argv[i] && *argv[i]) {
1633 session_id = QString::fromLatin1(argv[i]);
1634 qsizetype p = session_id.indexOf(u'_');
1635 if (p >= 0) {
1636 session_key = session_id.mid(p +1);
1637 session_id = session_id.left(p);
1638 }
1639 is_session_restored = true;
1640 }
1641#endif
1642 } else if (strcmp(arg, "-testability") == 0) {
1643 loadTestability = true;
1644 } else if (strncmp(arg, "-style=", 7) == 0) {
1646 } else if (strcmp(arg, "-style") == 0 && i < argc - 1) {
1648 } else {
1649 argv[j++] = argv[i];
1650 }
1651
1652 if (!s.isEmpty())
1653 styleOverride = s;
1654 }
1655
1656 if (j < argc) {
1657 argv[j] = nullptr;
1658 argc = j;
1659 }
1660
1661 // Load environment exported generic plugins
1662 QByteArray envPlugins = qgetenv("QT_QPA_GENERIC_PLUGINS");
1663 if (!envPlugins.isEmpty())
1664 pluginList += envPlugins.split(',');
1665
1666 if (platform_integration == nullptr)
1668
1669 updatePalette();
1672
1673#ifndef QT_NO_CURSOR
1675#endif
1676
1677 // trigger registering of QVariant's GUI types
1679
1680#if QT_CONFIG(animation)
1681 // trigger registering of animation interpolators
1683#endif
1684
1685 // set a global share context when enabled unless there is already one
1686#ifndef QT_NO_OPENGL
1690 ctx->create();
1692 ownGlobalShareContext = true;
1693 }
1694#endif
1695
1697
1698 is_app_running = true;
1699 init_plugins(pluginList);
1701
1702 Q_Q(QGuiApplication);
1703#ifndef QT_NO_SESSIONMANAGER
1704 // connect to the session manager
1705 session_manager = new QSessionManager(q, session_id, session_key);
1706#endif
1707
1708#if QT_CONFIG(library)
1709 if (qEnvironmentVariableIntValue("QT_LOAD_TESTABILITY") > 0)
1710 loadTestability = true;
1711
1712 if (loadTestability) {
1713 QLibrary testLib(QStringLiteral("qttestability"));
1714 if (Q_UNLIKELY(!testLib.load())) {
1715 qCritical() << "Library qttestability load failed:" << testLib.errorString();
1716 } else {
1717 typedef void (*TasInitialize)(void);
1718 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
1719 if (Q_UNLIKELY(!initFunction)) {
1720 qCritical("Library qttestability resolve failed!");
1721 } else {
1722 initFunction();
1723 }
1724 }
1725 }
1726#else
1727 Q_UNUSED(loadTestability);
1728#endif // QT_CONFIG(library)
1729
1730 // trigger changed signal and event delivery
1732
1736}
1737
1738extern void qt_cleanupFontDatabase();
1739
1741{
1742 is_app_closing = true;
1743 is_app_running = false;
1744
1745 for (int i = 0; i < generic_plugin_list.size(); ++i)
1746 delete generic_plugin_list.at(i);
1747 generic_plugin_list.clear();
1748
1750
1752
1753#ifndef QT_NO_CURSOR
1755#endif
1756
1758
1760
1763 delete inputMethod;
1764
1766
1768
1769#ifndef QT_NO_OPENGL
1770 if (ownGlobalShareContext) {
1773 }
1774#endif
1775
1776#if QT_CONFIG(vulkan)
1777 QVulkanDefaultInstance::cleanup();
1778#endif
1779
1780 platform_integration->destroy();
1781
1782 delete platform_theme;
1783 platform_theme = nullptr;
1784 delete platform_integration;
1785 platform_integration = nullptr;
1786
1787 window_list.clear();
1788 screen_list.clear();
1789
1790 self = nullptr;
1791}
1792
1793#if 0
1794#ifndef QT_NO_CURSOR
1795QCursor *overrideCursor();
1796void setOverrideCursor(const QCursor &);
1797void changeOverrideCursor(const QCursor &);
1798void restoreOverrideCursor();
1799#endif
1800
1801static QFont font();
1802static QFont font(const QWidget*);
1803static QFont font(const char *className);
1804static void setFont(const QFont &, const char *className = nullptr);
1805static QFontMetrics fontMetrics();
1806
1807#ifndef QT_NO_CLIPBOARD
1808static QClipboard *clipboard();
1809#endif
1810#endif
1811
1829
1847{
1848 CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers{})
1850 return pi->keyMapper()->queryKeyboardModifiers();
1851}
1852
1870
1881
1886QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
1887{
1889 if (!pi) {
1890 qWarning("QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1891 return nullptr;
1892 }
1893
1894 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) : nullptr;
1895}
1896
1922{
1923#if QT_CONFIG(accessibility)
1924 QAccessible::setRootObject(qApp);
1925#endif
1926 return QCoreApplication::exec();
1927}
1928
1930{
1931 if (e->spontaneous()) {
1932 // Capture the current mouse and keyboard states. Doing so here is
1933 // required in order to support Qt Test synthesized events. Real mouse
1934 // and keyboard state updates from the platform plugin are managed by
1935 // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
1936 // ### FIXME: Qt Test should not call qapp->notify(), but rather route
1937 // the events through the proper QPA interface. This is required to
1938 // properly generate all other events such as enter/leave etc.
1939 switch (e->type()) {
1941 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1944 break;
1945 }
1947 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1950 break;
1951 }
1953 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1956 break;
1957 }
1958 case QEvent::KeyPress:
1959 case QEvent::KeyRelease:
1960 case QEvent::MouseMove:
1961#if QT_CONFIG(wheelevent)
1962 case QEvent::Wheel:
1963#endif
1964 case QEvent::TouchBegin:
1966 case QEvent::TouchEnd:
1967#if QT_CONFIG(tabletevent)
1968 case QEvent::TabletMove:
1971#endif
1972 {
1973 QInputEvent *ie = static_cast<QInputEvent *>(e);
1975 break;
1976 }
1977 default:
1978 break;
1979 }
1980 }
1981}
1982
1986{
1987 if (object->isWindowType()) {
1989 return true; // Platform plugin ate the event
1990 }
1991
1993
1994 return QCoreApplication::notify(object, event);
1995}
1996
2000{
2001 switch (e->type()) {
2003 // if the layout direction was set explicitly, then don't override it here
2006 for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
2007 if (topLevelWindow->flags() != Qt::Desktop)
2008 postEvent(topLevelWindow, new QEvent(QEvent::LanguageChange));
2009 }
2010 break;
2013 for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
2014 if (topLevelWindow->flags() != Qt::Desktop)
2015 postEvent(topLevelWindow, new QEvent(e->type()));
2016 }
2017 break;
2018 case QEvent::Quit:
2019 // Close open windows. This is done in order to deliver de-expose
2020 // events while the event loop is still running.
2021 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2022 // Already closed windows will not have a platform window, skip those
2023 if (!topLevelWindow->handle())
2024 continue;
2025 if (!topLevelWindow->close()) {
2026 e->ignore();
2027 return true;
2028 }
2029 }
2030 break;
2031 default:
2032 break;
2033 }
2034 return QCoreApplication::event(e);
2035}
2036
2041{
2042 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2043}
2044
2046{
2047 if (!window)
2048 return false;
2049 QPlatformWindow *platformWindow = window->handle();
2050 if (!platformWindow)
2051 return false;
2052 // spontaneous events come from the platform integration already, we don't need to send the events back
2053 if (event->spontaneous())
2054 return false;
2055 // let the platform window do any handling it needs to as well
2056 return platformWindow->windowEvent(event);
2057}
2058
2060{
2061 return window->nativeEvent(eventType, message, result);
2062}
2063
2065{
2067 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2068
2069 switch(e->type) {
2072 break;
2075 break;
2078 break;
2081 break;
2084 break;
2087 break;
2090 break;
2093 break;
2096 break;
2099 break;
2102 break;
2105 break;
2109 break;
2112 break;
2116 break;
2120 break;
2124 break;
2128 break;
2132 break;
2136 break;
2140 break;
2143 break;
2146 break;
2150 break;
2154 break;
2158 break;
2159#ifndef QT_NO_GESTURES
2163 break;
2164#endif
2168 break;
2172 break;
2173#ifndef QT_NO_CONTEXTMENU
2177 break;
2178#endif
2181 break;
2182 default:
2183 qWarning() << "Unknown user input event type:" << e->type;
2184 break;
2185 }
2186}
2187
2201{
2204 QWindow *window = e->window.data();
2205 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2208 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2209 bool mouseMove = false;
2210 bool mousePress = false;
2211 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2212 QPointF globalPoint = e->globalPos;
2213
2214 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2215 qWarning("QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2216 return;
2217 }
2218
2219 type = e->buttonType;
2220 button = e->button;
2221
2223 mouseMove = true;
2225 mousePress = true;
2226
2227 if (!mouseMove && positionChanged) {
2231 e->source, e->nonClientArea);
2232 if (e->synthetic())
2234 processMouseEvent(&moveEvent); // mouse move excluding state change
2235 processMouseEvent(e); // the original mouse event
2236 return;
2237 }
2238 if (type == QEvent::MouseMove && !positionChanged) {
2239 // On Windows, and possibly other platforms, a touchpad can send a mouse move
2240 // that does not change position, between a press and a release. This may
2241 // confuse applications, so we always filter out these mouse events for
2242 // consistent behavior among platforms.
2243 return;
2244 }
2245
2247 QPointF localPoint = e->localPos;
2248 bool doubleClick = false;
2249 auto persistentEPD = devPriv->pointById(0);
2250
2251 if (mouseMove) {
2253 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2255 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2256 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2257 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2259 } else {
2260 static unsigned long lastPressTimestamp = 0;
2262 if (mousePress) {
2263 ulong doubleClickInterval = static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2264 doubleClick = e->timestamp - lastPressTimestamp
2265 < doubleClickInterval && button == mousePressButton;
2267 lastPressTimestamp = e ->timestamp;
2268 }
2269 }
2270
2271 if (e->nullWindow()) {
2272 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2273 if (window) {
2274 // Moves and the release following a press must go to the same
2275 // window, even if the cursor has moved on over another window.
2276 if (e->buttons != Qt::NoButton) {
2279 else
2281 } else if (currentMousePressWindow) {
2283 currentMousePressWindow = nullptr;
2284 }
2285 localPoint = window->mapFromGlobal(globalPoint);
2286 }
2287 }
2288
2289 if (!window)
2290 return;
2291
2292#ifndef QT_NO_CURSOR
2293 if (!e->synthetic()) {
2294 if (const QScreen *screen = window->screen())
2295 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2296 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2297 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2298 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2299 button, e->buttons, e->modifiers, e->source, device);
2300 // avoid incorrect velocity calculation: ev is in the native coordinate system,
2301 // but we need to consistently use the logical coordinate system for velocity
2302 // whenever QEventPoint::setTimestamp() is called
2303 ev.QInputEvent::setTimestamp(e->timestamp);
2304 cursor->pointerEvent(ev);
2305 }
2306 }
2307#endif
2308
2309 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2310 Q_ASSERT(devPriv->pointById(0) == persistentEPD); // we don't expect reallocation in QPlatformCursor::pointerEvenmt()
2311 // restore globalLastPosition to avoid invalidating the velocity calculations,
2312 // because the QPlatformCursor mouse event above was in native coordinates
2313 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2314 persistentEPD = nullptr; // incoming and synth events can cause reallocation during delivery, so don't use this again
2315 // ev now contains a detached copy of the QEventPoint from QPointingDevicePrivate::activePoints
2316 ev.setTimestamp(e->timestamp);
2317 if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
2318 // a modal window is blocking this window, don't allow mouse events through
2319 return;
2320 }
2321
2322 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2323 // QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
2324 QMutableSinglePointEvent::from(ev).setDoubleClick();
2325 }
2326
2327 QGuiApplication::sendSpontaneousEvent(window, &ev);
2328 e->eventAccepted = ev.isAccepted();
2329 if (!e->synthetic() && !ev.isAccepted()
2330 && !e->nonClientArea
2332 QList<QWindowSystemInterface::TouchPoint> points;
2334 point.id = 1;
2335 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2336
2337 // only translate left button related events to
2338 // avoid strange touch event sequences when several
2339 // buttons are pressed
2344 } else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2346 } else {
2347 return;
2348 }
2349
2350 points << point;
2351
2353 const QList<QEventPoint> &touchPoints =
2355
2358 processTouchEvent(&fake);
2359 }
2360 if (doubleClick) {
2362 if (!e->window.isNull() || e->nullWindow()) { // QTBUG-36364, check if window closed in response to press
2364 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2365 button, e->buttons, e->modifiers, e->source, device);
2366 dblClickEvent.setTimestamp(e->timestamp);
2367 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2368 }
2369 }
2371 if (auto *persistentEPD = devPriv->queryPointById(0)) {
2372 ev.setExclusiveGrabber(persistentEPD->eventPoint, nullptr);
2373 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2374 }
2375 }
2376}
2377
2379{
2380#if QT_CONFIG(wheelevent)
2381 QWindow *window = e->window.data();
2382 QPointF globalPoint = e->globalPos;
2383 QPointF localPoint = e->localPos;
2384
2385 if (e->nullWindow()) {
2386 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2387 if (window)
2388 localPoint = window->mapFromGlobal(globalPoint);
2389 }
2390
2391 if (!window)
2392 return;
2393
2396
2397 if (window->d_func()->blockedByModalWindow) {
2398 // a modal window is blocking this window, don't allow wheel events through
2399 return;
2400 }
2401
2402 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2403 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2405 ev.setTimestamp(e->timestamp);
2406 QGuiApplication::sendSpontaneousEvent(window, &ev);
2407 e->eventAccepted = ev.isAccepted();
2408#else
2409 Q_UNUSED(e);
2410#endif // QT_CONFIG(wheelevent)
2411}
2412
2414{
2415 QWindow *window = e->window.data();
2417 if (e->nullWindow()
2418#ifdef Q_OS_ANDROID
2419 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2420#endif
2421 ) {
2423 }
2424
2425#if defined(Q_OS_ANDROID)
2426 static bool backKeyPressAccepted = false;
2427 static bool menuKeyPressAccepted = false;
2428#endif
2429
2430#if !defined(Q_OS_MACOS)
2431 // FIXME: Include OS X in this code path by passing the key event through
2432 // QPlatformInputContext::filterEvent().
2433 if (e->keyType == QEvent::KeyPress && window) {
2436#if defined(Q_OS_ANDROID)
2437 backKeyPressAccepted = e->key == Qt::Key_Back;
2438 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2439#endif
2440 return;
2441 }
2442 }
2443#endif
2444
2445 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2447 e->unicode, e->repeat, e->repeatCount);
2448 ev.setTimestamp(e->timestamp);
2449
2450 // only deliver key events when we have a window, and no modal window is blocking this window
2451
2452 if (window && !window->d_func()->blockedByModalWindow)
2453 QGuiApplication::sendSpontaneousEvent(window, &ev);
2454#ifdef Q_OS_ANDROID
2455 else
2456 ev.setAccepted(false);
2457
2458 if (e->keyType == QEvent::KeyPress) {
2459 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2460 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2461 } else if (e->keyType == QEvent::KeyRelease) {
2462 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2463 if (window)
2465 } else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2466 platform_theme->showPlatformMenuBar();
2467 }
2468 }
2469#endif
2470 e->eventAccepted = ev.isAccepted();
2471}
2472
2474{
2475 if (!e->enter)
2476 return;
2477 if (e->enter.data()->d_func()->blockedByModalWindow) {
2478 // a modal window is blocking this window, don't allow enter events through
2479 return;
2480 }
2481
2483
2484 // TODO later: EnterEvent must report _which_ mouse entered the window; for now we assume primaryPointingDevice()
2486
2487 // Since we don't always track mouse moves that occur outside a window, any residual velocity
2488 // stored in the persistent QEventPoint may be inaccurate (especially in fast-moving autotests).
2489 // Reset the Kalman filter so that the velocity of the first mouse event after entering the window
2490 // will be based on a zero residual velocity (but the result can still be non-zero if the mouse
2491 // moves to a different position from where this enter event occurred; tests often do that).
2492 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2493 auto epd = devPriv->queryPointById(event.points().first().id());
2494 Q_ASSERT(epd);
2495 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2496
2497 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2498}
2499
2501{
2502 if (!e->leave)
2503 return;
2504 if (e->leave.data()->d_func()->blockedByModalWindow) {
2505 // a modal window is blocking this window, don't allow leave events through
2506 return;
2507 }
2508
2509 currentMouseWindow = nullptr;
2510
2512 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2513}
2514
2516{
2518 QWindow *newFocus = e->focused.data();
2519
2520 if (previous == newFocus)
2521 return;
2522
2523 if (newFocus)
2524 if (QPlatformWindow *platformWindow = newFocus->handle())
2525 if (platformWindow->isAlertState())
2526 platformWindow->setAlertState(false);
2527
2528 QObject *previousFocusObject = previous ? previous->focusObject() : nullptr;
2529
2530 if (previous) {
2531 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2532 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2533 }
2534
2536 if (!qApp)
2537 return;
2538
2539 if (previous) {
2542 newFocus && (newFocus->flags() & Qt::Popup) == Qt::Popup)
2544 QFocusEvent focusOut(QEvent::FocusOut, r);
2545 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2546 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2548 } else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2550 }
2551
2555 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2557 QFocusEvent focusIn(QEvent::FocusIn, r);
2558 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2561 } else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2563 }
2564
2565 if (self) {
2566 self->notifyActiveWindowChange(previous);
2567
2568 if (previousFocusObject != qApp->focusObject() ||
2569 // We are getting an activation change but there is no new focusObject, and we also
2570 // don't have a previousFocusObject in the previously active window anymore. This can
2571 // happen when window gets destroyed (see QWidgetWindow::focusObject returning nullptr
2572 // when already in the QWidget destructor), so update the focusObject to avoid dangling
2573 // pointers. See also QWidget::clearFocus(), which tries to cover for this as well.
2574 (previous && previousFocusObject == nullptr && qApp->focusObject() == nullptr)) {
2575 self->_q_updateFocusObject(qApp->focusObject());
2576 }
2577 }
2578
2579 emit qApp->focusWindowChanged(newFocus);
2580 if (previous)
2581 emit previous->activeChanged();
2582 if (newFocus)
2583 emit newFocus->activeChanged();
2584}
2585
2587{
2588 if (QWindow *window = wse->window.data()) {
2589 QWindowPrivate *windowPrivate = qt_window_private(window);
2590 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2591
2592 windowPrivate->windowState = wse->newState;
2593 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2594 if (newEffectiveState != originalEffectiveState)
2595 emit window->windowStateChanged(newEffectiveState);
2596
2597 windowPrivate->updateVisibility();
2598
2599 QWindowStateChangeEvent e(wse->oldState);
2600 QGuiApplication::sendSpontaneousEvent(window, &e);
2601 }
2602}
2603
2605{
2606 QWindow *window = wse->window.data();
2607 if (!window)
2608 return;
2609
2610 if (window->screen() == wse->screen.data())
2611 return;
2612
2613 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2614 if (QScreen *screen = wse->screen.data())
2615 topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */);
2616 else // Fall back to default behavior, and try to find some appropriate screen
2617 topLevelWindow->setScreen(nullptr);
2618 }
2619}
2620
2622{
2623 if (wde->window.isNull())
2624 return;
2625 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2626}
2627
2629{
2630 if (wse->window.isNull())
2631 return;
2632
2633 // Handle by forwarding directly to QWindowPrivate, instead of sending spontaneous
2634 // QEvent like most other functions, as there's no QEvent type for the safe area
2635 // change, and we don't want to add one until we know that this is a good API.
2636 qt_window_private(wse->window)->processSafeAreaMarginsChanged();
2637}
2638
2640{
2641 if (self)
2642 self->handleThemeChanged();
2643
2645
2646 QEvent themeChangeEvent(QEvent::ThemeChange);
2647 const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list;
2648 for (auto *window : windows)
2649 QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent);
2650}
2651
2653{
2654 const auto newColorScheme = platformTheme() ? platformTheme()->colorScheme()
2656 QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(newColorScheme);
2657
2658 updatePalette();
2659
2660 QIconLoader::instance()->updateSystemTheme();
2662
2664 const auto locker = qt_scoped_lock(applicationFontMutex);
2667 }
2669}
2670
2672{
2673 if (e->window.isNull())
2674 return;
2675
2676 QWindow *window = e->window.data();
2677 if (!window)
2678 return;
2679
2680 const QRect lastReportedGeometry = window->d_func()->geometry;
2681 const QRect requestedGeometry = e->requestedGeometry;
2682 const QRect actualGeometry = e->newGeometry;
2683
2684 // We send size and move events only if the geometry has changed from
2685 // what was last reported, or if the user tried to set a new geometry,
2686 // but the window manager responded by keeping the old geometry. In the
2687 // latter case we send move/resize events with the same geometry as the
2688 // last reported geometry, to indicate that the window wasn't moved or
2689 // resized. Note that this logic does not apply to the property changes
2690 // of the window, as we don't treat them as part of this request/response
2691 // protocol of QWindow/QPA.
2692 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2693 || requestedGeometry.size() != actualGeometry.size();
2694 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2695 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2696
2697 window->d_func()->geometry = actualGeometry;
2698
2699 if (isResize || window->d_func()->resizeEventPending) {
2700 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2701 QGuiApplication::sendSpontaneousEvent(window, &e);
2702
2703 window->d_func()->resizeEventPending = false;
2704
2705 if (actualGeometry.width() != lastReportedGeometry.width())
2706 emit window->widthChanged(actualGeometry.width());
2707 if (actualGeometry.height() != lastReportedGeometry.height())
2708 emit window->heightChanged(actualGeometry.height());
2709 }
2710
2711 if (isMove) {
2712 //### frame geometry
2713 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2714 QGuiApplication::sendSpontaneousEvent(window, &e);
2715
2716 if (actualGeometry.x() != lastReportedGeometry.x())
2717 emit window->xChanged(actualGeometry.x());
2718 if (actualGeometry.y() != lastReportedGeometry.y())
2719 emit window->yChanged(actualGeometry.y());
2720 }
2721}
2722
2724{
2725 if (e->window.isNull())
2726 return;
2727 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2728 // a modal window is blocking this window, don't allow close events through, unless they
2729 // originate from a call to QWindow::close.
2730 e->eventAccepted = false;
2731 return;
2732 }
2733
2735 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2736
2737 e->eventAccepted = event.isAccepted();
2738}
2739
2741{
2742 if (e->url.isEmpty())
2743 return;
2744
2746 QGuiApplication::sendSpontaneousEvent(qApp, &event);
2747}
2748
2750{
2751 for (int i = 0; i < tabletDevicePoints.size(); ++i) {
2752 TabletPointData &pointData = tabletDevicePoints[i];
2753 if (pointData.deviceId == deviceId)
2754 return pointData;
2755 }
2756
2757 tabletDevicePoints.append(TabletPointData(deviceId));
2758 return tabletDevicePoints.last();
2759}
2760
2762{
2763#if QT_CONFIG(tabletevent)
2764 const auto device = static_cast<const QPointingDevice *>(e->device);
2765 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2766
2768 if (e->buttons != pointData.state)
2769 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2770
2771 QWindow *window = e->window.data();
2773
2774 bool localValid = true;
2775 // If window is null, pick one based on the global position and make sure all
2776 // subsequent events up to the release are delivered to that same window.
2777 // If window is given, just send to that.
2778 if (type == QEvent::TabletPress) {
2779 if (e->nullWindow()) {
2781 localValid = false;
2782 }
2783 if (!window)
2784 return;
2785 pointData.target = window;
2786 } else {
2787 if (e->nullWindow()) {
2788 window = pointData.target;
2789 localValid = false;
2790 }
2792 pointData.target = nullptr;
2793 if (!window)
2794 return;
2795 }
2796 QPointF local = e->local;
2797 if (!localValid) {
2798 QPointF delta = e->global - e->global.toPoint();
2799 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2800 }
2801
2802 // TODO stop deducing the button state change here: rather require it from the platform plugin, as with mouse events
2803 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2805 for (int check = Qt::LeftButton; check <= int(Qt::MaxMouseButton); check = check << 1) {
2806 if (check & stateChange) {
2807 button = Qt::MouseButton(check);
2808 break;
2809 }
2810 }
2811
2812 QTabletEvent tabletEvent(type, device, local, e->global,
2813 e->pressure, e->xTilt, e->yTilt,
2814 e->tangentialPressure, e->rotation, e->z,
2815 e->modifiers, button, e->buttons);
2816 tabletEvent.setAccepted(false);
2817 tabletEvent.setTimestamp(e->timestamp);
2818 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
2819 pointData.state = e->buttons;
2820 if (!tabletEvent.isAccepted()
2823
2824 const QEvent::Type mouseType = [&]() {
2825 switch (type) {
2829 default: Q_UNREACHABLE();
2830 }
2831 }();
2833 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized, false, device);
2835 qCDebug(lcPtrDispatch) << "synthesizing mouse from tablet event" << mouseType
2836 << e->local << button << e->buttons << e->modifiers;
2837 processMouseEvent(&mouseEvent);
2838 }
2839#else
2840 Q_UNUSED(e);
2841#endif
2842}
2843
2845{
2846#if QT_CONFIG(tabletevent)
2847 const QPointingDevice *dev = static_cast<const QPointingDevice *>(e->device);
2848 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
2849 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
2850 tabletDevicePoint(dev->uniqueId().numericId()).state);
2851 ev.setTimestamp(e->timestamp);
2852 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
2853#else
2854 Q_UNUSED(e);
2855#endif
2856}
2857
2859{
2860#if QT_CONFIG(tabletevent)
2861 const QPointingDevice *dev = static_cast<const QPointingDevice *>(e->device);
2862 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
2863 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
2864 tabletDevicePoint(dev->uniqueId().numericId()).state);
2865 ev.setTimestamp(e->timestamp);
2866 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
2867#else
2868 Q_UNUSED(e);
2869#endif
2870}
2871
2872#ifndef QT_NO_GESTURES
2874{
2875 if (e->window.isNull())
2876 return;
2877
2878 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2879 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
2880 e->delta, e->sequenceId);
2881 ev.setTimestamp(e->timestamp);
2882 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
2883}
2884#endif // QT_NO_GESTURES
2885
2887{
2888 if (!e->window)
2889 return;
2890
2891 if (e->window->d_func()->blockedByModalWindow) {
2892 // a modal window is blocking this window, don't allow events through
2893 return;
2894 }
2895
2897 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
2898}
2899
2900#ifndef QT_NO_CONTEXTMENU
2902{
2903 // Widgets do not care about mouse triggered context menu events. Also, do not forward event
2904 // to a window blocked by a modal window.
2905 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
2906 return;
2907
2909 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
2910}
2911#endif
2912
2914{
2916 return;
2917
2919 QPointingDevice *device = const_cast<QPointingDevice *>(static_cast<const QPointingDevice *>(e->device));
2921
2922 if (e->touchType == QEvent::TouchCancel) {
2923 // The touch sequence has been canceled (e.g. by the compositor).
2924 // Send the TouchCancel to all windows with active touches and clean up.
2926 touchEvent.setTimestamp(e->timestamp);
2927 constexpr qsizetype Prealloc = decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
2928 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
2929
2930 for (auto &epd : devPriv->activePoints.values()) {
2931 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
2932 windowsNeedingCancel.insert(w);
2933 }
2934
2935 for (QWindow *w : windowsNeedingCancel)
2936 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
2937
2938 if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
2939 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
2940 synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
2941 if (!synthIt->window)
2942 continue;
2943 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
2944 e->timestamp,
2945 synthIt->pos,
2946 synthIt->screenPos,
2948 e->modifiers,
2952 false,
2953 device);
2955 processMouseEvent(&fake);
2956 }
2957 self->synthesizedMousePoints.clear();
2958 }
2959 self->lastTouchType = e->touchType;
2960 return;
2961 }
2962
2963 // Prevent sending ill-formed event sequences: Cancel can only be followed by a Begin.
2964 if (self->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
2965 return;
2966
2967 self->lastTouchType = e->touchType;
2968
2969 QPointer<QWindow> window = e->window; // the platform hopefully tells us which window received the event
2970 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
2971
2972 // For each temporary QEventPoint from the QPA TouchEvent:
2973 // - update the persistent QEventPoint in QPointingDevicePrivate::activePoints with current values
2974 // - determine which window to deliver it to
2975 // - add it to the QTouchEvent instance for that window (QMutableTouchEvent::target() will be QWindow*, for now)
2976 for (auto &tempPt : e->points) {
2977 // update state
2978 auto epd = devPriv->pointById(tempPt.id());
2979 auto &ep = epd->eventPoint;
2980 epd->eventPoint.setAccepted(false);
2981 switch (tempPt.state()) {
2983 // On touchpads, send all touch points to the same window.
2985 window = devPriv->firstActiveWindow();
2986 // If the QPA event didn't tell us which window, find the one under the touchpoint position.
2987 if (!window)
2988 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
2989 QMutableEventPoint::setWindow(ep, window);
2990 break;
2991
2993 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
2994 qCDebug(lcPtrDispatch) << "delivering touch release to same window"
2995 << QMutableEventPoint::window(ep) << "not" << window.data();
2997 break;
2998
2999 default: // update or stationary
3000 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3001 qCDebug(lcPtrDispatch) << "delivering touch update to same window"
3002 << QMutableEventPoint::window(ep) << "not" << window.data();
3004 break;
3005 }
3006 // If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen)
3007 if (Q_UNLIKELY(!window)) {
3008 qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window";
3009 continue;
3010 }
3011 QMutableEventPoint::update(tempPt, ep);
3012
3013 Q_ASSERT(window.data() != nullptr);
3014
3015 // make the *scene* position the same as the *global* position
3016 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3017
3018 // store the scene position as local position, for now
3019 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3020
3021 // setTimeStamp has side effects, so we do it last
3023
3024 // add the touchpoint to the event that will be delivered to the window
3025 bool added = false;
3026 for (QMutableTouchEvent &ev : touchEvents) {
3027 if (ev.target() == window.data()) {
3028 ev.addPoint(ep);
3029 added = true;
3030 break;
3031 }
3032 }
3033 if (!added) {
3034 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3035 mte.setTimestamp(e->timestamp);
3036 mte.setTarget(window.data());
3037 touchEvents.append(mte);
3038 }
3039 }
3040
3041 if (touchEvents.isEmpty())
3042 return;
3043
3044 for (QMutableTouchEvent &touchEvent : touchEvents) {
3045 QWindow *window = static_cast<QWindow *>(touchEvent.target());
3046
3047 QEvent::Type eventType;
3048 switch (touchEvent.touchPointStates()) {
3050 eventType = QEvent::TouchBegin;
3051 break;
3053 eventType = QEvent::TouchEnd;
3054 break;
3055 default:
3056 eventType = QEvent::TouchUpdate;
3057 break;
3058 }
3059
3060 if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
3061 // a modal window is blocking this window, don't allow touch events through
3062
3063 // QTBUG-37371 temporary fix; TODO: revisit when we have a forwarding solution
3064 if (touchEvent.type() == QEvent::TouchEnd) {
3065 // but don't leave dangling state: e.g.
3066 // QQuickWindowPrivate::itemForTouchPointId needs to be cleared.
3068 touchEvent.setTimestamp(e->timestamp);
3069 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3070 }
3071 continue;
3072 }
3073
3074 // Note: after the call to sendSpontaneousEvent, touchEvent.position() will have
3075 // changed to reflect the local position inside the last (random) widget it tried
3076 // to deliver the touch event to, and will therefore be invalid afterwards.
3077 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3078
3079 if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3080 // exclude devices which generate their own mouse events
3081 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3082
3083 QEvent::Type mouseEventType = QEvent::MouseMove;
3085 Qt::MouseButtons buttons = Qt::LeftButton;
3086 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3087 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3088 qCDebug(lcPtrDispatch) << "synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3089 }
3090 if (m_fakeMouseSourcePointId >= 0) {
3091 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3092 if (touchPoint) {
3093 switch (touchPoint->state()) {
3095 mouseEventType = QEvent::MouseButtonPress;
3097 break;
3099 mouseEventType = QEvent::MouseButtonRelease;
3101 buttons = Qt::NoButton;
3102 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3103 m_fakeMouseSourcePointId = -1;
3104 break;
3105 default:
3106 break;
3107 }
3108 if (touchPoint->state() != QEventPoint::State::Released) {
3109 self->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3110 touchPoint->position(), touchPoint->globalPosition(), window));
3111 }
3112 // All touch events that are not accepted by the application will be translated to
3113 // left mouse button events instead (see AA_SynthesizeMouseForUnhandledTouchEvents docs).
3114 // TODO why go through QPA? Why not just send a QMouseEvent right from here?
3116 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3117 touchPoint->globalPosition(),
3118 buttons,
3119 e->modifiers,
3120 button,
3121 mouseEventType,
3123 false,
3124 device);
3126 processMouseEvent(&fake);
3127 }
3128 }
3129 if (eventType == QEvent::TouchEnd)
3130 self->synthesizedMousePoints.clear();
3131 }
3132 }
3133 }
3134
3135 // Remove released points from QPointingDevicePrivate::activePoints only after the event is
3136 // delivered. Widgets and Qt Quick are allowed to access them at any time before this.
3137 for (const QEventPoint &touchPoint : e->points) {
3138 if (touchPoint.state() == QEventPoint::State::Released)
3139 devPriv->removePointById(touchPoint.id());
3140 }
3141}
3142
3144{
3145 // This operation only makes sense after the QGuiApplication constructor runs
3147 return;
3148
3149 if (!e->screen)
3150 return;
3151
3152 QScreen *s = e->screen.data();
3153 s->d_func()->orientation = e->orientation;
3154
3155 emit s->orientationChanged(s->orientation());
3156
3157 QScreenOrientationChangeEvent event(s, s->orientation());
3159}
3160
3162{
3163 // This operation only makes sense after the QGuiApplication constructor runs
3165 return;
3166
3167 if (!e->screen)
3168 return;
3169
3170 {
3171 QScreen *s = e->screen.data();
3172 QScreenPrivate::UpdateEmitter updateEmitter(s);
3173
3174 // Note: The incoming geometries have already been scaled by QHighDpi
3175 // in the QWSI layer, so we don't need to call updateGeometry() here.
3176 s->d_func()->geometry = e->geometry;
3177 s->d_func()->availableGeometry = e->availableGeometry;
3178
3179 s->d_func()->updatePrimaryOrientation();
3180 }
3181
3183}
3184
3186{
3187 // This operation only makes sense after the QGuiApplication constructor runs
3189 return;
3190
3192
3193 if (!e->screen)
3194 return;
3195
3196 {
3197 QScreen *s = e->screen.data();
3198 QScreenPrivate::UpdateEmitter updateEmitter(s);
3199 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3200 s->d_func()->updateGeometry();
3201 }
3202
3204 if (window->screen() == e->screen)
3205 QWindowPrivate::get(window)->updateDevicePixelRatio();
3206
3208}
3209
3211{
3212 // This operation only makes sense after the QGuiApplication constructor runs
3214 return;
3215
3216 if (!e->screen)
3217 return;
3218
3219 QScreen *s = e->screen.data();
3220 qreal rate = e->rate;
3221 // safeguard ourselves against buggy platform behavior...
3222 if (rate < 1.0)
3223 rate = 60.0;
3224 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3225 s->d_func()->refreshRate = rate;
3226 emit s->refreshRateChanged(s->refreshRate());
3227 }
3228}
3229
3231{
3232 if (!e->window)
3233 return;
3234
3235 QWindow *window = e->window.data();
3236 if (!window)
3237 return;
3239
3240 if (!p->receivedExpose) {
3241 if (p->resizeEventPending) {
3242 // as a convenience for plugins, send a resize event before the first expose event if they haven't done so
3243 // window->geometry() should have a valid size as soon as a handle exists.
3244 QResizeEvent e(window->geometry().size(), p->geometry.size());
3245 QGuiApplication::sendSpontaneousEvent(window, &e);
3246
3247 p->resizeEventPending = false;
3248 }
3249
3250 // FIXME: It would logically make sense to set this _after_ we've sent the
3251 // expose event to the window, to mark that it now has received an expose.
3252 // But some parts of Qt (mis)use this private member to check whether the
3253 // window has been mapped yet, which they do in code that is triggered
3254 // by the very same expose event we send below. To keep the code working
3255 // we need to set the variable up front, until the code has been fixed.
3256 p->receivedExpose = true;
3257 }
3258
3259 // If the platform does not send paint events we need to synthesize them from expose events
3260 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3261
3262 const bool wasExposed = p->exposed;
3263 p->exposed = e->isExposed && window->screen();
3264
3265 // We expect that the platform plugins send DevicePixelRatioChange events.
3266 // As a fail-safe make a final check here to make sure the cached DPR value is
3267 // always up to date before sending the expose event.
3268 if (e->isExposed && !e->region.isEmpty()) {
3269 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3270 if (dprWasChanged)
3271 qWarning() << "The cached device pixel ratio value was stale on window expose. "
3272 << "Please file a QTBUG which explains how to reproduce.";
3273 }
3274
3275 // We treat expose events for an already exposed window as paint events
3276 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3277 QPaintEvent paintEvent(e->region);
3278 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3279 if (paintEvent.isAccepted())
3280 return; // No need to send expose
3281
3282 // The paint event was not accepted, so we fall through and send an expose
3283 // event instead, to maintain compatibility for clients that haven't adopted
3284 // paint events yet.
3285 }
3286
3287 QExposeEvent exposeEvent(e->region);
3288 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3289 e->eventAccepted = exposeEvent.isAccepted();
3290
3291 // If the window was just exposed we also need to send a paint event,
3292 // so that clients that implement paint events will draw something.
3293 // Note that we we can not skip this based on the expose event being
3294 // accepted, as clients may implement exposeEvent to track the state
3295 // change, but without drawing anything.
3296 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3297 QPaintEvent paintEvent(e->region);
3298 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3299 }
3300}
3301
3303{
3304 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents), "QGuiApplication",
3305 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3306
3307 if (!e->window)
3308 return;
3309
3310 QPaintEvent paintEvent(e->region);
3311 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3312
3313 // We report back the accepted state to the platform, so that it can
3314 // decide when the best time to send the fallback expose event is.
3315 e->eventAccepted = paintEvent.isAccepted();
3316}
3317
3318#if QT_CONFIG(draganddrop)
3319
3325static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3326{
3329}
3330
3331QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w, const QMimeData *dropData,
3332 const QPoint &p, Qt::DropActions supportedActions,
3333 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3334{
3335 updateMouseAndModifierButtonState(buttons, modifiers);
3336
3337 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3338 QPlatformDrag *platformDrag = platformIntegration()->drag();
3339 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3340 lastAcceptedDropAction = Qt::IgnoreAction;
3341 return QPlatformDragQtResponse(false, lastAcceptedDropAction, QRect());
3342 }
3343
3344 if (!dropData) {
3345 currentDragWindow = nullptr;
3346 QDragLeaveEvent e;
3348 lastAcceptedDropAction = Qt::IgnoreAction;
3349 return QPlatformDragQtResponse(false, lastAcceptedDropAction, QRect());
3350 }
3351 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3352
3353 if (w != currentDragWindow) {
3354 lastAcceptedDropAction = Qt::IgnoreAction;
3355 if (currentDragWindow) {
3356 QDragLeaveEvent e;
3358 }
3360 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3362 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3363 lastAcceptedDropAction = e.dropAction();
3364 }
3365
3366 // Handling 'DragEnter' should suffice for the application.
3367 if (lastAcceptedDropAction != Qt::IgnoreAction
3368 && (supportedActions & lastAcceptedDropAction)) {
3369 me.setDropAction(lastAcceptedDropAction);
3370 me.accept();
3371 }
3373 lastAcceptedDropAction = me.isAccepted() ?
3374 me.dropAction() : Qt::IgnoreAction;
3375 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3376}
3377
3378QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w, const QMimeData *dropData,
3379 const QPoint &p, Qt::DropActions supportedActions,
3380 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3381{
3382 updateMouseAndModifierButtonState(buttons, modifiers);
3383
3384 currentDragWindow = nullptr;
3385
3386 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3388
3389 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3390 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3391 return response;
3392}
3393
3394#endif // QT_CONFIG(draganddrop)
3395
3396#ifndef QT_NO_CLIPBOARD
3401{
3402 if (QGuiApplicationPrivate::qt_clipboard == nullptr) {
3403 if (!qApp) {
3404 qWarning("QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3405 return nullptr;
3406 }
3408 }
3410}
3411#endif
3412
3439
3441{
3442 if (app_pal) {
3443 if (setPalette(*app_pal) && qGuiApp)
3444 qGuiApp->d_func()->handlePaletteChanged();
3445 } else {
3447 }
3448}
3449
3458
3459void QGuiApplicationPrivate::clearPalette()
3460{
3461 delete app_pal;
3462 app_pal = nullptr;
3463}
3464
3474{
3476 qGuiApp->d_func()->handlePaletteChanged();
3477}
3478
3480{
3481 // Resolve the palette against the theme palette, filling in
3482 // any missing roles, while keeping the original resolve mask.
3483 QPalette basePalette = qGuiApp ? qGuiApp->d_func()->basePalette() : Qt::gray;
3484 basePalette.setResolveMask(0); // The base palette only contributes missing colors roles
3485 QPalette resolvedPalette = palette.resolve(basePalette);
3486
3487 if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolveMask() == app_pal->resolveMask())
3488 return false;
3489
3490 if (!app_pal)
3491 app_pal = new QPalette(resolvedPalette);
3492 else
3493 *app_pal = resolvedPalette;
3494
3496
3497 return true;
3498}
3499
3500/*
3501 Returns the base palette used to fill in missing roles in
3502 the current application palette.
3503
3504 Normally this is the theme palette, but QApplication
3505 overrides this for compatibility reasons.
3506*/
3508{
3509 const auto pf = platformTheme();
3510 return pf && pf->palette() ? *pf->palette() : Qt::gray;
3511}
3512
3514{
3515#if QT_DEPRECATED_SINCE(6, 0)
3516 if (!className) {
3522 }
3523#else
3525#endif // QT_DEPRECATED_SINCE(6, 0)
3526
3530 }
3531}
3532
3537
3555{
3556 const auto locker = qt_scoped_lock(applicationFontMutex);
3557 if (!QGuiApplicationPrivate::self && !QGuiApplicationPrivate::app_font) {
3558 qWarning("QGuiApplication::font(): no QGuiApplication instance and no application font set.");
3559 return QFont(); // in effect: QFont((QFontPrivate*)nullptr), so no recursion
3560 }
3563}
3564
3571{
3572 auto locker = qt_unique_lock(applicationFontMutex);
3573 const bool emitChange = !QGuiApplicationPrivate::app_font
3577 else
3580
3581 if (emitChange && qGuiApp) {
3583 locker.unlock();
3584#if QT_DEPRECATED_SINCE(6, 0)
3587 emit qGuiApp->fontChanged(font);
3589#else
3590 Q_UNUSED(font);
3591#endif // QT_DEPRECATED_SINCE(6, 0)
3594 }
3595}
3596
3623
3625{
3626 if (prev) {
3628 QCoreApplication::sendEvent(prev, &de);
3629 }
3630 if (self->focus_window) {
3633 }
3634}
3635
3643{
3645}
3646
3658
3666
3667
3668
3692
3694{
3696}
3697
3699{
3700 if (!lastWindowClosed())
3701 return;
3702
3703 if (in_exec)
3704 emit q_func()->lastWindowClosed();
3705
3708}
3709
3724{
3726 auto *windowPrivate = qt_window_private(window);
3727 if (!windowPrivate->participatesInLastWindowClosed())
3728 continue;
3729
3730 if (windowPrivate->treatAsVisible())
3731 return false;
3732 }
3733
3734 return true;
3735}
3736
3738{
3739 // The automatic quit functionality is triggered by
3740 // both QEventLoopLocker and maybeLastWindowClosed.
3741 // Although the former is a QCoreApplication feature
3742 // we don't want to quit the application when there
3743 // are open windows, regardless of whether the app
3744 // also quits automatically on maybeLastWindowClosed.
3745 if (!lastWindowClosed())
3746 return false;
3747
3749}
3750
3758
3760{
3762 QGuiApplication::sendSpontaneousEvent(QGuiApplication::instance(), &event);
3763 windowSystemEvent->eventAccepted = event.isAccepted();
3764}
3765
3782
3808{
3809 if (qApp)
3810 qWarning("setHighDpiScaleFactorRoundingPolicy must be called before creating the QGuiApplication instance");
3812}
3813
3823
3834{
3835 if ((applicationState == state) && !forcePropagate)
3836 return;
3837
3839
3840 switch (state) {
3841 case Qt::ApplicationActive: {
3843 QCoreApplication::sendSpontaneousEvent(qApp, &appActivate);
3844 break; }
3847 QCoreApplication::sendSpontaneousEvent(qApp, &appDeactivate);
3848 break; }
3849 default:
3850 break;
3851 }
3852
3854 QCoreApplication::sendSpontaneousEvent(qApp, &event);
3855
3856 emit qApp->applicationStateChanged(applicationState);
3857}
3858
3962#ifndef QT_NO_SESSIONMANAGER
3964{
3965 Q_D(const QGuiApplication);
3966 return d->is_session_restored;
3967}
3968
3970{
3971 Q_D(const QGuiApplication);
3972 return d->session_manager->sessionId();
3973}
3974
3976{
3977 Q_D(const QGuiApplication);
3978 return d->session_manager->sessionKey();
3979}
3980
3982{
3983 Q_D(const QGuiApplication);
3984 return d->is_saving_session;
3985}
3986
3988{
3989 Q_Q(QGuiApplication);
3990 is_saving_session = true;
3991 emit q->commitDataRequest(*session_manager);
3992 is_saving_session = false;
3993}
3994
3995
3997{
3998 Q_Q(QGuiApplication);
3999 is_saving_session = true;
4000 emit q->saveStateRequest(*session_manager);
4001 is_saving_session = false;
4002}
4003#endif //QT_NO_SESSIONMANAGER
4004
4026
4041{
4045
4046 // no change to the explicitly set or auto-detected layout direction
4048 return;
4049
4051 if (qGuiApp) {
4052 emit qGuiApp->layoutDirectionChanged(direction);
4053 QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
4054 }
4055}
4056
4058{
4059 /*
4060 effective_layout_direction defaults to Qt::LeftToRight, and is updated with what is
4061 auto-detected by a call to setLayoutDirection(Qt::LayoutDirectionAuto). This happens in
4062 QGuiApplicationPrivate::init and when the language changes (or before if the application
4063 calls the static function, but then no translators are installed so the auto-detection
4064 always yields Qt::LeftToRight).
4065 So we can be certain that it's always the right value.
4066 */
4068}
4069
4080#ifndef QT_NO_CURSOR
4082{
4083 CHECK_QAPP_INSTANCE(nullptr)
4084 return qGuiApp->d_func()->cursor_list.isEmpty() ? nullptr : &qGuiApp->d_func()->cursor_list.first();
4085}
4086
4096{
4098 if (qGuiApp->d_func()->cursor_list.isEmpty())
4099 return;
4100 qGuiApp->d_func()->cursor_list.removeFirst();
4102}
4103#endif
4104
4105
4106#ifndef QT_NO_CURSOR
4107static inline void applyCursor(QWindow *w, QCursor c)
4108{
4109 if (const QScreen *screen = w->screen())
4111 cursor->changeCursor(&c, w);
4112}
4113
4114static inline void unsetCursor(QWindow *w)
4115{
4116 if (const QScreen *screen = w->screen())
4118 cursor->changeCursor(nullptr, w);
4119}
4120
4121static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
4122{
4123 for (int i = 0; i < l.size(); ++i) {
4124 QWindow *w = l.at(i);
4125 if (w->handle() && w->type() != Qt::Desktop)
4126 applyCursor(w, c);
4127 }
4128}
4129
4130static inline void applyOverrideCursor(const QList<QScreen *> &screens, const QCursor &c)
4131{
4132 for (QScreen *screen : screens) {
4134 cursor->setOverrideCursor(c);
4135 }
4136}
4137
4138static inline void clearOverrideCursor(const QList<QScreen *> &screens)
4139{
4140 for (QScreen *screen : screens) {
4142 cursor->clearOverrideCursor();
4143 }
4144}
4145
4146static inline void applyWindowCursor(const QList<QWindow *> &l)
4147{
4148 for (int i = 0; i < l.size(); ++i) {
4149 QWindow *w = l.at(i);
4150 if (w->handle() && w->type() != Qt::Desktop) {
4151 if (qt_window_private(w)->hasCursor) {
4152 applyCursor(w, w->cursor());
4153 } else {
4154 unsetCursor(w);
4155 }
4156 }
4157 }
4158}
4159
4195
4208{
4210 if (qGuiApp->d_func()->cursor_list.isEmpty())
4211 return;
4212 qGuiApp->d_func()->cursor_list.removeFirst();
4213 if (qGuiApp->d_func()->cursor_list.size() > 0) {
4214 QCursor c(qGuiApp->d_func()->cursor_list.value(0));
4217 else
4219 } else {
4223 }
4224}
4225#endif// QT_NO_CURSOR
4226
4243
4259
4270
4281{
4282 CHECK_QAPP_INSTANCE(nullptr)
4283 if (!qGuiApp->d_func()->inputMethod)
4284 qGuiApp->d_func()->inputMethod = new QInputMethod();
4285 return qGuiApp->d_func()->inputMethod;
4286}
4287
4303{
4304 Q_UNUSED(cshape);
4305 return QPixmap();
4306}
4307
4309{
4310 // Guard against the default initialization of qInf() (avoid UB or SIGFPE in conversion).
4311 if (Q_UNLIKELY(qIsInf(thePoint.x())))
4312 return QPoint(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
4313 return thePoint.toPoint();
4314}
4315
4316#if QT_CONFIG(draganddrop)
4317void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
4318{
4319 Q_UNUSED(drag);
4320
4321}
4322#endif
4323
4325{
4326#ifdef Q_OS_WIN
4327 if (!m_a8ColorProfile)
4328 m_a8ColorProfile = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering
4329 return m_a8ColorProfile.get();
4330#else
4331 return colorProfileForA32Text();
4332#endif
4333}
4334
4336{
4337 if (!m_a32ColorProfile)
4338 m_a32ColorProfile = QColorTrcLut::fromGamma(fontSmoothingGamma);
4339 return m_a32ColorProfile.get();
4340}
4341
4343{
4344 Q_Q(QGuiApplication);
4345
4346 QPlatformInputContext *inputContext = platformIntegration()->inputContext();
4347 const bool enabled = inputContext && QInputMethodPrivate::objectAcceptsInputMethod(object);
4348
4350 if (inputContext)
4351 inputContext->setFocusObject(object);
4352 emit q->focusObjectChanged(object);
4353}
4354
4363
4365{
4367
4368 if (!m_inputDeviceManager)
4369 m_inputDeviceManager = new QInputDeviceManager(QGuiApplication::instance());
4370
4371 return m_inputDeviceManager;
4372}
4373
4387void *QGuiApplication::resolveInterface(const char *name, int revision) const
4388{
4389 using namespace QNativeInterface;
4390 using namespace QNativeInterface::Private;
4391
4394
4395#if defined(Q_OS_WIN)
4397#endif
4398#if QT_CONFIG(xcb)
4399 QT_NATIVE_INTERFACE_RETURN_IF(QX11Application, platformNativeInterface());
4400#endif
4401#if QT_CONFIG(wayland)
4402 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandApplication, platformNativeInterface());
4403#endif
4404#if defined(Q_OS_VISIONOS)
4406#endif
4407
4408 return QCoreApplication::resolveInterface(name, revision);
4409}
4410
4412
4413#include "moc_qguiapplication.cpp"
IOBluetoothDevice * device
Type loadRelaxed() const noexcept
\inmodule QtCore
Definition qbytearray.h:57
QByteArray & prepend(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbytearray.h:280
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
bool startsWith(QByteArrayView bv) const
Definition qbytearray.h:223
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
Definition qbytearray.h:600
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:107
void clear()
Clears the contents of the byte array and makes it null.
QByteArray first(qsizetype n) const &
Definition qbytearray.h:196
The QClipboard class provides access to the window system clipboard.
Definition qclipboard.h:20
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
static std::shared_ptr< QColorTrcLut > fromGamma(qreal gamma, Direction dir=BiLinear)
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
QCoreApplicationPrivate::Type application_type
static QAbstractEventDispatcher * eventDispatcher
\inmodule QtCore
void * resolveInterface(const char *name, int revision) const
\macro Q_DECLARE_TR_FUNCTIONS(context)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool event(QEvent *) override
\reimp
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *)
static void quit()
\threadsafe
virtual bool notify(QObject *, QEvent *)
Sends event to receiver: {receiver}->event(event).
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
void applicationNameChanged()
friend class QGuiApplication
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
Sets the attribute attribute if on is true; otherwise clears the attribute.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static int exec()
Enters the main event loop and waits until exit() is called.
static bool startingUp()
Returns true if an application object has not been created yet; otherwise returns false.
QString applicationName
the name of this application
static void initialize()
Definition qcursor.cpp:690
static void cleanup()
Definition qcursor.cpp:675
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition qdir.h:184
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
Definition qdir.cpp:2030
static QString toNativeSeparators(const QString &pathName)
Definition qdir.cpp:929
static QString currentPath()
Returns the absolute path of the application's current directory.
Definition qdir.cpp:2054
\inmodule QtGui
Definition qdrag.h:22
\inmodule QtGui
Definition qevent.h:165
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
int id
the ID number of this event point.
Definition qeventpoint.h:24
\inmodule QtCore
Definition qcoreevent.h:45
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition qcoreevent.h:305
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ TabletMove
Definition qcoreevent.h:121
@ ApplicationPaletteChange
Definition qcoreevent.h:93
@ ApplicationDeactivate
Definition qcoreevent.h:166
@ NonClientAreaMouseButtonDblClick
Definition qcoreevent.h:215
@ TabletEnterProximity
Definition qcoreevent.h:209
@ FocusAboutToChange
Definition qcoreevent.h:68
@ EnterWhatsThisMode
Definition qcoreevent.h:170
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ WindowBlocked
Definition qcoreevent.h:141
@ ApplicationActivate
Definition qcoreevent.h:164
@ WindowUnblocked
Definition qcoreevent.h:142
@ ApplicationWindowIconChange
Definition qcoreevent.h:90
@ FocusOut
Definition qcoreevent.h:67
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ FocusIn
Definition qcoreevent.h:66
@ TouchCancel
Definition qcoreevent.h:264
@ ThemeChange
Definition qcoreevent.h:266
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ NonClientAreaMouseMove
Definition qcoreevent.h:212
@ PlatformPanel
Definition qcoreevent.h:270
@ WindowActivate
Definition qcoreevent.h:83
@ LanguageChange
Definition qcoreevent.h:123
@ TabletRelease
Definition qcoreevent.h:127
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ ApplicationFontChange
Definition qcoreevent.h:91
@ TabletLeaveProximity
Definition qcoreevent.h:210
@ WindowDeactivate
Definition qcoreevent.h:84
@ NonClientAreaMouseButtonPress
Definition qcoreevent.h:213
@ MouseButtonRelease
Definition qcoreevent.h:61
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
bool isAccepted() const
Definition qcoreevent.h:308
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:515
bool exists() const
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.
The QFileOpenEvent class provides an event that will be sent when there is a request to open a file o...
Definition qevent.h:848
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition qfile.h:162
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
static bool removeAllApplicationFonts()
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
static void initialize()
Definition qfont.cpp:2250
static void cleanup()
Definition qfont.cpp:2259
static QObject * create(const QString &, const QString &)
static Qt::ApplicationState applicationState
static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
static void setApplicationState(Qt::ApplicationState state, bool forcePropagate=false)
static QPointer< QWindow > currentDragWindow
static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
QSessionManager * session_manager
bool canQuitAutomatically() override
static void updateBlockedStatus(QWindow *window)
static QWindow * currentMousePressWindow
static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
static void showModalWindow(QWindow *window)
static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result)
static Qt::KeyboardModifiers modifier_buttons
static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
static void hideModalWindow(QWindow *window)
static QPlatformIntegration * platformIntegration()
static QWindowList window_list
static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
static QList< TabletPointData > tabletDevicePoints
virtual QPalette basePalette() const
static void processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
void _q_updateFocusObject(QObject *object)
static QStyleHints * styleHints
static TabletPointData & tabletDevicePoint(qint64 deviceId)
static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
static void processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
static QList< QObject * > generic_plugin_list
static void processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
static void processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
static QList< QScreen * > screen_list
static QPalette * app_pal
static QEvent::Type contextMenuEventType()
static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static void resetCachedDevicePixelRatio()
static QClipboard * qt_clipboard
static void processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e)
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy
static QString * desktopFileName
static Qt::MouseButtons mouse_buttons
virtual bool windowNeverBlocked(QWindow *window) const
static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
static QWindow * currentMouseWindow
static QInputDeviceManager * inputDeviceManager()
QPixmap getPixmapCursor(Qt::CursorShape cshape)
static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
bool isWindowBlocked(QWindow *window, QWindow **blockingWindow=nullptr) const
const QColorTrcLut * colorProfileForA8Text()
static QPlatformTheme * platform_theme
static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
static void processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
static void captureGlobalModifierState(QEvent *e)
virtual void handlePaletteChanged(const char *className=nullptr)
static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e)
QGuiApplicationPrivate(int &argc, char **argv)
static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
static QString * platform_name
static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
static QWindow * focus_window
void createEventDispatcher() override
Called from QCoreApplication::init()
virtual void handleThemeChanged()
static Qt::MouseButton mousePressButton
static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e)
static QString * displayName
static struct QGuiApplicationPrivate::QLastCursorPosition lastCursorPosition
static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
virtual void notifyActiveWindowChange(QWindow *previous)
static bool setPalette(const QPalette &palette)
virtual void notifyLayoutDirectionChange()
static QPlatformIntegration * platform_integration
void eventDispatcherReady() override
const QColorTrcLut * colorProfileForA32Text()
virtual Qt::WindowModality defaultModality() const
static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce)
static void applyWindowGeometrySpecificationTo(QWindow *window)
static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e)
static QPlatformTheme * platformTheme()
virtual void notifyWindowIconChanged()
\macro qGuiApp
Q_SLOT void setBadgeNumber(qint64 number)
Sets the application's badge to number.
static QFunctionPointer platformFunction(const QByteArray &function)
static void setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy)
static Qt::ApplicationState applicationState()
static void setQuitOnLastWindowClosed(bool quit)
static QPlatformNativeInterface * platformNativeInterface()
bool notify(QObject *, QEvent *) override
\reimp
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
static QWindow * modalWindow()
Returns the most recently shown modal window.
static QWindow * topLevelAt(const QPoint &pos)
Returns the top level window at the given position pos, if any.
static void setDesktopFileName(const QString &name)
static void setFont(const QFont &)
Changes the default application font to font.
bool isSavingSession() const
static QWindowList allWindows()
Returns a list of all the windows in the application.
static QClipboard * clipboard()
Returns the object for interacting with the clipboard.
QScreen * primaryScreen
the primary (or default) screen of the application.
bool isSessionRestored() const
Returns true if the application has been restored from an earlier \l{Session Management}{session}; ot...
static QPalette palette()
Returns the current application palette.
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
static void setPalette(const QPalette &pal)
Changes the application palette to pal.
static QCursor * overrideCursor()
Returns the active application override cursor.
bool quitOnLastWindowClosed
whether the application implicitly quits when the last window is closed.
static QFont font()
Returns the default application font.
bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override
static QStyleHints * styleHints()
Returns the application's style hints.
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
static void changeOverrideCursor(const QCursor &)
Changes the currently active application override cursor to cursor.
static void setApplicationDisplayName(const QString &name)
qreal devicePixelRatio() const
Returns the highest screen device pixel ratio found on the system.
void applicationDisplayNameChanged()
QString sessionKey() const
Returns the session key in the current \l{Session Management}{session}.
static void setLayoutDirection(Qt::LayoutDirection direction)
static QInputMethod * inputMethod()
returns the input method.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static Qt::KeyboardModifiers queryKeyboardModifiers()
Queries and returns the state of the modifier keys on the keyboard.
static void setDesktopSettingsAware(bool on)
Sets whether Qt should use the system's standard colors, fonts, etc., to on.
QString applicationDisplayName
the user-visible name of this application
static void setOverrideCursor(const QCursor &)
Sets the application override cursor to cursor.
bool event(QEvent *) override
\reimp
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
~QGuiApplication()
Destructs the application.
QString platformName
The name of the underlying platform plugin.
QString sessionId() const
Returns the current \l{Session Management}{session's} identifier.
QString desktopFileName
the base name of the desktop entry for this application
Qt::LayoutDirection layoutDirection
the default layout direction for this application
static QScreen * screenAt(const QPoint &point)
Returns the screen at point, or \nullptr if outside of any screen.
static int exec()
Enters the main event loop and waits until exit() is called, and then returns the value that was set ...
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
QIcon windowIcon
the default window icon
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy()
static void setWindowIcon(const QIcon &icon)
\inmodule QtCore
Definition qhash.h:1145
static void updateHighDpiScaling()
static void initHighDpiScaling()
static QIconLoader * instance()
static void clearIconCache()
Definition qicon.cpp:102
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
static QIcon fromTheme(const QString &name)
Definition qicon.cpp:1344
QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
static bool isRegistered(const QInputDevice *dev)
Capabilities capabilities
DeviceType type
\inmodule QtGui
Definition qevent.h:49
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition qevent.h:56
static bool objectAcceptsInputMethod(QObject *object)
The QInputMethod class provides access to the active text input method.
The QKeyEvent class describes a key event.
Definition qevent.h:424
static bool isDebugBuild() noexcept Q_DECL_CONST_FUNCTION
static QStringList platformPluginArguments(const QString &platformName)
Returns additional arguments to the platform plugin matching platformName which can be specified as a...
static QVersionNumber version() noexcept Q_DECL_CONST_FUNCTION
\inmodule QtCore \reentrant
Definition qlibrary.h:17
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
value_type takeFirst()
Definition qlist.h:566
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to)
static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t)
static QWindow * window(const QEventPoint &p)
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
Definition qevent_p.h:57
\inmodule QtCore
Definition qmutex.h:281
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
uint unused
Definition qobject.h:88
QAtomicPointer< QThreadData > threadData
Definition qobject_p.h:203
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
\inmodule QtGui
void setFormat(const QSurfaceFormat &format)
Sets the format the OpenGL context should be compatible with.
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
ResolveMask resolveMask() const
Definition qpalette.cpp:999
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
Definition qpalette.cpp:963
static void clear()
Removes all pixmaps from the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPlatformCursor class provides information about pointer device events (movement,...
static Capabilities capabilities()
The QPlatformDrag class provides an abstraction for drag.
static void setInputMethodAccepted(bool accepted)
The QPlatformInputContext class abstracts the input method dependent data and composing state.
virtual void setFocusObject(QObject *object)
This virtual method gets called to notify updated focus to object.
static QPlatformIntegration * create(const QString &name, const QStringList &args, int &argc, char **argv, const QString &platformPluginPath=QString())
static QStringList keys(const QString &platformPluginPath=QString())
Returns the list of valid keys, i.e.
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
virtual QPlatformCursor * cursor() const
Reimplement this function in subclass to return the cursor of the screen.
static QPlatformTheme * create(const QString &key, const QString &platformPluginPath=QString())
The QPlatformTheme class allows customizing the UI based on themes.
The QPlatformWindow class provides an abstraction for top-level windows.
virtual bool windowEvent(QEvent *event)
Reimplement this method to be able to do any platform specific event handling.
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr void setY(int y) noexcept
Sets the y coordinate of this point to the given y coordinate.
Definition qpoint.h:145
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:140
T * data() const noexcept
Definition qpointer.h:73
bool isNull() const noexcept
Definition qpointer.h:84
static QPointingDevicePrivate * get(QPointingDevice *q)
qint64 numericId
the numeric unique ID of the token represented by a touchpoint
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
QPointingDeviceUniqueId uniqueId
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
qreal devicePixelRatio
the screen's ratio between physical pixels and device-independent pixels
Definition qscreen.h:59
QList< QScreen * > virtualSiblings() const
Get the screen's virtual siblings.
Definition qscreen.cpp:357
Qt::ScreenOrientation orientation
the screen orientation
Definition qscreen.h:62
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
The QSessionManager class provides access to the session manager.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
static QString locate(StandardLocation type, const QString &fileName, LocateOptions options=LocateFile)
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
Definition qstring.cpp:6995
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5949
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
Definition qstring.h:1309
static QStyleHintsPrivate * get(QStyleHints *q)
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
static QSurfaceFormat defaultFormat()
Returns the global default surface format.
QEventPoint & point(int touchId)
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition qurl.cpp:1896
\inmodule QtCore
Definition qvariant.h:65
\inmodule QtCore
static Q_CORE_EXPORT int compare(const QVersionNumber &v1, const QVersionNumber &v2) noexcept
Compares v1 with v2 and returns an integer less than, equal to, or greater than zero,...
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
static QWindowPrivate * get(QWindow *window)
Definition qwindow_p.h:106
static Qt::WindowState effectiveState(Qt::WindowStates)
Definition qwindow.cpp:1419
\inmodule QtGui
Definition qevent.h:899
static QList< QEventPoint > fromNativeTouchPoints(const QList< QWindowSystemInterface::TouchPoint > &points, const QWindow *window, QEvent::Type *type=nullptr)
static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Make Qt Gui process all events on the event queue immediately.
static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
static bool handleCloseEvent(QWindow *window)
static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1)
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
virtual QObject * focusObject() const
Returns the QObject that will be the final receiver of events tied focus, such as key events.
Definition qwindow.cpp:2240
Qt::WindowModality modality
the modality of the window
Definition qwindow.h:78
EGLContext ctx
EGLImageKHR int int EGLuint64KHR * modifiers
QPushButton * button
[2]
QCursor cursor
QList< QVariant > arguments
direction
fontMetrics
else opt state
[0]
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
constexpr bool isAsciiDigit(char32_t c) noexcept
Definition qtools_p.h:67
@ BottomLeftCorner
@ TopRightCorner
@ TopLeftCorner
@ BottomRightCorner
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ MaxMouseButton
Definition qnamespace.h:91
@ NoButton
Definition qnamespace.h:57
WindowModality
@ NonModal
@ WindowModal
@ ApplicationModal
LayoutDirection
@ LeftToRight
@ LayoutDirectionAuto
@ RightToLeft
@ MouseEventSynthesizedByQt
@ MouseEventNotSynthesized
CursorShape
@ gray
Definition qnamespace.h:33
@ Key_Menu
Definition qnamespace.h:727
@ Key_Back
Definition qnamespace.h:846
@ NoModifier
@ AA_SynthesizeMouseForUnhandledTabletEvents
Definition qnamespace.h:459
@ AA_DontShowShortcutsInContextMenus
Definition qnamespace.h:463
@ AA_ShareOpenGLContexts
Definition qnamespace.h:447
@ AA_SetPalette
Definition qnamespace.h:448
@ AA_SynthesizeMouseForUnhandledTouchEvents
Definition qnamespace.h:437
@ AA_SynthesizeTouchForUnhandledMouseEvents
Definition qnamespace.h:436
DropAction
@ IgnoreAction
ApplicationState
Definition qnamespace.h:262
@ ApplicationActive
Definition qnamespace.h:266
@ ApplicationInactive
Definition qnamespace.h:265
HighDpiScaleFactorRoundingPolicy
@ SkipEmptyParts
Definition qnamespace.h:128
@ Desktop
Definition qnamespace.h:215
@ ToolTip
Definition qnamespace.h:213
@ Popup
Definition qnamespace.h:211
FocusReason
@ PopupFocusReason
@ OtherFocusReason
@ ActiveWindowFocusReason
#define Q_UNLIKELY(x)
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define Q_FUNC_INFO
#define QT_WARNING_PUSH
void Q_CORE_EXPORT qt_call_post_routines()
#define qApp
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:284
bool qIsInf(qfloat16 f) noexcept
Definition qfloat16.h:283
static bool needsWindowBlockedEvent(const QWindow *w)
static void applyCursor(QWindow *w, QCursor c)
Q_CORE_EXPORT void qt_call_post_routines()
static void init_plugins(const QList< QByteArray > &pluginList)
static Q_CONSTINIT unsigned applicationResourceFlags
static void initFontUnlocked()
static void clearFontUnlocked()
static void clearOverrideCursor(const QList< QScreen * > &screens)
void qRegisterGuiVariant()
static void applyWindowCursor(const QList< QWindow * > &l)
static Q_CONSTINIT bool force_reverse
static QWindowGeometrySpecification windowGeometrySpecification
static void unsetCursor(QWindow *w)
static bool qt_detectRTLLanguage()
static bool checkNeedPortalSupport()
static Q_CONSTINIT Qt::LayoutDirection effective_layout_direction
#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER
@ MouseSourceMaskSrc
@ MouseCapsMask
@ MouseFlagsCapsMask
@ MouseSourceMaskDst
@ MouseFlagsShift
@ MouseSourceShift
static Q_CONSTINIT int mouseDoubleClickDistance
static void init_platform(const QString &pluginNamesWithArguments, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv)
static Q_CONSTINIT Qt::LayoutDirection layout_direction
static Q_CONSTINIT int touchDoubleTapDistance
static void initThemeHints()
static void applyOverrideCursor(const QList< QScreen * > &screens, const QCursor &c)
static Q_CONSTINIT QBasicMutex applicationFontMutex
static int nextGeometryToken(const QByteArray &a, int &pos, char *op)
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
#define CHECK_QAPP_INSTANCE(...)
ApplicationResourceFlags
@ ApplicationFontExplicitlySet
static void updateBlockedStatusRecursion(QWindow *window, bool shouldBeBlocked)
static Q_CONSTINIT qreal fontSmoothingGamma
void qt_cleanupFontDatabase()
#define qGuiApp
#define qApp
void qRegisterGuiGetInterpolator()
QPair< qreal, qreal > QDpi
#define qCritical
Definition qlogging.h:167
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define QT_NATIVE_INTERFACE_RETURN_IF(NativeInterface, baseType)
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
static QString themeName()
QOpenGLContext * qt_gl_global_share_context()
void qt_gl_set_global_share_context(QOpenGLContext *context)
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLuint object
[3]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
GLenum type
GLuint GLsizei const GLchar * message
GLuint name
struct _cl_event * event
GLfixed GLfixed GLint GLint GLfixed points
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint GLenum * rate
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
SSL_CTX int void * arg
#define qPrintable(string)
Definition qstring.h:1531
#define QStringLiteral(str)
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define emit
#define Q_UNUSED(x)
#define Q_TRACE_PARAM_REPLACE(in, out)
Definition qtrace_p.h:231
#define Q_TRACE_SCOPE(x,...)
Definition qtrace_p.h:146
#define Q_TRACE_INSTRUMENT(provider)
Definition qtrace_p.h:230
unsigned long ulong
Definition qtypes.h:35
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
ptrdiff_t qintptr
Definition qtypes.h:166
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2950
bool testFlag(MaskType mask, FlagType flag)
QT_BEGIN_NAMESPACE constexpr const wchar_t * themeNames[]
const char className[16]
[1]
Definition qwizard.cpp:100
QList< int > list
[14]
QObject::connect nullptr
myObject disconnect()
[26]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSizePolicy policy
QDBusArgument argument
void processTouchEvent()
[toString-overload]
Q_GUI_EXPORT QPoint toPoint() const noexcept
void applyTo(QWindow *window) const
static QWindowGeometrySpecification fromArgument(const QByteArray &a)