e_input_evdev: reduce duplicated code in mouse button and move event 99/325199/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 2 Jun 2025 10:56:46 +0000 (19:56 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Wed, 4 Jun 2025 07:06:55 +0000 (16:06 +0900)
Change-Id: If9471407c1c6c9746d017511726cd00c652e0738
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_evdev.c

index f480e1d50cb1d37603ace4cea456ec6fc45be373..a9455166a2edebd986cf94e0aa9194adf2dbbbfa 100644 (file)
@@ -48,6 +48,7 @@ static void  _device_output_assign(E_Input_Evdev *evdev, E_Input_Seat_Capabiliti
 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 void  _e_input_aux_data_event_free(void *user_data, void *ev);
+static E_Device * _input_thread_mode_touch_device_get(E_Input_Evdev *evdev);
 
 static Eina_Bool _touch_blocked_by_palm, _touch_up_blocked_by_palm;
 
@@ -975,8 +976,26 @@ _input_thread_mode_pointer_device_get(E_Input_Evdev *evdev)
    return e_dev;
 }
 
+static Eo *
+_input_thread_mode_device_get(E_Input_Evdev *evdev, Eina_Bool touch_event)
+{
+   E_Device *e_dev = NULL;
+
+   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
+     {
+        if (touch_event)
+          e_dev = _input_thread_mode_touch_device_get(evdev);
+        else
+          e_dev = _input_thread_mode_pointer_device_get(evdev);
+
+        return (Eo *)g_object_ref(e_dev);
+     }
+
+   return NULL;
+}
+
 static Ecore_Event_Mouse_Move *
-_mouse_move_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radius_x, double radius_y, double pressure, double angle)
+_mouse_move_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radius_x, double radius_y, double pressure, double angle, Eina_Bool touch)
 {
    E_Input_Backend *input = NULL;
    Ecore_Event_Mouse_Move *ev = NULL;
@@ -1009,13 +1028,14 @@ _mouse_move_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radius
    ev->multi.root.x = ev->x;
    ev->multi.root.y = ev->y;
 
+   ev->dev = _input_thread_mode_device_get(evdev, touch);
+
    return ev;
 }
 
 static void
 _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *event)
 {
-   E_Device *e_dev = NULL;
    Ecore_Event_Mouse_Move *ev;
    E_Input_Backend *input;
    uint32_t timestamp = 0;
@@ -1026,18 +1046,12 @@ _device_pointer_motion(E_Input_Evdev *evdev, struct libinput_event_pointer *even
    else
      timestamp = e_util_timestamp_get();
 
-   ev = _mouse_move_event_create(evdev, timestamp, 1, 1, 1.0, 0.0);
+   ev = _mouse_move_event_create(evdev, timestamp, 1, 1, 1.0, 0.0, EINA_FALSE);
    if (!ev) return;
 
    evdev->mouse.dx = e_input_seat_pointer_dx_get(evdev->seat);
    evdev->mouse.dy = e_input_seat_pointer_dy_get(evdev->seat);
 
-   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);
-     }
-
    _input_event_add(evdev, ECORE_EVENT_MOUSE_MOVE, EINA_FALSE, ev, _e_input_event_mouse_move_cb_free, NULL);
 }
 
@@ -1245,7 +1259,7 @@ e_input_evdev_handle_pointer_motion_absolute(E_Input_Evdev *evdev, struct libinp
 }
 
 static Ecore_Event_Mouse_Button *
-_mouse_button_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radius_x, double radius_y, double pressure, double angle)
+_mouse_button_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radius_x, double radius_y, double pressure, double angle, Eina_Bool touch)
 {
    E_Input_Backend *input = NULL;
    Ecore_Event_Mouse_Button *ev = NULL;
@@ -1279,6 +1293,8 @@ _mouse_button_event_create(E_Input_Evdev *evdev, uint32_t timestamp, double radi
    ev->multi.root.x = ev->x;
    ev->multi.root.y = ev->y;
 
+   ev->dev = _input_thread_mode_device_get(evdev, touch);
+
    return ev;
 }
 
@@ -1318,7 +1334,6 @@ 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;
-   E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
    const char *device_name = NULL;
 
@@ -1368,7 +1383,7 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
         evdev->mouse.pressed_button &= ~(1 << button);
      }
 
-   ev = _mouse_button_event_create(evdev, timestamp, 1, 1, 1.0, 0.0);
+   ev = _mouse_button_event_create(evdev, timestamp, 1, 1, 1.0, 0.0, EINA_FALSE);
    if (!ev) return;
 
    if (state)
