Move context information from struct weescim to struct WSCContextISF 49/58849/2
authorLi Zhang <li2012.zhang@samsung.com>
Thu, 4 Feb 2016 05:35:33 +0000 (13:35 +0800)
committerLi Zhang <li2012.zhang@samsung.com>
Thu, 4 Feb 2016 05:39:19 +0000 (13:39 +0800)
Change-Id: I8d4a025b1711d6eca97a5575d6a45c52dda6c2da

ism/extras/efl_wsc/isf_wsc_context.cpp
ism/extras/efl_wsc/isf_wsc_context.h
ism/extras/efl_wsc/isf_wsc_control_ui.cpp
ism/extras/efl_wsc/isf_wsc_efl.cpp

index 04e72ce..9a8b49b 100644 (file)
@@ -339,7 +339,6 @@ static WSCContextISF                                   *_focused_ic
 static bool                                             _scim_initialized           = false;
 
 static int                                              _instance_count             = 0;
-static int                                              _context_count              = 0;
 
 static IMEngineFactoryPointer                           _fallback_factory;
 static IMEngineInstancePointer                          _fallback_instance;
@@ -552,7 +551,7 @@ check_space_symbol (Eina_Unicode uchar)
 }
 
 static void
-autoperiod_insert (WSCContextISF *ctx)
+autoperiod_insert (WSCContextISF *wsc_ctx)
 {
     char *plain_str = NULL;
     int cursor_pos = 0;
@@ -562,16 +561,16 @@ autoperiod_insert (WSCContextISF *ctx)
     if (autoperiod_allow == EINA_FALSE)
         return;
 
-    if (!ctx) return;
+    if (!wsc_ctx) return;
 
-    Ecore_IMF_Input_Panel_Layout layout = wsc_context_input_panel_layout_get (ctx->ctx);
+    Ecore_IMF_Input_Panel_Layout layout = wsc_context_input_panel_layout_get (wsc_ctx);
     if (layout != ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL)
         return;
 
     if ((ecore_time_get () - space_key_time) > DOUBLE_SPACE_INTERVAL)
         goto done;
 
-    wsc_context_surrounding_get (ctx->ctx, &plain_str, &cursor_pos);
+    wsc_context_surrounding_get (wsc_ctx, &plain_str, &cursor_pos);
     if (!plain_str) goto done;
 
     // Convert string from UTF-8 to unicode
@@ -582,7 +581,7 @@ autoperiod_insert (WSCContextISF *ctx)
 
     if (check_space_symbol (ustr[cursor_pos-1]) &&
         !(iswpunct (ustr[cursor_pos-2]) || check_space_symbol (ustr[cursor_pos-2]))) {
-        wsc_context_delete_surrounding (ctx->ctx, -1, 1);
+        wsc_context_delete_surrounding (wsc_ctx, -1, 1);
 
         if (input_lang == INPUT_LANG_OTHER) {
             fullstop_mark = strdup (".");
@@ -595,7 +594,7 @@ autoperiod_insert (WSCContextISF *ctx)
             fullstop_mark = strdup (utf8_wcstombs (wstr).c_str ());
         }
 
-        wsc_context_commit_string (ctx->ctx, fullstop_mark);
+        wsc_context_commit_string (wsc_ctx, fullstop_mark);
 
         if (fullstop_mark) {
             free (fullstop_mark);
@@ -609,7 +608,7 @@ done:
 }
 
 static Eina_Bool
-analyze_surrounding_text (WSCContextISF *ctx)
+analyze_surrounding_text (WSCContextISF *wsc_ctx)
 {
     char *plain_str = NULL;
     Eina_Unicode puncs[] = {'\n','.', '!', '?', 0x00BF /* ¿ */, 0x00A1 /* ¡ */,
@@ -623,8 +622,8 @@ analyze_surrounding_text (WSCContextISF *ctx)
     const int punc_num = sizeof (puncs) / sizeof (puncs[0]);
     WSCContextISF *context_scim;
 
-    if (!ctx) return EINA_FALSE;
-    context_scim = ctx;
+    if (!wsc_ctx) return EINA_FALSE;
+    context_scim = wsc_ctx;
     if (!context_scim || !context_scim->impl) return EINA_FALSE;
 
     switch (context_scim->impl->autocapital_type) {
@@ -642,7 +641,7 @@ analyze_surrounding_text (WSCContextISF *ctx)
     if (context_scim->impl->preedit_updating)
         return EINA_FALSE;
 
-    wsc_context_surrounding_get (ctx->ctx, &plain_str, &cursor_pos);
+    wsc_context_surrounding_get (wsc_ctx, &plain_str, &cursor_pos);
     if (!plain_str) goto done;
 
     if (cursor_pos == 0) {
@@ -708,33 +707,33 @@ done:
 }
 
 Eina_Bool
-caps_mode_check (WSCContextISF *ctx, Eina_Bool force, Eina_Bool noti)
+caps_mode_check (WSCContextISF *wsc_ctx, Eina_Bool force, Eina_Bool noti)
 {
     Eina_Bool uppercase;
     WSCContextISF *context_scim;
 
     if (get_keyboard_mode () == TOOLBAR_KEYBOARD_MODE) return EINA_FALSE;
 
-    if (!ctx) return EINA_FALSE;
-    context_scim = ctx;
+    if (!wsc_ctx) return EINA_FALSE;
+    context_scim = wsc_ctx;
 
     if (!context_scim || !context_scim->impl)
         return EINA_FALSE;
 
     if (context_scim->impl->next_shift_status == SHIFT_MODE_LOCK) return EINA_TRUE;
 
-    Ecore_IMF_Input_Panel_Layout layout = wsc_context_input_panel_layout_get (ctx->ctx);
+    Ecore_IMF_Input_Panel_Layout layout = wsc_context_input_panel_layout_get (wsc_ctx);
     if (layout != ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL)
         return EINA_FALSE;
 
     // Check autocapital type
-    if (wsc_context_input_panel_caps_lock_mode_get (ctx->ctx)) {
+    if (wsc_context_input_panel_caps_lock_mode_get (wsc_ctx)) {
         uppercase = EINA_TRUE;
     } else {
         if (autocap_allow == EINA_FALSE)
             return EINA_FALSE;
 
-        if (analyze_surrounding_text (ctx)) {
+        if (analyze_surrounding_text (wsc_ctx)) {
             uppercase = EINA_TRUE;
         } else {
             uppercase = EINA_FALSE;
@@ -744,12 +743,12 @@ caps_mode_check (WSCContextISF *ctx, Eina_Bool force, Eina_Bool noti)
     if (force) {
         context_scim->impl->next_shift_status = uppercase ? SHIFT_MODE_ON : SHIFT_MODE_OFF;
         if (noti)
-            isf_wsc_context_input_panel_caps_mode_set (ctx, uppercase);
+            isf_wsc_context_input_panel_caps_mode_set (wsc_ctx, uppercase);
     } else {
         if (context_scim->impl->next_shift_status != (uppercase ? SHIFT_MODE_ON : SHIFT_MODE_OFF)) {
             context_scim->impl->next_shift_status = uppercase ? SHIFT_MODE_ON : SHIFT_MODE_OFF;
             if (noti)
-                isf_wsc_context_input_panel_caps_mode_set (ctx, uppercase);
+                isf_wsc_context_input_panel_caps_mode_set (wsc_ctx, uppercase);
         }
     }
 
@@ -795,9 +794,9 @@ static void input_language_changed_cb (keynode_t *key, void* data)
     get_input_language ();
 }
 
-void context_scim_imdata_get (WSCContextISF *ctx, void* data, int* length)
+void context_scim_imdata_get (WSCContextISF *wsc_ctx, void* data, int* length)
 {
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
@@ -811,9 +810,9 @@ void context_scim_imdata_get (WSCContextISF *ctx, void* data, int* length)
 }
 
 void
-imengine_layout_set (WSCContextISF *ctx, Ecore_IMF_Input_Panel_Layout layout)
+imengine_layout_set (WSCContextISF *wsc_ctx, Ecore_IMF_Input_Panel_Layout layout)
 {
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim->impl->si && context_scim == _focused_ic) {
         _panel_client.prepare (context_scim->id);
@@ -837,24 +836,13 @@ insert_text (const char *text, uint32_t offset, const char *insert)
 }
 
 /* Public functions */
-WSCContextISF *
-isf_wsc_context_new (void)
+void
+isf_wsc_context_init (void)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
     int val;
 
-    WSCContextISF *context_scim = new WSCContextISF;
-    if (context_scim == NULL) {
-        std::cerr << "memory allocation failed in " << __FUNCTION__ << "\n";
-        return NULL;
-    }
-
-    if (_context_count == 0) {
-        _context_count = getpid () % 50000;
-    }
-    context_scim->id = _context_count++;
-
     if (!_scim_initialized) {
         ecore_wl_init (NULL);
         initialize ();
@@ -883,8 +871,6 @@ isf_wsc_context_new (void)
 
         vconf_notify_key_changed (VCONFKEY_ISF_INPUT_LANGUAGE, input_language_changed_cb, NULL);
     }
-
-    return context_scim;
 }
 
 void
@@ -906,11 +892,11 @@ isf_wsc_context_shutdown (void)
 }
 
 void
-isf_wsc_context_add (WSCContextISF *ctx)
+isf_wsc_context_add (WSCContextISF *wsc_ctx)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (!context_scim) return;
 
@@ -984,13 +970,13 @@ isf_wsc_context_add (WSCContextISF *ctx)
 }
 
 void
-isf_wsc_context_del (WSCContextISF *ctx)
+isf_wsc_context_del (WSCContextISF *wsc_ctx)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
     if (!_ic_list) return;
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim) {
         if (context_scim->id != _ic_list->id) {
@@ -1042,16 +1028,12 @@ isf_wsc_context_del (WSCContextISF *ctx)
     if (context_scim == _focused_ic)
         _focused_ic = 0;
 
-    if (context_scim) {
-        delete context_scim;
-        context_scim = 0;
-    }
 }
 
 void
-isf_wsc_context_focus_in (WSCContextISF *ctx)
+isf_wsc_context_focus_in (WSCContextISF *wsc_ctx)
 {
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (!context_scim)
         return;
@@ -1064,14 +1046,13 @@ isf_wsc_context_focus_in (WSCContextISF *ctx)
             return;
         }
         SCIM_DEBUG_FRONTEND(1) << "Focus out previous IC first: " << _focused_ic->id << "\n";
-        if (_focused_ic->ctx)
-            isf_wsc_context_focus_out (_focused_ic);
+        isf_wsc_context_focus_out (_focused_ic);
     }
 
     if (_change_keyboard_mode_by_focus_move) {
         //if h/w keyboard mode, keyboard mode will be changed to s/w mode when the entry get the focus.
         LOGD ("Keyboard mode is changed H/W->S/W because of focus_in.\n");
-        isf_wsc_context_set_keyboard_mode (ctx, TOOLBAR_HELPER_MODE);
+        isf_wsc_context_set_keyboard_mode (wsc_ctx, TOOLBAR_HELPER_MODE);
     }
 
     bool need_cap   = false;
@@ -1140,7 +1121,7 @@ isf_wsc_context_focus_in (WSCContextISF *ctx)
     //            _panel_client.hide_aux_string (context_scim->id);
     //            _panel_client.hide_lookup_table (context_scim->id);
                 context_scim->impl->si->focus_in ();
-                context_scim->impl->si->set_layout (wsc_context_input_panel_layout_get (ctx->ctx));
+                context_scim->impl->si->set_layout (wsc_context_input_panel_layout_get (wsc_ctx));
                 context_scim->impl->si->set_prediction_allow (context_scim->impl->prediction_allow);
                 if (context_scim->impl->imdata)
                     context_scim->impl->si->set_imdata ((const char *)context_scim->impl->imdata, context_scim->impl->imdata_size);
@@ -1150,19 +1131,19 @@ isf_wsc_context_focus_in (WSCContextISF *ctx)
 
             _panel_client.get_active_helper_option (&_active_helper_option);
             _panel_client.send ();
-            if (caps_mode_check (ctx, EINA_FALSE, EINA_TRUE) == EINA_FALSE) {
+            if (caps_mode_check (wsc_ctx, EINA_FALSE, EINA_TRUE) == EINA_FALSE) {
                 context_scim->impl->next_shift_status = 0;
             }
         }
     }
 
-    LOGD ("ctx : %p\n", ctx);
+    LOGD ("ctx : %p\n", wsc_ctx);
 }
 
 void
-isf_wsc_context_focus_out (WSCContextISF *ctx)
+isf_wsc_context_focus_out (WSCContextISF *wsc_ctx)
 {
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (!context_scim) return;
 
@@ -1170,12 +1151,12 @@ isf_wsc_context_focus_out (WSCContextISF *ctx)
 
     if (context_scim && context_scim->impl && context_scim == _focused_ic) {
 
-        LOGD ("ctx : %p\n", ctx);
+        LOGD ("ctx : %p\n", wsc_ctx);
 
         if (context_scim->impl->need_commit_preedit) {
             _hide_preedit_string (context_scim->id, false);
 
-            wsc_context_commit_preedit_string (context_scim->ctx);
+            wsc_context_commit_preedit_string (context_scim);
             _panel_client.prepare (context_scim->id);
             _panel_client.reset_input_context (context_scim->id);
             _panel_client.send ();
@@ -1199,11 +1180,11 @@ isf_wsc_context_focus_out (WSCContextISF *ctx)
 }
 
 void
-isf_wsc_context_reset (WSCContextISF *ctx)
+isf_wsc_context_reset (WSCContextISF *wsc_ctx)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim == _focused_ic) {
         if (context_scim->impl->si) {
@@ -1215,24 +1196,24 @@ isf_wsc_context_reset (WSCContextISF *ctx)
 
         if (context_scim->impl->need_commit_preedit) {
             _hide_preedit_string (context_scim->id, false);
-            wsc_context_commit_preedit_string (context_scim->ctx);
+            wsc_context_commit_preedit_string (context_scim);
         }
     }
 }
 
 void
-isf_wsc_context_cursor_position_set (WSCContextISF *ctx, int cursor_pos)
+isf_wsc_context_cursor_position_set (WSCContextISF *wsc_ctx, int cursor_pos)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim == _focused_ic) {
         if (context_scim->impl->cursor_pos != cursor_pos) {
-            LOGD ("ctx : %p, cursor pos : %d\n", ctx, cursor_pos);
+            LOGD ("ctx : %p, cursor pos : %d\n", wsc_ctx, cursor_pos);
             context_scim->impl->cursor_pos = cursor_pos;
 
-            caps_mode_check (ctx, EINA_FALSE, EINA_TRUE);
+            caps_mode_check (wsc_ctx, EINA_FALSE, EINA_TRUE);
 
             if (context_scim->impl->preedit_updating)
                 return;
@@ -1248,11 +1229,11 @@ isf_wsc_context_cursor_position_set (WSCContextISF *ctx, int cursor_pos)
 }
 
 void
-isf_wsc_context_preedit_string_get (WSCContextISF *ctx, char** str, int *cursor_pos)
+isf_wsc_context_preedit_string_get (WSCContextISF *wsc_ctx, char** str, int *cursor_pos)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim->impl->is_on) {
         String mbs = utf8_wcstombs (context_scim->impl->preedit_string);
@@ -1280,24 +1261,24 @@ isf_wsc_context_preedit_string_get (WSCContextISF *ctx, char** str, int *cursor_
 }
 
 void
-isf_wsc_context_prediction_allow_set (WSCContextISF* ctx, Eina_Bool prediction)
+isf_wsc_context_prediction_allow_set (WSCContextISF* wsc_ctx, Eina_Bool prediction)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " = " << (prediction == EINA_TRUE ? "true" : "false") << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim->impl->prediction_allow != prediction) {
         context_scim->impl->prediction_allow = prediction;
-        set_prediction_allow (ctx, prediction);
+        set_prediction_allow (wsc_ctx, prediction);
     }
 }
 
 Eina_Bool
-isf_wsc_context_prediction_allow_get (WSCContextISF* ctx)
+isf_wsc_context_prediction_allow_get (WSCContextISF* wsc_ctx)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     Eina_Bool ret = EINA_FALSE;
     if (context_scim && context_scim->impl) {
@@ -1309,17 +1290,17 @@ isf_wsc_context_prediction_allow_get (WSCContextISF* ctx)
 }
 
 void
-isf_wsc_context_autocapital_type_set (WSCContextISF* ctx, Ecore_IMF_Autocapital_Type autocapital_type)
+isf_wsc_context_autocapital_type_set (WSCContextISF* wsc_ctx, Ecore_IMF_Autocapital_Type autocapital_type)
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " = " << autocapital_type << "...\n";
 
-    WSCContextISF *context_scim = ctx;
+    WSCContextISF *context_scim = wsc_ctx;
 
     if (context_scim && context_scim->impl && context_scim->impl->autocapital_type != autocapital_type) {
         context_scim->impl->autocapital_type = autocapital_type;
 
         if (context_scim->impl->si && context_scim == _focused_ic) {
-            LOGD ("ctx : %p. set autocapital type : %d\n", ctx, autocapital_type);
+            LOGD ("ctx : %p. set autocapital type : %d\n", wsc_ctx, autocapital_type);
             _panel_client.prepare (context_scim->id);
             context_scim->impl->si->set_autocapital_type (autocapital_type);
             _panel_client.send ();
@@ -1327,6 +1308,7 @@ isf_wsc_context_autocapital_type_set (WSCContextISF* ctx, Ecore_IMF_Autocapital_
     }
 }
 
+#ifdef _TV
 static
 bool is_number_key(const char *str)
 {
@@ -1344,9 +1326,10 @@ bool is_number_key(const char *str)
     else
         return true;
 }
+#endif
 
 void
-isf_wsc_context_filter_key_event (struct weescim *wsc,
+isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx,
                                   uint32_t serial,
                                   uint32_t timestamp, uint32_t keycode, uint32_t symcode,
                                   char *keyname,
@@ -1355,10 +1338,10 @@ isf_wsc_context_filter_key_event (struct weescim *wsc,
 {
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
-    if (!wsc) return;
+    if (!wsc_ctx) return;
 
     Eina_Bool ret = EINA_FALSE;
-    KeyEvent key(symcode, wsc->modifiers);
+    KeyEvent key(symcode, wsc_ctx->modifiers);
     bool ignore_key = filter_keys (keyname, SCIM_CONFIG_HOTKEYS_FRONTEND_IGNORE_KEY);
 
     if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
@@ -1390,7 +1373,7 @@ isf_wsc_context_filter_key_event (struct weescim *wsc,
                 && key.code != 0xFF69) {
                 /* XF86back, Cancel (Power + Volume down) key */
 #endif
-                isf_wsc_context_set_keyboard_mode (wsc->wsc_ctx, TOOLBAR_KEYBOARD_MODE);
+                isf_wsc_context_set_keyboard_mode (wsc_ctx, TOOLBAR_KEYBOARD_MODE);
                 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\n", _active_helper_option);
             }
@@ -1398,10 +1381,10 @@ isf_wsc_context_filter_key_event (struct weescim *wsc,
     }
 
     if (!ignore_key) {
-        _panel_client.prepare (wsc->wsc_ctx->id);
+        _panel_client.prepare (wsc_ctx->id);
 
         ret = EINA_TRUE;
-        if (!filter_hotkeys (wsc->wsc_ctx, key)) {
+        if (!filter_hotkeys (wsc_ctx, key)) {
             if (!_focused_ic || !_focused_ic->impl || !_focused_ic->impl->is_on) {
                 ret = EINA_FALSE;
 #ifdef _TV
@@ -1438,7 +1421,7 @@ isf_wsc_context_filter_key_event (struct weescim *wsc,
                 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
                     if (key.code == SCIM_KEY_space ||
                         key.code == SCIM_KEY_KP_Space)
-                        autoperiod_insert (wsc->wsc_ctx);
+                        autoperiod_insert (wsc_ctx);
                 }
             }
         }
@@ -1446,93 +1429,93 @@ isf_wsc_context_filter_key_event (struct weescim *wsc,
     }
 
     if (ret == EINA_FALSE) {
-        send_wl_key_event (wsc->wsc_ctx, key, false);
+        send_wl_key_event (wsc_ctx, key, false);
     }
 }
 
 static void
-wsc_commit_preedit (weescim *ctx)
+wsc_commit_preedit (WSCContextISF* wsc_ctx)
 {
     char *surrounding_text;
 
-    if (!ctx || !ctx->preedit_str ||
-        strlen (ctx->preedit_str) == 0)
+    if (!wsc_ctx || !wsc_ctx->preedit_str ||
+        strlen (wsc_ctx->preedit_str) == 0)
         return;
 
-    wl_input_method_context_cursor_position (ctx->im_ctx,
+    wl_input_method_context_cursor_position (wsc_ctx->im_ctx,
                                              0, 0);
 
-    wl_input_method_context_commit_string (ctx->im_ctx,
-                                           ctx->serial,
-                                           ctx->preedit_str);
+    wl_input_method_context_commit_string (wsc_ctx->im_ctx,
+                                           wsc_ctx->serial,
+                                           wsc_ctx->preedit_str);
 
-    if (ctx->surrounding_text) {
-        surrounding_text = insert_text (ctx->surrounding_text,
-                                        ctx->surrounding_cursor,
-                                        ctx->preedit_str);
+    if (wsc_ctx->surrounding_text) {
+        surrounding_text = insert_text (wsc_ctx->surrounding_text,
+                                        wsc_ctx->surrounding_cursor,
+                                        wsc_ctx->preedit_str);
 
-        free (ctx->surrounding_text);
-        ctx->surrounding_text = surrounding_text;
-        ctx->surrounding_cursor += strlen (ctx->preedit_str);
+        free (wsc_ctx->surrounding_text);
+        wsc_ctx->surrounding_text = surrounding_text;
+        wsc_ctx->surrounding_cursor += strlen (wsc_ctx->preedit_str);
     } else {
-        ctx->surrounding_text = strdup (ctx->preedit_str);
-        ctx->surrounding_cursor = strlen (ctx->preedit_str);
+        wsc_ctx->surrounding_text = strdup (wsc_ctx->preedit_str);
+        wsc_ctx->surrounding_cursor = strlen (wsc_ctx->preedit_str);
     }
 
-    if (ctx->preedit_str)
-        free (ctx->preedit_str);
+    if (wsc_ctx->preedit_str)
+        free (wsc_ctx->preedit_str);
 
-    ctx->preedit_str = strdup ("");
+    wsc_ctx->preedit_str = strdup ("");
 }
 
 static void
-wsc_send_preedit (weescim *ctx, int32_t cursor)
+wsc_send_preedit (WSCContextISF* wsc_ctx, int32_t cursor)
 {
-    if (!ctx) return;
+    if (!wsc_ctx) return;
 
-    uint32_t index = strlen (ctx->preedit_str);
+    uint32_t index = strlen (wsc_ctx->preedit_str);
 
-    if (ctx->preedit_style)
-        wl_input_method_context_preedit_styling (ctx->im_ctx,
+    if (wsc_ctx->preedit_style)
+        wl_input_method_context_preedit_styling (wsc_ctx->im_ctx,
                                                  0,
-                                                 strlen (ctx->preedit_str),
-                                                 ctx->preedit_style);
+                                                 strlen (wsc_ctx->preedit_str),
+                                                 wsc_ctx->preedit_style);
     if (cursor > 0)
         index = cursor;
 
-    wl_input_method_context_preedit_cursor (ctx->im_ctx, index);
-    wl_input_method_context_preedit_string (ctx->im_ctx,
-                                            ctx->serial,
-                                            ctx->preedit_str,
-                                            ctx->preedit_str);
+    wl_input_method_context_preedit_cursor (wsc_ctx->im_ctx, index);
+    wl_input_method_context_preedit_string (wsc_ctx->im_ctx,
+                                            wsc_ctx->serial,
+                                            wsc_ctx->preedit_str,
+                                            wsc_ctx->preedit_str);
 }
 
-bool wsc_context_surrounding_get (weescim *ctx, char **text, int *cursor_pos)
+bool wsc_context_surrounding_get (WSCContextISF *wsc_ctx, char **text, int *cursor_pos)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return false;
 
     if (text) {
-        if (ctx->surrounding_text)
-            *text = strdup (ctx->surrounding_text);
+        if (wsc_ctx->surrounding_text)
+            *text = strdup (wsc_ctx->surrounding_text);
         else
             *text = strdup ("");
     }
 
     if (cursor_pos)
-        *cursor_pos = ctx->surrounding_cursor;
+        *cursor_pos = wsc_ctx->surrounding_cursor;
 
     return true;
 }
 
-Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get (weescim *ctx)
+Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get (WSCContextISF *wsc_ctx)
 {
     Ecore_IMF_Input_Panel_Layout layout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return layout;
 
-    switch (ctx->content_purpose) {
+    switch (wsc_ctx->content_purpose) {
         case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
         case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS_SIGNED:
         case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS_DECIMAL:
@@ -1577,14 +1560,14 @@ Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get (weescim *ctx)
     return layout;
 }
 
-int wsc_context_input_panel_layout_variation_get (weescim *ctx)
+int wsc_context_input_panel_layout_variation_get (WSCContextISF *wsc_ctx)
 {
     int layout_variation = 0;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return layout_variation;
 
-    switch (ctx->content_purpose) {
+    switch (wsc_ctx->content_purpose) {
         case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
             layout_variation = ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY_VARIATION_NORMAL;
             break;
@@ -1620,18 +1603,18 @@ int wsc_context_input_panel_layout_variation_get (weescim *ctx)
     return layout_variation;
 }
 
-Ecore_IMF_Autocapital_Type wsc_context_autocapital_type_get (weescim *ctx)
+Ecore_IMF_Autocapital_Type wsc_context_autocapital_type_get (WSCContextISF *wsc_ctx)
 {
     Ecore_IMF_Autocapital_Type autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return autocapital_type;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION)
         autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE;
-    else if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_WORD_CAPITALIZATION)
+    else if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_WORD_CAPITALIZATION)
         autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_WORD;
-    else if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE)
+    else if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE)
         autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_ALLCHARACTER;
     else
         autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
@@ -1639,25 +1622,25 @@ Ecore_IMF_Autocapital_Type wsc_context_autocapital_type_get (weescim *ctx)
     return autocapital_type;
 }
 
-bool wsc_context_input_panel_caps_lock_mode_get (weescim *ctx)
+bool wsc_context_input_panel_caps_lock_mode_get (WSCContextISF *wsc_ctx)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return false;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE)
         return true;
 
     return false;
 }
 
-Ecore_IMF_Input_Panel_Lang wsc_context_input_panel_language_get (weescim *ctx)
+Ecore_IMF_Input_Panel_Lang wsc_context_input_panel_language_get (WSCContextISF *wsc_ctx)
 {
     Ecore_IMF_Input_Panel_Lang language = ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return language;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_LATIN)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_LATIN)
         language = ECORE_IMF_INPUT_PANEL_LANG_ALPHABET;
     else
         language = ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
@@ -1665,30 +1648,30 @@ Ecore_IMF_Input_Panel_Lang wsc_context_input_panel_language_get (weescim *ctx)
     return language;
 }
 
-bool wsc_context_input_panel_password_mode_get (weescim *ctx)
+bool wsc_context_input_panel_password_mode_get (WSCContextISF *wsc_ctx)
 {
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_PASSWORD)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_PASSWORD)
         return true;
 
-    if (wsc_context_input_panel_layout_get (ctx) == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD)
+    if (wsc_context_input_panel_layout_get (wsc_ctx) == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD)
         return true;
 
     return false;
 }
 
-Ecore_IMF_Input_Hints wsc_context_input_hint_get (weescim *ctx)
+Ecore_IMF_Input_Hints wsc_context_input_hint_get (WSCContextISF *wsc_ctx)
 {
     int input_hint = ECORE_IMF_INPUT_HINT_NONE;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return (Ecore_IMF_Input_Hints)input_hint;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA)
         input_hint |= ECORE_IMF_INPUT_HINT_SENSITIVE_DATA;
     else
         input_hint &= ~ECORE_IMF_INPUT_HINT_SENSITIVE_DATA;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION)
         input_hint |= ECORE_IMF_INPUT_HINT_AUTO_COMPLETE;
     else
         input_hint &= ~ECORE_IMF_INPUT_HINT_AUTO_COMPLETE;
