e_input_evdev: refactoring duplicated code related to generate pointer/touch event 88/320588/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 10 Oct 2024 07:47:07 +0000 (16:47 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 19 Nov 2024 04:33:26 +0000 (13:33 +0900)
Change-Id: I8902827e75ce43c36bb847a9ca319c4b83a74010
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_evdev.c

index edaac6825e898fe4b245272c4592bef11b680cdf..c781e94ea938df1618fce1785b08bffbb37672e9 100644 (file)
@@ -39,6 +39,7 @@ static void  _device_configured_size_get(E_Input_Evdev *evdev, int *x, int *y, i
 static void  _device_output_assign(E_Input_Evdev *evdev, E_Input_Seat_Capabilities cap);
 
 static void  _pointer_touch_ecore_event_add(void *data);
+static void  _input_event_add(E_Input_Evdev *evdev, int event_type, Eina_Bool touch_event, void *ev, ev_free_func free_func, void *free_func_data);
 
 static Eina_Bool _touch_blocked_by_palm, _touch_up_blocked_by_palm;
 
@@ -959,7 +960,6 @@ _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *even
    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)
@@ -1009,28 +1009,9 @@ _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *even
      {
         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_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
-     }
-   else
-     {
-        input_event = E_NEW(E_Input_Event_Info, 1);
-        EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-        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_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
      }
 
-   return;
-
-err:
-   _e_input_event_mouse_move_cb_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, ECORE_EVENT_MOUSE_MOVE, EINA_FALSE, ev, _e_input_event_mouse_move_cb_free, NULL);
 }
 
 void
@@ -1047,7 +1028,6 @@ _device_pointer_relative_motion(E_Input_Evdev *evdev, struct libinput_event_poin
    E_Comp_Config *comp_conf;
    const char *device_name = NULL;
    uint32_t timestamp = 0;
-   E_Input_Event_Info *input_event = NULL;
 
    if (!(input = evdev->seat->input)) return;
 
@@ -1072,23 +1052,7 @@ _device_pointer_relative_motion(E_Input_Evdev *evdev, struct libinput_event_poin
    if (comp_conf && comp_conf->input_log_enable)
      ELOGF("Mouse", "Relative Move (time: %d, dx: %.2f, dy: %.2f, unaccel(%.2f, %.2f) device: %s)", NULL, ev->timestamp, dx[0], dy[0], dx[1], dy[1], device_name);
 
-   input_event = E_NEW(E_Input_Event_Info, 1);
-   EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-   input_event->touch_event = EINA_FALSE;
-   input_event->evdev = evdev;
-   input_event->ev = ev;
-   input_event->event_type = ECORE_EVENT_MOUSE_RELATIVE_MOVE;
-   input_event->free_func = _e_input_event_mouse_relative_move_cb_free;
-   input_event->free_func_data = NULL;
-
-   ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
-
-   return;
-
-err:
-   _e_input_event_mouse_relative_move_cb_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, ECORE_EVENT_MOUSE_RELATIVE_MOVE, EINA_FALSE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
 }
 
 static unsigned int
@@ -1269,7 +1233,6 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
    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);
 
@@ -1389,28 +1352,9 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
      {
         e_dev = _input_thread_mode_pointer_device_get(evdev);
         ev->dev = (Eo *)g_object_ref(e_dev);
-        e_input_event_add(input->event_source, state ? ECORE_EVENT_MOUSE_BUTTON_DOWN : ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
      }
-   else
-     {
-        input_event = E_NEW(E_Input_Event_Info, 1);
-        EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-        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_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
-     }
-
-   return;
-
-err:
-   _e_input_event_mouse_button_cb_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, state? ECORE_EVENT_MOUSE_BUTTON_DOWN : ECORE_EVENT_MOUSE_BUTTON_UP, EINA_FALSE, ev, _e_input_event_mouse_button_cb_free, NULL);
 }
 
 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
@@ -1548,28 +1492,9 @@ e_input_evdev_handle_axis(E_Input_Evdev *evdev, struct libinput_event_pointer *e
      {
         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);
-        EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-        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);
      }
 
-   return;
-
-err:
-   _e_input_event_mouse_wheel_cb_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, ECORE_EVENT_MOUSE_WHEEL, EINA_FALSE, ev, _e_input_event_mouse_wheel_cb_free, NULL);
 }
 #endif
 
@@ -1634,7 +1559,6 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
    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);
 
@@ -1715,32 +1639,12 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
      {
         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);
-        EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-        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);
-     }
-
-   return;
-
-err:
-   _e_input_event_mouse_wheel_cb_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, ECORE_EVENT_MOUSE_WHEEL, EINA_FALSE, ev, _e_input_event_mouse_wheel_cb_free, NULL);
 }
 #endif
 
-
 static E_Device *
 _input_thread_mode_touch_device_get(E_Input_Evdev *evdev)
 {
@@ -1873,7 +1777,7 @@ _pointer_touch_ecore_event_add(void *data)
 }
 
 static void
