Support to switch input thread mode 79/295179/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 4 May 2023 11:20:42 +0000 (20:20 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 4 Jul 2023 07:31:22 +0000 (07:31 +0000)
Change-Id: Ibdfb94419f75c40d820c88335ac38d06ebacb033
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
13 files changed:
src/bin/e_comp.c
src/bin/e_comp_wl.c
src/bin/e_config.c
src/bin/e_config.h
src/bin/e_devicemgr_input.c
src/bin/e_devicemgr_inputgen.c
src/bin/e_input.h
src/bin/e_input_evdev.c
src/bin/e_input_event.h
src/bin/e_input_inputs.c
src/bin/e_keyrouter.c
src/bin/e_keyrouter_events.c
src/bin/e_keyrouter_wl.c

index 54f3c6d..b4a6fde 100644 (file)
@@ -500,11 +500,14 @@ e_comp_shutdown(void)
    E_FREE_LIST(actions, e_object_del);
    E_FREE_LIST(hooks, e_client_hook_del);
 
-   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);
+        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);
+          }
      }
 
    _key_down_handler = NULL;
index 01cce49..2a67704 100644 (file)
@@ -5141,6 +5141,7 @@ _e_comp_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_sta
    uint32_t serial, keycode;
    struct wl_client *wc = NULL;
    E_Comp_Config *comp_conf = NULL;
+   const char *device_name = NULL;
 
    keycode = (ev->keycode - 8);
 
@@ -5156,10 +5157,22 @@ _e_comp_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_sta
         if (wl_resource_get_client(res) != wc) continue;
 
         TRACE_INPUT_BEGIN(_e_comp_wl_key_send);
-        _e_comp_wl_send_event_e_device(wc, ev->timestamp, dev, serial);
+        if (!e_input_thread_mode_get())
+          {
+             _e_comp_wl_send_event_device(wc, ev->timestamp, ev->dev, serial);
+             device_name = ecore_device_name_get(ev->dev);
+          }
+        else
+          {
+             if (dev)
+               {
+                  _e_comp_wl_send_event_e_device(wc, ev->timestamp, dev, serial);
+                  device_name = e_device_name_get(dev);
+               }
+          }
 
         if (comp_conf && comp_conf->input_log_enable)
-          ELOGF("Key", "Send Key %s (time: %d, device: %s)", ec, (state ? "Down" : "Up"), ev->timestamp, e_device_name_get(dev));
+          ELOGF("Key", "Send Key %s (time: %d, device: %s)", ec, (state ? "Down" : "Up"), ev->timestamp, device_name);
 
         wl_keyboard_send_key(res, serial, ev->timestamp,
                              keycode, state);
index 8864eb1..9bc3163 100644 (file)
@@ -323,6 +323,7 @@ _e_config_edd_init(Eina_Bool old)
    E_CONFIG_VAL(D, T, resize_object.border_width.b, INT);
    E_CONFIG_VAL(D, T, resize_object.image_path, STR);
    E_CONFIG_VAL(D, T, calc_vis_ignore_geometry, UINT);
+   E_CONFIG_VAL(D, T, input_thread_mode, UCHAR);
 }
 
 static Eina_Bool
@@ -582,6 +583,7 @@ e_config_load(void)
    E_CONFIG_LIMIT(e_config->resize_object.border_width.t, 0, 128);
    E_CONFIG_LIMIT(e_config->resize_object.border_width.b, 0, 128);
    E_CONFIG_LIMIT(e_config->calc_vis_ignore_geometry, 0, 1);
+   E_CONFIG_LIMIT(e_config->input_thread_mode, 0, 1);
 }
 
 EINTERN int
index 7cf9766..1445371 100644 (file)
@@ -313,6 +313,7 @@ struct _E_Config
    } resize_object;
 
    Eina_Bool calc_vis_ignore_geometry; // 0: unset ignore geometry, 1: ignore geometry calculate when the calculation of visibility.
+   Eina_Bool input_thread_mode; // 0: process key input event in main thread, 1: process key input event in input thread
 };
 
 struct _E_Config_Desklock_Background
