From 091b77793febf8c7e6e1b117724b28ff3d992a1e Mon Sep 17 00:00:00 2001 From: Li Zhang Date: Tue, 31 May 2016 20:45:09 +0800 Subject: [PATCH] Filter key event by APP, remove grab_keyboard Change-Id: I3c013c5a7e455f45b017142f05c28aca7993dc18 --- ism/extras/wayland_immodule/wayland_imcontext.c | 111 ++++++- ism/modules/panelagent/wayland/isf_wsc_context.h | 26 +- .../wayland/wayland_panel_agent_module.cpp | 324 ++++----------------- ism/src/scim_helper.cpp | 30 +- 4 files changed, 176 insertions(+), 315 deletions(-) diff --git a/ism/extras/wayland_immodule/wayland_imcontext.c b/ism/extras/wayland_immodule/wayland_imcontext.c index e266cec..94544c3 100644 --- a/ism/extras/wayland_immodule/wayland_imcontext.c +++ b/ism/extras/wayland_immodule/wayland_imcontext.c @@ -41,6 +41,11 @@ #define LOG_TAG "IMMODULE" #define HIDE_TIMER_INTERVAL 0.05 +#define WAIT_FOR_FILTER_DONE_SECOND 2 + +#define MOD_SHIFT_MASK 0x01 +#define MOD_ALT_MASK 0x02 +#define MOD_CONTROL_MASK 0x04 static Eina_Bool _clear_hide_timer(); static Ecore_Timer *_hide_timer = NULL; @@ -117,6 +122,13 @@ struct _WaylandIMContext void *input_panel_data; uint32_t input_panel_data_length; + + struct + { + uint32_t serial; + uint32_t state; + } last_key_event_filter; + Eina_List *keysym_list; // }; @@ -253,6 +265,7 @@ static void _win_focus_out_handler_del () static void _send_input_panel_hide_request(Ecore_IMF_Context *ctx) { + LOGD (""); // TIZEN_ONLY(20150708): Support back key _hide_req_ctx = NULL; // @@ -284,6 +297,8 @@ _input_panel_hide_timer_start(void *data) static void _input_panel_hide(Ecore_IMF_Context *ctx, Eina_Bool instant) { + LOGD (""); + if (!get_using_ctx()) { LOGW("Can't hide input_panel because there is no using context!!"); return; @@ -808,7 +823,7 @@ text_input_modifiers_map(void *data, struct wl_array *map) { WaylandIMContext *imcontext = (WaylandIMContext *)data; - + LOGD (""); imcontext->shift_mask = modifiers_get_mask(map, "Shift"); imcontext->control_mask = modifiers_get_mask(map, "Control"); imcontext->alt_mask = modifiers_get_mask(map, "Mod1"); @@ -866,11 +881,19 @@ text_input_keysym(void *data, if (modifiers & imcontext->alt_mask) e->modifiers |= ECORE_EVENT_MODIFIER_ALT; - - if (state) - ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL); - else - ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL); + //Save "wl_text_input::keysym" keysym to list if list is not empty, + //if not, send keysym to ecore loop as key event. + //This code let key event which will be filtered by IME one by one. + if (eina_list_count(imcontext->keysym_list)) { + e->data = (void *)(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP); + imcontext->keysym_list = eina_list_prepend(imcontext->keysym_list, e); + } + else { + if (state) + ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL); + else + ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL); + } } static void @@ -903,7 +926,7 @@ text_input_input_panel_state(void *data EINA_UNUSED, { // TIZEN_ONLY(20150708): Support input panel state callback WaylandIMContext *imcontext = (WaylandIMContext *)data; - + LOGD("input panel state: %d", state); switch (state) { case WL_TEXT_INPUT_INPUT_PANEL_STATE_HIDE: _input_panel_state = ECORE_IMF_INPUT_PANEL_STATE_HIDE; @@ -1152,6 +1175,21 @@ text_input_get_surrounding_text (void *data, } close(fd); } + +static void +text_input_filter_key_event_done(void *data, + struct wl_text_input *text_input EINA_UNUSED, + uint32_t serial, + uint32_t state) +{ + LOGD("serial:%d,state:%d", serial, state); + WaylandIMContext *imcontext = (WaylandIMContext *)data; + if (!imcontext) return; + + imcontext->last_key_event_filter.serial = serial; + imcontext->last_key_event_filter.state = state; +} + // static const struct wl_text_input_listener text_input_listener = @@ -1175,7 +1213,8 @@ static const struct wl_text_input_listener text_input_listener = text_input_input_panel_geometry, text_input_input_panel_data, text_input_get_selection_text, - text_input_get_surrounding_text + text_input_get_surrounding_text, + text_input_filter_key_event_done // }; @@ -1235,6 +1274,10 @@ wayland_im_context_add(Ecore_IMF_Context *ctx) imcontext->ctx = ctx; imcontext->input_panel_layout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL; + imcontext->keysym_list = NULL; + imcontext->shift_mask = MOD_SHIFT_MASK; + imcontext->control_mask = MOD_CONTROL_MASK; + imcontext->alt_mask = MOD_ALT_MASK; imcontext->text_input = wl_text_input_manager_create_text_input(imcontext->text_input_manager); @@ -1249,6 +1292,7 @@ wayland_im_context_del (Ecore_IMF_Context *ctx) { WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx); + Ecore_Event_Key *ev; LOGD ("context_del. ctx : %p", ctx); if (!imcontext) return; @@ -1289,6 +1333,10 @@ wayland_im_context_del (Ecore_IMF_Context *ctx) wl_text_input_destroy (imcontext->text_input); clear_preedit (imcontext); + + EINA_LIST_FREE(imcontext->keysym_list, ev) { + free(ev); + } } EAPI void @@ -1469,6 +1517,8 @@ wayland_im_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event EINA_UNUSED) { + Eina_Bool ret = EINA_FALSE; + if (type == ECORE_IMF_EVENT_MOUSE_UP) { if (ecore_imf_context_input_panel_enabled_get(ctx)) { LOGD ("[Mouse-up event] ctx : %p\n", ctx); @@ -1478,9 +1528,52 @@ wayland_im_context_filter_event(Ecore_IMF_Context *ctx, else LOGE ("Can't show IME because there is no focus. ctx : %p\n", ctx); } + } else if (type == ECORE_IMF_EVENT_KEY_UP || type == ECORE_IMF_EVENT_KEY_DOWN) { + Ecore_Event_Key *ev = (Ecore_Event_Key *)event; + WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx); + if (!imcontext) + return EINA_FALSE; + + int serial = imcontext->serial++; + double start_time = ecore_time_get(); + + uint32_t modifiers = 0; + if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT) + modifiers |= imcontext->shift_mask; + if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) + modifiers |= imcontext->control_mask; + if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT) + modifiers |= imcontext->alt_mask; + + LOGD ("ev:modifiers=%d, modifiers=%d, shift_mask=%d, control_mask=%d, alt_mask=%d", ev->modifiers, modifiers, imcontext->shift_mask, imcontext->control_mask, imcontext->alt_mask); + //Send key event to IME. + wl_text_input_filter_key_event(imcontext->text_input, serial, ev->timestamp, ev->keyname, + type == ECORE_IMF_EVENT_KEY_UP? WL_KEYBOARD_KEY_STATE_RELEASED : WL_KEYBOARD_KEY_STATE_PRESSED, + modifiers); + //Waiting for filter_key_event_done from IME. + //This function should return IME filtering result with boolean type. + while (ecore_time_get() - start_time < WAIT_FOR_FILTER_DONE_SECOND){ + wl_display_dispatch(ecore_wl_display_get()); + if (imcontext->last_key_event_filter.serial == serial) { + ret = imcontext->last_key_event_filter.state; + break; + } + } + + LOGD ("eclipse : %fs, serial (last,require) : (%d,%d)", (ecore_time_get() - start_time), imcontext->last_key_event_filter.serial, serial); + //Deal with the next key event in list. + if (eina_list_count (imcontext->keysym_list)) { + Eina_List *n = eina_list_last(imcontext->keysym_list); + ev = (Ecore_Event_Key *)eina_list_data_get(n); + int type = (int)ev->data; + + ev->data = NULL; + ecore_event_add(type, ev, NULL, NULL); + imcontext->keysym_list = eina_list_remove_list(imcontext->keysym_list, n); + } } - return EINA_FALSE; + return ret; } EAPI void diff --git a/ism/modules/panelagent/wayland/isf_wsc_context.h b/ism/modules/panelagent/wayland/isf_wsc_context.h index f939e9d..3664a2e 100644 --- a/ism/modules/panelagent/wayland/isf_wsc_context.h +++ b/ism/modules/panelagent/wayland/isf_wsc_context.h @@ -48,12 +48,6 @@ const double WILL_SHOW_TIMER_INTERVAL = 5.0; typedef struct _WSCContextISF WSCContextISF; typedef struct _WSCContextISFImpl WSCContextISFImpl; -typedef void (*keyboard_input_key_handler_t)(WSCContextISF *wsc_ctx, - uint32_t serial, - uint32_t time, uint32_t keycode, uint32_t symcode, - char *keyname, - enum wl_keyboard_key_state state); - struct weescim { struct wl_input_method *im; @@ -64,24 +58,11 @@ struct weescim struct _WSCContextISF { weescim *ctx; - struct wl_keyboard *keyboard; struct wl_input_method_context *im_ctx; - struct xkb_context *xkb_context; - - uint32_t modifiers; - - struct xkb_keymap *keymap; - struct xkb_state *state; - xkb_mod_mask_t control_mask; - xkb_mod_mask_t alt_mask; - xkb_mod_mask_t shift_mask; - - KeycodeRepository _keysym2keycode; - - keyboard_input_key_handler_t key_handler; Ecore_Fd_Handler* surrounding_text_fd_read_handler; Ecore_Fd_Handler* selection_text_fd_read_handler; + char *surrounding_text; char *selection_text; char *preedit_str; @@ -120,9 +101,8 @@ void isf_wsc_context_autocapital_type_set (WSCContextISF* wsc_ctx, Ecore_IMF_Aut void isf_wsc_context_bidi_direction_set (WSCContextISF* wsc_ctx, Ecore_IMF_BiDi_Direction direction); void isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx, uint32_t serial, - uint32_t timestamp, uint32_t key, uint32_t unicode, - char *keyname, - enum wl_keyboard_key_state state); + uint32_t timestamp, const char *keyname, + bool press, uint32_t modifiers); bool wsc_context_surrounding_get (WSCContextISF *wsc_ctx, char **text, int *cursor_pos); Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get(WSCContextISF *wsc_ctx); diff --git a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp index 38bd1f4..0af67ec 100644 --- a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp +++ b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp @@ -57,7 +57,6 @@ #include "isf_wsc_control_ui.h" #include -#include #include #include "isf_debug.h" @@ -238,6 +237,10 @@ static Input_Language input_lang #define WAYLAND_MODULE_CLIENT_ID (0) +#define MOD_SHIFT_MASK 0x01 +#define MOD_ALT_MASK 0x02 +#define MOD_CONTROL_MASK 0x04 + //////////////////////////////wayland_panel_agent_module begin////////////////////////////////////////////////// #define scim_module_init wayland_LTX_scim_module_init @@ -418,6 +421,17 @@ _wsc_im_ctx_process_input_device_event(void *data, struct wl_input_method_contex isf_wsc_context_process_input_device_event(wsc_ctx, type, input_data, input_data_len); } +static void +_wsc_im_ctx_filter_key_event(void *data, struct wl_input_method_context *im_ctx, uint32_t serial, uint32_t time, const char *keyname, uint32_t state, uint32_t modifiers) +{ + WSCContextISF *wsc_ctx = (WSCContextISF*)data; + if (!wsc_ctx) return; + + isf_wsc_context_filter_key_event(wsc_ctx, serial, time, keyname, + ((wl_keyboard_key_state)state) == WL_KEYBOARD_KEY_STATE_PRESSED, modifiers); +} + + static const struct wl_input_method_context_listener wsc_im_context_listener = { _wsc_im_ctx_reset, _wsc_im_ctx_content_type, @@ -429,176 +443,8 @@ static const struct wl_input_method_context_listener wsc_im_context_listener = { _wsc_im_ctx_input_panel_data, _wsc_im_ctx_bidi_direction, _wsc_im_ctx_cursor_position, - _wsc_im_ctx_process_input_device_event -}; - -static void -_init_keysym2keycode(WSCContextISF *wsc_ctx) -{ - uint32_t i = 0; - uint32_t code; - uint32_t num_syms; - const xkb_keysym_t *syms; - - if (!wsc_ctx || !wsc_ctx->state) - return; - - for (i = 0; i < 256; i++) { - code = i + 8; - num_syms = xkb_key_get_syms(wsc_ctx->state, code, &syms); - - if (num_syms == 1) - wsc_ctx->_keysym2keycode[syms[0]] = i; - } -} - -static void -_fini_keysym2keycode(WSCContextISF *wsc_ctx) -{ - wsc_ctx->_keysym2keycode.clear(); -} - -static void -_wsc_im_keyboard_keymap(void *data, - struct wl_keyboard *wl_keyboard, - uint32_t format, - int32_t fd, - uint32_t size) -{ - WSCContextISF *wsc_ctx = (WSCContextISF*)data; - char *map_str; - - if (!wsc_ctx) return; - - _fini_keysym2keycode(wsc_ctx); - - if (wsc_ctx->state) { - xkb_state_unref(wsc_ctx->state); - wsc_ctx->state = NULL; - } - - if (wsc_ctx->keymap) { - xkb_map_unref(wsc_ctx->keymap); - wsc_ctx->keymap = NULL; - } - - if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { - close(fd); - return; - } - - map_str = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); - if (map_str == MAP_FAILED) { - close(fd); - return; - } - - wsc_ctx->keymap = - xkb_map_new_from_string(wsc_ctx->xkb_context, - map_str, - XKB_KEYMAP_FORMAT_TEXT_V1, - (xkb_keymap_compile_flags)0); - - munmap(map_str, size); - close(fd); - - if (!wsc_ctx->keymap) { - LOGW ("failed to compile keymap\n"); - return; - } - - wsc_ctx->state = xkb_state_new(wsc_ctx->keymap); - if (!wsc_ctx->state) { - LOGW ("failed to create XKB state\n"); - xkb_map_unref(wsc_ctx->keymap); - return; - } - - wsc_ctx->control_mask = - 1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Control"); - wsc_ctx->alt_mask = - 1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Mod1"); - wsc_ctx->shift_mask = - 1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Shift"); - - LOGD ("create _keysym2keycode\n"); - _init_keysym2keycode(wsc_ctx); -} - -static void -_wsc_im_keyboard_key(void *data, - struct wl_keyboard *wl_keyboard, - uint32_t serial, - uint32_t time, - uint32_t key, - uint32_t state_w) -{ - WSCContextISF *wsc_ctx = (WSCContextISF*)data; - uint32_t code; - uint32_t num_syms; - const xkb_keysym_t *syms; - xkb_keysym_t sym; - char keyname[64] = {0}; - enum wl_keyboard_key_state state = (wl_keyboard_key_state)state_w; - - if (!wsc_ctx || !wsc_ctx->state) - return; - - code = key + 8; - num_syms = xkb_key_get_syms(wsc_ctx->state, code, &syms); - - sym = XKB_KEY_NoSymbol; - if (num_syms == 1) - { - sym = syms[0]; - xkb_keysym_get_name(sym, keyname, 64); - } - - if (wsc_ctx->key_handler) - (*wsc_ctx->key_handler)(wsc_ctx, serial, time, code, sym, keyname, - state); -} - -static void -_wsc_im_keyboard_modifiers(void *data, - struct wl_keyboard *wl_keyboard, - uint32_t serial, - uint32_t mods_depressed, - uint32_t mods_latched, - uint32_t mods_locked, - uint32_t group) -{ - WSCContextISF *wsc_ctx = (WSCContextISF*)data; - if (!wsc_ctx || !wsc_ctx->state) - return; - - struct wl_input_method_context *context = wsc_ctx->im_ctx; - xkb_mod_mask_t mask; - - xkb_state_update_mask(wsc_ctx->state, mods_depressed, - mods_latched, mods_locked, 0, 0, group); - mask = xkb_state_serialize_mods(wsc_ctx->state, - (xkb_state_component)(XKB_STATE_DEPRESSED | XKB_STATE_LATCHED)); - - wsc_ctx->modifiers = 0; - if (mask & wsc_ctx->control_mask) - wsc_ctx->modifiers |= SCIM_KEY_ControlMask; - if (mask & wsc_ctx->alt_mask) - wsc_ctx->modifiers |= SCIM_KEY_AltMask; - if (mask & wsc_ctx->shift_mask) - wsc_ctx->modifiers |= SCIM_KEY_ShiftMask; - - wl_input_method_context_modifiers(context, serial, - mods_depressed, mods_depressed, - mods_latched, group); -} - -static const struct wl_keyboard_listener wsc_im_keyboard_listener = { - _wsc_im_keyboard_keymap, - NULL, /* enter */ - NULL, /* leave */ - _wsc_im_keyboard_key, - _wsc_im_keyboard_modifiers + _wsc_im_ctx_process_input_device_event, + _wsc_im_ctx_filter_key_event }; static void @@ -612,21 +458,10 @@ _wsc_im_activate(void *data, struct wl_input_method *input_method, struct wl_inp return; } - wsc_ctx->xkb_context = xkb_context_new((xkb_context_flags)0); - if (wsc_ctx->xkb_context == NULL) { - LOGW ("Failed to create XKB context\n"); - delete wsc_ctx; - return; - } - wsc_ctx->id = text_input_id; wsc->wsc_ctx = wsc_ctx; wsc_ctx->ctx = wsc; - wsc_ctx->state = NULL; - wsc_ctx->keymap = NULL; - wsc_ctx->modifiers = 0; wsc_ctx->surrounding_text = NULL; - wsc_ctx->key_handler = isf_wsc_context_filter_key_event; get_language(&wsc_ctx->language); @@ -637,10 +472,6 @@ _wsc_im_activate(void *data, struct wl_input_method *input_method, struct wl_inp wsc_ctx->im_ctx = im_ctx; wl_input_method_context_add_listener (im_ctx, &wsc_im_context_listener, wsc_ctx); - wsc_ctx->keyboard = wl_input_method_context_grab_keyboard(im_ctx); - if (wsc_ctx->keyboard) - wl_keyboard_add_listener(wsc_ctx->keyboard, &wsc_im_keyboard_listener, wsc_ctx); - if (wsc_ctx->language) wl_input_method_context_language (im_ctx, wsc_ctx->serial, wsc_ctx->language); @@ -669,28 +500,6 @@ _wsc_im_deactivate(void *data, struct wl_input_method *input_method, struct wl_i isf_wsc_context_focus_out (wsc_ctx); - if (wsc_ctx->keyboard) { - wl_keyboard_destroy (wsc_ctx->keyboard); - wsc_ctx->keyboard = NULL; - } - - _fini_keysym2keycode (wsc_ctx); - - if (wsc_ctx->state) { - xkb_state_unref (wsc_ctx->state); - wsc_ctx->state = NULL; - } - - if (wsc_ctx->keymap) { - xkb_map_unref (wsc_ctx->keymap); - wsc_ctx->keymap = NULL; - } - - if (wsc_ctx->xkb_context) { - xkb_context_unref (wsc_ctx->xkb_context); - wsc_ctx->xkb_context = NULL; - } - if (wsc_ctx->im_ctx) { wl_input_method_context_destroy (wsc_ctx->im_ctx); wsc_ctx->im_ctx = NULL; @@ -959,6 +768,7 @@ check_space_symbol (Eina_Unicode uchar) static void autoperiod_insert (WSCContextISF *wsc_ctx) { + LOGD (""); char *plain_str = NULL; int cursor_pos = 0; Eina_Unicode *ustr = NULL; @@ -1605,22 +1415,30 @@ bool is_number_key(const char *str) void isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx, uint32_t serial, - uint32_t timestamp, uint32_t keycode, uint32_t symcode, - char *keyname, - enum wl_keyboard_key_state state) - + uint32_t timestamp, const char *keyname, + bool press, uint32_t modifiers) { SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n"; LOGD (""); if (!wsc_ctx) return; - KeyEvent key(symcode, wsc_ctx->modifiers); + String _keyname(keyname); + KeyEvent key(_keyname); + LOGD ("keyname: %s, keycode: %d, press: %d, modifiers: %d", keyname, key.code, press, modifiers); + bool ignore_key = filter_keys (keyname, SCIM_CONFIG_HOTKEYS_FRONTEND_IGNORE_KEY); - if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { - key.mask = SCIM_KEY_ReleaseMask; - } else if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (modifiers & MOD_SHIFT_MASK) + key.mask |= SCIM_KEY_ShiftMask; + if (modifiers & MOD_ALT_MASK) + key.mask |= SCIM_KEY_AltMask; + if (modifiers & MOD_CONTROL_MASK) + key.mask |= SCIM_KEY_ControlMask; + + if (!press) { + key.mask |= SCIM_KEY_ReleaseMask; + } else { if (!ignore_key) { /* Hardware input detect code */ #ifdef _TV @@ -1654,16 +1472,15 @@ isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx, } if (!ignore_key) { - if (!_focused_ic || !_focused_ic->impl || !_focused_ic->impl->is_on) { LOGD ("ic is off"); } else { - static uint32 _serial = 0; - g_info_manager->process_key_event (key, ++_serial); + g_info_manager->process_key_event (key, serial); + return; } - } else { - send_wl_key_event (wsc_ctx, key, false); } + + wl_input_method_context_filter_key_event_done (wsc_ctx->im_ctx, serial, EINA_FALSE); } static void @@ -2243,27 +2060,10 @@ panel_slot_update_preedit_caret (int context, int caret) } } -static Eina_Bool -feed_key_event (WSCContextISF *ic, const KeyEvent &key, bool fake) -{ - SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n"; - LOGD (""); - - if (key.code <= 0x7F || - (key.code >= SCIM_KEY_BackSpace && key.code <= SCIM_KEY_Delete) || - (key.code >= SCIM_KEY_Home && key.code <= SCIM_KEY_Hyper_R)) { - // ascii code and function keys - send_wl_key_event (ic, key, fake); - return EINA_TRUE; - } else { - return EINA_FALSE; - } -} - static void panel_slot_process_key_event (int context, const KeyEvent &key) { - LOGD (""); + LOGD ("keycode: %d", key.code); WSCContextISF* ic = find_ic (context); SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " key=" << key.get_key_string () << " ic=" << ic << "\n"; @@ -2273,31 +2073,12 @@ panel_slot_process_key_event (int context, const KeyEvent &key) if ((_focused_ic != NULL) && (_focused_ic != ic)) return; - //FIXME: filter_hotkeys should be added - //if (filter_hotkeys (ic, _key) == false && process_key) { - //if (!_focused_ic || !_focused_ic->impl->is_on) { - char code = key.get_ascii_code (); - if (key.is_key_press ()) { - if (isgraph (code)) { - char string[2] = {0}; - snprintf (string, sizeof (string), "%c", code); - - if (strlen (string) != 0) { - wsc_context_commit_string (ic, string); - caps_mode_check (ic, EINA_FALSE, EINA_TRUE); - } - } else { - if (key.code == SCIM_KEY_space || - key.code == SCIM_KEY_KP_Space) - autoperiod_insert (ic); - } - } - - if (!isgraph (code)) { - feed_key_event (ic, key, false); - } - //} - //} + if (key.is_key_press ()) { + if (key.code == SCIM_KEY_space || + key.code == SCIM_KEY_KP_Space) + autoperiod_insert (ic); + } + send_wl_key_event (ic, key, false); } static void @@ -2336,7 +2117,7 @@ panel_slot_forward_key_event (int context, const KeyEvent &key) if (strlen (key.get_key_string ().c_str ()) >= 116) return; - feed_key_event (ic, key, true); + send_wl_key_event (ic, key, true); } static void @@ -2484,10 +2265,6 @@ finalize (void) panel_finalize (); } -#define MOD_SHIFT_MASK 0x01 -#define MOD_ALT_MASK 0x02 -#define MOD_CONTROL_MASK 0x04 - static uint32_t _keyname_to_keysym (uint32_t keyname, uint32_t *modifiers) { if (!modifiers) @@ -2945,17 +2722,18 @@ public: void process_key_event_done(int id, uint32 context_id, KeyEvent &key, uint32 ret, uint32 serial) { LOGD ("client id:%d", id); WSCContextISF* ic = find_ic (context_id); + if (!ic) return; + if (ret == EINA_FALSE) { if (key.is_key_press()) { if (key.code == SCIM_KEY_space || - key.code == SCIM_KEY_KP_Space) + key.code == SCIM_KEY_KP_Space) { autoperiod_insert (ic); + } } } - if (ret == EINA_FALSE) { - send_wl_key_event (ic, key, false); - } + wl_input_method_context_filter_key_event_done (ic->im_ctx, serial, ret); } }; diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp index d34b6ad..78bdf4e 100644 --- a/ism/src/scim_helper.cpp +++ b/ism/src/scim_helper.cpp @@ -1056,18 +1056,18 @@ HelperAgent::filter_event () KeyEvent key; uint32 ret = 0; uint32 serial = 0; - if (m_impl->recv.get_data (key) && m_impl->recv.get_data (serial)) + if (m_impl->recv.get_data (key) && m_impl->recv.get_data (serial)) { m_impl->signal_process_key_event(this, key, ret); + if (ret == 0) + if (!m_impl->si.null ()) + { + ret = m_impl->si->process_key_event (key); + LOGD("imengine(%s) process key %d return %d", m_impl->si->get_factory_uuid().c_str(), key.code, ret); + } + m_impl->process_key_event_done (key, ret, serial); + } else LOGW ("wrong format of transaction\n"); - if (ret == 0) - if (!m_impl->si.null ()) - { - ret = m_impl->si->process_key_event (key); - LOGD("imengine(%s) process key %d return %d", m_impl->si->get_factory_uuid().c_str(), key.code, ret); - } - - m_impl->process_key_event_done (key, ret, serial); break; } case ISM_TRANS_CMD_SET_LAYOUT: @@ -1509,7 +1509,17 @@ HelperAgent::send_key_event (int ic, } bool ret = false; - if (!m_impl->si.null ()) { + + if (key.code <= 0x7F || + (key.code >= SCIM_KEY_BackSpace && key.code <= SCIM_KEY_Delete) || + (key.code >= SCIM_KEY_Home && key.code <= SCIM_KEY_Hyper_R)) { + // ascii code and function keys + ret = false; + } else { + ret = true; + } + + if (ret && (!m_impl->si.null ())) { ret = m_impl->si->process_key_event (key); LOGD ("imengine(%s) process key %d return %d", m_impl->si->get_factory_uuid().c_str(), key.code, ret); } -- 2.7.4