Android: handle keyPress event for Key_Back
Added logic so that accepting either the press or the release will keep the app running. This makes it possible to use the onBackPressed functionality in QML. This functionality is only intended for running in a complete Android environment, so make sure that we don't terminate the application in the NO_SDK case. Task-number: QTBUG-30803 Change-Id: I2546eea73bf6a6ee8b196125b7556479b9b10a9c Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
parent
472e448d6a
commit
fc98d027c0
@ -1666,41 +1666,36 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
|
||||
QWindow *window = e->window.data();
|
||||
modifier_buttons = e->modifiers;
|
||||
if (e->nullWindow
|
||||
#ifdef Q_OS_ANDROID
|
||||
|| (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back) || e->key == Qt::Key_Menu
|
||||
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
|
||||
|| e->key == Qt::Key_Back || e->key == Qt::Key_Menu
|
||||
#endif
|
||||
) {
|
||||
window = QGuiApplication::focusWindow();
|
||||
}
|
||||
if (!window
|
||||
#ifdef Q_OS_ANDROID
|
||||
&& e->keyType != QEvent::KeyRelease && e->key != Qt::Key_Back
|
||||
#endif
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (window && window->d_func()->blockedByModalWindow) {
|
||||
// a modal window is blocking this window, don't allow key events through
|
||||
return;
|
||||
}
|
||||
|
||||
QKeyEvent ev(e->keyType, e->key, e->modifiers,
|
||||
e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
|
||||
e->unicode, e->repeat, e->repeatCount);
|
||||
ev.setTimestamp(e->timestamp);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
if (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back) {
|
||||
if (!window) {
|
||||
// only deliver key events when we have a window, and no modal window is blocking this window
|
||||
|
||||
if (window && !window->d_func()->blockedByModalWindow)
|
||||
QGuiApplication::sendSpontaneousEvent(window, &ev);
|
||||
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
|
||||
else
|
||||
ev.setAccepted(false);
|
||||
|
||||
static bool backKeyPressAccepted = false;
|
||||
if (e->keyType == QEvent::KeyPress) {
|
||||
backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
|
||||
} else if (e->keyType == QEvent::KeyRelease && e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
|
||||
if (!window)
|
||||
qApp->quit();
|
||||
} else {
|
||||
QGuiApplication::sendEvent(window, &ev);
|
||||
if (!ev.isAccepted() && e->key == Qt::Key_Back)
|
||||
else
|
||||
QWindowSystemInterface::handleCloseEvent(window);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
QGuiApplication::sendSpontaneousEvent(window, &ev);
|
||||
}
|
||||
|
||||
void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
|
||||
|
Loading…
Reference in New Issue
Block a user