From dbb5c95f4d80644c6273b3adbe0148cdf30710d2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 1 Aug 2016 16:15:13 +0200 Subject: [PATCH] Windows QPA: Handle key event sequences of surrogates Emoji characters as input by the virtual keyboard are received as a sequence of surrogates. Store state internally when a high surrogate is received and send off the sequence when the matching low surrogate is received via input method. Task-number: QTBUG-50617 Change-Id: I91e763ec3e0747d6852f7c5c2057a67b0c24e0f5 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../platforms/windows/qwindowskeymapper.cpp | 16 ++++++++++++++++ .../platforms/windows/qwindowskeymapper.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 403ac6ecfb..1e58b9b3d4 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -37,6 +37,7 @@ #include "qwindowswindow.h" #include "qwindowsinputcontext.h" +#include #include #include #include @@ -1072,6 +1073,21 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, const MSG &ms if (PeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) { // Found a ?_CHAR uch = QChar(ushort(wm_char.wParam)); + if (uch.isHighSurrogate()) { + m_lastHighSurrogate = uch; + return true; + } else if (uch.isLowSurrogate() && !m_lastHighSurrogate.isNull()) { + if (QObject *focusObject = QGuiApplication::focusObject()) { + const QChar chars[2] = {m_lastHighSurrogate, uch}; + QInputMethodEvent event; + event.setCommitString(QString(chars, 2)); + QCoreApplication::sendEvent(focusObject, &event); + } + m_lastHighSurrogate = QChar(); + return true; + } else { + m_lastHighSurrogate = QChar(); + } if (msgType == WM_SYSKEYDOWN && uch.isLetter() && (msg.lParam & KF_ALTDOWN)) uch = uch.toLower(); // (See doc of WM_SYSCHAR) Alt-letter if (!code && !uch.row()) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.h b/src/plugins/platforms/windows/qwindowskeymapper.h index 3a3170e4ae..81ae1a3297 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.h +++ b/src/plugins/platforms/windows/qwindowskeymapper.h @@ -97,6 +97,7 @@ private: void deleteLayouts(); QWindow *m_keyGrabber; + QChar m_lastHighSurrogate; static const size_t NumKeyboardLayoutItems = 256; KeyboardLayoutItem keyLayout[NumKeyboardLayoutItems]; };