From 91d72d1548a70a70f362424db4bfffb1b1aeea1c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 10 Oct 2024 16:47:07 +0900 Subject: [PATCH] e_input_evdev: refactoring duplicated code related to generate pointer/touch event Change-Id: I429ac8ba9498c3122abe0ba0c582100359a0debb Signed-off-by: Jihoon Kim --- src/bin/e_input_evdev.c | 83 ++++++++++------------------------------- 1 file changed, 19 insertions(+), 64 deletions(-) diff --git a/src/bin/e_input_evdev.c b/src/bin/e_input_evdev.c index c57132203e..6fd4858a2f 100644 --- a/src/bin/e_input_evdev.c +++ b/src/bin/e_input_evdev.c @@ -31,6 +31,7 @@ static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, in static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap); static void _pointer_touch_ecore_event_add(void *data); +static void _input_thread_ecore_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; @@ -906,7 +907,6 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event Ecore_Event_Mouse_Move *ev; int x = 0, y = 0, w = 0, h = 0; const char *device_name = edev->name; - E_Input_Event_Info *input_event = NULL; if (!(input = edev->seat->input)) return; @@ -962,15 +962,7 @@ _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event ev->multi.root.x = ev->x; ev->multi.root.y = ev->y; - input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_FALSE; - input_event->evdev = edev; - 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); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_MOVE, EINA_FALSE, ev, _e_input_event_mouse_move_cb_free, NULL); } void @@ -986,7 +978,6 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point Ecore_Event_Mouse_Relative_Move *ev; E_Comp_Config *comp_conf; const char *device_name = NULL; - E_Input_Event_Info *input_event = NULL; if (!(input = edev->seat->input)) return; @@ -1009,15 +1000,7 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point if (comp_conf && comp_conf->input_log_enable) ELOGF("Mouse", "Relative Move (time: %d, dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel, device_name); - input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_FALSE; - input_event->evdev = edev; - 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); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_RELATIVE_MOVE, EINA_FALSE, ev, _e_input_event_mouse_relative_move_cb_free, NULL); } static void @@ -1145,7 +1128,6 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin uint32_t button, timestamp; E_Comp_Config *comp_conf = NULL; const char *device_name = NULL; - E_Input_Event_Info *input_event = NULL; if (!(edev = libinput_device_get_user_data(device))) { @@ -1261,15 +1243,7 @@ _device_handle_button(struct libinput_device *device, struct libinput_event_poin 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)); - input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_FALSE; - input_event->evdev = edev; - 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); + _input_thread_ecore_event_add(edev, 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 @@ -1406,15 +1380,7 @@ _device_handle_axis(struct libinput_device *device, struct libinput_event_pointe ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z); } - input_event = E_NEW(E_Input_Event_Info, 1); - 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); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_WHEEL, EINA_FALSE, ev, _e_input_event_mouse_wheel_cb_free, NULL); } #endif @@ -1479,7 +1445,6 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p Ecore_Device *detent_data = NULL; E_Comp_Config *comp_conf = NULL; int direction = 0, z = 0; - E_Input_Event_Info *input_event = NULL; if (!(edev = libinput_device_get_user_data(device))) { @@ -1555,15 +1520,7 @@ _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_p ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z); } - input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_FALSE; - input_event->evdev = edev; - 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); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_WHEEL, EINA_FALSE, ev, _e_input_event_mouse_wheel_cb_free, NULL); } #endif @@ -1661,7 +1618,7 @@ _pointer_touch_ecore_event_add(void *data) } static void -_input_thread_ecore_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev_free_func free_func, void *free_func_data) +_input_thread_ecore_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; @@ -1670,7 +1627,9 @@ _input_thread_ecore_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev return; input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_TRUE; + EINA_SAFETY_ON_NULL_GOTO(input_event, err); + + input_event->touch_event = touch_event; input_event->evdev = evdev; input_event->event_type = event_type; input_event->ev = ev; @@ -1678,6 +1637,11 @@ _input_thread_ecore_event_add(E_Input_Evdev *evdev, int event_type, void *ev, ev input_event->free_func_data = free_func_data; ecore_main_loop_thread_safe_call_async(_pointer_touch_ecore_event_add, input_event); + + return; + +err: + free_func((void *)free_func_data, (void *)ev); } static void @@ -1801,7 +1765,7 @@ _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch ELOGF("Touch", "Failed to pend event (%s). Call ecore_event_add imediately.", NULL, state == ECORE_EVENT_MOUSE_BUTTON_DOWN ? "DOWN" : "UP"); - _input_thread_ecore_event_add(edev, state, ev, _e_input_event_mouse_button_cb_free, NULL); + _input_thread_ecore_event_add(edev, state, EINA_TRUE, ev, _e_input_event_mouse_button_cb_free, NULL); } } @@ -1854,7 +1818,7 @@ _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touc if (!_touch_event_pending_add(edev, ECORE_EVENT_MOUSE_MOVE, ev)) { ELOGF("Touch", "Failed to pend event (MOVE). Call ecore_event_add immediately.", NULL); - _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_MOVE, EINA_TRUE, ev, _e_input_event_mouse_move_cb_free, NULL); } } @@ -1901,7 +1865,7 @@ _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touc if (!_touch_event_pending_add(edev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev)) { ELOGF("Touch", "Failed to pend event (CANCEL). Call ecore_event_add imediately.", NULL); - _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL); + _input_thread_ecore_event_add(edev, ECORE_EVENT_MOUSE_BUTTON_CANCEL, EINA_TRUE, ev, _e_input_event_mouse_button_cb_free, NULL); } } @@ -2235,7 +2199,6 @@ _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_ev Ecore_Axis *axis; E_Comp_Config *comp_conf; int touch_value; - E_Input_Event_Info *input_event = NULL; if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM && libinput_event_touch_aux_data_get_value(event) > 0) @@ -2279,15 +2242,7 @@ _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_ev } } - input_event = E_NEW(E_Input_Event_Info, 1); - input_event->touch_event = EINA_TRUE; - input_event->evdev = edev; - 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); + _input_thread_ecore_event_add(edev, ECORE_EVENT_AXIS_UPDATE, EINA_TRUE, ev, _e_input_aux_data_event_free, NULL); } E_Input_Evdev * -- 2.34.1