e_input: execute libinput API in input thread 45/311945/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 30 May 2024 06:40:15 +0000 (15:40 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 31 May 2024 02:56:43 +0000 (11:56 +0900)
Change-Id: I8e6bbce9623674467ab4e50a2d38e5d0171a0f20
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_backend.c
src/bin/inputmgr/e_input_evdev.c

index 8ee4e28..c472894 100644 (file)
@@ -566,24 +566,23 @@ _device_added(E_Input_Backend *input, struct libinput_device *device)
    E_Input_Seat *seat;
    E_Input_Evdev *edev;
 
-   ecore_thread_main_loop_begin();
    libinput_seat = libinput_device_get_seat(device);
    seat_name = libinput_seat_get_logical_name(libinput_seat);
 
+   ecore_thread_main_loop_begin();
+
    /* try to get a seat */
    if (!(seat = _seat_get(input, seat_name)))
      {
         ERR("Could not get matching seat: %s", seat_name);
-        ecore_thread_main_loop_end();
-        return;
+        goto end;
      }
 
    /* try to create a new evdev device */
    if (!(edev = e_input_evdev_device_create(seat, device)))
      {
         ERR("Failed to create new evdev device");
-        ecore_thread_main_loop_end();
-        return;
+        goto end;
      }
 
    /* append this device to the seat */
@@ -592,10 +591,10 @@ _device_added(E_Input_Backend *input, struct libinput_device *device)
    if (EINA_FALSE == _e_input_device_add(edev))
      {
         ERR("Failed to create evas device !\n");
-        ecore_thread_main_loop_end();
-        return;
+        goto end;
      }
 
+end:
    ecore_thread_main_loop_end();
 }
 
@@ -604,15 +603,16 @@ _device_removed(E_Input_Backend *input, struct libinput_device *device)
 {
    E_Input_Evdev *edev;
 
-   ecore_thread_main_loop_begin();
+   edev = libinput_device_get_user_data(device);
 
    /* try to get the evdev structure */
-   if (!(edev = libinput_device_get_user_data(device)))
+   if (!edev)
      {
-        ecore_thread_main_loop_end();
         return;
      }
 
+   ecore_thread_main_loop_begin();
+
    _e_input_device_remove(edev);
 
    /* remove this evdev from the seat's list of devices */
index b5ba1ac..f1a9852 100644 (file)
@@ -816,9 +816,14 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event
    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 = NULL;
+   uint32_t timestamp = 0;
 
    if (!(input = edev->seat->input)) return;
 
+   device_name = libinput_device_get_name(edev->device);
+   timestamp = libinput_event_pointer_get_time(event);
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -836,7 +841,7 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event
                   detent_data = data;
                }
           }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
+        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
           {
              ecore_dev = detent_data;
           }
@@ -890,7 +895,7 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event
 
    if (event)
      {
-        ev->timestamp = libinput_event_pointer_get_time(event);
+        ev->timestamp = timestamp;
      }
    else
      {
@@ -932,9 +937,14 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point
    Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
    Eina_List *l;
    E_Comp_Config *comp_conf;
+   const char *device_name = NULL;
+   uint32_t timestamp = 0;
 
    if (!(input = edev->seat->input)) return;
 
+   device_name = libinput_device_get_name(edev->device);
+   timestamp = libinput_event_pointer_get_time(event);
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -952,7 +962,7 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point
                   detent_data = data;
                }
           }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
+        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
           {
              ecore_dev = detent_data;
           }
@@ -978,7 +988,7 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point
 
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
-   if (event) ev->timestamp = libinput_event_pointer_get_time(event);
+   if (event) ev->timestamp = timestamp;
 
    ev->modifiers = edev->xkb.modifiers;
 
@@ -1125,6 +1135,7 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
    Eina_List *l;
    E_Comp_Config *comp_conf = NULL;
+   const char *device_name = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
@@ -1135,6 +1146,11 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
         return;
      }
 
+   state = libinput_event_pointer_get_button_state(event);
+   button = libinput_event_pointer_get_button(event);
+   timestamp = libinput_event_pointer_get_time(event);
+   device_name = libinput_device_get_name(edev->device);
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1152,7 +1168,7 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
                   detent_data = data;
                }
           }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
+        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
           {
              ecore_dev = detent_data;
           }
@@ -1169,10 +1185,6 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
         goto end;
      }
 
-   state = libinput_event_pointer_get_button_state(event);
-   button = libinput_event_pointer_get_button(event);
-   timestamp = libinput_event_pointer_get_time(event);
-
    button = ((button & 0x00F) + 1);
    if (button == 3) button = 2;
    else if (button == 2) button = 3;
