Modified to use new protocols related to focus events 56/266756/3
authorInHong Han <inhong1.han@samsung.com>
Thu, 18 Nov 2021 08:21:44 +0000 (17:21 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 6 Jan 2022 07:09:32 +0000 (07:09 +0000)
Change-Id: Iba48c6840219dc58d13cf6b683cd858ef05cd15d

ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp

index 92fdbf5..5236b33 100644 (file)
@@ -181,6 +181,9 @@ static void     finalize                                (void);
 static void     send_wl_key_event                       (WSCContextISF *ic, const KeyEvent &key, bool fake);
 static void     _hide_preedit_string                    (int context, bool update_preedit);
 
+static void     _create_wsc_context                     (struct weescim *wsc, WSCContextISF *wsc_ctx, struct zwp_input_method_context_v1 *im_ctx);
+static void     _destroy_wsc_context                    (struct weescim *wsc, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx);
+
 /* Local variables declaration */
 static String                                           _language;
 static WSCContextISFImpl                               *_used_ic_impl_list          = 0;
@@ -212,6 +215,7 @@ static struct _wl_im                                    *_wl_im_ctx
 static int                                              _ecore_wl2_init_count      = 0;
 
 static bool                                             _launch_ise_on_request     = false;
+static bool                                             _send_focus_in_event       = false;
 
 #define WAYLAND_MODULE_CLIENT_ID (0)
 #define MAX_PREEDIT_BUFSIZE 4000
@@ -806,7 +810,7 @@ wl_im_destroy ()
 }
 
 static void
-_wsc_im_activate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx, uint32_t text_input_id, uint32_t focus_in_event)
+_wsc_im_activate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
     if (!wsc) return;
@@ -816,75 +820,23 @@ _wsc_im_activate (void *data, struct zwp_input_method_v1 *input_method, struct z
         return;
     }
 
-    if (_need_wl_im_init) {
-        LOGD("destroy zwp_input_method_context_v1");
-        wl_im_destroy ();
-    }
-
-#if ENABLE_GRAB_KEYBOARD
-    wsc_ctx->xkb_context = xkb_context_new ((xkb_context_flags)0);
-    if (wsc_ctx->xkb_context == NULL) {
-        LOGW ("Failed to create XKB context");
-        delete wsc_ctx;
-        return;
-    }
-    wsc_ctx->state = NULL;
-    wsc_ctx->keymap = NULL;
-    wsc_ctx->modifiers = 0;
-#endif
-
-    wsc_ctx->id = text_input_id;
-    wsc->wsc_ctx = wsc_ctx;
-    wsc_ctx->ctx = wsc;
-    wsc_ctx->surrounding_text = NULL;
-    wsc_ctx->remote_surrounding_text = NULL;
-    wsc_ctx->surrounding_cursor = 0;
-    LOGD("inputmethod : %p, im context : %p, surrounding_cursor = %d", input_method, im_ctx, wsc_ctx->surrounding_cursor);
-
-    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;
-
-    wsc_ctx->im_ctx = im_ctx;
-    zwp_input_method_context_v1_add_listener (im_ctx, &wsc_im_context_listener, wsc_ctx);
-
-#if ENABLE_GRAB_KEYBOARD
-    wsc_ctx->keyboard = zwp_input_method_context_v1_grab_keyboard (im_ctx);
-    if (wsc_ctx->keyboard)
-        wl_keyboard_add_listener (wsc_ctx->keyboard, &wsc_im_keyboard_listener, wsc_ctx);
-#endif
-
-    if (wsc_ctx->language)
-        zwp_input_method_context_v1_language (im_ctx, wsc_ctx->serial, wsc_ctx->language);
-
-    isf_wsc_context_add (wsc_ctx);
+    LOGD("inputmethod : %p, im context : %p", input_method, im_ctx);
 
-    if (focus_in_event) {
-        isf_wsc_context_focus_in (wsc_ctx);
-        _wl_im_ctx->need_focus_event = EINA_TRUE;
-    }
+    _create_wsc_context (wsc, wsc_ctx, im_ctx);
+    _send_focus_in_event = true;
 }
 
 static void
-_wsc_im_deactivate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx, uint32_t focus_out_event)
+_wsc_im_deactivate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
 {
     struct weescim *wsc = (weescim*)data;
     if (!wsc || !wsc->wsc_ctx) return;
 
-    LOGD("inputmethod : %p, im ctx : %p, focus out : %d", input_method, im_ctx, focus_out_event);
+    LOGD("inputmethod : %p, im context : %p", input_method, im_ctx);
 
-    /* When the focus_in/input_panel_shutdown event is called,
-     * it is not possible to know the information of zwp_input_method_v1 to destroy */
-    _wl_im_ctx->wsc = wsc;
-    _wl_im_ctx->input_method = input_method;
-    _wl_im_ctx->im_ctx = im_ctx;
-    _need_wl_im_init = true;
-
-    if (focus_out_event) {
-        isf_wsc_context_focus_out (wsc->wsc_ctx);
-        _wl_im_ctx->need_focus_event = EINA_FALSE;
-    }
-    wsc->wsc_ctx->input_panel_shown_once = EINA_FALSE;
+    _destroy_wsc_context (wsc, input_method, im_ctx);
+    isf_wsc_context_focus_out (wsc->wsc_ctx);
+    _wl_im_ctx->need_focus_event = EINA_FALSE;
 }
 
 static void
