input_generator: add new APIs to generate axis events
[platform/core/api/efl-util.git] / src / efl_util.c
index 46d35dc..5995e3d 100644 (file)
@@ -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
 {