e_input_evdev: generate pointer ecore event asynchronously 26/318926/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Sep 2024 05:15:04 +0000 (14:15 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 28 Oct 2024 03:06:08 +0000 (12:06 +0900)
Change-Id: I00af6335135c9dfcfd84d76ce3fc42e5f7ddf16d
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/e_input_evdev.c

index aa7d12b7efd7a7570772006a560f2896e596d73f..25e2befcf28f8eb075f2ec748fe51953d207293f 100644 (file)
@@ -19,6 +19,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;
@@ -29,6 +30,8 @@ static void  _device_modifiers_update(E_Input_Evdev *edev);
 static void  _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
 static void  _device_output_assign(E_Input_Evdev *edev, 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
@@ -845,24 +848,21 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
    if (tmp) free(tmp);
 }
 
-static void
-_device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
+static Ecore_Device *
+_pointer_device_get(E_Input_Evdev *evdev)
 {
    E_Input_Backend *input;
-   Ecore_Event_Mouse_Move *ev;
    Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
    Eina_List *l;
-   int x = 0, y = 0, w = 0, h = 0;
-   const char *device_name = edev->name;
-
-   if (!(input = edev->seat->input)) return;
+   const char *device_name = NULL;
 
-   ecore_thread_main_loop_begin();
+   if (!(input = evdev->seat->input)) return NULL;
+   device_name = evdev->name;
 
-   if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
-   else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
+   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(edev->ecore_dev_list, l, data)
+        EINA_LIST_FOREACH(evdev->ecore_dev_list, l, data)
           {
              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
                {
@@ -881,21 +881,35 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event
      }
    else
      {
-        edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
-        ecore_dev = edev->ecore_dev;
+        evdev->ecore_dev = e_input_evdev_get_ecore_device(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;
+        return NULL;
      }
    else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
      {
         /* Do not process detent device's move events. */
-        goto end;
+        return NULL;
      }
 
+   return ecore_dev;
+}
+
+static void
+_device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
+{
+   E_Input_Backend *input;
+   Ecore_Event_Mouse_Move *ev;
+   int x = 0, y = 0, w = 0, h = 0;
+   const char *device_name = edev->name;
+   E_Input_Event_Info *input_event = NULL;
+
+   if (!(input = edev->seat->input)) return;
+
    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
 
    _device_configured_size_get(edev, &x, &y, &w, &h);
@@ -948,12 +962,15 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event
    ev->multi.root.x = ev->x;
    ev->multi.root.y = ev->y;
 
-   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 = edev;
+   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;
 
-end:
-   ecore_thread_main_loop_end();
+   ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
 }
 
 void
@@ -1163,10 +1180,9 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
    Ecore_Event_Mouse_Button *ev;
    enum libinput_button_state state;
    uint32_t button, timestamp;
-   Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
-   Eina_List *l;
    E_Comp_Config *comp_conf = NULL;
    const char *device_name = NULL;
+   E_Input_Event_Info *input_event = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
@@ -1177,40 +1193,6 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
         return;
      }
 
-   ecore_thread_main_loop_begin();
-
-   if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
-   else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
-     {
-        EINA_LIST_FOREACH(edev->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(libinput_device_get_name(edev->device)))
-          {
-             ecore_dev = detent_data;
-          }
-     }
-   else
-     {
-        edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
-        ecore_dev = edev->ecore_dev;
-     }
-
-   if (!ecore_dev)
-     {
-        ERR("Failed to get source ecore device from event !\n");
-        goto end;
-     }
-
    state = libinput_event_pointer_get_button_state(event);
    button = libinput_event_pointer_get_button(event);
    timestamp = libinput_event_pointer_get_time(event);
@@ -1231,7 +1213,7 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
              ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
                    button, device_name, blocked_client,
                    edev->seat->dev->server_blocked);
-             goto end;
+             return;
           }
         else
           {
@@ -1243,17 +1225,14 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
         if (!(edev->mouse.pressed_button & (1 << button)))
           {
              ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
-                   button, ecore_device_name_get(ecore_dev), blocked_client,
+                   button, device_name, blocked_client,
                    edev->seat->dev->server_blocked);
-             goto end;
+             return;
           }
         edev->mouse.pressed_button &= ~(1 << button);
      }
 
