From cfa4f2255083d17cd0f04f7bc282cd2ddd4807ba Mon Sep 17 00:00:00 2001 From: Haifeng Deng Date: Mon, 3 Jun 2013 19:53:33 +0800 Subject: [PATCH] Discard input keys that does not match with current ic value Change-Id: Ifd20d9b90f8b39a4daa3daf961c39d0bd2a72db4 --- ism/extras/efl_immodule/isf_imf_context.cpp | 19 +++++++++++++++++++ ism/src/scim_helper.cpp | 23 +++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ism/extras/efl_immodule/isf_imf_context.cpp b/ism/extras/efl_immodule/isf_imf_context.cpp index d5a1ef4..6b0ef12 100644 --- a/ism/extras/efl_immodule/isf_imf_context.cpp +++ b/ism/extras/efl_immodule/isf_imf_context.cpp @@ -282,6 +282,8 @@ static Eina_Bool autoperiod_allow static Eina_Bool autocap_allow = EINA_FALSE; static Eina_Bool desktop_mode = EINA_FALSE; +static bool _x_key_event_is_valid = false; + static Display *__current_display = 0; static int __current_alt_mask = Mod1Mask; static int __current_meta_mask = 0; @@ -1299,6 +1301,7 @@ isf_imf_context_focus_out (Ecore_IMF_Context *ctx) _panel_client.send (); _focused_ic = 0; } + _x_key_event_is_valid = false; } /** @@ -1741,6 +1744,13 @@ isf_imf_context_filter_event (Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, if (ic == NULL || ic->impl == NULL) return ret; + if (type == ECORE_IMF_EVENT_KEY_DOWN || type == ECORE_IMF_EVENT_KEY_UP) { + if (hw_keyboard_num_get () == 0 && !_x_key_event_is_valid) { + std::cerr << " Hardware keyboard is not connected and key event is not valid!!!\n"; + return EINA_TRUE; + } + } + KeyEvent key; unsigned int timestamp; @@ -2062,6 +2072,9 @@ panel_slot_process_key_event (int context, const KeyEvent &key) SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " key=" << key.get_key_string () << " ic=" << ic << "\n"; if (!(ic && ic->impl)) return; + if (_focused_ic != ic) + return; + KeyEvent _key = key; if (key.is_key_press () && ecore_imf_context_input_panel_layout_get (ic->ctx) == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL) { @@ -2127,6 +2140,11 @@ panel_slot_forward_key_event (int context, const KeyEvent &key) EcoreIMFContextISF *ic = find_ic (context); SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " key=" << key.get_key_string () << " ic=" << ic << "\n"; + if (!(ic && ic->impl)) + return; + if (_focused_ic != ic) + return; + if (strlen (key.get_key_string ().c_str ()) >= 116) return; @@ -3288,6 +3306,7 @@ static void send_x_key_event (const KeyEvent &key, bool fake) XSendEvent (event.display, event.window, True, KeyReleaseMask, (XEvent *)&event); } } + _x_key_event_is_valid = true; } static void diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp index 646d75a..730a360 100644 --- a/ism/src/scim_helper.cpp +++ b/ism/src/scim_helper.cpp @@ -109,6 +109,7 @@ public: uint32 magic; uint32 magic_active; int timeout; + uint32 focused_ic; HelperAgentSignalVoid signal_exit; HelperAgentSignalVoid signal_attach_input_context; @@ -160,7 +161,7 @@ public: HelperAgentSignalInt signal_longpress_candidate; public: - HelperAgentImpl () : magic (0), magic_active (0), timeout (-1) { } + HelperAgentImpl () : magic (0), magic_active (0), timeout (-1), focused_ic ((uint32) -1) { } }; HelperAgent::HelperAgent () @@ -455,11 +456,13 @@ HelperAgent::filter_event () case SCIM_TRANS_CMD_FOCUS_OUT: { m_impl->signal_focus_out (this, ic, ic_uuid); + m_impl->focused_ic = (uint32) -1; break; } case SCIM_TRANS_CMD_FOCUS_IN: { m_impl->signal_focus_in (this, ic, ic_uuid); + m_impl->focused_ic = ic; break; } case ISM_TRANS_CMD_SHOW_ISE_PANEL: @@ -861,7 +864,11 @@ HelperAgent::send_key_event (int ic, m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST); m_impl->send.put_data (m_impl->magic_active); m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_SEND_KEY_EVENT); - m_impl->send.put_data ((uint32)ic); + if (ic == -1) { + m_impl->send.put_data (m_impl->focused_ic); + } else { + m_impl->send.put_data ((uint32)ic); + } m_impl->send.put_data (ic_uuid); m_impl->send.put_data (key); m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active); @@ -887,7 +894,11 @@ HelperAgent::forward_key_event (int ic, m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST); m_impl->send.put_data (m_impl->magic_active); m_impl->send.put_command (SCIM_TRANS_CMD_FORWARD_KEY_EVENT); - m_impl->send.put_data ((uint32)ic); + if (ic == -1) { + m_impl->send.put_data (m_impl->focused_ic); + } else { + m_impl->send.put_data ((uint32)ic); + } m_impl->send.put_data (ic_uuid); m_impl->send.put_data (key); m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active); @@ -913,7 +924,11 @@ HelperAgent::commit_string (int ic, m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST); m_impl->send.put_data (m_impl->magic_active); m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_STRING); - m_impl->send.put_data ((uint32)ic); + if (ic == -1) { + m_impl->send.put_data (m_impl->focused_ic); + } else { + m_impl->send.put_data ((uint32)ic); + } m_impl->send.put_data (ic_uuid); m_impl->send.put_data (wstr); m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active); -- 2.7.4