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