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