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