-   if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
-     {
-        goto end;
-     }
+   if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
 
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
@@ -1279,7 +1258,6 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
    ev->multi.y = ev->y;
    ev->multi.root.x = ev->x;
    ev->multi.root.y = ev->y;
-   ev->dev = ecore_device_ref(ecore_dev);
 
    if (state)
      {
@@ -1320,13 +1298,15 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
    if (comp_conf && comp_conf->input_log_enable)
      ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
 
-   if (state)
-     ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
-   else
-     ecore_event_add(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 = edev;
+   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;
 
-end:
-   ecore_thread_main_loop_end();
+   ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
 }
 
 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
@@ -1397,40 +1377,6 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
 
    device_name = edev->name;
 
-   ecore_thread_main_loop_begin();
-
-   if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
-   else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
-     {
-        EINA_LIST_FOREACH(edev->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(libinput_device_get_name(edev->device)))
-          {
-             ecore_dev = detent_data;
-          }
-     }
-   else
-     {
-        edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
-        ecore_dev = edev->ecore_dev;
-     }
-
-   if (!ecore_dev)
-     {
-        ERR("Failed to get source ecore device from event !\n");
-        goto end;
-     }
-
    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
    if (libinput_event_pointer_has_axis(event, axis))
      z = _axis_value_get(event, axis);
@@ -1445,7 +1391,7 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
   if (z == 0)
     {
        ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
-       goto end;
+       return;
     }
 
    comp_conf = e_comp_config_get();
@@ -1466,13 +1412,10 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
                 direction, z, blocked_client, edev->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;
 
    timestamp = libinput_event_pointer_get_time(event);
 
@@ -1500,12 +1443,15 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
      }
 
+   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;
 
-   ev->dev = ecore_device_ref(ecore_dev);
-   ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
-
-end:
-   ecore_thread_main_loop_end();
+   ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
 }
 #endif
 
@@ -1567,10 +1513,10 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
    Ecore_Event_Mouse_Wheel *ev;
    uint32_t timestamp;
    enum libinput_pointer_axis axis;
-   Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
-   Eina_List *l;
+   Ecore_Device *detent_data = NULL;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
+   E_Input_Event_Info *input_event = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
@@ -1581,40 +1527,6 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
         return;
      }
 
-   ecore_thread_main_loop_begin();
-
-   if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
-   else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
-     {
-        EINA_LIST_FOREACH(edev->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(libinput_device_get_name(edev->device)))
-          {
-             ecore_dev = detent_data;
-          }
-     }
-   else
-     {
-        edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
-        ecore_dev = edev->ecore_dev;
-     }
-
-   if (!ecore_dev)
-     {
-        ERR("Failed to get source ecore device from event !\n");
-        goto end;
-     }
-
    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
    if (libinput_event_pointer_has_axis(event, axis))
      z = _scroll_value_get(event, axis, source);
@@ -1629,7 +1541,7 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
    if (z == 0)
      {
         ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
-        goto end;
+        return;
      }
 
    comp_conf = e_comp_config_get();
@@ -1649,13 +1561,10 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
                 direction, z, blocked_client, edev->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;
 
    timestamp = libinput_event_pointer_get_time(event);
 
@@ -1683,11 +1592,15 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
           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);
+   input_event = E_NEW(E_Input_Event_Info, 1);
+   input_event->touch_event =  EINA_FALSE;
+   input_event->evdev = edev;
+   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
 
@@ -1741,18 +1654,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 = _touch_device_get(input_info->evdev);
+   if (input_info->touch_event)
+     ecore_dev = _touch_device_get(input_info->evdev);
+   else
+     ecore_dev = _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)
@@ -1776,13 +1697,14 @@ _input_thread_ecore_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev
      return;
 
    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);
 }
 
 static void