From 4ea826318558dfdea5b244e80777c5b4f0ac4d7c Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 1 Oct 2020 15:56:27 +0200 Subject: [PATCH] [ion/simulator/events_keyboard] Serve ExternalText Generate an ExternalText event when catching a SDL_TextInputEvent whose text cannot be boiled down to one of the regular events. Change-Id: I036fa2a153c8351979521d7f8cba6b62aa64604b --- ion/src/simulator/shared/events_keyboard.cpp | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/ion/src/simulator/shared/events_keyboard.cpp b/ion/src/simulator/shared/events_keyboard.cpp index 79cfb8930..fcb6f16b4 100644 --- a/ion/src/simulator/shared/events_keyboard.cpp +++ b/ion/src/simulator/shared/events_keyboard.cpp @@ -1,9 +1,11 @@ #include "main.h" #include "platform.h" #include "layout.h" +#include "events.h" #include #include +#include #include #include @@ -148,20 +150,28 @@ static constexpr Event sEventForASCIICharAbove32[95] = { }; static Event eventFromSDLTextInputEvent(SDL_TextInputEvent event) { - if (strlen(event.text) != 1) { + if (strlen(event.text) == 1) { + char character = event.text[0]; + if (character >= 32 && character < 127) { + /* We remove the shift, otherwise it might stay activated when it + * shouldn't. For instance on a French keyboard, to input "1", we first + * press "Shift" (which activates the Shift modifier on the calculator), + * then we press "&", transformed by eventFromSDLTextInputEvent into the + * text "1". If we do not remove the Shift here, it would still be + * pressed afterwards. */ + Ion::Events::removeShift(); + Event res = sEventForASCIICharAbove32[character-32]; + if (res != None) { + return res; + } + } + } + if (!UTF8Helper::CanBeWrittenWithGlyphs(event.text)) { return None; } - char character = event.text[0]; - if (character >= 32 && character < 127) { - /* We remove the shift, otherwise it might stay activated when it shouldn't. - * For instance on a French keyboard, to input "1", we first press "Shift" - * (which activates the Shift modifier on the calculator), then we press - * "&", transformed by eventFromSDLTextInputEvent into the text "1". If we - * do not remove the Shift here, it would still be pressed afterwards. */ - Ion::Events::removeShift(); - return sEventForASCIICharAbove32[character-32]; - } - return None; + Ion::Events::removeShift(); + strlcpy(sharedExternalTextBuffer(), event.text, strlen(event.text) + 1); + return ExternalText; } Event getPlatformEvent() {