+
+static void
+_efl_util_destroy_mirror_buffer(efl_util_mirror_buffer *mbuffer)
+{
+ EINA_SAFETY_ON_NULL_RETURN(mbuffer);
+
+ if (mbuffer->buffer)
+ wl_buffer_destroy(mbuffer->buffer);
+
+ free(mbuffer);
+}
+
+static void
+_efl_util_screenmirror_handle_dequeued(void *data,
+ struct tizen_screenmirror *tz_screenmirror, struct wl_buffer *buffer)
+{
+ efl_util_screenmirror_h screenmirror;
+ efl_util_mirror_buffer *mbuffer;
+ Eina_List *l, *ll;
+
+ screenmirror = (efl_util_screenmirror_h)data;
+ screenmirror->cb_start = EINA_TRUE;
+
+ EINA_LIST_FOREACH_SAFE(screenmirror->buffer_list, l, ll, mbuffer)
+ {
+ if (mbuffer->buffer == buffer)
+ {
+ if (mbuffer->w != screenmirror->width || mbuffer->h != screenmirror->height ||
+ !screenmirror->mirror_working)
+ tbm_surface_destroy(mbuffer->t_surface);
+ else
+ screenmirror->user_func(screenmirror, mbuffer->t_surface, screenmirror->user_data);
+
+ screenmirror->buffer_list = eina_list_remove_list(screenmirror->buffer_list, l);
+ _efl_util_destroy_mirror_buffer(mbuffer);
+
+ break;
+ }
+ }
+
+ mbuffer = _efl_util_create_mirror_buffer(screenmirror);
+ if (mbuffer == NULL)
+ {
+ fprintf(stderr, "[screenmirror] fail: buffer create\n");
+ return;
+ }
+ screenmirror->buffer_list = eina_list_append(screenmirror->buffer_list, mbuffer);
+ tizen_screenmirror_queue(screenmirror->tz_screenmirror, mbuffer->buffer);
+}
+
+static void
+_efl_util_screenmirror_handle_content(void *data,
+ struct tizen_screenmirror *tz_screenmirror, uint32_t content)
+{
+ efl_util_screenmirror_h screenmirror = NULL;
+
+ screenmirror = (efl_util_screenmirror_h)data;
+ screenmirror->cb_content = EINA_TRUE;
+}
+
+static void
+_efl_util_screenmirror_handle_stop(void *data, struct tizen_screenmirror *tz_screenmirror)
+{
+ efl_util_screenmirror_h screenmirror = NULL;
+
+ screenmirror = (efl_util_screenmirror_h)data;
+ screenmirror->cb_stop = EINA_TRUE;
+}
+
+static const struct tizen_screenmirror_listener efl_util_screenmirror_listener = {
+ _efl_util_screenmirror_handle_dequeued,
+ _efl_util_screenmirror_handle_content,
+ _efl_util_screenmirror_handle_stop
+};
+
+API efl_util_screenmirror_h
+efl_util_screenmirror_initialize(int width, int height)
+{
+ efl_util_screenmirror_h screenmirror = NULL;
+ efl_util_mirror_buffer *mbuffer;
+ Efl_Util_Wl_Output_Info *output;
+ int ret = 0, i;
+
+ if (width <= 0 || height <= 0)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ _screenshot_mutex_lock();
+
+ if (g_screenmirror)
+ {
+ if (g_screenmirror->mirror_working)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_OPERATION);
+ _screenshot_mutex_unlock();
+ return NULL;
+ }
+ else
+ {
+ g_screenmirror->width = width;
+ g_screenmirror->height = height;
+ set_last_result(EFL_UTIL_ERROR_NONE);
+ _screenshot_mutex_unlock();
+ return g_screenmirror;
+ }
+ }
+
+ screenmirror = calloc(1, sizeof(struct _efl_util_screenmirror_h));
+ if (screenmirror == NULL)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
+ _screenshot_mutex_unlock();
+ return NULL;
+ }
+
+ if (!_eflutil.wl.shot.tz_screenshooter)
+ {
+ if (_efl_util_wl_screenshooter_init() == EINA_FALSE)
+ {
+ if (_eflutil.wl.shot.noti == 0)
+ set_last_result(EFL_UTIL_ERROR_PERMISSION_DENIED);
+ else
+ set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
+
+ goto fail_wl_init;
+ }
+ }
+
+ output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
+ if (!output)
+ {
+ set_last_result(EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE);
+ fprintf(stderr, "[screenmirror] fail: no output for screenmirror\n");
+ goto fail_get_output;
+ }
+
+ screenmirror->tz_screenmirror = tizen_screenshooter_get_screenmirror(_eflutil.wl.shot.tz_screenshooter, output->output);
+ wl_proxy_set_queue((struct wl_proxy *)screenmirror->tz_screenmirror, _eflutil.wl.shot.queue);
+ tizen_screenmirror_add_listener(screenmirror->tz_screenmirror, &efl_util_screenmirror_listener, screenmirror);
+ tizen_screenmirror_set_stretch(screenmirror->tz_screenmirror, TIZEN_SCREENMIRROR_STRETCH_KEEP_RATIO);
+ screenmirror->width = width;
+ screenmirror->height = height;
+
+ g_screenmirror = screenmirror;
+
+ for (i = 0; i < 1; i++)
+ {
+ mbuffer = _efl_util_create_mirror_buffer(screenmirror);
+ if (mbuffer)
+ {
+ screenmirror->buffer_list = eina_list_append(screenmirror->buffer_list, mbuffer);
+ tizen_screenmirror_queue(screenmirror->tz_screenmirror, mbuffer->buffer);
+ }
+ else
+ fprintf(stderr, "[screenmirror] fail: buffer create %d\n", i);
+ }
+ while (!screenmirror->cb_content && ret != -1)
+ ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
+
+ _screenshot_mutex_unlock();
+
+ return screenmirror;
+
+fail_get_output:
+fail_wl_init:
+ free(screenmirror);
+ _screenshot_mutex_unlock();
+ return NULL;
+}
+
+API int
+efl_util_screenmirror_deinitialize(efl_util_screenmirror_h screenmirror)
+{
+ efl_util_mirror_buffer *mbuffer;
+ Eina_List *l;
+
+ _screenshot_mutex_lock();
+
+ if (!screenmirror || (screenmirror != g_screenmirror))
+ {
+ _screenshot_mutex_unlock();
+ _screenshot_mutex_destory();
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (screenmirror->mirror_working)
+ {
+ fprintf(stderr, "[screenmirror] fail: execute stop before deinit\n");
+ _screenshot_mutex_unlock();
+ _screenshot_mutex_destory();
+ return EFL_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ EINA_LIST_FOREACH(screenmirror->buffer_list, l, mbuffer)
+ {
+ tbm_surface_destroy(mbuffer->t_surface);
+ _efl_util_destroy_mirror_buffer(mbuffer);
+ }
+ eina_list_free(screenmirror->buffer_list);
+
+ tizen_screenmirror_destroy(screenmirror->tz_screenmirror);
+ free(screenmirror);
+ g_screenmirror = NULL;
+
+ _efl_util_wl_screenshooter_deinit();
+
+ _screenshot_mutex_unlock();
+ _screenshot_mutex_destory();
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_screenmirror_set_handler(efl_util_screenmirror_h screenmirror,
+ efl_util_screenmirror_handler func, void *data)
+{
+ _screenshot_mutex_lock();
+
+ if (!screenmirror || (screenmirror != g_screenmirror) || !func)
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ screenmirror->user_func = func;
+ screenmirror->user_data = data;
+
+ _screenshot_mutex_unlock();
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_screenmirror_start(efl_util_screenmirror_h screenmirror)
+{
+ int ret = 0;
+
+ _screenshot_mutex_lock();
+
+ if (!screenmirror || (screenmirror != g_screenmirror))
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ else if (!screenmirror->user_func)
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL;
+ }
+ else if (screenmirror->mirror_working)
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_NONE;
+ }
+
+ screenmirror->cb_start = EINA_FALSE;
+ screenmirror->mirror_working = EINA_TRUE;
+ tizen_screenmirror_start(screenmirror->tz_screenmirror);
+ while (!screenmirror->cb_start && ret != -1)
+ ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
+ if (ret == -1)
+ {
+ fprintf(stderr, "[screenmirror] fail: tizen_screenmirror_start\n");
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL;
+ }
+
+ ret = pthread_create(&screenmirror->thread, NULL, _efl_util_screenmirror_loop, screenmirror);
+ if (ret < 0)
+ {
+ fprintf(stderr, "[screenmirror] fail: thread create fail\n");
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL;
+ }
+
+ pthread_setname_np(screenmirror->thread, "e_util_mirror");
+
+ _screenshot_mutex_unlock();
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_screenmirror_stop(efl_util_screenmirror_h screenmirror)
+{
+ int ret = 0;
+
+ _screenshot_mutex_lock();
+
+ if (!screenmirror || (screenmirror != g_screenmirror))
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ else if (!screenmirror->mirror_working)
+ {
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_NONE;
+ }
+ screenmirror->mirror_working = EINA_FALSE;
+ pthread_join(screenmirror->thread, NULL);
+ tizen_screenmirror_stop(screenmirror->tz_screenmirror);
+ screenmirror->cb_stop = EINA_FALSE;
+
+ while (!screenmirror->cb_stop && ret != -1)
+ ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
+ if (ret == -1)
+ {
+ fprintf(stderr, "[screenmirror] fail: tizen_screenmirror_stop\n");
+ _screenshot_mutex_unlock();
+ return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL;
+ }
+
+ _screenshot_mutex_unlock();
+
+ return EFL_UTIL_ERROR_NONE;
+}
+/* LCOV_EXCL_STOP */
+
+struct _efl_util_gesture_h
+{
+ Eina_Bool init;
+};
+
+API int EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
+API int EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
+API int EFL_UTIL_EVENT_GESTURE_TAP = 0;
+API int EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
+
+/* LCOV_EXCL_START */
+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)
+{
+ _eflutil_defaultqueue.wl.gesture.request_notified = 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)
+{
+ efl_util_event_gesture_edge_swipe_s *ev = NULL;
+
+ ev = (efl_util_event_gesture_edge_swipe_s *)calloc(1, sizeof(*ev));
+ if (!ev) return;
+
+ ev->mode = mode;
+
+ ev->fingers = fingers;
+ ev->sx = sx;
+ ev->sy = sy;
+ ev->edge = edge;
+
+ ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE, ev, NULL, NULL);
+}
+
+static void
+_cb_gesture_edge_drag_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)
+{
+ _eflutil_defaultqueue.wl.gesture.request_notified = error;
+}
+
+static void
+_cb_gesture_edge_drag(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int cx, int cy, uint32_t edge)
+{
+ efl_util_event_gesture_edge_drag_s *ev = NULL;
+
+ ev = (efl_util_event_gesture_edge_drag_s *)calloc(1, sizeof(*ev));
+ if (!ev) return;
+
+ ev->mode = mode;
+
+ ev->fingers = fingers;
+ ev->cx = cx;
+ ev->cy = cy;
+ ev->edge = edge;
+
+ ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_DRAG, ev, NULL, NULL);
+}
+
+static void
+_cb_gesture_tap_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t repeat EINA_UNUSED, uint32_t error)
+{
+ _eflutil_defaultqueue.wl.gesture.request_notified = error;
+}
+
+static void
+_cb_gesture_tap(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, uint32_t repeats)
+{
+ efl_util_event_gesture_tap_s *ev = NULL;
+
+ ev = (efl_util_event_gesture_tap_s *)calloc(1, sizeof(*ev));
+ if (!ev) return;
+
+ ev->mode = mode;
+
+ ev->fingers = fingers;
+ ev->repeats = repeats;
+
+ ecore_event_add(EFL_UTIL_EVENT_GESTURE_TAP, ev, NULL, NULL);
+}
+/* LCOV_EXCL_STOP */
+
+static void
+_cb_gesture_palm_cover_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t error)
+{
+ _eflutil_defaultqueue.wl.gesture.request_notified = error;
+}
+
+/* LCOV_EXCL_START */
+static void
+_cb_gesture_palm_cover(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface, uint32_t mode, uint32_t duration, int cx, int cy, uint32_t size, wl_fixed_t pressure)
+{
+ efl_util_event_gesture_palm_cover_s *ev = NULL;
+
+ ev = (efl_util_event_gesture_palm_cover_s *)calloc(1, sizeof(*ev));
+ if (!ev) return;
+
+ ev->mode = mode;
+
+ ev->duration = duration;
+ ev->cx = cx;
+ ev->cy = cy;
+ ev->size = size;
+ ev->pressure = wl_fixed_to_int(pressure);
+
+ ecore_event_add(EFL_UTIL_EVENT_GESTURE_PALM_COVER, ev, NULL, NULL);
+}
+/* LCOV_EXCL_STOP */
+
+static void
+_cb_gesture_activate_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t type EINA_UNUSED, uint32_t active EINA_UNUSED, uint32_t error)
+{
+ _eflutil_defaultqueue.wl.gesture.request_notified = error;
+}
+
+static efl_util_error_e
+_efl_util_gesture_convert_error(int ret)
+{
+ switch (ret)
+ {
+ case TIZEN_GESTURE_ERROR_NONE:
+ return EFL_UTIL_ERROR_NONE;
+ case TIZEN_GESTURE_ERROR_INVALID_DATA:
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ case TIZEN_GESTURE_ERROR_NO_PERMISSION:
+ return EFL_UTIL_ERROR_PERMISSION_DENIED;
+ case TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES:
+ return EFL_UTIL_ERROR_OUT_OF_MEMORY;
+ case TIZEN_GESTURE_ERROR_GRABBED_ALREADY:
+ return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE;
+ case TIZEN_GESTURE_ERROR_NOT_SUPPORTED:
+ return EFL_UTIL_ERROR_NOT_SUPPORTED;
+ default :
+ return EFL_UTIL_ERROR_NONE;
+ }
+}
+
+/* LCOV_EXCL_START */
+static efl_util_error_e
+_efl_util_gesture_verify_request_notified()
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+
+ while (_eflutil_defaultqueue.wl.gesture.request_notified == -1)
+ wl_display_dispatch(_eflutil_defaultqueue.wl.dpy);
+
+ ret = _efl_util_gesture_convert_error(_eflutil_defaultqueue.wl.gesture.request_notified);
+ _eflutil_defaultqueue.wl.gesture.request_notified = -1;
+
+ return ret;
+}
+
+static int
+_efl_util_gesture_grab_edge_swipe(efl_util_gesture_data data, Eina_Bool grabbed)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+ Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL;
+ unsigned int fingers = 0;
+ unsigned int edge = 0;
+ unsigned int edge_size = 0;
+ unsigned int start_point = 0;
+ unsigned int end_point = 0;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil_defaultqueue.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data;
+
+ fingers = edge_swipe_data->fingers;
+ edge = edge_swipe_data->edge;
+ edge_size = edge_swipe_data->edge_size;
+ start_point = edge_swipe_data->start_point;
+ end_point = edge_swipe_data->end_point;
+
+ if (grabbed)
+ tizen_gesture_grab_edge_swipe(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
+ else
+ tizen_gesture_ungrab_edge_swipe(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+
+static int
+_efl_util_gesture_grab_edge_drag(efl_util_gesture_data data, Eina_Bool grabbed)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+ Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL;
+ unsigned int fingers = 0;
+ unsigned int edge = 0;
+ unsigned int edge_size = 0;
+ unsigned int start_point = 0;
+ unsigned int end_point = 0;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil_defaultqueue.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data;
+
+ fingers = edge_drag_data->fingers;
+ edge = edge_drag_data->edge;
+ edge_size = edge_drag_data->edge_size;
+ start_point = edge_drag_data->start_point;
+ end_point = edge_drag_data->end_point;
+
+ if (grabbed)
+ tizen_gesture_grab_edge_drag(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
+ else
+ tizen_gesture_ungrab_edge_drag(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+
+static int
+_efl_util_gesture_grab_tap(efl_util_gesture_data data, Eina_Bool grabbed)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+ Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL;
+ unsigned int fingers = 0;
+ unsigned int repeats = 0;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil_defaultqueue.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data;
+
+ fingers = tap_data->fingers;
+ repeats = tap_data->repeats;
+
+ if (grabbed)
+ tizen_gesture_grab_tap(_eflutil_defaultqueue.wl.gesture.proto, fingers, repeats);
+ else
+ tizen_gesture_ungrab_tap(_eflutil_defaultqueue.wl.gesture.proto, fingers, repeats);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+
+static int
+_efl_util_gesture_grab_palm_cover(efl_util_gesture_data data, Eina_Bool grabbed)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil_defaultqueue.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (grabbed)
+ tizen_gesture_grab_palm_cover(_eflutil_defaultqueue.wl.gesture.proto);
+ else
+ tizen_gesture_ungrab_palm_cover(_eflutil_defaultqueue.wl.gesture.proto);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+/* LCOV_EXCL_STOP */
+
+API efl_util_gesture_h
+efl_util_gesture_initialize(void)
+{
+ efl_util_gesture_h gesture_h = NULL;
+
+ gesture_h = (efl_util_gesture_h)calloc(1, sizeof(struct _efl_util_gesture_h));
+ if (!gesture_h)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
+ goto out; /* LCOV_EXCL_LINE */
+ }
+
+ if (_wl_init_default_queue() == (int)EINA_FALSE)
+ {
+ set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
+ goto out; /* LCOV_EXCL_LINE */
+ }
+
+ while (!_eflutil_defaultqueue.wl.gesture.proto)
+ wl_display_dispatch(_eflutil_defaultqueue.wl.dpy); /* LCOV_EXCL_LINE */
+
+ if (_eflutil_defaultqueue.wl.gesture.event_init <= 0)
+ {
+ if (ecore_event_init() <= 0)
+ {
+ set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
+ goto out; /* LCOV_EXCL_LINE */
+ }
+ EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = ecore_event_type_new();
+ EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = ecore_event_type_new();
+ EFL_UTIL_EVENT_GESTURE_TAP = ecore_event_type_new();
+ EFL_UTIL_EVENT_GESTURE_PALM_COVER = ecore_event_type_new();
+ }
+ _eflutil_defaultqueue.wl.gesture.event_init++;
+ gesture_h->init = EINA_TRUE;
+
+ set_last_result(EFL_UTIL_ERROR_NONE);
+ return gesture_h;
+
+out:
+/* LCOV_EXCL_START */
+ if (gesture_h)
+ {
+ free(gesture_h);
+ gesture_h = NULL;
+ }
+ return gesture_h;
+/* LCOV_EXCL_STOP */
+}
+
+API int
+efl_util_gesture_deinitialize(efl_util_gesture_h gesture_h)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ free(gesture_h);
+ gesture_h = NULL;
+
+ _eflutil_defaultqueue.wl.gesture.event_init--;
+
+ if (_eflutil_defaultqueue.wl.gesture.event_init <= 0)
+ {
+ _eflutil_defaultqueue.wl.gesture.event_init = 0;
+ ecore_event_shutdown();
+ EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
+ EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
+ EFL_UTIL_EVENT_GESTURE_TAP = 0;
+ EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
+ }
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API efl_util_gesture_data
+efl_util_gesture_edge_swipe_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
+{
+ Efl_Util_Gesture_Edge_Swipe_Grab_Data *data;
+
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Swipe_Grab_Data));
+ if (!data)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
+ return NULL; /* LCOV_EXCL_LINE */
+ }
+
+ data->base.type = TIZEN_GESTURE_TYPE_EDGE_SWIPE;
+ data->fingers = fingers;
+ data->edge = edge;
+ data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
+
+ set_last_result(EFL_UTIL_ERROR_NONE);
+
+ return (void *)data;
+}
+
+API int
+efl_util_gesture_edge_swipe_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!data)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ free(data);
+ data = NULL;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_gesture_edge_swipe_size_set(efl_util_gesture_data data, efl_util_gesture_edge_size_e edge_size, unsigned int start_point, unsigned int end_point)
+{
+ Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(edge_swipe_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_swipe_data->base.type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ edge_swipe_data->edge_size = edge_size;
+ edge_swipe_data->start_point = start_point;
+ edge_swipe_data->end_point = end_point;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API efl_util_gesture_data
+efl_util_gesture_edge_drag_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
+{
+ Efl_Util_Gesture_Edge_Drag_Grab_Data *data;
+
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Drag_Grab_Data));
+ if (!data)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
+ return NULL; /* LCOV_EXCL_LINE */
+ }
+
+ data->base.type = TIZEN_GESTURE_TYPE_EDGE_DRAG;
+ data->fingers = fingers;
+ data->edge = edge;
+ data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
+
+ set_last_result(EFL_UTIL_ERROR_NONE);
+
+ return (void *)data;
+}
+
+API int
+efl_util_gesture_edge_drag_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!data)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ free(data);
+ data = NULL;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API int
+efl_util_gesture_edge_drag_size_set(efl_util_gesture_data data, efl_util_gesture_edge_size_e edge_size, unsigned int start_point, unsigned int end_point)
+{
+ Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(edge_drag_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_drag_data->base.type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ edge_drag_data->edge_size = edge_size;
+ edge_drag_data->start_point = start_point;
+ edge_drag_data->end_point = end_point;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API efl_util_gesture_data
+efl_util_gesture_tap_new(efl_util_gesture_h gesture_h, unsigned int fingers, unsigned int repeats)
+{
+ Efl_Util_Gesture_Tap_Grab_Data *data;
+
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ if (fingers <= 1 || repeats <= 1)
+ {
+ set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED);
+ return NULL;
+ }
+
+ data = (Efl_Util_Gesture_Tap_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Tap_Grab_Data));
+ if (!data)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
+ return NULL; /* LCOV_EXCL_LINE */
+ }
+
+ data->base.type = TIZEN_GESTURE_TYPE_TAP;
+ data->fingers = fingers;
+ data->repeats = repeats;
+
+ set_last_result(EFL_UTIL_ERROR_NONE);
+
+ return (void *)data;
+}
+
+API int
+efl_util_gesture_tap_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!data)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ free(data);
+ data = NULL;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+API efl_util_gesture_data
+efl_util_gesture_palm_cover_new(efl_util_gesture_h gesture_h)
+{
+ Efl_Util_Gesture_Palm_Cover_Grab_Data *data;
+
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ data = (Efl_Util_Gesture_Palm_Cover_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Palm_Cover_Grab_Data));
+ if (!data)
+ {
+ set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
+ return NULL; /* LCOV_EXCL_LINE */
+ }
+
+ data->base.type = TIZEN_GESTURE_TYPE_PALM_COVER;
+
+ set_last_result(EFL_UTIL_ERROR_NONE);
+
+ return (void *)data;
+}
+
+API int
+efl_util_gesture_palm_cover_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ if (!gesture_h || gesture_h->init == EINA_FALSE)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!data)
+ {
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ free(data);
+ data = NULL;
+
+ return EFL_UTIL_ERROR_NONE;
+}
+
+/* LCOV_EXCL_START */
+API int
+efl_util_gesture_grab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ switch (base_data->type)
+ {
+ case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
+ ret = _efl_util_gesture_grab_edge_swipe(data, EINA_TRUE);
+ break;
+ case TIZEN_GESTURE_TYPE_EDGE_DRAG:
+ ret = _efl_util_gesture_grab_edge_drag(data, EINA_TRUE);
+ break;
+ case TIZEN_GESTURE_TYPE_TAP:
+ ret = _efl_util_gesture_grab_tap(data, EINA_TRUE);
+ break;
+ case TIZEN_GESTURE_TYPE_PALM_COVER:
+ ret = _efl_util_gesture_grab_palm_cover(data, EINA_TRUE);
+ break;
+ default:
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+
+API int
+efl_util_gesture_ungrab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
+{
+ int ret = EFL_UTIL_ERROR_NONE;
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ switch (base_data->type)
+ {
+ case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
+ ret = _efl_util_gesture_grab_edge_swipe(data, EINA_FALSE);
+ break;
+ case TIZEN_GESTURE_TYPE_EDGE_DRAG:
+ ret = _efl_util_gesture_grab_edge_drag(data, EINA_FALSE);
+ break;
+ case TIZEN_GESTURE_TYPE_TAP:
+ ret = _efl_util_gesture_grab_tap(data, EINA_FALSE);
+ break;
+ case TIZEN_GESTURE_TYPE_PALM_COVER:
+ ret = _efl_util_gesture_grab_palm_cover(data, EINA_FALSE);
+ break;
+ default:
+ return EFL_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+/* LCOV_EXCL_STOP */
+
+API int
+efl_util_gesture_select(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
+{
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+ Ecore_Wl2_Window *wlwin;
+ struct wl_surface *surface;
+ int ret;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
+ return EFL_UTIL_ERROR_NOT_SUPPORTED;
+
+ wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
+ if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ surface = ecore_wl2_window_surface_get(wlwin);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ tizen_gesture_select_palm_cover(_eflutil_defaultqueue.wl.gesture.proto, surface);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+
+API int
+efl_util_gesture_deselect(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
+{
+ Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
+ Ecore_Wl2_Window *wlwin;
+ struct wl_surface *surface;
+ int ret;
+
+ base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
+ return EFL_UTIL_ERROR_NOT_SUPPORTED;
+
+ wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
+ if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ surface = ecore_wl2_window_surface_get(wlwin);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ tizen_gesture_deselect_palm_cover(_eflutil_defaultqueue.wl.gesture.proto, surface);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+
+/* LCOV_EXCL_START */
+API int
+efl_util_gesture_activate_set(efl_util_gesture_h gesture_h, unsigned int type, Eina_Bool active)
+{
+ int ret;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ tizen_gesture_activate_set(_eflutil_defaultqueue.wl.gesture.proto, NULL, type, active);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}
+/* LCOV_EXCL_STOP */
+
+API int
+efl_util_gesture_activate_set_on_window(efl_util_gesture_h gesture_h, Evas_Object *window, unsigned int type, Eina_Bool active)
+{
+ Ecore_Wl2_Window *wlwin;
+ struct wl_surface *surface;
+ int ret;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
+ if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
+
+ surface = ecore_wl2_window_surface_get(wlwin);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
+ EFL_UTIL_ERROR_INVALID_PARAMETER);
+
+ tizen_gesture_activate_set(_eflutil_defaultqueue.wl.gesture.proto, surface, type, active);
+
+ ret = _efl_util_gesture_verify_request_notified();
+
+ return ret;
+}