From e215bd722ec2093dd4f408549cb3aec6e6e56375 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 24 Jan 2017 20:17:35 +0900 Subject: [PATCH] Fix issue when focused_context is greater than 0x7FFF Since opensource SCIM generates helper_ic using the formula helper_ic = (uint32)(client&0xFFFF)|((context&0x7FFF)<<16); , if the context is greater than 0x7FFF the operator "=" is not appropriate for comparing two contexts properly. Thus added compare function for contexts and modified to use focused_context variable that is not being truncated by the helper_ic generation formula. But still, helper_ic related code seems to need a refinement. Change-Id: Iecf2c72788b7d3acebb4b119ad0fe4ea78a6b881 --- ism/src/isf_info_manager.cpp | 69 +++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/ism/src/isf_info_manager.cpp b/ism/src/isf_info_manager.cpp index 7b435dd..38ca94a 100644 --- a/ism/src/isf_info_manager.cpp +++ b/ism/src/isf_info_manager.cpp @@ -231,6 +231,18 @@ get_imengine_client_context (uint32 helper_ic, int& client, uint32& context) context = ((helper_ic >> 16) & 0x7FFF); } +static bool +clients_equal (int first, int second) +{ + return ((first & 0xFFFF) == (second & 0xFFFF)); +} + +static bool +contexts_equal (uint32 first, uint32 second) +{ + return ((first & 0x7FFF) == (second & 0x7FFF)); +} + //==================================== InfoManager =========================== class InfoManager::InfoManagerImpl { @@ -3285,6 +3297,11 @@ client context helpers: %d, helpers uuid count: %d", SCIM_DEBUG_MAIN (5) << "Target UUID = " << target_uuid << " Focused UUId = " << focused_uuid << "\nTarget Client = " << target_client << "\n"; if (client_info.type == FRONTEND_CLIENT) { + /* If the original context value is greater than 0x7FFF, the line below would not work properly + since the target_context acquired by get_imengnie_client_context() is always smaller than 0x7FFF. + But since the send_imengine_event() of scim_helper module will call IMEngine's + process_helper_event() function directly, instead of sending SEND_IMENGINE_EVENT message. + So we are not going to handle this kind of exceptional case for now. */ m_panel_agent_manager.process_helper_event (target_client, target_context, target_uuid, hiit->second.uuid, nest_trans); } } @@ -3311,12 +3328,18 @@ client context helpers: %d, helpers uuid count: %d", if (target_client == -1) { /* FIXUP: monitor 'Invalid Window' error */ LOGW ("focused target client is NULL"); - } else if (target_client == focused_client && target_context == focused_context && target_uuid == focused_uuid) { - ClientInfo client_info = socket_get_client_info (target_client); + } else if (target_uuid == focused_uuid && + clients_equal (target_client, focused_client) && + contexts_equal (target_context, focused_context)) { + ClientInfo client_info = socket_get_client_info (focused_client); if (client_info.type == FRONTEND_CLIENT) { - m_panel_agent_manager.socket_helper_key_event (target_client, target_context, cmd, key); + m_panel_agent_manager.socket_helper_key_event (focused_client, focused_context, cmd, key); } + } else { + LOGD ("[target_client : %d, focused_client : %d] => %d, [target_context : %u, focused_context : %u] => %d", + target_client, focused_client, clients_equal (target_client, focused_client), + target_context, focused_context, contexts_equal (target_context, focused_context)); } } } @@ -3357,13 +3380,13 @@ client context helpers: %d, helpers uuid count: %d", if (target_uuid.length () == 0) target_uuid = focused_uuid; - if (target_client == focused_client && - target_context == focused_context && - target_uuid == focused_uuid) { - ClientInfo client_info = socket_get_client_info (target_client); + if (target_uuid == focused_uuid && + clients_equal (target_client, focused_client) && + contexts_equal (target_context, focused_context)) { + ClientInfo client_info = socket_get_client_info (focused_client); if (client_info.type == FRONTEND_CLIENT) { - m_panel_agent_manager.commit_string (target_client, target_context, wstr); + m_panel_agent_manager.commit_string (focused_client, focused_context, wstr); } else { std::cerr << "target client is not existed!!!" << "\n"; } @@ -3448,13 +3471,13 @@ client context helpers: %d, helpers uuid count: %d", if (target_uuid.length () == 0) target_uuid = focused_uuid; - if (target_client == focused_client && - target_context == focused_context && - target_uuid == focused_uuid) { - ClientInfo client_info = socket_get_client_info (target_client); + if (target_uuid == focused_uuid && + clients_equal (target_client, focused_client) && + contexts_equal (target_context, focused_context)) { + ClientInfo client_info = socket_get_client_info (focused_client); if (client_info.type == FRONTEND_CLIENT) { - m_panel_agent_manager.show_preedit_string (target_client, target_context); + m_panel_agent_manager.show_preedit_string (focused_client, focused_context); } } } @@ -3477,13 +3500,13 @@ client context helpers: %d, helpers uuid count: %d", if (target_uuid.length () == 0) target_uuid = focused_uuid; - if (target_client == focused_client && - target_context == focused_context && - target_uuid == focused_uuid) { - ClientInfo client_info = socket_get_client_info (target_client); + if (target_uuid == focused_uuid && + clients_equal (target_client, focused_client) && + contexts_equal (target_context, focused_context)) { + ClientInfo client_info = socket_get_client_info (focused_client); if (client_info.type == FRONTEND_CLIENT) { - m_panel_agent_manager.hide_preedit_string (target_client, target_context); + m_panel_agent_manager.hide_preedit_string (focused_client, focused_context); } } } @@ -3507,13 +3530,13 @@ client context helpers: %d, helpers uuid count: %d", if (target_uuid.length () == 0) target_uuid = focused_uuid; - if (target_client == focused_client && - target_context == focused_context && - target_uuid == focused_uuid) { - ClientInfo client_info = socket_get_client_info (target_client); + if (target_uuid == focused_uuid && + clients_equal (target_client, focused_client) && + contexts_equal (target_context, focused_context)) { + ClientInfo client_info = socket_get_client_info (focused_client); if (client_info.type == FRONTEND_CLIENT) { - m_panel_agent_manager.update_preedit_string (target_client, target_context, preedit, commit, attrs, caret); + m_panel_agent_manager.update_preedit_string (focused_client, focused_context, preedit, commit, attrs, caret); } } } -- 2.7.4