Skip to content

Commit

Permalink
Windows QPA: Handle key event sequences of surrogates
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
FriedemannKleint committed Aug 3, 2016
1 parent 9b1db44 commit dbb5c95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/plugins/platforms/windows/qwindowskeymapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "qwindowswindow.h"
#include "qwindowsinputcontext.h"

#include <QtGui/QGuiApplication>
#include <QtGui/QWindow>
#include <qpa/qwindowsysteminterface.h>
#include <private/qguiapplication_p.h>
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/windows/qwindowskeymapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class QWindowsKeyMapper
void deleteLayouts();

QWindow *m_keyGrabber;
QChar m_lastHighSurrogate;
static const size_t NumKeyboardLayoutItems = 256;
KeyboardLayoutItem keyLayout[NumKeyboardLayoutItems];
};
Expand Down

0 comments on commit dbb5c95

Please sign in to comment.