Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimum patch to enable kanji input on AndroWish, Tcl/tk on Android.
diff --git a/SdlTkInt.c b/SdlTkInt.c
index 2ccb1da..f4e04bf 100644
--- a/SdlTkInt.c
+++ b/SdlTkInt.c
@@ -653,6 +653,12 @@ skipTranslation:
case SDL_KEYDOWN:
case SDL_KEYUP:
state = SDL_GetMouseState(&x, &y);
+ {
+ /* To make sure all key-related events has empty charValuePtr. */
+ TkKeyEvent* kePtr = (TkKeyEvent*) event;
+ kePtr->charValueLen = 0;
+ kePtr->charValuePtr = 0;
+ }
event->type = (sdl_event->type == SDL_KEYUP)
? KeyRelease : KeyPress;
@@ -705,18 +711,23 @@ skipTranslation:
event->xkey.same_screen = True;
event->xkey.nbytes = 0;
- if (sdl_event->type == SDL_TEXTINPUT ||
- sdl_event->type == SDL_TEXTEDITING) {
- event->xkey.nbytes = strlen(sdl_event->text.text);
- if (event->xkey.nbytes > sizeof (event->xkey.trans_chars)) {
- event->xkey.nbytes = sizeof (event->xkey.trans_chars);
- }
- memcpy(event->xkey.trans_chars, sdl_event->text.text,
- event->xkey.nbytes);
- /* ignore illegal UTF-8 */
- if ((event->xkey.trans_chars[0] & 0xFF) == 0xC0) {
- return 0;
- }
+ if (sdl_event->type == SDL_TEXTINPUT) {
+ TkKeyEvent* kePtr = (TkKeyEvent*) event;
+ int len = strlen(txt_sdl_event.text.text);
+ event->xkey.nbytes = len;
+ if (len > 1) {
+ /* Set charValuePtr/Len too.*/
+ kePtr->charValueLen = strlen(sdl_event->text.text);
+ kePtr->charValuePtr = ckalloc(kePtr->charValueLen+1);
+ memcpy(kePtr->charValuePtr, sdl_event->text.text,
+ kePtr->charValueLen+1);
+ } else if (len > sizeof (event->xkey.trans_chars)) {
+ event->xkey.nbytes = sizeof (event->xkey.trans_chars);
+ }
+ memcpy(event->xkey.trans_chars, txt_sdl_event.text.text,
+ event->xkey.nbytes);
+ } else if (sdl_event->type == SDL_TEXTEDITING) {
+ /* TODO: What can we do here? */
} else if (SDL_PeepEvents(&txt_sdl_event, 1, SDL_PEEKEVENT,
SDL_TEXTINPUT, SDL_TEXTINPUT) == 1) {
SDL_PeepEvents(&txt_sdl_event, 1, SDL_GETEVENT,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment