e_input_evdev: modify code for generating touch event 60/312060/3
authorDoyoun Kang <doyoun.kang@samsung.com>
Mon, 3 Jun 2024 10:46:22 +0000 (19:46 +0900)
committerDoyoun Kang <doyoun.kang@samsung.com>
Tue, 4 Jun 2024 05:44:22 +0000 (14:44 +0900)
We change the log for generating touch event.
- Current: Call ecore_event_add whenever a touch event occur
- Modify : When touch event occur, instead of immediately calling ecore_event_add,
           it waits until the "frame" event occurs and then calls the ecore_event_add

Change-Id: Ia3e37b77a9c17bd94592e9d4a75c22560e081350

src/bin/e_input_evdev.c
src/bin/e_input_private.h

index dbc3433b286ff1c172999c45e4d4b602273ee704..6f8ca90ad726dbfa20aa699305b5bf98a43e1305 100644 (file)
@@ -9,6 +9,13 @@
 
 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
 
+typedef struct _E_Input_Pending_Event E_Input_Pending_Event;
+
+struct _E_Input_Pending_Event {
+   int type;
+   void *event;
+};
+
 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);
@@ -1664,6 +1671,45 @@ end:
 }
 #endif
 
+static Eina_Bool
+_touch_event_pending_add(E_Input_Evdev *edev, int type, void *event)
+{
+   E_Input_Pending_Event *pending_event;
+
+   pending_event = E_NEW(E_Input_Pending_Event, 1);
+   if (!pending_event) return EINA_FALSE;
+
+   pending_event->type = type;
+   pending_event->event = event;
+
+   edev->pending_touch_event = eina_list_append(edev->pending_touch_event, pending_event);
+
+   return EINA_TRUE;
+}
+
+static void
+_touch_event_pending_flush(E_Input_Evdev *edev)
+{
+   E_Input_Pending_Event *ev;
+
+   EINA_LIST_FREE(edev->pending_touch_event, ev)
+     {
+        if ((ev->type == ECORE_EVENT_MOUSE_BUTTON_DOWN) ||
+            (ev->type == ECORE_EVENT_MOUSE_BUTTON_UP))
+          ecore_event_add(ev->type, ev->event, _e_input_event_mouse_button_cb_free, NULL);
+        else if (ev->type == ECORE_EVENT_MOUSE_MOVE)
+          ecore_event_add(ev->type, ev->event, _e_input_event_mouse_move_cb_free, NULL);
+        else if (ev->type == ECORE_EVENT_MOUSE_BUTTON_CANCEL)
+          ecore_event_add(ev->type, ev->event, _e_input_event_mouse_button_cb_free, NULL);
+        else
+          ELOGF("CRI", "NOT Supported pending event. type:%d", NULL, ev->type);
+
+        E_FREE(ev);
+     }
+
+   edev->pending_touch_event = NULL;
+}
+
 static void
 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
 {
@@ -1786,7 +1832,12 @@ _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch
    if (edev->mouse.did_triple)
      ev->triple_click = 1;
 
-   ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
+   if (!_touch_event_pending_add(edev, state, ev))
+     {
+        ELOGF("Touch", "Failed to pend event (%s). Call ecore_event_add imediately.", NULL,
+              state == ECORE_EVENT_MOUSE_BUTTON_DOWN ? "DOWN" : "UP");
+        ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
+     }
 
 end:
    ecore_thread_main_loop_end();
@@ -1867,7 +1918,11 @@ _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touc
    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);
+   if (!_touch_event_pending_add(edev, ECORE_EVENT_MOUSE_MOVE, ev))
+     {
+        ELOGF("Touch", "Failed to pend event (MOVE). Call ecore_event_add imediately.", NULL);
+        ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
+     }
 
 end:
    ecore_thread_main_loop_end();
@@ -1942,7 +1997,11 @@ _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touc
    ev->buttons = ((button & 0x00F) + 1);
    ev->dev = ecore_device_ref(ecore_dev);
 
-   ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
+   if (!_touch_event_pending_add(edev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev))
+     {
+        ELOGF("Touch", "Failed to pend event (CANCEL). Call ecore_event_add imediately.", NULL);
+        ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
+     }
 
 end:
    ecore_thread_main_loop_end();
@@ -2209,9 +2268,16 @@ _device_handle_touch_cancel(struct libinput_device *device, struct libinput_even
 
 
 static void
-_device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
+_device_handle_touch_frame(struct libinput_device *device, struct libinput_event_touch *event)
 {
-   /* DBG("Unhandled Touch Frame Event"); */
+   E_Input_Evdev *edev;
+
+   if (!(edev = libinput_device_get_user_data(device)))
+     return;
+
+   ecore_thread_main_loop_begin();
+   _touch_event_pending_flush(edev);
+   ecore_thread_main_loop_end();
 }
 
 static void
@@ -2384,6 +2450,7 @@ void
 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
 {
    Ecore_Device *dev;
+   E_Input_Pending_Event *ev;
    E_Input *e_input = e_input_get();
 
    EINA_SAFETY_ON_NULL_RETURN(edev);
@@ -2433,6 +2500,15 @@ _e_input_evdev_device_destroy(E_Input_Evdev *edev)
      }
    eina_stringshare_del(edev->output_name);
 
+   if (edev->pending_touch_event)
+     {
+        EINA_LIST_FREE(edev->pending_touch_event, ev)
+          {
+             E_FREE(ev->event);
+             E_FREE(ev);
+          }
+     }
+
    ecore_thread_main_loop_end();
 
    free(edev);
index 8d0a52614da41ee5a0a26a0cea29eb3476ce8aaf..aca3b3e8ce6023d415f07c93b7bd63039b5e2d9e 100644 (file)
@@ -163,6 +163,8 @@ struct _E_Input_Evdev
    Eina_Bool output_configured;
 
    Eina_Bool disable_acceleration;
+
+   Eina_List *pending_touch_event;
 };
 
 typedef enum _E_Input_Axis_Source {