From ab276a9171b99be61b21f32d2b8c5ddb058cfd86 Mon Sep 17 00:00:00 2001 From: Li Zhang Date: Sun, 23 Aug 2015 17:43:51 +0800 Subject: [PATCH] Handle H/W keyboard key Change-Id: I83bbdb7b9dc24a0eb6b592d932115bf8fdd059c8 --- ism/extras/efl_wsc/isf_wsc_context.cpp | 132 +++++++++++++++++++++++++++++++++ ism/extras/efl_wsc/isf_wsc_context.h | 6 ++ ism/extras/efl_wsc/isf_wsc_efl.cpp | 25 +++---- 3 files changed, 147 insertions(+), 16 deletions(-) diff --git a/ism/extras/efl_wsc/isf_wsc_context.cpp b/ism/extras/efl_wsc/isf_wsc_context.cpp index 90f7ac0..c68507c 100644 --- a/ism/extras/efl_wsc/isf_wsc_context.cpp +++ b/ism/extras/efl_wsc/isf_wsc_context.cpp @@ -174,6 +174,9 @@ static Eina_Bool panel_iochannel_handler (void /* utility functions */ static bool filter_hotkeys (WSCContextISF *ic, const KeyEvent &key); +static bool filter_keys (const char *keyname, + const char *config_path); + static void turn_on_ic (WSCContextISF *ic); static void turn_off_ic (WSCContextISF *ic); static void set_ic_capabilities (WSCContextISF *ic); @@ -278,6 +281,7 @@ static IMEngineFactoryPointer _fallback_factory; static IMEngineInstancePointer _fallback_instance; PanelClient _panel_client; static int _panel_client_id = 0; +static int _active_helper_option = 0; static Ecore_Fd_Handler *_panel_iochannel_read_handler = 0; static Ecore_Fd_Handler *_panel_iochannel_err_handler = 0; @@ -1191,6 +1195,114 @@ isf_wsc_context_autocapital_type_set (WSCContextISF* ctx, Ecore_IMF_Autocapital_ } } +EAPI void +isf_wsc_context_filter_key_event (struct weescim *wsc, + uint32_t serial, + uint32_t timestamp, uint32_t keycode, uint32_t unicode, + char *keyname, + enum wl_keyboard_key_state state) + +{ + SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n"; + + if (!wsc) return; + + Eina_Bool ret = EINA_FALSE; + KeyEvent key(keycode, wsc->modifiers); + + if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { + key.mask = SCIM_KEY_ReleaseMask; + } + + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (filter_keys (keyname, SCIM_CONFIG_HOTKEYS_FRONTEND_IGNORE_KEY)) + return; + + /* Hardware input detect code */ +#ifdef _TV + if (timestamp > 1 && _active_helper_option && key.code != 0xFF69 && !((key.code >= SCIM_KEY_Left) && (key.code <= SCIM_KEY_Down)) && key.code != 0xFF8D && key.code != 0x002d && key.code != 0xff67 && key.code != 0xff13 && key.code != 0x1008ff26 && + !((key.code >= SCIM_KEY_0) && (key.code <= SCIM_KEY_9))) { + /* Cancel (Power + Volume down), Right, Left, Up, Down, OK, minus, menu, pause, XF86back key, 0~9 key*/ +#else + if (timestamp > 1 && _active_helper_option && key.code != 0x1008ff26 && key.code != 0xFF69 /* XF86back, Cancel (Power + Volume down) key */) { +#endif + isf_wsc_context_set_keyboard_mode (wsc->wsc_ctx, TOOLBAR_KEYBOARD_MODE); + _panel_client.prepare (wsc->wsc_ctx->id); + _panel_client.get_active_helper_option (&_active_helper_option); + _panel_client.send (); + ISF_SAVE_LOG ("Changed keyboard mode from S/W to H/W (code: %x, name: %s)\n", key.code, keyname); + LOGD ("Hardware keyboard mode, active helper option: %d", _active_helper_option); + } + } + else if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { + if (filter_keys (keyname, SCIM_CONFIG_HOTKEYS_FRONTEND_IGNORE_KEY)) + return; + } + + _panel_client.prepare (wsc->wsc_ctx->id); + + ret = EINA_TRUE; + if (!filter_hotkeys (wsc->wsc_ctx, key)) { + if (timestamp == 0) { + ret = EINA_FALSE; + // in case of generated event + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + char code = key.get_ascii_code (); + if (isgraph (code)) { + char string[2] = {0}; + snprintf (string, sizeof (string), "%c", code); + + if (strlen (string) != 0) { + wsc_context_commit_string(wsc, string); + caps_mode_check (wsc->wsc_ctx, EINA_FALSE, EINA_TRUE); + ret = EINA_TRUE; + } + } else { + if (key.code == SCIM_KEY_space || + key.code == SCIM_KEY_KP_Space) + autoperiod_insert (wsc->wsc_ctx); + } + } + _panel_client.send (); + return; + } + if (!_focused_ic || !_focused_ic->impl || !_focused_ic->impl->is_on) { + ret = EINA_FALSE; +#ifdef _TV + } else if (_active_helper_option & ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT) { + void *pvoid = &ret; + _panel_client.process_key_event (key, (int*)pvoid); + if (!ret) { + ret = _focused_ic->impl->si->process_key_event (key); + } +#else + } else if (_active_helper_option & ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT) { + void *pvoid = &ret; + _panel_client.process_key_event (key, (int*)pvoid); + if (!ret && !(_active_helper_option & ISM_HELPER_WITHOUT_IMENGINE)) { + ret = _focused_ic->impl->si->process_key_event (key); + } +#endif + } else { + ret = _focused_ic->impl->si->process_key_event (key); + } + + if (ret == EINA_FALSE) { + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + if (key.code == SCIM_KEY_space || + key.code == SCIM_KEY_KP_Space) + autoperiod_insert (wsc->wsc_ctx); + } + } + } + _panel_client.send (); + + if(ret == EINA_FALSE) + { + send_wl_key_event(wsc->wsc_ctx, key, false); + } +} + static void wsc_commit_preedit (weescim *ctx) { @@ -1746,6 +1858,26 @@ filter_hotkeys (WSCContextISF *ic, const KeyEvent &key) } static bool +filter_keys (const char *keyname, const char *config_path) +{ + SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n"; + + if (!keyname) + return false; + + std::vector keys; + scim_split_string_list (keys, _config->read (String (config_path), String ("")), ','); + + for (unsigned int i = 0; i < keys.size (); ++i) { + if (!strcmp (keyname, keys [i].c_str ())) { + return true; + } + } + + return false; +} + +static bool panel_initialize (void) { SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n"; diff --git a/ism/extras/efl_wsc/isf_wsc_context.h b/ism/extras/efl_wsc/isf_wsc_context.h index 188c2cb..1e92a5b 100644 --- a/ism/extras/efl_wsc/isf_wsc_context.h +++ b/ism/extras/efl_wsc/isf_wsc_context.h @@ -33,6 +33,7 @@ typedef struct _WSCContextISFImpl WSCContextISFImpl; typedef void (*keyboard_input_key_handler_t)(struct weescim *wsc, uint32_t serial, uint32_t time, uint32_t key, uint32_t unicode, + char *keyname, enum wl_keyboard_key_state state); struct weescim @@ -100,6 +101,11 @@ EAPI void isf_wsc_context_preedit_string_get (WSCContextISF *ctx, char** str, in EAPI void isf_wsc_context_prediction_allow_set (WSCContextISF* ctx, Eina_Bool prediction); EAPI Eina_Bool isf_wsc_context_prediction_allow_get (WSCContextISF* ctx); EAPI void isf_wsc_context_autocapital_type_set (WSCContextISF* ctx, Ecore_IMF_Autocapital_Type autocapital_type); +EAPI void isf_wsc_context_filter_key_event (struct weescim *wsc, + uint32_t serial, + uint32_t timestamp, uint32_t key, uint32_t unicode, + char *keyname, + enum wl_keyboard_key_state state); EAPI WSCContextISF* isf_wsc_context_new (void); EAPI void isf_wsc_context_shutdown (void); diff --git a/ism/extras/efl_wsc/isf_wsc_efl.cpp b/ism/extras/efl_wsc/isf_wsc_efl.cpp index c7de444..b5a2bc0 100644 --- a/ism/extras/efl_wsc/isf_wsc_efl.cpp +++ b/ism/extras/efl_wsc/isf_wsc_efl.cpp @@ -82,10 +82,6 @@ static KeycodeRepository _keysym2keycode; #endif #define LOG_TAG "ISF_WSC_EFL" -/* This structure stores the wayland input method information */ -#define MOD_SHIFT_MASK 0x01 -#define MOD_ALT_MASK 0x02 -#define MOD_CONTROL_MASK 0x04 static struct weescim _wsc = {0}; @@ -332,6 +328,7 @@ _wsc_im_keyboard_key(void *data, 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 || !wsc->state) @@ -342,10 +339,13 @@ _wsc_im_keyboard_key(void *data, sym = XKB_KEY_NoSymbol; if (num_syms == 1) + { sym = syms[0]; + xkb_keysym_get_name(sym, keyname, 64); + } if (wsc->key_handler) - (*wsc->key_handler)(wsc, serial, time, key, sym, + (*wsc->key_handler)(wsc, serial, time, key, sym, keyname, state); } @@ -372,11 +372,11 @@ _wsc_im_keyboard_modifiers(void *data, wsc->modifiers = 0; if (mask & wsc->control_mask) - wsc->modifiers |= MOD_CONTROL_MASK; + wsc->modifiers |= SCIM_KEY_ControlMask; if (mask & wsc->alt_mask) - wsc->modifiers |= MOD_ALT_MASK; + wsc->modifiers |= SCIM_KEY_AltMask; if (mask & wsc->shift_mask) - wsc->modifiers |= MOD_SHIFT_MASK; + wsc->modifiers |= SCIM_KEY_ShiftMask; wl_input_method_context_modifiers(context, serial, mods_depressed, mods_depressed, @@ -472,13 +472,6 @@ static const struct wl_seat_listener wsc_seat_listener = { _wsc_seat_handle_capabilities, }; -static void -_wsc_im_key_handler(struct weescim *wsc, - uint32_t serial, uint32_t time, uint32_t key, uint32_t sym, - enum wl_keyboard_key_state state) -{ -} - static bool _wsc_setup(struct weescim *wsc) { @@ -494,7 +487,7 @@ _wsc_setup(struct weescim *wsc) return false; } - wsc->key_handler = _wsc_im_key_handler; + wsc->key_handler = isf_wsc_context_filter_key_event; wsc->wsc_ctx = isf_wsc_context_new (); if (!wsc->wsc_ctx) return false; -- 2.7.4