Fix shortcut handling in the Cocoa plugin
KeyPress events could be shortcuts or deadkeys, but we don't know which until we try. Shortcuts take precedence over deadkeys, so send them through QWindowSystemInterface::tryHandleSynchronousShortcutEvent() before passing it onto the input method. Change-Id: I479a3a7ff1c35e7c5692e8a17fb2173576dd0a29 Reviewed-by: Tasuku Suzuki <tasuku.suzuki@nokia.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
fbc251b364
commit
60c59b5cf5
@ -570,42 +570,43 @@ static QTouchDevice *touchDevice = 0;
|
||||
return qtMods;
|
||||
}
|
||||
|
||||
- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType
|
||||
- (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType
|
||||
{
|
||||
NSTimeInterval timestamp = [theEvent timestamp];
|
||||
NSTimeInterval timestamp = [nsevent timestamp];
|
||||
ulong qt_timestamp = timestamp * 1000;
|
||||
QString characters = QString::fromUtf8([[theEvent characters] UTF8String]);
|
||||
Qt::KeyboardModifiers modifiers = [self convertKeyModifiers : [theEvent modifierFlags]];
|
||||
QChar ch([[theEvent charactersIgnoringModifiers] characterAtIndex:0]);
|
||||
int keyCode = [self convertKeyCode : ch];
|
||||
QString characters = QString::fromUtf8([[nsevent characters] UTF8String]);
|
||||
Qt::KeyboardModifiers modifiers = [self convertKeyModifiers:[nsevent modifierFlags]];
|
||||
QChar ch([[nsevent charactersIgnoringModifiers] characterAtIndex:0]);
|
||||
int keyCode = [self convertKeyCode:ch];
|
||||
|
||||
QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters);
|
||||
}
|
||||
if (eventType == QEvent::KeyPress) {
|
||||
if (!m_keyEventsAccepted && m_composingText.isEmpty())
|
||||
m_keyEventsAccepted = QWindowSystemInterface::tryHandleSynchronousShortcutEvent(m_window, qt_timestamp, keyCode, modifiers, characters);
|
||||
|
||||
- (void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
QObject *fo = QGuiApplication::focusObject();
|
||||
m_keyEventsAccepted = false;
|
||||
if (fo) {
|
||||
QInputMethodQueryEvent queryEvent(Qt::ImHints);
|
||||
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||
Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
|
||||
if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText)) {
|
||||
[self interpretKeyEvents:[NSArray arrayWithObject: theEvent]];
|
||||
QObject *fo = QGuiApplication::focusObject();
|
||||
if (!m_keyEventsAccepted && fo) {
|
||||
QInputMethodQueryEvent queryEvent(Qt::ImHints);
|
||||
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||
Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
|
||||
if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText))
|
||||
[self interpretKeyEvents:[NSArray arrayWithObject:nsevent]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_keyEventsAccepted && m_composingText.isEmpty()) {
|
||||
[self handleKeyEvent : theEvent eventType :int(QEvent::KeyPress)];
|
||||
}
|
||||
if (!m_keyEventsAccepted && m_composingText.isEmpty())
|
||||
QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters);
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)theEvent
|
||||
- (void)keyDown:(NSEvent *)nsevent
|
||||
{
|
||||
if (!m_keyEventsAccepted && m_composingText.isEmpty()) {
|
||||
[self handleKeyEvent : theEvent eventType :int(QEvent::KeyRelease)];
|
||||
}
|
||||
m_keyEventsAccepted = false;
|
||||
[self handleKeyEvent:nsevent eventType:int(QEvent::KeyPress)];
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)nsevent
|
||||
{
|
||||
[self handleKeyEvent:nsevent eventType:int(QEvent::KeyRelease)];
|
||||
}
|
||||
|
||||
- (void) doCommandBySelector:(SEL)aSelector
|
||||
|
Loading…
Reference in New Issue
Block a user