From f8e9bd8e010d8b4c9b06184b7709feefa81b1884 Mon Sep 17 00:00:00 2001 From: Li Zhang Date: Mon, 27 Jun 2016 12:36:42 +0800 Subject: [PATCH] Add process_key_event_done function For avoiding block, process_key_event will not wait for result value. Change-Id: Ice3f418eb2b162741fd6ee0430d44ce22d97d929 --- .../ecore_socket_panel_agent_module.cpp | 19 ++++++++---- .../wayland/wayland_panel_agent_module.cpp | 36 ++++++++++++---------- ism/src/isf_info_manager.cpp | 27 +++++++++++++--- ism/src/isf_info_manager.h | 6 +++- ism/src/isf_panel_agent_base.cpp | 8 ++++- ism/src/isf_panel_agent_base.h | 11 ++++++- ism/src/isf_panel_agent_manager.cpp | 13 ++++++-- ism/src/isf_panel_agent_manager.h | 3 +- ism/src/scim_helper.cpp | 22 ++++++++++--- ism/src/scim_trans_commands.h | 2 ++ 10 files changed, 109 insertions(+), 38 deletions(-) diff --git a/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp b/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp index 905f475..85ff2ed 100644 --- a/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp +++ b/ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp @@ -768,7 +768,7 @@ private: m_send_trans.write_to_socket(client_socket); } - bool process_key_event(int client, uint32 context, const String& uuid, KeyEvent& key, _OUT_ uint32& result) { + bool process_key_event(int client, uint32 context, const String& uuid, KeyEvent& key, uint32 serial) { LOGD ("client id:%d\n", client); Socket client_socket(client); @@ -781,12 +781,9 @@ private: trans.put_data(uuid); trans.put_command(SCIM_TRANS_CMD_PROCESS_KEY_EVENT); trans.put_data(key); - int cmd; + trans.put_data(serial); - if (trans.write_to_socket(client_socket) - && trans.read_from_socket(client_socket) - && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY - && trans.get_data(result)) { + if (trans.write_to_socket(client_socket)) { SCIM_DEBUG_MAIN(1) << __func__ << " success\n"; return true; } else { @@ -2537,6 +2534,16 @@ private: //FIXME: useless //} else if (cmd == ISM_TRANS_CMD_UPDATE_ISE_EXIT) { // m_info_manager->UPDATE_ISE_EXIT(client_id); + } else if (cmd == ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE) { + KeyEvent key; + uint32 ret; + uint32 serial; + + if (m_recv_trans.get_data(key) && m_recv_trans.get_data(ret) && m_recv_trans.get_data(serial)) { + m_info_manager->process_key_event_done(key, ret, serial); + } else { + LOGW ("wrong format of transaction\n"); + } } else { LOGW ("unknow cmd: %d\n", cmd); } diff --git a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp index 8766b68..cb9bfda 100644 --- a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp +++ b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp @@ -1587,7 +1587,6 @@ isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx, if (!wsc_ctx) return; - Eina_Bool ret = EINA_FALSE; KeyEvent key(symcode, wsc_ctx->modifiers); bool ignore_key = filter_keys (keyname, SCIM_CONFIG_HOTKEYS_FRONTEND_IGNORE_KEY); @@ -1627,27 +1626,14 @@ isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx, } if (!ignore_key) { - ret = EINA_TRUE; if (!_focused_ic || !_focused_ic->impl || !_focused_ic->impl->is_on) { LOGD ("ic is off"); - ret = EINA_FALSE; } else { - uint32 _ret; - g_info_manager->process_key_event (key, _ret); - ret = (Eina_Bool)_ret; - } - - 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_ctx); - } + static uint32 _serial = 0; + g_info_manager->process_key_event (key, ++_serial); } - } - - if (ret == EINA_FALSE) { + } else { send_wl_key_event (wsc_ctx, key, false); } } @@ -2775,6 +2761,22 @@ public: wl_input_method_context_get_selection_text (ic->im_ctx, fd); } } + + 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 (ret == EINA_FALSE) { + if (key.is_key_press()) { + if (key.code == SCIM_KEY_space || + key.code == SCIM_KEY_KP_Space) + autoperiod_insert (ic); + } + } + + if (ret == EINA_FALSE) { + send_wl_key_event (ic, key, false); + } + } }; static scim::PanelAgentPointer instance; diff --git a/ism/src/isf_info_manager.cpp b/ism/src/isf_info_manager.cpp index 056df49..0ea1e21 100644 --- a/ism/src/isf_info_manager.cpp +++ b/ism/src/isf_info_manager.cpp @@ -1343,7 +1343,7 @@ public: m_should_shared_ise = should_shared_ise; } //SCIM_TRANS_CMD_PROCESS_KEY_EVENT - bool process_key_event (KeyEvent& key, _OUT_ uint32& result) { + bool process_key_event (KeyEvent& key, uint32 serial) { LOGD (""); HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid); @@ -1353,7 +1353,7 @@ public: uint32 ctx; get_focused_context (client, context); ctx = get_helper_ic (client, context); - return m_panel_agent_manager.process_key_event (it->second.id, ctx, m_current_helper_uuid, key, result); + return m_panel_agent_manager.process_key_event (it->second.id, ctx, m_current_helper_uuid, key, serial); } return false; @@ -3409,6 +3409,18 @@ client context helpers: %d, helpers uuid count: %d", // del_client (client); //} + void process_key_event_done (KeyEvent &key, uint32 ret, uint32 serial) { + LOGD (""); + int focused_client; + uint32 focused_context; + String focused_uuid = get_focused_context (focused_client, focused_context); + ClientInfo client_info = socket_get_client_info (focused_client); + + if (client_info.type == FRONTEND_CLIENT) { + m_panel_agent_manager.process_key_event_done (focused_client, focused_context, key, ret, serial); + } + } + void socket_reset_helper_input_context (const String& uuid, int client, uint32 context) { HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid); @@ -4037,9 +4049,9 @@ void InfoManager::hide_helper_ise (void) } //SCIM_TRANS_CMD_PROCESS_KEY_EVENT -bool InfoManager::process_key_event (KeyEvent& key, _OUT_ uint32& result) +bool InfoManager::process_key_event (KeyEvent& key, uint32 serial) { - return m_impl->process_key_event (key, result); + return m_impl->process_key_event (key, serial); } //ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY @@ -4683,6 +4695,13 @@ void InfoManager::socket_helper_send_private_command (int client, String command // m_impl->UPDATE_ISE_EXIT (client); //} +//ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE +void InfoManager::process_key_event_done (KeyEvent &key, uint32 ret, uint32 serial) +{ + m_impl->process_key_event_done (key, ret, serial); +} + + bool InfoManager::check_privilege_by_sockfd (int client_id, const String& privilege) { return m_impl->check_privilege_by_sockfd (client_id, privilege); } diff --git a/ism/src/isf_info_manager.h b/ism/src/isf_info_manager.h index b90fc43..9ae9022 100644 --- a/ism/src/isf_info_manager.h +++ b/ism/src/isf_info_manager.h @@ -582,7 +582,7 @@ public: void hide_helper_ise (void); //SCIM_TRANS_CMD_PROCESS_KEY_EVENT - bool process_key_event (KeyEvent& key, _OUT_ uint32& result); + bool process_key_event (KeyEvent& key, uint32 serial); //ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY void get_input_panel_geometry (int client_id, _OUT_ struct rectinfo& info); @@ -924,6 +924,10 @@ public: //ISM_TRANS_CMD_UPDATE_ISE_EXIT //void UPDATE_ISE_EXIT (int client); + + //ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE + void process_key_event_done (KeyEvent &key, uint32 ret, uint32 serial); + bool check_privilege_by_sockfd (int client_id, const String& privilege); void add_client (int client_id, uint32 key, ClientType type); diff --git a/ism/src/isf_panel_agent_base.cpp b/ism/src/isf_panel_agent_base.cpp index b86791c..150f13d 100644 --- a/ism/src/isf_panel_agent_base.cpp +++ b/ism/src/isf_panel_agent_base.cpp @@ -300,7 +300,7 @@ void PanelAgentBase::show_helper_option_window (int client, uint32 context, cons LOGW ("not implemented for %s", m_name.c_str ()); } -bool PanelAgentBase::process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, _OUT_ uint32& result) +bool PanelAgentBase::process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, uint32 serial) { LOGW ("not implemented for %s", m_name.c_str ()); return false; @@ -500,6 +500,12 @@ bool PanelAgentBase::process_input_device_event(int client, uint32 context, cons return false; } +void PanelAgentBase::process_key_event_done(int client, uint32 context, KeyEvent &key, uint32 ret, uint32 serial) +{ + LOGW("not implemented for %s", m_name.c_str()); +} + + } /* namespace scim */ /* diff --git a/ism/src/isf_panel_agent_base.h b/ism/src/isf_panel_agent_base.h index 5d51a79..6273bad 100644 --- a/ism/src/isf_panel_agent_base.h +++ b/ism/src/isf_panel_agent_base.h @@ -473,7 +473,7 @@ public: * * @return none. */ - virtual bool process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, _OUT_ uint32& result); + virtual bool process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, uint32 serial); /** * @brief get_helper_geometry. @@ -789,6 +789,15 @@ public: * @return none. */ virtual bool process_input_device_event(int client, uint32 context, const String& uuid, uint32 type, const char *data, size_t len, _OUT_ uint32& result); + + /** + * @brief process_key_event_done. + * + * @param + * + * @return none. + */ + virtual void process_key_event_done(int client, uint32 context, KeyEvent &key, uint32 ret, uint32 serial); }; /** @} */ diff --git a/ism/src/isf_panel_agent_manager.cpp b/ism/src/isf_panel_agent_manager.cpp index 03cdaff..e1e94c8 100644 --- a/ism/src/isf_panel_agent_manager.cpp +++ b/ism/src/isf_panel_agent_manager.cpp @@ -490,12 +490,12 @@ void PanelAgentManager::show_helper_option_window (int id, uint32 context_id, co _p->show_helper_option_window (id, context_id, uuid); } -bool PanelAgentManager::process_key_event (int id, uint32 context_id, const String& uuid, KeyEvent& key, _OUT_ uint32& result) +bool PanelAgentManager::process_key_event (int id, uint32 context_id, const String& uuid, KeyEvent& key, uint32 serial) { PanelAgentPointer _p = m_impl->get_panel_agent_by_id (id); if (!_p.null ()) - return _p->process_key_event (id, context_id, uuid, key, result); + return _p->process_key_event (id, context_id, uuid, key, serial); return false; } @@ -782,6 +782,15 @@ void PanelAgentManager::hide_helper_ise (int id, uint32 context) _p->hide_helper_ise (id, context); } +void PanelAgentManager::process_key_event_done(int id, uint32 context_id, KeyEvent &key, uint32 ret, uint32 serial) +{ + PanelAgentPointer _p = m_impl->get_panel_agent_by_id (id); + + if (!_p.null ()) + _p->process_key_event_done (id, context_id, key, ret, serial); +} + + } /* namespace scim */ diff --git a/ism/src/isf_panel_agent_manager.h b/ism/src/isf_panel_agent_manager.h index 40d32a0..540015c 100644 --- a/ism/src/isf_panel_agent_manager.h +++ b/ism/src/isf_panel_agent_manager.h @@ -306,7 +306,7 @@ public: void set_helper_bidi_direction (int client, uint32 context, const String& uuid, uint32& direction); void set_helper_caps_mode (int client, uint32 context, const String& uuid, uint32& mode); void show_helper_option_window (int client, uint32 context, const String& uuid); - bool process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, _OUT_ uint32& result); + bool process_key_event (int client, uint32 context, const String& uuid, KeyEvent& key, uint32 serial); bool get_helper_geometry (int client, uint32 context, String& uuid, _OUT_ struct rectinfo& info); void get_helper_imdata (int client, uint32 context, String& uuid, _OUT_ char** imdata, _OUT_ size_t& len); void get_helper_layout (int client, uint32 context, String& uuid, uint32& layout); @@ -342,6 +342,7 @@ public: void helper_attach_input_context_and_update_screen (int client, std::vector < std::pair >& helper_ic_index, uint32 current_screen); void hide_helper_ise (int id, uint32 context); bool process_input_device_event(int client, uint32 context, const String& uuid, uint32 type, const char *data, size_t len, _OUT_ uint32& result); + void process_key_event_done(int client, uint32 context, KeyEvent &key, uint32 ret, uint32 serial); }; /** @} */ diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp index 324116a..82fbab9 100644 --- a/ism/src/scim_helper.cpp +++ b/ism/src/scim_helper.cpp @@ -523,6 +523,19 @@ public: si->signal_connect_send_private_command ( slot (this, &HelperAgent::HelperAgentImpl::slot_send_private_command)); } +public: + void process_key_event_done(KeyEvent &key, uint32 ret, uint32 serial) { + if (socket_active.is_connected ()) { + send.clear (); + send.put_command (SCIM_TRANS_CMD_REQUEST); + send.put_data (magic_active); + send.put_command (ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE); + send.put_data (key); + send.put_data (ret); + send.put_data (serial); + send.write_to_socket (socket_active, magic_active); + } + } private: HelperAgentImpl () : magic (0), magic_active (0), timeout (-1), focused_ic ((uint32) -1) { } }; @@ -1043,7 +1056,8 @@ HelperAgent::filter_event () { KeyEvent key; uint32 ret = 0; - if (m_impl->recv.get_data (key)) + uint32 serial = 0; + if (m_impl->recv.get_data (key) && m_impl->recv.get_data (serial)) m_impl->signal_process_key_event(this, key, ret); else LOGW ("wrong format of transaction\n"); @@ -1053,10 +1067,8 @@ HelperAgent::filter_event () 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->send.clear (); - m_impl->send.put_command (SCIM_TRANS_CMD_REPLY); - m_impl->send.put_data (ret); - m_impl->send.write_to_socket (m_impl->socket); + + m_impl->process_key_event_done (key, ret, serial); break; } case ISM_TRANS_CMD_SET_LAYOUT: diff --git a/ism/src/scim_trans_commands.h b/ism/src/scim_trans_commands.h index 9511166..64482f4 100644 --- a/ism/src/scim_trans_commands.h +++ b/ism/src/scim_trans_commands.h @@ -682,6 +682,8 @@ const int ISM_TRANS_CMD_EXPAND_CANDIDATE = 1214; const int ISM_TRANS_CMD_CONTRACT_CANDIDATE = 1215; const int ISM_TRANS_CMD_UPDATE_ISE_EXIT = 1216; const int ISM_TRANS_CMD_SELECT_CANDIDATE = 1217; +const int ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE = 1218; + /* Panel to ISE */ const int ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_SHOW = 1251; -- 2.7.4