@@ -1184,7 +1196,6 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin
         if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
             (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
           {
-
              ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
                    button, ecore_device_name_get(ecore_dev), blocked_client,
                    edev->seat->dev->server_blocked);
@@ -1341,6 +1352,7 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
    Eina_List *l;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
+   const char *device_name = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
@@ -1351,6 +1363,26 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
         return;
      }
 
+   device_name = libinput_device_get_name(edev->device);
+   timestamp = libinput_event_pointer_get_time(event);
+
+   axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
+   if (libinput_event_pointer_has_axis(event, axis))
+     z = _axis_value_get(event, axis);
+
+   axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+   if (libinput_event_pointer_has_axis(event, axis))
+     {
+        direction = 1;
+        z = _axis_value_get(event, axis);
+     }
+
+  if (z == 0)
+    {
+       ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
+       return;
+    }
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1368,7 +1400,7 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
                   detent_data = data;
                }
           }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
+        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
           {
              ecore_dev = detent_data;
           }
@@ -1385,23 +1417,6 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
         goto end;
      }
 
-   axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
-   if (libinput_event_pointer_has_axis(event, axis))
-     z = _axis_value_get(event, axis);
-
-   axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
-   if (libinput_event_pointer_has_axis(event, axis))
-     {
-        direction = 1;
-        z = _axis_value_get(event, axis);
-     }
-
-  if (z == 0)
-    {
-       ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
-       goto end;
-    }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->e_wheel_click_angle)
      {
@@ -1428,8 +1443,6 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
         goto end;
      }
 
-   timestamp = libinput_event_pointer_get_time(event);
-
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
@@ -1454,7 +1467,6 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe
           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);
 
@@ -1525,6 +1537,7 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
    Eina_List *l;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
+   const char *device_name = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
@@ -1535,6 +1548,26 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
         return;
      }
 
+   device_name = libinput_device_get_name(edev->device);
+   timestamp = libinput_event_pointer_get_time(event);
+
+   axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
+   if (libinput_event_pointer_has_axis(event, axis))
+     z = _scroll_value_get(event, axis, source);
+
+   axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+   if (libinput_event_pointer_has_axis(event, axis))
+     {
+        direction = 1;
+        z = _scroll_value_get(event, axis, source);
+     }
+
+   if (z == 0)
+     {
+        ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
+        return;
+     }
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1552,7 +1585,7 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
                   detent_data = data;
                }
           }
-        if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
+        if (!ecore_dev && e_devicemgr_detent_is_detent(device_name))
           {
              ecore_dev = detent_data;
           }
@@ -1569,23 +1602,6 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
         goto end;
      }
 
-   axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
-   if (libinput_event_pointer_has_axis(event, axis))
-     z = _scroll_value_get(event, axis, source);
-
-   axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
-   if (libinput_event_pointer_has_axis(event, axis))
-     {
-        direction = 1;
-        z = _scroll_value_get(event, axis, source);
-     }
-
-   if (z == 0)
-     {
-        ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
-        goto end;
-     }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->e_wheel_click_angle)
      {
@@ -1611,8 +1627,6 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p
         goto end;
      }
 
-   timestamp = libinput_event_pointer_get_time(event);
-
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
@@ -1653,10 +1667,30 @@ _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch
    uint32_t timestamp, button = 0;
    Ecore_Device *ecore_dev = NULL, *data;
    Eina_List *l;
+   double radius_x = 1;
+   double radius_y = 1;
+   double pressure = 1.0;
+   double angle = 0.0;
 
    if (!edev) return;
    if (!(input = edev->seat->input)) return;
 
+   timestamp = libinput_event_touch_get_time(event);
+#if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
+   if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
+       == LIBINPUT_EVENT_TOUCH_DOWN)
+     {
+        if (libinput_event_touch_has_minor(event))
+          radius_x = libinput_event_touch_get_minor(event);
+        if (libinput_event_touch_has_major(event))
+          radius_y = libinput_event_touch_get_major(event);
+        if (libinput_event_touch_has_pressure(event))
+          pressure = libinput_event_touch_get_pressure(event);
+        if (libinput_event_touch_has_orientation(event))
+          angle = libinput_event_touch_get_orientation(event);
+     }
+#endif
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1685,8 +1719,6 @@ _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch
 
    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
 
-   timestamp = libinput_event_touch_get_time(event);
-
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
@@ -1703,24 +1735,11 @@ _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch
 
    ev->multi.device = edev->mt_slot;
    ev->multi.radius = 1;
