e_input_evdev: generate pointer ecore event asynchronously 67/318467/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Sep 2024 05:15:04 +0000 (14:15 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 30 Sep 2024 07:36:56 +0000 (16:36 +0900)
Change-Id: I00af6335135c9dfcfd84d76ce3fc42e5f7ddf16d
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_evdev.c

index 359edc5a5dca9dfcd05b8ec2711df1ae853d29ea..e98c99a66ffafb2869482f4d222d104a4400b69c 100644 (file)
@@ -27,6 +27,7 @@ struct _E_Input_Pending_Event {
 typedef struct _E_Input_Event
 {
    E_Input_Evdev *evdev;
+   Eina_Bool touch_event;
    int event_type;
    void *ev;
    ev_free_func free_func;
@@ -37,6 +38,8 @@ 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);
 
+static void  _pointer_touch_ecore_event_add(void *data);
+
 static Eina_Bool _touch_blocked_by_palm, _touch_up_blocked_by_palm;
 
 void
@@ -951,12 +954,12 @@ _input_thread_mode_pointer_device_get(E_Input_Evdev *evdev)
 static void
 _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *event)
 {
-   Ecore_Device *ecore_dev = NULL;
    E_Device *e_dev = NULL;
    Ecore_Event_Mouse_Move *ev;
    E_Input_Backend *input;
    uint32_t timestamp = 0;
    const char *device_name = evdev->name;
+   E_Input_Event_Info *input_event = NULL;
 
    if (!(input = evdev->seat->input)) return;
    if (event)
@@ -1010,13 +1013,15 @@ _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *even
      }
    else
      {
-        ecore_thread_main_loop_begin();
-
-        ecore_dev = _main_thread_mode_pointer_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
+        input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->touch_event = EINA_FALSE;
+        input_event->evdev = evdev;
+        input_event->ev = ev;
+        input_event->event_type = ECORE_EVENT_MOUSE_MOVE;
+        input_event->free_func = _e_input_event_mouse_move_cb_free;
+        input_event->free_func_data = NULL;
 
-        ecore_thread_main_loop_end();
+        ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
      }
 }
 
@@ -1282,10 +1287,10 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
    Ecore_Event_Mouse_Button *ev;
    enum libinput_button_state state;
    uint32_t button, timestamp;
-   Ecore_Device *ecore_dev = NULL;
    E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
    const char *device_name = NULL;
+   E_Input_Event_Info *input_event = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
@@ -1409,13 +1414,15 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
      }
    else
      {
-        ecore_thread_main_loop_begin();
-
-        ecore_dev = _main_thread_mode_pointer_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_event_add(state ? ECORE_EVENT_MOUSE_BUTTON_DOWN : ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
+        input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->touch_event =  EINA_FALSE;
+        input_event->evdev = evdev;
+        input_event->ev = ev;
+        input_event->event_type = state? ECORE_EVENT_MOUSE_BUTTON_DOWN : ECORE_EVENT_MOUSE_BUTTON_UP;
+        input_event->free_func = _e_input_event_mouse_button_cb_free;
+        input_event->free_func_data = NULL;
 
-        ecore_thread_main_loop_end();
+        ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
      }
 }
 
@@ -1474,6 +1481,7 @@ e_input_evdev_handle_axis(E_Input_Evdev *evdev, struct libinput_event_pointer *e
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
    const char *device_name = NULL;
+   E_Input_Event_Info *input_event = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
@@ -1502,40 +1510,6 @@ e_input_evdev_handle_axis(E_Input_Evdev *evdev, struct libinput_event_pointer *e
        return;
     }
 
-   ecore_thread_main_loop_begin();
-
-   if (evdev->ecore_dev) ecore_dev = evdev->ecore_dev;
-   else if (evdev->ecore_dev_list && eina_list_count(evdev->ecore_dev_list) > 0)
-     {
-        EINA_LIST_FOREACH(evdev->ecore_dev_list, l, data)
-          {
-             if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
-               {
-                  ecore_dev = data;
-                  break;
-               }
-             else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
-               {
-                  detent_data = data;
-               }
-          }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
-          {
-             ecore_dev = detent_data;
-          }
-     }
-   else
-     {
-        evdev->ecore_dev = e_input_evdev_ecore_device_get(evdev->path, ECORE_DEVICE_CLASS_MOUSE);
-        ecore_dev = evdev->ecore_dev;
-     }
-
-   if (!ecore_dev)
-     {
-        ERR("Failed to get source ecore device from event !\n");
-        goto end;
-     }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->e_wheel_click_angle)
      {
@@ -1554,13 +1528,10 @@ e_input_evdev_handle_axis(E_Input_Evdev *evdev, struct libinput_event_pointer *e
           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
                 direction, z, blocked_client, evdev->seat->dev->server_blocked);
 
-        goto end;
+        return;
      }
 
-   if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
-     {
-        goto end;
-     }
+   if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)))) return;
 
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
@@ -1586,11 +1557,24 @@ e_input_evdev_handle_axis(E_Input_Evdev *evdev, struct libinput_event_pointer *e
           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
      }
 
-   ev->dev = ecore_device_ref(ecore_dev);
-   ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
+   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
+     {
+        e_dev = _input_thread_mode_pointer_device_get(evdev);
+        ev->dev = (Eo *)g_object_ref(e_dev);
+        e_input_event_add(input->event_source, ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
+     }
+   else
+     {
+        input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->touch_event =  EINA_FALSE;
+        input_event->evdev = evdev;
+        input_event->ev = ev;
+        input_event->event_type = ECORE_EVENT_MOUSE_WHEEL;
+        input_event->free_func = _e_input_event_mouse_wheel_cb_free;
+        input_event->free_func_data = NULL;
 
-end:
-   ecore_thread_main_loop_end();
+        ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
+     }
 }
 #endif
 
@@ -1651,10 +1635,11 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
    Ecore_Event_Mouse_Wheel *ev;
    uint32_t timestamp;
    enum libinput_pointer_axis axis;
-   Ecore_Device *ecore_dev = NULL, *detent_data = NULL;
+   Ecore_Device *detent_data = NULL;
    E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
+   E_Input_Event_Info *input_event = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
@@ -1739,11 +1724,15 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
      }
    else
      {
-        ecore_thread_main_loop_begin();
-        ecore_dev = _main_thread_mode_pointer_device_get(evdev);
-        ev->dev = ecore_device_ref(ecore_dev);
-        ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
-        ecore_thread_main_loop_end();
+        input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->touch_event =  EINA_FALSE;
+        input_event->evdev = evdev;
+        input_event->ev = ev;
+        input_event->event_type = ECORE_EVENT_MOUSE_WHEEL;
+        input_event->free_func = _e_input_event_mouse_wheel_cb_free;
+        input_event->free_func_data = NULL;
+
+        ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
      }
 }
 #endif
@@ -1837,18 +1826,26 @@ _touch_event_pending_add(E_Input_Evdev *edev, int type, void *event)
 }
 
 static void
-_touch_ecore_event_add(void *data)
+_pointer_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->touch)
+     ecore_dev = _main_thread_mode_touch_device_get(input_info->evdev);
+   else
+     ecore_dev = _main_thread_mode_pointer_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_WHEEL)
+     {
+        Ecore_Event_Mouse_Wheel *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)
@@ -1876,13 +1873,14 @@ _input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func fr
    else
      {
         input_event = E_NEW(E_Input_Event_Info, 1);
+        input_event->touch_event =  EINA_TRUE;
         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);
+        ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
      }
 }