input: send mouse wheel event in input thread 15/317415/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 22 Aug 2024 02:31:07 +0000 (11:31 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 10 Sep 2024 04:21:17 +0000 (13:21 +0900)
Change-Id: Id494a841b084b6845e81a906d699ccddf2d8fb38
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_input_evdev.c
src/bin/server/e_comp_wl.c
src/bin/server/e_comp_wl_input_thread.c
src/bin/server/e_comp_wl_intern.h

index 6abf033fcb1959d68788654bd5de1402499248b3..0332c7827c2f8ce066659a76b04bcbaa0286b0e1 100644 (file)
@@ -491,7 +491,13 @@ _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
 {
    Ecore_Event_Mouse_Wheel *ev = event;
 
-   if (ev->dev) ecore_device_unref(ev->dev);
+   if (ev->dev)
+     {
+        if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
+          g_object_unref(ev->dev);
+        else
+          ecore_device_unref(ev->dev);
+     }
 
    free(ev);
 }
@@ -1636,11 +1642,10 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
    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 *ecore_dev = NULL, *detent_data = NULL;
+   E_Device *e_dev = NULL;
    E_Comp_Config *comp_conf = NULL;
    int direction = 0, z = 0;
-   const char *device_name = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(evdev);
 
@@ -1649,7 +1654,6 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
         return;
      }
 
-   device_name = evdev->name;
    timestamp = libinput_event_pointer_get_time(event);
 
    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
@@ -1669,40 +1673,6 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
         return;
      }
 
-   ecore_thread_main_loop_begin();
-
-   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(evdev->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(device_name))
-          {
-             ecore_dev = detent_data;
-          }
-     }
-   else
-     {
-        evdev->ecore_dev = e_input_evdev_ecore_device_get(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;
-     }
-
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->e_wheel_click_angle)
      {
@@ -1720,12 +1690,12 @@ e_input_evdev_handle_axis_v120(E_Input_Evdev *evdev, struct libinput_event_point
           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
                 direction, z, blocked_client, evdev->seat->dev->server_blocked);
 
-        goto end;
+        return;
      }
 
    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
      {
-        goto end;
+        return;
      }
 
    ev->window = (Ecore_Window)input->dev->window;
@@ -1752,11 +1722,20 @@ 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);
      }
 
-   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();
+   if (e_input_thread_mode_get() && e_input_pointer_thread_mode_get())
+     {
+        e_dev = _device_pointer_send_motion_thread_mode(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
+     {
+        ecore_thread_main_loop_begin();
+        ecore_dev = _device_pointer_send_motion(evdev);
+        ev->dev = ecore_device_ref(ecore_dev);
+        ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
+        ecore_thread_main_loop_end();
+     }
 }
 #endif
 
index 540c0afd95b1fc9669066bc2ceec677a5996d527..b434070b3645d77f40ad70af0c79894182051fee 100644 (file)
@@ -1785,12 +1785,15 @@ finish:
    need_send_released = EINA_FALSE;
 }
 
-static void
-_e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, int timestamp)
+EINTERN void
+e_comp_wl_surface_mouse_wheel_send(struct wl_resource *surface, int direction, int z, int timestamp)
 {
    struct wl_resource *res;
    struct wl_client *wc;
    Eina_List *l;
+
+   if (!surface) return;
+
    uint32_t axis, dir;
 
    if (direction == 0)
@@ -1803,20 +1806,25 @@ _e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, int timestamp)
    else
      dir = wl_fixed_from_int(z);
 
-   if (!ec) return;
-   if (e_object_is_del(E_OBJECT(ec))) return;
-   struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
-   if (!surface) return;
-
    wc = wl_resource_get_client(surface);
    EINA_LIST_FOREACH(e_comp_wl->ptr.resources, l, res)
      {
         if (!e_comp_wl_input_pointer_check(res)) continue;
         if (wl_resource_get_client(res) != wc) continue;
+        ELOGF("Mouse", "Send wheel event (timestamp: %d, axis: %d, dir: %d)", NULL, timestamp, axis, dir);
         wl_pointer_send_axis(res, timestamp, axis, dir);
      }
 }
 
