diff options
author | Samuel Nevala <samuel.nevala@intopalo.com> | 2015-10-22 12:08:54 +0300 |
---|---|---|
committer | Samuel Nevala <samuel.nevala@intopalo.com> | 2015-10-22 13:28:51 +0000 |
commit | f57afda69fd9fdf9444d13e3461d556fae1dfcdf (patch) | |
tree | 5b28eac4320fc4790123359f6ada6283388d86e4 /src/plugins/platforms | |
parent | 0d5bf2eb595e3df9c54c4ada6020f5ceae8b9408 (diff) |
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 <andrew.knight@intopalo.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtintegration.cpp | 20 |
1 files changed, 5 insertions, 15 deletions
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 <QtCore/QCoreApplication> #include <QtGui/QSurface> #include <QtGui/QOpenGLContext> #include <qfunctions_winrt.h> @@ -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<QObject *>(window) - : static_cast<QObject *>(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 |