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();
249 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
256#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
276 const qsizetype size = a.size();
281 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
283 else if (isAsciiDigit(*op))
288 const int numberPos = pos;
289 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
292 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
293 return ok ? result : -1;
300 for (
int i = 0; i < 4; ++i) {
302 const int value = nextGeometryToken(a, pos, &op);
314 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
318 result.corner = Qt::TopRightCorner;
327 QRect windowGeometry = window->frameGeometry();
328 QSize size = windowGeometry.size();
330 const QSize windowMinimumSize = window->minimumSize();
331 const QSize windowMaximumSize = window->maximumSize();
333 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
335 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
336 window->resize(size);
339 const QRect availableGeometry = window->screen()->virtualGeometry();
340 QPoint topLeft = windowGeometry.topLeft();
342 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
344 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
347 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
349 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
351 window->setFramePosition(topLeft);
358
359
360
361
362
363
364
365
368
369
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
491
492
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
645QGuiApplication::QGuiApplication(
int &argc,
char **argv)
647QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
649 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
653 QCoreApplicationPrivate::eventDispatcher->startingUp();
657
658
659QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
660 : QCoreApplication(p)
665
666
667QGuiApplication::~QGuiApplication()
669 Q_D(QGuiApplication);
671 qt_call_post_routines();
673 d->eventDispatcher->closingDown();
674 d->eventDispatcher =
nullptr;
676#ifndef QT_NO_CLIPBOARD
677 delete QGuiApplicationPrivate::qt_clipboard;
678 QGuiApplicationPrivate::qt_clipboard =
nullptr;
681#ifndef QT_NO_SESSIONMANAGER
682 delete d->session_manager;
683 d->session_manager =
nullptr;
686 QGuiApplicationPrivate::clearPalette();
687 QFontDatabase::removeAllApplicationFonts();
690 d->cursor_list.clear();
693#if QT_CONFIG(qtgui_threadpool)
695 QThreadPool *guiThreadPool =
nullptr;
697 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
702 guiThreadPool->waitForDone();
703 delete guiThreadPool;
707 delete QGuiApplicationPrivate::app_icon;
708 QGuiApplicationPrivate::app_icon =
nullptr;
709 delete QGuiApplicationPrivate::platform_name;
710 QGuiApplicationPrivate::platform_name =
nullptr;
711 delete QGuiApplicationPrivate::displayName;
712 QGuiApplicationPrivate::displayName =
nullptr;
713 delete QGuiApplicationPrivate::m_inputDeviceManager;
714 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
715 delete QGuiApplicationPrivate::desktopFileName;
716 QGuiApplicationPrivate::desktopFileName =
nullptr;
717 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
718 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
719 QGuiApplicationPrivate::lastCursorPosition.reset();
720 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
721 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
722 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
723 QGuiApplicationPrivate::currentDragWindow =
nullptr;
724 QGuiApplicationPrivate::tabletDevicePoints.clear();
727QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
728 : QCoreApplicationPrivate(argc, argv),
729 inputMethod(
nullptr),
730 lastTouchType(QEvent::TouchEnd)
733 application_type = QCoreApplicationPrivate::Gui;
734#ifndef QT_NO_SESSIONMANAGER
735 is_session_restored =
false;
736 is_saving_session =
false;
741
742
743
744
745
746
747
748
749
750
751
752void QGuiApplication::setApplicationDisplayName(
const QString &name)
754 if (!QGuiApplicationPrivate::displayName) {
755 QGuiApplicationPrivate::displayName =
new QString(name);
757 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
758 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
760 if (*QGuiApplicationPrivate::displayName != applicationName())
761 emit
qGuiApp->applicationDisplayNameChanged();
763 }
else if (name != *QGuiApplicationPrivate::displayName) {
764 *QGuiApplicationPrivate::displayName = name;
766 emit
qGuiApp->applicationDisplayNameChanged();
770QString QGuiApplication::applicationDisplayName()
772 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794void QGuiApplication::setBadgeNumber(qint64 number)
796 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815void QGuiApplication::setDesktopFileName(
const QString &name)
817 if (!QGuiApplicationPrivate::desktopFileName)
818 QGuiApplicationPrivate::desktopFileName =
new QString;
819 *QGuiApplicationPrivate::desktopFileName = name;
820 if (name.endsWith(QLatin1String(
".desktop"))) {
821 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
822 if (!filePath.isEmpty()) {
823 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
824 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
825 "be removed. Please specify a desktop file name without .desktop suffix");
826 (*QGuiApplicationPrivate::desktopFileName).chop(8);
831QString QGuiApplication::desktopFileName()
833 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
837
838
839
840
841
842
843
844
845
846
847
848
849
850QWindow *QGuiApplication::modalWindow()
853 if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
855 return QGuiApplicationPrivate::self->modalWindowList.constFirst();
860 QWindowPrivate *p = qt_window_private(window);
861 if (p->blockedByModalWindow != shouldBeBlocked) {
862 p->blockedByModalWindow = shouldBeBlocked;
863 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
864 QGuiApplication::sendEvent(window, &e);
865 for (QObject *c : window->children()) {
866 if (c->isWindowType())
867 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
872void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
874 bool shouldBeBlocked =
false;
875 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
876 if (!popupType && !self->modalWindowList.isEmpty())
877 shouldBeBlocked = self->isWindowBlocked(window);
878 updateBlockedStatusRecursion(window, shouldBeBlocked);
886 return w->isTopLevel();
889void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
891 self->modalWindowList.prepend(modal);
894 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
895 bool shouldBeBlocked = self->isWindowBlocked(currentMouseWindow);
896 if (shouldBeBlocked) {
898 self->modalWindowList.removeFirst();
899 QEvent e(QEvent::Leave);
900 QGuiApplication::sendEvent(currentMouseWindow, &e);
901 currentMouseWindow =
nullptr;
902 self->modalWindowList.prepend(modal);
906 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
907 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
908 updateBlockedStatus(window);
911 updateBlockedStatus(modal);
914void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
916 self->modalWindowList.removeAll(window);
918 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
919 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
920 updateBlockedStatus(window);
924Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
929bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
936
937
938
939
940bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
942 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
944 QWindow *unused =
nullptr;
946 blockingWindow = &unused;
947 *blockingWindow =
nullptr;
949 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
952 for (
int i = 0; i < modalWindowList.size(); ++i) {
953 QWindow *modalWindow = modalWindowList.at(i);
957 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
960 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
961 : modalWindow->modality()) {
962 case Qt::ApplicationModal:
963 *blockingWindow = modalWindow;
965 case Qt::WindowModal: {
968 auto *current = window;
970 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
971 *blockingWindow = modalWindow;
974 current = current->parent(QWindow::IncludeTransients);
979 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
986QWindow *QGuiApplicationPrivate::activePopupWindow()
989 return QGuiApplicationPrivate::popup_list.isEmpty() ?
990 nullptr : QGuiApplicationPrivate::popup_list.constLast();
993void QGuiApplicationPrivate::activatePopup(QWindow *popup)
995 if (!popup->isVisible())
997 popup_list.removeOne(popup);
998 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
999 popup_list.append(popup);
1002bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1004 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1005 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1010
1011
1012bool QGuiApplicationPrivate::closeAllPopups()
1018 while ((popup = activePopupWindow()) && maxiter--)
1020 return QGuiApplicationPrivate::popup_list.isEmpty();
1024
1025
1026
1027
1028
1029QWindow *QGuiApplication::focusWindow()
1031 return QGuiApplicationPrivate::focus_window;
1035
1036
1037
1038
1039
1040
1041
1044
1045
1046
1047
1048
1049
1050
1053
1054
1055
1056QObject *QGuiApplication::focusObject()
1059 return focusWindow()->focusObject();
1064
1065
1066
1067
1068
1069
1070
1071
1072QWindowList QGuiApplication::allWindows()
1074 return QGuiApplicationPrivate::window_list;
1078
1079
1080
1081
1082
1083
1084QWindowList QGuiApplication::topLevelWindows()
1086 const QWindowList &list = QGuiApplicationPrivate::window_list;
1087 QWindowList topLevelWindows;
1088 for (
int i = 0; i < list.size(); ++i) {
1089 QWindow *window = list.at(i);
1090 if (!window->isTopLevel())
1095 if (window->handle() && window->handle()->isEmbedded())
1098 topLevelWindows.prepend(window);
1101 return topLevelWindows;
1104QScreen *QGuiApplication::primaryScreen()
1106 if (QGuiApplicationPrivate::screen_list.isEmpty())
1108 return QGuiApplicationPrivate::screen_list.at(0);
1112
1113
1114
1115QList<QScreen *> QGuiApplication::screens()
1117 return QGuiApplicationPrivate::screen_list;
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131QScreen *QGuiApplication::screenAt(
const QPoint &point)
1133 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1134 for (
const QScreen *screen : QGuiApplication::screens()) {
1135 if (visitedScreens.contains(screen))
1139 for (QScreen *sibling : screen->virtualSiblings()) {
1140 if (sibling->geometry().contains(point))
1143 visitedScreens.append(sibling);
1151
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193qreal QGuiApplication::devicePixelRatio()
const
1195 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1196 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1198 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1199 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1200 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1202 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1205void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1207 m_maxDevicePixelRatio = 0.0;
1211
1212
1213QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1215 if (QScreen *windowScreen = screenAt(pos)) {
1216 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1217 return windowScreen->handle()->topLevelAt(devicePosition);
1223
1224
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
1259QString QGuiApplication::platformName()
1261 if (!QGuiApplication::instance()) {
1262#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1263 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1268 return QGuiApplicationPrivate::platform_name ?
1269 *QGuiApplicationPrivate::platform_name : QString();
1277static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1279 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1280 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1281 <<
"platformPluginPath" << platformPluginPath
1282 <<
"platformThemeName" << platformThemeName;
1284 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1285 QStringList platformArguments;
1286 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1287 for (
const auto &pluginArgument : std::as_const(plugins)) {
1289 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1290 if (arguments.isEmpty())
1292 const QString name = arguments.takeFirst().toLower();
1293 QString argumentsKey = name;
1296 argumentsKey[0] = argumentsKey.at(0).toUpper();
1297 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1299 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1302 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1303 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1304 if (availablePlugins.contains(name)) {
1305 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1306 qCWarning(lcQpaPluginLoading).nospace().noquote()
1307 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1309 qCInfo(lcQpaPluginLoading).nospace().noquote()
1310 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1311 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1313 qCWarning(lcQpaPluginLoading).nospace().noquote()
1314 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1315 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1318 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1319 QGuiApplicationPrivate::platform_name =
new QString(name);
1320 platformArguments = arguments;
1325 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1326 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1327 "Reinstalling the application may fix this problem.\n");
1329 if (!availablePlugins.isEmpty())
1330 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1332#if defined(Q_OS_WIN)
1335 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1336 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1338 qFatal(
"%s", qPrintable(fatalMessage));
1346 QStringList themeNames;
1347 if (!platformThemeName.isEmpty()) {
1348 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1349 themeNames.append(platformThemeName);
1354 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1355 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1359 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1360 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1361 themeNames.append(platformIntegrationThemeNames);
1364 for (
const QString &themeName : std::as_const(themeNames)) {
1365 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1366 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1367 if (QGuiApplicationPrivate::platform_theme) {
1368 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1371 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1372 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1373 if (QGuiApplicationPrivate::platform_theme) {
1374 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1380 if (!QGuiApplicationPrivate::platform_theme) {
1381 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1382 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1387 if (!platformArguments.isEmpty()) {
1388 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1389 for (
const QString &argument : std::as_const(platformArguments)) {
1390 const qsizetype equalsPos = argument.indexOf(u'=');
1391 const QByteArray name =
1392 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1394 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1395 nativeInterface->setProperty(name.constData(), std::move(value));
1400 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1401 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1402 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1403 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1405 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1406 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1407 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1413 for (
int i = 0; i < pluginList.size(); ++i) {
1414 QByteArray pluginSpec = pluginList.at(i);
1415 qsizetype colonPos = pluginSpec.indexOf(
':');
1418 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1420 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1421 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1423 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1425 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1429#if QT_CONFIG(commandlineparser)
1430void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1432 QCoreApplicationPrivate::addQtOptions(options);
1434#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1435 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1436 const bool x11 = sessionType ==
"x11";
1439 const bool x11 =
false;
1442 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1443 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1444 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1445 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1446 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1447 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1448 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1449 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1450 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1451 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1452 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1453 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1454 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1455 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1456 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1457 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1458 options->append(QCommandLineOption(QStringLiteral(
"session"),
1459 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1462 options->append(QCommandLineOption(QStringLiteral(
"display"),
1463 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1464 options->append(QCommandLineOption(QStringLiteral(
"name"),
1465 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1466 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1467 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1468 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1469 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1470 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1471 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1473 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1474 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1475 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1476 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1477 options->append(QCommandLineOption(QStringLiteral(
"title"),
1478 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1483void QGuiApplicationPrivate::createPlatformIntegration()
1485 QHighDpiScaling::initHighDpiScaling();
1488 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1491 QByteArray platformName;
1492#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1493 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1495#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1496 QList<QByteArray> platformArguments = platformName.split(
':');
1497 QByteArray platformPluginBase = platformArguments.first();
1499 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1500 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1502 QVector<QByteArray> preferredPlatformOrder;
1503 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1504 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1505 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1506 preferredPlatformOrder << xcbPlatformName;
1508 platformName.clear();
1511 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1512 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1513 if (hasWaylandDisplay || isWaylandSessionType) {
1514 preferredPlatformOrder.prepend(waylandPlatformName);
1516 if (defaultIsWayland)
1517 platformName.clear();
1520 if (!platformName.isEmpty())
1521 preferredPlatformOrder.append(platformName);
1523 platformName = preferredPlatformOrder.join(
';');
1526 bool platformExplicitlySelected =
false;
1527 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1528 if (!platformNameEnv.isEmpty()) {
1529 platformName = platformNameEnv;
1530 platformExplicitlySelected =
true;
1533 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1539 int j = argc ? 1 : 0;
1540 for (
int i=1; i<argc; i++) {
1543 if (*argv[i] !=
'-') {
1544 argv[j++] = argv[i];
1547 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1548 const char *arg = argv[i];
1551 if (strcmp(arg,
"-platformpluginpath") == 0) {
1553 platformPluginPath = QFile::decodeName(argv[i]);
1554 }
else if (strcmp(arg,
"-platform") == 0) {
1556 platformExplicitlySelected =
true;
1557 platformName = argv[i];
1559 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1561 platformThemeName = QString::fromLocal8Bit(argv[i]);
1562 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1564 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1565 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1567 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1568 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1570 icon = QFile::decodeName(argv[i]);
1573 argv[j++] = argv[i];
1582 Q_UNUSED(platformExplicitlySelected);
1584 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1585 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1587 if (!icon.isEmpty())
1588 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1592
1593
1594
1595
1596
1597void QGuiApplicationPrivate::createEventDispatcher()
1599 Q_ASSERT(!eventDispatcher);
1601 if (platform_integration ==
nullptr)
1602 createPlatformIntegration();
1605 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1606 "Creating the platform integration resulted in creating an event dispatcher");
1609 Q_ASSERT(!eventDispatcher);
1611 eventDispatcher = platform_integration->createEventDispatcher();
1614void QGuiApplicationPrivate::eventDispatcherReady()
1616 if (platform_integration ==
nullptr)
1617 createPlatformIntegration();
1619 platform_integration->initialize();
1622void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1624 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1626#if defined(Q_OS_MACOS)
1627 QMacAutoReleasePool pool;
1630 QCoreApplicationPrivate::init();
1632 QCoreApplicationPrivate::is_app_running =
false;
1634 bool loadTestability =
false;
1635 QList<QByteArray> pluginList;
1637#ifndef QT_NO_SESSIONMANAGER
1639 QString session_key;
1640# if defined(Q_OS_WIN)
1641 wchar_t guidstr[40];
1643 CoCreateGuid(&guid);
1644 StringFromGUID2(guid, guidstr, 40);
1645 session_id = QString::fromWCharArray(guidstr);
1646 CoCreateGuid(&guid);
1647 StringFromGUID2(guid, guidstr, 40);
1648 session_key = QString::fromWCharArray(guidstr);
1652 int j = argc ? 1 : 0;
1653 for (
int i=1; i<argc; i++) {
1656 if (*argv[i] !=
'-') {
1657 argv[j++] = argv[i];
1660 const char *arg = argv[i];
1663 if (strcmp(arg,
"-plugin") == 0) {
1665 pluginList << argv[i];
1666 }
else if (strcmp(arg,
"-reverse") == 0) {
1667 force_reverse =
true;
1669 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1672 if (QDir::currentPath() ==
"/"_L1) {
1673 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1674 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1675 kCFURLPOSIXPathStyle));
1676 if (qbundlePath.endsWith(
".app"_L1))
1677 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1680#ifndef QT_NO_SESSIONMANAGER
1681 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1683 if (argv[i] && *argv[i]) {
1684 session_id = QString::fromLatin1(argv[i]);
1685 qsizetype p = session_id.indexOf(u'_');
1687 session_key = session_id.mid(p +1);
1688 session_id = session_id.left(p);
1690 is_session_restored =
true;
1693 }
else if (strcmp(arg,
"-testability") == 0) {
1694 loadTestability =
true;
1695 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1696 s = QString::fromLocal8Bit(arg + 7);
1697 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1698 s = QString::fromLocal8Bit(argv[++i]);
1700 argv[j++] = argv[i];
1713 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1714 if (!envPlugins.isEmpty())
1715 pluginList += envPlugins.split(
',');
1717 if (platform_integration ==
nullptr)
1718 createPlatformIntegration();
1721 QFont::initialize();
1725 QCursorData::initialize();
1729 qRegisterGuiVariant();
1731#if QT_CONFIG(animation)
1733 qRegisterGuiGetInterpolator();
1736 QWindowSystemInterfacePrivate::eventTime.start();
1738 is_app_running =
true;
1739 init_plugins(pluginList);
1740 QWindowSystemInterface::flushWindowSystemEvents();
1742 Q_Q(QGuiApplication);
1743#ifndef QT_NO_SESSIONMANAGER
1745 session_manager =
new QSessionManager(q, session_id, session_key);
1748#if QT_CONFIG(library)
1749 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1750 loadTestability =
true;
1752 if (loadTestability) {
1753 QLibrary testLib(QStringLiteral(
"qttestability"));
1754 if (Q_UNLIKELY(!testLib.load())) {
1755 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1757 typedef void (*TasInitialize)(
void);
1758 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1759 if (Q_UNLIKELY(!initFunction)) {
1760 qCritical(
"Library qttestability resolve failed!");
1767 Q_UNUSED(loadTestability);
1771 QGuiApplication::setLayoutDirection(layout_direction);
1773 if (!QGuiApplicationPrivate::displayName)
1774 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1775 q, &QGuiApplication::applicationDisplayNameChanged);
1778extern void qt_cleanupFontDatabase();
1780QGuiApplicationPrivate::~QGuiApplicationPrivate()
1782 is_app_closing =
true;
1783 is_app_running =
false;
1785 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1786 delete generic_plugin_list.at(i);
1787 generic_plugin_list.clear();
1789 clearFontUnlocked();
1794 QCursorData::cleanup();
1797 layout_direction = Qt::LayoutDirectionAuto;
1799 cleanupThreadData();
1801 delete QGuiApplicationPrivate::styleHints;
1802 QGuiApplicationPrivate::styleHints =
nullptr;
1805 qt_cleanupFontDatabase();
1807 QPixmapCache::clear();
1810 if (ownGlobalShareContext) {
1811 delete qt_gl_global_share_context();
1812 qt_gl_set_global_share_context(
nullptr);
1816#if QT_CONFIG(vulkan)
1817 QVulkanDefaultInstance::cleanup();
1820 platform_integration->destroy();
1822 delete platform_theme;
1823 platform_theme =
nullptr;
1824 delete platform_integration;
1825 platform_integration =
nullptr;
1827 window_list.clear();
1829 screen_list.clear();
1836QCursor *overrideCursor();
1837void setOverrideCursor(
const QCursor &);
1838void changeOverrideCursor(
const QCursor &);
1839void restoreOverrideCursor();
1843static QFont font(
const QWidget*);
1844static QFont font(
const char *className);
1845static void setFont(
const QFont &,
const char *className =
nullptr);
1846static QFontMetrics fontMetrics();
1848#ifndef QT_NO_CLIPBOARD
1849static QClipboard *clipboard();
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1868 return QGuiApplicationPrivate::modifier_buttons;
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1890 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1891 return pi->keyMapper()->queryKeyboardModifiers();
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907Qt::MouseButtons QGuiApplication::mouseButtons()
1909 return QGuiApplicationPrivate::mouse_buttons;
1913
1914
1915
1916
1917QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1919 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1920 return pi ? pi->nativeInterface() :
nullptr;
1924
1925
1926
1927QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1929 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1931 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1935 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962int QGuiApplication::exec()
1964#if QT_CONFIG(accessibility)
1965 QAccessible::setRootObject(qApp);
1967 return QCoreApplication::exec();
1970void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
1972 if (e->spontaneous()) {
1980 switch (e->type()) {
1981 case QEvent::MouseButtonPress: {
1982 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1983 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
1984 QGuiApplicationPrivate::mouse_buttons |= me->button();
1987 case QEvent::MouseButtonDblClick: {
1988 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1989 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
1990 QGuiApplicationPrivate::mouse_buttons |= me->button();
1993 case QEvent::MouseButtonRelease: {
1994 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
1995 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
1996 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
1999 case QEvent::KeyPress:
2000 case QEvent::KeyRelease:
2001 case QEvent::MouseMove:
2002#if QT_CONFIG(wheelevent)
2005 case QEvent::TouchBegin:
2006 case QEvent::TouchUpdate:
2007 case QEvent::TouchEnd:
2008#if QT_CONFIG(tabletevent)
2009 case QEvent::TabletMove:
2010 case QEvent::TabletPress:
2011 case QEvent::TabletRelease:
2014 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2015 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2025
2026bool QGuiApplication::notify(QObject *object, QEvent *event)
2028 Q_D(QGuiApplication);
2029 if (object->isWindowType()) {
2030 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2034 switch (event->type()) {
2035 case QEvent::ApplicationDeactivate:
2036 case QEvent::OrientationChange:
2042 d->closeAllPopups();
2048 QGuiApplicationPrivate::captureGlobalModifierState(event);
2050 return QCoreApplication::notify(object, event);
2054
2055bool QGuiApplication::event(QEvent *e)
2057 switch (e->type()) {
2058 case QEvent::LanguageChange:
2060 if (layout_direction == Qt::LayoutDirectionAuto)
2061 setLayoutDirection(layout_direction);
2062 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2063 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2065 case QEvent::ApplicationFontChange:
2066 case QEvent::ApplicationPaletteChange:
2067 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2068 postEvent(topLevelWindow,
new QEvent(e->type()));
2070 case QEvent::ThemeChange:
2071 for (
auto *w : QGuiApplication::allWindows())
2077 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2079 if (!topLevelWindow->handle())
2081 if (!topLevelWindow->close()) {
2090 return QCoreApplication::event(e);
2093#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2095
2096
2097bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2099 QT_IGNORE_DEPRECATIONS(
2100 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2105bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2109 QPlatformWindow *platformWindow = window->handle();
2110 if (!platformWindow)
2113 if (event->spontaneous())
2116 return platformWindow->windowEvent(event);
2119bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2121 return window->nativeEvent(eventType, message, result);
2124bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2126 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArray(
"qtvirtualkeyboard");
2127 return usingVirtualKeyboard;
2131bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2133 if (!isUsingVirtualKeyboard()) {
2134 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2138 static QPointer<QWindow> virtualKeyboard;
2139 const QEvent::Type type = e->type();
2140 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2141 const auto me =
static_cast<QMouseEvent *>(e);
2142 const QPointF posF = me->globalPosition();
2143 const QPoint pos = posF.toPoint();
2146 if (!virtualKeyboard) {
2147 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2148 win->inherits(
"QtVirtualKeyboard::InputView")) {
2149 virtualKeyboard = win;
2151 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2156 Q_ASSERT(virtualKeyboard);
2157 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2158 && virtualKeyboard->geometry().contains(pos);
2160 if (!virtualKeyboardUnderMouse) {
2161 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2162 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2166 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2167 me->button(), me->buttons(), me->modifiers(),
2168 me->pointingDevice());
2170 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2171 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2177void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2179 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2180 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2183 case QWindowSystemInterfacePrivate::Mouse:
2184 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2186 case QWindowSystemInterfacePrivate::Wheel:
2187 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2189 case QWindowSystemInterfacePrivate::Key:
2190 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2192 case QWindowSystemInterfacePrivate::Touch:
2193 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2195 case QWindowSystemInterfacePrivate::GeometryChange:
2196 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2198 case QWindowSystemInterfacePrivate::Enter:
2199 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2201 case QWindowSystemInterfacePrivate::Leave:
2202 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2204 case QWindowSystemInterfacePrivate::FocusWindow:
2205 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2207 case QWindowSystemInterfacePrivate::WindowStateChanged:
2208 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2210 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2211 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2213 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2214 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2216 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2217 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2219 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2220 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2221 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2223 case QWindowSystemInterfacePrivate::ApplicationTermination:
2224 QGuiApplicationPrivate::processApplicationTermination(e);
2226 case QWindowSystemInterfacePrivate::FlushEvents: {
2227 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2228 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2230 case QWindowSystemInterfacePrivate::Close:
2231 QGuiApplicationPrivate::processCloseEvent(
2232 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2234 case QWindowSystemInterfacePrivate::ScreenOrientation:
2235 QGuiApplicationPrivate::processScreenOrientationChange(
2236 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2238 case QWindowSystemInterfacePrivate::ScreenGeometry:
2239 QGuiApplicationPrivate::processScreenGeometryChange(
2240 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2242 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2243 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2244 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2246 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2247 QGuiApplicationPrivate::processScreenRefreshRateChange(
2248 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2250 case QWindowSystemInterfacePrivate::ThemeChange:
2251 QGuiApplicationPrivate::processThemeChanged(
2252 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2254 case QWindowSystemInterfacePrivate::Expose:
2255 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2257 case QWindowSystemInterfacePrivate::Paint:
2258 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2260 case QWindowSystemInterfacePrivate::Tablet:
2261 QGuiApplicationPrivate::processTabletEvent(
2262 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2264 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2265 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2266 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2268 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2269 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2270 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2272#ifndef QT_NO_GESTURES
2273 case QWindowSystemInterfacePrivate::Gesture:
2274 QGuiApplicationPrivate::processGestureEvent(
2275 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2278 case QWindowSystemInterfacePrivate::PlatformPanel:
2279 QGuiApplicationPrivate::processPlatformPanelEvent(
2280 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2282 case QWindowSystemInterfacePrivate::FileOpen:
2283 QGuiApplicationPrivate::processFileOpenEvent(
2284 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2286#ifndef QT_NO_CONTEXTMENU
2287 case QWindowSystemInterfacePrivate::ContextMenu:
2288 QGuiApplicationPrivate::processContextMenuEvent(
2289 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2292 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2293 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2296 qWarning() <<
"Unknown user input event type:" << e->type;
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2315 QEvent::Type type = QEvent::None;
2316 Qt::MouseButton button = Qt::NoButton;
2317 QWindow *window = e->window.data();
2318 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2320 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2321 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2322 bool mouseMove =
false;
2323 bool mousePress =
false;
2324 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2325 QPointF globalPoint = e->globalPos;
2327 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2328 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2332 type = e->buttonType;
2335 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2337 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2340 if (!mouseMove && positionChanged) {
2341 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2342 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2343 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2344 e->source, e->nonClientArea, device, e->eventPointId);
2346 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2347 processMouseEvent(&moveEvent);
2348 processMouseEvent(e);
2351 if (type == QEvent::MouseMove && !positionChanged) {
2359 modifier_buttons = e->modifiers;
2360 QPointF localPoint = e->localPos;
2361 bool doubleClick =
false;
2362 auto persistentEPD = devPriv->pointById(0);
2364 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2365 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2368 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2369 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2370 mouseDoubleClickDistance : touchDoubleTapDistance);
2371 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2372 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2373 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2374 mousePressButton = Qt::NoButton;
2376 static unsigned long lastPressTimestamp = 0;
2377 static QPointer<QWindow> lastPressWindow =
nullptr;
2378 mouse_buttons = e->buttons;
2380 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2381 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2382 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2383 && button == mousePressButton && lastPressWindow == e->window;
2384 mousePressButton = button;
2385 lastPressTimestamp = e ->timestamp;
2386 lastPressWindow = e->window;
2390 if (e->nullWindow()) {
2391 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2395 if (e->buttons != Qt::NoButton) {
2396 if (!currentMousePressWindow)
2397 currentMousePressWindow = window;
2399 window = currentMousePressWindow;
2400 }
else if (currentMousePressWindow) {
2401 window = currentMousePressWindow;
2402 currentMousePressWindow =
nullptr;
2404 localPoint = window->mapFromGlobal(globalPoint);
2412 if (!e->synthetic()) {
2413 if (
const QScreen *screen = window->screen())
2414 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2415 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2416 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2417 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2418 button, e->buttons, e->modifiers, e->source, device);
2422 ev.QInputEvent::setTimestamp(e->timestamp);
2423 cursor->pointerEvent(ev);
2428 const auto *activePopup = activePopupWindow();
2429 if (type == QEvent::MouseButtonPress)
2430 active_popup_on_press = activePopup;
2431 if (window->d_func()->blockedByModalWindow && !activePopup) {
2436 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2437 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2440 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2441 persistentEPD =
nullptr;
2443 ev.setTimestamp(e->timestamp);
2445 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2447 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2448 if (handlingPopup) {
2449 if (type == QEvent::MouseButtonPress)
2450 active_popup_on_press = handlingPopup;
2455 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2457 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2460 QGuiApplication::sendSpontaneousEvent(window, &ev);
2461 e->eventAccepted = ev.isAccepted();
2462 if (!e->synthetic() && !ev.isAccepted()
2463 && !e->nonClientArea
2464 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2465 QList<QWindowSystemInterface::TouchPoint> points;
2466 QWindowSystemInterface::TouchPoint point;
2468 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2473 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2474 point.state = QEventPoint::State::Pressed;
2475 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2476 point.state = QEventPoint::State::Released;
2477 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2478 point.state = QEventPoint::State::Updated;
2486 const QList<QEventPoint> &touchPoints =
2487 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2489 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2490 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2491 processTouchEvent(&fake);
2494 mousePressButton = Qt::NoButton;
2495 if (!e->window.isNull() || e->nullWindow()) {
2496 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2497 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2498 button, e->buttons, e->modifiers, e->source, device);
2499 dblClickEvent.setTimestamp(e->timestamp);
2500 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2503 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2504 popup_closed_on_press =
false;
2505 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2506 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2507 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2512void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2514#if QT_CONFIG(wheelevent)
2515 QWindow *window = e->window.data();
2516 QPointF globalPoint = e->globalPos;
2517 QPointF localPoint = e->localPos;
2519 if (e->nullWindow()) {
2520 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2522 localPoint = window->mapFromGlobal(globalPoint);
2528 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2529 modifier_buttons = e->modifiers;
2531 if (window->d_func()->blockedByModalWindow) {
2536 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2537 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2538 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2539 ev.setTimestamp(e->timestamp);
2540 QGuiApplication::sendSpontaneousEvent(window, &ev);
2541 e->eventAccepted = ev.isAccepted();
2547void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2549 QWindow *window = e->window.data();
2550 modifier_buttons = e->modifiers;
2553 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2556 window = QGuiApplication::focusWindow();
2560 e->eventAccepted =
false;
2564#if defined(Q_OS_ANDROID)
2565 static bool backKeyPressAccepted =
false;
2566 static bool menuKeyPressAccepted =
false;
2569#if !defined(Q_OS_MACOS)
2572 if (e->keyType == QEvent::KeyPress) {
2573 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2574 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2575#if defined(Q_OS_ANDROID)
2576 backKeyPressAccepted = e->key == Qt::Key_Back;
2577 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2584 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2585 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2586 e->unicode, e->repeat, e->repeatCount);
2587 ev.setTimestamp(e->timestamp);
2589 const auto *activePopup = activePopupWindow();
2590 if (activePopup && activePopup != window) {
2592 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2598 if (!window->d_func()->blockedByModalWindow)
2599 QGuiApplication::sendSpontaneousEvent(window, &ev);
2602 ev.setAccepted(
false);
2604 if (e->keyType == QEvent::KeyPress) {
2605 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2606 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2607 }
else if (e->keyType == QEvent::KeyRelease) {
2608 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2610 QWindowSystemInterface::handleCloseEvent(window);
2611 }
else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2612 platform_theme->showPlatformMenuBar();
2616 e->eventAccepted = ev.isAccepted();
2619void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2623 if (e->enter.data()->d_func()->blockedByModalWindow) {
2628 currentMouseWindow = e->enter;
2631 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2638 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2639 auto epd = devPriv->queryPointById(event.points().first().id());
2641 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2643 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2646void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2650 if (e->leave.data()->d_func()->blockedByModalWindow) {
2655 currentMouseWindow =
nullptr;
2657 QEvent event(QEvent::Leave);
2658 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2661void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2663 QWindow *previous = QGuiApplicationPrivate::focus_window;
2664 QWindow *newFocus = e->focused.data();
2666 if (previous == newFocus)
2669 bool activatedPopup =
false;
2671 if (QPlatformWindow *platformWindow = newFocus->handle())
2672 if (platformWindow->isAlertState())
2673 platformWindow->setAlertState(
false);
2674 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2676 activatePopup(newFocus);
2679 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2682 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2683 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2686 QGuiApplicationPrivate::focus_window = newFocus;
2691 Qt::FocusReason r = e->reason;
2692 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2693 r = Qt::PopupFocusReason;
2694 QFocusEvent focusOut(QEvent::FocusOut, r);
2695 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2696 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2697 qApp, SLOT(_q_updateFocusObject(QObject*)));
2698 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2699 setApplicationState(Qt::ApplicationActive);
2702 if (QGuiApplicationPrivate::focus_window) {
2703 Qt::FocusReason r = e->reason;
2704 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2705 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2706 r = Qt::PopupFocusReason;
2707 QFocusEvent focusIn(QEvent::FocusIn, r);
2708 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2709 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2710 qApp, SLOT(_q_updateFocusObject(QObject*)));
2711 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2712 setApplicationState(Qt::ApplicationInactive);
2716 self->notifyActiveWindowChange(previous);
2718 if (previousFocusObject !=
qApp->focusObject() ||
2724 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2725 self->_q_updateFocusObject(
qApp->focusObject());
2729 emit
qApp->focusWindowChanged(newFocus);
2731 emit previous->activeChanged();
2733 emit newFocus->activeChanged();
2736void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2738 if (QWindow *window = wse->window.data()) {
2739 QWindowPrivate *windowPrivate = qt_window_private(window);
2740 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2742 windowPrivate->windowState = wse->newState;
2743 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2744 if (newEffectiveState != originalEffectiveState)
2745 emit window->windowStateChanged(newEffectiveState);
2747 windowPrivate->updateVisibility();
2749 QWindowStateChangeEvent e(wse->oldState);
2750 QGuiApplication::sendSpontaneousEvent(window, &e);
2754void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2756 QWindow *window = wse->window.data();
2760 if (window->screen() == wse->screen.data())
2763 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2764 if (QScreen *screen = wse->screen.data())
2765 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2767 topLevelWindow->setScreen(
nullptr);
2771void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2773 if (wde->window.isNull())
2775 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2778void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2780 if (wse->window.isNull())
2783 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2785 QEvent event(QEvent::SafeAreaMarginsChange);
2786 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2789void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2792 self->handleThemeChanged();
2794 QIconPrivate::clearIconCache();
2796 QEvent themeChangeEvent(QEvent::ThemeChange);
2797 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2800void QGuiApplicationPrivate::handleThemeChanged()
2802 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2805 QIconLoader::instance()->updateSystemTheme();
2806 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2808 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2809 const auto locker = qt_scoped_lock(applicationFontMutex);
2810 clearFontUnlocked();
2816void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2818 if (e->window.isNull())
2821 QWindow *window = e->window.data();
2825 const QRect lastReportedGeometry = window->d_func()->geometry;
2826 const QRect requestedGeometry = e->requestedGeometry;
2827 const QRect actualGeometry = e->newGeometry;
2837 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2838 || requestedGeometry.size() != actualGeometry.size();
2839 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2840 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2842 window->d_func()->geometry = actualGeometry;
2844 if (isResize || window->d_func()->resizeEventPending) {
2845 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2846 QGuiApplication::sendSpontaneousEvent(window, &e);
2848 window->d_func()->resizeEventPending =
false;
2850 if (actualGeometry.width() != lastReportedGeometry.width())
2851 emit window->widthChanged(actualGeometry.width());
2852 if (actualGeometry.height() != lastReportedGeometry.height())
2853 emit window->heightChanged(actualGeometry.height());
2858 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2859 QGuiApplication::sendSpontaneousEvent(window, &e);
2861 if (actualGeometry.x() != lastReportedGeometry.x())
2862 emit window->xChanged(actualGeometry.x());
2863 if (actualGeometry.y() != lastReportedGeometry.y())
2864 emit window->yChanged(actualGeometry.y());
2868void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2870 if (e->window.isNull())
2872 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2875 e->eventAccepted =
false;
2880 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2882 e->eventAccepted = event.isAccepted();
2885void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2887 if (e->url.isEmpty())
2890 QFileOpenEvent event(e->url);
2891 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2894QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2896 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2897 TabletPointData &pointData = tabletDevicePoints[i];
2898 if (pointData.deviceId == deviceId)
2902 tabletDevicePoints.append(TabletPointData(deviceId));
2903 return tabletDevicePoints.last();
2906void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2908#if QT_CONFIG(tabletevent)
2909 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2910 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2912 QEvent::Type type = QEvent::TabletMove;
2913 if (e->buttons != pointData.state)
2914 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2916 QWindow *window = e->window.data();
2917 modifier_buttons = e->modifiers;
2919 bool localValid =
true;
2923 if (type == QEvent::TabletPress) {
2924 if (e->nullWindow()) {
2925 window = QGuiApplication::topLevelAt(e->global.toPoint());
2930 active_popup_on_press = activePopupWindow();
2931 pointData.target = window;
2933 if (e->nullWindow()) {
2934 window = pointData.target;
2937 if (type == QEvent::TabletRelease)
2938 pointData.target =
nullptr;
2942 QPointF local = e->local;
2944 QPointF delta = e->global - e->global.toPoint();
2945 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2949 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2950 Qt::MouseButton button = Qt::NoButton;
2951 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
2952 if (check & stateChange) {
2953 button = Qt::MouseButton(check);
2958 const auto *activePopup = activePopupWindow();
2959 if (window->d_func()->blockedByModalWindow && !activePopup) {
2964 QTabletEvent tabletEvent(type, device, local, e->global,
2965 e->pressure, e->xTilt, e->yTilt,
2966 e->tangentialPressure, e->rotation, e->z,
2967 e->modifiers, button, e->buttons);
2968 tabletEvent.setAccepted(
false);
2969 tabletEvent.setTimestamp(e->timestamp);
2971 if (activePopup && activePopup != window) {
2973 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
2977 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
2978 pointData.state = e->buttons;
2979 if (!tabletEvent.isAccepted()
2980 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
2981 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
2983 const QEvent::Type mouseType = [&]() {
2985 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
2986 case QEvent::TabletMove:
return QEvent::MouseMove;
2987 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
2988 default: Q_UNREACHABLE();
2991 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
2992 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
2993 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2994 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
2995 << e->local << button << e->buttons << e->modifiers;
2996 processMouseEvent(&mouseEvent);
3003void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3005#if QT_CONFIG(tabletevent)
3006 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3007 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3008 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3009 tabletDevicePoint(dev->uniqueId().numericId()).state);
3010 ev.setTimestamp(e->timestamp);
3011 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3017void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3019#if QT_CONFIG(tabletevent)
3020 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3021 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3022 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3023 tabletDevicePoint(dev->uniqueId().numericId()).state);
3024 ev.setTimestamp(e->timestamp);
3025 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3031#ifndef QT_NO_GESTURES
3032void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3034 if (e->window.isNull())
3037 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3038 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3039 e->delta, e->sequenceId);
3040 ev.setTimestamp(e->timestamp);
3041 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3045void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3050 if (e->window->d_func()->blockedByModalWindow) {
3055 QEvent ev(QEvent::PlatformPanel);
3056 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3059#ifndef QT_NO_CONTEXTMENU
3060void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3064 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3067 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3068 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3069 e->eventAccepted = ev.isAccepted();
3073void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3075 if (!QInputDevicePrivate::isRegistered(e->device))
3078 modifier_buttons = e->modifiers;
3079 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3080 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3082 if (e->touchType == QEvent::TouchCancel) {
3085 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3086 touchEvent.setTimestamp(e->timestamp);
3087 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3088 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3090 for (
auto &epd : devPriv->activePoints.values()) {
3091 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3092 windowsNeedingCancel.insert(w);
3095 for (QWindow *w : windowsNeedingCancel)
3096 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3098 if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3099 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
3100 synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3101 if (!synthIt->window)
3103 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3110 QEvent::MouseButtonRelease,
3111 Qt::MouseEventNotSynthesized,
3114 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3115 processMouseEvent(&fake);
3117 self->synthesizedMousePoints.clear();
3119 self->lastTouchType = e->touchType;
3124 if (self->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3127 self->lastTouchType = e->touchType;
3129 QPointer<QWindow> window = e->window;
3130 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3136 for (
auto &tempPt : e->points) {
3138 auto epd = devPriv->pointById(tempPt.id());
3139 auto &ep = epd->eventPoint;
3140 epd->eventPoint.setAccepted(
false);
3141 switch (tempPt.state()) {
3142 case QEventPoint::State::Pressed:
3144 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3145 window = devPriv->firstActiveWindow();
3148 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3149 QMutableEventPoint::setWindow(ep, window);
3150 active_popup_on_press = activePopupWindow();
3153 case QEventPoint::State::Released:
3154 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3155 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3156 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3157 window = QMutableEventPoint::window(ep);
3161 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3162 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3163 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3164 window = QMutableEventPoint::window(ep);
3168 if (Q_UNLIKELY(!window)) {
3169 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3172 QMutableEventPoint::update(tempPt, ep);
3174 Q_ASSERT(window.data() !=
nullptr);
3177 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3180 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3183 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3187 for (QMutableTouchEvent &ev : touchEvents) {
3188 if (ev.target() == window.data()) {
3195 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3196 mte.setTimestamp(e->timestamp);
3197 mte.setTarget(window.data());
3198 touchEvents.append(mte);
3202 if (touchEvents.isEmpty())
3205 for (QMutableTouchEvent &touchEvent : touchEvents) {
3206 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3208 QEvent::Type eventType;
3209 switch (touchEvent.touchPointStates()) {
3210 case QEventPoint::State::Pressed:
3211 eventType = QEvent::TouchBegin;
3213 case QEventPoint::State::Released:
3214 eventType = QEvent::TouchEnd;
3217 eventType = QEvent::TouchUpdate;
3221 const auto *activePopup = activePopupWindow();
3222 if (window->d_func()->blockedByModalWindow && !activePopup) {
3226 if (touchEvent.type() == QEvent::TouchEnd) {
3229 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3230 touchEvent.setTimestamp(e->timestamp);
3231 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3236 if (activePopup && activePopup != window) {
3238 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3245 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3247 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3249 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3251 QEvent::Type mouseEventType = QEvent::MouseMove;
3252 Qt::MouseButton button = Qt::NoButton;
3253 Qt::MouseButtons buttons = Qt::LeftButton;
3254 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3255 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3256 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3258 if (m_fakeMouseSourcePointId >= 0) {
3259 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3261 switch (touchPoint->state()) {
3262 case QEventPoint::State::Pressed:
3263 mouseEventType = QEvent::MouseButtonPress;
3264 button = Qt::LeftButton;
3266 case QEventPoint::State::Released:
3267 mouseEventType = QEvent::MouseButtonRelease;
3268 button = Qt::LeftButton;
3269 buttons = Qt::NoButton;
3270 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3271 m_fakeMouseSourcePointId = -1;
3276 if (touchPoint->state() != QEventPoint::State::Released) {
3277 self->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3278 touchPoint->position(), touchPoint->globalPosition(), window));
3284 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3285 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3286 touchPoint->globalPosition(),
3291 Qt::MouseEventSynthesizedByQt,
3295 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3296 processMouseEvent(&fake);
3299 if (eventType == QEvent::TouchEnd)
3300 self->synthesizedMousePoints.clear();
3307 for (
const QEventPoint &touchPoint : e->points) {
3308 if (touchPoint.state() == QEventPoint::State::Released)
3309 devPriv->removePointById(touchPoint.id());
3313void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3316 if (QCoreApplication::startingUp())
3322 QScreen *s = e->screen.data();
3323 s->d_func()->orientation = e->orientation;
3325 emit s->orientationChanged(s->orientation());
3327 QScreenOrientationChangeEvent event(s, s->orientation());
3328 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3331void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3334 if (QCoreApplication::startingUp())
3341 QScreen *s = e->screen.data();
3342 QScreenPrivate::UpdateEmitter updateEmitter(s);
3346 s->d_func()->geometry = e->geometry;
3347 s->d_func()->availableGeometry = e->availableGeometry;
3349 s->d_func()->updatePrimaryOrientation();
3352 resetCachedDevicePixelRatio();
3355void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3358 if (QCoreApplication::startingUp())
3361 QHighDpiScaling::updateHighDpiScaling();
3367 QScreen *s = e->screen.data();
3368 QScreenPrivate::UpdateEmitter updateEmitter(s);
3369 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3370 s->d_func()->updateGeometry();
3373 for (QWindow *window : QGuiApplication::allWindows())
3374 if (window->screen() == e->screen)
3375 QWindowPrivate::get(window)->updateDevicePixelRatio();
3377 resetCachedDevicePixelRatio();
3380void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3383 if (QCoreApplication::startingUp())
3389 QScreen *s = e->screen.data();
3390 qreal rate = e->rate;
3394 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3395 s->d_func()->refreshRate = rate;
3396 emit s->refreshRateChanged(s->refreshRate());
3400void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3405 QWindow *window = e->window.data();
3408 QWindowPrivate *p = qt_window_private(window);
3410 if (!p->receivedExpose) {
3411 if (p->resizeEventPending) {
3414 QResizeEvent e(window->geometry().size(), p->geometry.size());
3415 QGuiApplication::sendSpontaneousEvent(window, &e);
3417 p->resizeEventPending =
false;
3426 p->receivedExpose =
true;
3430 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3432 const bool wasExposed = p->exposed;
3433 p->exposed = e->isExposed && window->screen();
3438 if (e->isExposed && !e->region.isEmpty()) {
3439 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3441 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3442 <<
"Please file a QTBUG which explains how to reproduce.";
3446 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3447 QPaintEvent paintEvent(e->region);
3448 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3449 if (paintEvent.isAccepted())
3457 QExposeEvent exposeEvent(e->region);
3458 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3459 e->eventAccepted = exposeEvent.isAccepted();
3466 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3467 QPaintEvent paintEvent(e->region);
3468 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3472void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3474 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3475 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3480 QPaintEvent paintEvent(e->region);
3481 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3485 e->eventAccepted = paintEvent.isAccepted();
3488#if QT_CONFIG(draganddrop)
3491
3492
3493
3494
3495static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3497 QGuiApplicationPrivate::mouse_buttons = buttons;
3498 QGuiApplicationPrivate::modifier_buttons = modifiers;
3501QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3502 const QPoint &p, Qt::DropActions supportedActions,
3503 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3505 updateMouseAndModifierButtonState(buttons, modifiers);
3507 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3508 QPlatformDrag *platformDrag = platformIntegration()->drag();
3509 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3510 lastAcceptedDropAction = Qt::IgnoreAction;
3511 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3515 currentDragWindow =
nullptr;
3517 QGuiApplication::sendEvent(w, &e);
3518 lastAcceptedDropAction = Qt::IgnoreAction;
3519 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3521 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3523 if (w != currentDragWindow) {
3524 lastAcceptedDropAction = Qt::IgnoreAction;
3525 if (currentDragWindow) {
3527 QGuiApplication::sendEvent(currentDragWindow, &e);
3529 currentDragWindow = w;
3530 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3531 QGuiApplication::sendEvent(w, &e);
3532 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3533 lastAcceptedDropAction = e.dropAction();
3537 if (lastAcceptedDropAction != Qt::IgnoreAction
3538 && (supportedActions & lastAcceptedDropAction)) {
3539 me.setDropAction(lastAcceptedDropAction);
3542 QGuiApplication::sendEvent(w, &me);
3543 lastAcceptedDropAction = me.isAccepted() ?
3544 me.dropAction() : Qt::IgnoreAction;
3545 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3548QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3549 const QPoint &p, Qt::DropActions supportedActions,
3550 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3552 updateMouseAndModifierButtonState(buttons, modifiers);
3554 currentDragWindow =
nullptr;
3556 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3557 QGuiApplication::sendEvent(w, &de);
3559 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3560 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3566#ifndef QT_NO_CLIPBOARD
3568
3569
3570QClipboard * QGuiApplication::clipboard()
3572 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3574 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3577 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3579 return QGuiApplicationPrivate::qt_clipboard;
3584
3585
3586
3587
3588
3589
3590
3591
3592
3595
3596
3597
3598
3599
3600
3602QPalette QGuiApplication::palette()
3604 if (!QGuiApplicationPrivate::app_pal)
3605 QGuiApplicationPrivate::updatePalette();
3607 return *QGuiApplicationPrivate::app_pal;