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