From c024ff1789b5d4324c20aa6c5c2b28b0cfd3d862 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 22 Aug 2024 11:31:07 +0900 Subject: [PATCH] input: send mouse wheel event in input thread Change-Id: Id494a841b084b6845e81a906d699ccddf2d8fb38 Signed-off-by: Jihoon Kim --- src/bin/inputmgr/e_input_evdev.c | 71 ++++++++++++--------------------- src/bin/server/e_comp_wl.c | 22 ++++++---- src/bin/server/e_comp_wl_input_thread.c | 38 ++++++++++++++++++ src/bin/server/e_comp_wl_intern.h | 1 + 4 files changed, 79 insertions(+), 53 deletions(-) diff --git a/src/bin/inputmgr/e_input_evdev.c b/src/bin/inputmgr/e_input_evdev.c index 6abf033..0332c78 100644 --- a/src/bin/inputmgr/e_input_evdev.c +++ b/src/bin/inputmgr/e_input_evdev.c @@ -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 diff --git a/src/bin/server/e_comp_wl.c b/src/bin/server/e_comp_wl.c index 540c0af..b434070 100644 --- a/src/bin/server/e_comp_wl.c +++ b/src/bin/server/e_comp_wl.c @@ -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,21 +1806,26 @@ _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) { E_Client *ec; diff --git a/src/bin/server/e_comp_wl_input_thread.c b/src/bin/server/e_comp_wl_input_thread.c index 71f30a7..3cd5e1c 100644 --- a/src/bin/server/e_comp_wl_input_thread.c +++ b/src/bin/server/e_comp_wl_input_thread.c @@ -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 diff --git a/src/bin/server/e_comp_wl_intern.h b/src/bin/server/e_comp_wl_intern.h index 96c52ba..4468714 100644 --- a/src/bin/server/e_comp_wl_intern.h +++ b/src/bin/server/e_comp_wl_intern.h @@ -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); -- 2.7.4