From f79480943ba123664a4cb09302cc7f908eb053e5 Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 25 Feb 2019 16:52:31 +0900 Subject: [PATCH] input_generator: add new APIs to generate axis events - add a new API to generator mouse wheel events. : efl_util_input_generate_wheel - add a new API to generator touch axis events. : efl_util_input_generate_axis Change-Id: I942038c21b4bd42cecaf9b6082f69ddad3737d20 --- include/efl_util.h.in | 72 +++++++++++++++++++ src/efl_util.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 264 insertions(+), 1 deletion(-) diff --git a/include/efl_util.h.in b/include/efl_util.h.in index 202ce02..61eb29d 100644 --- a/include/efl_util.h.in +++ b/include/efl_util.h.in @@ -261,6 +261,17 @@ typedef enum } efl_util_input_pointer_type_e; /** + * @platform + * @brief Enumeration of pointer wheel event types. + * @since_tizen 5.5 + */ +typedef enum +{ + EFL_UTIL_INPUT_POINTER_WHEEL_VERT, /**< Vertical wheel. */ + EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, /**< Horizontal wheel. */ +} efl_util_input_pointer_wheel_type_e; + +/** * @platform * @brief Initializes system and check input generate functions are supported, open devices generated events. * @since_tizen $TZ_CFG_VER_24_OR_30$ @@ -398,6 +409,67 @@ API int efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, e API int efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl_util_input_pointer_type_e pointer_type, int x, int y); /** + * @platform + * @brief Generates a wheel event using an opened device. + * @details Commonly wheel events are generated with one of two orientations, vertical and horizontal. + * #efl_util_input_pointer_wheel_type_e has enums for orientations. + * For each orientation there is a value which represents both size and direction. + * For #EFL_UTIL_INPUT_POINTER_WHEEL_VERT, if the value is positive, the direction is "up", if it's negative, the direction is "down" + * For #EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, if the value is positive, the direction is "right", if it's negative, the direction is "left" + * General mouse devices generate wheel events with value 1 or -1, + * but some mouse devices have a smooth wheel which generates wheel events with value bigger than absolute 1. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/inputgenerator + * @param[in] inputgen_h The #efl_util_inputgen_h handle + * @param[in] wheel_type The wheel type (ex> #EFL_UTIL_INPUT_POINTER_WHEEL_VERT, #EFL_UTIL_INPUT_POINTER_WHEEL_HORZ) + * @param[in] value The wheel value + * @return @c 0 on success, otherwise a negative error value + * @retval #EFL_UTIL_ERROR_NONE Successful + * @retval #EFL_UTIL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EFL_UTIL_ERROR_PERMISSION_DENIED No permission to generate a wheel event + * @retval #EFL_UTIL_ERROR_NO_SUCH_DEVICE No such device or address + * @retval #EFL_UTIL_ERROR_OUT_OF_MEMORY Memory allocation failure + * @retval #EFL_UTIL_ERROR_NOT_SUPPORTED Not supported + */ +API int efl_util_input_generate_wheel(efl_util_inputgen_h inputgen_h, efl_util_input_pointer_wheel_type_e wheel_type, int value); + +/** + * @platform + * @brief Generates a touch event using an opened device. + * @details Normally touch events are represented by a specific point (x, y). + * But there are many contact points between touchscreen and fingers. + * The coordinates (x, y) are the center of the contact area, and the area where the finger and the touchscreen come into contact is represented with an ellipse. + * To give information about the size of the touching cllipse, use @a radius_x and @a radius_y. + * The value of @a idx is touch index used in multi-touch. 0 means first touch, 1 means second touch and the index increases further. + * General devices support 10 touch indices(0 ~ 9), but this may differ depending on the device. + * Some devices may not support the @a palm value, and this value is closely dependent on device. + * The value of @a x, @a y, @a radius_x, @a radius_y, @a pressure and @a palm must be greater than 0. + * The @a angle is the angle between the vertical edge of the device and the y-axis of the ellipse. If the @a angle is 0, then the ellipse's y-axis is parallel to the device's vertical edge. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/inputgenerator + * @param[in] inputgen_h The #efl_util_inputgen_h handle + * @param[in] idx The index of the touching finger, used in multi-touch + * @param[in] touch_type The touch type (ex> #EFL_UTIL_INPUT_TOUCH_BEGIN, #EFL_UTIL_INPUT_TOUCH_UPDATE, #EFL_UTIL_INPUT_TOUCH_END) + * @param[in] x The x coordinate of the touch point + * @param[in] y The y coordinate of the touch point + * @param[in] radius_x The x-axis radius of the touching ellipse before rotation + * @param[in] radius_y The y-axis radius of the touching ellipse before rotation + * @param[in] pressure The pressure on the contact touch area + * @param[in] angle The rotation angle of the touching ellipse, in degrees + * @param[in] palm The palm area of the contact touch area + * @return @c 0 on success, otherwise a negative error value + * @retval #EFL_UTIL_ERROR_NONE Successful + * @retval #EFL_UTIL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EFL_UTIL_ERROR_PERMISSION_DENIED No permission to generate a touch event + * @retval #EFL_UTIL_ERROR_NO_SUCH_DEVICE No such device or address + * @retval #EFL_UTIL_ERROR_OUT_OF_MEMORY Memory allocation failure + * @retval #EFL_UTIL_ERROR_NOT_SUPPORTED Not supported + */ +API int efl_util_input_generate_touch_axis(efl_util_inputgen_h inputgen_h, int idx, efl_util_input_touch_type_e touch_type, int x, int y, double radius_x, double radius_y, double pressure, double angle, double palm); + +/** * @} */ diff --git a/src/efl_util.c b/src/efl_util.c index 46d35dc..5995e3d 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -95,6 +95,7 @@ static inline tizen_profile_t get_tizen_profile() #define LOG_TAG "TIZEN_N_EFL_UTIL" #define EFL_UTIL_INPUT_GENERATOR_DEFAULT_TIME_OUT 1000 #define EFL_UTIL_INPUT_GENERATOR_DEFAULT_DISPATCH_TIME_OUT 10 +#define EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER 10 typedef struct _Efl_Util_Wl_Surface_Lv_Info { @@ -173,6 +174,15 @@ typedef struct _Efl_Util_Device_Info Eina_Stringshare *name; } Efl_Util_Device_Info; +typedef struct _E_Devicemgr_Inputgen_Touch_Axis +{ + double radius_x; + double radius_y; + double pressure; + double angle; + double palm; +} E_Devicemgr_Inputgen_Touch_Axis; + typedef struct _Efl_Util_Data { /* wayland related stuffs */ @@ -243,7 +253,7 @@ static Efl_Util_Data _eflutil = NULL, NULL, NULL, { 0, NULL, NULL, NULL }, /* tizen_policy protocol */ { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ - { NULL, -1 }, /* tizen_input_device_manager protocol */ + { NULL, -1, NULL, NULL, NULL }, /* tizen_input_device_manager protocol */ { 0, NULL, NULL } /* display_policy protocol */ }, }; @@ -1229,6 +1239,7 @@ struct _efl_util_inputgen_h { unsigned int init_type; char name[32]; + E_Devicemgr_Inputgen_Touch_Axis *axis_info; }; static Eina_Bool @@ -1707,6 +1718,9 @@ efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h) if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER) clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE; + if (inputgen_h->axis_info) + free(inputgen_h->axis_info); + free(inputgen_h); inputgen_h = NULL; @@ -1786,6 +1800,146 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, return ret; } +static int +_efl_util_input_generate_touch_axis_send(unsigned int type, double value) +{ + int ret; + + tizen_input_device_manager_generate_axis(_eflutil.wl.devmgr.devicemgr, type, wl_fixed_from_double(value)); + + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; + + return ret; +} + +static void +_efl_util_input_generate_touch_axis_cleanup(efl_util_inputgen_h inputgen_h, int idx) +{ + int i; + if (idx >= 0) + { + inputgen_h->axis_info[idx].radius_x = 1.0; + inputgen_h->axis_info[idx].radius_y = 1.0; + inputgen_h->axis_info[idx].pressure = 1.0; + inputgen_h->axis_info[idx].angle = 0.0; + inputgen_h->axis_info[idx].palm = 0.0; + } + else + { + for (i = 0; i < EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER; i++) + { + inputgen_h->axis_info[i].radius_x = 1.0; + inputgen_h->axis_info[i].radius_y = 1.0; + inputgen_h->axis_info[i].pressure = 1.0; + inputgen_h->axis_info[i].angle = 0.0; + inputgen_h->axis_info[i].palm = 0.0; + } + } +} + +static int +_efl_util_input_generate_touch_axis_process(efl_util_inputgen_h inputgen_h, int idx, double radius_x, + double radius_y, double pressure, double angle, double palm) +{ + int ret = EFL_UTIL_ERROR_NONE; + + if (!inputgen_h->axis_info) + { + inputgen_h->axis_info = calloc(EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER, + sizeof(E_Devicemgr_Inputgen_Touch_Axis)); + _efl_util_input_generate_touch_axis_cleanup(inputgen_h, -1); + } + + if (inputgen_h->axis_info[idx].radius_x != radius_x) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_X, radius_x); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].radius_x = radius_x; + } + if (inputgen_h->axis_info[idx].radius_y != radius_y) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_Y, radius_y); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].radius_y = radius_y; + } + if (inputgen_h->axis_info[idx].pressure != pressure) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PRESSURE, pressure); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].pressure = pressure; + } + if (inputgen_h->axis_info[idx].angle != angle) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_ANGLE, angle); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].angle = angle; + } + if (inputgen_h->axis_info[idx].palm != palm) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PALM, palm); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].palm = palm; + } + + return ret; +} + +API int +efl_util_input_generate_touch_axis(efl_util_inputgen_h inputgen_h, int idx, + efl_util_input_touch_type_e touch_type, int x, int y, + double radius_x, double radius_y, + double pressure, double angle, double palm) +{ + int ret, version; + enum tizen_input_device_manager_pointer_event_type type; + + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + EINA_SAFETY_ON_FALSE_RETURN_VAL((radius_x >= 0.0 && radius_y >= 0.0), EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL((pressure >= 0.0 && palm >= 0.0), EFL_UTIL_ERROR_INVALID_PARAMETER); + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + version = tizen_input_device_manager_get_version(_eflutil.wl.devmgr.devicemgr); + EINA_SAFETY_ON_FALSE_RETURN_VAL((version >= 3), EFL_UTIL_ERROR_NOT_SUPPORTED); + + switch(touch_type) + { + case EFL_UTIL_INPUT_TOUCH_BEGIN: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN; + break; + case EFL_UTIL_INPUT_TOUCH_UPDATE: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE; + break; + case EFL_UTIL_INPUT_TOUCH_END: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END; + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (touch_type != EFL_UTIL_INPUT_TOUCH_END) + _efl_util_input_generate_touch_axis_process(inputgen_h, idx, radius_x, radius_y, pressure, angle, palm); + else + _efl_util_input_generate_touch_axis_cleanup(inputgen_h, idx); + + tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx); + + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; + + return ret; +} + + API int efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl_util_input_pointer_type_e pointer_type, int x, int y) { @@ -1825,6 +1979,43 @@ efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl return ret; } +API int +efl_util_input_generate_wheel(efl_util_inputgen_h inputgen_h, efl_util_input_pointer_wheel_type_e wheel_type, int value) +{ + int ret, version; + enum tizen_input_device_manager_pointer_event_type type; + + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + version = tizen_input_device_manager_get_version(_eflutil.wl.devmgr.devicemgr); + EINA_SAFETY_ON_FALSE_RETURN_VAL((version >= 3), EFL_UTIL_ERROR_NOT_SUPPORTED); + + switch(wheel_type) + { + case EFL_UTIL_INPUT_POINTER_WHEEL_VERT: + type = TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_WHEEL; + break; + case EFL_UTIL_INPUT_POINTER_WHEEL_HORZ: + type = TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_HWHEEL; + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + tizen_input_device_manager_generate_axis(_eflutil.wl.devmgr.devicemgr, type, wl_fixed_from_int(value)); + + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; + + return ret; +} + + struct _efl_util_screenshot_h { -- 2.7.4