-_input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func free_func, void *free_func_data)
+_input_event_add(E_Input_Evdev *evdev, int event_type, Eina_Bool touch_event, void *ev, ev_free_func free_func, void *free_func_data)
 {
    E_Input_Backend *input;
    E_Input_Event_Info *input_event = NULL;
@@ -1887,7 +1791,7 @@ _input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func fr
      {
         input_event = E_NEW(E_Input_Event_Info, 1);
         EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-        input_event->touch_event =  EINA_TRUE;
+        input_event->touch_event =  touch_event;
         input_event->evdev = evdev;
         input_event->event_type = event_type;
         input_event->ev = ev;
@@ -1901,8 +1805,6 @@ _input_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func fr
 
 err:
    free_func((void *)free_func_data, (void *)ev);
-
-   return;
 }
 
 static void
@@ -1914,11 +1816,11 @@ _touch_event_pending_flush(E_Input_Evdev *edev)
      {
         if ((ev->type == ECORE_EVENT_MOUSE_BUTTON_DOWN) ||
             (ev->type == ECORE_EVENT_MOUSE_BUTTON_UP))
-          _input_event_add(edev, ev->type, ev->event, _e_input_event_mouse_button_cb_free, NULL);
+          _input_event_add(edev, ev->type, EINA_TRUE, ev->event, _e_input_event_mouse_button_cb_free, NULL);
         else if (ev->type == ECORE_EVENT_MOUSE_MOVE)
-          _input_event_add(edev, ev->type, ev->event, _e_input_event_mouse_move_cb_free, NULL);
+          _input_event_add(edev, ev->type, EINA_TRUE, ev->event, _e_input_event_mouse_move_cb_free, NULL);
         else if (ev->type == ECORE_EVENT_MOUSE_BUTTON_CANCEL)
-          _input_event_add(edev, ev->type, ev->event, _e_input_event_mouse_button_cb_free, NULL);
+          _input_event_add(edev, ev->type, EINA_TRUE, ev->event, _e_input_event_mouse_button_cb_free, NULL);
         else
           {
              ELOGF("CRI", "NOT Supported pending event. type:%d", NULL, ev->type);
@@ -2041,7 +1943,7 @@ _device_handle_touch_event_send(E_Input_Evdev *evdev, struct libinput_event_touc
         ELOGF("Touch", "Failed to pend event (%s). Call ecore_event_add immediately.", NULL,
               state == ECORE_EVENT_MOUSE_BUTTON_DOWN ? "DOWN" : "UP");
 
-        _input_event_add(evdev, state, ev, _e_input_event_mouse_button_cb_free, NULL);
+        _input_event_add(evdev, state, EINA_TRUE, ev, _e_input_event_mouse_button_cb_free, NULL);
      }
 }
 
@@ -2105,7 +2007,7 @@ _device_handle_touch_motion_send(E_Input_Evdev *evdev, struct libinput_event_tou
    if (!_touch_event_pending_add(evdev, ECORE_EVENT_MOUSE_MOVE, ev))
      {
         ELOGF("Touch", "Failed to pend event (MOVE). Call ecore_event_add immediately.", NULL);
-        _input_event_add(evdev, ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
+        _input_event_add(evdev, ECORE_EVENT_MOUSE_MOVE, EINA_TRUE, ev, _e_input_event_mouse_move_cb_free, NULL);
      }
 }
 
@@ -2159,7 +2061,7 @@ _device_handle_touch_cancel_send(E_Input_Evdev *evdev, struct libinput_event_tou
    if (!_touch_event_pending_add(evdev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev))
      {
         ELOGF("Touch", "Failed to pend event (CANCEL). Call ecore_event_add immediately.", NULL);
-        _input_event_add(evdev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
+        _input_event_add(evdev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, EINA_TRUE, ev, _e_input_event_mouse_button_cb_free, NULL);
      }
 }
 
@@ -2474,7 +2376,6 @@ e_input_edev_handle_touch_aux_data(E_Input_Evdev *evdev, struct libinput_event_t
    E_Comp_Config *comp_conf;
    uint32_t timestamp = 0;
    int touch_value;
-   E_Input_Event_Info *input_event = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
@@ -2520,23 +2421,7 @@ e_input_edev_handle_touch_aux_data(E_Input_Evdev *evdev, struct libinput_event_t
           }
      }
 
-   input_event = E_NEW(E_Input_Event_Info, 1);
-   EINA_SAFETY_ON_NULL_GOTO(input_event, err);
-   input_event->touch_event = EINA_TRUE;
-   input_event->evdev = evdev;
-   input_event->ev = ev;
-   input_event->event_type = ECORE_EVENT_AXIS_UPDATE;
-   input_event->free_func = _e_input_aux_data_event_free;
-   input_event->free_func_data = NULL;
-
-   ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event);
-
-   return;
-
-err:
-   _e_input_aux_data_event_free(NULL, (void *)ev);
-
-   return;
+   _input_event_add(evdev, ECORE_EVENT_AXIS_UPDATE, EINA_TRUE, ev, _e_input_aux_data_event_free, NULL);
 }
 
 E_Input_Evdev *