@@ -1696,96 +1679,94 @@ Ecore_IMF_Input_Hints wsc_context_input_hint_get (weescim *ctx)
     return (Ecore_IMF_Input_Hints)input_hint;
 }
 
-Eina_Bool wsc_context_prediction_allow_get (weescim *ctx)
+Eina_Bool wsc_context_prediction_allow_get (WSCContextISF *wsc_ctx)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return EINA_FALSE;
 
-    if (ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION)
+    if (wsc_ctx->content_hint & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION)
         return EINA_TRUE;
     else
         return EINA_FALSE;
 }
 
-void wsc_context_delete_surrounding (weescim *ctx, int offset, int len)
+void wsc_context_delete_surrounding (WSCContextISF *wsc_ctx, int offset, int len)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return;
 
-    wl_input_method_context_delete_surrounding_text (ctx->im_ctx, offset, len);
+    wl_input_method_context_delete_surrounding_text (wsc_ctx->im_ctx, offset, len);
 }
 
-void wsc_context_set_selection (weescim *ctx, int start, int end)
+void wsc_context_set_selection (WSCContextISF *wsc_ctx, int start, int end)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return;
 
-    wl_input_method_context_selection_region (ctx->im_ctx, ctx->serial, start, end);
+    wl_input_method_context_selection_region (wsc_ctx->im_ctx, wsc_ctx->serial, start, end);
 }
 
