diff options
author | Christian Strømme <christian.stromme@theqtcompany.com> | 2015-02-27 16:32:33 +0100 |
---|---|---|
committer | Christian Stromme <christian.stromme@theqtcompany.com> | 2015-03-05 08:15:15 +0000 |
commit | 7f5b94b473cd19217127a69c0b8995e00b023173 (patch) | |
tree | 4fc26a47f9e46136ced6ab589fadc9b35443e023 /src/gui/kernel | |
parent | 212285639d748c7def8648f89b8c1c21c5f481e6 (diff) |
Fix shortcut overriding.
Moved to processKeyEvents() on all platforms except OS X.
Previously QWindowSystemInterface::tryHandleShortcutEvent() was called
from inside QWindowSystemInterface, this is considered unsafe as it
ends up calling sendEvent(). On some platforms the call might come from
a different thread then the receiver and cause an assert.
Task-number: QTBUG-44712
Change-Id: Ie80c698f63b9c3d9f52aa94380e539a84caea912
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 7 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.cpp | 10 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index b60ef4b8c1..243ef70efc 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1859,6 +1859,13 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE window = QGuiApplication::focusWindow(); } +#if !defined(Q_OS_OSX) + // On OS X the shortcut override is checked earlier, see: QWindowSystemInterface::handleKeyEvent() + const bool checkShortcut = e->keyType == QEvent::KeyPress && window != 0; + if (checkShortcut && QWindowSystemInterface::tryHandleShortcutEvent(window, e->timestamp, e->key, e->modifiers, e->unicode)) + return; +#endif // Q_OS_OSX + QKeyEvent ev(e->keyType, e->key, e->modifiers, e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 9a2fb33bbc..73b1a84005 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -292,8 +292,13 @@ void QWindowSystemInterface::handleKeyEvent(QWindow *w, QEvent::Type t, int k, Q void QWindowSystemInterface::handleKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count) { + // This is special handling needed for OS X which eventually will call sendEvent(), on other platforms + // this might not be safe, e.g., on Android. See: QGuiApplicationPrivate::processKeyEvent() for + // shortcut overriding on other platforms. +#if defined(Q_OS_OSX) if (t == QEvent::KeyPress && QWindowSystemInterface::tryHandleShortcutEvent(tlw, timestamp, k, mods, text)) return; +#endif // Q_OS_OSX QWindowSystemInterfacePrivate::KeyEvent * e = new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, t, k, mods, text, autorep, count); @@ -318,10 +323,7 @@ void QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestam const QString& text, bool autorep, ushort count, bool tryShortcutOverride) { - // on OS X we try the shortcut override even earlier and thus shouldn't handle it here - if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::tryHandleShortcutEvent(tlw, timestamp, key, modifiers, text)) - return; - + Q_UNUSED(tryShortcutOverride) QWindowSystemInterfacePrivate::KeyEvent * e = new QWindowSystemInterfacePrivate::KeyEvent(tlw, timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count); |