101#include <private/qvulkandefaultinstance_p.h>
105#include <QtCore/QThreadPool>
108#include <qtgui_tracepoints_p.h>
110#include <private/qtools_p.h>
119using namespace Qt::StringLiterals;
120using namespace QtMiscUtils;
123#define CHECK_QAPP_INSTANCE(...)
124 if (Q_LIKELY(QCoreApplication::instance())) {
126 qWarning("Must construct a QGuiApplication first.");
133Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
134Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
136Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
142Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
144Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
145 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
147Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
149Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
154Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
171Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
178Q_CONSTINIT
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
179Q_CONSTINIT
static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
182Q_DECL_DEPRECATED_X(
"Use QGuiApplicationPrivate::instance() instead")
183Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self =
nullptr;
185Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
187#ifndef QT_NO_CLIPBOARD
191Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
193Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
194Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
195Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
198Q_CONSTINIT
static QBasicMutex applicationFontMutex;
201Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
202Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
206Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
207Q_CONSTINIT QBasicAtomicInt QGuiApplicationPrivate::m_primaryScreenDpis = Q_BASIC_ATOMIC_INITIALIZER(0);
209Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
211Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
214#if QT_CONFIG(animation)
215extern void qRegisterGuiGetInterpolator();
220 return force_reverse ^
221 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
222 "Translate this string to the string 'LTR' in left-to-right"
223 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
224 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
229 if (!QGuiApplicationPrivate::app_font) {
230 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
231 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
232 QGuiApplicationPrivate::app_font =
new QFont(*font);
234 if (!QGuiApplicationPrivate::app_font)
235 QGuiApplicationPrivate::app_font =
236 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
241 delete QGuiApplicationPrivate::app_font;
242 QGuiApplicationPrivate::app_font =
nullptr;
247 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
248 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
251#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
252static bool checkNeedPortalSupport()
255 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
263#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
283 const qsizetype size = a.size();
288 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
290 else if (isAsciiDigit(*op))
295 const int numberPos = pos;
296 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
299 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
300 return ok ? result : -1;
307 for (
int i = 0; i < 4; ++i) {
309 const int value = nextGeometryToken(a, pos, &op);
321 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
325 result.corner = Qt::TopRightCorner;
334 QRect windowGeometry = window->frameGeometry();
335 QSize size = windowGeometry.size();
337 const QSize windowMinimumSize = window->minimumSize();
338 const QSize windowMaximumSize = window->maximumSize();
340 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
342 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
343 window->resize(size);
346 const QRect availableGeometry = window->screen()->virtualGeometry();
347 QPoint topLeft = windowGeometry.topLeft();
349 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
351 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
354 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
356 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
358 window->setFramePosition(topLeft);
365
366
367
368
369
370
371
372
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
491
492
493
494
495
498
499
500
501
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
646
647
648
649
650
651
652
653
654
655
656
658QGuiApplication::QGuiApplication(
int &argc,
char **argv)
660QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
662 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
666 QCoreApplicationPrivate::eventDispatcher->startingUp();
670
671
672QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
673 : QCoreApplication(p)
678
679
680QGuiApplication::~QGuiApplication()
682 Q_D(QGuiApplication);
684 qt_call_post_routines();
686 QGuiApplicationPrivate::destroyEventDispatcher();
688#ifndef QT_NO_CLIPBOARD
689 delete QGuiApplicationPrivate::qt_clipboard;
690 QGuiApplicationPrivate::qt_clipboard =
nullptr;
693#ifndef QT_NO_SESSIONMANAGER
694 delete d->session_manager;
695 d->session_manager =
nullptr;
698 QGuiApplicationPrivate::clearPalette();
699 QFontDatabase::removeAllApplicationFonts();
702 d->cursor_list.clear();
705#if QT_CONFIG(qtgui_threadpool)
707 QThreadPool *guiThreadPool =
nullptr;
709 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
714 guiThreadPool->waitForDone();
715 delete guiThreadPool;
719 delete QGuiApplicationPrivate::app_icon;
720 QGuiApplicationPrivate::app_icon =
nullptr;
721 delete QGuiApplicationPrivate::platform_name;
722 QGuiApplicationPrivate::platform_name =
nullptr;
723 delete QGuiApplicationPrivate::displayName;
724 QGuiApplicationPrivate::displayName =
nullptr;
725 delete QGuiApplicationPrivate::m_inputDeviceManager;
726 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
727 delete QGuiApplicationPrivate::desktopFileName;
728 QGuiApplicationPrivate::desktopFileName =
nullptr;
729 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
730 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
731 QGuiApplicationPrivate::lastCursorPosition.reset();
732 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
733 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
734 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
735 QGuiApplicationPrivate::currentDragWindow =
nullptr;
736 QGuiApplicationPrivate::tabletDevicePoints.clear();
737 QGuiApplicationPrivate::m_primaryScreenDpis.storeRelaxed(0);
740QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
741 : QCoreApplicationPrivate(argc, argv),
742 inputMethod(
nullptr),
743 lastTouchType(QEvent::TouchEnd)
746 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
this;)
748 application_type = QCoreApplicationPrivate::Gui;
749#ifndef QT_NO_SESSIONMANAGER
750 is_session_restored =
false;
751 is_saving_session =
false;
756
757
758
759
760
761
762
763
764
765
766
767void QGuiApplication::setApplicationDisplayName(
const QString &name)
769 if (!QGuiApplicationPrivate::displayName) {
770 QGuiApplicationPrivate::displayName =
new QString(name);
772 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
773 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
775 if (*QGuiApplicationPrivate::displayName != applicationName())
776 emit
qGuiApp->applicationDisplayNameChanged();
778 }
else if (name != *QGuiApplicationPrivate::displayName) {
779 *QGuiApplicationPrivate::displayName = name;
781 emit
qGuiApp->applicationDisplayNameChanged();
785QString QGuiApplication::applicationDisplayName()
787 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810qint64 QGuiApplication::badgeNumber()
const
812 Q_D(
const QGuiApplication);
813 return d->badgeNumber;
816void QGuiApplication::setBadgeNumber(qint64 number)
818 Q_D(QGuiApplication);
822 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
823 if (d->badgeNumber == number)
825 d->badgeNumber = number;
826 emit badgeNumberChanged(number);
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845void QGuiApplication::setDesktopFileName(
const QString &name)
847 if (!QGuiApplicationPrivate::desktopFileName)
848 QGuiApplicationPrivate::desktopFileName =
new QString;
849 *QGuiApplicationPrivate::desktopFileName = name;
850 if (name.endsWith(QLatin1String(
".desktop"))) {
851 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
852 if (!filePath.isEmpty()) {
853 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
854 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
855 "be removed. Please specify a desktop file name without .desktop suffix");
856 (*QGuiApplicationPrivate::desktopFileName).chop(8);
861QString QGuiApplication::desktopFileName()
863 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
867
868
869
870
871
872
873
874
875
876
877
878
879
880QWindow *QGuiApplication::modalWindow()
883 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
884 if (modalWindows.isEmpty())
886 return modalWindows.constFirst();
891 QWindowPrivate *p = qt_window_private(window);
892 if (p->blockedByModalWindow != shouldBeBlocked) {
893 p->blockedByModalWindow = shouldBeBlocked;
894 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
895 QGuiApplication::sendEvent(window, &e);
896 for (QObject *c : window->children()) {
897 if (c->isWindowType())
898 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
903void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
905 bool shouldBeBlocked =
false;
906 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
907 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
908 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
909 updateBlockedStatusRecursion(window, shouldBeBlocked);
917 return w->isTopLevel();
920void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
922 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
923 guiAppPrivate->modalWindowList.prepend(modal);
926 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
927 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
928 if (shouldBeBlocked) {
930 guiAppPrivate->modalWindowList.removeFirst();
931 QEvent e(QEvent::Leave);
932 QGuiApplication::sendEvent(currentMouseWindow, &e);
933 currentMouseWindow =
nullptr;
934 guiAppPrivate->modalWindowList.prepend(modal);
938 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
939 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
940 updateBlockedStatus(window);
943 updateBlockedStatus(modal);
946void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
948 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
950 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
951 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
952 updateBlockedStatus(window);
956Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
961bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
968
969
970
971
972bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
974 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
976 QWindow *unused =
nullptr;
978 blockingWindow = &unused;
979 *blockingWindow =
nullptr;
981 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
984 for (
int i = 0; i < modalWindowList.size(); ++i) {
985 QWindow *modalWindow = modalWindowList.at(i);
989 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
992 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
993 : modalWindow->modality()) {
994 case Qt::ApplicationModal:
995 *blockingWindow = modalWindow;
997 case Qt::WindowModal: {
1000 auto *current = window;
1002 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
1003 *blockingWindow = modalWindow;
1006 current = current->parent(QWindow::IncludeTransients);
1011 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1018QWindow *QGuiApplicationPrivate::activePopupWindow()
1021 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1022 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1025void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1027 if (!popup->isVisible())
1029 popup_list.removeOne(popup);
1030 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1031 popup_list.append(popup);
1034bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1036 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1037 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1042
1043
1044bool QGuiApplicationPrivate::closeAllPopups()
1050 while ((popup = activePopupWindow()) && maxiter--)
1052 return QGuiApplicationPrivate::popup_list.isEmpty();
1056
1057
1058
1059
1060
1061QWindow *QGuiApplication::focusWindow()
1063 return QGuiApplicationPrivate::focus_window;
1067
1068
1069
1070
1071
1072
1073
1076
1077
1078
1079
1080
1081
1082
1085
1086
1087
1088QObject *QGuiApplication::focusObject()
1091 return focusWindow()->focusObject();
1096
1097
1098
1099
1100
1101
1102
1103
1104QWindowList QGuiApplication::allWindows()
1106 return QGuiApplicationPrivate::window_list;
1110
1111
1112
1113
1114
1115
1116QWindowList QGuiApplication::topLevelWindows()
1118 const QWindowList &list = QGuiApplicationPrivate::window_list;
1119 QWindowList topLevelWindows;
1120 for (
int i = 0; i < list.size(); ++i) {
1121 QWindow *window = list.at(i);
1122 if (!window->isTopLevel())
1127 if (window->handle() && window->handle()->isEmbedded())
1130 topLevelWindows.prepend(window);
1133 return topLevelWindows;
1136QScreen *QGuiApplication::primaryScreen()
1138 if (QGuiApplicationPrivate::screen_list.isEmpty())
1140 return QGuiApplicationPrivate::screen_list.at(0);
1144
1145
1146
1147QList<QScreen *> QGuiApplication::screens()
1149 return QGuiApplicationPrivate::screen_list;
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163QScreen *QGuiApplication::screenAt(
const QPoint &point)
1165 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1166 for (
const QScreen *screen : QGuiApplication::screens()) {
1167 if (visitedScreens.contains(screen))
1171 for (QScreen *sibling : screen->virtualSiblings()) {
1172 if (sibling->geometry().contains(point))
1175 visitedScreens.append(sibling);
1183
1184
1185
1186
1187
1188
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225qreal QGuiApplication::devicePixelRatio()
const
1227 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1228 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1230 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1231 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1232 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1234 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1237void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1239 m_maxDevicePixelRatio = 0.0;
1242void QGuiApplicationPrivate::_q_updatePrimaryScreenDpis()
1245 const QScreen *screen = QGuiApplication::primaryScreen();
1247 int dpiX = qRound(screen->logicalDotsPerInchX());
1248 int dpiY = qRound(screen->logicalDotsPerInchY());
1249 dpis = (dpiX << 16) | (dpiY & 0xffff);
1250 QObject::connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
1251 q_func(), SLOT(_q_updatePrimaryScreenDpis()), Qt::UniqueConnection);
1253 m_primaryScreenDpis.storeRelaxed(dpis);
1257
1258
1259QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1261 if (QScreen *windowScreen = screenAt(pos)) {
1262 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1263 return windowScreen->handle()->topLevelAt(devicePosition);
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1305QString QGuiApplication::platformName()
1307 if (!QGuiApplication::instance()) {
1308#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1309 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1314 return QGuiApplicationPrivate::platform_name ?
1315 *QGuiApplicationPrivate::platform_name : QString();
1323static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1325 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1326 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1327 <<
"platformPluginPath" << platformPluginPath
1328 <<
"platformThemeName" << platformThemeName;
1330 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1331 QStringList platformArguments;
1332 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1333 for (
const auto &pluginArgument : std::as_const(plugins)) {
1335 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1336 if (arguments.isEmpty())
1338 const QString name = arguments.takeFirst().toLower();
1339 QString argumentsKey = name;
1342 argumentsKey[0] = argumentsKey.at(0).toUpper();
1343 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1345 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1348 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1349 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1350 if (availablePlugins.contains(name)) {
1351 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1352 qCWarning(lcQpaPluginLoading).nospace().noquote()
1353 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1355 qCInfo(lcQpaPluginLoading).nospace().noquote()
1356 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1357 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1359 qCWarning(lcQpaPluginLoading).nospace().noquote()
1360 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1361 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1364 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1365 QGuiApplicationPrivate::platform_name =
new QString(name);
1366 platformArguments = arguments;
1371 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1372 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1373 "Reinstalling the application may fix this problem.\n");
1375 if (!availablePlugins.isEmpty())
1376 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1378#if defined(Q_OS_WIN)
1381 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1382 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1384 qFatal(
"%s", qPrintable(fatalMessage));
1392 QStringList themeNames;
1393 if (!platformThemeName.isEmpty()) {
1394 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1395 themeNames.append(platformThemeName);
1398#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1400 if (checkNeedPortalSupport()) {
1401 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1402 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1407 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1408 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1409 themeNames.append(platformIntegrationThemeNames);
1412 for (
const QString &themeName : std::as_const(themeNames)) {
1413 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1414 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1415 if (QGuiApplicationPrivate::platform_theme) {
1416 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1419 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1420 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1421 if (QGuiApplicationPrivate::platform_theme) {
1422 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1428 if (!QGuiApplicationPrivate::platform_theme) {
1429 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1430 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1435 if (!platformArguments.isEmpty()) {
1436 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1437 for (
const QString &argument : std::as_const(platformArguments)) {
1438 const qsizetype equalsPos = argument.indexOf(u'=');
1439 const QByteArray name =
1440 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1442 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1443 nativeInterface->setProperty(name.constData(), std::move(value));
1448 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1449 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1450 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1451 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1453 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1454 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1455 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1461 for (
int i = 0; i < pluginList.size(); ++i) {
1462 QByteArray pluginSpec = pluginList.at(i);
1463 qsizetype colonPos = pluginSpec.indexOf(
':');
1466 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1468 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1469 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1471 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1473 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1477#if QT_CONFIG(commandlineparser)
1478void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1480 QCoreApplicationPrivate::addQtOptions(options);
1482#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1483 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1484 const bool x11 = sessionType ==
"x11";
1487 const bool x11 =
false;
1490 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1491 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1492 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1493 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1494 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1495 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1496 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1497 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1498 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1499 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1500 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1501 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1502 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1503 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1504 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1505 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1506 options->append(QCommandLineOption(QStringLiteral(
"session"),
1507 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1510 options->append(QCommandLineOption(QStringLiteral(
"display"),
1511 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1512 options->append(QCommandLineOption(QStringLiteral(
"name"),
1513 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1514 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1515 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1516 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1517 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1518 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1519 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1521 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1522 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1523 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1524 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1525 options->append(QCommandLineOption(QStringLiteral(
"title"),
1526 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1531void QGuiApplicationPrivate::createPlatformIntegration()
1533 QHighDpiScaling::initHighDpiScaling();
1536 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1539 QByteArray platformName;
1540#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1541 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1543#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1544 QList<QByteArray> platformArguments = platformName.split(
':');
1545 QByteArray platformPluginBase = platformArguments.first();
1547 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1548 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1550 QVector<QByteArray> preferredPlatformOrder;
1551 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1552 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1553 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1554 preferredPlatformOrder << xcbPlatformName;
1556 platformName.clear();
1559 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1560 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1561 if (hasWaylandDisplay || isWaylandSessionType) {
1562 preferredPlatformOrder.prepend(waylandPlatformName);
1564 if (defaultIsWayland)
1565 platformName.clear();
1568 if (!platformName.isEmpty())
1569 preferredPlatformOrder.append(platformName);
1571 platformName = preferredPlatformOrder.join(
';');
1574 bool platformExplicitlySelected =
false;
1575 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1576 if (!platformNameEnv.isEmpty()) {
1577 platformName = platformNameEnv;
1578 platformExplicitlySelected =
true;
1581 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1587 int j = argc ? 1 : 0;
1588 for (
int i=1; i<argc; i++) {
1591 if (*argv[i] !=
'-') {
1592 argv[j++] = argv[i];
1595 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1596 const char *arg = argv[i];
1599 if (strcmp(arg,
"-platformpluginpath") == 0) {
1601 platformPluginPath = QFile::decodeName(argv[i]);
1602 }
else if (strcmp(arg,
"-platform") == 0) {
1604 platformExplicitlySelected =
true;
1605 platformName = argv[i];
1607 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1609 platformThemeName = QString::fromLocal8Bit(argv[i]);
1610 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1612 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1613 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1615 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1616 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1618 icon = QFile::decodeName(argv[i]);
1621 argv[j++] = argv[i];
1630 Q_UNUSED(platformExplicitlySelected);
1632 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1633 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1635 if (!icon.isEmpty())
1636 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1640
1641
1642
1643
1644
1645void QGuiApplicationPrivate::createEventDispatcher()
1647 Q_ASSERT(!eventDispatcher);
1649 if (platform_integration ==
nullptr)
1650 createPlatformIntegration();
1653 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1654 "Creating the platform integration resulted in creating an event dispatcher");
1657 Q_ASSERT(!eventDispatcher);
1659 eventDispatcher = platform_integration->createEventDispatcher();
1662void QGuiApplicationPrivate::eventDispatcherReady()
1664 if (platform_integration ==
nullptr)
1665 createPlatformIntegration();
1667 platform_integration->initialize();
1670void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1672 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1674#if defined(Q_OS_MACOS)
1675 QMacAutoReleasePool pool;
1678 QObject::connect(q_func(), SIGNAL(screenAdded(QScreen*)),
1679 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1680 QObject::connect(q_func(), SIGNAL(primaryScreenChanged(QScreen *)),
1681 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1683 QCoreApplicationPrivate::init();
1685 QCoreApplicationPrivate::is_app_running =
false;
1687 bool loadTestability =
false;
1688 QList<QByteArray> pluginList;
1690#ifndef QT_NO_SESSIONMANAGER
1692 QString session_key;
1693# if defined(Q_OS_WIN)
1694 wchar_t guidstr[40];
1696 CoCreateGuid(&guid);
1697 StringFromGUID2(guid, guidstr, 40);
1698 session_id = QString::fromWCharArray(guidstr);
1699 CoCreateGuid(&guid);
1700 StringFromGUID2(guid, guidstr, 40);
1701 session_key = QString::fromWCharArray(guidstr);
1705 int j = argc ? 1 : 0;
1706 for (
int i=1; i<argc; i++) {
1709 if (*argv[i] !=
'-') {
1710 argv[j++] = argv[i];
1713 const char *arg = argv[i];
1716 if (strcmp(arg,
"-plugin") == 0) {
1718 pluginList << argv[i];
1719 }
else if (strcmp(arg,
"-reverse") == 0) {
1720 force_reverse =
true;
1722 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1725 if (QDir::currentPath() ==
"/"_L1) {
1726 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1727 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1728 kCFURLPOSIXPathStyle));
1729 if (qbundlePath.endsWith(
".app"_L1))
1730 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1733#ifndef QT_NO_SESSIONMANAGER
1734 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1736 if (argv[i] && *argv[i]) {
1737 session_id = QString::fromLatin1(argv[i]);
1738 qsizetype p = session_id.indexOf(u'_');
1740 session_key = session_id.mid(p +1);
1741 session_id = session_id.left(p);
1743 is_session_restored =
true;
1746 }
else if (strcmp(arg,
"-testability") == 0) {
1747 loadTestability =
true;
1748 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1749 s = QString::fromLocal8Bit(arg + 7);
1750 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1751 s = QString::fromLocal8Bit(argv[++i]);
1753 argv[j++] = argv[i];
1766 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1767 if (!envPlugins.isEmpty())
1768 pluginList += envPlugins.split(
',');
1770 if (platform_integration ==
nullptr)
1771 createPlatformIntegration();
1774 QFont::initialize();
1778 QCursorData::initialize();
1782 qRegisterGuiVariant();
1784#if QT_CONFIG(animation)
1786 qRegisterGuiGetInterpolator();
1789 QWindowSystemInterfacePrivate::eventTime.start();
1791#if QT_CONFIG(accessibility)
1792 QAccessible::installFactory([](
const QString &classname, QObject *object)
1793 -> QAccessibleInterface * {
1794 if (classname ==
"QForeignWindow"_L1)
1795 return new QAccessibleWindow(
static_cast<QWindow *>(object));
1800 is_app_running =
true;
1801 init_plugins(pluginList);
1802 QWindowSystemInterface::flushWindowSystemEvents();
1804 Q_Q(QGuiApplication);
1805#ifndef QT_NO_SESSIONMANAGER
1807 session_manager =
new QSessionManager(q, session_id, session_key);
1810#if QT_CONFIG(library)
1811 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1812 loadTestability =
true;
1814 if (loadTestability) {
1815 QLibrary testLib(QStringLiteral(
"qttestability"));
1816 if (Q_UNLIKELY(!testLib.load())) {
1817 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1819 typedef void (*TasInitialize)(
void);
1820 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1821 if (Q_UNLIKELY(!initFunction)) {
1822 qCritical(
"Library qttestability resolve failed!");
1829 Q_UNUSED(loadTestability);
1833 QGuiApplication::setLayoutDirection(layout_direction);
1835 if (!QGuiApplicationPrivate::displayName)
1836 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1837 q, &QGuiApplication::applicationDisplayNameChanged);
1840extern void qt_cleanupFontDatabase();
1842QGuiApplicationPrivate::~QGuiApplicationPrivate()
1844#if defined(Q_OS_MACOS)
1845 QMacAutoReleasePool pool;
1848 is_app_closing =
true;
1849 is_app_running =
false;
1851 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1852 delete generic_plugin_list.at(i);
1853 generic_plugin_list.clear();
1855 clearFontUnlocked();
1860 QCursorData::cleanup();
1863 layout_direction = Qt::LayoutDirectionAuto;
1865 cleanupThreadData();
1867 delete QGuiApplicationPrivate::styleHints;
1868 QGuiApplicationPrivate::styleHints =
nullptr;
1871 qt_cleanupFontDatabase();
1873 QPixmapCache::clear();
1876 if (ownGlobalShareContext) {
1877 delete qt_gl_global_share_context();
1878 qt_gl_set_global_share_context(
nullptr);
1882#if QT_CONFIG(vulkan)
1883 QVulkanDefaultInstance::cleanup();
1886 platform_integration->destroy();
1888 delete platform_theme;
1889 platform_theme =
nullptr;
1890 delete platform_integration;
1891 platform_integration =
nullptr;
1893 window_list.clear();
1895 screen_list.clear();
1898 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1903QCursor *overrideCursor();
1904void setOverrideCursor(
const QCursor &);
1905void changeOverrideCursor(
const QCursor &);
1906void restoreOverrideCursor();
1910static QFont font(
const QWidget*);
1911static QFont font(
const char *className);
1912static void setFont(
const QFont &,
const char *className =
nullptr);
1913static QFontMetrics fontMetrics();
1915#ifndef QT_NO_CLIPBOARD
1916static QClipboard *clipboard();
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1935 return QGuiApplicationPrivate::modifier_buttons;
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1957 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1958 return pi->keyMapper()->queryKeyboardModifiers();
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974Qt::MouseButtons QGuiApplication::mouseButtons()
1976 return QGuiApplicationPrivate::mouse_buttons;
1980
1981
1982
1983
1984QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1986 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1987 return pi ? pi->nativeInterface() :
nullptr;
1991
1992
1993
1994QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1996 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1998 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
2002 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029int QGuiApplication::exec()
2031#if QT_CONFIG(accessibility)
2032 QAccessible::setRootObject(qApp);
2034 return QCoreApplication::exec();
2037void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
2039 if (e->spontaneous()) {
2047 switch (e->type()) {
2048 case QEvent::MouseButtonPress: {
2049 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2050 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2051 QGuiApplicationPrivate::mouse_buttons |= me->button();
2054 case QEvent::MouseButtonDblClick: {
2055 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2056 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2057 QGuiApplicationPrivate::mouse_buttons |= me->button();
2060 case QEvent::MouseButtonRelease: {
2061 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2062 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2063 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2066 case QEvent::KeyPress:
2067 case QEvent::KeyRelease:
2068 case QEvent::MouseMove:
2069#if QT_CONFIG(wheelevent)
2072 case QEvent::TouchBegin:
2073 case QEvent::TouchUpdate:
2074 case QEvent::TouchEnd:
2075#if QT_CONFIG(tabletevent)
2076 case QEvent::TabletMove:
2077 case QEvent::TabletPress:
2078 case QEvent::TabletRelease:
2081 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2082 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2092
2093bool QGuiApplication::notify(QObject *object, QEvent *event)
2095 Q_D(QGuiApplication);
2096 if (object->isWindowType()) {
2097 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2101 switch (event->type()) {
2102 case QEvent::ApplicationDeactivate:
2103 case QEvent::OrientationChange:
2109 d->closeAllPopups();
2115 QGuiApplicationPrivate::captureGlobalModifierState(event);
2117 return QCoreApplication::notify(object, event);
2121
2122bool QGuiApplication::event(QEvent *e)
2124 switch (e->type()) {
2125 case QEvent::LanguageChange:
2127 if (layout_direction == Qt::LayoutDirectionAuto)
2128 setLayoutDirection(layout_direction);
2129 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2130 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2132 case QEvent::ApplicationFontChange:
2133 case QEvent::ApplicationPaletteChange:
2134 postEvent(QGuiApplication::styleHints(), e->clone());
2135 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2136 postEvent(topLevelWindow,
new QEvent(e->type()));
2138 case QEvent::ThemeChange:
2139 forwardEvent(QGuiApplication::styleHints(), e);
2140 for (
auto *w : QGuiApplication::allWindows())
2146 return QCoreApplication::event(e);
2149#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2151
2152
2153bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2155 QT_IGNORE_DEPRECATIONS(
2156 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2161bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2165 QPlatformWindow *platformWindow = window->handle();
2166 if (!platformWindow)
2169 if (event->spontaneous())
2172 return platformWindow->windowEvent(event);
2175bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2177 return window->nativeEvent(eventType, message, result);
2180bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2182 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArrayView(
"qtvirtualkeyboard");
2183 return usingVirtualKeyboard;
2187bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2189 if (!isUsingVirtualKeyboard()) {
2190 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2194 static QPointer<QWindow> virtualKeyboard;
2195 const QEvent::Type type = e->type();
2196 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2197 const auto me =
static_cast<QMouseEvent *>(e);
2198 const QPointF posF = me->globalPosition();
2199 const QPoint pos = posF.toPoint();
2202 if (!virtualKeyboard) {
2203 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2204 win->inherits(
"QtVirtualKeyboard::InputView")) {
2205 virtualKeyboard = win;
2207 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2212 Q_ASSERT(virtualKeyboard);
2213 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2214 && virtualKeyboard->geometry().contains(pos);
2216 if (!virtualKeyboardUnderMouse) {
2217 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2218 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2222 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2223 me->button(), me->buttons(), me->modifiers(),
2224 me->pointingDevice());
2226 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2227 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2233void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2235 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2236 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2238 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2239 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2240 if (!haveGuiApplication) {
2241 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2242 e->eventAccepted =
false;
2247 case QWindowSystemInterfacePrivate::Mouse:
2248 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2250 case QWindowSystemInterfacePrivate::Wheel:
2251 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2253 case QWindowSystemInterfacePrivate::Key:
2254 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2256 case QWindowSystemInterfacePrivate::Touch:
2257 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2259 case QWindowSystemInterfacePrivate::GeometryChange:
2260 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2262 case QWindowSystemInterfacePrivate::Enter:
2263 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2265 case QWindowSystemInterfacePrivate::Leave:
2266 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2268 case QWindowSystemInterfacePrivate::FocusWindow:
2269 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2271 case QWindowSystemInterfacePrivate::WindowStateChanged:
2272 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2274 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2275 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2277 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2278 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2280 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2281 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2283 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2284 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2285 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2287 case QWindowSystemInterfacePrivate::ApplicationTermination:
2288 QGuiApplicationPrivate::processApplicationTermination(e);
2290 case QWindowSystemInterfacePrivate::FlushEvents: {
2291 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2292 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2294 case QWindowSystemInterfacePrivate::Close:
2295 QGuiApplicationPrivate::processCloseEvent(
2296 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2298 case QWindowSystemInterfacePrivate::ScreenOrientation:
2299 QGuiApplicationPrivate::processScreenOrientationChange(
2300 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2302 case QWindowSystemInterfacePrivate::ScreenGeometry:
2303 QGuiApplicationPrivate::processScreenGeometryChange(
2304 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2306 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2307 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2308 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2310 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2311 QGuiApplicationPrivate::processScreenRefreshRateChange(
2312 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2314 case QWindowSystemInterfacePrivate::ThemeChange:
2315 QGuiApplicationPrivate::processThemeChanged(
2316 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2318 case QWindowSystemInterfacePrivate::Expose:
2319 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2321 case QWindowSystemInterfacePrivate::Paint:
2322 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2324 case QWindowSystemInterfacePrivate::Tablet:
2325 QGuiApplicationPrivate::processTabletEvent(
2326 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2328 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2329 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2330 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2332 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2333 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2334 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2336#ifndef QT_NO_GESTURES
2337 case QWindowSystemInterfacePrivate::Gesture:
2338 QGuiApplicationPrivate::processGestureEvent(
2339 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2342 case QWindowSystemInterfacePrivate::PlatformPanel:
2343 QGuiApplicationPrivate::processPlatformPanelEvent(
2344 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2346 case QWindowSystemInterfacePrivate::FileOpen:
2347 QGuiApplicationPrivate::processFileOpenEvent(
2348 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2350#ifndef QT_NO_CONTEXTMENU
2351 case QWindowSystemInterfacePrivate::ContextMenu:
2352 QGuiApplicationPrivate::processContextMenuEvent(
2353 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2356 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2357 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2360 qWarning() <<
"Unknown user input event type:" << e->type;
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2379 QEvent::Type type = QEvent::None;
2380 Qt::MouseButton button = Qt::NoButton;
2381 QWindow *window = e->window.data();
2382 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2384 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2385 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2386 bool mouseMove =
false;
2387 bool mousePress =
false;
2388 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2389 QPointF globalPoint = e->globalPos;
2391 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2392 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2396 type = e->buttonType;
2399 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2401 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2404 if (!mouseMove && positionChanged) {
2405 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2406 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2407 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2408 e->source, e->nonClientArea, device, e->eventPointId);
2410 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2411 processMouseEvent(&moveEvent);
2412 processMouseEvent(e);
2415 if (type == QEvent::MouseMove && !positionChanged) {
2423 modifier_buttons = e->modifiers;
2424 QPointF localPoint = e->localPos;
2425 bool doubleClick =
false;
2426 auto persistentEPD = devPriv->pointById(0);
2428 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2429 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2432 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2433 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2434 mouseDoubleClickDistance : touchDoubleTapDistance);
2435 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2436 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2437 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2438 mousePressButton = Qt::NoButton;
2440 static unsigned long lastPressTimestamp = 0;
2441 static QPointer<QWindow> lastPressWindow =
nullptr;
2442 mouse_buttons = e->buttons;
2444 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2445 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2446 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2447 && button == mousePressButton && lastPressWindow == e->window;
2448 mousePressButton = button;
2449 lastPressTimestamp = e ->timestamp;
2450 lastPressWindow = e->window;
2454 if (e->nullWindow()) {
2455 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2459 if (e->buttons != Qt::NoButton) {
2460 if (!currentMousePressWindow)
2461 currentMousePressWindow = window;
2463 window = currentMousePressWindow;
2464 }
else if (currentMousePressWindow) {
2465 window = currentMousePressWindow;
2466 currentMousePressWindow =
nullptr;
2468 localPoint = window->mapFromGlobal(globalPoint);
2476 if (!e->synthetic()) {
2477 if (
const QScreen *screen = window->screen())
2478 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2479 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2480 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2481 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2482 button, e->buttons, e->modifiers, e->source, device);
2486 ev.QInputEvent::setTimestamp(e->timestamp);
2487 cursor->pointerEvent(ev);
2492 const auto *activePopup = activePopupWindow();
2493 if (type == QEvent::MouseButtonPress)
2494 active_popup_on_press = activePopup;
2495 if (window->d_func()->blockedByModalWindow && !activePopup) {
2500 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2501 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2504 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2505 persistentEPD =
nullptr;
2507 ev.setTimestamp(e->timestamp);
2509 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2511 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2512 if (handlingPopup) {
2513 if (type == QEvent::MouseButtonPress)
2514 active_popup_on_press = handlingPopup;
2519 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2521 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2524 QGuiApplication::sendSpontaneousEvent(window, &ev);
2525 e->eventAccepted = ev.isAccepted();
2526 if (!e->synthetic() && !ev.isAccepted()
2527 && !e->nonClientArea
2528 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2529 QList<QWindowSystemInterface::TouchPoint> points;
2530 QWindowSystemInterface::TouchPoint point;
2532 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2537 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2538 point.state = QEventPoint::State::Pressed;
2539 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2540 point.state = QEventPoint::State::Released;
2541 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2542 point.state = QEventPoint::State::Updated;
2550 const QList<QEventPoint> &touchPoints =
2551 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2553 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2554 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2555 processTouchEvent(&fake);
2558 mousePressButton = Qt::NoButton;
2559 if (!e->window.isNull() || e->nullWindow()) {
2560 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2561 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2562 button, e->buttons, e->modifiers, e->source, device);
2563 dblClickEvent.setTimestamp(e->timestamp);
2564 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2567 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2568 popup_closed_on_press =
false;
2569 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2570 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2571 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2576void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2578#if QT_CONFIG(wheelevent)
2579 QWindow *window = e->window.data();
2580 QPointF globalPoint = e->globalPos;
2581 QPointF localPoint = e->localPos;
2583 if (e->nullWindow()) {
2584 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2586 localPoint = window->mapFromGlobal(globalPoint);
2592 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2593 modifier_buttons = e->modifiers;
2595 if (window->d_func()->blockedByModalWindow) {
2600 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2601 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2602 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2603 ev.setTimestamp(e->timestamp);
2604 QGuiApplication::sendSpontaneousEvent(window, &ev);
2605 e->eventAccepted = ev.isAccepted();
2611void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2613 QWindow *window = e->window.data();
2614 modifier_buttons = e->modifiers;
2615 if (e->nullWindow())
2616 window = QGuiApplication::focusWindow();
2619 e->eventAccepted =
false;
2623#if !defined(Q_OS_MACOS)
2626 if (e->keyType == QEvent::KeyPress) {
2627 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2628 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2634 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2635 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2636 e->unicode, e->repeat, e->repeatCount);
2637 ev.setTimestamp(e->timestamp);
2639 const auto *activePopup = activePopupWindow();
2640 if (activePopup && activePopup != window) {
2642 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2648 if (!window->d_func()->blockedByModalWindow)
2649 QGuiApplication::sendSpontaneousEvent(window, &ev);
2652 ev.setAccepted(
false);
2654 e->eventAccepted = ev.isAccepted();
2657void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2661 if (e->enter.data()->d_func()->blockedByModalWindow) {
2666 currentMouseWindow = e->enter;
2669 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2676 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2677 auto epd = devPriv->queryPointById(event.points().first().id());
2679 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2681 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2684void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2688 if (e->leave.data()->d_func()->blockedByModalWindow) {
2693 currentMouseWindow =
nullptr;
2695 QEvent event(QEvent::Leave);
2696 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2699void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2701 QWindow *previous = QGuiApplicationPrivate::focus_window;
2702 QWindow *newFocus = e->focused.data();
2704 if (previous == newFocus)
2707 bool activatedPopup =
false;
2709 if (QPlatformWindow *platformWindow = newFocus->handle())
2710 if (platformWindow->isAlertState())
2711 platformWindow->setAlertState(
false);
2712 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2714 activatePopup(newFocus);
2717 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2720 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2721 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2724 QGuiApplicationPrivate::focus_window = newFocus;
2729 Qt::FocusReason r = e->reason;
2730 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2731 r = Qt::PopupFocusReason;
2732 QFocusEvent focusOut(QEvent::FocusOut, r);
2733 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2734 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2735 qApp, SLOT(_q_updateFocusObject(QObject*)));
2736 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2737 setApplicationState(Qt::ApplicationActive);
2740 if (QGuiApplicationPrivate::focus_window) {
2741 Qt::FocusReason r = e->reason;
2742 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2743 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2744 r = Qt::PopupFocusReason;
2745 QFocusEvent focusIn(QEvent::FocusIn, r);
2746 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2747 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2748 qApp, SLOT(_q_updateFocusObject(QObject*)));
2749 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2750 setApplicationState(Qt::ApplicationInactive);
2753 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2754 guiAppPrivate->notifyActiveWindowChange(previous);
2756 if (previousFocusObject !=
qApp->focusObject() ||
2762 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2763 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2767 emit
qApp->focusWindowChanged(newFocus);
2769 emit previous->activeChanged();
2771 emit newFocus->activeChanged();
2774void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2776 if (QWindow *window = wse->window.data()) {
2777 QWindowPrivate *windowPrivate = qt_window_private(window);
2778 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2780 windowPrivate->windowState = wse->newState;
2781 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2782 if (newEffectiveState != originalEffectiveState)
2783 emit window->windowStateChanged(newEffectiveState);
2785 windowPrivate->updateVisibility();
2787 QWindowStateChangeEvent e(wse->oldState);
2788 QGuiApplication::sendSpontaneousEvent(window, &e);
2792void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2794 QWindow *window = wse->window.data();
2798 QScreen *screen = wse->screen.data();
2799 if (window->screen() == screen)
2802 auto *windowPrivate = QWindowPrivate::get(window);
2803 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2804 if (window == topLevelWindow) {
2806 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2808 topLevelWindow->setScreen(
nullptr);
2809 }
else if (screen) {
2814 windowPrivate->emitScreenChangedRecursion(screen);
2818void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2820 if (wde->window.isNull())
2822 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2825void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2827 if (wse->window.isNull())
2830 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2832 QEvent event(QEvent::SafeAreaMarginsChange);
2833 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2836void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2843 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2844 guiAppPrivate->handleThemeChanged();
2846 QIconPrivate::clearIconCache();
2848 QEvent themeChangeEvent(QEvent::ThemeChange);
2849 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2852void QGuiApplicationPrivate::handleThemeChanged()
2854 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2857 QIconLoader::instance()->updateSystemTheme();
2858 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2860 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2861 const auto locker = qt_scoped_lock(applicationFontMutex);
2862 clearFontUnlocked();
2868void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2870 if (e->window.isNull())
2873 QWindow *window = e->window.data();
2877 const QRect lastReportedGeometry = window->d_func()->geometry;
2878 const QRect requestedGeometry = e->requestedGeometry;
2879 const QRect actualGeometry = e->newGeometry;
2889 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2890 || requestedGeometry.size() != actualGeometry.size();
2891 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2892 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2894 window->d_func()->geometry = actualGeometry;
2896 if (isResize || window->d_func()->resizeEventPending) {
2897 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2898 QGuiApplication::sendSpontaneousEvent(window, &e);
2900 window->d_func()->resizeEventPending =
false;
2902 if (actualGeometry.width() != lastReportedGeometry.width())
2903 emit window->widthChanged(actualGeometry.width());
2904 if (actualGeometry.height() != lastReportedGeometry.height())
2905 emit window->heightChanged(actualGeometry.height());
2910 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2911 QGuiApplication::sendSpontaneousEvent(window, &e);
2913 if (actualGeometry.x() != lastReportedGeometry.x())
2914 emit window->xChanged(actualGeometry.x());
2915 if (actualGeometry.y() != lastReportedGeometry.y())
2916 emit window->yChanged(actualGeometry.y());
2920void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2922 if (e->window.isNull())
2924 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2927 e->eventAccepted =
false;
2932 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2934 e->eventAccepted = event.isAccepted();
2937void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2939 if (e->url.isEmpty())
2942 QFileOpenEvent event(e->url);
2943 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2946QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2948 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2949 TabletPointData &pointData = tabletDevicePoints[i];
2950 if (pointData.deviceId == deviceId)
2954 tabletDevicePoints.append(TabletPointData(deviceId));
2955 return tabletDevicePoints.last();
2958void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2960#if QT_CONFIG(tabletevent)
2961 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2962 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2964 QEvent::Type type = QEvent::TabletMove;
2965 if (e->buttons != pointData.state)
2966 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2968 QWindow *window = e->window.data();
2969 modifier_buttons = e->modifiers;
2971 bool localValid =
true;
2975 if (type == QEvent::TabletPress) {
2976 if (e->nullWindow()) {
2977 window = QGuiApplication::topLevelAt(e->global.toPoint());
2982 active_popup_on_press = activePopupWindow();
2983 pointData.target = window;
2985 if (e->nullWindow()) {
2986 window = pointData.target;
2989 if (type == QEvent::TabletRelease)
2990 pointData.target =
nullptr;
2994 QPointF local = e->local;
2996 QPointF delta = e->global - e->global.toPoint();
2997 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3001 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3002 Qt::MouseButton button = Qt::NoButton;
3003 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3004 if (check & stateChange) {
3005 button = Qt::MouseButton(check);
3010 const auto *activePopup = activePopupWindow();
3011 if (window->d_func()->blockedByModalWindow && !activePopup) {
3016 QTabletEvent tabletEvent(type, device, local, e->global,
3017 e->pressure, e->xTilt, e->yTilt,
3018 e->tangentialPressure, e->rotation, e->z,
3019 e->modifiers, button, e->buttons);
3020 tabletEvent.setAccepted(
false);
3021 tabletEvent.setTimestamp(e->timestamp);
3023 if (activePopup && activePopup != window) {
3025 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3029 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3030 pointData.state = e->buttons;
3031 if (!tabletEvent.isAccepted()
3032 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3033 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3035 const QEvent::Type mouseType = [&]() {
3037 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3038 case QEvent::TabletMove:
return QEvent::MouseMove;
3039 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3040 default: Q_UNREACHABLE();
3043 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3044 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3045 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3046 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3047 << e->local << button << e->buttons << e->modifiers;
3048 processMouseEvent(&mouseEvent);
3055void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3057#if QT_CONFIG(tabletevent)
3058 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3059 QTabletEvent ev(QEvent::TabletEnterProximity, dev, e->local, e->global,
3060 e->pressure, e->xTilt, e->yTilt,
3061 e->tangentialPressure, e->rotation, e->z,
3062 e->modifiers, Qt::NoButton,
3063 tabletDevicePoint(dev->uniqueId().numericId()).state);
3064 ev.setTimestamp(e->timestamp);
3065 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3071void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3073#if QT_CONFIG(tabletevent)
3074 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3075 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, e->local, e->global,
3076 e->pressure, e->xTilt, e->yTilt,
3077 e->tangentialPressure, e->rotation, e->z,
3078 e->modifiers, Qt::NoButton,
3079 tabletDevicePoint(dev->uniqueId().numericId()).state);
3080 ev.setTimestamp(e->timestamp);
3081 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3087#ifndef QT_NO_GESTURES
3088void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3090 if (e->window.isNull())
3093 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3094 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3095 e->delta, e->sequenceId);
3096 ev.setTimestamp(e->timestamp);
3097 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3101void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3106 if (e->window->d_func()->blockedByModalWindow) {
3111 QEvent ev(QEvent::PlatformPanel);
3112 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3115#ifndef QT_NO_CONTEXTMENU
3116void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3118 if (!e->window || e->window->d_func()->blockedByModalWindow) {
3119 e->eventAccepted =
false;
3123 QContextMenuEvent ev(e->pos, e->globalPos, e->modifiers, e->device);
3124 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3125 e->eventAccepted = ev.isAccepted();
3129void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3136 e->eventAccepted =
false;
3138 if (!QInputDevicePrivate::isRegistered(e->device))
3141 modifier_buttons = e->modifiers;
3142 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3143 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3145 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3147 if (e->touchType == QEvent::TouchCancel) {
3150 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3151 touchEvent.setTimestamp(e->timestamp);
3152 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3153 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3155 for (
auto &epd : devPriv->activePoints.values()) {
3156 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3157 windowsNeedingCancel.insert(w);
3160 for (QWindow *w : windowsNeedingCancel) {
3161 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3162 e->eventAccepted |= touchEvent.isAccepted();
3165 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3166 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3167 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3168 if (!synthIt->window)
3170 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3177 QEvent::MouseButtonRelease,
3178 Qt::MouseEventNotSynthesized,
3181 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3182 processMouseEvent(&fake);
3184 guiAppPrivate->synthesizedMousePoints.clear();
3187 guiAppPrivate->lastTouchType = e->touchType;
3188 devPriv->activePoints.clear();
3193 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3196 guiAppPrivate->lastTouchType = e->touchType;
3198 QPointer<QWindow> window = e->window;
3199 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3205 for (
auto &tempPt : e->points) {
3207 auto epd = devPriv->pointById(tempPt.id());
3208 auto &ep = epd->eventPoint;
3209 epd->eventPoint.setAccepted(
false);
3210 switch (tempPt.state()) {
3211 case QEventPoint::State::Pressed:
3213 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3214 window = devPriv->firstActiveWindow();
3217 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3218 QMutableEventPoint::setWindow(ep, window);
3219 active_popup_on_press = activePopupWindow();
3222 case QEventPoint::State::Released:
3223 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3224 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3225 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3226 window = QMutableEventPoint::window(ep);
3230 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3231 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3232 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3233 window = QMutableEventPoint::window(ep);
3237 if (Q_UNLIKELY(!window)) {
3238 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3241 QMutableEventPoint::update(tempPt, ep);
3243 Q_ASSERT(window.data() !=
nullptr);
3246 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3249 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3252 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3256 for (QMutableTouchEvent &ev : touchEvents) {
3257 if (ev.target() == window.data()) {
3264 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3265 mte.setTimestamp(e->timestamp);
3266 mte.setTarget(window.data());
3267 touchEvents.append(mte);
3271 if (touchEvents.isEmpty())
3274 for (QMutableTouchEvent &touchEvent : touchEvents) {
3275 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3277 QEvent::Type eventType;
3278 switch (touchEvent.touchPointStates()) {
3279 case QEventPoint::State::Pressed:
3280 eventType = QEvent::TouchBegin;
3282 case QEventPoint::State::Released:
3283 eventType = QEvent::TouchEnd;
3286 eventType = QEvent::TouchUpdate;
3290 const auto *activePopup = activePopupWindow();
3291 if (window->d_func()->blockedByModalWindow && !activePopup) {
3295 if (touchEvent.type() == QEvent::TouchEnd) {
3298 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3299 touchEvent.setTimestamp(e->timestamp);
3300 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3305 if (activePopup && activePopup != window) {
3307 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3314 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3315 e->eventAccepted |= touchEvent.isAccepted();
3317 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3319 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3321 QEvent::Type mouseEventType = QEvent::MouseMove;
3322 Qt::MouseButton button = Qt::NoButton;
3323 Qt::MouseButtons buttons = Qt::LeftButton;
3324 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3325 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3326 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3328 if (m_fakeMouseSourcePointId >= 0) {
3329 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3331 switch (touchPoint->state()) {
3332 case QEventPoint::State::Pressed:
3333 mouseEventType = QEvent::MouseButtonPress;
3334 button = Qt::LeftButton;
3336 case QEventPoint::State::Released:
3337 mouseEventType = QEvent::MouseButtonRelease;
3338 button = Qt::LeftButton;
3339 buttons = Qt::NoButton;
3340 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3341 m_fakeMouseSourcePointId = -1;
3346 if (touchPoint->state() != QEventPoint::State::Released) {
3347 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3348 touchPoint->position(), touchPoint->globalPosition(), window));
3354 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3355 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3356 touchPoint->globalPosition(),
3361 Qt::MouseEventSynthesizedByQt,
3365 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3366 processMouseEvent(&fake);
3367 e->eventAccepted |= fake.eventAccepted;
3370 if (eventType == QEvent::TouchEnd)
3371 guiAppPrivate->synthesizedMousePoints.clear();
3378 for (
const QEventPoint &touchPoint : e->points) {
3379 if (touchPoint.state() == QEventPoint::State::Released)
3380 devPriv->removePointById(touchPoint.id());
3384void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3387 if (QCoreApplication::startingUp())
3393 QScreen *s = e->screen.data();
3394 s->d_func()->orientation = e->orientation;
3396 emit s->orientationChanged(s->orientation());
3398 QScreenOrientationChangeEvent event(s, s->orientation());
3399 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3402void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3405 if (QCoreApplication::startingUp())
3412 QScreen *s = e->screen.data();
3413 QScreenPrivate::UpdateEmitter updateEmitter(s);
3417 s->d_func()->geometry = e->geometry;
3418 s->d_func()->availableGeometry = e->availableGeometry;
3420 s->d_func()->updatePrimaryOrientation();
3423 resetCachedDevicePixelRatio();
3426void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3429 if (QCoreApplication::startingUp())
3432 QHighDpiScaling::updateHighDpiScaling();
3438 QScreen *s = e->screen.data();
3439 QScreenPrivate::UpdateEmitter updateEmitter(s);
3440 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3441 s->d_func()->updateGeometry();
3444 for (QWindow *window : QGuiApplication::allWindows())
3445 if (window->screen() == e->screen)
3446 QWindowPrivate::get(window)->updateDevicePixelRatio();
3448 resetCachedDevicePixelRatio();
3451void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3454 if (QCoreApplication::startingUp())
3460 QScreen *s = e->screen.data();
3461 qreal rate = e->rate;
3465 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3466 s->d_func()->refreshRate = rate;
3467 emit s->refreshRateChanged(s->refreshRate());
3471void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3476 QWindow *window = e->window.data();
3479 QWindowPrivate *p = qt_window_private(window);
3486 p->positionAutomatic =
false;
3487 p->resizeAutomatic =
false;
3490 if (!p->receivedExpose) {
3491 if (p->resizeEventPending) {
3494 QResizeEvent e(window->geometry().size(), p->geometry.size());
3495 QGuiApplication::sendSpontaneousEvent(window, &e);
3497 p->resizeEventPending =
false;
3506 p->receivedExpose =
true;
3510 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3512 const bool wasExposed = p->exposed;
3513 p->exposed = e->isExposed && window->screen();
3518 if (e->isExposed && !e->region.isEmpty()) {
3519 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3521 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3522 <<
"Please file a QTBUG which explains how to reproduce.";
3526 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3527 QPaintEvent paintEvent(e->region);
3528 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3529 if (paintEvent.isAccepted())
3537 QExposeEvent exposeEvent(e->region);
3538 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3539 e->eventAccepted = exposeEvent.isAccepted();
3546 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3547 QPaintEvent paintEvent(e->region);
3548 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3552void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3554 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3555 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3560 QPaintEvent paintEvent(e->region);
3561 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3565 e->eventAccepted = paintEvent.isAccepted();
3568#if QT_CONFIG(draganddrop)
3571
3572
3573
3574
3575static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3577 QGuiApplicationPrivate::mouse_buttons = buttons;
3578 QGuiApplicationPrivate::modifier_buttons = modifiers;
3581QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3582 const QPoint &p, Qt::DropActions supportedActions,
3583 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3585 updateMouseAndModifierButtonState(buttons, modifiers);
3587 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3588 QPlatformDrag *platformDrag = platformIntegration()->drag();
3589 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3590 lastAcceptedDropAction = Qt::IgnoreAction;
3591 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3595 currentDragWindow =
nullptr;
3597 QGuiApplication::sendEvent(w, &e);
3598 lastAcceptedDropAction = Qt::IgnoreAction;
3599 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3601 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3603 if (w != currentDragWindow) {
3604 lastAcceptedDropAction = Qt::IgnoreAction;
3605 if (currentDragWindow) {
3607 QGuiApplication::sendEvent(currentDragWindow, &e);
3609 currentDragWindow = w;
3610 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3611 QGuiApplication::sendEvent(w, &e);
3612 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3613 lastAcceptedDropAction = e.dropAction();
3617 if (lastAcceptedDropAction != Qt::IgnoreAction
3618 && (supportedActions & lastAcceptedDropAction)) {
3619 me.setDropAction(lastAcceptedDropAction);
3622 QGuiApplication::sendEvent(w, &me);
3623 lastAcceptedDropAction = me.isAccepted() ?
3624 me.dropAction() : Qt::IgnoreAction;
3625 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3628QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3629 const QPoint &p, Qt::DropActions supportedActions,
3630 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3632 updateMouseAndModifierButtonState(buttons, modifiers);
3634 currentDragWindow =
nullptr;
3636 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3637 QGuiApplication::sendEvent(w, &de);
3639 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3640 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3646#ifndef QT_NO_CLIPBOARD
3648
3649
3650QClipboard * QGuiApplication::clipboard()
3652 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3654 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3657 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3659 return QGuiApplicationPrivate::qt_clipboard;
3664
3665
3666
3667
3668
3669
3670
3671
3672
3675
3676
3677
3678
3679
3680
3682QPalette QGuiApplication::palette()
3684 if (!QGuiApplicationPrivate::app_pal)
3685 QGuiApplicationPrivate::updatePalette();
3687 return *QGuiApplicationPrivate::app_pal;