@@ -928,12 +880,58 @@ _wsc_im_hide_input_panel (void *data, struct zwp_input_method_v1 *input_method,
     isf_wsc_context_input_panel_hide (wsc->wsc_ctx);
 }
 
+static void
+_wsc_im_open_connection (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
+{
+    struct weescim *wsc = (weescim*)data;
+    if (!wsc) return;
+
+    WSCContextISF *wsc_ctx = new WSCContextISF;
+    if (!wsc_ctx) {
+        return;
+    }
+
+    LOGD("inputmethod : %p, im context : %p", input_method, im_ctx);
+
+    _create_wsc_context (wsc, wsc_ctx, im_ctx);
+}
+
+static void
+_wsc_im_close_connection (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
+{
+    struct weescim *wsc = (weescim*)data;
+    if (!wsc || !wsc->wsc_ctx) return;
+
+    LOGD("inputmethod : %p, im context : %p", input_method, im_ctx);
+
+    _destroy_wsc_context (wsc, input_method, im_ctx);
+}
+
+static void
+_wsc_im_set_text_input_id (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx, uint32_t text_input_id)
+{
+    struct weescim *wsc = (weescim*)data;
+    if (!wsc || !wsc->wsc_ctx) return;
+
+    wsc->wsc_ctx->id = text_input_id;
+    isf_wsc_context_add (wsc->wsc_ctx);
+
+    if (_send_focus_in_event) {
+        isf_wsc_context_focus_in (wsc->wsc_ctx);
+        _wl_im_ctx->need_focus_event = EINA_TRUE;
+        _send_focus_in_event = false;
+    }
+}
+
 static const struct zwp_input_method_v1_listener wsc_im_listener = {
     _wsc_im_activate,
     _wsc_im_deactivate,
     _wsc_im_destroy,
     _wsc_im_show_input_panel,
-    _wsc_im_hide_input_panel
+    _wsc_im_hide_input_panel,
+    _wsc_im_open_connection,
+    _wsc_im_close_connection,
+    _wsc_im_set_text_input_id
 };
 
 static bool
@@ -2972,6 +2970,61 @@ reload_config_callback (const ConfigPointer &config)
     _keyboard_layout = scim_get_default_keyboard_layout ();
 }
 
+static void
+_create_wsc_context (struct weescim *wsc, WSCContextISF *wsc_ctx, struct zwp_input_method_context_v1 *im_ctx)
+{
+    if (_need_wl_im_init) {
+        LOGD("destroy zwp_input_method_context_v1");
+        wl_im_destroy ();
+    }
+
+#if ENABLE_GRAB_KEYBOARD
+    wsc_ctx->xkb_context = xkb_context_new ((xkb_context_flags)0);
+    if (wsc_ctx->xkb_context == NULL) {
+        LOGW ("Failed to create XKB context");
+        delete wsc_ctx;
+        return;
+    }
+    wsc_ctx->state = NULL;
+    wsc_ctx->keymap = NULL;
+    wsc_ctx->modifiers = 0;
+#endif
+
+    wsc->wsc_ctx = wsc_ctx;
+    wsc_ctx->ctx = wsc;
+    wsc_ctx->surrounding_text = NULL;
+    wsc_ctx->remote_surrounding_text = NULL;
+    wsc_ctx->surrounding_cursor = 0;
+    wsc_ctx->preedit_str = strdup ("");
+    wsc_ctx->content_hint = ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE;
+    wsc_ctx->content_purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL;
+
+    wsc_ctx->im_ctx = im_ctx;
+    zwp_input_method_context_v1_add_listener (im_ctx, &wsc_im_context_listener, wsc_ctx);
+
+#if ENABLE_GRAB_KEYBOARD
+    wsc_ctx->keyboard = zwp_input_method_context_v1_grab_keyboard (im_ctx);
+    if (wsc_ctx->keyboard)
+        wl_keyboard_add_listener (wsc_ctx->keyboard, &wsc_im_keyboard_listener, wsc_ctx);
+#endif
+
+    if (wsc_ctx->language)
+        zwp_input_method_context_v1_language (im_ctx, wsc_ctx->serial, wsc_ctx->language);
+}
+
+static void
+_destroy_wsc_context (struct weescim *wsc, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
+{
+    /* When the focus_in/input_panel_shutdown event is called,
+     * it is not possible to know the information of zwp_input_method_v1 to destroy */
+    _wl_im_ctx->wsc = wsc;
+    _wl_im_ctx->input_method = input_method;
+    _wl_im_ctx->im_ctx = im_ctx;
+    _need_wl_im_init = true;
+
+    wsc->wsc_ctx->input_panel_shown_once = EINA_FALSE;
+}
+
 class WaylandPanelAgent: public PanelAgentBase
 {
     Connection _config_connection;