@@ -1387,12 +1402,6 @@ e_input_evdev_handle_button(E_Input_Evdev *evdev, struct libinput_event_pointer
    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 (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);
-     }
-
    _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);
 }
 
@@ -1453,7 +1462,6 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
    uint32_t timestamp;
    enum libinput_pointer_axis axis;
    Ecore_Device *detent_data = NULL;
-   E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
    E_Input_Device *dev = NULL;
@@ -1534,11 +1542,7 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
      }
 
-   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);
-     }
+   ev->dev = _input_thread_mode_device_get(evdev, EINA_FALSE);
 
    _input_event_add(evdev, ECORE_EVENT_MOUSE_WHEEL, EINA_FALSE, ev, _e_input_event_mouse_wheel_cb_free, NULL);
 }
@@ -1738,7 +1742,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;
-   E_Device *e_dev = NULL;
    double radius_x = 1;
    double radius_y = 1;
    double pressure = 1.0;
@@ -1761,7 +1764,7 @@ _device_handle_touch_event_send(E_Input_Evdev *evdev, struct libinput_event_touc
           angle = libinput_event_touch_get_orientation(event);
      }
 
-   ev = _mouse_button_event_create(evdev, timestamp, radius_x, radius_y, pressure, angle);
+   ev = _mouse_button_event_create(evdev, timestamp, radius_x, radius_y, pressure, angle, EINA_TRUE);
    if (!ev) return;
 
    if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
@@ -1781,12 +1784,6 @@ _device_handle_touch_event_send(E_Input_Evdev *evdev, struct libinput_event_touc
    if (evdev->mouse.did_triple)
      ev->triple_click = 1;
 
-   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
-     {
-        e_dev = _input_thread_mode_touch_device_get(evdev);
-        ev->dev = (Eo *)g_object_ref(e_dev);
-     }
-
    if (!_touch_event_pending_add(evdev, state, ev))
      {
         ELOGF("Touch", "Failed to pend event (%s). Call ecore_event_add immediately.", NULL,
@@ -1801,7 +1798,6 @@ _device_handle_touch_motion_send(E_Input_Evdev *evdev, struct libinput_event_tou
 {
    E_Input_Backend *input;
    Ecore_Event_Mouse_Move *ev;
-   E_Device *e_dev = NULL;
    uint32_t timestamp = 0;
    double radius_x = 1.0, radius_y = 1.0, pressure = 1.0, angle = 0.0;
    E_Comp_Config *comp_conf = NULL;
@@ -1820,15 +1816,9 @@ _device_handle_touch_motion_send(E_Input_Evdev *evdev, struct libinput_event_tou
    if (libinput_event_touch_has_orientation(event))
      angle = libinput_event_touch_get_orientation(event);
 
-   ev = _mouse_move_event_create(evdev, timestamp, radius_x, radius_y, pressure, angle);
+   ev = _mouse_move_event_create(evdev, timestamp, radius_x, radius_y, pressure, angle, EINA_TRUE);
    if (!ev) return;
 
-   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
-     {
-        e_dev = _input_thread_mode_touch_device_get(evdev);
-        ev->dev = (Eo *)g_object_ref(e_dev);
-     }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->input_log_enable)
      ELOGF("Touch", "Move (id: %d, x: %d, y: %d)", NULL, evdev->mt_slot, ev->x, ev->y);
@@ -1846,7 +1836,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;
-   E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
 
    if (!evdev) return;
@@ -1854,19 +1843,13 @@ _device_handle_touch_cancel_send(E_Input_Evdev *evdev, struct libinput_event_tou
 
    timestamp = libinput_event_touch_get_time(event);
 
-   ev = _mouse_button_event_create(evdev, timestamp, 1, 1, 1.0, 0.0);
+   ev = _mouse_button_event_create(evdev, timestamp, 1, 1, 1.0, 0.0, EINA_TRUE);
    if (!ev) return;
 
    evdev->touch.pressed &= ~(1 << ev->multi.device);
 
    ev->buttons = ((button & 0x00F) + 1);
 
-   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
-     {
-        e_dev = _input_thread_mode_touch_device_get(evdev);
-        ev->dev = (Eo *)g_object_ref(e_dev);
-     }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->input_log_enable)
      ELOGF("Touch", "Cancel (x: %d, y: %d, timestamp: %u (current time), device: %s)", NULL,