99#include <private/qvulkandefaultinstance_p.h>
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;
180Q_DECL_DEPRECATED_X(
"Use QGuiApplicationPrivate::instance() instead")
181Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self =
nullptr;
183Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
185#ifndef QT_NO_CLIPBOARD
189Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
191Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
192Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
193Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
196Q_CONSTINIT
static QBasicMutex applicationFontMutex;
199Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
200Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
204Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
206Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
208Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
211#if QT_CONFIG(animation)
212extern void qRegisterGuiGetInterpolator();
217 return force_reverse ^
218 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
219 "Translate this string to the string 'LTR' in left-to-right"
220 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
221 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
226 if (!QGuiApplicationPrivate::app_font) {
227 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
228 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
229 QGuiApplicationPrivate::app_font =
new QFont(*font);
231 if (!QGuiApplicationPrivate::app_font)
232 QGuiApplicationPrivate::app_font =
233 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
238 delete QGuiApplicationPrivate::app_font;
239 QGuiApplicationPrivate::app_font =
nullptr;
244 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
245 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
248#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
249static bool checkNeedPortalSupport()
252 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
260#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
280 const qsizetype size = a.size();
285 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
287 else if (isAsciiDigit(*op))
292 const int numberPos = pos;
293 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
296 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
297 return ok ? result : -1;
304 for (
int i = 0; i < 4; ++i) {
306 const int value = nextGeometryToken(a, pos, &op);
318 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
322 result.corner = Qt::TopRightCorner;
331 QRect windowGeometry = window->frameGeometry();
332 QSize size = windowGeometry.size();
334 const QSize windowMinimumSize = window->minimumSize();
335 const QSize windowMaximumSize = window->maximumSize();
337 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
339 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
340 window->resize(size);
343 const QRect availableGeometry = window->screen()->virtualGeometry();
344 QPoint topLeft = windowGeometry.topLeft();
346 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
348 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
351 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
353 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
355 window->setFramePosition(topLeft);
362
363
364
365
366
367
368
369
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
495
496
497
498
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
655QGuiApplication::QGuiApplication(
int &argc,
char **argv)
657QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
659 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
663 QCoreApplicationPrivate::eventDispatcher->startingUp();
667
668
669QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
670 : QCoreApplication(p)
675
676
677QGuiApplication::~QGuiApplication()
679 Q_D(QGuiApplication);
681 qt_call_post_routines();
683 d->eventDispatcher->closingDown();
684 d->eventDispatcher =
nullptr;
686#ifndef QT_NO_CLIPBOARD
687 delete QGuiApplicationPrivate::qt_clipboard;
688 QGuiApplicationPrivate::qt_clipboard =
nullptr;
691#ifndef QT_NO_SESSIONMANAGER
692 delete d->session_manager;
693 d->session_manager =
nullptr;
696 QGuiApplicationPrivate::clearPalette();
697 QFontDatabase::removeAllApplicationFonts();
700 d->cursor_list.clear();
703#if QT_CONFIG(qtgui_threadpool)
705 QThreadPool *guiThreadPool =
nullptr;
707 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
712 guiThreadPool->waitForDone();
713 delete guiThreadPool;
717 delete QGuiApplicationPrivate::app_icon;
718 QGuiApplicationPrivate::app_icon =
nullptr;
719 delete QGuiApplicationPrivate::platform_name;
720 QGuiApplicationPrivate::platform_name =
nullptr;
721 delete QGuiApplicationPrivate::displayName;
722 QGuiApplicationPrivate::displayName =
nullptr;
723 delete QGuiApplicationPrivate::m_inputDeviceManager;
724 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
725 delete QGuiApplicationPrivate::desktopFileName;
726 QGuiApplicationPrivate::desktopFileName =
nullptr;
727 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
728 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
729 QGuiApplicationPrivate::lastCursorPosition.reset();
730 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
731 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
732 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
733 QGuiApplicationPrivate::currentDragWindow =
nullptr;
734 QGuiApplicationPrivate::tabletDevicePoints.clear();
737QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
738 : QCoreApplicationPrivate(argc, argv),
739 inputMethod(
nullptr),
740 lastTouchType(QEvent::TouchEnd)
743 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
this;)
745 application_type = QCoreApplicationPrivate::Gui;
746#ifndef QT_NO_SESSIONMANAGER
747 is_session_restored =
false;
748 is_saving_session =
false;
753
754
755
756
757
758
759
760
761
762
763
764void QGuiApplication::setApplicationDisplayName(
const QString &name)
766 if (!QGuiApplicationPrivate::displayName) {
767 QGuiApplicationPrivate::displayName =
new QString(name);
769 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
770 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
772 if (*QGuiApplicationPrivate::displayName != applicationName())
773 emit
qGuiApp->applicationDisplayNameChanged();
775 }
else if (name != *QGuiApplicationPrivate::displayName) {
776 *QGuiApplicationPrivate::displayName = name;
778 emit
qGuiApp->applicationDisplayNameChanged();
782QString QGuiApplication::applicationDisplayName()
784 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806void QGuiApplication::setBadgeNumber(qint64 number)
808 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827void QGuiApplication::setDesktopFileName(
const QString &name)
829 if (!QGuiApplicationPrivate::desktopFileName)
830 QGuiApplicationPrivate::desktopFileName =
new QString;
831 *QGuiApplicationPrivate::desktopFileName = name;
832 if (name.endsWith(QLatin1String(
".desktop"))) {
833 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
834 if (!filePath.isEmpty()) {
835 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
836 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
837 "be removed. Please specify a desktop file name without .desktop suffix");
838 (*QGuiApplicationPrivate::desktopFileName).chop(8);
843QString QGuiApplication::desktopFileName()
845 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
849
850
851
852
853
854
855
856
857
858
859
860
861
862QWindow *QGuiApplication::modalWindow()
865 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
866 if (modalWindows.isEmpty())
868 return modalWindows.constFirst();
873 QWindowPrivate *p = qt_window_private(window);
874 if (p->blockedByModalWindow != shouldBeBlocked) {
875 p->blockedByModalWindow = shouldBeBlocked;
876 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
877 QGuiApplication::sendEvent(window, &e);
878 for (QObject *c : window->children()) {
879 if (c->isWindowType())
880 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
885void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
887 bool shouldBeBlocked =
false;
888 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
889 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
890 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
891 updateBlockedStatusRecursion(window, shouldBeBlocked);
899 return w->isTopLevel();
902void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
904 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
905 guiAppPrivate->modalWindowList.prepend(modal);
908 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
909 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
910 if (shouldBeBlocked) {
912 guiAppPrivate->modalWindowList.removeFirst();
913 QEvent e(QEvent::Leave);
914 QGuiApplication::sendEvent(currentMouseWindow, &e);
915 currentMouseWindow =
nullptr;
916 guiAppPrivate->modalWindowList.prepend(modal);
920 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
921 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
922 updateBlockedStatus(window);
925 updateBlockedStatus(modal);
928void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
930 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
932 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
933 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
934 updateBlockedStatus(window);
938Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
943bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
950
951
952
953
954bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
956 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
958 QWindow *unused =
nullptr;
960 blockingWindow = &unused;
961 *blockingWindow =
nullptr;
963 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
966 for (
int i = 0; i < modalWindowList.size(); ++i) {
967 QWindow *modalWindow = modalWindowList.at(i);
971 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
974 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
975 : modalWindow->modality()) {
976 case Qt::ApplicationModal:
977 *blockingWindow = modalWindow;
979 case Qt::WindowModal: {
982 auto *current = window;
984 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
985 *blockingWindow = modalWindow;
988 current = current->parent(QWindow::IncludeTransients);
993 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1000QWindow *QGuiApplicationPrivate::activePopupWindow()
1003 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1004 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1007void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1009 if (!popup->isVisible())
1011 popup_list.removeOne(popup);
1012 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1013 popup_list.append(popup);
1016bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1018 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1019 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1024
1025
1026bool QGuiApplicationPrivate::closeAllPopups()
1032 while ((popup = activePopupWindow()) && maxiter--)
1034 return QGuiApplicationPrivate::popup_list.isEmpty();
1038
1039
1040
1041
1042
1043QWindow *QGuiApplication::focusWindow()
1045 return QGuiApplicationPrivate::focus_window;
1049
1050
1051
1052
1053
1054
1055
1058
1059
1060
1061
1062
1063
1064
1067
1068
1069
1070QObject *QGuiApplication::focusObject()
1073 return focusWindow()->focusObject();
1078
1079
1080
1081
1082
1083
1084
1085
1086QWindowList QGuiApplication::allWindows()
1088 return QGuiApplicationPrivate::window_list;
1092
1093
1094
1095
1096
1097
1098QWindowList QGuiApplication::topLevelWindows()
1100 const QWindowList &list = QGuiApplicationPrivate::window_list;
1101 QWindowList topLevelWindows;
1102 for (
int i = 0; i < list.size(); ++i) {
1103 QWindow *window = list.at(i);
1104 if (!window->isTopLevel())
1109 if (window->handle() && window->handle()->isEmbedded())
1112 topLevelWindows.prepend(window);
1115 return topLevelWindows;
1118QScreen *QGuiApplication::primaryScreen()
1120 if (QGuiApplicationPrivate::screen_list.isEmpty())
1122 return QGuiApplicationPrivate::screen_list.at(0);
1126
1127
1128
1129QList<QScreen *> QGuiApplication::screens()
1131 return QGuiApplicationPrivate::screen_list;
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145QScreen *QGuiApplication::screenAt(
const QPoint &point)
1147 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1148 for (
const QScreen *screen : QGuiApplication::screens()) {
1149 if (visitedScreens.contains(screen))
1153 for (QScreen *sibling : screen->virtualSiblings()) {
1154 if (sibling->geometry().contains(point))
1157 visitedScreens.append(sibling);
1165
1166
1167
1168
1169
1170
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207qreal QGuiApplication::devicePixelRatio()
const
1209 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1210 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1212 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1213 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1214 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1216 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1219void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1221 m_maxDevicePixelRatio = 0.0;
1225
1226
1227QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1229 if (QScreen *windowScreen = screenAt(pos)) {
1230 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1231 return windowScreen->handle()->topLevelAt(devicePosition);
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1273QString QGuiApplication::platformName()
1275 if (!QGuiApplication::instance()) {
1276#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1277 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1282 return QGuiApplicationPrivate::platform_name ?
1283 *QGuiApplicationPrivate::platform_name : QString();
1291static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1293 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1294 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1295 <<
"platformPluginPath" << platformPluginPath
1296 <<
"platformThemeName" << platformThemeName;
1298 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1299 QStringList platformArguments;
1300 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1301 for (
const auto &pluginArgument : std::as_const(plugins)) {
1303 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1304 if (arguments.isEmpty())
1306 const QString name = arguments.takeFirst().toLower();
1307 QString argumentsKey = name;
1310 argumentsKey[0] = argumentsKey.at(0).toUpper();
1311 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1313 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1316 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1317 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1318 if (availablePlugins.contains(name)) {
1319 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1320 qCWarning(lcQpaPluginLoading).nospace().noquote()
1321 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1323 qCInfo(lcQpaPluginLoading).nospace().noquote()
1324 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1325 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1327 qCWarning(lcQpaPluginLoading).nospace().noquote()
1328 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1329 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1332 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1333 QGuiApplicationPrivate::platform_name =
new QString(name);
1334 platformArguments = arguments;
1339 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1340 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1341 "Reinstalling the application may fix this problem.\n");
1343 if (!availablePlugins.isEmpty())
1344 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1346#if defined(Q_OS_WIN)
1349 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1350 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1352 qFatal(
"%s", qPrintable(fatalMessage));
1360 QStringList themeNames;
1361 if (!platformThemeName.isEmpty()) {
1362 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1363 themeNames.append(platformThemeName);
1366#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1368 if (checkNeedPortalSupport()) {
1369 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1370 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1375 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1376 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1377 themeNames.append(platformIntegrationThemeNames);
1380 for (
const QString &themeName : std::as_const(themeNames)) {
1381 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1382 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1383 if (QGuiApplicationPrivate::platform_theme) {
1384 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1387 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1388 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1389 if (QGuiApplicationPrivate::platform_theme) {
1390 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1396 if (!QGuiApplicationPrivate::platform_theme) {
1397 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1398 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1403 if (!platformArguments.isEmpty()) {
1404 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1405 for (
const QString &argument : std::as_const(platformArguments)) {
1406 const qsizetype equalsPos = argument.indexOf(u'=');
1407 const QByteArray name =
1408 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1410 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1411 nativeInterface->setProperty(name.constData(), std::move(value));
1416 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1417 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1418 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1419 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1421 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1422 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1423 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1429 for (
int i = 0; i < pluginList.size(); ++i) {
1430 QByteArray pluginSpec = pluginList.at(i);
1431 qsizetype colonPos = pluginSpec.indexOf(
':');
1434 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1436 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1437 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1439 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1441 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1445#if QT_CONFIG(commandlineparser)
1446void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1448 QCoreApplicationPrivate::addQtOptions(options);
1450#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1451 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1452 const bool x11 = sessionType ==
"x11";
1455 const bool x11 =
false;
1458 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1459 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1460 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1461 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1462 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1463 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1464 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1465 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1466 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1467 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1468 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1469 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1470 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1471 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1472 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1473 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1474 options->append(QCommandLineOption(QStringLiteral(
"session"),
1475 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1478 options->append(QCommandLineOption(QStringLiteral(
"display"),
1479 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1480 options->append(QCommandLineOption(QStringLiteral(
"name"),
1481 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1482 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1483 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1484 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1485 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1486 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1487 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1489 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1490 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1491 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1492 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1493 options->append(QCommandLineOption(QStringLiteral(
"title"),
1494 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1499void QGuiApplicationPrivate::createPlatformIntegration()
1501 QHighDpiScaling::initHighDpiScaling();
1504 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1507 QByteArray platformName;
1508#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1509 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1511#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1512 QList<QByteArray> platformArguments = platformName.split(
':');
1513 QByteArray platformPluginBase = platformArguments.first();
1515 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1516 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1518 QVector<QByteArray> preferredPlatformOrder;
1519 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1520 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1521 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1522 preferredPlatformOrder << xcbPlatformName;
1524 platformName.clear();
1527 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1528 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1529 if (hasWaylandDisplay || isWaylandSessionType) {
1530 preferredPlatformOrder.prepend(waylandPlatformName);
1532 if (defaultIsWayland)
1533 platformName.clear();
1536 if (!platformName.isEmpty())
1537 preferredPlatformOrder.append(platformName);
1539 platformName = preferredPlatformOrder.join(
';');
1542 bool platformExplicitlySelected =
false;
1543 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1544 if (!platformNameEnv.isEmpty()) {
1545 platformName = platformNameEnv;
1546 platformExplicitlySelected =
true;
1549 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1555 int j = argc ? 1 : 0;
1556 for (
int i=1; i<argc; i++) {
1559 if (*argv[i] !=
'-') {
1560 argv[j++] = argv[i];
1563 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1564 const char *arg = argv[i];
1567 if (strcmp(arg,
"-platformpluginpath") == 0) {
1569 platformPluginPath = QFile::decodeName(argv[i]);
1570 }
else if (strcmp(arg,
"-platform") == 0) {
1572 platformExplicitlySelected =
true;
1573 platformName = argv[i];
1575 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1577 platformThemeName = QString::fromLocal8Bit(argv[i]);
1578 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1580 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1581 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1583 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1584 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1586 icon = QFile::decodeName(argv[i]);
1589 argv[j++] = argv[i];
1598 Q_UNUSED(platformExplicitlySelected);
1600 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1601 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1603 if (!icon.isEmpty())
1604 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1608
1609
1610
1611
1612
1613void QGuiApplicationPrivate::createEventDispatcher()
1615 Q_ASSERT(!eventDispatcher);
1617 if (platform_integration ==
nullptr)
1618 createPlatformIntegration();
1621 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1622 "Creating the platform integration resulted in creating an event dispatcher");
1625 Q_ASSERT(!eventDispatcher);
1627 eventDispatcher = platform_integration->createEventDispatcher();
1630void QGuiApplicationPrivate::eventDispatcherReady()
1632 if (platform_integration ==
nullptr)
1633 createPlatformIntegration();
1635 platform_integration->initialize();
1638void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1640 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1642#if defined(Q_OS_MACOS)
1643 QMacAutoReleasePool pool;
1646 QCoreApplicationPrivate::init();
1648 QCoreApplicationPrivate::is_app_running =
false;
1650 bool loadTestability =
false;
1651 QList<QByteArray> pluginList;
1653#ifndef QT_NO_SESSIONMANAGER
1655 QString session_key;
1656# if defined(Q_OS_WIN)
1657 wchar_t guidstr[40];
1659 CoCreateGuid(&guid);
1660 StringFromGUID2(guid, guidstr, 40);
1661 session_id = QString::fromWCharArray(guidstr);
1662 CoCreateGuid(&guid);
1663 StringFromGUID2(guid, guidstr, 40);
1664 session_key = QString::fromWCharArray(guidstr);
1668 int j = argc ? 1 : 0;
1669 for (
int i=1; i<argc; i++) {
1672 if (*argv[i] !=
'-') {
1673 argv[j++] = argv[i];
1676 const char *arg = argv[i];
1679 if (strcmp(arg,
"-plugin") == 0) {
1681 pluginList << argv[i];
1682 }
else if (strcmp(arg,
"-reverse") == 0) {
1683 force_reverse =
true;
1685 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1688 if (QDir::currentPath() ==
"/"_L1) {
1689 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1690 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1691 kCFURLPOSIXPathStyle));
1692 if (qbundlePath.endsWith(
".app"_L1))
1693 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1696#ifndef QT_NO_SESSIONMANAGER
1697 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1699 if (argv[i] && *argv[i]) {
1700 session_id = QString::fromLatin1(argv[i]);
1701 qsizetype p = session_id.indexOf(u'_');
1703 session_key = session_id.mid(p +1);
1704 session_id = session_id.left(p);
1706 is_session_restored =
true;
1709 }
else if (strcmp(arg,
"-testability") == 0) {
1710 loadTestability =
true;
1711 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1712 s = QString::fromLocal8Bit(arg + 7);
1713 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1714 s = QString::fromLocal8Bit(argv[++i]);
1716 argv[j++] = argv[i];
1729 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1730 if (!envPlugins.isEmpty())
1731 pluginList += envPlugins.split(
',');
1733 if (platform_integration ==
nullptr)
1734 createPlatformIntegration();
1737 QFont::initialize();
1741 QCursorData::initialize();
1745 qRegisterGuiVariant();
1747#if QT_CONFIG(animation)
1749 qRegisterGuiGetInterpolator();
1752 QWindowSystemInterfacePrivate::eventTime.start();
1754 is_app_running =
true;
1755 init_plugins(pluginList);
1756 QWindowSystemInterface::flushWindowSystemEvents();
1758 Q_Q(QGuiApplication);
1759#ifndef QT_NO_SESSIONMANAGER
1761 session_manager =
new QSessionManager(q, session_id, session_key);
1764#if QT_CONFIG(library)
1765 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1766 loadTestability =
true;
1768 if (loadTestability) {
1769 QLibrary testLib(QStringLiteral(
"qttestability"));
1770 if (Q_UNLIKELY(!testLib.load())) {
1771 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1773 typedef void (*TasInitialize)(
void);
1774 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1775 if (Q_UNLIKELY(!initFunction)) {
1776 qCritical(
"Library qttestability resolve failed!");
1783 Q_UNUSED(loadTestability);
1787 QGuiApplication::setLayoutDirection(layout_direction);
1789 if (!QGuiApplicationPrivate::displayName)
1790 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1791 q, &QGuiApplication::applicationDisplayNameChanged);
1794extern void qt_cleanupFontDatabase();
1796QGuiApplicationPrivate::~QGuiApplicationPrivate()
1798#if defined(Q_OS_MACOS)
1799 QMacAutoReleasePool pool;
1802 is_app_closing =
true;
1803 is_app_running =
false;
1805 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1806 delete generic_plugin_list.at(i);
1807 generic_plugin_list.clear();
1809 clearFontUnlocked();
1814 QCursorData::cleanup();
1817 layout_direction = Qt::LayoutDirectionAuto;
1819 cleanupThreadData();
1821 delete QGuiApplicationPrivate::styleHints;
1822 QGuiApplicationPrivate::styleHints =
nullptr;
1825 qt_cleanupFontDatabase();
1827 QPixmapCache::clear();
1830 if (ownGlobalShareContext) {
1831 delete qt_gl_global_share_context();
1832 qt_gl_set_global_share_context(
nullptr);
1836#if QT_CONFIG(vulkan)
1837 QVulkanDefaultInstance::cleanup();
1840 platform_integration->destroy();
1842 delete platform_theme;
1843 platform_theme =
nullptr;
1844 delete platform_integration;
1845 platform_integration =
nullptr;
1847 window_list.clear();
1849 screen_list.clear();
1852 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1857QCursor *overrideCursor();
1858void setOverrideCursor(
const QCursor &);
1859void changeOverrideCursor(
const QCursor &);
1860void restoreOverrideCursor();
1864static QFont font(
const QWidget*);
1865static QFont font(
const char *className);
1866static void setFont(
const QFont &,
const char *className =
nullptr);
1867static QFontMetrics fontMetrics();
1869#ifndef QT_NO_CLIPBOARD
1870static QClipboard *clipboard();
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1889 return QGuiApplicationPrivate::modifier_buttons;
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1911 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1912 return pi->keyMapper()->queryKeyboardModifiers();
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928Qt::MouseButtons QGuiApplication::mouseButtons()
1930 return QGuiApplicationPrivate::mouse_buttons;
1934
1935
1936
1937
1938QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1940 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1941 return pi ? pi->nativeInterface() :
nullptr;
1945
1946
1947
1948QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1950 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1952 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1956 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983int QGuiApplication::exec()
1985#if QT_CONFIG(accessibility)
1986 QAccessible::setRootObject(qApp);
1988 return QCoreApplication::exec();
1991void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
1993 if (e->spontaneous()) {
2001 switch (e->type()) {
2002 case QEvent::MouseButtonPress: {
2003 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2004 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2005 QGuiApplicationPrivate::mouse_buttons |= me->button();
2008 case QEvent::MouseButtonDblClick: {
2009 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2010 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2011 QGuiApplicationPrivate::mouse_buttons |= me->button();
2014 case QEvent::MouseButtonRelease: {
2015 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2016 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2017 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2020 case QEvent::KeyPress:
2021 case QEvent::KeyRelease:
2022 case QEvent::MouseMove:
2023#if QT_CONFIG(wheelevent)
2026 case QEvent::TouchBegin:
2027 case QEvent::TouchUpdate:
2028 case QEvent::TouchEnd:
2029#if QT_CONFIG(tabletevent)
2030 case QEvent::TabletMove:
2031 case QEvent::TabletPress:
2032 case QEvent::TabletRelease:
2035 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2036 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2046
2047bool QGuiApplication::notify(QObject *object, QEvent *event)
2049 Q_D(QGuiApplication);
2050 if (object->isWindowType()) {
2051 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2055 switch (event->type()) {
2056 case QEvent::ApplicationDeactivate:
2057 case QEvent::OrientationChange:
2063 d->closeAllPopups();
2069 QGuiApplicationPrivate::captureGlobalModifierState(event);
2071 return QCoreApplication::notify(object, event);
2075
2076bool QGuiApplication::event(QEvent *e)
2078 switch (e->type()) {
2079 case QEvent::LanguageChange:
2081 if (layout_direction == Qt::LayoutDirectionAuto)
2082 setLayoutDirection(layout_direction);
2083 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2084 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2086 case QEvent::ApplicationFontChange:
2087 case QEvent::ApplicationPaletteChange:
2088 postEvent(QGuiApplication::styleHints(), e->clone());
2089 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2090 postEvent(topLevelWindow,
new QEvent(e->type()));
2092 case QEvent::ThemeChange:
2093 forwardEvent(QGuiApplication::styleHints(), e);
2094 for (
auto *w : QGuiApplication::allWindows())
2100 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2102 if (!topLevelWindow->handle())
2104 if (!topLevelWindow->close()) {
2113 return QCoreApplication::event(e);
2116#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2118
2119
2120bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2122 QT_IGNORE_DEPRECATIONS(
2123 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2128bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2132 QPlatformWindow *platformWindow = window->handle();
2133 if (!platformWindow)
2136 if (event->spontaneous())
2139 return platformWindow->windowEvent(event);
2142bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2144 return window->nativeEvent(eventType, message, result);
2147bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2149 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArray(
"qtvirtualkeyboard");
2150 return usingVirtualKeyboard;
2154bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2156 if (!isUsingVirtualKeyboard()) {
2157 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2161 static QPointer<QWindow> virtualKeyboard;
2162 const QEvent::Type type = e->type();
2163 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2164 const auto me =
static_cast<QMouseEvent *>(e);
2165 const QPointF posF = me->globalPosition();
2166 const QPoint pos = posF.toPoint();
2169 if (!virtualKeyboard) {
2170 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2171 win->inherits(
"QtVirtualKeyboard::InputView")) {
2172 virtualKeyboard = win;
2174 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2179 Q_ASSERT(virtualKeyboard);
2180 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2181 && virtualKeyboard->geometry().contains(pos);
2183 if (!virtualKeyboardUnderMouse) {
2184 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2185 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2189 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2190 me->button(), me->buttons(), me->modifiers(),
2191 me->pointingDevice());
2193 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2194 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2200void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2202 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2203 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2205 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2206 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2207 if (!haveGuiApplication) {
2208 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2209 e->eventAccepted =
false;
2214 case QWindowSystemInterfacePrivate::Mouse:
2215 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2217 case QWindowSystemInterfacePrivate::Wheel:
2218 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2220 case QWindowSystemInterfacePrivate::Key:
2221 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2223 case QWindowSystemInterfacePrivate::Touch:
2224 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2226 case QWindowSystemInterfacePrivate::GeometryChange:
2227 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2229 case QWindowSystemInterfacePrivate::Enter:
2230 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2232 case QWindowSystemInterfacePrivate::Leave:
2233 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2235 case QWindowSystemInterfacePrivate::FocusWindow:
2236 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2238 case QWindowSystemInterfacePrivate::WindowStateChanged:
2239 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2241 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2242 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2244 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2245 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2247 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2248 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2250 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2251 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2252 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2254 case QWindowSystemInterfacePrivate::ApplicationTermination:
2255 QGuiApplicationPrivate::processApplicationTermination(e);
2257 case QWindowSystemInterfacePrivate::FlushEvents: {
2258 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2259 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2261 case QWindowSystemInterfacePrivate::Close:
2262 QGuiApplicationPrivate::processCloseEvent(
2263 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2265 case QWindowSystemInterfacePrivate::ScreenOrientation:
2266 QGuiApplicationPrivate::processScreenOrientationChange(
2267 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2269 case QWindowSystemInterfacePrivate::ScreenGeometry:
2270 QGuiApplicationPrivate::processScreenGeometryChange(
2271 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2273 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2274 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2275 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2277 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2278 QGuiApplicationPrivate::processScreenRefreshRateChange(
2279 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2281 case QWindowSystemInterfacePrivate::ThemeChange:
2282 QGuiApplicationPrivate::processThemeChanged(
2283 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2285 case QWindowSystemInterfacePrivate::Expose:
2286 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2288 case QWindowSystemInterfacePrivate::Paint:
2289 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2291 case QWindowSystemInterfacePrivate::Tablet:
2292 QGuiApplicationPrivate::processTabletEvent(
2293 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2295 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2296 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2297 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2299 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2300 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2301 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2303#ifndef QT_NO_GESTURES
2304 case QWindowSystemInterfacePrivate::Gesture:
2305 QGuiApplicationPrivate::processGestureEvent(
2306 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2309 case QWindowSystemInterfacePrivate::PlatformPanel:
2310 QGuiApplicationPrivate::processPlatformPanelEvent(
2311 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2313 case QWindowSystemInterfacePrivate::FileOpen:
2314 QGuiApplicationPrivate::processFileOpenEvent(
2315 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2317#ifndef QT_NO_CONTEXTMENU
2318 case QWindowSystemInterfacePrivate::ContextMenu:
2319 QGuiApplicationPrivate::processContextMenuEvent(
2320 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2323 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2324 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2327 qWarning() <<
"Unknown user input event type:" << e->type;
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2346 QEvent::Type type = QEvent::None;
2347 Qt::MouseButton button = Qt::NoButton;
2348 QWindow *window = e->window.data();
2349 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2351 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2352 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2353 bool mouseMove =
false;
2354 bool mousePress =
false;
2355 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2356 QPointF globalPoint = e->globalPos;
2358 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2359 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2363 type = e->buttonType;
2366 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2368 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2371 if (!mouseMove && positionChanged) {
2372 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2373 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2374 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2375 e->source, e->nonClientArea, device, e->eventPointId);
2377 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2378 processMouseEvent(&moveEvent);
2379 processMouseEvent(e);
2382 if (type == QEvent::MouseMove && !positionChanged) {
2390 modifier_buttons = e->modifiers;
2391 QPointF localPoint = e->localPos;
2392 bool doubleClick =
false;
2393 auto persistentEPD = devPriv->pointById(0);
2395 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2396 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2399 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2400 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2401 mouseDoubleClickDistance : touchDoubleTapDistance);
2402 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2403 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2404 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2405 mousePressButton = Qt::NoButton;
2407 static unsigned long lastPressTimestamp = 0;
2408 static QPointer<QWindow> lastPressWindow =
nullptr;
2409 mouse_buttons = e->buttons;
2411 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2412 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2413 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2414 && button == mousePressButton && lastPressWindow == e->window;
2415 mousePressButton = button;
2416 lastPressTimestamp = e ->timestamp;
2417 lastPressWindow = e->window;
2421 if (e->nullWindow()) {
2422 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2426 if (e->buttons != Qt::NoButton) {
2427 if (!currentMousePressWindow)
2428 currentMousePressWindow = window;
2430 window = currentMousePressWindow;
2431 }
else if (currentMousePressWindow) {
2432 window = currentMousePressWindow;
2433 currentMousePressWindow =
nullptr;
2435 localPoint = window->mapFromGlobal(globalPoint);
2443 if (!e->synthetic()) {
2444 if (
const QScreen *screen = window->screen())
2445 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2446 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2447 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2448 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2449 button, e->buttons, e->modifiers, e->source, device);
2453 ev.QInputEvent::setTimestamp(e->timestamp);
2454 cursor->pointerEvent(ev);
2459 const auto *activePopup = activePopupWindow();
2460 if (type == QEvent::MouseButtonPress)
2461 active_popup_on_press = activePopup;
2462 if (window->d_func()->blockedByModalWindow && !activePopup) {
2467 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2468 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2471 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2472 persistentEPD =
nullptr;
2474 ev.setTimestamp(e->timestamp);
2476 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2478 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2479 if (handlingPopup) {
2480 if (type == QEvent::MouseButtonPress)
2481 active_popup_on_press = handlingPopup;
2486 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2488 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2491 QGuiApplication::sendSpontaneousEvent(window, &ev);
2492 e->eventAccepted = ev.isAccepted();
2493 if (!e->synthetic() && !ev.isAccepted()
2494 && !e->nonClientArea
2495 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2496 QList<QWindowSystemInterface::TouchPoint> points;
2497 QWindowSystemInterface::TouchPoint point;
2499 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2504 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2505 point.state = QEventPoint::State::Pressed;
2506 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2507 point.state = QEventPoint::State::Released;
2508 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2509 point.state = QEventPoint::State::Updated;
2517 const QList<QEventPoint> &touchPoints =
2518 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2520 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2521 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2522 processTouchEvent(&fake);
2525 mousePressButton = Qt::NoButton;
2526 if (!e->window.isNull() || e->nullWindow()) {
2527 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2528 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2529 button, e->buttons, e->modifiers, e->source, device);
2530 dblClickEvent.setTimestamp(e->timestamp);
2531 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2534 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2535 popup_closed_on_press =
false;
2536 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2537 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2538 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2543void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2545#if QT_CONFIG(wheelevent)
2546 QWindow *window = e->window.data();
2547 QPointF globalPoint = e->globalPos;
2548 QPointF localPoint = e->localPos;
2550 if (e->nullWindow()) {
2551 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2553 localPoint = window->mapFromGlobal(globalPoint);
2559 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2560 modifier_buttons = e->modifiers;
2562 if (window->d_func()->blockedByModalWindow) {
2567 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2568 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2569 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2570 ev.setTimestamp(e->timestamp);
2571 QGuiApplication::sendSpontaneousEvent(window, &ev);
2572 e->eventAccepted = ev.isAccepted();
2578void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2580 QWindow *window = e->window.data();
2581 modifier_buttons = e->modifiers;
2584 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2587 window = QGuiApplication::focusWindow();
2591 e->eventAccepted =
false;
2595#if defined(Q_OS_ANDROID)
2596 static bool backKeyPressAccepted =
false;
2597 static bool menuKeyPressAccepted =
false;
2600#if !defined(Q_OS_MACOS)
2603 if (e->keyType == QEvent::KeyPress) {
2604 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2605 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2606#if defined(Q_OS_ANDROID)
2607 backKeyPressAccepted = e->key == Qt::Key_Back;
2608 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2615 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2616 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2617 e->unicode, e->repeat, e->repeatCount);
2618 ev.setTimestamp(e->timestamp);
2620 const auto *activePopup = activePopupWindow();
2621 if (activePopup && activePopup != window) {
2623 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2629 if (!window->d_func()->blockedByModalWindow)
2630 QGuiApplication::sendSpontaneousEvent(window, &ev);
2633 ev.setAccepted(
false);
2635 if (e->keyType == QEvent::KeyPress) {
2636 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2637 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2638 }
else if (e->keyType == QEvent::KeyRelease) {
2639 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2641 QWindowSystemInterface::handleCloseEvent(window);
2642 }
else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2643 platform_theme->showPlatformMenuBar();
2647 e->eventAccepted = ev.isAccepted();
2650void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2654 if (e->enter.data()->d_func()->blockedByModalWindow) {
2659 currentMouseWindow = e->enter;
2662 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2669 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2670 auto epd = devPriv->queryPointById(event.points().first().id());
2672 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2674 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2677void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2681 if (e->leave.data()->d_func()->blockedByModalWindow) {
2686 currentMouseWindow =
nullptr;
2688 QEvent event(QEvent::Leave);
2689 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2692void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2694 QWindow *previous = QGuiApplicationPrivate::focus_window;
2695 QWindow *newFocus = e->focused.data();
2697 if (previous == newFocus)
2700 bool activatedPopup =
false;
2702 if (QPlatformWindow *platformWindow = newFocus->handle())
2703 if (platformWindow->isAlertState())
2704 platformWindow->setAlertState(
false);
2705 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2707 activatePopup(newFocus);
2710 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2713 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2714 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2717 QGuiApplicationPrivate::focus_window = newFocus;
2722 Qt::FocusReason r = e->reason;
2723 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2724 r = Qt::PopupFocusReason;
2725 QFocusEvent focusOut(QEvent::FocusOut, r);
2726 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2727 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2728 qApp, SLOT(_q_updateFocusObject(QObject*)));
2729 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2730 setApplicationState(Qt::ApplicationActive);
2733 if (QGuiApplicationPrivate::focus_window) {
2734 Qt::FocusReason r = e->reason;
2735 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2736 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2737 r = Qt::PopupFocusReason;
2738 QFocusEvent focusIn(QEvent::FocusIn, r);
2739 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2740 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2741 qApp, SLOT(_q_updateFocusObject(QObject*)));
2742 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2743 setApplicationState(Qt::ApplicationInactive);
2746 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2747 guiAppPrivate->notifyActiveWindowChange(previous);
2749 if (previousFocusObject !=
qApp->focusObject() ||
2755 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2756 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2760 emit
qApp->focusWindowChanged(newFocus);
2762 emit previous->activeChanged();
2764 emit newFocus->activeChanged();
2767void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2769 if (QWindow *window = wse->window.data()) {
2770 QWindowPrivate *windowPrivate = qt_window_private(window);
2771 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2773 windowPrivate->windowState = wse->newState;
2774 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2775 if (newEffectiveState != originalEffectiveState)
2776 emit window->windowStateChanged(newEffectiveState);
2778 windowPrivate->updateVisibility();
2780 QWindowStateChangeEvent e(wse->oldState);
2781 QGuiApplication::sendSpontaneousEvent(window, &e);
2785void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2787 QWindow *window = wse->window.data();
2791 if (window->screen() == wse->screen.data())
2794 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2795 if (QScreen *screen = wse->screen.data())
2796 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2798 topLevelWindow->setScreen(
nullptr);
2802void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2804 if (wde->window.isNull())
2806 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2809void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2811 if (wse->window.isNull())
2814 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2816 QEvent event(QEvent::SafeAreaMarginsChange);
2817 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2820void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2827 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2828 guiAppPrivate->handleThemeChanged();
2830 QIconPrivate::clearIconCache();
2832 QEvent themeChangeEvent(QEvent::ThemeChange);
2833 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2836void QGuiApplicationPrivate::handleThemeChanged()
2838 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2841 QIconLoader::instance()->updateSystemTheme();
2842 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2844 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2845 const auto locker = qt_scoped_lock(applicationFontMutex);
2846 clearFontUnlocked();
2852void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2854 if (e->window.isNull())
2857 QWindow *window = e->window.data();
2861 const QRect lastReportedGeometry = window->d_func()->geometry;
2862 const QRect requestedGeometry = e->requestedGeometry;
2863 const QRect actualGeometry = e->newGeometry;
2873 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2874 || requestedGeometry.size() != actualGeometry.size();
2875 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2876 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2878 window->d_func()->geometry = actualGeometry;
2880 if (isResize || window->d_func()->resizeEventPending) {
2881 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2882 QGuiApplication::sendSpontaneousEvent(window, &e);
2884 window->d_func()->resizeEventPending =
false;
2886 if (actualGeometry.width() != lastReportedGeometry.width())
2887 emit window->widthChanged(actualGeometry.width());
2888 if (actualGeometry.height() != lastReportedGeometry.height())
2889 emit window->heightChanged(actualGeometry.height());
2894 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2895 QGuiApplication::sendSpontaneousEvent(window, &e);
2897 if (actualGeometry.x() != lastReportedGeometry.x())
2898 emit window->xChanged(actualGeometry.x());
2899 if (actualGeometry.y() != lastReportedGeometry.y())
2900 emit window->yChanged(actualGeometry.y());
2904void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2906 if (e->window.isNull())
2908 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2911 e->eventAccepted =
false;
2916 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2918 e->eventAccepted = event.isAccepted();
2921void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2923 if (e->url.isEmpty())
2926 QFileOpenEvent event(e->url);
2927 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2930QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2932 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2933 TabletPointData &pointData = tabletDevicePoints[i];
2934 if (pointData.deviceId == deviceId)
2938 tabletDevicePoints.append(TabletPointData(deviceId));
2939 return tabletDevicePoints.last();
2942void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2944#if QT_CONFIG(tabletevent)
2945 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2946 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2948 QEvent::Type type = QEvent::TabletMove;
2949 if (e->buttons != pointData.state)
2950 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2952 QWindow *window = e->window.data();
2953 modifier_buttons = e->modifiers;
2955 bool localValid =
true;
2959 if (type == QEvent::TabletPress) {
2960 if (e->nullWindow()) {
2961 window = QGuiApplication::topLevelAt(e->global.toPoint());
2966 active_popup_on_press = activePopupWindow();
2967 pointData.target = window;
2969 if (e->nullWindow()) {
2970 window = pointData.target;
2973 if (type == QEvent::TabletRelease)
2974 pointData.target =
nullptr;
2978 QPointF local = e->local;
2980 QPointF delta = e->global - e->global.toPoint();
2981 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2985 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2986 Qt::MouseButton button = Qt::NoButton;
2987 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
2988 if (check & stateChange) {
2989 button = Qt::MouseButton(check);
2994 const auto *activePopup = activePopupWindow();
2995 if (window->d_func()->blockedByModalWindow && !activePopup) {
3000 QTabletEvent tabletEvent(type, device, local, e->global,
3001 e->pressure, e->xTilt, e->yTilt,
3002 e->tangentialPressure, e->rotation, e->z,
3003 e->modifiers, button, e->buttons);
3004 tabletEvent.setAccepted(
false);
3005 tabletEvent.setTimestamp(e->timestamp);
3007 if (activePopup && activePopup != window) {
3009 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3013 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3014 pointData.state = e->buttons;
3015 if (!tabletEvent.isAccepted()
3016 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3017 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3019 const QEvent::Type mouseType = [&]() {
3021 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3022 case QEvent::TabletMove:
return QEvent::MouseMove;
3023 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3024 default: Q_UNREACHABLE();
3027 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3028 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3029 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3030 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3031 << e->local << button << e->buttons << e->modifiers;
3032 processMouseEvent(&mouseEvent);
3039void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3041#if QT_CONFIG(tabletevent)
3042 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3043 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3044 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3045 tabletDevicePoint(dev->uniqueId().numericId()).state);
3046 ev.setTimestamp(e->timestamp);
3047 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3053void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3055#if QT_CONFIG(tabletevent)
3056 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3057 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3058 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3059 tabletDevicePoint(dev->uniqueId().numericId()).state);
3060 ev.setTimestamp(e->timestamp);
3061 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3067#ifndef QT_NO_GESTURES
3068void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3070 if (e->window.isNull())
3073 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3074 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3075 e->delta, e->sequenceId);
3076 ev.setTimestamp(e->timestamp);
3077 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3081void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3086 if (e->window->d_func()->blockedByModalWindow) {
3091 QEvent ev(QEvent::PlatformPanel);
3092 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3095#ifndef QT_NO_CONTEXTMENU
3096void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3100 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3103 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3104 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3105 e->eventAccepted = ev.isAccepted();
3109void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3111 if (!QInputDevicePrivate::isRegistered(e->device))
3114 modifier_buttons = e->modifiers;
3115 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3116 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3118 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3120 if (e->touchType == QEvent::TouchCancel) {
3123 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3124 touchEvent.setTimestamp(e->timestamp);
3125 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3126 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3128 for (
auto &epd : devPriv->activePoints.values()) {
3129 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3130 windowsNeedingCancel.insert(w);
3133 for (QWindow *w : windowsNeedingCancel)
3134 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3136 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3137 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3138 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3139 if (!synthIt->window)
3141 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3148 QEvent::MouseButtonRelease,
3149 Qt::MouseEventNotSynthesized,
3152 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3153 processMouseEvent(&fake);
3155 guiAppPrivate->synthesizedMousePoints.clear();
3157 guiAppPrivate->lastTouchType = e->touchType;
3162 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3165 guiAppPrivate->lastTouchType = e->touchType;
3167 QPointer<QWindow> window = e->window;
3168 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3174 for (
auto &tempPt : e->points) {
3176 auto epd = devPriv->pointById(tempPt.id());
3177 auto &ep = epd->eventPoint;
3178 epd->eventPoint.setAccepted(
false);
3179 switch (tempPt.state()) {
3180 case QEventPoint::State::Pressed:
3182 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3183 window = devPriv->firstActiveWindow();
3186 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3187 QMutableEventPoint::setWindow(ep, window);
3188 active_popup_on_press = activePopupWindow();
3191 case QEventPoint::State::Released:
3192 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3193 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3194 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3195 window = QMutableEventPoint::window(ep);
3199 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3200 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3201 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3202 window = QMutableEventPoint::window(ep);
3206 if (Q_UNLIKELY(!window)) {
3207 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3210 QMutableEventPoint::update(tempPt, ep);
3212 Q_ASSERT(window.data() !=
nullptr);
3215 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3218 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3221 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3225 for (QMutableTouchEvent &ev : touchEvents) {
3226 if (ev.target() == window.data()) {
3233 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3234 mte.setTimestamp(e->timestamp);
3235 mte.setTarget(window.data());
3236 touchEvents.append(mte);
3240 if (touchEvents.isEmpty())
3243 for (QMutableTouchEvent &touchEvent : touchEvents) {
3244 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3246 QEvent::Type eventType;
3247 switch (touchEvent.touchPointStates()) {
3248 case QEventPoint::State::Pressed:
3249 eventType = QEvent::TouchBegin;
3251 case QEventPoint::State::Released:
3252 eventType = QEvent::TouchEnd;
3255 eventType = QEvent::TouchUpdate;
3259 const auto *activePopup = activePopupWindow();
3260 if (window->d_func()->blockedByModalWindow && !activePopup) {
3264 if (touchEvent.type() == QEvent::TouchEnd) {
3267 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3268 touchEvent.setTimestamp(e->timestamp);
3269 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3274 if (activePopup && activePopup != window) {
3276 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3283 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3285 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3287 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3289 QEvent::Type mouseEventType = QEvent::MouseMove;
3290 Qt::MouseButton button = Qt::NoButton;
3291 Qt::MouseButtons buttons = Qt::LeftButton;
3292 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3293 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3294 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3296 if (m_fakeMouseSourcePointId >= 0) {
3297 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3299 switch (touchPoint->state()) {
3300 case QEventPoint::State::Pressed:
3301 mouseEventType = QEvent::MouseButtonPress;
3302 button = Qt::LeftButton;
3304 case QEventPoint::State::Released:
3305 mouseEventType = QEvent::MouseButtonRelease;
3306 button = Qt::LeftButton;
3307 buttons = Qt::NoButton;
3308 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3309 m_fakeMouseSourcePointId = -1;
3314 if (touchPoint->state() != QEventPoint::State::Released) {
3315 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3316 touchPoint->position(), touchPoint->globalPosition(), window));
3322 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3323 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3324 touchPoint->globalPosition(),
3329 Qt::MouseEventSynthesizedByQt,
3333 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3334 processMouseEvent(&fake);
3337 if (eventType == QEvent::TouchEnd)
3338 guiAppPrivate->synthesizedMousePoints.clear();
3345 for (
const QEventPoint &touchPoint : e->points) {
3346 if (touchPoint.state() == QEventPoint::State::Released)
3347 devPriv->removePointById(touchPoint.id());
3351void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3354 if (QCoreApplication::startingUp())
3360 QScreen *s = e->screen.data();
3361 s->d_func()->orientation = e->orientation;
3363 emit s->orientationChanged(s->orientation());
3365 QScreenOrientationChangeEvent event(s, s->orientation());
3366 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3369void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3372 if (QCoreApplication::startingUp())
3379 QScreen *s = e->screen.data();
3380 QScreenPrivate::UpdateEmitter updateEmitter(s);
3384 s->d_func()->geometry = e->geometry;
3385 s->d_func()->availableGeometry = e->availableGeometry;
3387 s->d_func()->updatePrimaryOrientation();
3390 resetCachedDevicePixelRatio();
3393void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3396 if (QCoreApplication::startingUp())
3399 QHighDpiScaling::updateHighDpiScaling();
3405 QScreen *s = e->screen.data();
3406 QScreenPrivate::UpdateEmitter updateEmitter(s);
3407 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3408 s->d_func()->updateGeometry();
3411 for (QWindow *window : QGuiApplication::allWindows())
3412 if (window->screen() == e->screen)
3413 QWindowPrivate::get(window)->updateDevicePixelRatio();
3415 resetCachedDevicePixelRatio();
3418void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3421 if (QCoreApplication::startingUp())
3427 QScreen *s = e->screen.data();
3428 qreal rate = e->rate;
3432 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3433 s->d_func()->refreshRate = rate;
3434 emit s->refreshRateChanged(s->refreshRate());
3438void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3443 QWindow *window = e->window.data();
3446 QWindowPrivate *p = qt_window_private(window);
3453 p->positionAutomatic =
false;
3454 p->resizeAutomatic =
false;
3457 if (!p->receivedExpose) {
3458 if (p->resizeEventPending) {
3461 QResizeEvent e(window->geometry().size(), p->geometry.size());
3462 QGuiApplication::sendSpontaneousEvent(window, &e);
3464 p->resizeEventPending =
false;
3473 p->receivedExpose =
true;
3477 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3479 const bool wasExposed = p->exposed;
3480 p->exposed = e->isExposed && window->screen();
3485 if (e->isExposed && !e->region.isEmpty()) {
3486 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3488 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3489 <<
"Please file a QTBUG which explains how to reproduce.";
3493 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3494 QPaintEvent paintEvent(e->region);
3495 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3496 if (paintEvent.isAccepted())
3504 QExposeEvent exposeEvent(e->region);
3505 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3506 e->eventAccepted = exposeEvent.isAccepted();
3513 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3514 QPaintEvent paintEvent(e->region);
3515 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3519void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3521 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3522 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3527 QPaintEvent paintEvent(e->region);
3528 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3532 e->eventAccepted = paintEvent.isAccepted();
3535#if QT_CONFIG(draganddrop)
3538
3539
3540
3541
3542static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3544 QGuiApplicationPrivate::mouse_buttons = buttons;
3545 QGuiApplicationPrivate::modifier_buttons = modifiers;
3548QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3549 const QPoint &p, Qt::DropActions supportedActions,
3550 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3552 updateMouseAndModifierButtonState(buttons, modifiers);
3554 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3555 QPlatformDrag *platformDrag = platformIntegration()->drag();
3556 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3557 lastAcceptedDropAction = Qt::IgnoreAction;
3558 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3562 currentDragWindow =
nullptr;
3564 QGuiApplication::sendEvent(w, &e);
3565 lastAcceptedDropAction = Qt::IgnoreAction;
3566 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3568 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3570 if (w != currentDragWindow) {
3571 lastAcceptedDropAction = Qt::IgnoreAction;
3572 if (currentDragWindow) {
3574 QGuiApplication::sendEvent(currentDragWindow, &e);
3576 currentDragWindow = w;
3577 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3578 QGuiApplication::sendEvent(w, &e);
3579 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3580 lastAcceptedDropAction = e.dropAction();
3584 if (lastAcceptedDropAction != Qt::IgnoreAction
3585 && (supportedActions & lastAcceptedDropAction)) {
3586 me.setDropAction(lastAcceptedDropAction);
3589 QGuiApplication::sendEvent(w, &me);
3590 lastAcceptedDropAction = me.isAccepted() ?
3591 me.dropAction() : Qt::IgnoreAction;
3592 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3595QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3596 const QPoint &p, Qt::DropActions supportedActions,
3597 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3599 updateMouseAndModifierButtonState(buttons, modifiers);
3601 currentDragWindow =
nullptr;
3603 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3604 QGuiApplication::sendEvent(w, &de);
3606 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3607 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3613#ifndef QT_NO_CLIPBOARD
3615
3616
3617QClipboard * QGuiApplication::clipboard()
3619 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3621 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3624 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3626 return QGuiApplicationPrivate::qt_clipboard;
3631
3632
3633
3634
3635
3636
3637
3638
3639
3642
3643
3644
3645
3646
3647
3649QPalette QGuiApplication::palette()
3651 if (!QGuiApplicationPrivate::app_pal)
3652 QGuiApplicationPrivate::updatePalette();
3654 return *QGuiApplicationPrivate::app_pal;