index d036a13..8fca4bc 100644 (file)
@@ -170,8 +170,15 @@ _e_devicemgr_input_mouse_button_remap(Ecore_Event_Mouse_Button *ev, Eina_Bool pr
    ev_key->keycode = e_devicemgr->dconfig->conf->input.back_keycode;
    ev_key->data = key_data;
 
-   E_Input_Event_Source *input_event_source = e_input_event_source_get();
-   e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
+   if (e_input_thread_mode_get())
+     {
+        E_Input_Event_Source *input_event_source = e_input_event_source_get();
+        e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
+     }
+   else
+     {
+        ecore_event_add(pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
+     }
 
    return ECORE_CALLBACK_DONE;
 
index 6640815..30d3479 100644 (file)
@@ -77,6 +77,15 @@ _e_devicemgr_inputgen_key_event_free(void *data EINA_UNUSED, void *ev)
    eina_stringshare_del(e->key);
    eina_stringshare_del(e->compose);
 
+   if (e_input_thread_mode_get())
+     {
+        if (e->dev) g_object_unref(e->dev);
+     }
+   else
+     {
+        if (e->dev) ecore_device_unref(e->dev);
+     }
+
    if (e->data) E_FREE(e->data);
 
    free(e);
@@ -115,13 +124,27 @@ e_devicemgr_inputgen_key_event_add(const char *key, Eina_Bool pressed, char *ide
 
    e->modifiers = 0;
 
-   dev = e_input_evdev_get_e_device(identifier, ECORE_DEVICE_CLASS_KEYBOARD);
-   e->dev = (Eo *)dev;
+   if (e_input_thread_mode_get())
+     {
+        dev = e_input_evdev_get_e_device(identifier, ECORE_DEVICE_CLASS_KEYBOARD);
+        e->dev = (Eo *)g_object_ref(dev);
+     }
+   else
+     {
+        e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(identifier, ECORE_DEVICE_CLASS_KEYBOARD));
+     }
 
    DMDBG("Generate key event: key: %s, keycode: %d, iden: %s\n", e->key, e->keycode, identifier);
 
-   E_Input_Event_Source *input_event_source = e_input_event_source_get();
-   e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_devicemgr_inputgen_key_event_free, NULL);
+   if (e_input_thread_mode_get())
+     {
+        E_Input_Event_Source *input_event_source = e_input_event_source_get();
+        e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_devicemgr_inputgen_key_event_free, NULL);
+     }
+   else
+     {
+        ecore_event_add(pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_devicemgr_inputgen_key_event_free, NULL);
+     }
 
    return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
 
index da465bd..a5a0ffb 100644 (file)
@@ -149,6 +149,8 @@ EINTERN Eina_Bool e_input_device_seat_name_set(E_Input_Device *dev, const char *
 
 E_API E_Input_Hook *e_input_hook_add(E_Input_Hook_Point hookpoint, E_Input_Hook_Cb func, const void *data);
 E_API void e_input_hook_del(E_Input_Hook *ch);
+
+E_API Eina_Bool e_input_thread_mode_get();
 E_API E_Input_Event_Source *e_input_event_source_get();
 
 EINTERN Eina_Bool e_input_relative_motion_handler_set(e_input_relative_motion_cb handler);
index 9c8334f..ad5e1fe 100644 (file)
@@ -474,7 +474,15 @@ _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
 {
    Ecore_Event_Key *ev = event;
 
-   //if (ev->dev) ecore_device_unref(ev->dev);
+   if (e_input_thread_mode_get())
+     {
+        if (ev->dev) g_object_unref(ev->dev);
+     }
+   else
+     {
+        if (ev->dev) ecore_device_unref(ev->dev);
+     }
+
    if (ev->data) E_FREE(ev->data);
 
    free(ev);
@@ -712,18 +720,29 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
    e->same_screen = 1;
    e->keycode = code;
    e->data = key_data;
-   e->dev = (Eo *)e_dev;
 
    _device_modifiers_update(edev);
 
    e->modifiers = edev->xkb.modifiers;
 
    comp_conf = e_comp_config_get();
-   if (comp_conf && comp_conf->input_log_enable)
-     ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e_device_name_get(e_dev));
 
-   e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
+   if (e_input_thread_mode_get())
+     {
+        e->dev = (Eo *)g_object_ref(e_dev);
+        if (comp_conf && comp_conf->input_log_enable)
+          ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e_device_name_get(e_dev));
 
+        e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
+     }
+   else
+     {
+        e->dev = ecore_device_ref(ecore_dev);
+        if (comp_conf && comp_conf->input_log_enable)
+          ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(ecore_dev));
+
+        ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
+     }
    if (tmp) free(tmp);
 }
 
index 8b75ec0..ac0ef18 100755 (executable)
@@ -7,7 +7,7 @@
 #ifndef E_INPUT_EVENT_H
 #define E_INPUT_EVENT_H
 
-typedef gboolean (*ev_handler_func)(void *func_data, int type, void *user_data);
+typedef Eina_Bool (*ev_handler_func)(void *func_data, int type, void *user_data);
 typedef void (*ev_free_func)(void *user_data, void *event_data);
 
 struct _e_input_event_handler {
index 15a8812..b03e088 100644 (file)
@@ -523,6 +523,22 @@ _input_events_process(E_Input_Backend *input)
      }
 }
 
+static Eina_Bool
+_cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
+{
+   E_Input_Backend *input;
+
+   if (!(input = data)) return EINA_TRUE;
+
+   if (libinput_dispatch(input->libinput) != 0)
+     ERR("Failed to dispatch libinput events: %m");
+
+   /* process pending events */
+   _input_events_process(input);
+
+   return EINA_TRUE;
+}
+
 static gboolean
 input_thread_prepare(GSource *source, gint *time)
 {
@@ -647,15 +663,45 @@ e_input_enable_input(E_Input_Backend *input)
 
    input->fd = libinput_get_fd(input->libinput);
 
+   if (!e_input_thread_mode_get())
+     {
+        if (!input->hdlr)
+          {
+             input->hdlr =
+                ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
+                                          _cb_input_dispatch, input, NULL, NULL);
+          }
+
+        if (input->suspended)
+          {
+             if (libinput_resume(input->libinput) != 0)
+               goto err;
+
+             input->suspended = EINA_FALSE;
+
+             /* process pending events */
+             _input_events_process(input);
+          }
+     }
+
    input->enabled = EINA_TRUE;
    input->suspended = EINA_FALSE;
 
-   input->input_thread = ecore_thread_feedback_run(input_thread_start, input_thread_feedback, input_thread_end, input_thread_cancel, input, EINA_FALSE);
+   if (e_input_thread_mode_get())
+     {
+        input->input_thread = ecore_thread_feedback_run(input_thread_start, input_thread_feedback, input_thread_end, input_thread_cancel, input, EINA_FALSE);
+     }
 
    return EINA_TRUE;
 
 err:
    input->enabled = EINA_FALSE;
+   if (!e_input_thread_mode_get())
+     {
+        if (input->hdlr)
+          ecore_main_fd_handler_del(input->hdlr);
+        input->hdlr = NULL;
+     }
 
    return EINA_FALSE;
 }
@@ -674,8 +720,11 @@ e_input_disable_input(E_Input_Backend *input)
 
    input->suspended = EINA_TRUE;
 
-   if (input->input_thread && !ecore_thread_check(input->input_thread))
-     ecore_thread_cancel(input->input_thread);
+   if (e_input_thread_mode_get())
+     {
+        if (input->input_thread && !ecore_thread_check(input->input_thread))
+          ecore_thread_cancel(input->input_thread);
+     }
 }
 
 EINTERN Eina_List *
@@ -689,4 +738,13 @@ E_API E_Input_Event_Source *
 e_input_event_source_get()
 {
    return g_input_event_source;
-}
\ No newline at end of file
+}
+
+E_API Eina_Bool
+e_input_thread_mode_get()
+{
+   if (e_config)
+     return e_config->input_thread_mode;
+   else
+     return EINA_TRUE;
+}
index 4560d99..ac613fb 100644 (file)
@@ -272,7 +272,7 @@ _e_keyrouter_keygrab_print(void *data, const char *log_path)
    log_fl = NULL;
 }
 
-static gboolean
+static Eina_Bool
 _e_keyrouter_cb_key_down(void *data, int type, void *event)
 {
    Ecore_Event_Key *ev;
@@ -287,7 +287,7 @@ _e_keyrouter_cb_key_down(void *data, int type, void *event)
    return e_keyrouter_event_process(event, (E_Device *)ev->dev, type);
 }
 