-void wsc_context_commit_string (weescim *ctx, const char *str)
+void wsc_context_commit_string (WSCContextISF *wsc_ctx, const char *str)
 {
-    if (!ctx)
+    if (!wsc_ctx)
         return;
 
-    if (ctx->preedit_str) {
-        free (ctx->preedit_str);
-        ctx->preedit_str = NULL;
+    if (wsc_ctx->preedit_str) {
+        free (wsc_ctx->preedit_str);
+        wsc_ctx->preedit_str = NULL;
     }
 
-    ctx->preedit_str = strdup (str);
-    wsc_commit_preedit (ctx);
+    wsc_ctx->preedit_str = strdup (str);
+    wsc_commit_preedit (wsc_ctx);
 }
 
-void wsc_context_commit_preedit_string (weescim *ctx)
+void wsc_context_commit_preedit_string (WSCContextISF *wsc_ctx)
 {
     char *preedit_str = NULL;
     int cursor_pos = 0;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return;
 
-    if (ctx->wsc_ctx)
-        isf_wsc_context_preedit_string_get (ctx->wsc_ctx, &preedit_str, &cursor_pos);
+    isf_wsc_context_preedit_string_get (wsc_ctx, &preedit_str, &cursor_pos);
 
-    if (ctx->preedit_str) {
-        free (ctx->preedit_str);
-        ctx->preedit_str = NULL;
+    if (wsc_ctx->preedit_str) {
+        free (wsc_ctx->preedit_str);
+        wsc_ctx->preedit_str = NULL;
     }
 
-    ctx->preedit_str = preedit_str;
-    wsc_commit_preedit (ctx);
+    wsc_ctx->preedit_str = preedit_str;
+    wsc_commit_preedit (wsc_ctx);
 }
 
-void wsc_context_send_preedit_string (weescim *ctx)
+void wsc_context_send_preedit_string (WSCContextISF *wsc_ctx)
 {
     char *preedit_str = NULL;
     int cursor_pos = 0;
 
-    if (!ctx)
+    if (!wsc_ctx)
         return;
 
-    if (ctx->wsc_ctx)
-        isf_wsc_context_preedit_string_get (ctx->wsc_ctx, &preedit_str, &cursor_pos);
+    isf_wsc_context_preedit_string_get (wsc_ctx, &preedit_str, &cursor_pos);
 
-    if (ctx->preedit_str) {
-        free (ctx->preedit_str);
-        ctx->preedit_str = NULL;
+    if (wsc_ctx->preedit_str) {
+        free (wsc_ctx->preedit_str);
+        wsc_ctx->preedit_str = NULL;
     }
 
-    ctx->preedit_str = preedit_str;
-    wsc_send_preedit (ctx, cursor_pos);
+    wsc_ctx->preedit_str = preedit_str;
+    wsc_send_preedit (wsc_ctx, cursor_pos);
 }
 
-void wsc_context_send_key (weescim *ctx, uint32_t keysym, uint32_t modifiers, uint32_t time, bool press)
+void wsc_context_send_key (WSCContextISF *wsc_ctx, uint32_t keysym, uint32_t modifiers, uint32_t time, bool press)
 {
-    if (!ctx || !ctx->im_ctx)
+    if (!wsc_ctx)
         return;
 
-    ctx->modifiers = modifiers;
+    wsc_ctx->modifiers = modifiers;
 
-    wl_input_method_context_keysym (ctx->im_ctx, ctx->serial, time,
-            keysym, press ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED, ctx->modifiers);
+    wl_input_method_context_keysym (wsc_ctx->im_ctx, wsc_ctx->serial, time,
+            keysym, press ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED, wsc_ctx->modifiers);
 }
 
 static void
@@ -2336,7 +2317,7 @@ panel_slot_process_key_event (int context, const KeyEvent &key)
 
     KeyEvent _key = key;
     if (key.is_key_press () &&
-        wsc_context_input_panel_layout_get (ic->ctx) == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL) {
+        wsc_context_input_panel_layout_get (ic) == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL) {
         if (key.code == SHIFT_MODE_OFF ||
             key.code == SHIFT_MODE_ON ||
             key.code == SHIFT_MODE_LOCK) {
@@ -2366,7 +2347,7 @@ panel_slot_process_key_event (int context, const KeyEvent &key)
                     snprintf (string, sizeof (string), "%c", code);
 
                     if (strlen (string) != 0) {
-                        wsc_context_commit_string(ic->ctx, string);
+                        wsc_context_commit_string(ic, string);
                         caps_mode_check (ic, EINA_FALSE, EINA_TRUE);
                     }
                 } else {
@@ -2397,7 +2378,7 @@ panel_slot_commit_string (int context, const WideString &wstr)
 
         if (ic->impl->need_commit_preedit)
             _hide_preedit_string (ic->id, false);
-        wsc_context_commit_string (ic->ctx, utf8_wcstombs (wstr).c_str ());
+        wsc_context_commit_string (ic, utf8_wcstombs (wstr).c_str ());
     }
 }
 
@@ -2467,7 +2448,7 @@ panel_slot_reset_keyboard_ise (int context)
             _hide_preedit_string (ic->id, false);
 
             if (wstr.length ()) {
-                wsc_context_commit_string (ic->ctx, utf8_wcstombs (wstr).c_str ());
+                wsc_context_commit_string (ic, utf8_wcstombs (wstr).c_str ());
                 if (!check_valid_ic (ic))
                     return;
             }
@@ -2544,7 +2525,7 @@ _hide_preedit_string (int context, bool update_preedit)
                     ic->impl->need_commit_preedit = false;
                 }
             }
-            wsc_context_send_preedit_string (ic->ctx);
+            wsc_context_send_preedit_string (ic);
         } else {
             _panel_client.prepare (ic->id);
             _panel_client.hide_preedit_string (ic->id);
@@ -2594,7 +2575,7 @@ panel_slot_update_preedit_string (int context,
                 ic->impl->preedit_updating = true;
                 if (check_valid_ic (ic))
                     ic->impl->preedit_updating = false;
-                wsc_context_send_preedit_string (ic->ctx);
+                wsc_context_send_preedit_string (ic);
             } else {
                 _panel_client.prepare (ic->id);
                 _panel_client.update_preedit_string (ic->id, str, attrs, caret);
@@ -3128,7 +3109,7 @@ static void send_wl_key_event (WSCContextISF *ic, const KeyEvent &key, bool fake
     sym = _keyname_to_keysym (key.code, &modifiers);
 
     if (ic)
-        wsc_context_send_key (ic->ctx, key.code, modifiers, time, key.is_key_press ());
+        wsc_context_send_key (ic, key.code, modifiers, time, key.is_key_press ());
 }
 
 static void
@@ -3262,7 +3243,7 @@ slot_hide_preedit_string (IMEngineInstanceBase *si)
                 if (check_valid_ic (ic))
                     ic->impl->preedit_started = false;
             }
-            wsc_context_send_preedit_string (ic->ctx);
+            wsc_context_send_preedit_string (ic);
         } else {
             _panel_client.hide_preedit_string (ic->id);
         }
