Qt 6.x
The Qt SDK
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
21#include <QtCore/QAbstractEventDispatcher>
22#include <QtCore/QFileInfo>
23#include <QtCore/QStandardPaths>
24#include <QtCore/QVariant>
25#include <QtCore/private/qcoreapplication_p.h>
26#include <QtCore/private/qabstracteventdispatcher_p.h>
27#include <QtCore/qmutex.h>
28#include <QtCore/private/qthread_p.h>
29#include <QtCore/private/qlocking_p.h>
30#include <QtCore/private/qflatmap_p.h>
31#include <QtCore/qdir.h>
32#include <QtCore/qlibraryinfo.h>
33#include <QtCore/private/qnumeric_p.h>
34#include <QtDebug>
35#if QT_CONFIG(accessibility)
36#include "qaccessible.h"
37#endif
38#include <qpalette.h>
39#include <qscreen.h>
40#include "qsessionmanager.h"
41#include <private/qcolortrclut_p.h>
42#include <private/qscreen_p.h>
43
44#include <QtGui/qgenericpluginfactory.h>
45#include <QtGui/qstylehints.h>
46#include <QtGui/private/qstylehints_p.h>
47#include <QtGui/qinputmethod.h>
48#include <QtGui/qpixmapcache.h>
49#include <qpa/qplatforminputcontext.h>
50#include <qpa/qplatforminputcontext_p.h>
51
52#include <qpa/qwindowsysteminterface.h>
53#include <qpa/qwindowsysteminterface_p.h>
54#include "private/qwindow_p.h"
55#include "private/qicon_p.h"
56#include "private/qcursor_p.h"
57#if QT_CONFIG(opengl)
58# include "private/qopenglcontext_p.h"
59#endif
60#include "private/qinputdevicemanager_p.h"
61#include "private/qinputmethod_p.h"
62#include "private/qpointingdevice_p.h"
63
64#include <qpa/qplatformthemefactory_p.h>
65
66#if QT_CONFIG(draganddrop)
67#include <qpa/qplatformdrag.h>
68#include <private/qdnd_p.h>
69#endif
70
71#ifndef QT_NO_CURSOR
72#include <qpa/qplatformcursor.h>
73#endif
74
75#include <QtGui/QPixmap>
76
77#ifndef QT_NO_CLIPBOARD
78#include <QtGui/QClipboard>
79#endif
80
81#if QT_CONFIG(library)
82#include <QtCore/QLibrary>
83#endif
84
85#if defined(Q_OS_MAC)
86# include "private/qcore_mac_p.h"
87#elif defined(Q_OS_WIN)
88# include <QtCore/qt_windows.h>
89# include <QtCore/QLibraryInfo>
90#endif // Q_OS_WIN
91
92#ifdef Q_OS_WASM
93#include <emscripten.h>
94#endif
95
96#if QT_CONFIG(vulkan)
97#include <private/qvulkandefaultinstance_p.h>
98#endif
99
100#include <qtgui_tracepoints_p.h>
101
102#include <private/qtools_p.h>
103
104#include <limits>
105
107
108using namespace Qt::StringLiterals;
109using namespace QtMiscUtils;
110
111// Helper macro for static functions to check on the existence of the application class.
112#define CHECK_QAPP_INSTANCE(...) \
113 if (Q_LIKELY(QCoreApplication::instance())) { \
114 } else { \
115 qWarning("Must construct a QGuiApplication first."); \
116 return __VA_ARGS__; \
117 }
118
119Q_CORE_EXPORT void qt_call_post_routines();
120Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app = false;
121
122Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
123Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
124
126
128
130
132
135
137
139
142
144
146{
149
150Q_CONSTINIT static unsigned applicationResourceFlags = 0;
151
152Q_CONSTINIT QIcon *QGuiApplicationPrivate::app_icon = nullptr;
153
155Q_CONSTINIT QString *QGuiApplicationPrivate::displayName = nullptr;
157
158Q_CONSTINIT QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
159
161
162Q_CONSTINIT static int mouseDoubleClickDistance = 0;
163Q_CONSTINIT static int touchDoubleTapDistance = 0;
164
166
169Q_CONSTINIT static bool force_reverse = false;
170
171Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
172Q_CONSTINIT int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
173
174#ifndef QT_NO_CLIPBOARD
176#endif
177
179
181Q_CONSTINIT QWindow *QGuiApplicationPrivate::focus_window = nullptr;
182
184Q_CONSTINIT QFont *QGuiApplicationPrivate::app_font = nullptr;
187
188Q_CONSTINIT QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
189
190Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
191
192Q_CONSTINIT static qreal fontSmoothingGamma = 1.7;
193
195
196extern void qRegisterGuiVariant();
197#if QT_CONFIG(animation)
198extern void qRegisterGuiGetInterpolator();
199#endif
200
202{
203 return force_reverse ^
204 (QGuiApplication::tr("QT_LAYOUT_DIRECTION",
205 "Translate this string to the string 'LTR' in left-to-right"
206 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
207 " and Arabic) to get proper widget layout.") == "RTL"_L1);
208}
209
210static void initFontUnlocked()
211{
214 if (const QFont *font = theme->font(QPlatformTheme::SystemFont))
216 }
219 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
220}
221
222static inline void clearFontUnlocked()
223{
226}
227
228static void initThemeHints()
229{
232}
233
235{
236#if QT_CONFIG(dbus)
237 return QFileInfo::exists("/.flatpak-info"_L1) || qEnvironmentVariableIsSet("SNAP");
238#else
239 return false;
240#endif // QT_CONFIG(dbus)
241}
242
243// Using aggregate initialization instead of ctor so we can have a POD global static
244#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1, -1, -1, -1 }
245
246// Geometry specification for top level windows following the convention of the
247// -geometry command line arguments in X11 (see XParseGeometry).
249{
251 void applyTo(QWindow *window) const;
252
256 int width;
258};
259
260// Parse a token of a X11 geometry specification "200x100+10-20".
261static inline int nextGeometryToken(const QByteArray &a, int &pos, char *op)
262{
263 *op = 0;
264 const qsizetype size = a.size();
265 if (pos >= size)
266 return -1;
267
268 *op = a.at(pos);
269 if (*op == '+' || *op == '-' || *op == 'x')
270 pos++;
271 else if (isAsciiDigit(*op))
272 *op = 'x'; // If it starts with a digit, it is supposed to be a width specification.
273 else
274 return -1;
275
276 const int numberPos = pos;
277 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
278
279 bool ok;
280 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
281 return ok ? result : -1;
282}
283
285{
287 int pos = 0;
288 for (int i = 0; i < 4; ++i) {
289 char op;
290 const int value = nextGeometryToken(a, pos, &op);
291 if (value < 0)
292 break;
293 switch (op) {
294 case 'x':
295 (result.width >= 0 ? result.height : result.width) = value;
296 break;
297 case '+':
298 case '-':
299 if (result.xOffset >= 0) {
300 result.yOffset = value;
301 if (op == '-')
303 } else {
304 result.xOffset = value;
305 if (op == '-')
306 result.corner = Qt::TopRightCorner;
307 }
308 }
309 }
310 return result;
311}
312
314{
315 QRect windowGeometry = window->frameGeometry();
316 QSize size = windowGeometry.size();
317 if (width >= 0 || height >= 0) {
318 const QSize windowMinimumSize = window->minimumSize();
319 const QSize windowMaximumSize = window->maximumSize();
320 if (width >= 0)
321 size.setWidth(qBound(windowMinimumSize.width(), width, windowMaximumSize.width()));
322 if (height >= 0)
323 size.setHeight(qBound(windowMinimumSize.height(), height, windowMaximumSize.height()));
324 window->resize(size);
325 }
326 if (xOffset >= 0 || yOffset >= 0) {
327 const QRect availableGeometry = window->screen()->virtualGeometry();
328 QPoint topLeft = windowGeometry.topLeft();
329 if (xOffset >= 0) {
331 xOffset :
332 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
333 }
334 if (yOffset >= 0) {
336 yOffset :
337 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
338 }
339 window->setFramePosition(topLeft);
340 }
341}
342
344
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
651{
652}
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
730{
733 if (qGuiApp) {
736
738 emit qGuiApp->applicationDisplayNameChanged();
739 }
742 if (qGuiApp)
743 emit qGuiApp->applicationDisplayNameChanged();
744 }
745}
746
748{
750}
751
772{
774}
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.first();
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
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{
894
895 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
896 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
898 }
899}
900
902{
903 return Qt::NonModal;
904}
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
970{
972}
973
997{
998 if (focusWindow())
999 return focusWindow()->focusObject();
1000 return nullptr;
1001}
1002
1013{
1015}
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
1045 }
1046
1047 return topLevelWindows;
1048}
1049
1051{
1053 return nullptr;
1055}
1056
1062{
1064}
1065
1078{
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
1202{
1205}
1206
1207Q_LOGGING_CATEGORY(lcQpaPluginLoading, "qt.qpa.plugin");
1208Q_LOGGING_CATEGORY(lcQpaTheme, "qt.qpa.theme");
1209Q_LOGGING_CATEGORY(lcPtrDispatch, "qt.pointer.dispatch");
1210
1211static void init_platform(const QString &pluginNamesWithArguments, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv)
1212{
1213 qCDebug(lcQpaPluginLoading) << "init_platform called with"
1214 << "pluginNamesWithArguments" << pluginNamesWithArguments
1215 << "platformPluginPath" << platformPluginPath
1216 << "platformThemeName" << platformThemeName;
1217
1218 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1219 QStringList platformArguments;
1220 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1221 for (const auto &pluginArgument : plugins) {
1222 // Split into platform name and arguments
1223 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1224 if (arguments.isEmpty())
1225 continue;
1226 const QString name = arguments.takeFirst().toLower();
1227 QString argumentsKey = name;
1228 if (name.isEmpty())
1229 continue;
1230 argumentsKey[0] = argumentsKey.at(0).toUpper();
1232
1233 qCDebug(lcQpaPluginLoading) << "Attempting to load Qt platform plugin" << name << "with arguments" << arguments;
1234
1235 // Create the platform integration.
1238 if (availablePlugins.contains(name)) {
1239 qCInfo(lcQpaPluginLoading).nospace().noquote()
1240 << "Could not load the Qt platform plugin \"" << name << "\" in \""
1241 << QDir::toNativeSeparators(platformPluginPath) << "\" even though it was found.";
1242 } else {
1243 qCWarning(lcQpaPluginLoading).nospace().noquote()
1244 << "Could not find the Qt platform plugin \"" << name << "\" in \""
1245 << QDir::toNativeSeparators(platformPluginPath) << "\"";
1246 }
1247 } else {
1248 qCDebug(lcQpaPluginLoading) << "Successfully loaded Qt platform plugin" << name;
1250 platformArguments = arguments;
1251 break;
1252 }
1253 }
1254
1256 QString fatalMessage = QStringLiteral("This application failed to start because no Qt platform plugin could be initialized. "
1257 "Reinstalling the application may fix this problem.\n");
1258
1259 if (!availablePlugins.isEmpty())
1260 fatalMessage += "\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(", "_L1));
1261
1262#if defined(Q_OS_WIN)
1263 // Windows: Display message box unless it is a console application
1264 // or debug build showing an assert box.
1265 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1266 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1267#endif // Q_OS_WIN
1268 qFatal("%s", qPrintable(fatalMessage));
1269
1270 return;
1271 }
1272
1273 // Create the platform theme:
1274
1275 // 1) Fetch the platform name from the environment if present.
1277 if (!platformThemeName.isEmpty()) {
1278 qCDebug(lcQpaTheme) << "Adding" << platformThemeName << "from environment to list of theme names";
1279 themeNames.append(platformThemeName);
1280 }
1281
1282 // 2) Special case - check whether it's a flatpak or snap app to use xdg-desktop-portal platform theme for portals support
1283 if (checkNeedPortalSupport()) {
1284 qCDebug(lcQpaTheme) << "Adding xdgdesktopportal to list of theme names";
1285 themeNames.append(QStringLiteral("xdgdesktopportal"));
1286 }
1287
1288 // 3) Ask the platform integration for a list of theme names
1289 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1290 qCDebug(lcQpaTheme) << "Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1291 themeNames += platformIntegrationThemeNames;
1292 // 4) Look for a theme plugin.
1293 for (const QString &themeName : std::as_const(themeNames)) {
1294 qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via QPlatformThemeFactory::create";
1297 qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
1298 break;
1299 }
1300 }
1301
1302 // 5) If no theme plugin was found ask the platform integration to
1303 // create a theme
1305 for (const QString &themeName : std::as_const(themeNames)) {
1306 qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via createPlatformTheme";
1309 qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
1310 break;
1311 }
1312 }
1313 // No error message; not having a theme plugin is allowed.
1314 }
1315
1316 // 6) Fall back on the built-in "null" platform theme.
1318 qCDebug(lcQpaTheme) << "Failed to create platform theme; using \"null\" platform theme";
1320 }
1321
1322 // Set arguments as dynamic properties on the native interface as
1323 // boolean 'foo' or strings: 'foo=bar'
1324 if (!platformArguments.isEmpty()) {
1325 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1326 for (const QString &argument : std::as_const(platformArguments)) {
1327 const qsizetype equalsPos = argument.indexOf(u'=');
1328 const QByteArray name =
1329 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1330 const QVariant value =
1331 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(true);
1332 nativeInterface->setProperty(name.constData(), value);
1333 }
1334 }
1335 }
1336
1337 const auto platformIntegration = QGuiApplicationPrivate::platformIntegration();
1338 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1340 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1341}
1342
1343static void init_plugins(const QList<QByteArray> &pluginList)
1344{
1345 for (int i = 0; i < pluginList.size(); ++i) {
1346 QByteArray pluginSpec = pluginList.at(i);
1347 qsizetype colonPos = pluginSpec.indexOf(':');
1348 QObject *plugin;
1349 if (colonPos < 0)
1351 else
1352 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1353 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1354 if (plugin)
1356 else
1357 qWarning("No such plugin for spec \"%s\"", pluginSpec.constData());
1358 }
1359}
1360
1361#if QT_CONFIG(commandlineparser)
1362void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1363{
1364 QCoreApplicationPrivate::addQtOptions(options);
1365
1366#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1367 const QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
1368 const bool x11 = sessionType == "x11";
1369 // Technically the x11 aliases are only available if platformName is "xcb", but we can't know that here.
1370#else
1371 const bool x11 = false;
1372#endif
1373
1374 options->append(QCommandLineOption(QStringLiteral("platform"),
1375 QGuiApplication::tr("QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral("platformName[:options]")));
1376 options->append(QCommandLineOption(QStringLiteral("platformpluginpath"),
1377 QGuiApplication::tr("Path to the platform plugins."), QStringLiteral("path")));
1378 options->append(QCommandLineOption(QStringLiteral("platformtheme"),
1379 QGuiApplication::tr("Platform theme."), QStringLiteral("theme")));
1380 options->append(QCommandLineOption(QStringLiteral("plugin"),
1381 QGuiApplication::tr("Additional plugins to load, can be specified multiple times."), QStringLiteral("plugin")));
1382 options->append(QCommandLineOption(QStringLiteral("qwindowgeometry"),
1383 QGuiApplication::tr("Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral("geometry")));
1384 options->append(QCommandLineOption(QStringLiteral("qwindowicon"),
1385 QGuiApplication::tr("Default window icon."), QStringLiteral("icon")));
1386 options->append(QCommandLineOption(QStringLiteral("qwindowtitle"),
1387 QGuiApplication::tr("Title of the first window."), QStringLiteral("title")));
1388 options->append(QCommandLineOption(QStringLiteral("reverse"),
1389 QGuiApplication::tr("Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1390 options->append(QCommandLineOption(QStringLiteral("session"),
1391 QGuiApplication::tr("Restores the application from an earlier session."), QStringLiteral("session")));
1392
1393 if (x11) {
1394 options->append(QCommandLineOption(QStringLiteral("display"),
1395 QGuiApplication::tr("Display name, overrides $DISPLAY."), QStringLiteral("display")));
1396 options->append(QCommandLineOption(QStringLiteral("name"),
1397 QGuiApplication::tr("Instance name according to ICCCM 4.1.2.5."), QStringLiteral("name")));
1398 options->append(QCommandLineOption(QStringLiteral("nograb"),
1399 QGuiApplication::tr("Disable mouse grabbing (useful in debuggers).")));
1400 options->append(QCommandLineOption(QStringLiteral("dograb"),
1401 QGuiApplication::tr("Force mouse grabbing (even when running in a debugger).")));
1402 options->append(QCommandLineOption(QStringLiteral("visual"),
1403 QGuiApplication::tr("ID of the X11 Visual to use."), QStringLiteral("id")));
1404 // Not using the "QStringList names" solution for those aliases, because it makes the first column too wide
1405 options->append(QCommandLineOption(QStringLiteral("geometry"),
1406 QGuiApplication::tr("Alias for --qwindowgeometry."), QStringLiteral("geometry")));
1407 options->append(QCommandLineOption(QStringLiteral("icon"),
1408 QGuiApplication::tr("Alias for --qwindowicon."), QStringLiteral("icon")));
1409 options->append(QCommandLineOption(QStringLiteral("title"),
1410 QGuiApplication::tr("Alias for --qwindowtitle."), QStringLiteral("title")));
1411 }
1412}
1413#endif // QT_CONFIG(commandlineparser)
1414
1416{
1418
1419 // Load the platform integration
1420 QString platformPluginPath = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH"));
1421
1422
1423 QByteArray platformName;
1424#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1425 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1426#endif
1427#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1428 QList<QByteArray> platformArguments = platformName.split(':');
1429 QByteArray platformPluginBase = platformArguments.first();
1430
1431 const bool hasWaylandDisplay = qEnvironmentVariableIsSet("WAYLAND_DISPLAY");
1432 const bool isWaylandSessionType = qgetenv("XDG_SESSION_TYPE") == "wayland";
1433
1434 QVector<QByteArray> preferredPlatformOrder;
1435 const bool defaultIsXcb = platformPluginBase == "xcb";
1436 const QByteArray xcbPlatformName = defaultIsXcb ? platformName : "xcb";
1437 if (qEnvironmentVariableIsSet("DISPLAY")) {
1438 preferredPlatformOrder << xcbPlatformName;
1439 if (defaultIsXcb)
1440 platformName.clear();
1441 }
1442
1443 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith("wayland");
1444 const QByteArray waylandPlatformName = defaultIsWayland ? platformName : "wayland";
1445 if (hasWaylandDisplay || isWaylandSessionType) {
1446 preferredPlatformOrder.prepend(waylandPlatformName);
1447
1448 if (defaultIsWayland)
1449 platformName.clear();
1450 }
1451
1452 if (!platformName.isEmpty())
1453 preferredPlatformOrder.append(platformName);
1454
1455 platformName = preferredPlatformOrder.join(';');
1456#endif
1457
1458 bool platformExplicitlySelected = false;
1459 QByteArray platformNameEnv = qgetenv("QT_QPA_PLATFORM");
1460 if (!platformNameEnv.isEmpty()) {
1461 platformName = platformNameEnv;
1462 platformExplicitlySelected = true;
1463 }
1464
1465 QString platformThemeName = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORMTHEME"));
1466
1467 // Get command line params
1468
1469 QString icon;
1470
1471 int j = argc ? 1 : 0;
1472 for (int i=1; i<argc; i++) {
1473 if (!argv[i])
1474 continue;
1475 if (*argv[i] != '-') {
1476 argv[j++] = argv[i];
1477 continue;
1478 }
1479 const bool xcbIsDefault = platformName.startsWith("xcb");
1480 const char *arg = argv[i];
1481 if (arg[1] == '-') // startsWith("--")
1482 ++arg;
1483 if (strcmp(arg, "-platformpluginpath") == 0) {
1484 if (++i < argc)
1485 platformPluginPath = QFile::decodeName(argv[i]);
1486 } else if (strcmp(arg, "-platform") == 0) {
1487 if (++i < argc) {
1488 platformExplicitlySelected = true;
1489 platformName = argv[i];
1490 }
1491 } else if (strcmp(arg, "-platformtheme") == 0) {
1492 if (++i < argc)
1493 platformThemeName = QString::fromLocal8Bit(argv[i]);
1494 } else if (strcmp(arg, "-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg, "-geometry") == 0)) {
1495 if (++i < argc)
1497 } else if (strcmp(arg, "-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg, "-title") == 0)) {
1498 if (++i < argc)
1500 } else if (strcmp(arg, "-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg, "-icon") == 0)) {
1501 if (++i < argc) {
1503 }
1504 } else {
1505 argv[j++] = argv[i];
1506 }
1507 }
1508
1509 if (j < argc) {
1510 argv[j] = nullptr;
1511 argc = j;
1512 }
1513
1514 Q_UNUSED(platformExplicitlySelected);
1515
1516 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1517 if (const QPlatformTheme *theme = platformTheme())
1519
1520 if (!icon.isEmpty())
1522}
1523
1531{
1533
1534 if (platform_integration == nullptr)
1536
1537 // The platform integration should not result in creating an event dispatcher
1538 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher, "QGuiApplication",
1539 "Creating the platform integration resulted in creating an event dispatcher");
1540
1541 // Nor should it mess with the QCoreApplication's event dispatcher
1543
1545}
1546
1548{
1549 if (platform_integration == nullptr)
1551
1553}
1554
1556{
1557 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1558
1559#if defined(Q_OS_MACOS)
1561#endif
1562
1564
1565 QCoreApplicationPrivate::is_app_running = false; // Starting up.
1566
1567 bool loadTestability = false;
1568 QList<QByteArray> pluginList;
1569 // Get command line params
1570#ifndef QT_NO_SESSIONMANAGER
1571 QString session_id;
1572 QString session_key;
1573# if defined(Q_OS_WIN)
1574 wchar_t guidstr[40];
1575 GUID guid;
1576 CoCreateGuid(&guid);
1577 StringFromGUID2(guid, guidstr, 40);
1578 session_id = QString::fromWCharArray(guidstr);
1579 CoCreateGuid(&guid);
1580 StringFromGUID2(guid, guidstr, 40);
1581 session_key = QString::fromWCharArray(guidstr);
1582# endif
1583#endif
1584 QString s;
1585 int j = argc ? 1 : 0;
1586 for (int i=1; i<argc; i++) {
1587 if (!argv[i])
1588 continue;
1589 if (*argv[i] != '-') {
1590 argv[j++] = argv[i];
1591 continue;
1592 }
1593 const char *arg = argv[i];
1594 if (arg[1] == '-') // startsWith("--")
1595 ++arg;
1596 if (strcmp(arg, "-plugin") == 0) {
1597 if (++i < argc)
1598 pluginList << argv[i];
1599 } else if (strcmp(arg, "-reverse") == 0) {
1600 force_reverse = true;
1601#ifdef Q_OS_MAC
1602 } else if (strncmp(arg, "-psn_", 5) == 0) {
1603 // eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder.
1604 // special hack to change working directory (for an app bundle) when running from finder
1605 if (QDir::currentPath() == "/"_L1) {
1606 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1607 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1608 kCFURLPOSIXPathStyle));
1609 if (qbundlePath.endsWith(".app"_L1))
1610 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1611 }
1612#endif
1613#ifndef QT_NO_SESSIONMANAGER
1614 } else if (strcmp(arg, "-session") == 0 && i < argc - 1) {
1615 ++i;
1616 if (argv[i] && *argv[i]) {
1617 session_id = QString::fromLatin1(argv[i]);
1618 qsizetype p = session_id.indexOf(u'_');
1619 if (p >= 0) {
1620 session_key = session_id.mid(p +1);
1621 session_id = session_id.left(p);
1622 }
1623 is_session_restored = true;
1624 }
1625#endif
1626 } else if (strcmp(arg, "-testability") == 0) {
1627 loadTestability = true;
1628 } else if (strncmp(arg, "-style=", 7) == 0) {
1630 } else if (strcmp(arg, "-style") == 0 && i < argc - 1) {
1632 } else {
1633 argv[j++] = argv[i];
1634 }
1635
1636 if (!s.isEmpty())
1637 styleOverride = s;
1638 }
1639
1640 if (j < argc) {
1641 argv[j] = nullptr;
1642 argc = j;
1643 }
1644
1645 // Load environment exported generic plugins
1646 QByteArray envPlugins = qgetenv("QT_QPA_GENERIC_PLUGINS");
1647 if (!envPlugins.isEmpty())
1648 pluginList += envPlugins.split(',');
1649
1650 if (platform_integration == nullptr)
1652
1653 updatePalette();
1656
1657#ifndef QT_NO_CURSOR
1659#endif
1660
1661 // trigger registering of QVariant's GUI types
1663
1664#if QT_CONFIG(animation)
1665 // trigger registering of animation interpolators
1667#endif
1668
1669 // set a global share context when enabled unless there is already one
1670#ifndef QT_NO_OPENGL
1674 ctx->create();
1676 ownGlobalShareContext = true;
1677 }
1678#endif
1679
1681
1682 is_app_running = true;
1683 init_plugins(pluginList);
1685
1686 Q_Q(QGuiApplication);
1687#ifndef QT_NO_SESSIONMANAGER
1688 // connect to the session manager
1689 session_manager = new QSessionManager(q, session_id, session_key);
1690#endif
1691
1692#if QT_CONFIG(library)
1693 if (qEnvironmentVariableIntValue("QT_LOAD_TESTABILITY") > 0)
1694 loadTestability = true;
1695
1696 if (loadTestability) {
1697 QLibrary testLib(QStringLiteral("qttestability"));
1698 if (Q_UNLIKELY(!testLib.load())) {
1699 qCritical() << "Library qttestability load failed:" << testLib.errorString();
1700 } else {
1701 typedef void (*TasInitialize)(void);
1702 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
1703 if (Q_UNLIKELY(!initFunction)) {
1704 qCritical("Library qttestability resolve failed!");
1705 } else {
1706 initFunction();
1707 }
1708 }
1709 }
1710#else
1711 Q_UNUSED(loadTestability);
1712#endif // QT_CONFIG(library)
1713
1714 // trigger changed signal and event delivery
1716
1720}
1721
1722extern void qt_cleanupFontDatabase();
1723
1725{
1726 is_app_closing = true;
1727 is_app_running = false;
1728
1729 for (int i = 0; i < generic_plugin_list.size(); ++i)
1730 delete generic_plugin_list.at(i);
1732
1734
1736
1737#ifndef QT_NO_CURSOR
1739#endif
1740
1742
1744
1747 delete inputMethod;
1748
1750
1752
1753#ifndef QT_NO_OPENGL
1754 if (ownGlobalShareContext) {
1757 }
1758#endif
1759
1760#if QT_CONFIG(vulkan)
1761 QVulkanDefaultInstance::cleanup();
1762#endif
1763
1765
1766 delete platform_theme;
1767 platform_theme = nullptr;
1768 delete platform_integration;
1769 platform_integration = nullptr;
1770
1773
1774 self = nullptr;
1775}
1776
1777#if 0
1778#ifndef QT_NO_CURSOR
1779QCursor *overrideCursor();
1780void setOverrideCursor(const QCursor &);
1781void changeOverrideCursor(const QCursor &);
1782void restoreOverrideCursor();
1783#endif
1784
1785static QFont font();
1786static QFont font(const QWidget*);
1787static QFont font(const char *className);
1788static void setFont(const QFont &, const char *className = nullptr);
1789static QFontMetrics fontMetrics();
1790
1791#ifndef QT_NO_CLIPBOARD
1792static QClipboard *clipboard();
1793#endif
1794#endif
1795
1810{
1812}
1813
1831{
1832 CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers{})
1834 return pi->queryKeyboardModifiers();
1835}
1836
1851{
1853}
1854
1861{
1863 return pi ? pi->nativeInterface() : nullptr;
1864}
1865
1870QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
1871{
1873 if (!pi) {
1874 qWarning("QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1875 return nullptr;
1876 }
1877
1878 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) : nullptr;
1879}
1880
1905{
1906#if QT_CONFIG(accessibility)
1907 QAccessible::setRootObject(qApp);
1908#endif
1909 return QCoreApplication::exec();
1910}
1911
1913{
1914 if (e->spontaneous()) {
1915 // Capture the current mouse and keyboard states. Doing so here is
1916 // required in order to support Qt Test synthesized events. Real mouse
1917 // and keyboard state updates from the platform plugin are managed by
1918 // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
1919 // ### FIXME: Qt Test should not call qapp->notify(), but rather route
1920 // the events through the proper QPA interface. This is required to
1921 // properly generate all other events such as enter/leave etc.
1922 switch (e->type()) {
1924 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1927 break;
1928 }
1930 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1933 break;
1934 }
1936 QMouseEvent *me = static_cast<QMouseEvent *>(e);
1939 break;
1940 }
1941 case QEvent::KeyPress:
1942 case QEvent::KeyRelease:
1943 case QEvent::MouseMove:
1944#if QT_CONFIG(wheelevent)
1945 case QEvent::Wheel:
1946#endif
1947 case QEvent::TouchBegin:
1949 case QEvent::TouchEnd:
1950#if QT_CONFIG(tabletevent)
1951 case QEvent::TabletMove:
1954#endif
1955 {
1956 QInputEvent *ie = static_cast<QInputEvent *>(e);
1958 break;
1959 }
1960 default:
1961 break;
1962 }
1963 }
1964}
1965
1969{
1970 if (object->isWindowType()) {
1972 return true; // Platform plugin ate the event
1973 }
1974
1976
1977 return QCoreApplication::notify(object, event);
1978}
1979
1983{
1984 if (e->type() == QEvent::LanguageChange) {
1985 // if the layout direction was set explicitly, then don't override it here
1988 for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
1989 if (topLevelWindow->flags() != Qt::Desktop)
1990 postEvent(topLevelWindow, new QEvent(QEvent::LanguageChange));
1991 }
1992 } else if (e->type() == QEvent::ApplicationFontChange ||
1994 for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
1995 if (topLevelWindow->flags() != Qt::Desktop)
1996 postEvent(topLevelWindow, new QEvent(e->type()));
1997 }
1998 } else if (e->type() == QEvent::Quit) {
1999 // Close open windows. This is done in order to deliver de-expose
2000 // events while the event loop is still running.
2001 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2002 // Already closed windows will not have a platform window, skip those
2003 if (!topLevelWindow->handle())
2004 continue;
2005 if (!topLevelWindow->close()) {
2006 e->ignore();
2007 return true;
2008 }
2009 }
2010 }
2011
2012 return QCoreApplication::event(e);
2013}
2014
2019{
2020 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2021}
2022
2024{
2025 if (!window)
2026 return false;
2027 QPlatformWindow *platformWindow = window->handle();
2028 if (!platformWindow)
2029 return false;
2030 // spontaneous events come from the platform integration already, we don't need to send the events back
2031 if (event->spontaneous())
2032 return false;
2033 // let the platform window do any handling it needs to as well
2034 return platformWindow->windowEvent(event);
2035}
2036
2038{
2039 return window->nativeEvent(eventType, message, result);
2040}
2041
2043{
2045 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2046
2047 switch(e->type) {
2050 break;
2053 break;
2056 break;
2059 break;
2062 break;
2065 break;
2068 break;
2071 break;
2074 break;
2077 break;
2080 break;
2083 break;
2087 break;
2090 break;
2094 break;
2098 break;
2102 break;
2106 break;
2110 break;
2114 break;
2118 break;
2121 break;
2124 break;
2128 break;
2132 break;
2136 break;
2137#ifndef QT_NO_GESTURES
2141 break;
2142#endif
2146 break;
2150 break;
2151#ifndef QT_NO_CONTEXTMENU
2155 break;
2156#endif
2159 break;
2160 default:
2161 qWarning() << "Unknown user input event type:" << e->type;
2162 break;
2163 }
2164}
2165
2179{
2182 QWindow *window = e->window.data();
2183 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2186 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2187 bool mouseMove = false;
2188 bool mousePress = false;
2189 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2190 QPointF globalPoint = e->globalPos;
2191
2192 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2193 qWarning("QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2194 return;
2195 }
2196
2197 type = e->buttonType;
2198 button = e->button;
2199
2201 mouseMove = true;
2203 mousePress = true;
2204
2205 if (!mouseMove && positionChanged) {
2207 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2209 e->source, e->nonClientArea);
2210 if (e->synthetic())
2212 processMouseEvent(&moveEvent); // mouse move excluding state change
2213 processMouseEvent(e); // the original mouse event
2214 return;
2215 }
2216 if (type == QEvent::MouseMove && !positionChanged) {
2217 // On Windows, and possibly other platforms, a touchpad can send a mouse move
2218 // that does not change position, between a press and a release. This may
2219 // confuse applications, so we always filter out these mouse events for
2220 // consistent behavior among platforms.
2221 return;
2222 }
2223
2224 modifier_buttons = e->modifiers;
2225 QPointF localPoint = e->localPos;
2226 bool doubleClick = false;
2227 auto persistentEPD = devPriv->pointById(0);
2228
2229 if (mouseMove) {
2231 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2233 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2234 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2235 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2237 } else {
2238 mouse_buttons = e->buttons;
2239 if (mousePress) {
2240 ulong doubleClickInterval = static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2241 doubleClick = e->timestamp - persistentEPD->eventPoint.pressTimestamp()
2242 < doubleClickInterval && button == mousePressButton;
2244 }
2245 }
2246
2247 if (e->nullWindow()) {
2249 if (window) {
2250 // Moves and the release following a press must go to the same
2251 // window, even if the cursor has moved on over another window.
2252 if (e->buttons != Qt::NoButton) {
2255 else
2257 } else if (currentMousePressWindow) {
2259 currentMousePressWindow = nullptr;
2260 }
2261 localPoint = window->mapFromGlobal(globalPoint);
2262 }
2263 }
2264
2265 if (!window)
2266 return;
2267
2268#ifndef QT_NO_CURSOR
2269 if (!e->synthetic()) {
2270 if (const QScreen *screen = window->screen())
2271 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2272 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2273 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2274 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2275 button, e->buttons, e->modifiers, e->source, device);
2276 // avoid incorrect velocity calculation: ev is in the native coordinate system,
2277 // but we need to consistently use the logical coordinate system for velocity
2278 // whenever QEventPoint::setTimestamp() is called
2279 ev.QInputEvent::setTimestamp(e->timestamp);
2280 cursor->pointerEvent(ev);
2281 }
2282 }
2283#endif
2284
2285 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2286 Q_ASSERT(devPriv->pointById(0) == persistentEPD); // we don't expect reallocation in QPlatformCursor::pointerEvenmt()
2287 // restore globalLastPosition to avoid invalidating the velocity calculations,
2288 // because the QPlatformCursor mouse event above was in native coordinates
2289 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2290 persistentEPD = nullptr; // incoming and synth events can cause reallocation during delivery, so don't use this again
2291 // ev now contains a detached copy of the QEventPoint from QPointingDevicePrivate::activePoints
2292 ev.setTimestamp(e->timestamp);
2293 if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
2294 // a modal window is blocking this window, don't allow mouse events through
2295 return;
2296 }
2297
2298 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2299 // QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
2301 }
2302
2303 QGuiApplication::sendSpontaneousEvent(window, &ev);
2304 e->eventAccepted = ev.isAccepted();
2305 if (!e->synthetic() && !ev.isAccepted()
2306 && !e->nonClientArea
2310 point.id = 1;
2311 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2312
2313 // only translate left button related events to
2314 // avoid strange touch event sequences when several
2315 // buttons are pressed
2320 } else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2322 } else {
2323 return;
2324 }
2325
2326 points << point;
2327
2329 const QList<QEventPoint> &touchPoints =
2331
2332 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2334 processTouchEvent(&fake);
2335 }
2336 if (doubleClick) {
2338 if (!e->window.isNull() || e->nullWindow()) { // QTBUG-36364, check if window closed in response to press
2340 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2341 button, e->buttons, e->modifiers, e->source, device);
2342 dblClickEvent.setTimestamp(e->timestamp);
2343 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2344 }
2345 }
2346 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2347 if (auto *persistentEPD = devPriv->queryPointById(0)) {
2348 ev.setExclusiveGrabber(persistentEPD->eventPoint, nullptr);
2349 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2350 }
2351 }
2352}
2353
2355{
2356#if QT_CONFIG(wheelevent)
2357 QWindow *window = e->window.data();
2358 QPointF globalPoint = e->globalPos;
2359 QPointF localPoint = e->localPos;
2360
2361 if (e->nullWindow()) {
2363 if (window)
2364 localPoint = window->mapFromGlobal(globalPoint);
2365 }
2366
2367 if (!window)
2368 return;
2369
2371 modifier_buttons = e->modifiers;
2372
2373 if (window->d_func()->blockedByModalWindow) {
2374 // a modal window is blocking this window, don't allow wheel events through
2375 return;
2376 }
2377
2378 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2379 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2380 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2381 ev.setTimestamp(e->timestamp);
2382 QGuiApplication::sendSpontaneousEvent(window, &ev);
2383 e->eventAccepted = ev.isAccepted();
2384#else
2385 Q_UNUSED(e);
2386#endif // QT_CONFIG(wheelevent)
2387}
2388
2390{
2391 QWindow *window = e->window.data();
2392 modifier_buttons = e->modifiers;
2393 if (e->nullWindow()
2394#ifdef Q_OS_ANDROID
2395 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2396#endif
2397 ) {
2399 }
2400
2401#if defined(Q_OS_ANDROID)
2402 static bool backKeyPressAccepted = false;
2403 static bool menuKeyPressAccepted = false;
2404#endif
2405
2406#if !defined(Q_OS_MACOS)
2407 // FIXME: Include OS X in this code path by passing the key event through
2408 // QPlatformInputContext::filterEvent().
2409 if (e->keyType == QEvent::KeyPress && window) {
2410 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2411 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2412#if defined(Q_OS_ANDROID)
2413 backKeyPressAccepted = e->key == Qt::Key_Back;
2414 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2415#endif
2416 return;
2417 }
2418 }
2419#endif
2420
2421 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2422 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2423 e->unicode, e->repeat, e->repeatCount);
2424 ev.setTimestamp(e->timestamp);
2425
2426 // only deliver key events when we have a window, and no modal window is blocking this window
2427
2428 if (window && !window->d_func()->blockedByModalWindow)
2429 QGuiApplication::sendSpontaneousEvent(window, &ev);
2430#ifdef Q_OS_ANDROID
2431 else
2432 ev.setAccepted(false);
2433
2434 if (e->keyType == QEvent::KeyPress) {
2435 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2436 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2437 } else if (e->keyType == QEvent::KeyRelease) {
2438 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2439 if (window)
2441 } else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2443 }
2444 }
2445#endif
2446 e->eventAccepted = ev.isAccepted();
2447}
2448
2450{
2451 if (!e->enter)
2452 return;
2453 if (e->enter.data()->d_func()->blockedByModalWindow) {
2454 // a modal window is blocking this window, don't allow enter events through
2455 return;
2456 }
2457
2458 currentMouseWindow = e->enter;
2459
2460 // TODO later: EnterEvent must report _which_ mouse entered the window; for now we assume primaryPointingDevice()
2461 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2462
2463 // Since we don't always track mouse moves that occur outside a window, any residual velocity
2464 // stored in the persistent QEventPoint may be inaccurate (especially in fast-moving autotests).
2465 // Reset the Kalman filter so that the velocity of the first mouse event after entering the window
2466 // will be based on a zero residual velocity (but the result can still be non-zero if the mouse
2467 // moves to a different position from where this enter event occurred; tests often do that).
2468 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2469 auto epd = devPriv->queryPointById(event.points().first().id());
2470 Q_ASSERT(epd);
2471 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2472
2473 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2474}
2475
2477{
2478 if (!e->leave)
2479 return;
2480 if (e->leave.data()->d_func()->blockedByModalWindow) {
2481 // a modal window is blocking this window, don't allow leave events through
2482 return;
2483 }
2484
2485 currentMouseWindow = nullptr;
2486
2488 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2489}
2490
2492{
2494 QWindow *newFocus = e->activated.data();
2495
2496 if (previous == newFocus)
2497 return;
2498
2499 if (newFocus)
2500 if (QPlatformWindow *platformWindow = newFocus->handle())
2501 if (platformWindow->isAlertState())
2502 platformWindow->setAlertState(false);
2503
2504 QObject *previousFocusObject = previous ? previous->focusObject() : nullptr;
2505
2506 if (previous) {
2507 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2508 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2509 }
2510
2512 if (!qApp)
2513 return;
2514
2515 if (previous) {
2516 Qt::FocusReason r = e->reason;
2518 newFocus && (newFocus->flags() & Qt::Popup) == Qt::Popup)
2520 QFocusEvent focusOut(QEvent::FocusOut, r);
2521 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2522 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2524 } else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2526 }
2527
2529 Qt::FocusReason r = e->reason;
2531 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2533 QFocusEvent focusIn(QEvent::FocusIn, r);
2534 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2537 } else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2539 }
2540
2541 if (self) {
2542 self->notifyActiveWindowChange(previous);
2543
2544 if (previousFocusObject != qApp->focusObject() ||
2545 // We are getting an activation change but there is no new focusObject, and we also
2546 // don't have a previousFocusObject in the previously active window anymore. This can
2547 // happen when window gets destroyed (see QWidgetWindow::focusObject returning nullptr
2548 // when already in the QWidget destructor), so update the focusObject to avoid dangling
2549 // pointers. See also QWidget::clearFocus(), which tries to cover for this as well.
2550 (previous && previousFocusObject == nullptr && qApp->focusObject() == nullptr)) {
2551 self->_q_updateFocusObject(qApp->focusObject());
2552 }
2553 }
2554
2555 emit qApp->focusWindowChanged(newFocus);
2556 if (previous)
2557 emit previous->activeChanged();
2558 if (newFocus)
2559 emit newFocus->activeChanged();
2560}
2561
2563{
2564 if (QWindow *window = wse->window.data()) {
2565 QWindowPrivate *windowPrivate = qt_window_private(window);
2566 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2567
2568 windowPrivate->windowState = wse->newState;
2569 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2570 if (newEffectiveState != originalEffectiveState)
2571 emit window->windowStateChanged(newEffectiveState);
2572
2573 windowPrivate->updateVisibility();
2574
2576 QGuiApplication::sendSpontaneousEvent(window, &e);
2577 }
2578}
2579
2581{
2582 if (QWindow *window = wse->window.data()) {
2583 if (window->screen() == wse->screen.data())
2584 return;
2585
2586 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2587 if (QScreen *screen = wse->screen.data())
2588 topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */);
2589 else // Fall back to default behavior, and try to find some appropriate screen
2590 topLevelWindow->setScreen(nullptr);
2591 }
2592
2593 // We may have changed scaling; trigger resize event if needed,
2594 // except on Windows, where we send resize events during WM_DPICHANGED
2595 // event handling. FIXME: unify DPI change handling across all platforms.
2596#ifndef Q_OS_WIN
2597 if (window->handle()) {
2600 }
2601#endif
2603 }
2604}
2605
2607{
2608 if (wde->window.isNull())
2609 return;
2611}
2612
2614{
2615 if (wse->window.isNull())
2616 return;
2617
2618 // Handle by forwarding directly to QWindowPrivate, instead of sending spontaneous
2619 // QEvent like most other functions, as there's no QEvent type for the safe area
2620 // change, and we don't want to add one until we know that this is a good API.
2622}
2623
2625{
2626 if (self)
2627 self->handleThemeChanged();
2628
2630
2632
2633 QEvent themeChangeEvent(QEvent::ThemeChange);
2634 const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list;
2635 for (auto *window : windows)
2636 QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent);
2637}
2638
2646{
2649}
2650
2652{
2653 updatePalette();
2654
2657
2659 const auto locker = qt_scoped_lock(applicationFontMutex);
2662 }
2664}
2665
2667{
2668 if (e->window.isNull())
2669 return;
2670
2671 QWindow *window = e->window.data();
2672 if (!window)
2673 return;
2674
2675 const QRect lastReportedGeometry = window->d_func()->geometry;
2676 const QRect requestedGeometry = e->requestedGeometry;
2677 const QRect actualGeometry = e->newGeometry;
2678
2679 // We send size and move events only if the geometry has changed from
2680 // what was last reported, or if the user tried to set a new geometry,
2681 // but the window manager responded by keeping the old geometry. In the
2682 // latter case we send move/resize events with the same geometry as the
2683 // last reported geometry, to indicate that the window wasn't moved or
2684 // resized. Note that this logic does not apply to the property changes
2685 // of the window, as we don't treat them as part of this request/response
2686 // protocol of QWindow/QPA.
2687 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2688 || requestedGeometry.size() != actualGeometry.size();
2689 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2690 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2691
2692 window->d_func()->geometry = actualGeometry;
2693
2694 if (isResize || window->d_func()->resizeEventPending) {
2695 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2696 QGuiApplication::sendSpontaneousEvent(window, &e);
2697
2698 window->d_func()->resizeEventPending = false;
2699
2700 if (actualGeometry.width() != lastReportedGeometry.width())
2701 emit window->widthChanged(actualGeometry.width());
2702 if (actualGeometry.height() != lastReportedGeometry.height())
2703 emit window->heightChanged(actualGeometry.height());
2704 }
2705
2706 if (isMove) {
2707 //### frame geometry
2708 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2709 QGuiApplication::sendSpontaneousEvent(window, &e);
2710
2711 if (actualGeometry.x() != lastReportedGeometry.x())
2712 emit window->xChanged(actualGeometry.x());
2713 if (actualGeometry.y() != lastReportedGeometry.y())
2714 emit window->yChanged(actualGeometry.y());
2715 }
2716}
2717
2719{
2720 if (e->window.isNull())
2721 return;
2722 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2723 // a modal window is blocking this window, don't allow close events through, unless they
2724 // originate from a call to QWindow::close.
2725 e->eventAccepted = false;
2726 return;
2727 }
2728
2730 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2731
2732 e->eventAccepted = event.isAccepted();
2733}
2734
2736{
2737 if (e->url.isEmpty())
2738 return;
2739
2740 QFileOpenEvent event(e->url);
2741 QGuiApplication::sendSpontaneousEvent(qApp, &event);
2742}
2743
2745{
2746 for (int i = 0; i < tabletDevicePoints.size(); ++i) {
2747 TabletPointData &pointData = tabletDevicePoints[i];
2748 if (pointData.deviceId == deviceId)
2749 return pointData;
2750 }
2751
2752 tabletDevicePoints.append(TabletPointData(deviceId));
2753 return tabletDevicePoints.last();
2754}
2755
2757{
2758#if QT_CONFIG(tabletevent)
2759 const auto device = static_cast<const QPointingDevice *>(e->device);
2760 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2761
2763 if (e->buttons != pointData.state)
2764 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2765
2766 QWindow *window = e->window.data();
2767 modifier_buttons = e->modifiers;
2768
2769 bool localValid = true;
2770 // If window is null, pick one based on the global position and make sure all
2771 // subsequent events up to the release are delivered to that same window.
2772 // If window is given, just send to that.
2773 if (type == QEvent::TabletPress) {
2774 if (e->nullWindow()) {
2775 window = QGuiApplication::topLevelAt(e->global.toPoint());
2776 localValid = false;
2777 }
2778 if (!window)
2779 return;
2780 pointData.target = window;
2781 } else {
2782 if (e->nullWindow()) {
2783 window = pointData.target;
2784 localValid = false;
2785 }
2787 pointData.target = nullptr;
2788 if (!window)
2789 return;
2790 }
2791 QPointF local = e->local;
2792 if (!localValid) {
2793 QPointF delta = e->global - e->global.toPoint();
2794 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2795 }
2796
2797 // TODO stop deducing the button state change here: rather require it from the platform plugin, as with mouse events
2798 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2800 for (int check = Qt::LeftButton; check <= int(Qt::MaxMouseButton); check = check << 1) {
2801 if (check & stateChange) {
2802 button = Qt::MouseButton(check);
2803 break;
2804 }
2805 }
2806
2807 QTabletEvent tabletEvent(type, device, local, e->global,
2808 e->pressure, e->xTilt, e->yTilt,
2809 e->tangentialPressure, e->rotation, e->z,
2810 e->modifiers, button, e->buttons);
2811 tabletEvent.setAccepted(false);
2812 tabletEvent.setTimestamp(e->timestamp);
2813 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
2814 pointData.state = e->buttons;
2815 if (!tabletEvent.isAccepted()
2818
2819 const QEvent::Type mouseType = [&]() {
2820 switch (type) {
2824 default: Q_UNREACHABLE();
2825 }
2826 }();
2827 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
2828 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized, false, device);
2830 qCDebug(lcPtrDispatch) << "synthesizing mouse from tablet event" << mouseType
2831 << e->local << button << e->buttons << e->modifiers;
2832 processMouseEvent(&mouseEvent);
2833 }
2834#else
2835 Q_UNUSED(e);
2836#endif
2837}
2838
2840{
2841#if QT_CONFIG(tabletevent)
2842 const QPointingDevice *dev = static_cast<const QPointingDevice *>(e->device);
2843 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
2844 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
2846 ev.setTimestamp(e->timestamp);
2847 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
2848#else
2849 Q_UNUSED(e);
2850#endif
2851}
2852
2854{
2855#if QT_CONFIG(tabletevent)
2856 const QPointingDevice *dev = static_cast<const QPointingDevice *>(e->device);
2857 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
2858 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
2860 ev.setTimestamp(e->timestamp);
2861 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
2862#else
2863 Q_UNUSED(e);
2864#endif
2865}
2866
2867#ifndef QT_NO_GESTURES
2869{
2870 if (e->window.isNull())
2871 return;
2872
2873 const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
2874 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
2875 e->delta, e->sequenceId);
2876 ev.setTimestamp(e->timestamp);
2877 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
2878}
2879#endif // QT_NO_GESTURES
2880
2882{
2883 if (!e->window)
2884 return;
2885
2886 if (e->window->d_func()->blockedByModalWindow) {
2887 // a modal window is blocking this window, don't allow events through
2888 return;
2889 }
2890
2892 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
2893}
2894
2895#ifndef QT_NO_CONTEXTMENU
2897{
2898 // Widgets do not care about mouse triggered context menu events. Also, do not forward event
2899 // to a window blocked by a modal window.
2900 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
2901 return;
2902
2903 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
2904 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
2905}
2906#endif
2907
2909{
2911 return;
2912
2913 modifier_buttons = e->modifiers;
2914 QPointingDevice *device = const_cast<QPointingDevice *>(static_cast<const QPointingDevice *>(e->device));
2916
2917 if (e->touchType == QEvent::TouchCancel) {
2918 // The touch sequence has been canceled (e.g. by the compositor).
2919 // Send the TouchCancel to all windows with active touches and clean up.
2920 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
2921 touchEvent.setTimestamp(e->timestamp);
2922 QSet<QWindow *> windowsNeedingCancel;
2923
2924 for (auto &epd : devPriv->activePoints.values()) {
2925 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
2926 windowsNeedingCancel.insert(w);
2927 }
2928
2929 for (QSet<QWindow *>::const_iterator winIt = windowsNeedingCancel.constBegin(),
2930 winItEnd = windowsNeedingCancel.constEnd(); winIt != winItEnd; ++winIt) {
2931 QGuiApplication::sendSpontaneousEvent(*winIt, &touchEvent);
2932 }
2933 if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
2935 synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
2936 if (!synthIt->window)
2937 continue;
2938 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
2939 e->timestamp,
2940 synthIt->pos,
2941 synthIt->screenPos,
2943 e->modifiers,
2947 false,
2948 device);
2950 processMouseEvent(&fake);
2951 }
2952 self->synthesizedMousePoints.clear();
2953 }
2954 self->lastTouchType = e->touchType;
2955 return;
2956 }
2957
2958 // Prevent sending ill-formed event sequences: Cancel can only be followed by a Begin.
2959 if (self->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
2960 return;
2961
2962 self->lastTouchType = e->touchType;
2963
2964 QPointer<QWindow> window = e->window; // the platform hopefully tells us which window received the event
2966
2967 // For each temporary QEventPoint from the QPA TouchEvent:
2968 // - update the persistent QEventPoint in QPointingDevicePrivate::activePoints with current values
2969 // - determine which window to deliver it to
2970 // - add it to the QTouchEvent instance for that window (QMutableTouchEvent::target() will be QWindow*, for now)
2971 for (auto &tempPt : e->points) {
2972 // update state
2973 auto epd = devPriv->pointById(tempPt.id());
2974 auto &ep = epd->eventPoint;
2975 epd->eventPoint.setAccepted(false);
2976 switch (tempPt.state()) {
2978 // On touchpads, send all touch points to the same window.
2979 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
2980 window = devPriv->firstActiveWindow();
2981 // If the QPA event didn't tell us which window, find the one under the touchpoint position.
2982 if (!window)
2983 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
2984 QMutableEventPoint::setWindow(ep, window);
2985 break;
2986
2988 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
2989 qCDebug(lcPtrDispatch) << "delivering touch release to same window"
2990 << QMutableEventPoint::window(ep) << "not" << window.data();
2992 break;
2993
2994 default: // update or stationary
2995 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
2996 qCDebug(lcPtrDispatch) << "delivering touch update to same window"
2997 << QMutableEventPoint::window(ep) << "not" << window.data();
2999 break;
3000 }
3001 // If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen)
3002 if (Q_UNLIKELY(!window)) {
3003 qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window";
3004 continue;
3005 }
3006 QMutableEventPoint::update(tempPt, ep);
3007
3008 Q_ASSERT(window.data() != nullptr);
3009
3010 // make the *scene* position the same as the *global* position
3011 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3012
3013 // store the scene position as local position, for now
3014 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3015
3016 // setTimeStamp has side effects, so we do it last
3017 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3018
3019 // add the touchpoint to the event that will be delivered to the window
3020 bool added = false;
3021 for (QMutableTouchEvent &ev : touchEvents) {
3022 if (ev.target() == window.data()) {
3023 ev.addPoint(ep);
3024 added = true;
3025 break;
3026 }
3027 }
3028 if (!added) {
3029 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3030 mte.setTimestamp(e->timestamp);
3031 mte.setTarget(window.data());
3032 touchEvents.append(mte);
3033 }
3034 }
3035
3036 if (touchEvents.isEmpty())
3037 return;
3038
3039 for (QMutableTouchEvent &touchEvent : touchEvents) {
3040 QWindow *window = static_cast<QWindow *>(touchEvent.target());
3041
3042 QEvent::Type eventType;
3043 switch (touchEvent.touchPointStates()) {
3045 eventType = QEvent::TouchBegin;
3046 break;
3048 eventType = QEvent::TouchEnd;
3049 break;
3050 default:
3051 eventType = QEvent::TouchUpdate;
3052 break;
3053 }
3054
3055 if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
3056 // a modal window is blocking this window, don't allow touch events through
3057
3058 // QTBUG-37371 temporary fix; TODO: revisit when we have a forwarding solution
3059 if (touchEvent.type() == QEvent::TouchEnd) {
3060 // but don't leave dangling state: e.g.
3061 // QQuickWindowPrivate::itemForTouchPointId needs to be cleared.
3062 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3063 touchEvent.setTimestamp(e->timestamp);
3064 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3065 }
3066 continue;
3067 }
3068
3069 // Note: after the call to sendSpontaneousEvent, touchEvent.position() will have
3070 // changed to reflect the local position inside the last (random) widget it tried
3071 // to deliver the touch event to, and will therefore be invalid afterwards.
3072 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3073
3074 if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3075 // exclude devices which generate their own mouse events
3076 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3077
3078 QEvent::Type mouseEventType = QEvent::MouseMove;
3080 Qt::MouseButtons buttons = Qt::LeftButton;
3081 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3082 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3083 qCDebug(lcPtrDispatch) << "synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3084 }
3085 if (m_fakeMouseSourcePointId >= 0) {
3086 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3087 if (touchPoint) {
3088 switch (touchPoint->state()) {
3090 mouseEventType = QEvent::MouseButtonPress;
3092 break;
3094 mouseEventType = QEvent::MouseButtonRelease;
3096 buttons = Qt::NoButton;
3097 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3098 m_fakeMouseSourcePointId = -1;
3099 break;
3100 default:
3101 break;
3102 }
3103 if (touchPoint->state() != QEventPoint::State::Released) {
3105 touchPoint->position(), touchPoint->globalPosition(), window));
3106 }
3107 // All touch events that are not accepted by the application will be translated to
3108 // left mouse button events instead (see AA_SynthesizeMouseForUnhandledTouchEvents docs).
3109 // TODO why go through QPA? Why not just send a QMouseEvent right from here?
3111 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3112 touchPoint->globalPosition(),
3113 buttons,
3114 e->modifiers,
3115 button,
3116 mouseEventType,
3118 false,
3119 device);
3121 processMouseEvent(&fake);
3122 }
3123 }
3124 if (eventType == QEvent::TouchEnd)
3125 self->synthesizedMousePoints.clear();
3126 }
3127 }
3128 }
3129
3130 // Remove released points from QPointingDevicePrivate::activePoints only after the event is
3131 // delivered. Widgets and Qt Quick are allowed to access them at any time before this.
3132 for (const QEventPoint &touchPoint : e->points) {
3133 if (touchPoint.state() == QEventPoint::State::Released)
3134 devPriv->removePointById(touchPoint.id());
3135 }
3136}
3137
3139{
3140 // This operation only makes sense after the QGuiApplication constructor runs
3142 return;
3143
3144 if (!e->screen)
3145 return;
3146
3147 QScreen *s = e->screen.data();
3148 s->d_func()->orientation = e->orientation;
3149
3150 emit s->orientationChanged(s->orientation());
3151
3152 QScreenOrientationChangeEvent event(s, s->orientation());
3154}
3155
3157{
3158 // This operation only makes sense after the QGuiApplication constructor runs
3160 return;
3161
3162 if (!e->screen)
3163 return;
3164
3165 {
3166 QScreen *s = e->screen.data();
3167 QScreenPrivate::UpdateEmitter updateEmitter(s);
3168
3169 // Note: The incoming geometries have already been scaled by QHighDpi
3170 // in the QWSI layer, so we don't need to call updateGeometry() here.
3171 s->d_func()->geometry = e->geometry;
3172 s->d_func()->availableGeometry = e->availableGeometry;
3173
3174 s->d_func()->updatePrimaryOrientation();
3175 }
3176
3178}
3179
3181{
3182 // This operation only makes sense after the QGuiApplication constructor runs
3184 return;
3185
3187
3188 if (!e->screen)
3189 return;
3190
3191 {
3192 QScreen *s = e->screen.data();
3193 QScreenPrivate::UpdateEmitter updateEmitter(s);
3194 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3195 s->d_func()->updateGeometry();
3196 }
3197
3199 if (window->screen() == e->screen)
3201
3203}
3204
3206{
3207 // This operation only makes sense after the QGuiApplication constructor runs
3209 return;
3210
3211 if (!e->screen)
3212 return;
3213
3214 QScreen *s = e->screen.data();
3215 qreal rate = e->rate;
3216 // safeguard ourselves against buggy platform behavior...
3217 if (rate < 1.0)
3218 rate = 60.0;
3219 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3220 s->d_func()->refreshRate = rate;
3221 emit s->refreshRateChanged(s->refreshRate());
3222 }
3223}
3224
3226{
3227 if (!e->window)
3228 return;
3229
3230 QWindow *window = e->window.data();
3231 if (!window)
3232 return;
3234
3235 if (!p->receivedExpose) {
3236 if (p->resizeEventPending) {
3237 // as a convenience for plugins, send a resize event before the first expose event if they haven't done so
3238 // window->geometry() should have a valid size as soon as a handle exists.
3239 QResizeEvent e(window->geometry().size(), p->geometry.size());
3240 QGuiApplication::sendSpontaneousEvent(window, &e);
3241
3242 p->resizeEventPending = false;
3243 }
3244
3245 // FIXME: It would logically make sense to set this _after_ we've sent the
3246 // expose event to the window, to mark that it now has received an expose.
3247 // But some parts of Qt (mis)use this private member to check whether the
3248 // window has been mapped yet, which they do in code that is triggered
3249 // by the very same expose event we send below. To keep the code working
3250 // we need to set the variable up front, until the code has been fixed.
3251 p->receivedExpose = true;
3252 }
3253
3254 // If the platform does not send paint events we need to synthesize them from expose events
3255 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3256
3257 const bool wasExposed = p->exposed;
3258 p->exposed = e->isExposed && window->screen();
3259
3260 // We treat expose events for an already exposed window as paint events
3261 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3262 QPaintEvent paintEvent(e->region);
3263 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3264 if (paintEvent.isAccepted())
3265 return; // No need to send expose
3266
3267 // The paint event was not accepted, so we fall through and send an expose
3268 // event instead, to maintain compatibility for clients that haven't adopted
3269 // paint events yet.
3270 }
3271
3272 QExposeEvent exposeEvent(e->region);
3273 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3274 e->eventAccepted = exposeEvent.isAccepted();
3275
3276 // If the window was just exposed we also need to send a paint event,
3277 // so that clients that implement paint events will draw something.
3278 // Note that we we can not skip this based on the expose event being
3279 // accepted, as clients may implement exposeEvent to track the state
3280 // change, but without drawing anything.
3281 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3282 QPaintEvent paintEvent(e->region);
3283 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3284 }
3285}
3286
3288{
3289 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents), "QGuiApplication",
3290 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3291
3292 if (!e->window)
3293 return;
3294
3295 QPaintEvent paintEvent(e->region);
3296 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3297
3298 // We report back the accepted state to the platform, so that it can
3299 // decide when the best time to send the fallback expose event is.
3300 e->eventAccepted = paintEvent.isAccepted();
3301}
3302
3303#if QT_CONFIG(draganddrop)
3304
3310static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3311{
3314}
3315
3316QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w, const QMimeData *dropData,
3317 const QPoint &p, Qt::DropActions supportedActions,
3318 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3319{
3320 updateMouseAndModifierButtonState(buttons, modifiers);
3321
3322 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3323 QPlatformDrag *platformDrag = platformIntegration()->drag();
3324 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3325 lastAcceptedDropAction = Qt::IgnoreAction;
3326 return QPlatformDragQtResponse(false, lastAcceptedDropAction, QRect());
3327 }
3328
3329 if (!dropData) {
3330 currentDragWindow = nullptr;
3331 QDragLeaveEvent e;
3333 lastAcceptedDropAction = Qt::IgnoreAction;
3334 return QPlatformDragQtResponse(false, lastAcceptedDropAction, QRect());
3335 }
3336 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3337
3338 if (w != currentDragWindow) {
3339 lastAcceptedDropAction = Qt::IgnoreAction;
3340 if (currentDragWindow) {
3341 QDragLeaveEvent e;
3343 }
3345 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3347 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3348 lastAcceptedDropAction = e.dropAction();
3349 }
3350
3351 // Handling 'DragEnter' should suffice for the application.
3352 if (lastAcceptedDropAction != Qt::IgnoreAction
3353 && (supportedActions & lastAcceptedDropAction)) {
3354 me.setDropAction(lastAcceptedDropAction);
3355 me.accept();
3356 }
3358 lastAcceptedDropAction = me.isAccepted() ?
3359 me.dropAction() : Qt::IgnoreAction;
3360 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3361}
3362
3363QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w, const QMimeData *dropData,
3364 const QPoint &p, Qt::DropActions supportedActions,
3365 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3366{
3367 updateMouseAndModifierButtonState(buttons, modifiers);
3368
3369 currentDragWindow = nullptr;
3370
3371 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3373
3374 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3375 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3376 return response;
3377}
3378
3379#endif // QT_CONFIG(draganddrop)
3380
3381#ifndef QT_NO_CLIPBOARD
3386{
3387 if (QGuiApplicationPrivate::qt_clipboard == nullptr) {
3388 if (!qApp) {
3389 qWarning("QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3390 return nullptr;
3391 }
3393 }
3395}
3396#endif
3397
3418{
3421
3423}
3424
3426{
3427 if (app_pal) {
3428 if (setPalette(*app_pal) && qGuiApp)
3429 qGuiApp->d_func()->handlePaletteChanged();
3430 } else {
3432 }
3433}
3434
3435void QGuiApplicationPrivate::clearPalette()
3436{
3437 delete app_pal;
3438 app_pal = nullptr;
3439}
3440
3450{
3452 qGuiApp->d_func()->handlePaletteChanged();
3453}
3454
3456{
3457 // Resolve the palette against the theme palette, filling in
3458 // any missing roles, while keeping the original resolve mask.
3459 QPalette basePalette = qGuiApp ? qGuiApp->d_func()->basePalette() : Qt::gray;
3460 basePalette.setResolveMask(0); // The base palette only contributes missing colors roles
3461 QPalette resolvedPalette = palette.resolve(basePalette);
3462
3463 if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolveMask() == app_pal->resolveMask())
3464 return false;
3465
3466 if (!app_pal)
3467 app_pal = new QPalette(resolvedPalette);
3468 else
3469 *app_pal = resolvedPalette;
3470
3472
3473 return true;
3474}
3475
3476/*
3477 Returns the base palette used to fill in missing roles in
3478 the current application palette.
3479
3480 Normally this is the theme palette, but QApplication
3481 overrides this for compatibility reasons.
3482*/
3484{
3485 return platformTheme() ? *platformTheme()->palette() : Qt::gray;
3486}
3487
3489{
3490#if QT_DEPRECATED_SINCE(6, 0)
3491 if (!className) {
3497 }
3498#else
3500#endif // QT_DEPRECATED_SINCE(6, 0)
3501
3505 }
3506}
3507
3509{
3511}
3512
3530{
3531 const auto locker = qt_scoped_lock(applicationFontMutex);
3532 if (!QGuiApplicationPrivate::self && !QGuiApplicationPrivate::app_font) {
3533 qWarning("QGuiApplication::font(): no QGuiApplication instance and no application font set.");
3534 return QFont(); // in effect: QFont((QFontPrivate*)nullptr), so no recursion
3535 }
3538}
3539
3546{
3547 auto locker = qt_unique_lock(applicationFontMutex);
3548 const bool emitChange = !QGuiApplicationPrivate::app_font
3552 else
3555
3556 if (emitChange && qGuiApp) {
3558 locker.unlock();
3559#if QT_DEPRECATED_SINCE(6, 0)
3562 emit qGuiApp->fontChanged(font);
3564#else
3565 Q_UNUSED(font);
3566#endif // QT_DEPRECATED_SINCE(6, 0)
3569 }
3570}
3571
3591{
3593 for (int i = 0; i < list.size(); ++i) {
3596 }
3597}
3598
3600{
3601 if (prev) {
3603 QCoreApplication::sendEvent(prev, &de);
3604 }
3605 if (self->focus_window) {
3608 }
3609}
3610
3618{
3620}
3621
3623{
3631 QGuiApplicationPrivate::self->notifyWindowIconChanged();
3632}
3633
3635{
3638 for (int i = 0; i < list.size(); ++i)
3640}
3641
3642
3643
3660{
3662}
3663
3665{
3667}
3668
3670{
3671 if (!lastWindowClosed())
3672 return;
3673
3674 if (in_exec)
3675 emit q_func()->lastWindowClosed();
3676
3679}
3680
3695{
3697 auto *windowPrivate = qt_window_private(window);
3698 if (!windowPrivate->participatesInLastWindowClosed())
3699 continue;
3700
3701 if (windowPrivate->treatAsVisible())
3702 return false;
3703 }
3704
3705 return true;
3706}
3707
3709{
3711 return false;
3712
3714}
3715
3717{
3720 else
3722}
3723
3725{
3727 QGuiApplication::sendSpontaneousEvent(QGuiApplication::instance(), &event);
3728 windowSystemEvent->eventAccepted = event.isAccepted();
3729}
3730
3744{
3746}
3747
3773{
3775}
3776
3783{
3785}
3786
3797{
3798 if ((applicationState == state) && !forcePropagate)
3799 return;
3800
3802
3803 switch (state) {
3804 case Qt::ApplicationActive: {
3806 QCoreApplication::sendSpontaneousEvent(qApp, &appActivate);
3807 break; }
3810 QCoreApplication::sendSpontaneousEvent(qApp, &appDeactivate);
3811 break; }
3812 default:
3813 break;
3814 }
3815
3817 QCoreApplication::sendSpontaneousEvent(qApp, &event);
3818
3819 emit qApp->applicationStateChanged(applicationState);
3820}
3821
3925#ifndef QT_NO_SESSIONMANAGER
3927{
3928 Q_D(const QGuiApplication);
3929 return d->is_session_restored;
3930}
3931
3933{
3934 Q_D(const QGuiApplication);
3935 return d->session_manager->sessionId();
3936}
3937
3939{
3940 Q_D(const QGuiApplication);
3941 return d->session_manager->sessionKey();
3942}
3943
3945{
3946 Q_D(const QGuiApplication);
3947 return d->is_saving_session;
3948}
3949
3951{
3952 Q_Q(QGuiApplication);
3953 is_saving_session = true;
3954 emit q->commitDataRequest(*session_manager);
3955 is_saving_session = false;
3956}
3957
3958
3960{
3961 Q_Q(QGuiApplication);
3962 is_saving_session = true;
3963 emit q->saveStateRequest(*session_manager);
3964 is_saving_session = false;
3965}
3966#endif //QT_NO_SESSIONMANAGER
3967
3980{
3987 }
3988}
3989
4004{
4008
4009 // no change to the explicitly set or auto-detected layout direction
4011 return;
4012
4014 if (qGuiApp) {
4015 emit qGuiApp->layoutDirectionChanged(direction);
4016 QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
4017 }
4018}
4019
4021{
4022 /*
4023 effective_layout_direction defaults to Qt::LeftToRight, and is updated with what is
4024 auto-detected by a call to setLayoutDirection(Qt::LayoutDirectionAuto). This happens in
4025 QGuiApplicationPrivate::init and when the language changes (or before if the application
4026 calls the static function, but then no translators are installed so the auto-detection
4027 always yields Qt::LeftToRight).
4028 So we can be certain that it's always the right value.
4029 */
4031}
4032
4043#ifndef QT_NO_CURSOR
4045{
4046 CHECK_QAPP_INSTANCE(nullptr)
4047 return qGuiApp->d_func()->cursor_list.isEmpty() ? nullptr : &qGuiApp->d_func()->cursor_list.first();
4048}
4049
4059{
4061 if (qGuiApp->d_func()->cursor_list.isEmpty())
4062 return;
4063 qGuiApp->d_func()->cursor_list.removeFirst();
4065}
4066#endif
4067
4068
4069#ifndef QT_NO_CURSOR
4070static inline void applyCursor(QWindow *w, QCursor c)
4071{
4072 if (const QScreen *screen = w->screen())
4074 cursor->changeCursor(&c, w);
4075}
4076
4077static inline void unsetCursor(QWindow *w)
4078{
4079 if (const QScreen *screen = w->screen())
4081 cursor->changeCursor(nullptr, w);
4082}
4083
4084static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
4085{
4086 for (int i = 0; i < l.size(); ++i) {
4087 QWindow *w = l.at(i);
4088 if (w->handle() && w->type() != Qt::Desktop)
4089 applyCursor(w, c);
4090 }
4091}
4092
4093static inline void applyOverrideCursor(const QList<QScreen *> &screens, const QCursor &c)
4094{
4095 for (QScreen *screen : screens) {
4097 cursor->setOverrideCursor(c);
4098 }
4099}
4100
4101static inline void clearOverrideCursor(const QList<QScreen *> &screens)
4102{
4103 for (QScreen *screen : screens) {
4105 cursor->clearOverrideCursor();
4106 }
4107}
4108
4109static inline void applyWindowCursor(const QList<QWindow *> &l)
4110{
4111 for (int i = 0; i < l.size(); ++i) {
4112 QWindow *w = l.at(i);
4113 if (w->handle() && w->type() != Qt::Desktop) {
4114 if (qt_window_private(w)->hasCursor) {
4115 applyCursor(w, w->cursor());
4116 } else {
4117 unsetCursor(w);
4118 }
4119 }
4120 }
4121}
4122
4150{
4152 qGuiApp->d_func()->cursor_list.prepend(cursor);
4155 else
4157}
4158
4171{
4173 if (qGuiApp->d_func()->cursor_list.isEmpty())
4174 return;
4175 qGuiApp->d_func()->cursor_list.removeFirst();
4176 if (qGuiApp->d_func()->cursor_list.size() > 0) {
4177 QCursor c(qGuiApp->d_func()->cursor_list.value(0));
4180 else
4182 } else {
4186 }
4187}
4188#endif// QT_NO_CURSOR
4189
4201{
4205}
4206
4219{
4221}
4222
4230{
4232}
4233
4244{
4245 CHECK_QAPP_INSTANCE(nullptr)
4246 if (!qGuiApp->d_func()->inputMethod)
4247 qGuiApp->d_func()->inputMethod = new QInputMethod();
4248 return qGuiApp->d_func()->inputMethod;
4249}
4250
4266{
4267 Q_UNUSED(cshape);
4268 return QPixmap();
4269}
4270
4272{
4273 // Guard against the default initialization of qInf() (avoid UB or SIGFPE in conversion).
4274 if (Q_UNLIKELY(qIsInf(thePoint.x())))
4275 return QPoint(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
4276 return thePoint.toPoint();
4277}
4278
4279#if QT_CONFIG(draganddrop)
4280void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
4281{
4282 Q_UNUSED(drag);
4283
4284}
4285#endif
4286
4288{
4289#ifdef Q_OS_WIN
4290 if (!m_a8ColorProfile)
4291 m_a8ColorProfile = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering
4292 return m_a8ColorProfile.get();
4293#else
4294 return colorProfileForA32Text();
4295#endif
4296}
4297
4299{
4300 if (!m_a32ColorProfile)
4301 m_a32ColorProfile = QColorTrcLut::fromGamma(fontSmoothingGamma);
4302 return m_a32ColorProfile.get();
4303}
4304
4306{
4307 Q_Q(QGuiApplication);
4308
4310 const bool enabled = inputContext && QInputMethodPrivate::objectAcceptsInputMethod(object);
4311
4313 if (inputContext)
4314 inputContext->setFocusObject(object);
4315 emit q->focusObjectChanged(object);
4316}
4317
4324 MouseFlagsShift = 16
4326
4328{
4330
4331 if (!m_inputDeviceManager)
4332 m_inputDeviceManager = new QInputDeviceManager(QGuiApplication::instance());
4333
4334 return m_inputDeviceManager;
4335}
4336
4350void *QGuiApplication::resolveInterface(const char *name, int revision) const
4351{
4352 using namespace QNativeInterface;
4353 using namespace QNativeInterface::Private;
4354
4357
4358#if defined(Q_OS_WIN)
4360#endif
4361#if QT_CONFIG(xcb)
4362 QT_NATIVE_INTERFACE_RETURN_IF(QX11Application, platformNativeInterface());
4363#endif
4364#if defined(Q_OS_UNIX)
4365 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandApplication, platformNativeInterface());
4366#endif
4367
4368 return QCoreApplication::resolveInterface(name, revision);
4369}
4370
4372
4373#include "moc_qguiapplication.cpp"
IOBluetoothDevice * device
Type loadRelaxed() const noexcept
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
qsizetype indexOf(char c, qsizetype from=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool startsWith(QByteArrayView bv) const
Definition qbytearray.h:170
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:106
void clear()
Clears the contents of the byte array and makes it null.
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
QChar toUpper() const noexcept
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition qchar.h:449
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:561
static std::shared_ptr< QColorTrcLut > fromGamma(qreal gamma)
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:593
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:699
static void cleanup()
Definition qcursor.cpp:684
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:183
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
Definition qdir.cpp:2027
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:2051
\inmodule QtGui
Definition qdrag.h:22
void start() noexcept
Starts this timer.
\inmodule QtGui
Definition qevent.h:164
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:25
void setAccepted(bool accepted=true)
\inmodule QtCore
Definition qcoreevent.h:45
virtual void setAccepted(bool accepted)
Definition qcoreevent.h:302
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:299
bool isAccepted() const
Definition qcoreevent.h:303
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:514
bool exists() const
Returns true if the file 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:847
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition qfile.h:162
const mapped_container_type & values() const noexcept
Definition qflatmap_p.h:583
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
static bool removeAllApplicationFonts()
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:20
static void initialize()
Definition qfont.cpp:2211
static void cleanup()
Definition qfont.cpp:2220
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
QHash< QWindow *, SynthesizedMouseData > synthesizedMousePoints
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 processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *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 Qt::ColorScheme colorScheme()
QGuiApplicationPrivate::colorScheme.
static void processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
static void resetCachedDevicePixelRatio()
static QClipboard * qt_clipboard
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:1135
static void updateHighDpiScaling()
static void initHighDpiScaling()
void updateSystemTheme()
static QIconLoader * instance()
static void clearIconCache()
Definition qicon.cpp:101
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
static QIcon fromTheme(const QString &name)
Definition qicon.cpp:1296
QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
static bool isRegistered(const QInputDevice *dev)
Capabilities capabilities
\inmodule QtGui
Definition qevent.h:49
virtual void setTimestamp(quint64 timestamp)
Definition qevent.h:59
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:423
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...
\inmodule QtCore \reentrant
Definition qlibrary.h:17
bool load()
Loads the library and returns true if the library was loaded successfully; otherwise returns false.
Definition qlibrary.cpp:806
QFunctionPointer resolve(const char *symbol)
Returns the address of the exported symbol symbol.
QString errorString() const
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
void removeFirst() noexcept
Definition qlist.h:800
bool isEmpty() const noexcept
Definition qlist.h:390
T & first()
Definition qlist.h:628
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
value_type takeFirst()
Definition qlist.h:549
qsizetype removeAll(const AT &t)
Definition qlist.h:575
void prepend(rvalue_ref t)
Definition qlist.h:456
void append(parameter_type t)
Definition qlist.h:441
void clear()
Definition qlist.h:417
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtGui
Definition qevent.h:195
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:501
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)
void setDoubleClick(bool d=true)
Definition qevent_p.h:65
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
Definition qevent_p.h:57
void setTarget(QObject *target)
Definition qevent_p.h:41
\inmodule QtCore
Definition qmutex.h:285
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
uint unused
Definition qobject.h:75
QAtomicPointer< QThreadData > threadData
Definition qobject_p.h:202
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3099
\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:485
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setResolveMask(ResolveMask mask)
ResolveMask resolveMask() const
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.
virtual QStringList themeNames() const
virtual QAbstractEventDispatcher * createEventDispatcher() const =0
Factory function for the GUI event dispatcher.
virtual bool hasCapability(Capability cap) const
virtual void setApplicationBadge(qint64 number)
virtual QPlatformInputContext * inputContext() const
Returns the platforms input context.
virtual void setApplicationIcon(const QIcon &icon) const
virtual QPlatformTheme * createPlatformTheme(const QString &name) const
virtual void quit() const
virtual void initialize()
Performs initialization steps that depend on having an event dispatcher available.
virtual void destroy()
Called before the platform integration is deleted.
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.
virtual void showPlatformMenuBar()
virtual Qt::ColorScheme colorScheme() const
virtual const QPalette * palette(Palette type=SystemPalette) const
virtual QVariant themeHint(ThemeHint hint) const
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:214
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:333
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:338
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:394
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr void setY(int y) noexcept
Sets the y coordinate of this point to the given y coordinate.
Definition qpoint.h:142
constexpr void setX(int x) noexcept
Sets the x coordinate of this point to the given x coordinate.
Definition qpoint.h:137
void setTimestamp(quint64 timestamp) override
Definition qevent.cpp:335
void clearPassiveGrabbers(const QEventPoint &point)
Removes all passive grabbers from the given point.
Definition qevent.cpp:430
void setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber)
Informs the delivery logic that the given exclusiveGrabber is to receive all future update events and...
Definition qevent.cpp:366
\inmodule QtCore
Definition qpointer.h:18
T * data() const
Definition qpointer.h:56
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition qpointer.h:67
QWindow * firstActiveWindow() const
EventPointData * queryPointById(int id) const
EventPointData * pointById(int id) const
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:483
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:184
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:187
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:178
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
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
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
The QSessionManager class provides access to the session manager.
Definition qset.h:18
const_iterator constBegin() const noexcept
Definition qset.h:139
const_iterator constEnd() const noexcept
Definition qset.h:143
iterator insert(const T &value)
Definition qset.h:155
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:115
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
static QString locate(StandardLocation type, const QString &fileName, LocateOptions options=LocateFile)
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
Definition qstring.cpp:6737
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
Definition qstring.cpp:7956
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5788
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8606
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
Definition qstring.cpp:5204
QString section(QChar sep, qsizetype start, qsizetype end=-1, SectionFlags flags=SectionDefault) const
This function returns a section of the string.
Definition qstring.h:1139
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition qstring.cpp:5350
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
Definition qstring.h:1164
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
Definition qstring.cpp:5161
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4420
static QStyleHintsPrivate * get(QStyleHints *q)
void setColorScheme(Qt::ColorScheme colorScheme)
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
int mouseDoubleClickInterval
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks.
Definition qstylehints.h:29
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:916
bool isEmpty() const
void append(const T &t)
bool contains(const AT &t) const
\inmodule QtCore
Definition qvariant.h:64
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
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:94
void updateVisibility()
Definition qwindow.cpp:404
virtual void processSafeAreaMarginsChanged()
Definition qwindow_p.h:83
Qt::WindowStates windowState
Definition qwindow_p.h:112
static Qt::WindowState effectiveState(Qt::WindowStates)
Definition qwindow.cpp:1359
void updateDevicePixelRatio()
Definition qwindow.cpp:1341
\inmodule QtGui
Definition qevent.h:898
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:2168
Qt::WindowModality modality
the modality of the window
Definition qwindow.h:78
EGLContext ctx
EGLImageKHR int int EGLuint64KHR * modifiers
QPushButton * button
[2]
QCursor cursor
double pi
[0]
double e
QList< QVariant > arguments
direction
fontMetrics
else opt state
[0]
T toNativePixels(const T &value, const C *context)
T fromNativePixels(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
ColorScheme
Definition qnamespace.h:49
MouseButton
Definition qnamespace.h:55
@ LeftButton
Definition qnamespace.h:57
@ MaxMouseButton
Definition qnamespace.h:90
@ NoButton
Definition qnamespace.h:56
WindowModality
@ NonModal
@ WindowModal
@ ApplicationModal
LayoutDirection
@ LeftToRight
@ LayoutDirectionAuto
@ RightToLeft
@ MouseEventSynthesizedByQt
@ MouseEventNotSynthesized
CursorShape
@ gray
Definition qnamespace.h:32
@ Key_Menu
Definition qnamespace.h:722
@ Key_Back
Definition qnamespace.h:841
@ NoModifier
@ AA_SynthesizeMouseForUnhandledTabletEvents
Definition qnamespace.h:458
@ AA_DontShowShortcutsInContextMenus
Definition qnamespace.h:462
@ AA_ShareOpenGLContexts
Definition qnamespace.h:446
@ AA_SetPalette
Definition qnamespace.h:447
@ AA_SynthesizeMouseForUnhandledTouchEvents
Definition qnamespace.h:436
@ AA_SynthesizeTouchForUnhandledMouseEvents
Definition qnamespace.h:435
DropAction
@ IgnoreAction
ApplicationState
Definition qnamespace.h:261
@ ApplicationActive
Definition qnamespace.h:265
@ ApplicationInactive
Definition qnamespace.h:264
HighDpiScaleFactorRoundingPolicy
@ SkipEmptyParts
Definition qnamespace.h:127
@ Desktop
Definition qnamespace.h:214
@ ToolTip
Definition qnamespace.h:212
@ Popup
Definition qnamespace.h:210
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
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:287
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:303
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:238
bool qIsInf(qfloat16 f) noexcept
Definition qfloat16.h:237
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:163
#define qWarning
Definition qlogging.h:162
#define qFatal
Definition qlogging.h:164
#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:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
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
const GLubyte * c
GLuint GLenum * rate
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
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:1391
#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:30
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
ptrdiff_t qintptr
Definition qtypes.h:71
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2864
bool testFlag(MaskType mask, FlagType flag)
static const wchar_t * themeNames[QWindowsVistaStylePrivate::NThemes]
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)