103#include <QtCore/QThreadPool>
106#include <qtgui_tracepoints_p.h>
108#include <private/qtools_p.h>
117using namespace Qt::StringLiterals;
118using namespace QtMiscUtils;
121#define CHECK_QAPP_INSTANCE(...)
122 if (Q_LIKELY(QCoreApplication::instance())) {
124 qWarning("Must construct a QGuiApplication first.");
131Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
132Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
134Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
140Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
142Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
143 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
145Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
147Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
152Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
169Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
176Q_CONSTINIT
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
177Q_CONSTINIT
static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
181Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
183#ifndef QT_NO_CLIPBOARD
187Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
189Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
190Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
191Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
194Q_CONSTINIT
static QBasicMutex applicationFontMutex;
197Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
198Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
202Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
204Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
206Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
209#if QT_CONFIG(animation)
210extern void qRegisterGuiGetInterpolator();
215 return force_reverse ^
216 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
217 "Translate this string to the string 'LTR' in left-to-right"
218 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
219 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
224 if (!QGuiApplicationPrivate::app_font) {
225 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
226 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
227 QGuiApplicationPrivate::app_font =
new QFont(*font);
229 if (!QGuiApplicationPrivate::app_font)
230 QGuiApplicationPrivate::app_font =
231 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
236 delete QGuiApplicationPrivate::app_font;
237 QGuiApplicationPrivate::app_font =
nullptr;
242 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
243 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
246#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
247static bool checkNeedPortalSupport()
250 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
258#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
278 const qsizetype size = a.size();
283 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
285 else if (isAsciiDigit(*op))
290 const int numberPos = pos;
291 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
294 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
295 return ok ? result : -1;
302 for (
int i = 0; i < 4; ++i) {
304 const int value = nextGeometryToken(a, pos, &op);
316 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
320 result.corner = Qt::TopRightCorner;
329 QRect windowGeometry = window->frameGeometry();
330 QSize size = windowGeometry.size();
332 const QSize windowMinimumSize = window->minimumSize();
333 const QSize windowMaximumSize = window->maximumSize();
335 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
337 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
338 window->resize(size);
341 const QRect availableGeometry = window->screen()->virtualGeometry();
342 QPoint topLeft = windowGeometry.topLeft();
344 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
346 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
349 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
351 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
353 window->setFramePosition(topLeft);
360
361
362
363
364
365
366
367
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
647QGuiApplication::QGuiApplication(
int &argc,
char **argv)
649QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
651 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
655 QCoreApplicationPrivate::eventDispatcher->startingUp();
659
660
661QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
662 : QCoreApplication(p)
667
668
669QGuiApplication::~QGuiApplication()
671 Q_D(QGuiApplication);
673 qt_call_post_routines();
675 d->eventDispatcher->closingDown();
676 d->eventDispatcher =
nullptr;
678#ifndef QT_NO_CLIPBOARD
679 delete QGuiApplicationPrivate::qt_clipboard;
680 QGuiApplicationPrivate::qt_clipboard =
nullptr;
683#ifndef QT_NO_SESSIONMANAGER
684 delete d->session_manager;
685 d->session_manager =
nullptr;
688 QGuiApplicationPrivate::clearPalette();
689 QFontDatabase::removeAllApplicationFonts();
692 d->cursor_list.clear();
695#if QT_CONFIG(qtgui_threadpool)
697 QThreadPool *guiThreadPool =
nullptr;
699 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
704 guiThreadPool->waitForDone();
705 delete guiThreadPool;
709 delete QGuiApplicationPrivate::app_icon;
710 QGuiApplicationPrivate::app_icon =
nullptr;
711 delete QGuiApplicationPrivate::platform_name;
712 QGuiApplicationPrivate::platform_name =
nullptr;
713 delete QGuiApplicationPrivate::displayName;
714 QGuiApplicationPrivate::displayName =
nullptr;
715 delete QGuiApplicationPrivate::m_inputDeviceManager;
716 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
717 delete QGuiApplicationPrivate::desktopFileName;
718 QGuiApplicationPrivate::desktopFileName =
nullptr;
719 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
720 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
721 QGuiApplicationPrivate::lastCursorPosition.reset();
722 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
723 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
724 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
725 QGuiApplicationPrivate::currentDragWindow =
nullptr;
726 QGuiApplicationPrivate::tabletDevicePoints.clear();
729QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
730 : QCoreApplicationPrivate(argc, argv),
731 inputMethod(
nullptr),
732 lastTouchType(QEvent::TouchEnd)
735 application_type = QCoreApplicationPrivate::Gui;
736#ifndef QT_NO_SESSIONMANAGER
737 is_session_restored =
false;
738 is_saving_session =
false;
743
744
745
746
747
748
749
750
751
752
753
754void QGuiApplication::setApplicationDisplayName(
const QString &name)
756 if (!QGuiApplicationPrivate::displayName) {
757 QGuiApplicationPrivate::displayName =
new QString(name);
759 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
760 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
762 if (*QGuiApplicationPrivate::displayName != applicationName())
763 emit
qGuiApp->applicationDisplayNameChanged();
765 }
else if (name != *QGuiApplicationPrivate::displayName) {
766 *QGuiApplicationPrivate::displayName = name;
768 emit
qGuiApp->applicationDisplayNameChanged();
772QString QGuiApplication::applicationDisplayName()
774 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796void QGuiApplication::setBadgeNumber(qint64 number)
798 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817void QGuiApplication::setDesktopFileName(
const QString &name)
819 if (!QGuiApplicationPrivate::desktopFileName)
820 QGuiApplicationPrivate::desktopFileName =
new QString;
821 *QGuiApplicationPrivate::desktopFileName = name;
822 if (name.endsWith(QLatin1String(
".desktop"))) {
823 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
824 if (!filePath.isEmpty()) {
825 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
826 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
827 "be removed. Please specify a desktop file name without .desktop suffix");
828 (*QGuiApplicationPrivate::desktopFileName).chop(8);
833QString QGuiApplication::desktopFileName()
835 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
839
840
841
842
843
844
845
846
847
848
849
850
851
852QWindow *QGuiApplication::modalWindow()
855 if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
857 return QGuiApplicationPrivate::self->modalWindowList.constFirst();
862 QWindowPrivate *p = qt_window_private(window);
863 if (p->blockedByModalWindow != shouldBeBlocked) {
864 p->blockedByModalWindow = shouldBeBlocked;
865 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
866 QGuiApplication::sendEvent(window, &e);
867 for (QObject *c : window->children()) {
868 if (c->isWindowType())
869 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
874void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
876 bool shouldBeBlocked =
false;
877 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
878 if (!popupType && !self->modalWindowList.isEmpty())
879 shouldBeBlocked = self->isWindowBlocked(window);
880 updateBlockedStatusRecursion(window, shouldBeBlocked);
888 return w->isTopLevel();
891void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
893 self->modalWindowList.prepend(modal);
896 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
897 bool shouldBeBlocked = self->isWindowBlocked(currentMouseWindow);
898 if (shouldBeBlocked) {
900 self->modalWindowList.removeFirst();
901 QEvent e(QEvent::Leave);
902 QGuiApplication::sendEvent(currentMouseWindow, &e);
903 currentMouseWindow =
nullptr;
904 self->modalWindowList.prepend(modal);
908 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
909 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
910 updateBlockedStatus(window);
913 updateBlockedStatus(modal);
916void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
918 self->modalWindowList.removeAll(window);
920 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
921 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
922 updateBlockedStatus(window);
926Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
931bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
938
939
940
941
942bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
944 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
946 QWindow *unused =
nullptr;
948 blockingWindow = &unused;
949 *blockingWindow =
nullptr;
951 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
954 for (
int i = 0; i < modalWindowList.size(); ++i) {
955 QWindow *modalWindow = modalWindowList.at(i);
959 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
962 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
963 : modalWindow->modality()) {
964 case Qt::ApplicationModal:
965 *blockingWindow = modalWindow;
967 case Qt::WindowModal: {
970 auto *current = window;
972 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
973 *blockingWindow = modalWindow;
976 current = current->parent(QWindow::IncludeTransients);
981 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
988QWindow *QGuiApplicationPrivate::activePopupWindow()
991 return QGuiApplicationPrivate::popup_list.isEmpty() ?
992 nullptr : QGuiApplicationPrivate::popup_list.constLast();
995void QGuiApplicationPrivate::activatePopup(QWindow *popup)
997 if (!popup->isVisible())
999 popup_list.removeOne(popup);
1000 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1001 popup_list.append(popup);
1004bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1006 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1007 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1012
1013
1014bool QGuiApplicationPrivate::closeAllPopups()
1020 while ((popup = activePopupWindow()) && maxiter--)
1022 return QGuiApplicationPrivate::popup_list.isEmpty();
1026
1027
1028
1029
1030
1031QWindow *QGuiApplication::focusWindow()
1033 return QGuiApplicationPrivate::focus_window;
1037
1038
1039
1040
1041
1042
1043
1046
1047
1048
1049
1050
1051
1052
1055
1056
1057
1058QObject *QGuiApplication::focusObject()
1061 return focusWindow()->focusObject();
1066
1067
1068
1069
1070
1071
1072
1073
1074QWindowList QGuiApplication::allWindows()
1076 return QGuiApplicationPrivate::window_list;
1080
1081
1082
1083
1084
1085
1086QWindowList QGuiApplication::topLevelWindows()
1088 const QWindowList &list = QGuiApplicationPrivate::window_list;
1089 QWindowList topLevelWindows;
1090 for (
int i = 0; i < list.size(); ++i) {
1091 QWindow *window = list.at(i);
1092 if (!window->isTopLevel())
1097 if (window->handle() && window->handle()->isEmbedded())
1100 topLevelWindows.prepend(window);
1103 return topLevelWindows;
1106QScreen *QGuiApplication::primaryScreen()
1108 if (QGuiApplicationPrivate::screen_list.isEmpty())
1110 return QGuiApplicationPrivate::screen_list.at(0);
1114
1115
1116
1117QList<QScreen *> QGuiApplication::screens()
1119 return QGuiApplicationPrivate::screen_list;
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133QScreen *QGuiApplication::screenAt(
const QPoint &point)
1135 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1136 for (
const QScreen *screen : QGuiApplication::screens()) {
1137 if (visitedScreens.contains(screen))
1141 for (QScreen *sibling : screen->virtualSiblings()) {
1142 if (sibling->geometry().contains(point))
1145 visitedScreens.append(sibling);
1153
1154
1155
1156
1157
1158
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195qreal QGuiApplication::devicePixelRatio()
const
1197 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1198 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1200 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1201 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1202 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1204 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1207void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1209 m_maxDevicePixelRatio = 0.0;
1213
1214
1215QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1217 if (QScreen *windowScreen = screenAt(pos)) {
1218 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1219 return windowScreen->handle()->topLevelAt(devicePosition);
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1261QString QGuiApplication::platformName()
1263 if (!QGuiApplication::instance()) {
1264#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1265 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1270 return QGuiApplicationPrivate::platform_name ?
1271 *QGuiApplicationPrivate::platform_name : QString();
1279static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1281 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1282 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1283 <<
"platformPluginPath" << platformPluginPath
1284 <<
"platformThemeName" << platformThemeName;
1286 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1287 QStringList platformArguments;
1288 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1289 for (
const auto &pluginArgument : std::as_const(plugins)) {
1291 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1292 if (arguments.isEmpty())
1294 const QString name = arguments.takeFirst().toLower();
1295 QString argumentsKey = name;
1298 argumentsKey[0] = argumentsKey.at(0).toUpper();
1299 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1301 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1304 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1305 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1306 if (availablePlugins.contains(name)) {
1307 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1308 qCWarning(lcQpaPluginLoading).nospace().noquote()
1309 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1311 qCInfo(lcQpaPluginLoading).nospace().noquote()
1312 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1313 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1315 qCWarning(lcQpaPluginLoading).nospace().noquote()
1316 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1317 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1320 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1321 QGuiApplicationPrivate::platform_name =
new QString(name);
1322 platformArguments = arguments;
1327 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1328 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1329 "Reinstalling the application may fix this problem.\n");
1331 if (!availablePlugins.isEmpty())
1332 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1334#if defined(Q_OS_WIN)
1337 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1338 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1340 qFatal(
"%s", qPrintable(fatalMessage));
1348 QStringList themeNames;
1349 if (!platformThemeName.isEmpty()) {
1350 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1351 themeNames.append(platformThemeName);
1354#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1356 if (checkNeedPortalSupport()) {
1357 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1358 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1363 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1364 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1365 themeNames.append(platformIntegrationThemeNames);
1368 for (
const QString &themeName : std::as_const(themeNames)) {
1369 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1370 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1371 if (QGuiApplicationPrivate::platform_theme) {
1372 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1375 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1376 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1377 if (QGuiApplicationPrivate::platform_theme) {
1378 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1384 if (!QGuiApplicationPrivate::platform_theme) {
1385 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1386 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1391 if (!platformArguments.isEmpty()) {
1392 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1393 for (
const QString &argument : std::as_const(platformArguments)) {
1394 const qsizetype equalsPos = argument.indexOf(u'=');
1395 const QByteArray name =
1396 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1398 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1399 nativeInterface->setProperty(name.constData(), std::move(value));
1404 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1405 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1406 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1407 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1409 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1410 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1411 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1417 for (
int i = 0; i < pluginList.size(); ++i) {
1418 QByteArray pluginSpec = pluginList.at(i);
1419 qsizetype colonPos = pluginSpec.indexOf(
':');
1422 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1424 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1425 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1427 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1429 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1433#if QT_CONFIG(commandlineparser)
1434void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1436 QCoreApplicationPrivate::addQtOptions(options);
1438#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1439 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1440 const bool x11 = sessionType ==
"x11";
1443 const bool x11 =
false;
1446 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1447 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1448 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1449 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1450 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1451 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1452 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1453 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1454 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1455 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1456 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1457 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1458 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1459 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1460 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1461 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1462 options->append(QCommandLineOption(QStringLiteral(
"session"),
1463 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1466 options->append(QCommandLineOption(QStringLiteral(
"display"),
1467 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1468 options->append(QCommandLineOption(QStringLiteral(
"name"),
1469 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1470 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1471 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1472 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1473 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1474 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1475 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1477 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1478 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1479 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1480 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1481 options->append(QCommandLineOption(QStringLiteral(
"title"),
1482 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1487void QGuiApplicationPrivate::createPlatformIntegration()
1489 QHighDpiScaling::initHighDpiScaling();
1492 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1495 QByteArray platformName;
1496#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1497 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1499#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1500 QList<QByteArray> platformArguments = platformName.split(
':');
1501 QByteArray platformPluginBase = platformArguments.first();
1503 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1504 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1506 QVector<QByteArray> preferredPlatformOrder;
1507 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1508 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1509 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1510 preferredPlatformOrder << xcbPlatformName;
1512 platformName.clear();
1515 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1516 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1517 if (hasWaylandDisplay || isWaylandSessionType) {
1518 preferredPlatformOrder.prepend(waylandPlatformName);
1520 if (defaultIsWayland)
1521 platformName.clear();
1524 if (!platformName.isEmpty())
1525 preferredPlatformOrder.append(platformName);
1527 platformName = preferredPlatformOrder.join(
';');
1530 bool platformExplicitlySelected =
false;
1531 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1532 if (!platformNameEnv.isEmpty()) {
1533 platformName = platformNameEnv;
1534 platformExplicitlySelected =
true;
1537 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1543 int j = argc ? 1 : 0;
1544 for (
int i=1; i<argc; i++) {
1547 if (*argv[i] !=
'-') {
1548 argv[j++] = argv[i];
1551 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1552 const char *arg = argv[i];
1555 if (strcmp(arg,
"-platformpluginpath") == 0) {
1557 platformPluginPath = QFile::decodeName(argv[i]);
1558 }
else if (strcmp(arg,
"-platform") == 0) {
1560 platformExplicitlySelected =
true;
1561 platformName = argv[i];
1563 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1565 platformThemeName = QString::fromLocal8Bit(argv[i]);
1566 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1568 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1569 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1571 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1572 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1574 icon = QFile::decodeName(argv[i]);
1577 argv[j++] = argv[i];
1586 Q_UNUSED(platformExplicitlySelected);
1588 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1589 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1591 if (!icon.isEmpty())
1592 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1596
1597
1598
1599
1600
1601void QGuiApplicationPrivate::createEventDispatcher()
1603 Q_ASSERT(!eventDispatcher);
1605 if (platform_integration ==
nullptr)
1606 createPlatformIntegration();
1609 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1610 "Creating the platform integration resulted in creating an event dispatcher");
1613 Q_ASSERT(!eventDispatcher);
1615 eventDispatcher = platform_integration->createEventDispatcher();
1618void QGuiApplicationPrivate::eventDispatcherReady()
1620 if (platform_integration ==
nullptr)
1621 createPlatformIntegration();
1623 platform_integration->initialize();
1626void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1628 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1630#if defined(Q_OS_MACOS)
1631 QMacAutoReleasePool pool;
1634 QCoreApplicationPrivate::init();
1636 QCoreApplicationPrivate::is_app_running =
false;
1638 bool loadTestability =
false;
1639 QList<QByteArray> pluginList;
1641#ifndef QT_NO_SESSIONMANAGER
1643 QString session_key;
1644# if defined(Q_OS_WIN)
1645 wchar_t guidstr[40];
1647 CoCreateGuid(&guid);
1648 StringFromGUID2(guid, guidstr, 40);
1649 session_id = QString::fromWCharArray(guidstr);
1650 CoCreateGuid(&guid);
1651 StringFromGUID2(guid, guidstr, 40);
1652 session_key = QString::fromWCharArray(guidstr);
1656 int j = argc ? 1 : 0;
1657 for (
int i=1; i<argc; i++) {
1660 if (*argv[i] !=
'-') {
1661 argv[j++] = argv[i];
1664 const char *arg = argv[i];
1667 if (strcmp(arg,
"-plugin") == 0) {
1669 pluginList << argv[i];
1670 }
else if (strcmp(arg,
"-reverse") == 0) {
1671 force_reverse =
true;
1673 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1676 if (QDir::currentPath() ==
"/"_L1) {
1677 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1678 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1679 kCFURLPOSIXPathStyle));
1680 if (qbundlePath.endsWith(
".app"_L1))
1681 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1684#ifndef QT_NO_SESSIONMANAGER
1685 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1687 if (argv[i] && *argv[i]) {
1688 session_id = QString::fromLatin1(argv[i]);
1689 qsizetype p = session_id.indexOf(u'_');
1691 session_key = session_id.mid(p +1);
1692 session_id = session_id.left(p);
1694 is_session_restored =
true;
1697 }
else if (strcmp(arg,
"-testability") == 0) {
1698 loadTestability =
true;
1699 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1700 s = QString::fromLocal8Bit(arg + 7);
1701 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1702 s = QString::fromLocal8Bit(argv[++i]);
1704 argv[j++] = argv[i];
1717 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1718 if (!envPlugins.isEmpty())
1719 pluginList += envPlugins.split(
',');
1721 if (platform_integration ==
nullptr)
1722 createPlatformIntegration();
1725 QFont::initialize();
1729 QCursorData::initialize();
1733 qRegisterGuiVariant();
1735#if QT_CONFIG(animation)
1737 qRegisterGuiGetInterpolator();
1740 QWindowSystemInterfacePrivate::eventTime.start();
1742 is_app_running =
true;
1743 init_plugins(pluginList);
1744 QWindowSystemInterface::flushWindowSystemEvents();
1746 Q_Q(QGuiApplication);
1747#ifndef QT_NO_SESSIONMANAGER
1749 session_manager =
new QSessionManager(q, session_id, session_key);
1752#if QT_CONFIG(library)
1753 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1754 loadTestability =
true;
1756 if (loadTestability) {
1757 QLibrary testLib(QStringLiteral(
"qttestability"));
1758 if (Q_UNLIKELY(!testLib.load())) {
1759 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1761 typedef void (*TasInitialize)(
void);
1762 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1763 if (Q_UNLIKELY(!initFunction)) {
1764 qCritical(
"Library qttestability resolve failed!");
1771 Q_UNUSED(loadTestability);
1775 QGuiApplication::setLayoutDirection(layout_direction);
1777 if (!QGuiApplicationPrivate::displayName)
1778 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1779 q, &QGuiApplication::applicationDisplayNameChanged);
1782extern void qt_cleanupFontDatabase();
1784QGuiApplicationPrivate::~QGuiApplicationPrivate()
1786 is_app_closing =
true;
1787 is_app_running =
false;
1789 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1790 delete generic_plugin_list.at(i);
1791 generic_plugin_list.clear();
1793 clearFontUnlocked();
1798 QCursorData::cleanup();
1801 layout_direction = Qt::LayoutDirectionAuto;
1803 cleanupThreadData();
1805 delete QGuiApplicationPrivate::styleHints;
1806 QGuiApplicationPrivate::styleHints =
nullptr;
1809 qt_cleanupFontDatabase();
1811 QPixmapCache::clear();
1814 if (ownGlobalShareContext) {
1815 delete qt_gl_global_share_context();
1816 qt_gl_set_global_share_context(
nullptr);
1820#if QT_CONFIG(vulkan)
1821 QVulkanDefaultInstance::cleanup();
1824 platform_integration->destroy();
1826 delete platform_theme;
1827 platform_theme =
nullptr;
1828 delete platform_integration;
1829 platform_integration =
nullptr;
1831 window_list.clear();
1833 screen_list.clear();
1840QCursor *overrideCursor();
1841void setOverrideCursor(
const QCursor &);
1842void changeOverrideCursor(
const QCursor &);
1843void restoreOverrideCursor();
1847static QFont font(
const QWidget*);
1848static QFont font(
const char *className);
1849static void setFont(
const QFont &,
const char *className =
nullptr);
1850static QFontMetrics fontMetrics();
1852#ifndef QT_NO_CLIPBOARD
1853static QClipboard *clipboard();
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1872 return QGuiApplicationPrivate::modifier_buttons;
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1894 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1895 return pi->keyMapper()->queryKeyboardModifiers();
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911Qt::MouseButtons QGuiApplication::mouseButtons()
1913 return QGuiApplicationPrivate::mouse_buttons;
1917
1918
1919
1920
1921QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1923 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1924 return pi ? pi->nativeInterface() :
nullptr;
1928
1929
1930
1931QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1933 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1935 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1939 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966int QGuiApplication::exec()
1968#if QT_CONFIG(accessibility)
1969 QAccessible::setRootObject(qApp);
1971 return QCoreApplication::exec();
1974void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
1976 if (e->spontaneous()) {
1984 switch (e->type()) {
1985 case QEvent::MouseButtonPress: {
1986 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1987 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
1988 QGuiApplicationPrivate::mouse_buttons |= me->button();
1991 case QEvent::MouseButtonDblClick: {
1992 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1993 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
1994 QGuiApplicationPrivate::mouse_buttons |= me->button();
1997 case QEvent::MouseButtonRelease: {
1998 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1999 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2000 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2003 case QEvent::KeyPress:
2004 case QEvent::KeyRelease:
2005 case QEvent::MouseMove:
2006#if QT_CONFIG(wheelevent)
2009 case QEvent::TouchBegin:
2010 case QEvent::TouchUpdate:
2011 case QEvent::TouchEnd:
2012#if QT_CONFIG(tabletevent)
2013 case QEvent::TabletMove:
2014 case QEvent::TabletPress:
2015 case QEvent::TabletRelease:
2018 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2019 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2029
2030bool QGuiApplication::notify(QObject *object, QEvent *event)
2032 Q_D(QGuiApplication);
2033 if (object->isWindowType()) {
2034 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2038 switch (event->type()) {
2039 case QEvent::ApplicationDeactivate:
2040 case QEvent::OrientationChange:
2046 d->closeAllPopups();
2052 QGuiApplicationPrivate::captureGlobalModifierState(event);
2054 return QCoreApplication::notify(object, event);
2058
2059bool QGuiApplication::event(QEvent *e)
2061 switch (e->type()) {
2062 case QEvent::LanguageChange:
2064 if (layout_direction == Qt::LayoutDirectionAuto)
2065 setLayoutDirection(layout_direction);
2066 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2067 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2069 case QEvent::ApplicationFontChange:
2070 case QEvent::ApplicationPaletteChange:
2071 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2072 postEvent(topLevelWindow,
new QEvent(e->type()));
2074 case QEvent::ThemeChange:
2075 for (
auto *w : QGuiApplication::allWindows())
2081 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2083 if (!topLevelWindow->handle())
2085 if (!topLevelWindow->close()) {
2094 return QCoreApplication::event(e);
2097#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2099
2100
2101bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2103 QT_IGNORE_DEPRECATIONS(
2104 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2109bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2113 QPlatformWindow *platformWindow = window->handle();
2114 if (!platformWindow)
2117 if (event->spontaneous())
2120 return platformWindow->windowEvent(event);
2123bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2125 return window->nativeEvent(eventType, message, result);
2128bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2130 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArray(
"qtvirtualkeyboard");
2131 return usingVirtualKeyboard;
2135bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2137 if (!isUsingVirtualKeyboard()) {
2138 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2142 static QPointer<QWindow> virtualKeyboard;
2143 const QEvent::Type type = e->type();
2144 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2145 const auto me =
static_cast<QMouseEvent *>(e);
2146 const QPointF posF = me->globalPosition();
2147 const QPoint pos = posF.toPoint();
2150 if (!virtualKeyboard) {
2151 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2152 win->inherits(
"QtVirtualKeyboard::InputView")) {
2153 virtualKeyboard = win;
2155 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2160 Q_ASSERT(virtualKeyboard);
2161 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2162 && virtualKeyboard->geometry().contains(pos);
2164 if (!virtualKeyboardUnderMouse) {
2165 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2166 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2170 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2171 me->button(), me->buttons(), me->modifiers(),
2172 me->pointingDevice());
2174 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2175 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2181void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2183 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2184 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2187 case QWindowSystemInterfacePrivate::Mouse:
2188 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2190 case QWindowSystemInterfacePrivate::Wheel:
2191 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2193 case QWindowSystemInterfacePrivate::Key:
2194 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2196 case QWindowSystemInterfacePrivate::Touch:
2197 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2199 case QWindowSystemInterfacePrivate::GeometryChange:
2200 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2202 case QWindowSystemInterfacePrivate::Enter:
2203 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2205 case QWindowSystemInterfacePrivate::Leave:
2206 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2208 case QWindowSystemInterfacePrivate::FocusWindow:
2209 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2211 case QWindowSystemInterfacePrivate::WindowStateChanged:
2212 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2214 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2215 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2217 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2218 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2220 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2221 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2223 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2224 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2225 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2227 case QWindowSystemInterfacePrivate::ApplicationTermination:
2228 QGuiApplicationPrivate::processApplicationTermination(e);
2230 case QWindowSystemInterfacePrivate::FlushEvents: {
2231 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2232 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2234 case QWindowSystemInterfacePrivate::Close:
2235 QGuiApplicationPrivate::processCloseEvent(
2236 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2238 case QWindowSystemInterfacePrivate::ScreenOrientation:
2239 QGuiApplicationPrivate::processScreenOrientationChange(
2240 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2242 case QWindowSystemInterfacePrivate::ScreenGeometry:
2243 QGuiApplicationPrivate::processScreenGeometryChange(
2244 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2246 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2247 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2248 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2250 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2251 QGuiApplicationPrivate::processScreenRefreshRateChange(
2252 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2254 case QWindowSystemInterfacePrivate::ThemeChange:
2255 QGuiApplicationPrivate::processThemeChanged(
2256 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2258 case QWindowSystemInterfacePrivate::Expose:
2259 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2261 case QWindowSystemInterfacePrivate::Paint:
2262 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2264 case QWindowSystemInterfacePrivate::Tablet:
2265 QGuiApplicationPrivate::processTabletEvent(
2266 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2268 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2269 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2270 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2272 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2273 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2274 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2276#ifndef QT_NO_GESTURES
2277 case QWindowSystemInterfacePrivate::Gesture:
2278 QGuiApplicationPrivate::processGestureEvent(
2279 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2282 case QWindowSystemInterfacePrivate::PlatformPanel:
2283 QGuiApplicationPrivate::processPlatformPanelEvent(
2284 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2286 case QWindowSystemInterfacePrivate::FileOpen:
2287 QGuiApplicationPrivate::processFileOpenEvent(
2288 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2290#ifndef QT_NO_CONTEXTMENU
2291 case QWindowSystemInterfacePrivate::ContextMenu:
2292 QGuiApplicationPrivate::processContextMenuEvent(
2293 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2296 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2297 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2300 qWarning() <<
"Unknown user input event type:" << e->type;
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2319 QEvent::Type type = QEvent::None;
2320 Qt::MouseButton button = Qt::NoButton;
2321 QWindow *window = e->window.data();
2322 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2324 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2325 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2326 bool mouseMove =
false;
2327 bool mousePress =
false;
2328 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2329 QPointF globalPoint = e->globalPos;
2331 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2332 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2336 type = e->buttonType;
2339 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2341 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2344 if (!mouseMove && positionChanged) {
2345 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2346 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2347 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2348 e->source, e->nonClientArea, device, e->eventPointId);
2350 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2351 processMouseEvent(&moveEvent);
2352 processMouseEvent(e);
2355 if (type == QEvent::MouseMove && !positionChanged) {
2363 modifier_buttons = e->modifiers;
2364 QPointF localPoint = e->localPos;
2365 bool doubleClick =
false;
2366 auto persistentEPD = devPriv->pointById(0);
2368 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2369 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2372 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2373 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2374 mouseDoubleClickDistance : touchDoubleTapDistance);
2375 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2376 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2377 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2378 mousePressButton = Qt::NoButton;
2380 static unsigned long lastPressTimestamp = 0;
2381 static QPointer<QWindow> lastPressWindow =
nullptr;
2382 mouse_buttons = e->buttons;
2384 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2385 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2386 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2387 && button == mousePressButton && lastPressWindow == e->window;
2388 mousePressButton = button;
2389 lastPressTimestamp = e ->timestamp;
2390 lastPressWindow = e->window;
2394 if (e->nullWindow()) {
2395 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2399 if (e->buttons != Qt::NoButton) {
2400 if (!currentMousePressWindow)
2401 currentMousePressWindow = window;
2403 window = currentMousePressWindow;
2404 }
else if (currentMousePressWindow) {
2405 window = currentMousePressWindow;
2406 currentMousePressWindow =
nullptr;
2408 localPoint = window->mapFromGlobal(globalPoint);
2416 if (!e->synthetic()) {
2417 if (
const QScreen *screen = window->screen())
2418 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2419 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2420 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2421 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2422 button, e->buttons, e->modifiers, e->source, device);
2426 ev.QInputEvent::setTimestamp(e->timestamp);
2427 cursor->pointerEvent(ev);
2432 const auto *activePopup = activePopupWindow();
2433 if (type == QEvent::MouseButtonPress)
2434 active_popup_on_press = activePopup;
2435 if (window->d_func()->blockedByModalWindow && !activePopup) {
2440 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2441 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2444 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2445 persistentEPD =
nullptr;
2447 ev.setTimestamp(e->timestamp);
2449 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2451 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2452 if (handlingPopup) {
2453 if (type == QEvent::MouseButtonPress)
2454 active_popup_on_press = handlingPopup;
2459 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2461 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2464 QGuiApplication::sendSpontaneousEvent(window, &ev);
2465 e->eventAccepted = ev.isAccepted();
2466 if (!e->synthetic() && !ev.isAccepted()
2467 && !e->nonClientArea
2468 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2469 QList<QWindowSystemInterface::TouchPoint> points;
2470 QWindowSystemInterface::TouchPoint point;
2472 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2477 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2478 point.state = QEventPoint::State::Pressed;
2479 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2480 point.state = QEventPoint::State::Released;
2481 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2482 point.state = QEventPoint::State::Updated;
2490 const QList<QEventPoint> &touchPoints =
2491 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2493 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2494 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2495 processTouchEvent(&fake);
2498 mousePressButton = Qt::NoButton;
2499 if (!e->window.isNull() || e->nullWindow()) {
2500 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2501 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2502 button, e->buttons, e->modifiers, e->source, device);
2503 dblClickEvent.setTimestamp(e->timestamp);
2504 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2507 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2508 popup_closed_on_press =
false;
2509 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2510 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2511 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2516void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2518#if QT_CONFIG(wheelevent)
2519 QWindow *window = e->window.data();
2520 QPointF globalPoint = e->globalPos;
2521 QPointF localPoint = e->localPos;
2523 if (e->nullWindow()) {
2524 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2526 localPoint = window->mapFromGlobal(globalPoint);
2532 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2533 modifier_buttons = e->modifiers;
2535 if (window->d_func()->blockedByModalWindow) {
2540 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2541 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2542 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2543 ev.setTimestamp(e->timestamp);
2544 QGuiApplication::sendSpontaneousEvent(window, &ev);
2545 e->eventAccepted = ev.isAccepted();
2551void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2553 QWindow *window = e->window.data();
2554 modifier_buttons = e->modifiers;
2557 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2560 window = QGuiApplication::focusWindow();
2564 e->eventAccepted =
false;
2568#if defined(Q_OS_ANDROID)
2569 static bool backKeyPressAccepted =
false;
2570 static bool menuKeyPressAccepted =
false;
2573#if !defined(Q_OS_MACOS)
2576 if (e->keyType == QEvent::KeyPress) {
2577 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2578 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2579#if defined(Q_OS_ANDROID)
2580 backKeyPressAccepted = e->key == Qt::Key_Back;
2581 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2588 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2589 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2590 e->unicode, e->repeat, e->repeatCount);
2591 ev.setTimestamp(e->timestamp);
2593 const auto *activePopup = activePopupWindow();
2594 if (activePopup && activePopup != window) {
2596 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2602 if (!window->d_func()->blockedByModalWindow)
2603 QGuiApplication::sendSpontaneousEvent(window, &ev);
2606 ev.setAccepted(
false);
2608 if (e->keyType == QEvent::KeyPress) {
2609 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2610 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2611 }
else if (e->keyType == QEvent::KeyRelease) {
2612 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2614 QWindowSystemInterface::handleCloseEvent(window);
2615 }
else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2616 platform_theme->showPlatformMenuBar();
2620 e->eventAccepted = ev.isAccepted();
2623void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2627 if (e->enter.data()->d_func()->blockedByModalWindow) {
2632 currentMouseWindow = e->enter;
2635 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2642 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2643 auto epd = devPriv->queryPointById(event.points().first().id());
2645 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2647 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2650void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2654 if (e->leave.data()->d_func()->blockedByModalWindow) {
2659 currentMouseWindow =
nullptr;
2661 QEvent event(QEvent::Leave);
2662 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2665void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2667 QWindow *previous = QGuiApplicationPrivate::focus_window;
2668 QWindow *newFocus = e->focused.data();
2670 if (previous == newFocus)
2673 bool activatedPopup =
false;
2675 if (QPlatformWindow *platformWindow = newFocus->handle())
2676 if (platformWindow->isAlertState())
2677 platformWindow->setAlertState(
false);
2678 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2680 activatePopup(newFocus);
2683 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2686 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2687 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2690 QGuiApplicationPrivate::focus_window = newFocus;
2695 Qt::FocusReason r = e->reason;
2696 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2697 r = Qt::PopupFocusReason;
2698 QFocusEvent focusOut(QEvent::FocusOut, r);
2699 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2700 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2701 qApp, SLOT(_q_updateFocusObject(QObject*)));
2702 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2703 setApplicationState(Qt::ApplicationActive);
2706 if (QGuiApplicationPrivate::focus_window) {
2707 Qt::FocusReason r = e->reason;
2708 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2709 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2710 r = Qt::PopupFocusReason;
2711 QFocusEvent focusIn(QEvent::FocusIn, r);
2712 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2713 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2714 qApp, SLOT(_q_updateFocusObject(QObject*)));
2715 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2716 setApplicationState(Qt::ApplicationInactive);
2720 self->notifyActiveWindowChange(previous);
2722 if (previousFocusObject !=
qApp->focusObject() ||
2728 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2729 self->_q_updateFocusObject(
qApp->focusObject());
2733 emit
qApp->focusWindowChanged(newFocus);
2735 emit previous->activeChanged();
2737 emit newFocus->activeChanged();
2740void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2742 if (QWindow *window = wse->window.data()) {
2743 QWindowPrivate *windowPrivate = qt_window_private(window);
2744 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2746 windowPrivate->windowState = wse->newState;
2747 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2748 if (newEffectiveState != originalEffectiveState)
2749 emit window->windowStateChanged(newEffectiveState);
2751 windowPrivate->updateVisibility();
2753 QWindowStateChangeEvent e(wse->oldState);
2754 QGuiApplication::sendSpontaneousEvent(window, &e);
2758void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2760 QWindow *window = wse->window.data();
2764 if (window->screen() == wse->screen.data())
2767 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2768 if (QScreen *screen = wse->screen.data())
2769 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2771 topLevelWindow->setScreen(
nullptr);
2775void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2777 if (wde->window.isNull())
2779 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2782void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2784 if (wse->window.isNull())
2787 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2789 QEvent event(QEvent::SafeAreaMarginsChange);
2790 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2793void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2796 self->handleThemeChanged();
2798 QIconPrivate::clearIconCache();
2800 QEvent themeChangeEvent(QEvent::ThemeChange);
2801 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2804void QGuiApplicationPrivate::handleThemeChanged()
2806 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2809 QIconLoader::instance()->updateSystemTheme();
2810 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2812 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2813 const auto locker = qt_scoped_lock(applicationFontMutex);
2814 clearFontUnlocked();
2820void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2822 if (e->window.isNull())
2825 QWindow *window = e->window.data();
2829 const QRect lastReportedGeometry = window->d_func()->geometry;
2830 const QRect requestedGeometry = e->requestedGeometry;
2831 const QRect actualGeometry = e->newGeometry;
2841 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2842 || requestedGeometry.size() != actualGeometry.size();
2843 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2844 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2846 window->d_func()->geometry = actualGeometry;
2848 if (isResize || window->d_func()->resizeEventPending) {
2849 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2850 QGuiApplication::sendSpontaneousEvent(window, &e);
2852 window->d_func()->resizeEventPending =
false;
2854 if (actualGeometry.width() != lastReportedGeometry.width())
2855 emit window->widthChanged(actualGeometry.width());
2856 if (actualGeometry.height() != lastReportedGeometry.height())
2857 emit window->heightChanged(actualGeometry.height());
2862 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2863 QGuiApplication::sendSpontaneousEvent(window, &e);
2865 if (actualGeometry.x() != lastReportedGeometry.x())
2866 emit window->xChanged(actualGeometry.x());
2867 if (actualGeometry.y() != lastReportedGeometry.y())
2868 emit window->yChanged(actualGeometry.y());
2872void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2874 if (e->window.isNull())
2876 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2879 e->eventAccepted =
false;
2884 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2886 e->eventAccepted = event.isAccepted();
2889void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2891 if (e->url.isEmpty())
2894 QFileOpenEvent event(e->url);
2895 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2898QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2900 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2901 TabletPointData &pointData = tabletDevicePoints[i];
2902 if (pointData.deviceId == deviceId)
2906 tabletDevicePoints.append(TabletPointData(deviceId));
2907 return tabletDevicePoints.last();
2910void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2912#if QT_CONFIG(tabletevent)
2913 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2914 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2916 QEvent::Type type = QEvent::TabletMove;
2917 if (e->buttons != pointData.state)
2918 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2920 QWindow *window = e->window.data();
2921 modifier_buttons = e->modifiers;
2923 bool localValid =
true;
2927 if (type == QEvent::TabletPress) {
2928 if (e->nullWindow()) {
2929 window = QGuiApplication::topLevelAt(e->global.toPoint());
2934 active_popup_on_press = activePopupWindow();
2935 pointData.target = window;
2937 if (e->nullWindow()) {
2938 window = pointData.target;
2941 if (type == QEvent::TabletRelease)
2942 pointData.target =
nullptr;
2946 QPointF local = e->local;
2948 QPointF delta = e->global - e->global.toPoint();
2949 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2953 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2954 Qt::MouseButton button = Qt::NoButton;
2955 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
2956 if (check & stateChange) {
2957 button = Qt::MouseButton(check);
2962 const auto *activePopup = activePopupWindow();
2963 if (window->d_func()->blockedByModalWindow && !activePopup) {
2968 QTabletEvent tabletEvent(type, device, local, e->global,
2969 e->pressure, e->xTilt, e->yTilt,
2970 e->tangentialPressure, e->rotation, e->z,
2971 e->modifiers, button, e->buttons);
2972 tabletEvent.setAccepted(
false);
2973 tabletEvent.setTimestamp(e->timestamp);
2975 if (activePopup && activePopup != window) {
2977 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
2981 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
2982 pointData.state = e->buttons;
2983 if (!tabletEvent.isAccepted()
2984 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
2985 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
2987 const QEvent::Type mouseType = [&]() {
2989 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
2990 case QEvent::TabletMove:
return QEvent::MouseMove;
2991 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
2992 default: Q_UNREACHABLE();
2995 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
2996 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
2997 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2998 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
2999 << e->local << button << e->buttons << e->modifiers;
3000 processMouseEvent(&mouseEvent);
3007void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3009#if QT_CONFIG(tabletevent)
3010 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3011 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3012 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3013 tabletDevicePoint(dev->uniqueId().numericId()).state);
3014 ev.setTimestamp(e->timestamp);
3015 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3021void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3023#if QT_CONFIG(tabletevent)
3024 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3025 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3026 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3027 tabletDevicePoint(dev->uniqueId().numericId()).state);
3028 ev.setTimestamp(e->timestamp);
3029 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3035#ifndef QT_NO_GESTURES
3036void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3038 if (e->window.isNull())
3041 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3042 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3043 e->delta, e->sequenceId);
3044 ev.setTimestamp(e->timestamp);
3045 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3049void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3054 if (e->window->d_func()->blockedByModalWindow) {
3059 QEvent ev(QEvent::PlatformPanel);
3060 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3063#ifndef QT_NO_CONTEXTMENU
3064void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3068 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3071 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3072 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3073 e->eventAccepted = ev.isAccepted();
3077void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3079 if (!QInputDevicePrivate::isRegistered(e->device))
3082 modifier_buttons = e->modifiers;
3083 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3084 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3086 if (e->touchType == QEvent::TouchCancel) {
3089 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3090 touchEvent.setTimestamp(e->timestamp);
3091 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3092 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3094 for (
auto &epd : devPriv->activePoints.values()) {
3095 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3096 windowsNeedingCancel.insert(w);
3099 for (QWindow *w : windowsNeedingCancel)
3100 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3102 if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3103 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
3104 synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3105 if (!synthIt->window)
3107 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3114 QEvent::MouseButtonRelease,
3115 Qt::MouseEventNotSynthesized,
3118 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3119 processMouseEvent(&fake);
3121 self->synthesizedMousePoints.clear();
3123 self->lastTouchType = e->touchType;
3128 if (self->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3131 self->lastTouchType = e->touchType;
3133 QPointer<QWindow> window = e->window;
3134 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3140 for (
auto &tempPt : e->points) {
3142 auto epd = devPriv->pointById(tempPt.id());
3143 auto &ep = epd->eventPoint;
3144 epd->eventPoint.setAccepted(
false);
3145 switch (tempPt.state()) {
3146 case QEventPoint::State::Pressed:
3148 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3149 window = devPriv->firstActiveWindow();
3152 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3153 QMutableEventPoint::setWindow(ep, window);
3154 active_popup_on_press = activePopupWindow();
3157 case QEventPoint::State::Released:
3158 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3159 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3160 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3161 window = QMutableEventPoint::window(ep);
3165 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3166 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3167 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3168 window = QMutableEventPoint::window(ep);
3172 if (Q_UNLIKELY(!window)) {
3173 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3176 QMutableEventPoint::update(tempPt, ep);
3178 Q_ASSERT(window.data() !=
nullptr);
3181 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3184 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3187 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3191 for (QMutableTouchEvent &ev : touchEvents) {
3192 if (ev.target() == window.data()) {
3199 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3200 mte.setTimestamp(e->timestamp);
3201 mte.setTarget(window.data());
3202 touchEvents.append(mte);
3206 if (touchEvents.isEmpty())
3209 for (QMutableTouchEvent &touchEvent : touchEvents) {
3210 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3212 QEvent::Type eventType;
3213 switch (touchEvent.touchPointStates()) {
3214 case QEventPoint::State::Pressed:
3215 eventType = QEvent::TouchBegin;
3217 case QEventPoint::State::Released:
3218 eventType = QEvent::TouchEnd;
3221 eventType = QEvent::TouchUpdate;
3225 const auto *activePopup = activePopupWindow();
3226 if (window->d_func()->blockedByModalWindow && !activePopup) {
3230 if (touchEvent.type() == QEvent::TouchEnd) {
3233 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3234 touchEvent.setTimestamp(e->timestamp);
3235 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3240 if (activePopup && activePopup != window) {
3242 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3249 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3251 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3253 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3255 QEvent::Type mouseEventType = QEvent::MouseMove;
3256 Qt::MouseButton button = Qt::NoButton;
3257 Qt::MouseButtons buttons = Qt::LeftButton;
3258 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3259 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3260 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3262 if (m_fakeMouseSourcePointId >= 0) {
3263 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3265 switch (touchPoint->state()) {
3266 case QEventPoint::State::Pressed:
3267 mouseEventType = QEvent::MouseButtonPress;
3268 button = Qt::LeftButton;
3270 case QEventPoint::State::Released:
3271 mouseEventType = QEvent::MouseButtonRelease;
3272 button = Qt::LeftButton;
3273 buttons = Qt::NoButton;
3274 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3275 m_fakeMouseSourcePointId = -1;
3280 if (touchPoint->state() != QEventPoint::State::Released) {
3281 self->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3282 touchPoint->position(), touchPoint->globalPosition(), window));
3288 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3289 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3290 touchPoint->globalPosition(),
3295 Qt::MouseEventSynthesizedByQt,
3299 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3300 processMouseEvent(&fake);
3303 if (eventType == QEvent::TouchEnd)
3304 self->synthesizedMousePoints.clear();
3311 for (
const QEventPoint &touchPoint : e->points) {
3312 if (touchPoint.state() == QEventPoint::State::Released)
3313 devPriv->removePointById(touchPoint.id());
3317void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3320 if (QCoreApplication::startingUp())
3326 QScreen *s = e->screen.data();
3327 s->d_func()->orientation = e->orientation;
3329 emit s->orientationChanged(s->orientation());
3331 QScreenOrientationChangeEvent event(s, s->orientation());
3332 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3335void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3338 if (QCoreApplication::startingUp())
3345 QScreen *s = e->screen.data();
3346 QScreenPrivate::UpdateEmitter updateEmitter(s);
3350 s->d_func()->geometry = e->geometry;
3351 s->d_func()->availableGeometry = e->availableGeometry;
3353 s->d_func()->updatePrimaryOrientation();
3356 resetCachedDevicePixelRatio();
3359void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3362 if (QCoreApplication::startingUp())
3365 QHighDpiScaling::updateHighDpiScaling();
3371 QScreen *s = e->screen.data();
3372 QScreenPrivate::UpdateEmitter updateEmitter(s);
3373 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3374 s->d_func()->updateGeometry();
3377 for (QWindow *window : QGuiApplication::allWindows())
3378 if (window->screen() == e->screen)
3379 QWindowPrivate::get(window)->updateDevicePixelRatio();
3381 resetCachedDevicePixelRatio();
3384void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3387 if (QCoreApplication::startingUp())
3393 QScreen *s = e->screen.data();
3394 qreal rate = e->rate;
3398 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3399 s->d_func()->refreshRate = rate;
3400 emit s->refreshRateChanged(s->refreshRate());
3404void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3409 QWindow *window = e->window.data();
3412 QWindowPrivate *p = qt_window_private(window);
3419 p->positionAutomatic =
false;
3420 p->resizeAutomatic =
false;
3423 if (!p->receivedExpose) {
3424 if (p->resizeEventPending) {
3427 QResizeEvent e(window->geometry().size(), p->geometry.size());
3428 QGuiApplication::sendSpontaneousEvent(window, &e);
3430 p->resizeEventPending =
false;
3439 p->receivedExpose =
true;
3443 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3445 const bool wasExposed = p->exposed;
3446 p->exposed = e->isExposed && window->screen();
3451 if (e->isExposed && !e->region.isEmpty()) {
3452 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3454 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3455 <<
"Please file a QTBUG which explains how to reproduce.";
3459 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3460 QPaintEvent paintEvent(e->region);
3461 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3462 if (paintEvent.isAccepted())
3470 QExposeEvent exposeEvent(e->region);
3471 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3472 e->eventAccepted = exposeEvent.isAccepted();
3479 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3480 QPaintEvent paintEvent(e->region);
3481 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3485void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3487 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3488 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3493 QPaintEvent paintEvent(e->region);
3494 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3498 e->eventAccepted = paintEvent.isAccepted();
3501#if QT_CONFIG(draganddrop)
3504
3505
3506
3507
3508static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3510 QGuiApplicationPrivate::mouse_buttons = buttons;
3511 QGuiApplicationPrivate::modifier_buttons = modifiers;
3514QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3515 const QPoint &p, Qt::DropActions supportedActions,
3516 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3518 updateMouseAndModifierButtonState(buttons, modifiers);
3520 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3521 QPlatformDrag *platformDrag = platformIntegration()->drag();
3522 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3523 lastAcceptedDropAction = Qt::IgnoreAction;
3524 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3528 currentDragWindow =
nullptr;
3530 QGuiApplication::sendEvent(w, &e);
3531 lastAcceptedDropAction = Qt::IgnoreAction;
3532 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3534 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3536 if (w != currentDragWindow) {
3537 lastAcceptedDropAction = Qt::IgnoreAction;
3538 if (currentDragWindow) {
3540 QGuiApplication::sendEvent(currentDragWindow, &e);
3542 currentDragWindow = w;
3543 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3544 QGuiApplication::sendEvent(w, &e);
3545 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3546 lastAcceptedDropAction = e.dropAction();
3550 if (lastAcceptedDropAction != Qt::IgnoreAction
3551 && (supportedActions & lastAcceptedDropAction)) {
3552 me.setDropAction(lastAcceptedDropAction);
3555 QGuiApplication::sendEvent(w, &me);
3556 lastAcceptedDropAction = me.isAccepted() ?
3557 me.dropAction() : Qt::IgnoreAction;
3558 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3561QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3562 const QPoint &p, Qt::DropActions supportedActions,
3563 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3565 updateMouseAndModifierButtonState(buttons, modifiers);
3567 currentDragWindow =
nullptr;
3569 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3570 QGuiApplication::sendEvent(w, &de);
3572 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3573 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3579#ifndef QT_NO_CLIPBOARD
3581
3582
3583QClipboard * QGuiApplication::clipboard()
3585 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3587 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3590 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3592 return QGuiApplicationPrivate::qt_clipboard;
3597
3598
3599
3600
3601
3602
3603
3604
3605
3608
3609
3610
3611
3612
3613
3615QPalette QGuiApplication::palette()
3617 if (!QGuiApplicationPrivate::app_pal)
3618 QGuiApplicationPrivate::updatePalette();
3620 return *QGuiApplicationPrivate::app_pal;