efl_util.c add wl_seat
[platform/core/api/efl-util.git] / src / efl_util.c
index a8b882f..902b0db 100644 (file)
@@ -216,7 +216,10 @@ typedef struct _Efl_Util_Data
          Eina_List *devices;
          Eina_List *wait_devices;
          struct wl_event_source *wait_timer;
+         int max_touch_count;
+         int request_touch_count;
       } devmgr;
+      struct wl_seat *seat;
       struct
       {
          unsigned int id;
@@ -253,7 +256,8 @@ 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, NULL, NULL, NULL }, /* tizen_input_device_manager protocol */
+      { NULL, -1, NULL, NULL, NULL, 0, 0 }, /* tizen_input_device_manager protocol */
+      NULL, /* wl_seat protocol */
       { 0, NULL, NULL } /* display_policy protocol */
    },
 };
@@ -297,6 +301,7 @@ static void                    _cb_device_add(void *data EINA_UNUSED, struct tiz
 static void                    _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier  EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
 static void                    _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
 static void                    _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
+static void                    _cb_max_touch_count(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, int32_t max_count EINA_UNUSED, struct wl_seat *seat EINA_UNUSED);
 
 static void                    _cb_gesture_edge_swipe_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t edge EINA_UNUSED, uint32_t edge_size EINA_UNUSED, uint32_t start_point EINA_UNUSED, uint32_t end_point EINA_UNUSED, uint32_t error);
 static void                    _cb_gesture_edge_swipe(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int sx, int sy, uint32_t edge);
@@ -347,7 +352,8 @@ struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
    _cb_device_add,
    _cb_device_remove,
    _cb_error,
-   _cb_block_expired
+   _cb_block_expired,
+   _cb_max_touch_count
 };
 
 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
@@ -529,6 +535,22 @@ static const struct tizen_screenshooter_listener tz_screenshooter_listener =
 };
 
 static void
+_cb_seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
+{
+}
+
+static void
+_cb_seat_name(void *data, struct wl_seat *seat EINA_UNUSED, const char *name)
+{
+}
+
+static const struct wl_seat_listener _seat_listener =
+{
+   _cb_seat_capabilities,
+   _cb_seat_name,
+};
+
+static void
 _cb_wl_reg_global(void *data,
                   struct wl_registry *reg,
                   unsigned int id,
@@ -563,6 +585,11 @@ _cb_wl_reg_global(void *data,
         output->output = wl_registry_bind(reg, id, &wl_output_interface, version);
         wl_output_add_listener(output->output, &output_listener, output);
      }
+   else if(strcmp(interface, "wl_seat") == 0)
+     {
+        _eflutil.wl.seat = wl_registry_bind(reg, id, &wl_seat_interface, version);
+        wl_seat_add_listener(_eflutil.wl.seat, &_seat_listener, NULL);
+     }
    else if (strcmp(interface, "tizen_input_device_manager") == 0)
      {
         _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, id, &tizen_input_device_manager_interface, version);
@@ -1396,6 +1423,16 @@ _cb_block_expired(void *data EINA_UNUSED,
 }
 /* LCOV_EXCL_STOP */
 
+static void
+_cb_max_touch_count(void *data EINA_UNUSED,
+                    struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
+                    uint32_t serial EINA_UNUSED,
+                    int32_t max_count,
+                    struct wl_seat *seat EINA_UNUSED)
+{
+   _eflutil.wl.devmgr.max_touch_count = max_count;
+}
+
 static efl_util_error_e
 _efl_util_input_convert_input_generator_error(int ret)
 {
@@ -1409,6 +1446,8 @@ _efl_util_input_convert_input_generator_error(int ret)
            return EFL_UTIL_ERROR_OUT_OF_MEMORY;
         case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
            return EFL_UTIL_ERROR_INVALID_PARAMETER;
+        case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED:
+           return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE;
         default :
            return EFL_UTIL_ERROR_NONE;
      }
@@ -1706,6 +1745,39 @@ out:
 }
 
 API int
+efl_util_input_set_touch_count(int max_count)
+{
+   int ret = EFL_UTIL_ERROR_NONE;
+
+   ret = _wl_init();
+   if (ret == (int)EINA_FALSE)
+     {
+        return EFL_UTIL_ERROR_INVALID_PARAMETER;
+     }
+
+   while (!_eflutil.wl.devmgr.devicemgr)
+     wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
+
+   if (_eflutil.wl.devmgr.max_touch_count >= max_count)
+     return EFL_UTIL_ERROR_NONE;
+
+   tizen_input_device_manager_set_touch_count(_eflutil.wl.devmgr.devicemgr, max_count);
+
+   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;
+
+   if (ret == EFL_UTIL_ERROR_NONE)
+     {
+        _eflutil.wl.devmgr.request_touch_count = max_count;
+     }
+
+   return ret;
+}
+
+API int
 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
 {
    int ret = EFL_UTIL_ERROR_NONE;
@@ -1773,6 +1845,9 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
    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);
 
+   if (idx >= _eflutil.wl.devmgr.max_touch_count)
+     return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
 
    switch(touch_type)
@@ -2114,6 +2189,8 @@ efl_util_screenshot_initialize(int width, int height)
           {
              set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
              _screenshot_mutex_unlock();
+             if (screenshot)
+                free(screenshot);
              return NULL;
           }
         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
@@ -2186,6 +2263,8 @@ fail_memory:
    if (display_wrapper)
      wl_proxy_wrapper_destroy(display_wrapper);
    set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
+   if (screenshot)
+     free(screenshot);
    _screenshot_mutex_unlock();
    return NULL;