@@ -3340,7 +3321,7 @@ slot_update_preedit_string (IMEngineInstanceBase *si,
             ic->impl->preedit_updating = true;
             if (check_valid_ic (ic))
                 ic->impl->preedit_updating = false;
-            wsc_context_send_preedit_string (ic->ctx);
+            wsc_context_send_preedit_string (ic);
         } else {
             _panel_client.update_preedit_string (ic->id, str, attrs, caret);
         }
@@ -3368,14 +3349,14 @@ slot_commit_string (IMEngineInstanceBase *si,
 
     WSCContextISF *ic = static_cast<WSCContextISF *> (si->get_frontend_data ());
 
-    if (ic && ic->ctx) {
+    if (ic) {
         if (utf8_wcstombs (str) == String (" ") || utf8_wcstombs (str) == String (" "))
             autoperiod_insert (ic);
 
         Eina_Bool auto_capitalized = EINA_FALSE;
 
         if (ic->impl) {
-            if (wsc_context_input_panel_layout_get (ic->ctx) == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL &&
+            if (wsc_context_input_panel_layout_get (ic) == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL &&
                 ic->impl->shift_mode_enabled &&
                 ic->impl->autocapital_type != ECORE_IMF_AUTOCAPITAL_TYPE_NONE &&
                 get_keyboard_mode () == TOOLBAR_HELPER_MODE) {
@@ -3409,14 +3390,14 @@ slot_commit_string (IMEngineInstanceBase *si,
                             converted[0] += 32;
                     }
 
-                    wsc_context_commit_string (ic->ctx, converted);
+                    wsc_context_commit_string (ic, converted);
                     auto_capitalized = EINA_TRUE;
                 }
             }
         }
 
         if (!auto_capitalized) {
-            wsc_context_commit_string (ic->ctx, utf8_wcstombs (str).c_str ());
+            wsc_context_commit_string (ic, utf8_wcstombs (str).c_str ());
         }
     }
 }
@@ -3533,7 +3514,7 @@ slot_get_surrounding_text (IMEngineInstanceBase *si,
     if (ic && ic->impl && _focused_ic == ic) {
         char *surrounding = NULL;
         int   cursor_index;
-        if (wsc_context_surrounding_get (_focused_ic->ctx, &surrounding, &cursor_index)) {
+        if (wsc_context_surrounding_get (_focused_ic, &surrounding, &cursor_index)) {
             SCIM_DEBUG_FRONTEND(2) << "Surrounding text: " << surrounding <<"\n";
             SCIM_DEBUG_FRONTEND(2) << "Cursor Index    : " << cursor_index <<"\n";
 
@@ -3581,7 +3562,7 @@ slot_delete_surrounding_text (IMEngineInstanceBase *si,
     WSCContextISF *ic = static_cast<WSCContextISF *> (si->get_frontend_data ());
 
     if (ic && _focused_ic == ic) {
-        wsc_context_delete_surrounding (_focused_ic->ctx, offset, len);
+        wsc_context_delete_surrounding (_focused_ic, offset, len);
         return true;
     }
     return false;
@@ -3597,7 +3578,7 @@ slot_set_selection (IMEngineInstanceBase *si,
     WSCContextISF *ic = static_cast<WSCContextISF *> (si->get_frontend_data ());
 
     if (_focused_ic && _focused_ic == ic) {
-        wsc_context_set_selection (_focused_ic->ctx, start, end);
+        wsc_context_set_selection (_focused_ic, start, end);
         return true;
     }
     return false;
@@ -3645,8 +3626,8 @@ slot_send_private_command (IMEngineInstanceBase *si,
     WSCContextISF *ic = static_cast<WSCContextISF *> (si->get_frontend_data ());
 
     if (_focused_ic && _focused_ic == ic) {
-        if (_focused_ic->ctx && _focused_ic->ctx->im_ctx)
-            wl_input_method_context_private_command (_focused_ic->ctx->im_ctx, _focused_ic->ctx->serial, command.c_str ());
+        if (_focused_ic->im_ctx)
+            wl_input_method_context_private_command (_focused_ic->im_ctx, _focused_ic->serial, command.c_str ());
     }
 }
 
@@ -3687,6 +3668,6 @@ fallback_commit_string_cb (IMEngineInstanceBase  *si,
     SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
 
     if (_focused_ic && _focused_ic->impl) {
-        wsc_context_commit_string (_focused_ic->ctx, utf8_wcstombs (str).c_str ());
+        wsc_context_commit_string (_focused_ic, utf8_wcstombs (str).c_str ());
     }
 }
index 174d02e..0f4b6d2 100644 (file)
 #include <Ecore.h>
 #include <Ecore_IMF.h>
 #include <dlog.h>
+#include "scim_stl_map.h"
+
+#if SCIM_USE_STL_EXT_HASH_MAP
+    typedef __gnu_cxx::hash_map <uint32_t, uint32_t, __gnu_cxx::hash <uint32_t> >   KeycodeRepository;
+#elif SCIM_USE_STL_HASH_MAP
+    typedef std::hash_map <uint32_t, ClientInfo, std::hash <uint32_t> >             KeycodeRepository;
+#else
+    typedef std::map <uint32_t, uint32_t>                                           KeycodeRepository;
+#endif
 
 struct weescim;
 
@@ -39,7 +48,7 @@ const double WILL_SHOW_TIMER_INTERVAL = 5.0;
 typedef struct _WSCContextISF      WSCContextISF;
 typedef struct _WSCContextISFImpl  WSCContextISFImpl;
 
-typedef void (*keyboard_input_key_handler_t)(struct weescim *wsc,
+typedef void (*keyboard_input_key_handler_t)(WSCContextISF *wsc_ctx,
                                              uint32_t serial,
                                              uint32_t time, uint32_t keycode, uint32_t symcode,
                                              char *keyname,
@@ -48,9 +57,16 @@ typedef void (*keyboard_input_key_handler_t)(struct weescim *wsc,
 struct weescim
 {
     struct wl_input_method *im;
-    struct wl_input_method_context *im_ctx;
     struct wl_seat *seat;
+
+    WSCContextISF *wsc_ctx;
+};
+
+struct _WSCContextISF {
+    weescim *ctx;
+
     struct wl_keyboard *keyboard;
+    struct wl_input_method_context *im_ctx;
 
     struct xkb_context *xkb_context;
 
@@ -62,8 +78,11 @@ struct weescim
     xkb_mod_mask_t alt_mask;
     xkb_mod_mask_t shift_mask;
 
+    KeycodeRepository _keysym2keycode;
+
     keyboard_input_key_handler_t key_handler;
 
+
     char *surrounding_text;
     char *preedit_str;
     char *language;
@@ -77,15 +96,8 @@ struct weescim
     uint32_t return_key_type;
 
     Eina_Bool context_changed;
-    Eina_Bool hw_kbd;
     Eina_Bool return_key_disabled;
 
-    WSCContextISF *wsc_ctx;
-};
-
-struct _WSCContextISF {
-    weescim *ctx;
-
     WSCContextISFImpl *impl;
 
     int id; /* Input Context id*/
@@ -94,45 +106,45 @@ struct _WSCContextISF {
 
 void get_language(char **language);
 int get_panel_client_id ();
-Eina_Bool caps_mode_check (WSCContextISF *ctx, Eina_Bool force, Eina_Bool noti);
+Eina_Bool caps_mode_check (WSCContextISF *wsc_ctx, Eina_Bool force, Eina_Bool noti);
 
 WSCContextISF *get_focused_ic ();
 
-void context_scim_imdata_get (WSCContextISF *ctx, void* data, int* length);
-void imengine_layout_set (WSCContextISF *ctx, Ecore_IMF_Input_Panel_Layout layout);
-
-void isf_wsc_context_add (WSCContextISF *ctx);
-void isf_wsc_context_del (WSCContextISF *ctx);
-void isf_wsc_context_focus_in (WSCContextISF *ctx);
-void isf_wsc_context_focus_out (WSCContextISF *ctx);
-void isf_wsc_context_reset (WSCContextISF *ctx);
-void isf_wsc_context_cursor_position_set (WSCContextISF *ctx, int cursor_pos);
-void isf_wsc_context_preedit_string_get (WSCContextISF *ctx, char** str, int *cursor_pos);
-void isf_wsc_context_prediction_allow_set (WSCContextISF* ctx, Eina_Bool prediction);
-Eina_Bool isf_wsc_context_prediction_allow_get (WSCContextISF* ctx);
-void isf_wsc_context_autocapital_type_set (WSCContextISF* ctx, Ecore_IMF_Autocapital_Type autocapital_type);
-void isf_wsc_context_filter_key_event (struct weescim *wsc,
+void context_scim_imdata_get (WSCContextISF *wsc_ctx, void* data, int* length);
+void imengine_layout_set (WSCContextISF *wsc_ctx, Ecore_IMF_Input_Panel_Layout layout);
+
+void isf_wsc_context_add (WSCContextISF *wsc_ctx);
+void isf_wsc_context_del (WSCContextISF *wsc_ctx);
+void isf_wsc_context_focus_in (WSCContextISF *wsc_ctx);
+void isf_wsc_context_focus_out (WSCContextISF *wsc_ctx);
+void isf_wsc_context_reset (WSCContextISF *wsc_ctx);
+void isf_wsc_context_cursor_position_set (WSCContextISF *wsc_ctx, int cursor_pos);
+void isf_wsc_context_preedit_string_get (WSCContextISF *wsc_ctx, char** str, int *cursor_pos);
+void isf_wsc_context_prediction_allow_set (WSCContextISF* wsc_ctx, Eina_Bool prediction);
+Eina_Bool isf_wsc_context_prediction_allow_get (WSCContextISF* wsc_ctx);
+void isf_wsc_context_autocapital_type_set (WSCContextISF* wsc_ctx, Ecore_IMF_Autocapital_Type autocapital_type);
+void isf_wsc_context_filter_key_event (WSCContextISF* wsc_ctx,
                                        uint32_t serial,
                                        uint32_t timestamp, uint32_t key, uint32_t unicode,
                                        char *keyname,
                                        enum wl_keyboard_key_state state);
 
-WSCContextISF* isf_wsc_context_new      (void);
+void           isf_wsc_context_init      (void);
 void           isf_wsc_context_shutdown (void);
 
-bool wsc_context_surrounding_get (weescim *ctx, char **text, int *cursor_pos);
-Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get(weescim *ctx);
-int wsc_context_input_panel_layout_variation_get (weescim *ctx);
-bool wsc_context_input_panel_caps_lock_mode_get(weescim *ctx);
-void wsc_context_delete_surrounding (weescim *ctx, int offset, int len);
-Ecore_IMF_Autocapital_Type wsc_context_autocapital_type_get (weescim *ctx);
-Ecore_IMF_Input_Panel_Lang wsc_context_input_panel_language_get (weescim *ctx);
-bool wsc_context_input_panel_password_mode_get (weescim *ctx);
-Ecore_IMF_Input_Hints wsc_context_input_hint_get (weescim *ctx);
-Eina_Bool wsc_context_prediction_allow_get (weescim *ctx);
-void wsc_context_commit_preedit_string(weescim *ctx);
-void wsc_context_commit_string(weescim *ctx, const char *str);
-void wsc_context_send_preedit_string(weescim *ctx);
-void wsc_context_send_key(weescim *ctx, uint32_t keysym, uint32_t modifiers, uint32_t time, bool press);
+bool wsc_context_surrounding_get (WSCContextISF *wsc_ctx, char **text, int *cursor_pos);
+Ecore_IMF_Input_Panel_Layout wsc_context_input_panel_layout_get(WSCContextISF *wsc_ctx);
+int wsc_context_input_panel_layout_variation_get (WSCContextISF *wsc_ctx);
+bool wsc_context_input_panel_caps_lock_mode_get(WSCContextISF *wsc_ctx);
+void wsc_context_delete_surrounding (WSCContextISF *wsc_ctx, int offset, int len);
+Ecore_IMF_Autocapital_Type wsc_context_autocapital_type_get (WSCContextISF *wsc_ctx);
+Ecore_IMF_Input_Panel_Lang wsc_context_input_panel_language_get (WSCContextISF *wsc_ctx);
+bool wsc_context_input_panel_password_mode_get (WSCContextISF *wsc_ctx);
+Ecore_IMF_Input_Hints wsc_context_input_hint_get (WSCContextISF *wsc_ctx);
+Eina_Bool wsc_context_prediction_allow_get (WSCContextISF *wsc_ctx);
+void wsc_context_commit_preedit_string(WSCContextISF *wsc_ctx);
+void wsc_context_commit_string(WSCContextISF *wsc_ctx, const char *str);
+void wsc_context_send_preedit_string(WSCContextISF *wsc_ctx);
+void wsc_context_send_key(WSCContextISF *wsc_ctx, uint32_t keysym, uint32_t modifiers, uint32_t time, bool press);
 
 #endif /* __ISF_WSC_CONTEXT_H_ */
index 6dc10b0..0b4bf1e 100644 (file)
@@ -74,16 +74,16 @@ void isf_wsc_input_panel_shutdown (void)
 {
 }
 
-void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
+void isf_wsc_context_input_panel_show (WSCContextISF* wsc_ctx)
 {
     int length = -1;
     void *packet = NULL;
     char imdata[1024] = {0};
     bool input_panel_show = false;
-    input_panel_ctx = ctx;
+    input_panel_ctx = wsc_ctx;
     Ise_Context iseContext;
 
-    if (!ctx || !ctx->ctx)
+    if (!wsc_ctx || !wsc_ctx->ctx)
         return;
 
     if (kbd_mode == TOOLBAR_KEYBOARD_MODE) {
@@ -92,19 +92,19 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
     }
 
     /* set password mode */
-    iseContext.password_mode = wsc_context_input_panel_password_mode_get (ctx->ctx);
+    iseContext.password_mode = wsc_context_input_panel_password_mode_get (wsc_ctx);
 
     /* set language */
-    iseContext.language = wsc_context_input_panel_language_get (ctx->ctx);
+    iseContext.language = wsc_context_input_panel_language_get (wsc_ctx);
 
     /* set layout in ise context info */
-    iseContext.layout = wsc_context_input_panel_layout_get (ctx->ctx);
+    iseContext.layout = wsc_context_input_panel_layout_get (wsc_ctx);
 
     /* set layout variation in ise context info */
-    iseContext.layout_variation = wsc_context_input_panel_layout_variation_get (ctx->ctx);
+    iseContext.layout_variation = wsc_context_input_panel_layout_variation_get (wsc_ctx);
 
     /* set prediction allow */
-    iseContext.prediction_allow = wsc_context_prediction_allow_get (ctx->ctx);
+    iseContext.prediction_allow = wsc_context_prediction_allow_get (wsc_ctx);
 
     if (iseContext.layout == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD)
         iseContext.password_mode = EINA_TRUE;
@@ -115,34 +115,34 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
     if (iseContext.layout == ECORE_IMF_INPUT_PANEL_LAYOUT_TERMINAL)
         iseContext.prediction_allow = EINA_FALSE;
 
-    isf_wsc_context_prediction_allow_set (ctx, iseContext.prediction_allow);
+    isf_wsc_context_prediction_allow_set (wsc_ctx, iseContext.prediction_allow);
 
     /* set return key type */
-    iseContext.return_key_type = (Ecore_IMF_Input_Panel_Return_Key_Type)ctx->ctx->return_key_type;
+    iseContext.return_key_type = (Ecore_IMF_Input_Panel_Return_Key_Type)wsc_ctx->return_key_type;
 
     /* set return key disabled */
-    iseContext.return_key_disabled = ctx->ctx->return_key_disabled;
+    iseContext.return_key_disabled = wsc_ctx->return_key_disabled;
 
     /* set caps mode */
-    iseContext.caps_mode = caps_mode_check (ctx, EINA_TRUE, EINA_FALSE);
+    iseContext.caps_mode = caps_mode_check (wsc_ctx, EINA_TRUE, EINA_FALSE);
 
     /* set client window */
     iseContext.client_window = 0;
 
     /* set the size of imdata */
-    context_scim_imdata_get (ctx, (void *)imdata, &iseContext.imdata_size);
+    context_scim_imdata_get (wsc_ctx, (void *)imdata, &iseContext.imdata_size);
 
     /* set the cursor position of the editable widget */
     wsc_context_surrounding_get (ctx->ctx, NULL, &iseContext.cursor_pos);
 
-    iseContext.autocapital_type = wsc_context_autocapital_type_get (ctx->ctx);
+    iseContext.autocapital_type = wsc_context_autocapital_type_get (wsc_ctx);
 
-    iseContext.input_hint = wsc_context_input_hint_get (ctx->ctx);
+    iseContext.input_hint = wsc_context_input_hint_get (wsc_ctx);
 
     /* FIXME */
     iseContext.bidi_direction = ECORE_IMF_BIDI_DIRECTION_NEUTRAL;
 
-    LOGD ("ctx : %p, layout : %d, layout variation : %d\n", ctx, iseContext.layout, iseContext.layout_variation);
+    LOGD ("ctx : %p, layout : %d, layout variation : %d\n", wsc_ctx, iseContext.layout, iseContext.layout_variation);
     LOGD ("language : %d, cursor position : %d, caps mode : %d\n", iseContext.language, iseContext.cursor_pos, iseContext.caps_mode);
     LOGD ("return_key_type : %d, return_key_disabled : %d, autocapital type : %d\n", iseContext.return_key_type, iseContext.return_key_disabled, iseContext.autocapital_type);
     LOGD ("password mode : %d, prediction_allow : %d\n", iseContext.password_mode, iseContext.prediction_allow);
@@ -161,13 +161,13 @@ void isf_wsc_context_input_panel_show (WSCContextISF* ctx)
     memcpy (packet, (void *)&iseContext, sizeof (iseContext));
     memcpy ((void *)((char *)packet + sizeof (iseContext)), (void *)imdata, iseContext.imdata_size);
 
-    int context_id = _get_context_id (ctx);
+    int context_id = _get_context_id (wsc_ctx);
 
     _isf_wsc_context_input_panel_show (get_panel_client_id (), context_id, packet, length, input_panel_show);
 
     free (packet);
 
-    caps_mode_check (ctx, EINA_TRUE, EINA_TRUE);
+    caps_mode_check (wsc_ctx, EINA_TRUE, EINA_TRUE);
 }
 
 void isf_wsc_context_input_panel_hide (WSCContextISF *ctx)
index a94406a..219f0ef 100644 (file)
@@ -45,7 +45,6 @@
 #include <malloc.h>
 #include "scim_private.h"
 #include "scim.h"
-#include "scim_stl_map.h"
 #if HAVE_VCONF
 #include <vconf.h>
 #include <vconf-keys.h>
 #include <text-client-protocol.h>
 #include "isf_wsc_context.h"
 #include "isf_wsc_control_ui.h"
-#include "scim_stl_map.h"
 
 using namespace scim;
 
-#if SCIM_USE_STL_EXT_HASH_MAP
-    typedef __gnu_cxx::hash_map <uint32_t, uint32_t, __gnu_cxx::hash <uint32_t> >   KeycodeRepository;
-#elif SCIM_USE_STL_HASH_MAP
-    typedef std::hash_map <uint32_t, ClientInfo, std::hash <uint32_t> >             KeycodeRepository;
-#else
-    typedef std::map <uint32_t, uint32_t>                                           KeycodeRepository;
-#endif
-
-static KeycodeRepository _keysym2keycode;
-
 /////////////////////////////////////////////////////////////////////////////
 // Declaration of macro.
 /////////////////////////////////////////////////////////////////////////////
@@ -83,6 +71,8 @@ static KeycodeRepository _keysym2keycode;
 #define LOG_TAG                                         "ISF_WSC_EFL"
 
 static struct weescim _wsc                                  = {0};
+static int            _context_count                        = 0;
+
 
 /////////////////////////////////////////////////////////////////////////////
 // Implementation of Wayland Input Method functions.
@@ -90,16 +80,16 @@ static struct weescim _wsc                                  = {0};
 static void
 _wsc_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx, const char *text, uint32_t cursor, uint32_t anchor)
 {
-    struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
 
-    if (wsc->surrounding_text)
-        free (wsc->surrounding_text);
+    if (wsc_ctx->surrounding_text)
+        free (wsc_ctx->surrounding_text);
 
-    wsc->surrounding_text = strdup (text ? text : "");
-    wsc->surrounding_cursor = cursor;
+    wsc_ctx->surrounding_text = strdup (text ? text : "");
+    wsc_ctx->surrounding_cursor = cursor;
 
-    isf_wsc_context_cursor_position_set(wsc->wsc_ctx, cursor);
+    isf_wsc_context_cursor_position_set(wsc_ctx, cursor);
 
     LOGD ("text : '%s', cursor : %d\n", text, cursor);
 }
@@ -107,86 +97,83 @@ _wsc_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx,
 static void
 _wsc_im_ctx_reset(void *data, struct wl_input_method_context *im_ctx)
 {
-    struct weescim *wsc = (weescim*)data;
-    if (!wsc || !wsc->wsc_ctx) return;
-
-    isf_wsc_context_reset(wsc->wsc_ctx);
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
+    isf_wsc_context_reset(wsc_ctx);
 }
 
 static void
 _wsc_im_ctx_content_type(void *data, struct wl_input_method_context *im_ctx, uint32_t hint, uint32_t purpose)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
 
     LOGD ("im_context = %p hint = %d purpose = %d\n", im_ctx, hint, purpose);
 
-    if (!wsc || !wsc->context_changed)
-        return;
+    if (!wsc_ctx->context_changed) return;
 
-    wsc->content_hint = hint;
-    wsc->content_purpose = purpose;
+    wsc_ctx->content_hint = hint;
+    wsc_ctx->content_purpose = purpose;
 
-    if (wsc->wsc_ctx) {
-        isf_wsc_context_input_panel_layout_set (wsc->wsc_ctx,
-                                                wsc_context_input_panel_layout_get (wsc));
+    isf_wsc_context_input_panel_layout_set (wsc_ctx,
+                                            wsc_context_input_panel_layout_get (wsc_ctx));
 
-        isf_wsc_context_autocapital_type_set (wsc->wsc_ctx, wsc_context_autocapital_type_get(wsc));
+    isf_wsc_context_autocapital_type_set (wsc_ctx, wsc_context_autocapital_type_get(wsc_ctx));
 
-        isf_wsc_context_input_panel_language_set (wsc->wsc_ctx, wsc_context_input_panel_language_get(wsc));
+    isf_wsc_context_input_panel_language_set (wsc_ctx, wsc_context_input_panel_language_get(wsc_ctx));
 
-        caps_mode_check (wsc->wsc_ctx, EINA_TRUE, EINA_TRUE);
+    caps_mode_check (wsc_ctx, EINA_TRUE, EINA_TRUE);
 
-        wsc->context_changed = EINA_FALSE;
-    }
+    wsc_ctx->context_changed = EINA_FALSE;
 }
 
 static void
 _wsc_im_ctx_invoke_action(void *data, struct wl_input_method_context *im_ctx, uint32_t button, uint32_t index)
 {
-    struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
 
     LOGD ("invoke action. button : %d\n", button);
 
     if (button != BTN_LEFT)
         return;
 
-    wsc_context_send_preedit_string (wsc);
+    wsc_context_send_preedit_string (wsc_ctx);
 }
 
 static void
 _wsc_im_ctx_commit_state(void *data, struct wl_input_method_context *im_ctx, uint32_t serial)
 {
-    struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
 
-    wsc->serial = serial;
+    wsc_ctx->serial = serial;
 
-    if (wsc->surrounding_text)
-        LOGD ("Surrounding text updated: '%s'\n", wsc->surrounding_text);
+    if (wsc_ctx->surrounding_text)
+        LOGD ("Surrounding text updated: '%s'\n", wsc_ctx->surrounding_text);
 
-    if (wsc->language)
-        wl_input_method_context_language (im_ctx, wsc->serial, wsc->language);
+    if (wsc_ctx->language)
+        wl_input_method_context_language (im_ctx, wsc_ctx->serial, wsc_ctx->language);
 
-    wl_input_method_context_text_direction (im_ctx, wsc->serial, wsc->text_direction);
+    wl_input_method_context_text_direction (im_ctx, wsc_ctx->serial, wsc_ctx->text_direction);
 }
 
 static void
 _wsc_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ctx, const char *language)
 {
-    struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    if (!wsc_ctx) return;
 
-    if (language && wsc->language && !strcmp (language, wsc->language))
+    if (language && wsc_ctx->language && !strcmp (language, wsc_ctx->language))
         return;
 
-    if (wsc->language) {
-        free (wsc->language);
-        wsc->language = NULL;
+    if (wsc_ctx->language) {
+        free (wsc_ctx->language);
+        wsc_ctx->language = NULL;
     }
 
     if (language) {
-        wsc->language = strdup (language);
+        wsc_ctx->language = strdup (language);
         LOGD ("Language changed, new: '%s'\n", language);
     }
 }
@@ -194,40 +181,40 @@ _wsc_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ct
 static void
 _wsc_im_ctx_return_key_type(void *data, struct wl_input_method_context *im_ctx, uint32_t return_key_type)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
 
     LOGD ("im_context = %p return key type = %d\n", im_ctx, return_key_type);
-    if (!wsc || !wsc->wsc_ctx) return;
+    if (!wsc_ctx) return;
 
-    if (wsc->return_key_type != return_key_type) {
-        wsc->return_key_type = return_key_type;
-        isf_wsc_context_input_panel_return_key_type_set (wsc->wsc_ctx, (Ecore_IMF_Input_Panel_Return_Key_Type)wsc->return_key_type);
+    if (wsc_ctx->return_key_type != return_key_type) {
+        wsc_ctx->return_key_type = return_key_type;
+        isf_wsc_context_input_panel_return_key_type_set (wsc_ctx, (Ecore_IMF_Input_Panel_Return_Key_Type)wsc_ctx->return_key_type);
     }
 }
 
 static void
 _wsc_im_ctx_return_key_disabled(void *data, struct wl_input_method_context *im_ctx, uint32_t disabled)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
     Eina_Bool return_key_disabled = !!disabled;
 
     LOGD ("im_context = %p return key disabled = %d\n", im_ctx, return_key_disabled);
-    if (!wsc || !wsc->wsc_ctx) return;
+    if (!wsc_ctx) return;
 
-    if (wsc->return_key_disabled != return_key_disabled) {
-        wsc->return_key_disabled = return_key_disabled;
-        isf_wsc_context_input_panel_return_key_disabled_set (wsc->wsc_ctx, wsc->return_key_disabled);
+    if (wsc_ctx->return_key_disabled != return_key_disabled) {
+        wsc_ctx->return_key_disabled = return_key_disabled;
+        isf_wsc_context_input_panel_return_key_disabled_set (wsc_ctx, wsc_ctx->return_key_disabled);
     }
 }
 
 static void
 _wsc_im_ctx_input_panel_data(void *data, struct wl_input_method_context *im_ctx, const char *input_panel_data, uint32_t input_panel_data_length)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
     LOGD ("im_context = %p input panel data = %s len = %d\n", im_ctx, input_panel_data, input_panel_data_length);
-    if (!wsc || !wsc->wsc_ctx) return;
+    if (!wsc_ctx) return;
 
-    isf_wsc_context_input_panel_imdata_set (wsc->wsc_ctx, (void *)input_panel_data, input_panel_data_length);
+    isf_wsc_context_input_panel_imdata_set (wsc_ctx, (void *)input_panel_data, input_panel_data_length);
 }
 
 static const struct wl_input_method_context_listener wsc_im_context_listener = {
@@ -243,29 +230,29 @@ static const struct wl_input_method_context_listener wsc_im_context_listener = {
 };
 
 static void
-_init_keysym2keycode(struct weescim *wsc)
+_init_keysym2keycode(WSCContextISF *wsc_ctx)
 {
     uint32_t i = 0;
     uint32_t code;
     uint32_t num_syms;
     const xkb_keysym_t *syms;
 
-    if (!wsc || !wsc->state)
+    if (!wsc_ctx || !wsc_ctx->state)
         return;
 
     for (i = 0; i < 256; i++) {
         code = i + 8;
-        num_syms = xkb_key_get_syms(wsc->state, code, &syms);
+        num_syms = xkb_key_get_syms(wsc_ctx->state, code, &syms);
 
         if (num_syms == 1)
-            _keysym2keycode[syms[0]] = i;
+            wsc_ctx->_keysym2keycode[syms[0]] = i;
     }
 }
 
 static void
-_fini_keysym2keycode(struct weescim *wsc)
+_fini_keysym2keycode(WSCContextISF *wsc_ctx)
 {
-    _keysym2keycode.clear();
+    wsc_ctx->_keysym2keycode.clear();
 }
 
 static void
@@ -275,21 +262,21 @@ _wsc_im_keyboard_keymap(void *data,
         int32_t fd,
         uint32_t size)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
     char *map_str;
 
-    if (!wsc) return;
+    if (!wsc_ctx) return;
 
-    _fini_keysym2keycode(wsc);
+    _fini_keysym2keycode(wsc_ctx);
 
-    if (wsc->state) {
-        xkb_state_unref(wsc->state);
-        wsc->state = NULL;
+    if (wsc_ctx->state) {
+        xkb_state_unref(wsc_ctx->state);
+        wsc_ctx->state = NULL;
     }
 
-    if (wsc->keymap) {
-        xkb_map_unref(wsc->keymap);
-        wsc->keymap = NULL;
+    if (wsc_ctx->keymap) {
+        xkb_map_unref(wsc_ctx->keymap);
+        wsc_ctx->keymap = NULL;
     }
 
     if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
@@ -303,8 +290,8 @@ _wsc_im_keyboard_keymap(void *data,
         return;
     }
 
-    wsc->keymap =
-        xkb_map_new_from_string(wsc->xkb_context,
+    wsc_ctx->keymap =
+        xkb_map_new_from_string(wsc_ctx->xkb_context,
                 map_str,
                 XKB_KEYMAP_FORMAT_TEXT_V1,
                 (xkb_keymap_compile_flags)0);
@@ -312,27 +299,27 @@ _wsc_im_keyboard_keymap(void *data,
     munmap(map_str, size);
     close(fd);
 
-    if (!wsc->keymap) {
+    if (!wsc_ctx->keymap) {
         LOGW ("failed to compile keymap\n");
         return;
     }
 
-    wsc->state = xkb_state_new(wsc->keymap);
-    if (!wsc->state) {
+    wsc_ctx->state = xkb_state_new(wsc_ctx->keymap);
+    if (!wsc_ctx->state) {
         LOGW ("failed to create XKB state\n");
-        xkb_map_unref(wsc->keymap);
+        xkb_map_unref(wsc_ctx->keymap);
         return;
     }
 
-    wsc->control_mask =
-        1 << xkb_map_mod_get_index(wsc->keymap, "Control");
-    wsc->alt_mask =
-        1 << xkb_map_mod_get_index(wsc->keymap, "Mod1");
-    wsc->shift_mask =
-        1 << xkb_map_mod_get_index(wsc->keymap, "Shift");
+    wsc_ctx->control_mask =
+        1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Control");
+    wsc_ctx->alt_mask =
+        1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Mod1");
+    wsc_ctx->shift_mask =
+        1 << xkb_map_mod_get_index(wsc_ctx->keymap, "Shift");
 
     LOGW ("create _keysym2keycode\n");
-    _init_keysym2keycode(wsc);
+    _init_keysym2keycode(wsc_ctx);
 }
 
 static void
@@ -343,7 +330,7 @@ _wsc_im_keyboard_key(void *data,
         uint32_t key,
         uint32_t state_w)
 {
-    struct weescim *wsc = (weescim*)data;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
     uint32_t code;
     uint32_t num_syms;
     const xkb_keysym_t *syms;
@@ -351,11 +338,11 @@ _wsc_im_keyboard_key(void *data,
     char keyname[64] = {0};
     enum wl_keyboard_key_state state = (wl_keyboard_key_state)state_w;
 
-    if (!wsc || !wsc->state)
+    if (!wsc_ctx || !wsc_ctx->state)
         return;
 
     code = key + 8;
-    num_syms = xkb_key_get_syms(wsc->state, code, &syms);
+    num_syms = xkb_key_get_syms(wsc_ctx->state, code, &syms);
 
     sym = XKB_KEY_NoSymbol;
     if (num_syms == 1)
@@ -364,8 +351,8 @@ _wsc_im_keyboard_key(void *data,
         xkb_keysym_get_name(sym, keyname, 64);
     }
 
-    if (wsc->key_handler)
-        (*wsc->key_handler)(wsc, serial, time, code, sym, keyname,
+    if (wsc_ctx->key_handler)
+        (*wsc_ctx->key_handler)(wsc_ctx, serial, time, code, sym, keyname,
                 state);
 }
 
@@ -378,25 +365,25 @@ _wsc_im_keyboard_modifiers(void *data,
         uint32_t mods_locked,
         uint32_t group)
 {
-    struct weescim *wsc = (weescim*)data;
-    struct wl_input_method_context *context = wsc->im_ctx;
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+    struct wl_input_method_context *context = wsc_ctx->im_ctx;
     xkb_mod_mask_t mask;
 
-    if (!wsc || !wsc->state)
+    if (!wsc_ctx || !wsc_ctx->state)
         return;
 
-    xkb_state_update_mask(wsc->state, mods_depressed,
+    xkb_state_update_mask(wsc_ctx->state, mods_depressed,
             mods_latched, mods_locked, 0, 0, group);
-    mask = xkb_state_serialize_mods(wsc->state,
+    mask = xkb_state_serialize_mods(wsc_ctx->state,
             (xkb_state_component)(XKB_STATE_DEPRESSED | XKB_STATE_LATCHED));
 
-    wsc->modifiers = 0;
-    if (mask & wsc->control_mask)
-        wsc->modifiers |= SCIM_KEY_ControlMask;
-    if (mask & wsc->alt_mask)
-        wsc->modifiers |= SCIM_KEY_AltMask;
-    if (mask & wsc->shift_mask)
-        wsc->modifiers |= SCIM_KEY_ShiftMask;
+    wsc_ctx->modifiers = 0;
+    if (mask & wsc_ctx->control_mask)
+        wsc_ctx->modifiers |= SCIM_KEY_ControlMask;
+    if (mask & wsc_ctx->alt_mask)
+        wsc_ctx->modifiers |= SCIM_KEY_AltMask;
+    if (mask & wsc_ctx->shift_mask)
+        wsc_ctx->modifiers |= SCIM_KEY_ShiftMask;
 
     wl_input_method_context_modifiers(context, serial,
             mods_depressed, mods_depressed,
@@ -417,77 +404,121 @@ _wsc_im_activate(void *data, struct wl_input_method *input_method, struct wl_inp
     struct weescim *wsc = (weescim*)data;
     if (!wsc) return;
 
-    if (wsc->im_ctx)
-        wl_input_method_context_destroy (wsc->im_ctx);
+    WSCContextISF *wsc_ctx = new WSCContextISF;
+    if (!wsc_ctx) {
+        return;
+    }
+    wsc_ctx->xkb_context = xkb_context_new((xkb_context_flags)0);
+    if (wsc_ctx->xkb_context == NULL) {
+        LOGW ("Failed to create XKB context\n");
+        delete wsc_ctx;
+        return;
+    }
+    if (_context_count == 0) {
+        _context_count = getpid () % 50000;
+    }
+    wsc_ctx->id = _context_count++;
+    wsc->wsc_ctx = wsc_ctx;
+    wsc_ctx->ctx = wsc;
+    wsc_ctx->state = NULL;
+    wsc_ctx->keymap = NULL;
+    wsc_ctx->surrounding_text = NULL;
+    wsc_ctx->key_handler = isf_wsc_context_filter_key_event;
 
-    if (wsc->preedit_str)
-        free (wsc->preedit_str);
+    get_language(&wsc_ctx->language);
 
-    wsc->preedit_str = strdup ("");
-    wsc->content_hint = WL_TEXT_INPUT_CONTENT_HINT_NONE;
-    wsc->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NORMAL;
+    wsc_ctx->preedit_str = strdup ("");
+    wsc_ctx->content_hint = WL_TEXT_INPUT_CONTENT_HINT_NONE;
+    wsc_ctx->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NORMAL;
 
-    if (wsc->language) {
-        free (wsc->language);
-        wsc->language = NULL;
-    }
+    wsc_ctx->im_ctx = im_ctx;
+    wl_input_method_context_add_listener (im_ctx, &wsc_im_context_listener, wsc_ctx);
 
-    if (wsc->surrounding_text) {
-        free (wsc->surrounding_text);
-        wsc->surrounding_text = NULL;
-    }
+    wsc_ctx->keyboard = wl_input_method_context_grab_keyboard(im_ctx);
+    if (wsc_ctx->keyboard)
+        wl_keyboard_add_listener(wsc_ctx->keyboard, &wsc_im_keyboard_listener, wsc_ctx);
 
-    wsc->im_ctx = im_ctx;
-    wl_input_method_context_add_listener (im_ctx, &wsc_im_context_listener, wsc);
+    if (wsc_ctx->language)
+        wl_input_method_context_language (im_ctx, wsc_ctx->serial, wsc_ctx->language);
 
-    wsc->keyboard = wl_input_method_context_grab_keyboard(im_ctx);
-    if (wsc->keyboard)
-        wl_keyboard_add_listener(wsc->keyboard, &wsc_im_keyboard_listener, wsc);
+    wl_input_method_context_text_direction (im_ctx, wsc_ctx->serial, wsc_ctx->text_direction);
 
-    if (wsc->language)
-        wl_input_method_context_language (im_ctx, wsc->serial, wsc->language);
+    isf_wsc_context_add (wsc_ctx);
 
-    wl_input_method_context_text_direction (im_ctx, wsc->serial, wsc->text_direction);
+    wsc_ctx->context_changed = EINA_TRUE;
 
-    wsc->context_changed = EINA_TRUE;
-    isf_wsc_context_focus_in (wsc->wsc_ctx);
+    isf_wsc_context_focus_in (wsc_ctx);
 }
 
 static void
 _wsc_im_deactivate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    if (!wsc || !wsc->wsc_ctx) return;
+    WSCContextISF *wsc_ctx = wsc->wsc_ctx;
+
+    isf_wsc_context_input_panel_hide (wsc_ctx);
+    isf_wsc_context_focus_out (wsc_ctx);
+
+    if (wsc_ctx->keyboard) {
+        wl_keyboard_destroy (wsc_ctx->keyboard);
+        wsc_ctx->keyboard = NULL;
+    }
+
+    _fini_keysym2keycode (wsc_ctx);
+
+    if (wsc_ctx->state) {
+        xkb_state_unref (wsc_ctx->state);
+        wsc_ctx->state = NULL;
+    }
+
+    if (wsc_ctx->keymap) {
+        xkb_map_unref (wsc_ctx->keymap);
+        wsc_ctx->keymap = NULL;
+    }
 
-    if (wsc->wsc_ctx) {
-        isf_wsc_context_input_panel_hide (wsc->wsc_ctx);
-        isf_wsc_context_focus_out (wsc->wsc_ctx);
+    if (wsc_ctx->im_ctx) {
+        wl_input_method_context_destroy (wsc_ctx->im_ctx);
+        wsc_ctx->im_ctx = NULL;
     }
 
-    if (wsc->im_ctx) {
-        wl_input_method_context_destroy(wsc->im_ctx);
-        wsc->im_ctx = NULL;
+    if (wsc_ctx->preedit_str) {
+        free (wsc_ctx->preedit_str);
+        wsc_ctx->preedit_str = NULL;
     }
+
+    if (wsc_ctx->surrounding_text) {
+        free (wsc_ctx->surrounding_text);
+        wsc_ctx->surrounding_text = NULL;
+    }
+
+    if (wsc_ctx->language) {
+        free (wsc_ctx->language);
+        wsc_ctx->language = NULL;
+    }
+
+    isf_wsc_context_del (wsc_ctx);
+    delete wsc_ctx;
+    wsc->wsc_ctx = NULL;
+
 }
 
 static void
 _wsc_im_show_input_panel(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    if (!wsc || !wsc->wsc_ctx) return;
 
-    if (wsc->wsc_ctx)
-        isf_wsc_context_input_panel_show (wsc->wsc_ctx);
+    isf_wsc_context_input_panel_show (wsc->wsc_ctx);
 }
 
 static void
 _wsc_im_hide_input_panel(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
-    if (!wsc) return;
+    if (!wsc || !wsc->wsc_ctx) return;
 
-    if (wsc->wsc_ctx)
-        isf_wsc_context_input_panel_hide (wsc->wsc_ctx);
+    isf_wsc_context_input_panel_hide (wsc->wsc_ctx);
 }
 
 static const struct wl_input_method_listener wsc_im_listener = {
@@ -505,9 +536,9 @@ _wsc_seat_handle_capabilities(void *data, struct wl_seat *seat,
     if (!wsc) return;
 
     if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
-        wsc->hw_kbd = true;
+
     } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
-        wsc->hw_kbd = false;
+
     }
 }
 
@@ -524,21 +555,6 @@ _wsc_setup(struct weescim *wsc)
 
     if (!wsc) return false;
 
-    wsc->xkb_context = xkb_context_new((xkb_context_flags)0);
-    if (wsc->xkb_context == NULL) {
-        LOGW ("Failed to create XKB context\n");
-        return false;
-    }
-
-    wsc->key_handler = isf_wsc_context_filter_key_event;
-
-    wsc->wsc_ctx = isf_wsc_context_new ();
-    if (!wsc->wsc_ctx) return false;
-
-    wsc->wsc_ctx->ctx = wsc;
-
-    get_language(&wsc->language);
-
     if (!(registry = ecore_wl_registry_get()))
         return false;
 
@@ -574,68 +590,22 @@ _wsc_setup(struct weescim *wsc)
         return false;
     }
 
-    isf_wsc_context_add (wsc->wsc_ctx);
-
     return true;
 }
 
-static void
-_wsc_free (struct weescim *wsc)
-{
-    if (!wsc) return;
-
-    _fini_keysym2keycode (wsc);
-
-    if (wsc->state) {
-        xkb_state_unref (wsc->state);
-        wsc->state = NULL;
-    }
-
-    if (wsc->keymap) {
-        xkb_map_unref (wsc->keymap);
-        wsc->keymap = NULL;
-    }
-
-    if (wsc->im_ctx) {
-        wl_input_method_context_destroy (wsc->im_ctx);
-        wsc->im_ctx = NULL;
-    }
-
-    if (wsc->wsc_ctx) {
-        isf_wsc_context_del (wsc->wsc_ctx);
-        wsc->wsc_ctx = NULL;
-    }
-
-    if (wsc->preedit_str) {
-        free (wsc->preedit_str);
-        wsc->preedit_str = NULL;
-    }
-
-    if (wsc->surrounding_text) {
-        free (wsc->surrounding_text);
-        wsc->surrounding_text = NULL;
-    }
-
-    if (wsc->language) {
-        free (wsc->language);
-        wsc->language = NULL;
-    }
-
-    isf_wsc_context_shutdown ();
-}
-
 int main (int argc EINA_UNUSED, char **argv EINA_UNUSED)
 {
     sleep(1);
 
+    isf_wsc_context_init ();
+
     if (!_wsc_setup (&_wsc)) {
-        _wsc_free (&_wsc);
         return 0;
     }
 
     ecore_main_loop_begin();
 
-    _wsc_free (&_wsc);
+    isf_wsc_context_shutdown ();
 
     return 0;
 }