-   ev->multi.radius_x = 1;
-   ev->multi.radius_y = 1;
-   ev->multi.pressure = 1.0;
-   ev->multi.angle = 0.0;
-#if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
-   if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
-       == LIBINPUT_EVENT_TOUCH_DOWN)
-     {
-        if (libinput_event_touch_has_minor(event))
-          ev->multi.radius_x = libinput_event_touch_get_minor(event);
-        if (libinput_event_touch_has_major(event))
-          ev->multi.radius_y = libinput_event_touch_get_major(event);
-        if (libinput_event_touch_has_pressure(event))
-          ev->multi.pressure = libinput_event_touch_get_pressure(event);
-        if (libinput_event_touch_has_orientation(event))
-          ev->multi.angle = libinput_event_touch_get_orientation(event);
-     }
-#endif
+   ev->multi.radius_x = radius_x;
+   ev->multi.radius_y = radius_y;
+   ev->multi.pressure = pressure;
+   ev->multi.angle = angle;
+
    ev->multi.x = ev->x;
    ev->multi.y = ev->y;
    ev->multi.root.x = ev->x;
@@ -1780,10 +1799,24 @@ _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touc
    Ecore_Event_Mouse_Move *ev;
    Ecore_Device *ecore_dev = NULL, *data;
    Eina_List *l;
+   uint32_t timestamp = 0;
+   double radius_x = 1.0, radius_y = 1.0, pressure = 1.0, angle = 0.0;
 
    if (!edev) return;
    if (!(input = edev->seat->input)) return;
 
+   timestamp = libinput_event_touch_get_time(event);
+#if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
+   if (libinput_event_touch_has_minor(event))
+     radius_x = libinput_event_touch_get_minor(event);
+   if (libinput_event_touch_has_major(event))
+     radius_y = libinput_event_touch_get_major(event);
+   if (libinput_event_touch_has_pressure(event))
+     pressure = libinput_event_touch_get_pressure(event);
+   if (libinput_event_touch_has_orientation(event))
+     angle = libinput_event_touch_get_orientation(event);
+#endif
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1815,7 +1848,7 @@ _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touc
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
-   ev->timestamp = libinput_event_touch_get_time(event);
+   ev->timestamp = timestamp;
    ev->same_screen = 1;
 
    _device_modifiers_update(edev);
@@ -1828,20 +1861,10 @@ _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touc
 
    ev->multi.device = edev->mt_slot;
    ev->multi.radius = 1;
-   ev->multi.radius_x = 1;
-   ev->multi.radius_y = 1;
-   ev->multi.pressure = 1.0;
-   ev->multi.angle = 0.0;
-#if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
-   if (libinput_event_touch_has_minor(event))
-     ev->multi.radius_x = libinput_event_touch_get_minor(event);
-   if (libinput_event_touch_has_major(event))
-     ev->multi.radius_y = libinput_event_touch_get_major(event);
-   if (libinput_event_touch_has_pressure(event))
-     ev->multi.pressure = libinput_event_touch_get_pressure(event);
-   if (libinput_event_touch_has_orientation(event))
-     ev->multi.angle = libinput_event_touch_get_orientation(event);
-#endif
+   ev->multi.radius_x = radius_x;
+   ev->multi.radius_y = radius_y;
+   ev->multi.pressure = pressure;
+   ev->multi.angle = angle;
    ev->multi.x = ev->x;
    ev->multi.y = ev->y;
    ev->multi.root.x = ev->x;
@@ -1866,6 +1889,8 @@ _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touc
    if (!edev) return;
    if (!(input = edev->seat->input)) return;
 
+   timestamp = libinput_event_touch_get_time(event);
+
    ecore_thread_main_loop_begin();
 
    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
@@ -1894,8 +1919,6 @@ _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touc
 
    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
 
-   timestamp = libinput_event_touch_get_time(event);
-
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
@@ -2216,15 +2239,20 @@ _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_ev
    Ecore_Device *ecore_dev = NULL, *data;
    Eina_List *l;
    E_Comp_Config *comp_conf;
-
-   ecore_thread_main_loop_begin();
+   uint32_t timestamp = 0;
+   int touch_value;
 
    if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
        libinput_event_touch_aux_data_get_value(event) > 0)
-      goto end;
+      return;
 
-   if (!(edev = libinput_device_get_user_data(device))) goto end;
-   if (!(input = edev->seat->input)) goto end;
+   if (!(edev = libinput_device_get_user_data(device))) return;
+   if (!(input = edev->seat->input)) return;
+
+   timestamp = libinput_event_touch_aux_data_get_time(event);
+   touch_value = libinput_event_touch_aux_data_get_value(event);
+
+   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)
@@ -2255,13 +2283,13 @@ _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_ev
    ev->window = (Ecore_Window)input->dev->window;
    ev->event_window = (Ecore_Window)input->dev->window;
    ev->root_window = (Ecore_Window)input->dev->window;
-   ev->timestamp = libinput_event_touch_aux_data_get_time(event);
+   ev->timestamp = timestamp;;
 
    axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
    if (axis)
      {
         axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
-        axis->value = libinput_event_touch_aux_data_get_value(event);
+        axis->value = touch_value;
         ev->naxis = 1;
      }
    ev->axis = axis;