From a9ca63b3676d25af331515771853c2c8b638405b Mon Sep 17 00:00:00 2001 From: Dav999 Date: Thu, 1 Aug 2024 19:18:20 +0200 Subject: [PATCH] Add buffer for IME editing events When inputting uncommitted text from an IME, this is now stored in a std::string imebuffer, just like keybuffer. It also enables extended editing events, so text longer than what fits in the standard editing event is also supported. This commit does not yet display the text onscreen. --- desktop_version/src/KeyPoll.cpp | 14 ++++++++++++-- desktop_version/src/KeyPoll.h | 1 + desktop_version/src/main.cpp | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index b56b9d47..55779915 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -50,7 +50,8 @@ KeyPoll::KeyPoll(void) // 0..5 sensitivity = 2; - keybuffer=""; + keybuffer = ""; + imebuffer = ""; leftbutton=0; rightbutton=0; middlebutton=0; mousex = 0; mousey = 0; @@ -64,13 +65,15 @@ KeyPoll::KeyPoll(void) void KeyPoll::enabletextentry(void) { - keybuffer=""; + keybuffer = ""; + imebuffer = ""; SDL_StartTextInput(); } void KeyPoll::disabletextentry(void) { SDL_StopTextInput(); + imebuffer = ""; } bool KeyPoll::textentry(void) @@ -321,6 +324,13 @@ void KeyPoll::Poll(void) keybuffer += evt.text.text; } break; + case SDL_TEXTEDITING: + imebuffer = evt.edit.text; + break; + case SDL_TEXTEDITING_EXT: + imebuffer = evt.editExt.text; + SDL_free(evt.editExt.text); + break; /* Mouse Input */ case SDL_MOUSEMOTION: diff --git a/desktop_version/src/KeyPoll.h b/desktop_version/src/KeyPoll.h index 5718ebf0..2d7c5f9b 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -69,6 +69,7 @@ public: bool textentry(void); bool pressedbackspace; std::string keybuffer; + std::string imebuffer; bool linealreadyemptykludge; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index c3672eb4..2f884ec7 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -599,6 +599,7 @@ int main(int argc, char *argv[]) } SDL_SetHintWithPriority(SDL_HINT_IME_SHOW_UI, "1", SDL_HINT_OVERRIDE); + SDL_SetHintWithPriority(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1", SDL_HINT_OVERRIDE); /* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */ SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE);