e_input_evdev: generate touch ecore event asynchronously 66/318466/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Sep 2024 02:43:44 +0000 (11:43 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 30 Sep 2024 07:36:56 +0000 (16:36 +0900)
Change-Id: Ib9203fb7cba2947dca2c67472549bee2162cf12f
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_evdev.c

index aa3ad633f49f5b9b22560b17a162e7793973432c..359edc5a5dca9dfcd05b8ec2711df1ae853d29ea 100644 (file)
@@ -24,6 +24,15 @@ struct _E_Input_Pending_Event {
    void *event;
 };
 
+typedef struct _E_Input_Event
+{
+   E_Input_Evdev *evdev;
+   int event_type;
+   void *ev;
+   ev_free_func free_func;
+   void *free_func_data;
+} E_Input_Event_Info;
+
 static void  _device_modifiers_update(E_Input_Evdev *evdev);
 static void  _device_configured_size_get(E_Input_Evdev *evdev, int *x, int *y, int *w, int *h);
 static void  _device_output_assign(E_Input_Evdev *evdev, E_Input_Seat_Capabilities cap);
@@ -1827,10 +1836,38 @@ _touch_event_pending_add(E_Input_Evdev *edev, int type, void *event)
    return EINA_TRUE;
 }
 
+static void
+_touch_ecore_event_add(void *data)
+{
+   E_Input_Event_Info *input_info = data;
+   Ecore_Device *ecore_dev = NULL;
+
+   ecore_dev = _main_thread_mode_touch_device_get(input_info->evdev);
+
+   if (input_info->event_type == ECORE_EVENT_MOUSE_MOVE)
+     {
+        Ecore_Event_Mouse_Move *ev = input_info->ev;
+        ev->dev = ecore_device_ref(ecore_dev);
+     }
+   else if (input_info->event_type == ECORE_EVENT_MOUSE_BUTTON_DOWN ||
+            input_info->event_type == ECORE_EVENT_MOUSE_BUTTON_UP ||
+            input_info->event_type == ECORE_EVENT_MOUSE_BUTTON_CANCEL)
+     {
+        Ecore_Event_Mouse_Button *ev = input_info->ev;
+        ev->dev = ecore_device_ref(ecore_dev);
+     }
+
+   ecore_event_add(input_info->event_type, input_info->ev, input_info->free_func, input_info->free_func_data);
+
+   free(input_info);
+}
+
 static void
 _input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func free_func, void *free_func_data)
 {
    E_Input_Backend *input;
+   E_Input_Event_Info *input_event = NULL;
+
    if (!(input = evdev->seat->input))
      return;
 
@@ -1838,9 +1875,14 @@ _input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func fr
      e_input_event_add(input->event_source, event_type, ev, free_func, free_func_data);
    else
      {
-        ecore_thread_main_loop_begin();
-        ecore_event_add(event_type, ev, free_func, free_func_data);
-        ecore_thread_main_loop_end();
+        input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->evdev = evdev;
+        input_event->event_type = event_type;
+        input_event->ev = ev;
+        input_event->free_func = free_func;
+        input_event->free_func_data = free_func_data;
+
+        ecore_main_loop_thread_safe_call_async(_touch_ecore_event_add, input_event);
      }
 }
 
@@ -1873,7 +1915,6 @@ _device_handle_touch_event_send(E_Input_Evdev *evdev, struct libinput_event_touc
    E_Input_Backend *input;
    Ecore_Event_Mouse_Button *ev;
    uint32_t timestamp, button = 0;
-   Ecore_Device *ecore_dev = NULL;
    E_Device *e_dev = NULL;
    double radius_x = 1;
    double radius_y = 1;
@@ -1972,13 +2013,6 @@ _device_handle_touch_event_send(E_Input_Evdev *evdev, struct libinput_event_touc
         e_dev = _input_thread_mode_touch_device_get(evdev);
         ev->dev = (Eo *)g_object_ref(e_dev);
      }
-   else
-     {
-        ecore_thread_main_loop_begin();
-        ecore_dev = _main_thread_mode_touch_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_thread_main_loop_end();
-     }
 
    if (!_touch_event_pending_add(evdev, state, ev))
      {
@@ -1994,7 +2028,6 @@ _device_handle_touch_motion_send(E_Input_Evdev *evdev, struct libinput_event_tou
 {
    E_Input_Backend *input;
    Ecore_Event_Mouse_Move *ev;
-   Ecore_Device *ecore_dev = NULL;
    E_Device *e_dev = NULL;
    uint32_t timestamp = 0;
    double radius_x = 1.0, radius_y = 1.0, pressure = 1.0, angle = 0.0;
@@ -2046,13 +2079,6 @@ _device_handle_touch_motion_send(E_Input_Evdev *evdev, struct libinput_event_tou
         e_dev = _input_thread_mode_touch_device_get(evdev);
         ev->dev = (Eo *)g_object_ref(e_dev);
      }
-   else
-     {
-        ecore_thread_main_loop_begin();
-        ecore_dev = _main_thread_mode_touch_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_thread_main_loop_end();
-     }
 
    if (!_touch_event_pending_add(evdev, ECORE_EVENT_MOUSE_MOVE, ev))
      {
@@ -2067,7 +2093,6 @@ _device_handle_touch_cancel_send(E_Input_Evdev *evdev, struct libinput_event_tou
    E_Input_Backend *input;
    Ecore_Event_Mouse_Button *ev;
    uint32_t timestamp, button = 0;
-   Ecore_Device *ecore_dev = NULL;
    E_Device *e_dev = NULL;
 
    if (!evdev) return;
@@ -2108,13 +2133,6 @@ _device_handle_touch_cancel_send(E_Input_Evdev *evdev, struct libinput_event_tou
         e_dev = _input_thread_mode_touch_device_get(evdev);
         ev->dev = (Eo *)g_object_ref(e_dev);
      }
-   else
-     {
-        ecore_thread_main_loop_begin();
-        ecore_dev = _main_thread_mode_touch_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_thread_main_loop_end();
-     }
 
    if (!_touch_event_pending_add(evdev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev))
      {
@@ -2397,17 +2415,21 @@ e_input_evdev_handle_touch_cancel(E_Input_Evdev *evdev, struct libinput_event_to
    _device_handle_touch_cancel_send(evdev, event);
 }
 
+static void
+_touch_frame_event_add(void *data)
+{
+   E_Input_Evdev *evdev = data;
+
+   _touch_event_pending_flush(evdev);
+   ecore_event_add(E_EVENT_INPUT_TOUCH_FRAME, NULL, NULL, NULL);
+}
 
 EINTERN void
 e_input_evdev_handle_touch_frame(E_Input_Evdev *evdev, struct libinput_event_touch *event)
 {
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
-   ecore_thread_main_loop_begin();
-   _touch_event_pending_flush(evdev);
-   ecore_event_add(E_EVENT_INPUT_TOUCH_FRAME, NULL, NULL, NULL);
-
-   ecore_thread_main_loop_end();
+   ecore_main_loop_thread_safe_call_async(_touch_frame_event_add, evdev);
 }
 
 static void