Discard input keys that does not match with current ic value 44/17344/1
authorHaifeng Deng <haifeng.deng@samsung.com>
Mon, 3 Jun 2013 11:53:33 +0000 (19:53 +0800)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 6 Mar 2014 11:25:05 +0000 (20:25 +0900)
Change-Id: Ifd20d9b90f8b39a4daa3daf961c39d0bd2a72db4

ism/extras/efl_immodule/isf_imf_context.cpp
ism/src/scim_helper.cpp

index d5a1ef4..6b0ef12 100644 (file)
@@ -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
index 646d75a..730a360 100644 (file)
@@ -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);