+static void
+_e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, int timestamp)
+{
+   if (!ec) return;
+   if (e_object_is_del(E_OBJECT(ec))) return;
+   struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
+   e_comp_wl_surface_mouse_wheel_send(surface, direction, z, timestamp);
+}
+
 static void
 _e_comp_wl_evas_cb_mouse_wheel(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
 {
index 71f30a787d318419a728ec378df9328226f0f660..3cd5e1c3b65b147fc9e3822a45416ea8a422b271 100644 (file)
@@ -11,6 +11,7 @@
 static E_Input_Event_Handler *_mouse_move_handler = NULL;
 static E_Input_Event_Handler *_mouse_down_handler = NULL;
 static E_Input_Event_Handler *_mouse_up_handler = NULL;
+static E_Input_Event_Handler *_mouse_wheel_handler = NULL;
 
 static Eina_Bool e_input_handlers_added = EINA_FALSE;
 
@@ -303,6 +304,35 @@ err:
    return ECORE_CALLBACK_RENEW;
 }
 
+static Eina_Bool
+_e_comp_wl_cb_mouse_wheel_thread_mode(void *d EINA_UNUSED, int t EINA_UNUSED, void *event)
+{
+   Ecore_Event_Mouse_Wheel *ev = event;
+   E_Input_Thread_Client *iec = NULL;
+   struct wl_resource *surface = NULL;
+
+   iec = _e_comp_wl_input_thread_client_under_pointer(ev->x, ev->y);
+   if (!iec)
+     goto err;
+
+   surface = e_input_thread_client_wl_resource_get(iec);
+   if (!surface)
+     {
+        ELOGF("Mouse", "Wheel. surface NULL", NULL);
+        goto err;
+     }
+
+   if (!eina_list_count(e_comp_wl->ptr.resources))
+     return ECORE_CALLBACK_RENEW;
+
+   _e_comp_wl_device_input_thread_send_event_device(iec, (E_Device *)ev->dev, ev->timestamp);
+
+   e_comp_wl_surface_mouse_wheel_send(surface, ev->direction, ev->z, ev->timestamp);
+
+err:
+   return ECORE_CALLBACK_RENEW;
+}
+
 EINTERN void
 e_comp_wl_input_thread_add_e_input_handlers()
 {
@@ -326,6 +356,9 @@ e_comp_wl_input_thread_add_e_input_handlers()
              if (!_mouse_up_handler)
                _mouse_up_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_MOUSE_BUTTON_UP, _e_comp_wl_cb_mouse_button_up_thread_mode, NULL);
 
+             if (!_mouse_wheel_handler)
+               _mouse_wheel_handler = e_input_event_handler_add(input_event_source, ECORE_EVENT_MOUSE_WHEEL, _e_comp_wl_cb_mouse_wheel_thread_mode, NULL);
+
              e_input_handlers_added = EINA_TRUE;
           }
      }
@@ -360,6 +393,11 @@ e_comp_wl_input_thread_remove_e_input_handlers()
                e_input_event_handler_del(input_event_source, _mouse_up_handler);
 
              _mouse_up_handler = NULL;
+
+             if (_mouse_wheel_handler)
+               e_input_event_handler_del(input_event_source, _mouse_wheel_handler);
+
+             _mouse_wheel_handler = NULL;
           }
      }
    else
index 96c52ba7deff881650b384334d8ad7005d3790e2..446871474fa3201d426ee9f947bd6bbc734aff87 100644 (file)
@@ -107,6 +107,7 @@ EINTERN void      e_comp_wl_trace_serial_debug(Eina_Bool on);
 
 EINTERN void      e_comp_wl_surface_send_mouse_move(struct wl_resource *surface, int x, int y, int client_x, int client_y, unsigned int timestamp);
 EINTERN void      e_comp_wl_surface_mouse_button_send(struct wl_resource *surface, uint32_t timestamp, uint32_t button_id, uint32_t state);
+EINTERN void      e_comp_wl_surface_mouse_wheel_send(struct wl_resource *surface, int direction, int z, int timestamp);
 
 EINTERN E_Devicemgr_Input_Device *e_comp_wl_device_last_device_get(Ecore_Device_Class dev_class);
 EINTERN void      e_comp_wl_device_last_device_set(Ecore_Device_Class dev_class, E_Devicemgr_Input_Device *device);