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