From 6ad271b3cd1adbdf0e8c05324d7c6949cc545965 Mon Sep 17 00:00:00 2001 From: DaeKwang Ryu Date: Tue, 6 Dec 2016 11:37:03 +0900 Subject: [PATCH] [SDL_Tizen] implement SDL_TEXTINPUT and EDITING Tizen support SDL_TEXTINPUT and SDL_TEXTEDITING events. Change-Id: I60ae50c333e2e767083a4817ebafb6f27461e987 --- src/video/tizen/SDL_tizenevents.c | 133 ++++++++++++++++++++++++++++++++++-- src/video/tizen/SDL_tizenkeyboard.c | 20 +++++- 2 files changed, 146 insertions(+), 7 deletions(-) diff --git a/src/video/tizen/SDL_tizenevents.c b/src/video/tizen/SDL_tizenevents.c index 9b84368..447281f 100755 --- a/src/video/tizen/SDL_tizenevents.c +++ b/src/video/tizen/SDL_tizenevents.c @@ -39,6 +39,8 @@ #include "../../events/scancodes_tizen.h" #include "SDL_tizenkeyboard.h" +extern TizenKeyboard tizen_keyboard; + static SDL_Scancode TranslateKeycode(int keycode) { @@ -59,15 +61,91 @@ Tizen_PumpEvents(_THIS) ecore_main_loop_iterate(); } +Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier) +{ + int modifier = ECORE_IMF_KEYBOARD_MODIFIER_NONE; // If no other matches returns NONE. + + + if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h + { + modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h + } + + if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT ) + { + modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT; + } + + if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL ) + { + modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL; + } + + if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN ) + { + modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN; + } + + if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR ) + { + modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR; + } + + return (Ecore_IMF_Keyboard_Modifiers)modifier; +} + Eina_Bool _tizen_cb_event_keyup_change(void *data, int type, void *event) { if (!event) return ECORE_CALLBACK_PASS_ON; Ecore_Event_Key * e = event; - SDL_Scancode scancode = TranslateKeycode(e->keycode); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "key up: %d", scancode); - SDL_SendKeyboardKey(SDL_RELEASED, scancode); + SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; + if (!e->key) return ECORE_CALLBACK_PASS_ON; + + if (tizen_keyboard.imf_context) { + Ecore_IMF_Event_Key_Up ecore_ev; + + ecore_ev.keyname = e->keyname; + ecore_ev.key = e->key; + ecore_ev.string = e->string; + ecore_ev.compose = e->compose; + ecore_ev.timestamp = e->timestamp; + ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers ); + ecore_ev.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE; + + if (ecore_imf_context_filter_event(tizen_keyboard.imf_context, + ECORE_IMF_EVENT_KEY_UP, + (Ecore_IMF_Event *)&ecore_ev)) { + return ECORE_CALLBACK_PASS_ON; + } + } + + if (SDL_GetEventState(SDL_TEXTINPUT)) { + if (!strcmp(e->key, "BackSpace")) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + else if (!strcmp(e->key, "Delete") || + (!strcmp(e->key, "KP_Delete") && !e->string)) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + else if ((!strcmp(e->key, "Return")) || (!strcmp(e->key, "KP_Enter"))) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + else if (e->string) { + // Nothing + } + else { + scancode = TranslateKeycode(e->keycode); + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } + } else { + scancode = TranslateKeycode(e->keycode); + SDL_SendKeyboardKey(SDL_RELEASED, scancode); + } return ECORE_CALLBACK_PASS_ON; } @@ -78,9 +156,52 @@ _tizen_cb_event_keydown_change(void *data, int type, void *event) if (!event) return ECORE_CALLBACK_PASS_ON; Ecore_Event_Key * e = event; - SDL_Scancode scancode = TranslateKeycode(e->keycode); - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "key down: %d", scancode); - SDL_SendKeyboardKey(SDL_PRESSED, scancode); + SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; + if (!e->key) return ECORE_CALLBACK_PASS_ON; + + if (tizen_keyboard.imf_context) { + Ecore_IMF_Event_Key_Down ecore_ev; + + ecore_ev.keyname = e->keyname; + ecore_ev.key = e->key; + ecore_ev.string = e->string; + ecore_ev.compose = e->compose; + ecore_ev.timestamp = e->timestamp; + ecore_ev.modifiers = EcoreInputModifierToEcoreIMFModifier ( e->modifiers ); + ecore_ev.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE; + + if (ecore_imf_context_filter_event(tizen_keyboard.imf_context, + ECORE_IMF_EVENT_KEY_DOWN, + (Ecore_IMF_Event *)&ecore_ev)) { + return ECORE_CALLBACK_PASS_ON; + } + } + + if (SDL_GetEventState(SDL_TEXTINPUT)) { + if (!strcmp(e->key, "BackSpace")) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } + else if (!strcmp(e->key, "Delete") || + (!strcmp(e->key, "KP_Delete") && !e->string)) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } + else if ((!strcmp(e->key, "Return")) || (!strcmp(e->key, "KP_Enter"))) { + scancode = SDL_GetScancodeFromName(e->key); + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } + else if (e->string) { + SDL_SendKeyboardText(e->string); + } + else { + scancode = TranslateKeycode(e->keycode); + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } + } else { + scancode = TranslateKeycode(e->keycode); + SDL_SendKeyboardKey(SDL_PRESSED, scancode); + } return ECORE_CALLBACK_PASS_ON; } diff --git a/src/video/tizen/SDL_tizenkeyboard.c b/src/video/tizen/SDL_tizenkeyboard.c index cc55b93..9c48a6a 100755 --- a/src/video/tizen/SDL_tizenkeyboard.c +++ b/src/video/tizen/SDL_tizenkeyboard.c @@ -29,7 +29,7 @@ /* Tizen Keyboard */ -static TizenKeyboard tizen_keyboard; +TizenKeyboard tizen_keyboard; void _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info) @@ -41,6 +41,21 @@ _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void } void +_ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info EINA_UNUSED) +{ + char *preedit_string; + int cursor_pos; + Ecore_IMF_Context *imf_context = ctx; + + // get preedit string and attributes + ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, NULL, &cursor_pos); + SDL_Log("preedit string : %s, %d", preedit_string, cursor_pos); + + SDL_SendEditingText(preedit_string, 0, cursor_pos); + free(preedit_string); +} + +void _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, int value) { //ECORE_IMF_INPUT_PANEL_STATE_SHOW : 0 @@ -82,6 +97,9 @@ void Tizen_InitKeyboard(_THIS) ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id); ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL); + + ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, NULL); + ecore_imf_context_input_panel_event_callback_add (tizen_keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL); ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0); -- 2.7.4