Support to switch input thread mode 00/292700/7
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 10 May 2023 02:21:05 +0000 (11:21 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 3 Jul 2023 10:05:11 +0000 (19:05 +0900)
Change-Id: I736e9472a30e8004565dab8e557ba349f9875f48
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/e_mod_main.c

index 2534345883a9aeef9486eb1ea050bf136627b656..2ad56ffb193ab7500ed957b02d1bc718fb9ff3e6 100644 (file)
@@ -150,6 +150,7 @@ static struct wl_client *g_client = NULL;
 static Eina_List *shutdown_list = NULL;
 static Eina_Bool g_disable_show_panel = EINA_FALSE;
 static Eeze_Udev_Watch *eeze_udev_watch_handler = NULL;
+static Ecore_Event_Handler *ecore_key_down_handler = NULL;
 static E_Input_Event_Filter *e_input_key_down_filter = NULL;
 static Eina_List *handlers = NULL;
 static uint32_t g_text_input_count = 1;
@@ -468,12 +469,23 @@ _e_text_input_method_context_grab_set(E_Input_Method_Context *context, Eina_Bool
         if (context->kbd.state) xkb_state_unref(context->kbd.state);
         context->kbd.keymap = xkb_map_ref(e_comp_wl->xkb.keymap);
         context->kbd.state = xkb_state_new(e_comp_wl->xkb.keymap);
-
-        E_Input_Event_Source *input_event_source = e_input_event_source_get();
-        if (input_event_source)
+        if (!e_input_thread_mode_get())
+          {
+             E_LIST_HANDLER_APPEND(context->kbd.handlers, ECORE_EVENT_KEY_DOWN,
+                                   _e_text_input_method_context_ecore_cb_key_down,
+                                   context);
+             E_LIST_HANDLER_APPEND(context->kbd.handlers, ECORE_EVENT_KEY_UP,
+                                   _e_text_input_method_context_ecore_cb_key_up,
+                                   context);
+          }
+        else
           {
-             _key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_text_input_method_context_ecore_cb_key_down, context);
-             _key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_text_input_method_context_ecore_cb_key_up, context);
+             E_Input_Event_Source *input_event_source = e_input_event_source_get();
+             if (input_event_source)
+               {
+                  _key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_text_input_method_context_ecore_cb_key_down, context);
+                  _key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_text_input_method_context_ecore_cb_key_up, context);
+               }
           }
 
         e_comp_grab_input(0, 1);
@@ -482,17 +494,20 @@ _e_text_input_method_context_grab_set(E_Input_Method_Context *context, Eina_Bool
      {
         E_FREE_LIST(context->kbd.handlers, ecore_event_handler_del);
 
-        E_Input_Event_Source *input_event_source = e_input_event_source_get();
-        if (input_event_source)
+        if (e_input_thread_mode_get())
           {
-             if (_key_down_handler)
-               e_input_event_handler_del(input_event_source, _key_down_handler);
+             E_Input_Event_Source *input_event_source = e_input_event_source_get();
+             if (input_event_source)
+               {
+                  if (_key_down_handler)
+                    e_input_event_handler_del(input_event_source, _key_down_handler);
 
-             if (_key_up_handler)
-               e_input_event_handler_del(input_event_source, _key_up_handler);
+                  if (_key_up_handler)
+                    e_input_event_handler_del(input_event_source, _key_up_handler);
 
-             _key_down_handler = NULL;
-             _key_up_handler = NULL;
+                  _key_down_handler = NULL;
+                  _key_up_handler = NULL;
+               }
           }
 
         e_comp_ungrab_input(0, 1);
@@ -662,9 +677,16 @@ feed_key_event(const char *keyname, const char *key, const char *string, int key
    e->same_screen = 1;
    e->keycode = keycode;
 
-   E_Input_Event_Source *input_event_source = e_input_event_source_get();
-   if (input_event_source)
-     e_input_event_add(input_event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_keyevent_free, NULL);
+   if (!e_input_thread_mode_get())
+     {
+        ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_keyevent_free, NULL);
+     }
+   else
+     {
+        E_Input_Event_Source *input_event_source = e_input_event_source_get();
+        if (input_event_source)
+          e_input_event_add(input_event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_keyevent_free, NULL);
+     }
 }
 
 static void
@@ -1040,7 +1062,7 @@ _e_text_input_method_context_cb_resource_destroy(struct wl_resource *resource)
    free(context);
 }
 
