From f57afda69fd9fdf9444d13e3461d556fae1dfcdf Mon Sep 17 00:00:00 2001 From: Samuel Nevala Date: Thu, 22 Oct 2015 12:08:54 +0300 Subject: winrt: Fix sending of back key event. Windows Runtime side callback is run from XAML thread and receiver is at UI thread thus sendEvent asserts. Use synchronous system interface key event handler to deliver the event. Task-Id: QTBUG-48105 Change-Id: I91a8ef6fd29c277edfb699b688b9e7895dadda8f Reviewed-by: Andrew Knight --- src/plugins/platforms/winrt/qwinrtintegration.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/plugins/platforms/winrt/qwinrtintegration.cpp') diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp index a5582b031d..7ee3bf8593 100644 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ b/src/plugins/platforms/winrt/qwinrtintegration.cpp @@ -45,7 +45,6 @@ #include "qwinrtfontdatabase.h" #include "qwinrttheme.h" -#include #include #include #include @@ -258,21 +257,12 @@ QPlatformTheme *QWinRTIntegration::createPlatformTheme(const QString &name) cons HRESULT QWinRTIntegration::onBackButtonPressed(IInspectable *, IBackPressedEventArgs *args) { Q_D(QWinRTIntegration); - - QKeyEvent backPress(QEvent::KeyPress, Qt::Key_Back, Qt::NoModifier); - QKeyEvent backRelease(QEvent::KeyRelease, Qt::Key_Back, Qt::NoModifier); - backPress.setAccepted(false); - backRelease.setAccepted(false); - QWindow *window = d->mainScreen->topWindow(); - QObject *receiver = window ? static_cast(window) - : static_cast(QCoreApplication::instance()); - - // If the event is ignored, the app go to the background - QCoreApplication::sendEvent(receiver, &backPress); - QCoreApplication::sendEvent(receiver, &backRelease); - args->put_Handled(backPress.isAccepted() || backRelease.isAccepted()); - + QWindowSystemInterface::setSynchronousWindowSystemEvents(true); + const bool pressed = QWindowSystemInterface::handleKeyEvent(window, QEvent::KeyPress, Qt::Key_Back, Qt::NoModifier); + const bool released = QWindowSystemInterface::handleKeyEvent(window, QEvent::KeyRelease, Qt::Key_Back, Qt::NoModifier); + QWindowSystemInterface::setSynchronousWindowSystemEvents(false); + args->put_Handled(pressed || released); return S_OK; } #endif // Q_OS_WINPHONE -- cgit v1.2.3