72295c3f571f37baae6a6e49889b4c7740208235
[platform/core/api/efl-util.git] / src / efl_util.c
1 /*
2  * Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define LOG_TAG "TIZEN_N_EFL_UTIL"
18
19 #include <efl_util.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <xf86drm.h>
28 #include <tbm_bufmgr.h>
29 #include <tbm_surface.h>
30 #include <tbm_surface_internal.h>
31 #include <Elementary.h>
32 #include <Ecore_Evas.h>
33 #include <pthread.h>
34
35 #include <Ecore_Wl2.h>
36 #include <wayland-client.h>
37 #include <wayland-tbm-client.h>
38 #include <tizen-extension-client-protocol.h>
39 #include <screenshooter-client-protocol.h>
40
41 #include <efl_util_screenshot_extension.h>
42
43 #include <dlog.h>
44 #ifdef LOG_TAG
45 #undef LOG_TAG
46 #endif
47
48 /* Determine Tizen profile at runtime */
49 #include <system_info.h>
50 typedef enum {
51    TIZEN_PROFILE_UNKNOWN = 0,
52    TIZEN_PROFILE_MOBILE = 0x1,
53    TIZEN_PROFILE_WEARABLE = 0x2,
54    TIZEN_PROFILE_TV = 0x4,
55    TIZEN_PROFILE_IVI = 0x8,
56    TIZEN_PROFILE_COMMON = 0x10,
57 } tizen_profile_t;
58 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
59 static tizen_profile_t _get_tizen_profile()
60 {
61    char *profileName;
62    system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
63    switch (*profileName) {
64    case 'm':
65    case 'M':
66      profile = TIZEN_PROFILE_MOBILE;
67      break;
68    case 'w':
69    case 'W':
70      profile = TIZEN_PROFILE_WEARABLE;
71      break;
72    case 't':
73    case 'T':
74      profile = TIZEN_PROFILE_TV;
75      break;
76    case 'i':
77    case 'I':
78      profile = TIZEN_PROFILE_IVI;
79      break;
80    default: // common or unknown ==> ALL ARE COMMON.
81      profile = TIZEN_PROFILE_COMMON;
82    }
83    free(profileName);
84
85    return profile;
86 }
87 static inline tizen_profile_t get_tizen_profile()
88 {
89    if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
90      return profile;
91    return _get_tizen_profile();
92 }
93
94
95 #define LOG_TAG "TIZEN_N_EFL_UTIL"
96
97
98 /* callback handler index */
99 #define CBH_NOTI_LEV 0
100 #define CBH_SCR_MODE 1
101 #define CBH_MAX      2
102
103 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
104
105 typedef struct _Efl_Util_Callback_Info
106 {
107    Evas_Object *win;
108    Efl_Util_Cb cb;
109    void *data;
110 } Efl_Util_Callback_Info;
111
112 typedef struct _Efl_Util_Wl_Surface_Lv_Info
113 {
114    void *surface; /* wl_surface */
115    int level;
116    Eina_Bool wait_for_done;
117    uint32_t state;
118 } Efl_Util_Wl_Surface_Lv_Info;
119
120 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
121 {
122    void *surface; /* wl_surface */
123    unsigned int mode;
124    Eina_Bool wait_for_done;
125    uint32_t state;
126 } Efl_Util_Wl_Surface_Scr_Mode_Info;
127
128 typedef struct _Efl_Util_Wl_Surface_Brightness_Info
129 {
130    void *surface; /* wl_surface */
131    int brightness;
132    Eina_Bool wait_for_done;
133    uint32_t state;
134 } Efl_Util_Wl_Surface_Brightness_Info;
135
136 typedef struct _Efl_Util_Wl_Output_Info
137 {
138     struct wl_output *output;
139     int offset_x, offset_y, width, height;
140 } Efl_Util_Wl_Output_Info;
141
142 typedef struct _Efl_Util_Gesture_Common_Grab_Data
143 {
144    int type;
145 } Efl_Util_Gesture_Common_Grab_Data;
146
147 typedef struct _Efl_Util_Gesture_Edge_Swipe_Grab_Data
148 {
149    Efl_Util_Gesture_Common_Grab_Data base;
150
151    unsigned int fingers;
152    efl_util_gesture_edge_e edge;
153    efl_util_gesture_edge_size_e edge_size;
154    unsigned int start_point;
155    unsigned int end_point;
156 } Efl_Util_Gesture_Edge_Swipe_Grab_Data;
157
158 typedef struct _Efl_Util_Gesture_Edge_Drag_Grab_Data
159 {
160    Efl_Util_Gesture_Common_Grab_Data base;
161
162    unsigned int fingers;
163    efl_util_gesture_edge_e edge;
164    efl_util_gesture_edge_size_e edge_size;
165    unsigned int start_point;
166    unsigned int end_point;
167 } Efl_Util_Gesture_Edge_Drag_Grab_Data;
168
169 typedef struct _Efl_Util_Gesture_Tap_Grab_Data
170 {
171    Efl_Util_Gesture_Common_Grab_Data base;
172
173    unsigned int fingers;
174    unsigned int repeats;
175 } Efl_Util_Gesture_Tap_Grab_Data;
176
177 typedef struct _Efl_Util_Gesture_Palm_Cover_Grab_Data
178 {
179    Efl_Util_Gesture_Common_Grab_Data base;
180 } Efl_Util_Gesture_Palm_Cover_Grab_Data;
181
182 typedef struct _Efl_Util_Data
183 {
184    /* wayland related stuffs */
185    struct
186    {
187       Eina_Bool init;
188       Ecore_Wl2_Display *wl2_display;
189       struct wl_display *dpy;
190       struct wl_event_queue *queue;
191       int dpy_fd;
192       Ecore_Fd_Handler *fd_hdl;
193
194       struct
195       {
196          unsigned int id;
197          struct tizen_policy *proto;
198          Eina_Hash *hash_noti_lv;
199          Eina_Hash *hash_scr_mode;
200       } policy;
201       struct
202       {
203          struct wl_event_queue *queue;
204          struct screenshooter *screenshooter;
205          struct tizen_screenshooter *tz_screenshooter;
206          struct wayland_tbm_client *tbm_client;
207          Eina_List *output_list;
208          uint32_t noti;
209       } shot;
210       struct
211       {
212          struct tizen_input_device_manager *devicemgr;
213          int request_notified;
214       } devmgr;
215       struct
216       {
217          unsigned int id;
218          struct tizen_display_policy *proto;
219          Eina_Hash *hash_brightness;
220       } display_policy;
221       struct
222       {
223          struct tizen_gesture *proto;
224          int request_notified;
225          int event_init;
226       } gesture;
227    } wl;
228
229    struct
230    {
231       Eina_List *info_list; /* list of callback info */
232       unsigned int atom; /* x11 atom */
233    } cb_handler[CBH_MAX];
234 } Efl_Util_Data;
235
236 static Efl_Util_Data _eflutil =
237 {
238    {
239       EINA_FALSE,
240       NULL, NULL, NULL,
241       -1, NULL,
242       { 0, NULL, NULL, NULL }, /* tizen_policy protocol */
243       { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */
244       { NULL, -1 }, /* tizen_input_device_manager protocol */
245       { 0, NULL, NULL }, /* display_policy protocol */
246       { NULL, -1, EINA_FALSE } /* tizen_gesture protocol */
247    },
248    {
249       { NULL, 0 }, /* handler for notification level */
250       { NULL, 0 }  /* handler for screen mode */
251    },
252 };
253
254 static Eina_Bool               _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
255 static Eina_Bool               _cb_info_del_by_win(Evas_Object *win, int idx);
256 static Eina_List              *_cb_info_list_get(int idx);
257 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
258 static Eina_Bool               _wl_init(void);
259 static void                    _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
260 static void                    _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
261 static void                    _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
262 static void                    _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name);
263 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
264 static void                    _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant);
265 static void                    _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h);
266 static void                    _cb_wl_tz_policy_notification_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, int32_t level, uint32_t state);
267 static void                    _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id);
268 static void                    _cb_wl_tz_policy_scr_mode_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t mode, uint32_t state);
269 static void                    _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force);
270 static void                    _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints);
271 static void                    _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id);
272 static void                    _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options);
273 static void                    _cb_wl_conformant_region(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial);
274
275 static void                    _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state);
276
277 static void                    _cb_device_add(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);
278 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);
279 static void                    _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode);
280 static void                    _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED);
281
282 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);
283 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);
284 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);
285 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);
286 static void                    _cb_gesture_tap_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t repeats EINA_UNUSED, uint32_t error);
287 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);
288 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);
289 static void                    _cb_gesture_palm_cover(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t mode, uint32_t duration, int cx, int cy, uint32_t size, wl_fixed_t pressure);
290 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);
291
292
293 static const struct wl_registry_listener _wl_reg_listener =
294 {
295    _cb_wl_reg_global,
296    _cb_wl_reg_global_remove
297 };
298
299 static const struct wl_registry_listener _wl_reg_screenshooter_listener =
300 {
301    _cb_wl_reg_screenshooter_global,
302    _cb_wl_reg_screenshooter_global_remove
303 };
304
305 struct tizen_policy_listener _wl_tz_policy_listener =
306 {
307    _cb_wl_tz_policy_conformant,
308    _cb_wl_tz_policy_conformant_area,
309    _cb_wl_tz_policy_notification_done,
310    _cb_wl_tz_policy_transient_for_done,
311    _cb_wl_tz_policy_scr_mode_done,
312    _cb_wl_tz_policy_iconify_state_changed,
313    _cb_wl_tz_policy_supported_aux_hints,
314    _cb_wl_tz_policy_allowed_aux_hint,
315    _cb_wl_tz_policy_aux_message,
316    _cb_wl_conformant_region,
317 };
318
319 struct tizen_input_device_manager_listener _wl_tz_devmgr_listener =
320 {
321    _cb_device_add,
322    _cb_device_remove,
323    _cb_error,
324    _cb_block_expired
325 };
326
327 struct tizen_display_policy_listener _wl_tz_display_policy_listener =
328 {
329    _cb_wl_tz_display_policy_brightness_done,
330 };
331
332 struct tizen_gesture_listener _wl_tz_gesture_listener =
333 {
334    _cb_gesture_edge_swipe_notify,
335    _cb_gesture_edge_swipe,
336    _cb_gesture_edge_drag_notify,
337    _cb_gesture_edge_drag,
338    _cb_gesture_tap_notify,
339    _cb_gesture_tap,
340    _cb_gesture_palm_cover_notify,
341    _cb_gesture_palm_cover,
342    _cb_gesture_activate_notify
343 };
344
345 static Eina_Bool
346 _cb_info_add(Evas_Object *win,
347              Efl_Util_Cb cb,
348              void *data,
349              int idx)
350 {
351    Efl_Util_Callback_Info *info;
352
353    info = _cb_info_find_by_win(win, idx);
354    if (info)
355      {
356         _eflutil.cb_handler[idx].info_list
357            = eina_list_remove(_eflutil.cb_handler[idx].info_list,
358                               info);
359         free(info);
360      }
361
362    info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
363    if (!info) return EINA_FALSE;
364
365    info->win = win;
366    info->cb = cb;
367    info->data = data;
368
369    _eflutil.cb_handler[idx].info_list
370       = eina_list_append(_eflutil.cb_handler[idx].info_list,
371                          info);
372
373    return EINA_TRUE;
374 }
375
376 static Eina_Bool
377 _cb_info_del_by_win(Evas_Object *win,
378                     int idx)
379 {
380    Efl_Util_Callback_Info *info;
381
382    info = _cb_info_find_by_win(win, idx);
383    if (!info) return EINA_FALSE;
384
385    _eflutil.cb_handler[idx].info_list
386       = eina_list_remove(_eflutil.cb_handler[idx].info_list,
387                          info);
388    free(info);
389
390    return EINA_TRUE;
391 }
392
393 static Eina_List *
394 _cb_info_list_get(int idx)
395 {
396    return _eflutil.cb_handler[idx].info_list;
397 }
398
399 static Efl_Util_Callback_Info *
400 _cb_info_find_by_win(Evas_Object *win,
401                      int idx)
402 {
403    Eina_List *l, *ll;
404    Efl_Util_Callback_Info *info;
405
406    l = _cb_info_list_get(idx);
407    EINA_LIST_FOREACH(l, ll, info)
408      {
409         if (info->win == win) return info;
410      }
411
412    return NULL;
413 }
414
415 static Eina_Bool
416 _wl_init(void)
417 {
418    struct wl_display *display_wrapper = NULL;
419    struct wl_registry *reg = NULL;
420
421    if (_eflutil.wl.init) return EINA_TRUE;
422
423    ecore_wl2_init();
424
425    _eflutil.wl.wl2_display = ecore_wl2_display_connect(NULL);
426    EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.wl2_display, fail);
427    _eflutil.wl.dpy = ecore_wl2_display_get(_eflutil.wl.wl2_display);
428    EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail);
429
430    display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
431    EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail);
432
433    _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy);
434    EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail);
435
436    wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue);
437
438    reg = wl_display_get_registry(display_wrapper);
439    wl_proxy_wrapper_destroy(display_wrapper);
440    display_wrapper = NULL;
441    EINA_SAFETY_ON_NULL_GOTO(reg, fail);
442
443    wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
444
445    _eflutil.wl.init = EINA_TRUE;
446
447    return EINA_TRUE;
448 fail:
449    if (display_wrapper)
450      wl_proxy_wrapper_destroy(display_wrapper);
451
452    if (_eflutil.wl.queue)
453      {
454         wl_event_queue_destroy(_eflutil.wl.queue);
455         _eflutil.wl.queue = NULL;
456      }
457
458    ecore_wl2_shutdown();
459    return EINA_FALSE;
460 }
461
462 static void
463 _cb_wl_output_geometry(void *data, struct wl_output *wl_output, int x, int y,
464                        int physical_width, int physical_height, int subpixel,
465                        const char *make, const char *model, int transform)
466 {
467    Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
468    if (wl_output == output->output)
469      {
470         output->offset_x = x;
471         output->offset_y = y;
472      }
473 }
474
475 static void
476 _cb_wl_output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
477                    int width, int height, int refresh)
478 {
479    Efl_Util_Wl_Output_Info *output = wl_output_get_user_data(wl_output);
480    if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT))
481      {
482         output->width = width;
483         output->height = height;
484      }
485 }
486
487 static void
488 _cb_wl_output_done(void *data, struct wl_output *wl_output)
489 {
490 }
491
492 static void
493 _cb_wl_output_scale(void *data, struct wl_output *wl_output, int32_t factor)
494 {
495 }
496
497 static const struct wl_output_listener output_listener =
498 {
499     _cb_wl_output_geometry,
500     _cb_wl_output_mode,
501     _cb_wl_output_done,
502     _cb_wl_output_scale
503 };
504
505 static void
506 _cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter)
507 {
508    Eina_Bool *shot_done = (Eina_Bool*)data;
509    if (shot_done)
510      *shot_done = EINA_TRUE;
511 }
512
513 static const struct screenshooter_listener screenshooter_listener =
514 {
515     _cb_wl_screenshot_done
516 };
517
518 static void
519 _cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format)
520 {
521 }
522
523 static void
524 _cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti)
525 {
526    _eflutil.wl.shot.noti = noti;
527 }
528
529 static const struct tizen_screenshooter_listener tz_screenshooter_listener =
530 {
531     _cb_tz_screenshot_format,
532     _cb_tz_screenshot_noti
533 };
534
535 static void
536 _cb_wl_reg_global(void *data,
537                   struct wl_registry *reg,
538                   unsigned int id,
539                   const char *interface,
540                   unsigned int version)
541 {
542    if (!strcmp(interface, "tizen_policy"))
543      {
544         struct tizen_policy *proto;
545         proto = wl_registry_bind(reg,
546                                   id,
547                                   &tizen_policy_interface,
548                                   7);
549         if (!proto) return;
550
551         tizen_policy_add_listener(proto,
552                                   &_wl_tz_policy_listener,
553                                   NULL);
554
555         _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free);
556         _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free);
557         _eflutil.wl.policy.proto = proto;
558         _eflutil.wl.policy.id = id;
559      }
560    else if (strcmp(interface, "wl_output") == 0)
561      {
562         Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info));
563         EINA_SAFETY_ON_NULL_RETURN(output);
564
565         _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output);
566
567         output->output = wl_registry_bind(reg, id, &wl_output_interface, version);
568         wl_output_add_listener(output->output, &output_listener, output);
569      }
570    else if (strcmp(interface, "tizen_input_device_manager") == 0)
571      {
572         _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, id, &tizen_input_device_manager_interface, version);
573         tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL);
574      }
575    else if (!strcmp(interface, "tizen_display_policy"))
576      {
577         _eflutil.wl.display_policy.proto = wl_registry_bind(reg, id, &tizen_display_policy_interface, version);
578         if (!_eflutil.wl.display_policy.proto) return;
579
580         tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto,
581                                           &_wl_tz_display_policy_listener,
582                                           NULL);
583
584         _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free);
585         _eflutil.wl.display_policy.id = id;
586      }
587    else if (strcmp(interface, "tizen_gesture") == 0)
588      {
589         _eflutil.wl.gesture.proto = wl_registry_bind(reg, id, &tizen_gesture_interface, version);
590         tizen_gesture_add_listener(_eflutil.wl.gesture.proto, &_wl_tz_gesture_listener, NULL);
591      }
592 }
593 /* LCOV_EXCL_START */
594 static void
595 _cb_wl_reg_global_remove(void *data,
596                          struct wl_registry *reg,
597                          unsigned int id)
598 {
599    /* unset each global id number to 0 since global id is started
600     * from number 1 on server side display structure
601     */
602    if (id == _eflutil.wl.policy.id)
603      {
604         _eflutil.wl.policy.id = 0;
605         _eflutil.wl.policy.proto = NULL;
606         eina_hash_free(_eflutil.wl.policy.hash_noti_lv);
607         eina_hash_free(_eflutil.wl.policy.hash_scr_mode);
608      }
609    else if (id == _eflutil.wl.display_policy.id)
610      {
611         _eflutil.wl.display_policy.id = 0;
612         _eflutil.wl.display_policy.proto = NULL;
613         eina_hash_free(_eflutil.wl.display_policy.hash_brightness);
614      }
615 }
616 /* LCOV_EXCL_STOP */
617
618 static void
619 _cb_wl_reg_screenshooter_global(void *data,
620                   struct wl_registry *reg,
621                   unsigned int name,
622                   const char *interface,
623                   unsigned int version)
624 {
625    if (strcmp(interface, "screenshooter") == 0)
626      {
627         _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version);
628         screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL);
629      }
630    else if (strcmp(interface, "tizen_screenshooter") == 0)
631      {
632         _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version);
633         tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL);
634
635         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
636      }
637 }
638
639 /* LCOV_EXCL_START */
640 static void
641 _cb_wl_reg_screenshooter_global_remove(void *data,
642                          struct wl_registry *reg,
643                          unsigned int name)
644 {
645 }
646
647 static Efl_Util_Callback_Info *
648 _cb_info_find_by_wlsurf(void *wlsurf,
649                         int idx)
650 {
651    Eina_List *l, *ll;
652    Efl_Util_Callback_Info *info;
653    Ecore_Wl2_Window *wlwin2 = NULL;
654    void *wlsurf2 = NULL;
655
656    l = _cb_info_list_get(idx);
657    EINA_LIST_FOREACH(l, ll, info)
658      {
659         wlwin2 = (Ecore_Wl2_Window *)elm_win_wl_window_get(info->win);
660         wlsurf2 = ecore_wl2_window_surface_get(wlwin2);
661         if (wlsurf== wlsurf2) return info;
662      }
663
664    return NULL;
665 }
666
667 static void
668 _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy,
669                             struct wl_surface *surface, uint32_t is_conformant)
670 {
671 }
672
673 static void
674 _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy,
675                                  struct wl_surface *surface, uint32_t conformant_part,
676                                  uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
677 {
678 }
679 /* LCOV_EXCL_STOP */
680
681 static void
682 _cb_wl_tz_policy_notification_done(void *data,
683                                    struct tizen_policy *tizen_policy,
684                                    struct wl_surface *surface,
685                                    int32_t level,
686                                    uint32_t state)
687 {
688    Efl_Util_Wl_Surface_Lv_Info *lv_info;
689    Efl_Util_Callback_Info *cb_info;
690
691    lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
692    if (lv_info)
693      {
694         lv_info->level = level;
695         lv_info->wait_for_done = EINA_FALSE;
696         lv_info->state = state;
697      }
698
699    if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
700
701    cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
702    if (!cb_info) return;
703    if (!cb_info->cb) return;
704
705    cb_info->cb(cb_info->win,
706                EFL_UTIL_ERROR_PERMISSION_DENIED,
707                cb_info->data);
708 }
709
710 /* LCOV_EXCL_START */
711 static void
712 _cb_wl_tz_policy_transient_for_done(void *data, struct tizen_policy *tizen_policy, uint32_t child_id)
713 {
714 }
715 /* LCOV_EXCL_STOP */
716
717 static void
718 _cb_wl_tz_policy_scr_mode_done(void *data,
719                                struct tizen_policy *tizen_policy,
720                                struct wl_surface *surface,
721                                uint32_t mode,
722                                uint32_t state)
723 {
724
725    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
726    Efl_Util_Callback_Info *cb_info;
727
728    scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
729    if (scr_mode_info)
730      {
731         scr_mode_info->mode = mode;
732         scr_mode_info->wait_for_done = EINA_FALSE;
733         scr_mode_info->state = state;
734      }
735
736    if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return;
737
738    cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
739    if (!cb_info) return;
740    if (!cb_info->cb) return;
741
742    cb_info->cb(cb_info->win,
743                EFL_UTIL_ERROR_PERMISSION_DENIED,
744                cb_info->data);
745 }
746
747 /* LCOV_EXCL_START */
748 static void                    _cb_wl_tz_policy_iconify_state_changed(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, uint32_t iconified, uint32_t force)
749 {
750 }
751
752 static void                    _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints)
753 {
754 }
755
756 static void                    _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id)
757 {
758 }
759
760 static void                    _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options)
761 {
762 }
763 static void                    _cb_wl_conformant_region(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial)
764 {
765 }
766 /* LCOV_EXCL_STOP */
767
768 static void
769 _cb_wl_tz_display_policy_brightness_done(void *data,
770                                  struct tizen_display_policy *tizen_display_policy,
771                                  struct wl_surface *surface,
772                                  int32_t brightness,
773                                  uint32_t state)
774 {
775    Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
776
777    brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
778    if (brightness_info)
779      {
780         brightness_info->brightness = brightness;
781         brightness_info->wait_for_done = EINA_FALSE;
782         brightness_info->state = state;
783      }
784 }
785
786 static void
787 _cb_window_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
788 {
789    Efl_Util_Wl_Surface_Lv_Info *lv_info;
790
791    lv_info = data;
792    if (EINA_UNLIKELY(!lv_info))
793      return;
794
795    eina_hash_del(_eflutil.wl.policy.hash_noti_lv, &lv_info->surface, lv_info);
796 }
797
798 API int
799 efl_util_set_notification_window_level(Evas_Object *window,
800                                        efl_util_notification_level_e level)
801 {
802    Eina_Bool res;
803
804    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
805    EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_NONE) &&
806                                    (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
807                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
808
809    if (level == EFL_UTIL_NOTIFICATION_LEVEL_1)
810      {
811         dlog_print(DLOG_WARN, LOG_TAG,
812           "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead.");
813      }
814    else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2)
815      {
816         dlog_print(DLOG_WARN, LOG_TAG,
817           "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead.");
818      }
819    else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3)
820      {
821         dlog_print(DLOG_WARN, LOG_TAG,
822           "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead.");
823      }
824
825    Elm_Win_Type type;
826    Ecore_Wl2_Window *wlwin;
827    struct wl_surface *surface;
828    Efl_Util_Wl_Surface_Lv_Info *lv_info;
829    Ecore_Wl2_Window_Type wl_type;
830
831    res = _wl_init();
832    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
833
834    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
835    EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
836
837    type = elm_win_type_get(window);
838    if (type != ELM_WIN_NOTIFICATION)
839      {
840         wl_type = ecore_wl2_window_type_get(wlwin);
841         EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL2_WINDOW_TYPE_NOTIFICATION),
842                                         EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
843      }
844
845    while (!_eflutil.wl.policy.proto)
846      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
847
848    surface = ecore_wl2_window_surface_get(wlwin);
849    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
850                                   EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
851
852    lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
853    if (!lv_info)
854      {
855         lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
856         EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
857
858         lv_info->surface = surface;
859         lv_info->level = (int)level;
860         lv_info->wait_for_done = EINA_TRUE;
861         lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
862         eina_hash_add(_eflutil.wl.policy.hash_noti_lv,
863                       &surface,
864                       lv_info);
865
866         evas_object_event_callback_add(window, EVAS_CALLBACK_DEL,
867                                        _cb_window_del, lv_info);
868      }
869    else
870      {
871         lv_info->level = (int)level;
872         lv_info->wait_for_done = EINA_TRUE;
873         lv_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
874      }
875
876
877    tizen_policy_set_notification_level(_eflutil.wl.policy.proto,
878                                        surface, (int)level);
879
880    if (lv_info->wait_for_done)
881      {
882         int count = 0;
883         while (lv_info->wait_for_done && (count < 3))
884           {
885              ecore_wl2_display_flush(_eflutil.wl.wl2_display);
886              wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
887              count++;
888           }
889
890         if (lv_info->wait_for_done)
891           {
892              return EFL_UTIL_ERROR_INVALID_PARAMETER;
893           }
894         else
895           {
896              if (lv_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
897                {
898                   return EFL_UTIL_ERROR_PERMISSION_DENIED;
899                }
900           }
901      }
902
903    return EFL_UTIL_ERROR_NONE;
904 }
905
906 API int
907 efl_util_get_notification_window_level(Evas_Object *window,
908                                        efl_util_notification_level_e *level)
909 {
910    Eina_Bool res;
911
912    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
913    EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
914
915    Elm_Win_Type type;
916    Ecore_Wl2_Window *wlwin;
917    struct wl_surface *surface;
918    Efl_Util_Wl_Surface_Lv_Info *lv_info;
919    Ecore_Wl2_Window_Type wl_type;
920
921    res = _wl_init();
922    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
923
924    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
925    EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
926
927    type = elm_win_type_get(window);
928    if (type != ELM_WIN_NOTIFICATION)
929      {
930         wl_type = ecore_wl2_window_type_get(wlwin);
931         EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL2_WINDOW_TYPE_NOTIFICATION),
932                                         EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
933      }
934
935    while (!_eflutil.wl.policy.proto)
936      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
937
938    surface = ecore_wl2_window_surface_get(wlwin);
939    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
940                                   EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
941
942    lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface);
943    if (lv_info)
944      {
945         if (lv_info->wait_for_done)
946           {
947              int count = 0;
948              while ((lv_info->wait_for_done) && (count < 3))
949                {
950                   ecore_wl2_display_flush(_eflutil.wl.wl2_display);
951                   wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
952                   count++;
953                }
954
955              if (lv_info->wait_for_done)
956                {
957                   *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
958                   return EFL_UTIL_ERROR_INVALID_PARAMETER;
959                }
960           }
961
962         switch (lv_info->level)
963           {
964            case TIZEN_POLICY_LEVEL_1:       *level = EFL_UTIL_NOTIFICATION_LEVEL_1;       break;
965            case TIZEN_POLICY_LEVEL_2:       *level = EFL_UTIL_NOTIFICATION_LEVEL_2;       break;
966            case TIZEN_POLICY_LEVEL_3:       *level = EFL_UTIL_NOTIFICATION_LEVEL_3;       break;
967            case TIZEN_POLICY_LEVEL_NONE:    *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE;    break;
968            case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
969            case TIZEN_POLICY_LEVEL_MEDIUM:  *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM;  break;
970            case TIZEN_POLICY_LEVEL_HIGH:    *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH;    break;
971            case TIZEN_POLICY_LEVEL_TOP:     *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP;     break;
972            default:                         *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
973             return EFL_UTIL_ERROR_INVALID_PARAMETER;
974           }
975         return EFL_UTIL_ERROR_NONE;
976      }
977    else
978      *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
979
980    return EFL_UTIL_ERROR_NONE;
981 }
982
983 API int
984 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
985                                                 efl_util_notification_window_level_error_cb callback,
986                                                 void *user_data)
987 {
988    dlog_print(DLOG_WARN, LOG_TAG,
989      "DEPRECATION WARNING: efl_util_set_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
990
991    Eina_Bool ret = EINA_FALSE;
992
993    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
994    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
995
996    ret = _cb_info_add(window,
997                       (Efl_Util_Cb)callback,
998                       user_data,
999                       CBH_NOTI_LEV);
1000    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1001
1002    return EFL_UTIL_ERROR_NONE;
1003 }
1004
1005 API int
1006 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
1007 {
1008    dlog_print(DLOG_WARN, LOG_TAG,
1009      "DEPRECATION WARNING: efl_util_unset_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead.");
1010
1011    Eina_Bool ret = EINA_FALSE;
1012
1013    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1014
1015    ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
1016    if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1017
1018    return EFL_UTIL_ERROR_NONE;
1019 }
1020
1021 API int
1022 efl_util_set_window_opaque_state(Evas_Object *window,
1023                                  int opaque)
1024 {
1025    Eina_Bool res;
1026
1027    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1028    EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
1029                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
1030
1031    Ecore_Wl2_Window *wlwin;
1032    struct wl_surface *surface;
1033
1034    if (!_eflutil.wl.policy.proto)
1035      {
1036         int ret = 0;
1037
1038         res = _wl_init();
1039         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1040
1041         while (!_eflutil.wl.policy.proto && ret != -1)
1042           ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1043
1044         EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
1045      }
1046
1047    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
1048    if (!wlwin)
1049       return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
1050
1051    surface  = ecore_wl2_window_surface_get(wlwin);
1052    if (!surface)
1053       return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
1054
1055    tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque);
1056
1057    return EFL_UTIL_ERROR_NONE;
1058 }
1059
1060 API int
1061 efl_util_set_window_screen_mode(Evas_Object *window,
1062                                 efl_util_screen_mode_e mode)
1063 {
1064    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1065    EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
1066                                     (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
1067                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
1068
1069    Ecore_Wl2_Window *wlwin;
1070    struct wl_surface *surface;
1071    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1072    Eina_Bool res;
1073
1074    res = _wl_init();
1075    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1076
1077    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
1078    if (wlwin)
1079      {
1080         while (!_eflutil.wl.policy.proto)
1081           wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1082
1083         surface = ecore_wl2_window_surface_get(wlwin);
1084         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1085                                        EFL_UTIL_ERROR_INVALID_PARAMETER);
1086
1087         scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1088         if (!scr_mode_info)
1089           {
1090              scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
1091              EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1092
1093              scr_mode_info->surface = surface;
1094              scr_mode_info->mode = (unsigned int)mode;
1095              scr_mode_info->wait_for_done = EINA_TRUE;
1096              scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1097
1098              eina_hash_add(_eflutil.wl.policy.hash_scr_mode,
1099                            &surface,
1100                            scr_mode_info);
1101           }
1102         else
1103           {
1104              scr_mode_info->mode = (unsigned int)mode;
1105              scr_mode_info->wait_for_done = EINA_TRUE;
1106              scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE;
1107           }
1108
1109         tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto,
1110                                             surface, (unsigned int)mode);
1111         if (scr_mode_info->wait_for_done)
1112           {
1113              int count = 0;
1114              while (scr_mode_info->wait_for_done && (count < 3))
1115                {
1116                   ecore_wl2_display_flush(_eflutil.wl.wl2_display);
1117                   wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1118                   count++;
1119                }
1120
1121              if (scr_mode_info->wait_for_done)
1122                {
1123                   return EFL_UTIL_ERROR_INVALID_PARAMETER;
1124                }
1125              else
1126                {
1127                   if (scr_mode_info->state == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1128                     {
1129                        return EFL_UTIL_ERROR_PERMISSION_DENIED;
1130                     }
1131                }
1132           }
1133
1134         return EFL_UTIL_ERROR_NONE;
1135      }
1136    else
1137      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1138 }
1139
1140 API int
1141 efl_util_get_window_screen_mode(Evas_Object *window,
1142                                 efl_util_screen_mode_e *mode)
1143 {
1144    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1145    EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
1146
1147    Ecore_Wl2_Window *wlwin;
1148    struct wl_surface *surface;
1149    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
1150    Eina_Bool res;
1151
1152    res = _wl_init();
1153    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1154
1155    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
1156    if (wlwin)
1157      {
1158         while (!_eflutil.wl.policy.proto)
1159           wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1160
1161         surface = ecore_wl2_window_surface_get(wlwin);
1162         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1163                                        EFL_UTIL_ERROR_INVALID_PARAMETER);
1164
1165         scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface);
1166         if (scr_mode_info)
1167           {
1168              if (scr_mode_info->wait_for_done)
1169                {
1170                   while (scr_mode_info->wait_for_done)
1171                     {
1172                        ecore_wl2_display_flush(_eflutil.wl.wl2_display);
1173                        wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1174                     }
1175                }
1176
1177              switch (scr_mode_info->mode)
1178                {
1179                 case TIZEN_POLICY_MODE_DEFAULT:   *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;   break;
1180                 case TIZEN_POLICY_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
1181                 default:                          *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1182                   return EFL_UTIL_ERROR_INVALID_PARAMETER;
1183                }
1184              return EFL_UTIL_ERROR_NONE;
1185           }
1186         else
1187           {
1188              *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
1189              return EFL_UTIL_ERROR_INVALID_PARAMETER;
1190           }
1191      }
1192    else
1193      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1194 }
1195
1196 API int
1197 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
1198                                          efl_util_window_screen_mode_error_cb callback,
1199                                          void *user_data)
1200 {
1201    /* Wearable device cannot use this. */
1202    if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1203      return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1204
1205    dlog_print(DLOG_WARN, LOG_TAG,
1206      "DEPRECATION WARNING: efl_util_set_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
1207
1208    Eina_Bool ret = EINA_FALSE;
1209
1210    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1211    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
1212
1213    ret = _cb_info_add(window,
1214                       (Efl_Util_Cb)callback,
1215                       user_data,
1216                       CBH_SCR_MODE);
1217    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1218
1219    return EFL_UTIL_ERROR_NONE;
1220 }
1221
1222 API int
1223 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
1224 {
1225    /* Wearable device cannot use this. */
1226    if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
1227      return EFL_UTIL_ERROR_NO_SUCH_DEVICE;
1228
1229    dlog_print(DLOG_WARN, LOG_TAG,
1230      "DEPRECATION WARNING: efl_util_unset_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead.");
1231
1232    Eina_Bool ret = EINA_FALSE;
1233
1234    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1235
1236    ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
1237    if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1238
1239    return EFL_UTIL_ERROR_NONE;
1240 }
1241
1242 API int
1243 efl_util_set_window_brightness(Evas_Object *window, int brightness)
1244 {
1245    Ecore_Wl2_Window *wlwin;
1246    struct wl_surface *surface;
1247    Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1248    Eina_Bool res;
1249
1250    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1251    EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER);
1252
1253    res = _wl_init();
1254    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1255
1256    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
1257    if (wlwin)
1258      {
1259         while (!_eflutil.wl.display_policy.proto)
1260           wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1261
1262         surface = ecore_wl2_window_surface_get(wlwin);
1263         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1264                                        EFL_UTIL_ERROR_INVALID_PARAMETER);
1265
1266         brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1267         if (!brightness_info)
1268           {
1269              brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info));
1270              EINA_SAFETY_ON_NULL_RETURN_VAL(brightness_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
1271
1272              brightness_info->surface = surface;
1273              brightness_info->brightness = brightness;
1274              brightness_info->wait_for_done = EINA_TRUE;
1275              brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1276
1277              eina_hash_add(_eflutil.wl.display_policy.hash_brightness,
1278                            &surface,
1279                            brightness_info);
1280            }
1281          else
1282            {
1283               brightness_info->brightness = brightness;
1284               brightness_info->wait_for_done = EINA_TRUE;
1285               brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE;
1286            }
1287
1288          tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto,
1289                                                     surface, brightness);
1290          if (brightness_info->wait_for_done)
1291            {
1292               int count = 0;
1293               while (brightness_info->wait_for_done && (count < 3))
1294                 {
1295                    ecore_wl2_display_flush(_eflutil.wl.wl2_display);
1296                    wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1297                    count++;
1298                 }
1299
1300               if (brightness_info->wait_for_done)
1301                 {
1302                    return EFL_UTIL_ERROR_INVALID_PARAMETER;
1303                 }
1304               else
1305                 {
1306                    if (brightness_info->state == TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED)
1307                      {
1308                         return EFL_UTIL_ERROR_PERMISSION_DENIED;
1309                      }
1310                 }
1311            }
1312         return EFL_UTIL_ERROR_NONE;
1313      }
1314    else
1315      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1316 }
1317
1318 API int
1319 efl_util_get_window_brightness(Evas_Object *window, int *brightness)
1320 {
1321    Ecore_Wl2_Window *wlwin;
1322    struct wl_surface *surface;
1323    Efl_Util_Wl_Surface_Brightness_Info *brightness_info;
1324    Eina_Bool res;
1325
1326    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
1327    EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER);
1328
1329    res = _wl_init();
1330    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
1331
1332    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
1333    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
1334
1335    while (!_eflutil.wl.display_policy.proto)
1336      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1337
1338    surface = ecore_wl2_window_surface_get(wlwin);
1339    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
1340                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
1341
1342    brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface);
1343    if (brightness_info)
1344      {
1345         if (brightness_info->wait_for_done)
1346           {
1347              while (brightness_info->wait_for_done)
1348                {
1349                   ecore_wl2_display_flush(_eflutil.wl.wl2_display);
1350                   wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1351                }
1352           }
1353          *brightness = brightness_info->brightness;
1354      }
1355    else
1356      *brightness = -1;
1357
1358    return EFL_UTIL_ERROR_NONE;
1359 }
1360
1361
1362 struct _efl_util_inputgen_h
1363 {
1364    unsigned int init_type;
1365    char name[32];
1366 };
1367
1368 static void
1369 _cb_device_add(void *data EINA_UNUSED,
1370                struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1371                uint32_t serial EINA_UNUSED,
1372                const char *identifier EINA_UNUSED,
1373                struct tizen_input_device *device EINA_UNUSED,
1374                struct wl_seat *seat EINA_UNUSED)
1375 {
1376    ;
1377 }
1378
1379 /* LCOV_EXCL_START */
1380 static void
1381 _cb_device_remove(void *data EINA_UNUSED,
1382                struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1383                uint32_t serial  EINA_UNUSED,
1384                const char *identifier  EINA_UNUSED,
1385                struct tizen_input_device *device  EINA_UNUSED,
1386                struct wl_seat *seat  EINA_UNUSED)
1387 {
1388    ;
1389 }
1390 /* LCOV_EXCL_STOP */
1391
1392 static void
1393 _cb_error(void *data EINA_UNUSED,
1394           struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED,
1395           uint32_t errorcode)
1396 {
1397    _eflutil.wl.devmgr.request_notified = errorcode;
1398 }
1399
1400 /* LCOV_EXCL_START */
1401 static void
1402 _cb_block_expired(void *data EINA_UNUSED,
1403                   struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED)
1404 {
1405    ;
1406 }
1407 /* LCOV_EXCL_STOP */
1408
1409 static efl_util_error_e
1410 _efl_util_input_convert_input_generator_error(int ret)
1411 {
1412    switch (ret)
1413      {
1414         case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE:
1415            return EFL_UTIL_ERROR_NONE;
1416         case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION:
1417            return EFL_UTIL_ERROR_PERMISSION_DENIED;
1418         case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES:
1419            return EFL_UTIL_ERROR_OUT_OF_MEMORY;
1420         case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER:
1421            return EFL_UTIL_ERROR_INVALID_PARAMETER;
1422         default :
1423            return EFL_UTIL_ERROR_NONE;
1424      }
1425 }
1426
1427 API efl_util_inputgen_h
1428 efl_util_input_initialize_generator(unsigned int dev_type)
1429 {
1430    int ret = EFL_UTIL_ERROR_NONE;
1431    efl_util_inputgen_h inputgen_h = NULL;
1432    unsigned int clas = 0x0;
1433
1434    if (!dev_type ||
1435         dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1436                     | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1437                     | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1438      {
1439         set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1440         goto out;
1441      }
1442
1443    inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1444    if (!inputgen_h)
1445      {
1446         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1447         goto out;
1448      }
1449
1450    inputgen_h->init_type |= dev_type;
1451
1452    ret = _wl_init();
1453    if (ret == (int)EINA_FALSE)
1454      {
1455         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1456         goto out;
1457      }
1458
1459    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1460      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1461    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1462      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1463    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1464      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1465
1466    while (!_eflutil.wl.devmgr.devicemgr)
1467      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1468
1469    tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas);
1470
1471    while (_eflutil.wl.devmgr.request_notified == -1)
1472      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1473
1474    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1475    _eflutil.wl.devmgr.request_notified = -1;
1476
1477    set_last_result(ret);
1478    if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1479      goto out;
1480
1481    return inputgen_h;
1482
1483 out:
1484    if (inputgen_h)
1485      {
1486         free(inputgen_h);
1487         inputgen_h = NULL;
1488      }
1489    return NULL;
1490 }
1491
1492 API efl_util_inputgen_h
1493 efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name)
1494 {
1495    int ret = EFL_UTIL_ERROR_NONE;
1496    efl_util_inputgen_h inputgen_h = NULL;
1497    unsigned int clas = 0x0;
1498
1499    if (!dev_type ||
1500         dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN
1501                     | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD
1502                     | EFL_UTIL_INPUT_DEVTYPE_POINTER))
1503      {
1504         set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1505         goto out;
1506      }
1507
1508    inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h));
1509    if (!inputgen_h)
1510      {
1511         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1512         goto out;
1513      }
1514
1515    inputgen_h->init_type |= dev_type;
1516    strncpy(inputgen_h->name, name, 31);
1517
1518    ret = _wl_init();
1519    if (ret == (int)EINA_FALSE)
1520      {
1521         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1522         goto out;
1523      }
1524
1525    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1526      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1527    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1528      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1529    if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1530      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1531
1532    while (!_eflutil.wl.devmgr.devicemgr)
1533      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1534
1535    tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name);
1536
1537    while (_eflutil.wl.devmgr.request_notified == -1)
1538      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1539
1540    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1541    _eflutil.wl.devmgr.request_notified = -1;
1542
1543    set_last_result(ret);
1544    if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1545      goto out;
1546
1547    return inputgen_h;
1548
1549 out:
1550    if (inputgen_h)
1551      {
1552         free(inputgen_h);
1553         inputgen_h = NULL;
1554      }
1555    return NULL;
1556 }
1557
1558
1559 API int
1560 efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h)
1561 {
1562    int ret = EFL_UTIL_ERROR_NONE;
1563    unsigned int clas = 0x0;
1564    EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1565
1566    if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN)
1567      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN;
1568    if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD)
1569      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD;
1570    if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER)
1571      clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE;
1572
1573    free(inputgen_h);
1574    inputgen_h = NULL;
1575
1576    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1577
1578    tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas);
1579
1580    while (_eflutil.wl.devmgr.request_notified == -1)
1581      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1582
1583    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1584    _eflutil.wl.devmgr.request_notified = -1;
1585
1586    return ret;
1587 }
1588
1589 API int
1590 efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed)
1591 {
1592    int ret = EFL_UTIL_ERROR_NONE;
1593
1594    EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1595    EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER);
1596    EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER);
1597    EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1598
1599    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1600
1601    tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed);
1602
1603    while (_eflutil.wl.devmgr.request_notified == -1)
1604      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1605
1606    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1607    _eflutil.wl.devmgr.request_notified = -1;
1608
1609    return ret;
1610 }
1611
1612 API int
1613 efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx,
1614                               efl_util_input_touch_type_e touch_type, int x, int y)
1615 {
1616    int ret;
1617    enum tizen_input_device_manager_pointer_event_type type;
1618
1619    EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1620    EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1621    EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1622    EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1623
1624    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1625
1626    switch(touch_type)
1627      {
1628         case EFL_UTIL_INPUT_TOUCH_BEGIN:
1629            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1630            break;
1631         case EFL_UTIL_INPUT_TOUCH_UPDATE:
1632            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1633            break;
1634         case EFL_UTIL_INPUT_TOUCH_END:
1635            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1636            break;
1637         default:
1638            return EFL_UTIL_ERROR_INVALID_PARAMETER;
1639      }
1640
1641    tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx);
1642
1643    while (_eflutil.wl.devmgr.request_notified == -1)
1644      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1645
1646    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1647    _eflutil.wl.devmgr.request_notified = -1;
1648
1649    return ret;
1650 }
1651
1652 API int
1653 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)
1654 {
1655    int ret;
1656    enum tizen_input_device_manager_pointer_event_type type;
1657
1658    EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
1659    EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER);
1660    EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER);
1661    EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE);
1662
1663    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER);
1664
1665    switch(pointer_type)
1666      {
1667         case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN:
1668            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN;
1669            break;
1670         case EFL_UTIL_INPUT_POINTER_MOVE:
1671            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE;
1672            break;
1673         case EFL_UTIL_INPUT_POINTER_BUTTON_UP:
1674            type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END;
1675            break;
1676         default:
1677            return EFL_UTIL_ERROR_INVALID_PARAMETER;
1678      }
1679
1680    tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons);
1681
1682    while (_eflutil.wl.devmgr.request_notified == -1)
1683      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1684
1685    ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified);
1686    _eflutil.wl.devmgr.request_notified = -1;
1687
1688    return ret;
1689 }
1690
1691
1692 struct _efl_util_screenshot_h
1693 {
1694    int width;
1695    int height;
1696
1697    Eina_Bool shot_done;
1698
1699    /* tbm bufmgr */
1700    tbm_bufmgr bufmgr;
1701
1702    Eina_Bool auto_rotation;
1703 };
1704
1705 /* scrrenshot handle */
1706 static efl_util_screenshot_h g_screenshot;
1707 static Eina_Bool shot_mutex_init;
1708 static pthread_mutex_t shot_lock;
1709
1710 static Eina_Bool
1711 _screenshot_mutex_init(void)
1712 {
1713    if (shot_mutex_init)
1714      return EINA_TRUE;
1715
1716    if (pthread_mutex_init(&shot_lock, NULL))
1717      {
1718         fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/
1719         return EINA_FALSE; /*LCOV_EXCL_LINE*/
1720      }
1721
1722    shot_mutex_init = EINA_TRUE;
1723
1724    return EINA_TRUE;
1725 }
1726
1727 static Eina_Bool
1728 _screenshot_mutex_destory(void)
1729 {
1730    if (!shot_mutex_init)
1731      return EINA_TRUE;
1732
1733    if (pthread_mutex_destroy(&shot_lock))
1734      {
1735         fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/
1736         return EINA_FALSE; /*LCOV_EXCL_LINE*/
1737      }
1738
1739    shot_mutex_init = EINA_FALSE;
1740
1741    return EINA_TRUE;
1742 }
1743
1744 void
1745 _screenshot_mutex_lock(void)
1746 {
1747    if (!_screenshot_mutex_init())
1748      return;
1749
1750    pthread_mutex_lock(&shot_lock);
1751 }
1752
1753 void
1754 _screenshot_mutex_unlock(void)
1755 {
1756    pthread_mutex_unlock(&shot_lock);
1757 }
1758
1759 API efl_util_screenshot_h
1760 efl_util_screenshot_initialize(int width, int height)
1761 {
1762    efl_util_screenshot_h screenshot = NULL;
1763    struct wl_display *display_wrapper = NULL;
1764    struct wl_registry *reg = NULL;
1765    int ret = 0;
1766
1767    EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param);
1768    EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param);
1769
1770    _screenshot_mutex_lock();
1771
1772    if (!_eflutil.wl.shot.screenshooter)
1773      {
1774         ret = _wl_init();
1775         if (ret == (int)EINA_FALSE)
1776           {
1777              set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1778              _screenshot_mutex_unlock();
1779              return NULL;
1780           }
1781         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
1782
1783         display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy);
1784         EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory);
1785
1786         _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy);
1787         EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory);
1788
1789         wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue);
1790
1791         reg = wl_display_get_registry(display_wrapper);
1792         wl_proxy_wrapper_destroy(display_wrapper);
1793         display_wrapper = NULL;
1794         EINA_SAFETY_ON_NULL_GOTO(reg, fail_init);
1795
1796         wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL);
1797
1798         ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1799         EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init);
1800         EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init);
1801         EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init);
1802
1803         _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy);
1804         EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init);
1805      }
1806
1807    if (_eflutil.wl.shot.noti == 0)
1808      {
1809         fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1810         goto fail_init;
1811      }
1812
1813    if (g_screenshot)
1814      {
1815         if (g_screenshot->width != width || g_screenshot->height != height)
1816           {
1817              g_screenshot->width = width;
1818              g_screenshot->height = height;
1819           }
1820
1821         _screenshot_mutex_unlock();
1822
1823         return g_screenshot;
1824      }
1825
1826    screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1827    EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1828
1829    screenshot->width = width;
1830    screenshot->height = height;
1831    screenshot->auto_rotation = EINA_TRUE;
1832
1833    screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1834    EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1835
1836    g_screenshot = screenshot;
1837    set_last_result(EFL_UTIL_ERROR_NONE);
1838
1839    screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1840
1841    _screenshot_mutex_unlock();
1842
1843    return g_screenshot;
1844
1845 fail_param:
1846    set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1847    return NULL;
1848 fail_memory:
1849 /* LCOV_EXCL_START */
1850    if (display_wrapper)
1851      wl_proxy_wrapper_destroy(display_wrapper);
1852    set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1853    return NULL;
1854 fail_init:
1855    if (screenshot)
1856      efl_util_screenshot_deinitialize(screenshot);
1857    _screenshot_mutex_unlock();
1858    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1859    return NULL;
1860 /* LCOV_EXCL_STOP */
1861 }
1862
1863 API int
1864 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1865 {
1866    _screenshot_mutex_lock();
1867
1868    if (!screenshot)
1869      {
1870         _screenshot_mutex_unlock();
1871         _screenshot_mutex_destory();
1872         return EFL_UTIL_ERROR_INVALID_PARAMETER;
1873      }
1874
1875    free(screenshot);
1876    g_screenshot = NULL;
1877
1878    if (_eflutil.wl.shot.queue)
1879      {
1880         wl_event_queue_destroy(_eflutil.wl.shot.queue);
1881         _eflutil.wl.shot.queue = NULL;
1882      }
1883
1884    if (_eflutil.wl.shot.screenshooter)
1885      {
1886         screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1887         _eflutil.wl.shot.screenshooter = NULL;
1888      }
1889    if (_eflutil.wl.shot.tz_screenshooter)
1890      {
1891         tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1892         _eflutil.wl.shot.tz_screenshooter = NULL;
1893      }
1894
1895    _screenshot_mutex_unlock();
1896    _screenshot_mutex_destory();
1897
1898    return EFL_UTIL_ERROR_NONE;
1899 }
1900
1901
1902 API tbm_surface_h
1903 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1904 {
1905    tbm_surface_h t_surface = NULL;
1906    struct wl_buffer *buffer = NULL;
1907    Efl_Util_Wl_Output_Info *output;
1908    int ret = 0;
1909
1910    _screenshot_mutex_lock();
1911
1912    if (!screenshot || (screenshot != g_screenshot))
1913      {
1914         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1915         _screenshot_mutex_unlock();
1916         return NULL;
1917      }
1918
1919    output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1920    if (!output)
1921      {
1922         fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1923         goto fail;
1924      }
1925
1926    t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1927    if (!t_surface)
1928      {
1929         fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1930         goto fail;
1931      }
1932
1933    buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1934    if (!buffer)
1935      {
1936         fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1937         goto fail;
1938      }
1939
1940    screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1941
1942    screenshot->shot_done = EINA_FALSE;
1943    while (!screenshot->shot_done && ret != -1)
1944      ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1945
1946    if (ret == -1)
1947      {
1948         fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1949         goto fail;
1950      }
1951
1952    wl_buffer_destroy(buffer);
1953
1954    /* reset shot_done for next screenshot */
1955    screenshot->shot_done = EINA_FALSE;
1956
1957    set_last_result(EFL_UTIL_ERROR_NONE);
1958
1959    _screenshot_mutex_unlock();
1960
1961    return t_surface;
1962
1963 fail:
1964    if (t_surface)
1965      tbm_surface_destroy(t_surface);
1966    if (buffer)
1967      wl_buffer_destroy(buffer);
1968
1969    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1970
1971    _screenshot_mutex_unlock();
1972
1973    return NULL;
1974 }
1975
1976 /* LCOV_EXCL_START */
1977 API int
1978 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1979 {
1980    if (!screenshot || (screenshot != g_screenshot))
1981      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1982
1983    if (!(set == 0 || set == 1))
1984      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1985
1986    if (set)
1987      g_screenshot->auto_rotation = EINA_TRUE;
1988    else
1989      g_screenshot->auto_rotation = EINA_FALSE;
1990
1991    tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1992
1993    return EFL_UTIL_ERROR_NONE;
1994 }
1995
1996 API int
1997 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
1998 {
1999    if (!screenshot || (screenshot != g_screenshot) || !set)
2000      return EFL_UTIL_ERROR_INVALID_PARAMETER;
2001
2002    *set = g_screenshot->auto_rotation;
2003
2004    return EFL_UTIL_ERROR_NONE;
2005 }
2006 /* LCOV_EXCL_STOP */
2007
2008 struct _efl_util_gesture_h
2009 {
2010    Eina_Bool init;
2011 };
2012
2013 API int EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
2014 API int EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
2015 API int EFL_UTIL_EVENT_GESTURE_TAP = 0;
2016 API int EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
2017
2018 /* LCOV_EXCL_START */
2019 static void
2020 _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)
2021 {
2022    _eflutil.wl.gesture.request_notified = error;
2023 }
2024
2025 static void
2026 _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)
2027 {
2028    efl_util_event_gesture_edge_swipe_s *ev = NULL;
2029
2030    ev = (efl_util_event_gesture_edge_swipe_s *)calloc(1, sizeof(*ev));
2031    if (!ev) return;
2032
2033    ev->mode = mode;
2034
2035    ev->fingers = fingers;
2036    ev->sx = sx;
2037    ev->sy = sy;
2038    ev->edge = edge;
2039
2040    ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE, ev, NULL, NULL);
2041 }
2042
2043 static void
2044 _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)
2045 {
2046    _eflutil.wl.gesture.request_notified = error;
2047 }
2048
2049 static void
2050 _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)
2051 {
2052    efl_util_event_gesture_edge_drag_s *ev = NULL;
2053
2054    ev = (efl_util_event_gesture_edge_drag_s *)calloc(1, sizeof(*ev));
2055    if (!ev) return;
2056
2057    ev->mode = mode;
2058
2059    ev->fingers = fingers;
2060    ev->cx = cx;
2061    ev->cy = cy;
2062    ev->edge = edge;
2063
2064    ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_DRAG, ev, NULL, NULL);
2065 }
2066
2067 static void
2068 _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)
2069 {
2070    _eflutil.wl.gesture.request_notified = error;
2071 }
2072
2073 static void
2074 _cb_gesture_tap(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, uint32_t repeats)
2075 {
2076    efl_util_event_gesture_tap_s *ev = NULL;
2077
2078    ev = (efl_util_event_gesture_tap_s *)calloc(1, sizeof(*ev));
2079    if (!ev) return;
2080
2081    ev->mode = mode;
2082
2083    ev->fingers = fingers;
2084    ev->repeats = repeats;
2085
2086    ecore_event_add(EFL_UTIL_EVENT_GESTURE_TAP, ev, NULL, NULL);
2087 }
2088 /* LCOV_EXCL_STOP */
2089
2090 static void
2091 _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)
2092 {
2093    _eflutil.wl.gesture.request_notified = error;
2094 }
2095
2096 /* LCOV_EXCL_START */
2097 static void
2098 _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)
2099 {
2100    efl_util_event_gesture_palm_cover_s *ev = NULL;
2101
2102    ev = (efl_util_event_gesture_palm_cover_s *)calloc(1, sizeof(*ev));
2103    if (!ev) return;
2104
2105    ev->mode = mode;
2106
2107    ev->duration = duration;
2108    ev->cx = cx;
2109    ev->cy = cy;
2110    ev->size = size;
2111    ev->pressure = wl_fixed_to_int(pressure);
2112
2113    ecore_event_add(EFL_UTIL_EVENT_GESTURE_PALM_COVER, ev, NULL, NULL);
2114 }
2115 /* LCOV_EXCL_STOP */
2116
2117 static void
2118 _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)
2119 {
2120    _eflutil.wl.gesture.request_notified = error;
2121 }
2122
2123 static efl_util_error_e
2124 _efl_util_gesture_convert_error(int ret)
2125 {
2126    switch (ret)
2127      {
2128         case TIZEN_GESTURE_ERROR_NONE:
2129            return EFL_UTIL_ERROR_NONE;
2130         case TIZEN_GESTURE_ERROR_INVALID_DATA:
2131            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2132         case TIZEN_GESTURE_ERROR_NO_PERMISSION:
2133            return EFL_UTIL_ERROR_PERMISSION_DENIED;
2134         case TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES:
2135            return EFL_UTIL_ERROR_OUT_OF_MEMORY;
2136         case TIZEN_GESTURE_ERROR_GRABBED_ALREADY:
2137            return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE;
2138         case TIZEN_GESTURE_ERROR_NOT_SUPPORTED:
2139            return EFL_UTIL_ERROR_NOT_SUPPORTED;
2140         default :
2141            return EFL_UTIL_ERROR_NONE;
2142      }
2143 }
2144
2145 /* LCOV_EXCL_START */
2146 static int
2147 _efl_util_gesture_grab_edge_swipe(efl_util_gesture_data data)
2148 {
2149    int ret = EFL_UTIL_ERROR_NONE;
2150    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2151    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL;
2152    unsigned int fingers = 0;
2153    unsigned int edge = 0;
2154    unsigned int edge_size = 0;
2155    unsigned int start_point = 0;
2156    unsigned int end_point = 0;
2157
2158    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2159
2160    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2161    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2162    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2163                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2164
2165    edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data;
2166
2167    fingers = edge_swipe_data->fingers;
2168    edge = edge_swipe_data->edge;
2169    edge_size = edge_swipe_data->edge_size;
2170    start_point = edge_swipe_data->start_point;
2171    end_point = edge_swipe_data->end_point;
2172
2173    tizen_gesture_grab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2174
2175    while (_eflutil.wl.gesture.request_notified == -1)
2176      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2177
2178    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2179    _eflutil.wl.gesture.request_notified = -1;
2180
2181    return ret;
2182 }
2183
2184 static int
2185 _efl_util_gesture_ungrab_edge_swipe(efl_util_gesture_data data)
2186 {
2187    int ret = EFL_UTIL_ERROR_NONE;
2188    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2189    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL;
2190    unsigned int fingers = 0;
2191    unsigned int edge = 0;
2192    unsigned int edge_size = 0;
2193    unsigned int start_point = 0;
2194    unsigned int end_point = 0;
2195
2196    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2197
2198    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2199    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2200    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2201                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2202
2203    edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data;
2204
2205    fingers = edge_swipe_data->fingers;
2206    edge = edge_swipe_data->edge;
2207    edge_size = edge_swipe_data->edge_size;
2208    start_point = edge_swipe_data->start_point;
2209    end_point = edge_swipe_data->end_point;
2210
2211    tizen_gesture_ungrab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2212
2213    while (_eflutil.wl.gesture.request_notified == -1)
2214      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2215
2216    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2217    _eflutil.wl.gesture.request_notified = -1;
2218
2219    return ret;
2220 }
2221
2222 static int
2223 _efl_util_gesture_grab_edge_drag(efl_util_gesture_data data)
2224 {
2225    int ret = EFL_UTIL_ERROR_NONE;
2226    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2227    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL;
2228    unsigned int fingers = 0;
2229    unsigned int edge = 0;
2230    unsigned int edge_size = 0;
2231    unsigned int start_point = 0;
2232    unsigned int end_point = 0;
2233
2234    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2235
2236    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2237    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2238    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2239                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2240
2241    edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data;
2242
2243    fingers = edge_drag_data->fingers;
2244    edge = edge_drag_data->edge;
2245    edge_size = edge_drag_data->edge_size;
2246    start_point = edge_drag_data->start_point;
2247    end_point = edge_drag_data->end_point;
2248
2249    tizen_gesture_grab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2250
2251    while (_eflutil.wl.gesture.request_notified == -1)
2252      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2253
2254    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2255    _eflutil.wl.gesture.request_notified = -1;
2256
2257    return ret;
2258 }
2259
2260 static int
2261 _efl_util_gesture_ungrab_edge_drag(efl_util_gesture_data data)
2262 {
2263    int ret = EFL_UTIL_ERROR_NONE;
2264    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2265    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL;
2266    unsigned int fingers = 0;
2267    unsigned int edge = 0;
2268    unsigned int edge_size = 0;
2269    unsigned int start_point = 0;
2270    unsigned int end_point = 0;
2271
2272    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2273
2274    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2275    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2276    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2277                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2278
2279    edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data;
2280
2281    fingers = edge_drag_data->fingers;
2282    edge = edge_drag_data->edge;
2283    edge_size = edge_drag_data->edge_size;
2284    start_point = edge_drag_data->start_point;
2285    end_point = edge_drag_data->end_point;
2286
2287    tizen_gesture_ungrab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2288
2289    while (_eflutil.wl.gesture.request_notified == -1)
2290      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2291
2292    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2293    _eflutil.wl.gesture.request_notified = -1;
2294
2295    return ret;
2296 }
2297
2298
2299 static int
2300 _efl_util_gesture_grab_tap(efl_util_gesture_data data)
2301 {
2302    int ret = EFL_UTIL_ERROR_NONE;
2303    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2304    Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL;
2305    unsigned int fingers = 0;
2306    unsigned int repeats = 0;
2307
2308    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2309
2310    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2311    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2312    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP,
2313                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2314
2315    tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data;
2316
2317    fingers = tap_data->fingers;
2318    repeats = tap_data->repeats;
2319
2320    tizen_gesture_grab_tap(_eflutil.wl.gesture.proto, fingers, repeats);
2321
2322    while (_eflutil.wl.gesture.request_notified == -1)
2323      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2324
2325    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2326    _eflutil.wl.gesture.request_notified = -1;
2327
2328    return ret;
2329 }
2330
2331 static int
2332 _efl_util_gesture_ungrab_tap(efl_util_gesture_data data)
2333 {
2334    int ret = EFL_UTIL_ERROR_NONE;
2335    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2336    Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL;
2337    unsigned int fingers = 0;
2338    unsigned int repeats = 0;
2339
2340    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2341
2342    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2343    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2344    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP,
2345                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2346
2347    tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data;
2348
2349    fingers = tap_data->fingers;
2350    repeats = tap_data->repeats;
2351
2352    tizen_gesture_ungrab_tap(_eflutil.wl.gesture.proto, fingers, repeats);
2353
2354    while (_eflutil.wl.gesture.request_notified == -1)
2355      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2356
2357    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2358    _eflutil.wl.gesture.request_notified = -1;
2359
2360    return ret;
2361 }
2362
2363 static int
2364 _efl_util_gesture_grab_palm_cover(efl_util_gesture_data data)
2365 {
2366    int ret = EFL_UTIL_ERROR_NONE;
2367    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2368
2369    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2370
2371    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2372    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2373    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER,
2374                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2375
2376    tizen_gesture_grab_palm_cover(_eflutil.wl.gesture.proto);
2377
2378    while (_eflutil.wl.gesture.request_notified == -1)
2379      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2380
2381    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2382    _eflutil.wl.gesture.request_notified = -1;
2383
2384    return ret;
2385 }
2386
2387 static int
2388 _efl_util_gesture_ungrab_palm_cover(efl_util_gesture_data data)
2389 {
2390    int ret = EFL_UTIL_ERROR_NONE;
2391    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2392
2393    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2394
2395    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2396    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2397    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER,
2398                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2399
2400    tizen_gesture_ungrab_palm_cover(_eflutil.wl.gesture.proto);
2401
2402    while (_eflutil.wl.gesture.request_notified == -1)
2403      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2404
2405    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2406    _eflutil.wl.gesture.request_notified = -1;
2407
2408    return ret;
2409 }
2410
2411 static Eina_Bool
2412 _efl_util_fd_cb(void *data, Ecore_Fd_Handler *hdl)
2413 {
2414    if (_eflutil.wl.dpy && _eflutil.wl.queue)
2415      {
2416         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2417         return ECORE_CALLBACK_RENEW;
2418      }
2419    else
2420      {
2421         return ECORE_CALLBACK_CANCEL;
2422      }
2423 }
2424 /* LCOV_EXCL_STOP */
2425
2426 API efl_util_gesture_h
2427 efl_util_gesture_initialize(void)
2428 {
2429    efl_util_gesture_h gesture_h = NULL;
2430    int dpy_fd = -1;
2431
2432    gesture_h = (efl_util_gesture_h)calloc(1, sizeof(struct _efl_util_gesture_h));
2433    if (!gesture_h)
2434      {
2435         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2436         goto out; /* LCOV_EXCL_LINE */
2437      }
2438
2439    if (_wl_init() == (int)EINA_FALSE)
2440      {
2441         set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
2442         goto out; /* LCOV_EXCL_LINE */
2443      }
2444
2445    while (!_eflutil.wl.gesture.proto)
2446      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); /* LCOV_EXCL_LINE */
2447
2448    if (_eflutil.wl.gesture.event_init <= 0)
2449      {
2450         if (ecore_event_init() <= 0)
2451           {
2452              set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
2453              goto out; /* LCOV_EXCL_LINE */
2454           }
2455         EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = ecore_event_type_new();
2456         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = ecore_event_type_new();
2457         EFL_UTIL_EVENT_GESTURE_TAP = ecore_event_type_new();
2458         EFL_UTIL_EVENT_GESTURE_PALM_COVER = ecore_event_type_new();
2459
2460         dpy_fd = wl_display_get_fd(_eflutil.wl.dpy);
2461         _eflutil.wl.dpy_fd = fcntl(dpy_fd, F_DUPFD_CLOEXEC, 0);
2462         if (_eflutil.wl.dpy_fd >= 0)
2463           _eflutil.wl.fd_hdl = ecore_main_fd_handler_add(_eflutil.wl.dpy_fd,
2464                                  ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR,
2465                                  _efl_util_fd_cb, NULL,
2466                                  NULL, NULL);
2467      }
2468    _eflutil.wl.gesture.event_init++;
2469    gesture_h->init = EINA_TRUE;
2470
2471    set_last_result(EFL_UTIL_ERROR_NONE);
2472    return gesture_h;
2473
2474 out:
2475 /* LCOV_EXCL_START */
2476    if (gesture_h)
2477      {
2478         free(gesture_h);
2479         gesture_h = NULL;
2480      }
2481    return gesture_h;
2482 /* LCOV_EXCL_STOP */
2483 }
2484
2485 API int
2486 efl_util_gesture_deinitialize(efl_util_gesture_h gesture_h)
2487 {
2488    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2489    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2490
2491    free(gesture_h);
2492    gesture_h = NULL;
2493
2494    _eflutil.wl.gesture.event_init--;
2495
2496    if (_eflutil.wl.gesture.event_init <= 0)
2497      {
2498         _eflutil.wl.gesture.event_init = 0;
2499         ecore_event_shutdown();
2500         EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
2501         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
2502         EFL_UTIL_EVENT_GESTURE_TAP = 0;
2503         EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
2504         if (_eflutil.wl.dpy_fd >= 0)
2505           {
2506              ecore_main_fd_handler_del(_eflutil.wl.fd_hdl);
2507              _eflutil.wl.fd_hdl = NULL;
2508              close(_eflutil.wl.dpy_fd);
2509              _eflutil.wl.dpy_fd = -1;
2510           }
2511      }
2512
2513    return EFL_UTIL_ERROR_NONE;
2514 }
2515
2516 API efl_util_gesture_data
2517 efl_util_gesture_edge_swipe_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
2518 {
2519    Efl_Util_Gesture_Edge_Swipe_Grab_Data *data;
2520
2521    if (!gesture_h || gesture_h->init == EINA_FALSE)
2522      {
2523         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2524         return NULL;
2525      }
2526
2527    if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
2528      {
2529         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2530         return NULL;
2531      }
2532
2533    data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Swipe_Grab_Data));
2534    if (!data)
2535      {
2536         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2537         return NULL; /* LCOV_EXCL_LINE */
2538      }
2539
2540    data->base.type = TIZEN_GESTURE_TYPE_EDGE_SWIPE;
2541    data->fingers = fingers;
2542    data->edge = edge;
2543    data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
2544
2545    set_last_result(EFL_UTIL_ERROR_NONE);
2546
2547    return (void *)data;
2548 }
2549
2550 API int
2551 efl_util_gesture_edge_swipe_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2552 {
2553    if (!gesture_h || gesture_h->init == EINA_FALSE)
2554      {
2555         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2556      }
2557
2558    if (!data)
2559      {
2560         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2561      }
2562
2563    free(data);
2564    data = NULL;
2565
2566    return EFL_UTIL_ERROR_NONE;
2567 }
2568
2569 API int
2570 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)
2571 {
2572    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = data;
2573
2574    EINA_SAFETY_ON_NULL_RETURN_VAL(edge_swipe_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2575    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_swipe_data->base.type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2576                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2577    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
2578                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2579    EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
2580
2581    edge_swipe_data->edge_size = edge_size;
2582    edge_swipe_data->start_point = start_point;
2583    edge_swipe_data->end_point = end_point;
2584
2585    return EFL_UTIL_ERROR_NONE;
2586 }
2587
2588 API efl_util_gesture_data
2589 efl_util_gesture_edge_drag_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
2590 {
2591    Efl_Util_Gesture_Edge_Drag_Grab_Data *data;
2592
2593    if (!gesture_h || gesture_h->init == EINA_FALSE)
2594      {
2595         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2596         return NULL;
2597      }
2598
2599    if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
2600      {
2601         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2602         return NULL;
2603      }
2604
2605    data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Drag_Grab_Data));
2606    if (!data)
2607      {
2608         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2609         return NULL; /* LCOV_EXCL_LINE */
2610      }
2611
2612    data->base.type = TIZEN_GESTURE_TYPE_EDGE_DRAG;
2613    data->fingers = fingers;
2614    data->edge = edge;
2615    data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
2616
2617    set_last_result(EFL_UTIL_ERROR_NONE);
2618
2619    return (void *)data;
2620 }
2621
2622 API int
2623 efl_util_gesture_edge_drag_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2624 {
2625    if (!gesture_h || gesture_h->init == EINA_FALSE)
2626      {
2627         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2628      }
2629
2630    if (!data)
2631      {
2632         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2633      }
2634
2635    free(data);
2636    data = NULL;
2637
2638    return EFL_UTIL_ERROR_NONE;
2639 }
2640
2641 API int
2642 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)
2643 {
2644    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = data;
2645
2646    EINA_SAFETY_ON_NULL_RETURN_VAL(edge_drag_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2647    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_drag_data->base.type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2648                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2649    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
2650                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2651    EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
2652
2653    edge_drag_data->edge_size = edge_size;
2654    edge_drag_data->start_point = start_point;
2655    edge_drag_data->end_point = end_point;
2656
2657    return EFL_UTIL_ERROR_NONE;
2658 }
2659
2660 API efl_util_gesture_data
2661 efl_util_gesture_tap_new(efl_util_gesture_h gesture_h, unsigned int fingers, unsigned int repeats)
2662 {
2663    Efl_Util_Gesture_Tap_Grab_Data *data;
2664
2665    if (!gesture_h || gesture_h->init == EINA_FALSE)
2666      {
2667         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2668         return NULL;
2669      }
2670
2671    if (fingers <= 1 || repeats <= 1)
2672      {
2673         set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED);
2674         return NULL;
2675      }
2676
2677    data = (Efl_Util_Gesture_Tap_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Tap_Grab_Data));
2678    if (!data)
2679      {
2680         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2681         return NULL; /* LCOV_EXCL_LINE */
2682      }
2683
2684    data->base.type = TIZEN_GESTURE_TYPE_TAP;
2685    data->fingers = fingers;
2686    data->repeats = repeats;
2687
2688    set_last_result(EFL_UTIL_ERROR_NONE);
2689
2690    return (void *)data;
2691 }
2692
2693 API int
2694 efl_util_gesture_tap_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2695 {
2696    if (!gesture_h || gesture_h->init == EINA_FALSE)
2697      {
2698         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2699      }
2700
2701    if (!data)
2702      {
2703         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2704      }
2705
2706    free(data);
2707    data = NULL;
2708
2709    return EFL_UTIL_ERROR_NONE;
2710 }
2711
2712 API efl_util_gesture_data
2713 efl_util_gesture_palm_cover_new(efl_util_gesture_h gesture_h)
2714 {
2715    Efl_Util_Gesture_Palm_Cover_Grab_Data *data;
2716
2717    if (!gesture_h || gesture_h->init == EINA_FALSE)
2718      {
2719         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2720         return NULL;
2721      }
2722
2723    data = (Efl_Util_Gesture_Palm_Cover_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Palm_Cover_Grab_Data));
2724    if (!data)
2725      {
2726         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2727         return NULL; /* LCOV_EXCL_LINE */
2728      }
2729
2730    data->base.type = TIZEN_GESTURE_TYPE_PALM_COVER;
2731
2732    set_last_result(EFL_UTIL_ERROR_NONE);
2733
2734    return (void *)data;
2735 }
2736
2737 API int
2738 efl_util_gesture_palm_cover_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2739 {
2740    if (!gesture_h || gesture_h->init == EINA_FALSE)
2741      {
2742         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2743      }
2744
2745    if (!data)
2746      {
2747         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2748      }
2749
2750    free(data);
2751    data = NULL;
2752
2753    return EFL_UTIL_ERROR_NONE;
2754 }
2755
2756 /* LCOV_EXCL_START */
2757 API int
2758 efl_util_gesture_grab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2759 {
2760    int ret = EFL_UTIL_ERROR_NONE;
2761    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2762
2763    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2764
2765    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2766    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2767    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2768
2769    switch (base_data->type)
2770      {
2771         case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
2772            ret = _efl_util_gesture_grab_edge_swipe(data);
2773            break;
2774         case TIZEN_GESTURE_TYPE_EDGE_DRAG:
2775            ret = _efl_util_gesture_grab_edge_drag(data);
2776            break;
2777         case TIZEN_GESTURE_TYPE_TAP:
2778            ret = _efl_util_gesture_grab_tap(data);
2779            break;
2780         case TIZEN_GESTURE_TYPE_PALM_COVER:
2781            ret = _efl_util_gesture_grab_palm_cover(data);
2782            break;
2783         default:
2784            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2785      }
2786
2787    return ret;
2788 }
2789
2790 API int
2791 efl_util_gesture_ungrab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2792 {
2793    int ret = EFL_UTIL_ERROR_NONE;
2794    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2795
2796    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2797
2798    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2799    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2800    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2801
2802    switch (base_data->type)
2803      {
2804         case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
2805            ret = _efl_util_gesture_ungrab_edge_swipe(data);
2806            break;
2807         case TIZEN_GESTURE_TYPE_EDGE_DRAG:
2808            ret = _efl_util_gesture_ungrab_edge_drag(data);
2809            break;
2810         case TIZEN_GESTURE_TYPE_TAP:
2811            ret = _efl_util_gesture_ungrab_tap(data);
2812            break;
2813         case TIZEN_GESTURE_TYPE_PALM_COVER:
2814            ret = _efl_util_gesture_ungrab_palm_cover(data);
2815            break;
2816         default:
2817            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2818      }
2819
2820    return ret;
2821 }
2822 /* LCOV_EXCL_STOP */
2823
2824 API int
2825 efl_util_gesture_select(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
2826 {
2827    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2828    Ecore_Wl2_Window *wlwin;
2829    struct wl_surface *surface;
2830    int ret;
2831
2832    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2833
2834    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2835    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2836    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2837    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2838
2839    if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
2840      return EFL_UTIL_ERROR_NOT_SUPPORTED;
2841
2842    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2843    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2844
2845    surface = ecore_wl2_window_surface_get(wlwin);
2846    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2847                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2848
2849    tizen_gesture_select_palm_cover(_eflutil.wl.gesture.proto, surface);
2850
2851    while (_eflutil.wl.gesture.request_notified == -1)
2852      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2853
2854    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2855    _eflutil.wl.gesture.request_notified = -1;
2856
2857    return ret;
2858 }
2859
2860 API int
2861 efl_util_gesture_deselect(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
2862 {
2863    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2864    Ecore_Wl2_Window *wlwin;
2865    struct wl_surface *surface;
2866    int ret;
2867
2868    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2869
2870    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2871    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2872    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2873    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2874
2875    if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
2876      return EFL_UTIL_ERROR_NOT_SUPPORTED;
2877
2878    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2879    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2880
2881    surface = ecore_wl2_window_surface_get(wlwin);
2882    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2883                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2884
2885    tizen_gesture_deselect_palm_cover(_eflutil.wl.gesture.proto, surface);
2886
2887    while (_eflutil.wl.gesture.request_notified == -1)
2888      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2889
2890    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2891    _eflutil.wl.gesture.request_notified = -1;
2892
2893    return ret;
2894 }
2895
2896 /* LCOV_EXCL_START */
2897 API int
2898 efl_util_gesture_activate_set(efl_util_gesture_h gesture_h, unsigned int type, Eina_Bool active)
2899 {
2900    int ret;
2901
2902    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2903    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2904    EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
2905
2906    tizen_gesture_activate_set(_eflutil.wl.gesture.proto, NULL, type, active);
2907
2908    while (_eflutil.wl.gesture.request_notified == -1)
2909      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2910
2911    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2912    _eflutil.wl.gesture.request_notified = -1;
2913
2914    return ret;
2915 }
2916 /* LCOV_EXCL_STOP */
2917
2918 API int
2919 efl_util_gesture_activate_set_on_window(efl_util_gesture_h gesture_h, Evas_Object *window, unsigned int type, Eina_Bool active)
2920 {
2921    Ecore_Wl2_Window *wlwin;
2922    struct wl_surface *surface;
2923    int ret;
2924
2925    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2926    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2927    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2928    EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
2929
2930    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2931    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2932
2933    surface = ecore_wl2_window_surface_get(wlwin);
2934    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2935                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2936
2937    tizen_gesture_activate_set(_eflutil.wl.gesture.proto, surface, type, active);
2938
2939    while (_eflutil.wl.gesture.request_notified == -1)
2940      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2941
2942    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2943    _eflutil.wl.gesture.request_notified = -1;
2944
2945    return ret;
2946 }