652aa1adea5f25157f7e5d9088d94c0c021caffe
[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         wl_registry_destroy(reg);
1807         reg = NULL;
1808      }
1809
1810    if (_eflutil.wl.shot.noti == 0)
1811      {
1812         fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */
1813         goto fail_init;
1814      }
1815
1816    if (g_screenshot)
1817      {
1818         if (g_screenshot->width != width || g_screenshot->height != height)
1819           {
1820              g_screenshot->width = width;
1821              g_screenshot->height = height;
1822           }
1823
1824         _screenshot_mutex_unlock();
1825
1826         return g_screenshot;
1827      }
1828
1829    screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h));
1830    EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory);
1831
1832    screenshot->width = width;
1833    screenshot->height = height;
1834    screenshot->auto_rotation = EINA_TRUE;
1835
1836    screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client);
1837    EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init);
1838
1839    g_screenshot = screenshot;
1840    set_last_result(EFL_UTIL_ERROR_NONE);
1841
1842    screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done);
1843
1844    _screenshot_mutex_unlock();
1845
1846    return g_screenshot;
1847
1848 fail_param:
1849    set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1850    return NULL;
1851 fail_memory:
1852 /* LCOV_EXCL_START */
1853    if (display_wrapper)
1854      wl_proxy_wrapper_destroy(display_wrapper);
1855    set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY);
1856    return NULL;
1857 fail_init:
1858    if (reg)
1859      wl_registry_destroy(reg);
1860    if (screenshot)
1861      efl_util_screenshot_deinitialize(screenshot);
1862    _screenshot_mutex_unlock();
1863    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL);
1864    return NULL;
1865 /* LCOV_EXCL_STOP */
1866 }
1867
1868 API int
1869 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1870 {
1871    _screenshot_mutex_lock();
1872
1873    if (!screenshot)
1874      {
1875         _screenshot_mutex_unlock();
1876         _screenshot_mutex_destory();
1877         return EFL_UTIL_ERROR_INVALID_PARAMETER;
1878      }
1879
1880    free(screenshot);
1881    g_screenshot = NULL;
1882
1883    if (_eflutil.wl.shot.screenshooter)
1884      {
1885         screenshooter_destroy(_eflutil.wl.shot.screenshooter);
1886         _eflutil.wl.shot.screenshooter = NULL;
1887      }
1888    if (_eflutil.wl.shot.tz_screenshooter)
1889      {
1890         tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter);
1891         _eflutil.wl.shot.tz_screenshooter = NULL;
1892      }
1893
1894    if (_eflutil.wl.shot.queue)
1895      {
1896         wl_event_queue_destroy(_eflutil.wl.shot.queue);
1897         _eflutil.wl.shot.queue = NULL;
1898      }
1899
1900    _screenshot_mutex_unlock();
1901    _screenshot_mutex_destory();
1902
1903    return EFL_UTIL_ERROR_NONE;
1904 }
1905
1906
1907 API tbm_surface_h
1908 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1909 {
1910    tbm_surface_h t_surface = NULL;
1911    struct wl_buffer *buffer = NULL;
1912    Efl_Util_Wl_Output_Info *output;
1913    int ret = 0;
1914
1915    _screenshot_mutex_lock();
1916
1917    if (!screenshot || (screenshot != g_screenshot))
1918      {
1919         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
1920         _screenshot_mutex_unlock();
1921         return NULL;
1922      }
1923
1924    output = eina_list_nth(_eflutil.wl.shot.output_list, 0);
1925    if (!output)
1926      {
1927         fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */
1928         goto fail;
1929      }
1930
1931    t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888);
1932    if (!t_surface)
1933      {
1934         fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */
1935         goto fail;
1936      }
1937
1938    buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface);
1939    if (!buffer)
1940      {
1941         fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */
1942         goto fail;
1943      }
1944
1945    screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer);
1946
1947    screenshot->shot_done = EINA_FALSE;
1948    while (!screenshot->shot_done && ret != -1)
1949      ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue);
1950
1951    if (ret == -1)
1952      {
1953         fprintf(stderr, "[screenshot] fail: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */
1954         goto fail;
1955      }
1956
1957    wl_buffer_destroy(buffer);
1958
1959    /* reset shot_done for next screenshot */
1960    screenshot->shot_done = EINA_FALSE;
1961
1962    set_last_result(EFL_UTIL_ERROR_NONE);
1963
1964    _screenshot_mutex_unlock();
1965
1966    return t_surface;
1967
1968 fail:
1969    if (t_surface)
1970      tbm_surface_destroy(t_surface);
1971    if (buffer)
1972      wl_buffer_destroy(buffer);
1973
1974    set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL);
1975
1976    _screenshot_mutex_unlock();
1977
1978    return NULL;
1979 }
1980
1981 /* LCOV_EXCL_START */
1982 API int
1983 efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set)
1984 {
1985    if (!screenshot || (screenshot != g_screenshot))
1986      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1987
1988    if (!(set == 0 || set == 1))
1989      return EFL_UTIL_ERROR_INVALID_PARAMETER;
1990
1991    if (set)
1992      g_screenshot->auto_rotation = EINA_TRUE;
1993    else
1994      g_screenshot->auto_rotation = EINA_FALSE;
1995
1996    tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation);
1997
1998    return EFL_UTIL_ERROR_NONE;
1999 }
2000
2001 API int
2002 efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set)
2003 {
2004    if (!screenshot || (screenshot != g_screenshot) || !set)
2005      return EFL_UTIL_ERROR_INVALID_PARAMETER;
2006
2007    *set = g_screenshot->auto_rotation;
2008
2009    return EFL_UTIL_ERROR_NONE;
2010 }
2011 /* LCOV_EXCL_STOP */
2012
2013 struct _efl_util_gesture_h
2014 {
2015    Eina_Bool init;
2016 };
2017
2018 API int EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
2019 API int EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
2020 API int EFL_UTIL_EVENT_GESTURE_TAP = 0;
2021 API int EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
2022
2023 /* LCOV_EXCL_START */
2024 static void
2025 _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)
2026 {
2027    _eflutil.wl.gesture.request_notified = error;
2028 }
2029
2030 static void
2031 _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)
2032 {
2033    efl_util_event_gesture_edge_swipe_s *ev = NULL;
2034
2035    ev = (efl_util_event_gesture_edge_swipe_s *)calloc(1, sizeof(*ev));
2036    if (!ev) return;
2037
2038    ev->mode = mode;
2039
2040    ev->fingers = fingers;
2041    ev->sx = sx;
2042    ev->sy = sy;
2043    ev->edge = edge;
2044
2045    ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE, ev, NULL, NULL);
2046 }
2047
2048 static void
2049 _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)
2050 {
2051    _eflutil.wl.gesture.request_notified = error;
2052 }
2053
2054 static void
2055 _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)
2056 {
2057    efl_util_event_gesture_edge_drag_s *ev = NULL;
2058
2059    ev = (efl_util_event_gesture_edge_drag_s *)calloc(1, sizeof(*ev));
2060    if (!ev) return;
2061
2062    ev->mode = mode;
2063
2064    ev->fingers = fingers;
2065    ev->cx = cx;
2066    ev->cy = cy;
2067    ev->edge = edge;
2068
2069    ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_DRAG, ev, NULL, NULL);
2070 }
2071
2072 static void
2073 _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)
2074 {
2075    _eflutil.wl.gesture.request_notified = error;
2076 }
2077
2078 static void
2079 _cb_gesture_tap(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, uint32_t repeats)
2080 {
2081    efl_util_event_gesture_tap_s *ev = NULL;
2082
2083    ev = (efl_util_event_gesture_tap_s *)calloc(1, sizeof(*ev));
2084    if (!ev) return;
2085
2086    ev->mode = mode;
2087
2088    ev->fingers = fingers;
2089    ev->repeats = repeats;
2090
2091    ecore_event_add(EFL_UTIL_EVENT_GESTURE_TAP, ev, NULL, NULL);
2092 }
2093 /* LCOV_EXCL_STOP */
2094
2095 static void
2096 _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)
2097 {
2098    _eflutil.wl.gesture.request_notified = error;
2099 }
2100
2101 /* LCOV_EXCL_START */
2102 static void
2103 _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)
2104 {
2105    efl_util_event_gesture_palm_cover_s *ev = NULL;
2106
2107    ev = (efl_util_event_gesture_palm_cover_s *)calloc(1, sizeof(*ev));
2108    if (!ev) return;
2109
2110    ev->mode = mode;
2111
2112    ev->duration = duration;
2113    ev->cx = cx;
2114    ev->cy = cy;
2115    ev->size = size;
2116    ev->pressure = wl_fixed_to_int(pressure);
2117
2118    ecore_event_add(EFL_UTIL_EVENT_GESTURE_PALM_COVER, ev, NULL, NULL);
2119 }
2120 /* LCOV_EXCL_STOP */
2121
2122 static void
2123 _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)
2124 {
2125    _eflutil.wl.gesture.request_notified = error;
2126 }
2127
2128 static efl_util_error_e
2129 _efl_util_gesture_convert_error(int ret)
2130 {
2131    switch (ret)
2132      {
2133         case TIZEN_GESTURE_ERROR_NONE:
2134            return EFL_UTIL_ERROR_NONE;
2135         case TIZEN_GESTURE_ERROR_INVALID_DATA:
2136            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2137         case TIZEN_GESTURE_ERROR_NO_PERMISSION:
2138            return EFL_UTIL_ERROR_PERMISSION_DENIED;
2139         case TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES:
2140            return EFL_UTIL_ERROR_OUT_OF_MEMORY;
2141         case TIZEN_GESTURE_ERROR_GRABBED_ALREADY:
2142            return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE;
2143         case TIZEN_GESTURE_ERROR_NOT_SUPPORTED:
2144            return EFL_UTIL_ERROR_NOT_SUPPORTED;
2145         default :
2146            return EFL_UTIL_ERROR_NONE;
2147      }
2148 }
2149
2150 /* LCOV_EXCL_START */
2151 static int
2152 _efl_util_gesture_grab_edge_swipe(efl_util_gesture_data data)
2153 {
2154    int ret = EFL_UTIL_ERROR_NONE;
2155    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2156    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL;
2157    unsigned int fingers = 0;
2158    unsigned int edge = 0;
2159    unsigned int edge_size = 0;
2160    unsigned int start_point = 0;
2161    unsigned int end_point = 0;
2162
2163    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2164
2165    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2166    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2167    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2168                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2169
2170    edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data;
2171
2172    fingers = edge_swipe_data->fingers;
2173    edge = edge_swipe_data->edge;
2174    edge_size = edge_swipe_data->edge_size;
2175    start_point = edge_swipe_data->start_point;
2176    end_point = edge_swipe_data->end_point;
2177
2178    tizen_gesture_grab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2179
2180    while (_eflutil.wl.gesture.request_notified == -1)
2181      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2182
2183    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2184    _eflutil.wl.gesture.request_notified = -1;
2185
2186    return ret;
2187 }
2188
2189 static int
2190 _efl_util_gesture_ungrab_edge_swipe(efl_util_gesture_data data)
2191 {
2192    int ret = EFL_UTIL_ERROR_NONE;
2193    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2194    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL;
2195    unsigned int fingers = 0;
2196    unsigned int edge = 0;
2197    unsigned int edge_size = 0;
2198    unsigned int start_point = 0;
2199    unsigned int end_point = 0;
2200
2201    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2202
2203    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2204    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2205    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2206                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2207
2208    edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data;
2209
2210    fingers = edge_swipe_data->fingers;
2211    edge = edge_swipe_data->edge;
2212    edge_size = edge_swipe_data->edge_size;
2213    start_point = edge_swipe_data->start_point;
2214    end_point = edge_swipe_data->end_point;
2215
2216    tizen_gesture_ungrab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2217
2218    while (_eflutil.wl.gesture.request_notified == -1)
2219      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2220
2221    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2222    _eflutil.wl.gesture.request_notified = -1;
2223
2224    return ret;
2225 }
2226
2227 static int
2228 _efl_util_gesture_grab_edge_drag(efl_util_gesture_data data)
2229 {
2230    int ret = EFL_UTIL_ERROR_NONE;
2231    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2232    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL;
2233    unsigned int fingers = 0;
2234    unsigned int edge = 0;
2235    unsigned int edge_size = 0;
2236    unsigned int start_point = 0;
2237    unsigned int end_point = 0;
2238
2239    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2240
2241    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2242    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2243    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2244                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2245
2246    edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data;
2247
2248    fingers = edge_drag_data->fingers;
2249    edge = edge_drag_data->edge;
2250    edge_size = edge_drag_data->edge_size;
2251    start_point = edge_drag_data->start_point;
2252    end_point = edge_drag_data->end_point;
2253
2254    tizen_gesture_grab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2255
2256    while (_eflutil.wl.gesture.request_notified == -1)
2257      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2258
2259    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2260    _eflutil.wl.gesture.request_notified = -1;
2261
2262    return ret;
2263 }
2264
2265 static int
2266 _efl_util_gesture_ungrab_edge_drag(efl_util_gesture_data data)
2267 {
2268    int ret = EFL_UTIL_ERROR_NONE;
2269    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2270    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL;
2271    unsigned int fingers = 0;
2272    unsigned int edge = 0;
2273    unsigned int edge_size = 0;
2274    unsigned int start_point = 0;
2275    unsigned int end_point = 0;
2276
2277    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2278
2279    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2280    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2281    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2282                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2283
2284    edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data;
2285
2286    fingers = edge_drag_data->fingers;
2287    edge = edge_drag_data->edge;
2288    edge_size = edge_drag_data->edge_size;
2289    start_point = edge_drag_data->start_point;
2290    end_point = edge_drag_data->end_point;
2291
2292    tizen_gesture_ungrab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point);
2293
2294    while (_eflutil.wl.gesture.request_notified == -1)
2295      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2296
2297    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2298    _eflutil.wl.gesture.request_notified = -1;
2299
2300    return ret;
2301 }
2302
2303
2304 static int
2305 _efl_util_gesture_grab_tap(efl_util_gesture_data data)
2306 {
2307    int ret = EFL_UTIL_ERROR_NONE;
2308    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2309    Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL;
2310    unsigned int fingers = 0;
2311    unsigned int repeats = 0;
2312
2313    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2314
2315    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2316    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2317    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP,
2318                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2319
2320    tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data;
2321
2322    fingers = tap_data->fingers;
2323    repeats = tap_data->repeats;
2324
2325    tizen_gesture_grab_tap(_eflutil.wl.gesture.proto, fingers, repeats);
2326
2327    while (_eflutil.wl.gesture.request_notified == -1)
2328      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2329
2330    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2331    _eflutil.wl.gesture.request_notified = -1;
2332
2333    return ret;
2334 }
2335
2336 static int
2337 _efl_util_gesture_ungrab_tap(efl_util_gesture_data data)
2338 {
2339    int ret = EFL_UTIL_ERROR_NONE;
2340    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2341    Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL;
2342    unsigned int fingers = 0;
2343    unsigned int repeats = 0;
2344
2345    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2346
2347    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2348    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2349    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP,
2350                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2351
2352    tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data;
2353
2354    fingers = tap_data->fingers;
2355    repeats = tap_data->repeats;
2356
2357    tizen_gesture_ungrab_tap(_eflutil.wl.gesture.proto, fingers, repeats);
2358
2359    while (_eflutil.wl.gesture.request_notified == -1)
2360      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2361
2362    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2363    _eflutil.wl.gesture.request_notified = -1;
2364
2365    return ret;
2366 }
2367
2368 static int
2369 _efl_util_gesture_grab_palm_cover(efl_util_gesture_data data)
2370 {
2371    int ret = EFL_UTIL_ERROR_NONE;
2372    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2373
2374    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2375
2376    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2377    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2378    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER,
2379                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2380
2381    tizen_gesture_grab_palm_cover(_eflutil.wl.gesture.proto);
2382
2383    while (_eflutil.wl.gesture.request_notified == -1)
2384      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2385
2386    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2387    _eflutil.wl.gesture.request_notified = -1;
2388
2389    return ret;
2390 }
2391
2392 static int
2393 _efl_util_gesture_ungrab_palm_cover(efl_util_gesture_data data)
2394 {
2395    int ret = EFL_UTIL_ERROR_NONE;
2396    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2397
2398    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2399
2400    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER);
2401    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2402    EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER,
2403                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2404
2405    tizen_gesture_ungrab_palm_cover(_eflutil.wl.gesture.proto);
2406
2407    while (_eflutil.wl.gesture.request_notified == -1)
2408      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2409
2410    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2411    _eflutil.wl.gesture.request_notified = -1;
2412
2413    return ret;
2414 }
2415
2416 static Eina_Bool
2417 _efl_util_fd_cb(void *data, Ecore_Fd_Handler *hdl)
2418 {
2419    if (_eflutil.wl.dpy && _eflutil.wl.queue)
2420      {
2421         wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2422         return ECORE_CALLBACK_RENEW;
2423      }
2424    else
2425      {
2426         return ECORE_CALLBACK_CANCEL;
2427      }
2428 }
2429 /* LCOV_EXCL_STOP */
2430
2431 API efl_util_gesture_h
2432 efl_util_gesture_initialize(void)
2433 {
2434    efl_util_gesture_h gesture_h = NULL;
2435    int dpy_fd = -1;
2436
2437    gesture_h = (efl_util_gesture_h)calloc(1, sizeof(struct _efl_util_gesture_h));
2438    if (!gesture_h)
2439      {
2440         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2441         goto out; /* LCOV_EXCL_LINE */
2442      }
2443
2444    if (_wl_init() == (int)EINA_FALSE)
2445      {
2446         set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
2447         goto out; /* LCOV_EXCL_LINE */
2448      }
2449
2450    while (!_eflutil.wl.gesture.proto)
2451      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); /* LCOV_EXCL_LINE */
2452
2453    if (_eflutil.wl.gesture.event_init <= 0)
2454      {
2455         if (ecore_event_init() <= 0)
2456           {
2457              set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */
2458              goto out; /* LCOV_EXCL_LINE */
2459           }
2460         EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = ecore_event_type_new();
2461         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = ecore_event_type_new();
2462         EFL_UTIL_EVENT_GESTURE_TAP = ecore_event_type_new();
2463         EFL_UTIL_EVENT_GESTURE_PALM_COVER = ecore_event_type_new();
2464
2465         dpy_fd = wl_display_get_fd(_eflutil.wl.dpy);
2466         _eflutil.wl.dpy_fd = fcntl(dpy_fd, F_DUPFD_CLOEXEC, 0);
2467         if (_eflutil.wl.dpy_fd >= 0)
2468           _eflutil.wl.fd_hdl = ecore_main_fd_handler_add(_eflutil.wl.dpy_fd,
2469                                  ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR,
2470                                  _efl_util_fd_cb, NULL,
2471                                  NULL, NULL);
2472      }
2473    _eflutil.wl.gesture.event_init++;
2474    gesture_h->init = EINA_TRUE;
2475
2476    set_last_result(EFL_UTIL_ERROR_NONE);
2477    return gesture_h;
2478
2479 out:
2480 /* LCOV_EXCL_START */
2481    if (gesture_h)
2482      {
2483         free(gesture_h);
2484         gesture_h = NULL;
2485      }
2486    return gesture_h;
2487 /* LCOV_EXCL_STOP */
2488 }
2489
2490 API int
2491 efl_util_gesture_deinitialize(efl_util_gesture_h gesture_h)
2492 {
2493    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2494    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2495
2496    free(gesture_h);
2497    gesture_h = NULL;
2498
2499    _eflutil.wl.gesture.event_init--;
2500
2501    if (_eflutil.wl.gesture.event_init <= 0)
2502      {
2503         _eflutil.wl.gesture.event_init = 0;
2504         ecore_event_shutdown();
2505         EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0;
2506         EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0;
2507         EFL_UTIL_EVENT_GESTURE_TAP = 0;
2508         EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0;
2509         if (_eflutil.wl.dpy_fd >= 0)
2510           {
2511              ecore_main_fd_handler_del(_eflutil.wl.fd_hdl);
2512              _eflutil.wl.fd_hdl = NULL;
2513              close(_eflutil.wl.dpy_fd);
2514              _eflutil.wl.dpy_fd = -1;
2515           }
2516      }
2517
2518    return EFL_UTIL_ERROR_NONE;
2519 }
2520
2521 API efl_util_gesture_data
2522 efl_util_gesture_edge_swipe_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
2523 {
2524    Efl_Util_Gesture_Edge_Swipe_Grab_Data *data;
2525
2526    if (!gesture_h || gesture_h->init == EINA_FALSE)
2527      {
2528         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2529         return NULL;
2530      }
2531
2532    if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
2533      {
2534         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2535         return NULL;
2536      }
2537
2538    data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Swipe_Grab_Data));
2539    if (!data)
2540      {
2541         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2542         return NULL; /* LCOV_EXCL_LINE */
2543      }
2544
2545    data->base.type = TIZEN_GESTURE_TYPE_EDGE_SWIPE;
2546    data->fingers = fingers;
2547    data->edge = edge;
2548    data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
2549
2550    set_last_result(EFL_UTIL_ERROR_NONE);
2551
2552    return (void *)data;
2553 }
2554
2555 API int
2556 efl_util_gesture_edge_swipe_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2557 {
2558    if (!gesture_h || gesture_h->init == EINA_FALSE)
2559      {
2560         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2561      }
2562
2563    if (!data)
2564      {
2565         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2566      }
2567
2568    free(data);
2569    data = NULL;
2570
2571    return EFL_UTIL_ERROR_NONE;
2572 }
2573
2574 API int
2575 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)
2576 {
2577    Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = data;
2578
2579    EINA_SAFETY_ON_NULL_RETURN_VAL(edge_swipe_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2580    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_swipe_data->base.type == TIZEN_GESTURE_TYPE_EDGE_SWIPE,
2581                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2582    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
2583                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2584    EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
2585
2586    edge_swipe_data->edge_size = edge_size;
2587    edge_swipe_data->start_point = start_point;
2588    edge_swipe_data->end_point = end_point;
2589
2590    return EFL_UTIL_ERROR_NONE;
2591 }
2592
2593 API efl_util_gesture_data
2594 efl_util_gesture_edge_drag_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge)
2595 {
2596    Efl_Util_Gesture_Edge_Drag_Grab_Data *data;
2597
2598    if (!gesture_h || gesture_h->init == EINA_FALSE)
2599      {
2600         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2601         return NULL;
2602      }
2603
2604    if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT)
2605      {
2606         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2607         return NULL;
2608      }
2609
2610    data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Drag_Grab_Data));
2611    if (!data)
2612      {
2613         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2614         return NULL; /* LCOV_EXCL_LINE */
2615      }
2616
2617    data->base.type = TIZEN_GESTURE_TYPE_EDGE_DRAG;
2618    data->fingers = fingers;
2619    data->edge = edge;
2620    data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL;
2621
2622    set_last_result(EFL_UTIL_ERROR_NONE);
2623
2624    return (void *)data;
2625 }
2626
2627 API int
2628 efl_util_gesture_edge_drag_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2629 {
2630    if (!gesture_h || gesture_h->init == EINA_FALSE)
2631      {
2632         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2633      }
2634
2635    if (!data)
2636      {
2637         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2638      }
2639
2640    free(data);
2641    data = NULL;
2642
2643    return EFL_UTIL_ERROR_NONE;
2644 }
2645
2646 API int
2647 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)
2648 {
2649    Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = data;
2650
2651    EINA_SAFETY_ON_NULL_RETURN_VAL(edge_drag_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2652    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_drag_data->base.type == TIZEN_GESTURE_TYPE_EDGE_DRAG,
2653                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2654    EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL,
2655                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
2656    EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER);
2657
2658    edge_drag_data->edge_size = edge_size;
2659    edge_drag_data->start_point = start_point;
2660    edge_drag_data->end_point = end_point;
2661
2662    return EFL_UTIL_ERROR_NONE;
2663 }
2664
2665 API efl_util_gesture_data
2666 efl_util_gesture_tap_new(efl_util_gesture_h gesture_h, unsigned int fingers, unsigned int repeats)
2667 {
2668    Efl_Util_Gesture_Tap_Grab_Data *data;
2669
2670    if (!gesture_h || gesture_h->init == EINA_FALSE)
2671      {
2672         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2673         return NULL;
2674      }
2675
2676    if (fingers <= 1 || repeats <= 1)
2677      {
2678         set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED);
2679         return NULL;
2680      }
2681
2682    data = (Efl_Util_Gesture_Tap_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Tap_Grab_Data));
2683    if (!data)
2684      {
2685         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2686         return NULL; /* LCOV_EXCL_LINE */
2687      }
2688
2689    data->base.type = TIZEN_GESTURE_TYPE_TAP;
2690    data->fingers = fingers;
2691    data->repeats = repeats;
2692
2693    set_last_result(EFL_UTIL_ERROR_NONE);
2694
2695    return (void *)data;
2696 }
2697
2698 API int
2699 efl_util_gesture_tap_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2700 {
2701    if (!gesture_h || gesture_h->init == EINA_FALSE)
2702      {
2703         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2704      }
2705
2706    if (!data)
2707      {
2708         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2709      }
2710
2711    free(data);
2712    data = NULL;
2713
2714    return EFL_UTIL_ERROR_NONE;
2715 }
2716
2717 API efl_util_gesture_data
2718 efl_util_gesture_palm_cover_new(efl_util_gesture_h gesture_h)
2719 {
2720    Efl_Util_Gesture_Palm_Cover_Grab_Data *data;
2721
2722    if (!gesture_h || gesture_h->init == EINA_FALSE)
2723      {
2724         set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER);
2725         return NULL;
2726      }
2727
2728    data = (Efl_Util_Gesture_Palm_Cover_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Palm_Cover_Grab_Data));
2729    if (!data)
2730      {
2731         set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
2732         return NULL; /* LCOV_EXCL_LINE */
2733      }
2734
2735    data->base.type = TIZEN_GESTURE_TYPE_PALM_COVER;
2736
2737    set_last_result(EFL_UTIL_ERROR_NONE);
2738
2739    return (void *)data;
2740 }
2741
2742 API int
2743 efl_util_gesture_palm_cover_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2744 {
2745    if (!gesture_h || gesture_h->init == EINA_FALSE)
2746      {
2747         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2748      }
2749
2750    if (!data)
2751      {
2752         return EFL_UTIL_ERROR_INVALID_PARAMETER;
2753      }
2754
2755    free(data);
2756    data = NULL;
2757
2758    return EFL_UTIL_ERROR_NONE;
2759 }
2760
2761 /* LCOV_EXCL_START */
2762 API int
2763 efl_util_gesture_grab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2764 {
2765    int ret = EFL_UTIL_ERROR_NONE;
2766    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2767
2768    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2769
2770    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2771    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2772    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2773
2774    switch (base_data->type)
2775      {
2776         case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
2777            ret = _efl_util_gesture_grab_edge_swipe(data);
2778            break;
2779         case TIZEN_GESTURE_TYPE_EDGE_DRAG:
2780            ret = _efl_util_gesture_grab_edge_drag(data);
2781            break;
2782         case TIZEN_GESTURE_TYPE_TAP:
2783            ret = _efl_util_gesture_grab_tap(data);
2784            break;
2785         case TIZEN_GESTURE_TYPE_PALM_COVER:
2786            ret = _efl_util_gesture_grab_palm_cover(data);
2787            break;
2788         default:
2789            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2790      }
2791
2792    return ret;
2793 }
2794
2795 API int
2796 efl_util_gesture_ungrab(efl_util_gesture_h gesture_h, efl_util_gesture_data data)
2797 {
2798    int ret = EFL_UTIL_ERROR_NONE;
2799    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2800
2801    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2802
2803    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2804    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2805    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2806
2807    switch (base_data->type)
2808      {
2809         case TIZEN_GESTURE_TYPE_EDGE_SWIPE:
2810            ret = _efl_util_gesture_ungrab_edge_swipe(data);
2811            break;
2812         case TIZEN_GESTURE_TYPE_EDGE_DRAG:
2813            ret = _efl_util_gesture_ungrab_edge_drag(data);
2814            break;
2815         case TIZEN_GESTURE_TYPE_TAP:
2816            ret = _efl_util_gesture_ungrab_tap(data);
2817            break;
2818         case TIZEN_GESTURE_TYPE_PALM_COVER:
2819            ret = _efl_util_gesture_ungrab_palm_cover(data);
2820            break;
2821         default:
2822            return EFL_UTIL_ERROR_INVALID_PARAMETER;
2823      }
2824
2825    return ret;
2826 }
2827 /* LCOV_EXCL_STOP */
2828
2829 API int
2830 efl_util_gesture_select(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
2831 {
2832    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2833    Ecore_Wl2_Window *wlwin;
2834    struct wl_surface *surface;
2835    int ret;
2836
2837    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2838
2839    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2840    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2841    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2842    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2843
2844    if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
2845      return EFL_UTIL_ERROR_NOT_SUPPORTED;
2846
2847    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2848    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2849
2850    surface = ecore_wl2_window_surface_get(wlwin);
2851    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2852                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2853
2854    tizen_gesture_select_palm_cover(_eflutil.wl.gesture.proto, surface);
2855
2856    while (_eflutil.wl.gesture.request_notified == -1)
2857      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2858
2859    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2860    _eflutil.wl.gesture.request_notified = -1;
2861
2862    return ret;
2863 }
2864
2865 API int
2866 efl_util_gesture_deselect(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data)
2867 {
2868    Efl_Util_Gesture_Common_Grab_Data *base_data = NULL;
2869    Ecore_Wl2_Window *wlwin;
2870    struct wl_surface *surface;
2871    int ret;
2872
2873    base_data = (Efl_Util_Gesture_Common_Grab_Data *)data;
2874
2875    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2876    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2877    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2878    EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER);
2879
2880    if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER)
2881      return EFL_UTIL_ERROR_NOT_SUPPORTED;
2882
2883    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2884    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2885
2886    surface = ecore_wl2_window_surface_get(wlwin);
2887    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2888                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2889
2890    tizen_gesture_deselect_palm_cover(_eflutil.wl.gesture.proto, surface);
2891
2892    while (_eflutil.wl.gesture.request_notified == -1)
2893      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2894
2895    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2896    _eflutil.wl.gesture.request_notified = -1;
2897
2898    return ret;
2899 }
2900
2901 /* LCOV_EXCL_START */
2902 API int
2903 efl_util_gesture_activate_set(efl_util_gesture_h gesture_h, unsigned int type, Eina_Bool active)
2904 {
2905    int ret;
2906
2907    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2908    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2909    EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
2910
2911    tizen_gesture_activate_set(_eflutil.wl.gesture.proto, NULL, type, active);
2912
2913    while (_eflutil.wl.gesture.request_notified == -1)
2914      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2915
2916    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2917    _eflutil.wl.gesture.request_notified = -1;
2918
2919    return ret;
2920 }
2921 /* LCOV_EXCL_STOP */
2922
2923 API int
2924 efl_util_gesture_activate_set_on_window(efl_util_gesture_h gesture_h, Evas_Object *window, unsigned int type, Eina_Bool active)
2925 {
2926    Ecore_Wl2_Window *wlwin;
2927    struct wl_surface *surface;
2928    int ret;
2929
2930    EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER);
2931    EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER);
2932    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
2933    EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER);
2934
2935    wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window);
2936    if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER;
2937
2938    surface = ecore_wl2_window_surface_get(wlwin);
2939    EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
2940                                   EFL_UTIL_ERROR_INVALID_PARAMETER);
2941
2942    tizen_gesture_activate_set(_eflutil.wl.gesture.proto, surface, type, active);
2943
2944    while (_eflutil.wl.gesture.request_notified == -1)
2945      wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue);
2946
2947    ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified);
2948    _eflutil.wl.gesture.request_notified = -1;
2949
2950    return ret;
2951 }