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