-static gboolean
+static Eina_Bool
 _e_mod_ecore_key_down_cb(void *data, int type, void *event)
 {
    Ecore_Event_Key *ev = (Ecore_Event_Key *)event;
@@ -1053,12 +1075,24 @@ _e_mod_ecore_key_down_cb(void *data, int type, void *event)
    if (g_disable_show_panel == EINA_TRUE)
      return ECORE_CALLBACK_PASS_ON;
 
-   E_Device *dev = (E_Device *)ev->dev;
+   if (e_input_thread_mode_get())
+     {
+        E_Device *dev = (E_Device *)ev->dev;
 
-   /* process remote controller key exceptionally */
-   if (e_device_class_get(dev) == ECORE_DEVICE_CLASS_KEYBOARD &&
-       e_device_subclass_get(dev) == ECORE_DEVICE_SUBCLASS_REMOCON)
-     return ECORE_CALLBACK_PASS_ON;
+        /* process remote controller key exceptionally */
+        if (e_device_class_get(dev) == ECORE_DEVICE_CLASS_KEYBOARD &&
+            e_device_subclass_get(dev) == ECORE_DEVICE_SUBCLASS_REMOCON)
+          return ECORE_CALLBACK_PASS_ON;
+     }
+   else
+     {
+        Ecore_Device *dev = ev->dev;
+
+        /* process remote controller key exceptionally */
+        if (ecore_device_class_get(dev) == ECORE_DEVICE_CLASS_KEYBOARD &&
+            ecore_device_subclass_get(dev) == ECORE_DEVICE_SUBCLASS_REMOCON)
+          return ECORE_CALLBACK_PASS_ON;
+     }
 
    /* process up/down/left/right and some keys exceptionally */
    /* KP_XXX key is used as arrow key and number key in keypad, so ev->string is used for checking whether KP_XXX key is number key or not */
@@ -1126,11 +1160,22 @@ _e_text_input_deactivate(E_Text_Input *text_input, E_Input_Method *input_method,
                }
           }
 
-        if (e_input_key_down_filter)
+        if (e_input_thread_mode_get())
           {
-             E_Input_Event_Source *input_event_source = e_input_event_source_get();
-             e_input_event_filter_del(input_event_source, e_input_key_down_filter);
-             e_input_key_down_filter = NULL;
+             if (e_input_key_down_filter)
+               {
+                  E_Input_Event_Source *input_event_source = e_input_event_source_get();
+                  e_input_event_filter_del(input_event_source, e_input_key_down_filter);
+                  e_input_key_down_filter = NULL;
+               }
+          }
+        else
+          {
+             if (ecore_key_down_handler)
+               {
+                  ecore_event_handler_del(ecore_key_down_handler);
+                  ecore_key_down_handler = NULL;
+               }
           }
 
         LOGI("Resetting input_method->input : %p, text_input : %p, %p %p",
@@ -1222,9 +1267,19 @@ _e_text_input_cb_activate(struct wl_client *client, struct wl_resource *resource
 
    if (input_method->resource)
      {
-       E_Input_Event_Source *input_event_source = e_input_event_source_get();
-       if (!e_input_key_down_filter)
-         e_input_key_down_filter = e_input_event_filter_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_mod_ecore_key_down_cb, NULL);
+       if (!e_input_thread_mode_get())
+         {
+            if (!ecore_key_down_handler)
+              ecore_key_down_handler = ecore_event_handler_prepend(ECORE_EVENT_KEY_DOWN,
+                                                                   _e_mod_ecore_key_down_cb,
+                                                                   NULL);
+         }
+       else
+         {
+            E_Input_Event_Source *input_event_source = e_input_event_source_get();
+            if (!e_input_key_down_filter)
+              e_input_key_down_filter = e_input_event_filter_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_mod_ecore_key_down_cb, NULL);
+         }
 
         context = create_input_method_context(client, input_method);
         EINA_SAFETY_ON_NULL_GOTO(context, err);