-static gboolean
+static Eina_Bool
 _e_keyrouter_cb_key_up(void *data, int type, void *event)
 {
    Ecore_Event_Key *ev;
@@ -348,11 +348,19 @@ _e_keyrouter_init_handlers(void)
    E_LIST_HANDLER_APPEND(krt->handlers, E_EVENT_CLIENT_STACK, _e_keyrouter_client_cb_stack, NULL);
    E_LIST_HANDLER_APPEND(krt->handlers, E_EVENT_CLIENT_REMOVE, _e_keyrouter_client_cb_remove, NULL);
 
-   input_event_source = e_input_event_source_get();
-   if (input_event_source)
+   if (!e_input_thread_mode_get())
      {
-        krt->_key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_keyrouter_cb_key_down, NULL);
-        krt->_key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_keyrouter_cb_key_up, NULL);
+        E_LIST_HANDLER_APPEND(krt->handlers, ECORE_EVENT_KEY_DOWN, _e_keyrouter_cb_key_down, NULL);
+        E_LIST_HANDLER_APPEND(krt->handlers, ECORE_EVENT_KEY_UP, _e_keyrouter_cb_key_up, NULL);
+     }
+   else
+     {
+        input_event_source = e_input_event_source_get();
+        if (input_event_source)
+          {
+             krt->_key_down_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_DOWN, _e_keyrouter_cb_key_down, NULL);
+             krt->_key_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_KEY_UP, _e_keyrouter_cb_key_up, NULL);
+          }
      }
 
    e_info_server_hook_set("keyrouter", _e_keyrouter_info_print, NULL);
@@ -370,18 +378,21 @@ _e_keyrouter_deinit_handlers(void)
    EINA_LIST_FREE(krt->handlers, h)
      ecore_event_handler_del(h);
 
-   input_event_source = e_input_event_source_get();
-   if (input_event_source)
+   if (e_input_thread_mode_get())
      {
-        if (krt->_key_down_handler)
-          e_input_event_handler_del(input_event_source, krt->_key_down_handler);
+        input_event_source = e_input_event_source_get();
+        if (input_event_source)
+          {
+             if (krt->_key_down_handler)
+               e_input_event_handler_del(input_event_source, krt->_key_down_handler);
 
-        if (krt->_key_up_handler)
-          e_input_event_handler_del(input_event_source, krt->_key_up_handler);
-     }
+             if (krt->_key_up_handler)
+               e_input_event_handler_del(input_event_source, krt->_key_up_handler);
+          }
 
-   krt->_key_down_handler = NULL;
-   krt->_key_up_handler = NULL;
+        krt->_key_down_handler = NULL;
+        krt->_key_up_handler = NULL;
+     }
 
    e_info_server_hook_set("keyrouter", NULL, NULL);
    e_info_server_hook_set("keygrab", NULL, NULL);
index 49232c4..b4eab68 100644 (file)
@@ -79,8 +79,15 @@ _e_keyrouter_key_free(Ecore_Event_Key *ev)
    eina_stringshare_del(ev->string);
    eina_stringshare_del(ev->compose);
 
+   if (e_input_thread_mode_get())
+     {
+        if (ev->dev) g_object_unref(ev->dev);
+     }
+   else
+     {
+        if (ev->dev) ecore_device_unref(ev->dev);
+     }
    if (ev->data) E_FREE(ev->data);
-   if (ev->dev) ecore_device_unref(ev->dev);
 
    E_FREE(ev);
 }
index 6d89682..e3b431b 100644 (file)
@@ -47,8 +47,15 @@ _e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_ke
         wc = wl_resource_get_client(res);
         if (!focused && wc != client) continue;
         TRACE_INPUT_BEGIN(_e_comp_wl_key_send);
-        if (dev)
-          e_comp_wl_send_event_e_device(client, ev->timestamp, dev, serial);
+        if (!e_input_thread_mode_get())
+          {
+             e_comp_wl_send_event_device(client, ev->timestamp, ev->dev, serial);
+          }
+        else
+          {
+             if (dev)
+               e_comp_wl_send_event_e_device(client, ev->timestamp, dev, serial);
+          }
 
         if (comp_conf && comp_conf->input_log_enable)
           INF("[Server] Routed Key %s (time: %d)\n", (state ? "Down" : "Up"), ev->timestamp);