code refactoring
[platform/core/api/efl-util.git] / src / efl_util.c
1 /*
2  * Copyright (c) 2011-2015 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 <Elementary.h>
24 #include <Ecore_Evas.h>
25
26 #if X11
27 #include <Ecore_X.h>
28 #include <utilX.h>
29 #endif /* end of X11 */
30
31 #if WAYLAND
32 #include <Ecore_Wayland.h>
33 #include <wayland-client.h>
34 #include "tizen_notification-client-protocol.h"
35 #include "tizen_window_screen-client-protocol.h"
36 #endif /* end of WAYLAND */
37
38 /* callback handler index */
39 #define CBH_NOTI_LEV 0
40 #define CBH_SCR_MODE 1
41 #define CBH_MAX      2
42
43 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
44
45 typedef struct _Efl_Util_Callback_Info
46 {
47    Evas_Object *win;
48    Efl_Util_Cb cb;
49    void *data;
50 } Efl_Util_Callback_Info;
51
52 typedef struct _Efl_Util_Wl_Surface_Lv_Info
53 {
54    void *surface; /* wl_surface */
55    int level;
56    Eina_Bool wait_for_done;
57 } Efl_Util_Wl_Surface_Lv_Info;
58
59 typedef struct _Efl_Util_Wl_Surface_Scr_Mode_Info
60 {
61    void *surface; /* wl_surface */
62    unsigned int mode;
63    Eina_Bool wait_for_done;
64 } Efl_Util_Wl_Surface_Scr_Mode_Info;
65
66 typedef struct _Efl_Util_Data
67 {
68    /* x11 related stuffs */
69    struct
70    {
71       Eina_Bool init;
72       Ecore_Event_Handler *handler; /* x11 client message handler */
73       #if X11
74       Ecore_X_Display *dpy;
75       #endif /* end of X11 */
76    } x11;
77
78    struct
79    {
80       Eina_List *info_list; /* list of callback info */
81       unsigned int atom; /* x11 atom */
82    } cb_handler[CBH_MAX];
83
84    /* wayland related stuffs */
85    struct
86    {
87       Eina_Bool init;
88       #if WAYLAND
89       struct wl_display *dpy;
90       struct
91       {
92          struct tizen_notification *proto;
93          Eina_Hash *hash;
94       } noti_lv;
95       struct
96       {
97          struct tizen_window_screen *proto;
98          Eina_Hash *hash;
99       } scr_mode;
100       #endif /* end of WAYLAND */
101    } wl;
102 } Efl_Util_Data;
103
104 static Efl_Util_Data _eflutil =
105 {
106    {
107       EINA_FALSE,
108       NULL,
109       #if X11
110       NULL
111       #endif /* end of X11 */
112    },
113    {
114       { NULL, 0 }, /* handler for notification level */
115       { NULL, 0 }  /* handler for screen mode */
116    },
117    {
118       EINA_FALSE,
119       #if WAYLAND
120       NULL,
121       { NULL, NULL }, /* tizen_notification protocol */
122       { NULL, NULL }  /* tizen_window_screen protocol */
123       #endif /* end of WAYLAND */
124    }
125 };
126
127 static Eina_Bool               _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
128 static Eina_Bool               _cb_info_del_by_win(Evas_Object *win, int idx);
129 static Eina_List              *_cb_info_list_get(int idx);
130 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
131 #if X11
132 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin);
133 static Eina_Bool               _cb_x11_client_msg(void *data, int type, void *event);
134 static Eina_Bool               _x11_init(void);
135 #endif /* end of X11 */
136 #if WAYLAND
137 static Eina_Bool               _wl_init(void);
138 static void                    _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
139 static void                    _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
140 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
141 static void                    _cb_wl_tz_noti_lv_done(void *data, struct tizen_notification *proto, struct wl_surface *surface, int32_t level, uint32_t state);
142 static void                    _cb_wl_tz_scr_mode_done(void *data, struct tizen_window_screen *proto, struct wl_surface *surface, uint32_t mode, uint32_t state);
143
144 static const struct wl_registry_listener _wl_reg_listener =
145 {
146    _cb_wl_reg_global,
147    _cb_wl_reg_global_remove
148 };
149
150 struct tizen_notification_listener _wl_tz_noti_lv_listener =
151 {
152    _cb_wl_tz_noti_lv_done
153 };
154
155 struct tizen_window_screen_listener _wl_tz_scr_mode_listener =
156 {
157    _cb_wl_tz_scr_mode_done
158 };
159 #endif /* end of WAYLAND */
160
161 static Eina_Bool
162 _cb_info_add(Evas_Object *win,
163              Efl_Util_Cb cb,
164              void *data,
165              int idx)
166 {
167    Efl_Util_Callback_Info *info;
168
169    info = _cb_info_find_by_win(win, idx);
170    if (info)
171      {
172         _eflutil.cb_handler[idx].info_list
173            = eina_list_remove(_eflutil.cb_handler[idx].info_list,
174                               info);
175         free(info);
176      }
177
178    info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
179    if (!info) return EINA_FALSE;
180
181    info->win = win;
182    info->cb = cb;
183    info->data = data;
184
185    _eflutil.cb_handler[idx].info_list
186       = eina_list_append(_eflutil.cb_handler[idx].info_list,
187                          info);
188
189 #if X11
190    if (!_eflutil.x11.handler)
191      _eflutil.x11.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
192                                                     _cb_x11_client_msg,
193                                                     NULL);
194 #endif /* end of X11 */
195
196    return EINA_TRUE;
197 }
198
199 static Eina_Bool
200 _cb_info_del_by_win(Evas_Object *win,
201                     int idx)
202 {
203    Efl_Util_Callback_Info *info;
204    unsigned int count;
205
206    info = _cb_info_find_by_win(win, idx);
207    if (!info) return EINA_FALSE;
208
209    _eflutil.cb_handler[idx].info_list
210       = eina_list_remove(_eflutil.cb_handler[idx].info_list,
211                          info);
212    free(info);
213
214    count = eina_list_count(_eflutil.cb_handler[idx].info_list);
215    if ((count == 0) && (_eflutil.x11.handler))
216      {
217         ecore_event_handler_del(_eflutil.x11.handler);
218         _eflutil.x11.handler = NULL;
219      }
220
221    return EINA_TRUE;
222 }
223
224 static Eina_List *
225 _cb_info_list_get(int idx)
226 {
227    return _eflutil.cb_handler[idx].info_list;
228 }
229
230 static Efl_Util_Callback_Info *
231 _cb_info_find_by_win(Evas_Object *win,
232                      int idx)
233 {
234    Eina_List *l, *ll;
235    Efl_Util_Callback_Info *info;
236
237    l = _cb_info_list_get(idx);
238    EINA_LIST_FOREACH(l, ll, info)
239      {
240         if (info->win == win) return info;
241      }
242
243    return NULL;
244 }
245
246 #if X11
247 static Efl_Util_Callback_Info *
248 _cb_info_find_by_xwin(unsigned int xwin,
249                       int idx)
250 {
251    Eina_List *l, *ll;
252    Efl_Util_Callback_Info *info;
253    unsigned int xwin2;
254
255    l = _cb_info_list_get(idx);
256    EINA_LIST_FOREACH(l, ll, info)
257      {
258         xwin2 = elm_win_xwindow_get(info->win);
259         if (xwin == xwin2) return info;
260      }
261
262    return NULL;
263 }
264
265 static Eina_Bool
266 _cb_x11_client_msg(void *data,
267                    int type,
268                    void *event)
269 {
270    Ecore_X_Event_Client_Message *ev;
271    Ecore_X_Window xwin;
272    Efl_Util_Callback_Info *info;
273
274    ev = event;
275    if (!ev) return ECORE_CALLBACK_PASS_ON;
276
277    xwin = ev->win;
278    if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
279
280    if (ev->message_type == _eflutil.atom.noti_lv)
281      {
282         info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
283
284         /* permission denied */
285         if ((ev->data.l[1] == 0) &&
286             (info) &&
287             (info->cb))
288           {
289              info->cb(info->win,
290                       EFL_UTIL_ERROR_PERMISSION_DENIED,
291                       info->data);
292           }
293      }
294    else if (ev->message_type == _eflutil.atom.scr_mode)
295      {
296         info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
297
298         /* permission denied */
299         if ((ev->data.l[1] == 0) &&
300             (info) &&
301             (info->cb))
302           {
303              info->cb(info->win,
304                       EFL_UTIL_ERROR_PERMISSION_DENIED,
305                       info->data);
306           }
307      }
308    return ECORE_CALLBACK_PASS_ON;
309 }
310
311 static Eina_Bool
312 _x11_init(void)
313 {
314    if (_eflutil.x11.init) return EINA_TRUE;
315
316    _eflutil.x11.dpy = ecore_x_display_get();
317    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.x11.dpy, EINA_FALSE);
318
319    _eflutil.x11.init = EINA_TRUE;
320
321    return EINA_TRUE;
322 }
323 #endif /* end of X11 */
324
325 #if WAYLAND
326 static Eina_Bool
327 _wl_init(void)
328 {
329    struct wl_registry *reg;
330
331    if (_eflutil.wl.init) return EINA_TRUE;
332
333    _eflutil.wl.dpy = ecore_wl_display_get();
334    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.dpy, EINA_FALSE);
335
336    reg = wl_display_get_registry(_eflutil.wl.dpy);
337    EINA_SAFETY_ON_NULL_RETURN_VAL(reg, EINA_FALSE);
338
339    wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
340
341    _eflutil.wl.init = EINA_TRUE;
342
343    return EINA_TRUE;
344 }
345
346 static void
347 _cb_wl_reg_global(void *data,
348                   struct wl_registry *reg,
349                   unsigned int name,
350                   const char *interface,
351                   unsigned int version)
352 {
353    if (!strcmp(interface, "tizen_notification"))
354      {
355         struct tizen_notification *proto;
356         proto = wl_registry_bind(reg,
357                                  name,
358                                  &tizen_notification_interface,
359                                  1);
360         if (!proto) return;
361
362         tizen_notification_add_listener(proto,
363                                         &_wl_tz_noti_lv_listener,
364                                         NULL);
365
366         _eflutil.wl.noti_lv.hash = eina_hash_pointer_new(free);
367         _eflutil.wl.noti_lv.proto = proto;
368      }
369    else if (!strcmp(interface, "tizen_window_screen"))
370      {
371         struct tizen_window_screen *proto;
372         proto = wl_registry_bind(reg,
373                                  name,
374                                  &tizen_window_screen_interface,
375                                  1);
376         if (!proto) return;
377
378         tizen_window_screen_add_listener(proto,
379                                          &_wl_tz_scr_mode_listener,
380                                          NULL);
381
382         _eflutil.wl.scr_mode.hash = eina_hash_pointer_new(free);
383         _eflutil.wl.scr_mode.proto = proto;
384      }
385 }
386
387 static void
388 _cb_wl_reg_global_remove(void *data,
389                          struct wl_registry *reg,
390                          unsigned int name)
391 {
392    _eflutil.wl.noti_lv.proto = NULL;
393    eina_hash_free(_eflutil.wl.noti_lv.hash);
394    _eflutil.wl.scr_mode.proto = NULL;
395    eina_hash_free(_eflutil.wl.scr_mode.hash);
396 }
397
398 static Efl_Util_Callback_Info *
399 _cb_info_find_by_wlsurf(void *wlsurf,
400                         int idx)
401 {
402    Eina_List *l, *ll;
403    Efl_Util_Callback_Info *info;
404    Ecore_Wl_Window *wlwin2 = NULL;
405    void *wlsurf2 = NULL;
406
407    l = _cb_info_list_get(idx);
408    EINA_LIST_FOREACH(l, ll, info)
409      {
410         wlwin2 = elm_win_wl_window_get(info->win);
411         wlsurf2 = ecore_wl_window_surface_get(wlwin2);
412         if (wlsurf== wlsurf2) return info;
413      }
414
415    return NULL;
416 }
417
418 static void
419 _cb_wl_tz_noti_lv_done(void *data,
420                        struct tizen_notification *proto,
421                        struct wl_surface *surface,
422                        int32_t level,
423                        uint32_t state)
424 {
425    Efl_Util_Wl_Surface_Lv_Info *lv_info;
426    Efl_Util_Callback_Info *cb_info;
427
428    lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
429    if (lv_info)
430      {
431         lv_info->level = level;
432         lv_info->wait_for_done = EINA_FALSE;
433      }
434
435    if (state != TIZEN_NOTIFICATION_ERROR_STATE_PERMISSION_DENIED) return;
436
437    cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
438    if (!cb_info) return;
439    if (!cb_info->cb) return;
440
441    cb_info->cb(cb_info->win,
442                EFL_UTIL_ERROR_PERMISSION_DENIED,
443                cb_info->data);
444 }
445
446 static void
447 _cb_wl_tz_scr_mode_done(void *data,
448                         struct tizen_window_screen *proto,
449                         struct wl_surface *surface,
450                         uint32_t mode,
451                         uint32_t state)
452 {
453
454    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
455    Efl_Util_Callback_Info *cb_info;
456
457    scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
458    if (scr_mode_info)
459      {
460         scr_mode_info->mode = mode;
461         scr_mode_info->wait_for_done = EINA_FALSE;
462      }
463
464    if (state != TIZEN_WINDOW_SCREEN_ERROR_STATE_PERMISSION_DENIED) return;
465
466    cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE);
467    if (!cb_info) return;
468    if (!cb_info->cb) return;
469
470    cb_info->cb(cb_info->win,
471                EFL_UTIL_ERROR_PERMISSION_DENIED,
472                cb_info->data);
473 }
474 #endif /* end of WAYLAND */
475
476 API int
477 efl_util_set_notification_window_level(Evas_Object *window,
478                                        efl_util_notification_level_e level)
479 {
480    Eina_Bool res;
481
482    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
483    EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
484                                    (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
485                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
486
487 #if X11
488    Ecore_X_Window_Type window_type;
489    Ecore_X_Window xwin;
490
491    res = _x11_init();
492    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
493
494    xwin = elm_win_xwindow_get(window);
495    if (xwin)
496      {
497         if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
498           {
499              // success to get window type
500              if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
501                {
502                   // given EFL window's type is not notification type.
503                   return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
504                }
505           }
506         else
507           return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
508
509         utilx_set_system_notification_level(_eflutil.x11.dpy,
510                                             xwin,
511                                             level);
512         return EFL_UTIL_ERROR_NONE;
513      }
514 #endif /* end of X11 */
515
516 #if WAYLAND
517    Elm_Win_Type type;
518    Ecore_Wl_Window *wlwin;
519    struct wl_surface *surface;
520    Efl_Util_Wl_Surface_Lv_Info *lv_info;
521
522    res = _wl_init();
523    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
524
525    type = elm_win_type_get(window);
526    EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
527                                    EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
528
529    wlwin = elm_win_wl_window_get(window);
530    if (wlwin)
531      {
532         while (!_eflutil.wl.noti_lv.proto)
533           wl_display_dispatch(_eflutil.wl.dpy);
534
535         surface = ecore_wl_window_surface_get(wlwin);
536         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
537                                        EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
538
539         lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
540         if (!lv_info)
541           {
542              lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
543              EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
544
545              lv_info->surface = surface;
546              lv_info->level = (int)level;
547              lv_info->wait_for_done = EINA_TRUE;
548
549              eina_hash_add(_eflutil.wl.noti_lv.hash,
550                            &surface,
551                            lv_info);
552           }
553         else
554           {
555              lv_info->level = (int)level;
556              lv_info->wait_for_done = EINA_TRUE;
557           }
558
559         tizen_notification_set_level(_eflutil.wl.noti_lv.proto,
560                                      surface,
561                                      (int)level);
562
563         return EFL_UTIL_ERROR_NONE;
564      }
565 #endif /* end of WAYLAND */
566
567    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
568 }
569
570 API int
571 efl_util_get_notification_window_level(Evas_Object *window,
572                                        efl_util_notification_level_e *level)
573 {
574    Eina_Bool res;
575
576    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
577    EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
578
579 #if X11
580    Ecore_X_Window_Type window_type;
581    Utilx_Notification_Level utilx_level;
582    Ecore_X_Window xwin;
583
584    res = _x11_init();
585    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
586
587    xwin = elm_win_xwindow_get(window);
588    if (xwin)
589      {
590         if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
591           {
592              // success to get window type
593              if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
594                {
595                   // given EFL window's type is not notification type.
596                   return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
597                }
598
599              utilx_level = utilx_get_system_notification_level(_eflutil.x11.dpy, xwin);
600              if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
601                *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
602              else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
603                *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
604              else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
605                *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
606              else
607                return EFL_UTIL_ERROR_INVALID_PARAMETER;
608           }
609         else
610           return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
611
612         return EFL_UTIL_ERROR_NONE;
613      }
614 #endif /* end of X11 */
615
616 #if WAYLAND
617    Elm_Win_Type type;
618    Ecore_Wl_Window *wlwin;
619    struct wl_surface *surface;
620    Efl_Util_Wl_Surface_Lv_Info *lv_info;
621
622    res = _wl_init();
623    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
624
625    type = elm_win_type_get(window);
626    EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
627                                    EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
628
629    wlwin = elm_win_wl_window_get(window);
630    if (wlwin)
631      {
632         while (!_eflutil.wl.noti_lv.proto)
633           wl_display_dispatch(_eflutil.wl.dpy);
634
635         surface = ecore_wl_window_surface_get(wlwin);
636         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
637                                        EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
638
639         lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
640         if (lv_info)
641           {
642              if (lv_info->wait_for_done)
643                {
644                   if (ecore_wl_window_shell_surface_get(wlwin) ||
645                       ecore_wl_window_xdg_surface_get(wlwin))
646                     {
647                        while (lv_info->wait_for_done)
648                          {
649                             ecore_wl_flush();
650                             wl_display_dispatch(_eflutil.wl.dpy);
651                          }
652                     }
653                   else
654                     {
655                        *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
656                        return EFL_UTIL_ERROR_INVALID_PARAMETER;
657                     }
658                }
659
660              switch (lv_info->level)
661                {
662                 case TIZEN_NOTIFICATION_LEVEL_1:       *level = EFL_UTIL_NOTIFICATION_LEVEL_1;       break;
663                 case TIZEN_NOTIFICATION_LEVEL_2:       *level = EFL_UTIL_NOTIFICATION_LEVEL_2;       break;
664                 case TIZEN_NOTIFICATION_LEVEL_3:       *level = EFL_UTIL_NOTIFICATION_LEVEL_3;       break;
665                 case TIZEN_NOTIFICATION_LEVEL_NONE:    *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE;    break;
666                 case TIZEN_NOTIFICATION_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
667                 case TIZEN_NOTIFICATION_LEVEL_MEDIUM:  *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM;  break;
668                 case TIZEN_NOTIFICATION_LEVEL_HIGH:    *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH;    break;
669                 case TIZEN_NOTIFICATION_LEVEL_TOP:     *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP;     break;
670                 default:                               *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
671                                                        return EFL_UTIL_ERROR_INVALID_PARAMETER;
672                }
673              return EFL_UTIL_ERROR_NONE;
674           }
675         else
676           *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
677
678         return EFL_UTIL_ERROR_NONE;
679      }
680 #endif /* end of WAYLAND */
681    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
682 }
683
684 API int
685 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
686                                                 efl_util_notification_window_level_error_cb callback,
687                                                 void *user_data)
688 {
689    Eina_Bool ret = EINA_FALSE;
690
691    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
692    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
693
694    ret = _cb_info_add(window,
695                       (Efl_Util_Cb)callback,
696                       user_data,
697                       CBH_NOTI_LEV);
698    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
699
700 #if X11
701    if (!_eflutil.atom.noti_lv)
702      _eflutil.atom.noti_lv = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
703 #endif /* end of X11 */
704
705    return EFL_UTIL_ERROR_NONE;
706 }
707
708 API int
709 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
710 {
711    Eina_Bool ret = EINA_FALSE;
712
713    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
714
715    ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
716    if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
717
718    return EFL_UTIL_ERROR_NONE;
719 }
720
721 API int
722 efl_util_set_window_opaque_state(Evas_Object *window,
723                                  int opaque)
724 {
725    Eina_Bool res;
726
727    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
728    EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
729                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
730
731 #if X11
732    Ecore_X_Window xwin;
733    Utilx_Opaque_State state;
734    int ret;
735
736    res = _x11_init();
737    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
738
739    xwin = elm_win_xwindow_get(window);
740    EINA_SAFETY_ON_NULL_RETURN_VAL(xwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
741
742    if (opaque)
743      state = UTILX_OPAQUE_STATE_ON;
744    else
745      state = UTILX_OPAQUE_STATE_OFF;
746
747    ret = utilx_set_window_opaque_state(_eflutil.x11.dpy,
748                                        xwin,
749                                        state);
750
751    if (!ret)
752      return EFL_UTIL_ERROR_INVALID_PARAMETER;
753    else
754      return EFL_UTIL_ERROR_NONE;
755 #endif /* end of X11 */
756
757 #if WAYLAND
758    Ecore_Wl_Window *wlwin;
759    int x, y, w, h;
760
761    res = _wl_init();
762    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
763
764    wlwin = elm_win_wl_window_get(window);
765    if (wlwin)
766      {
767         evas_object_geometry_get(window, &x, &y, &w, &h);
768
769         if (opaque)
770           ecore_wl_window_opaque_region_set(wlwin, x, y, w, h);
771         else
772           ecore_wl_window_opaque_region_set(wlwin, 0, 0, 0, 0);
773
774         return EFL_UTIL_ERROR_NONE;
775      }
776
777    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
778 #endif /* end of WAYLAND */
779 }
780
781 API int
782 efl_util_set_window_screen_mode(Evas_Object *window,
783                                 efl_util_screen_mode_e mode)
784 {
785    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
786    EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
787                                     (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
788                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
789
790 #if X11
791    Evas *e;
792    Ecore_Evas *ee;
793    int id;
794
795    e = evas_object_evas_get(window);
796    EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
797
798    ee = ecore_evas_ecore_evas_get(e);
799    EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
800
801    id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
802    if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
803      {
804         if (id == -1)
805           ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
806         else
807           ecore_evas_aux_hint_val_set(ee, id, "1");
808      }
809    else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
810      {
811         if (id == -1)
812           ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
813         else
814           ecore_evas_aux_hint_val_set(ee, id, "0");
815      }
816    else
817      return EFL_UTIL_ERROR_INVALID_PARAMETER;
818
819    return EFL_UTIL_ERROR_NONE;
820 #endif /* end of X11 */
821
822 #if WAYLAND
823    Ecore_Wl_Window *wlwin;
824    struct wl_surface *surface;
825    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
826    Eina_Bool res;
827
828    res = _wl_init();
829    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
830
831    wlwin = elm_win_wl_window_get(window);
832    if (wlwin)
833      {
834         while (!_eflutil.wl.scr_mode.proto)
835           wl_display_dispatch(_eflutil.wl.dpy);
836
837         surface = ecore_wl_window_surface_get(wlwin);
838         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
839                                        EFL_UTIL_ERROR_INVALID_PARAMETER);
840
841         scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
842         if (!scr_mode_info)
843           {
844              scr_mode_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Scr_Mode_Info));
845              EINA_SAFETY_ON_NULL_RETURN_VAL(scr_mode_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
846
847              scr_mode_info->surface = surface;
848              scr_mode_info->mode = (unsigned int)mode;
849              scr_mode_info->wait_for_done = EINA_TRUE;
850
851              eina_hash_add(_eflutil.wl.scr_mode.hash,
852                            &surface,
853                            scr_mode_info);
854           }
855         else
856           {
857              scr_mode_info->mode = (unsigned int)mode;
858              scr_mode_info->wait_for_done = EINA_TRUE;
859           }
860
861         tizen_window_screen_set_mode(_eflutil.wl.scr_mode.proto,
862                                      surface,
863                                      (unsigned int)mode);
864
865         return EFL_UTIL_ERROR_NONE;
866      }
867    else
868      return EFL_UTIL_ERROR_INVALID_PARAMETER;
869 #endif /* end of WAYLAND */
870 }
871
872 API int
873 efl_util_get_window_screen_mode(Evas_Object *window,
874                                 efl_util_screen_mode_e *mode)
875 {
876    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
877    EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
878
879 #if X11
880    Evas *e;
881    Ecore_Evas *ee;
882    const char *str;
883    int id;
884
885    e = evas_object_evas_get(window);
886    EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
887
888    ee = ecore_evas_ecore_evas_get(e);
889    EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
890
891    id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
892    EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
893
894    str = ecore_evas_aux_hint_val_get(ee, id);
895    EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
896
897    if (strncmp(str, "1", strlen("1")) == 0)
898      *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
899    else
900      *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
901
902    return EFL_UTIL_ERROR_NONE;
903 #endif /* end of X11 */
904
905 #if WAYLAND
906    Ecore_Wl_Window *wlwin;
907    struct wl_surface *surface;
908    Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info;
909    Eina_Bool res;
910
911    res = _wl_init();
912    EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER);
913
914    wlwin = elm_win_wl_window_get(window);
915    if (wlwin)
916      {
917         while (!_eflutil.wl.scr_mode.proto)
918           wl_display_dispatch(_eflutil.wl.dpy);
919
920         surface = ecore_wl_window_surface_get(wlwin);
921         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
922                                        EFL_UTIL_ERROR_INVALID_PARAMETER);
923
924         scr_mode_info = eina_hash_find(_eflutil.wl.scr_mode.hash, &surface);
925         if (scr_mode_info)
926           {
927              if (scr_mode_info->wait_for_done)
928                {
929                   while (scr_mode_info->wait_for_done)
930                     {
931                        ecore_wl_flush();
932                        wl_display_dispatch(_eflutil.wl.dpy);
933                     }
934                }
935
936              switch (scr_mode_info->mode)
937                {
938                 case TIZEN_WINDOW_SCREEN_MODE_DEFAULT:   *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;   break;
939                 case TIZEN_WINDOW_SCREEN_MODE_ALWAYS_ON: *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON; break;
940                 default:                                 *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
941                   return EFL_UTIL_ERROR_INVALID_PARAMETER;
942                }
943              return EFL_UTIL_ERROR_NONE;
944           }
945         else
946           {
947              *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
948              return EFL_UTIL_ERROR_INVALID_PARAMETER;
949           }
950      }
951    else
952      return EFL_UTIL_ERROR_INVALID_PARAMETER;
953 #endif /* end of WAYLAND */
954 }
955
956 API int
957 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
958                                          efl_util_window_screen_mode_error_cb callback,
959                                          void *user_data)
960 {
961    Eina_Bool ret = EINA_FALSE;
962
963    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
964    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
965
966    ret = _cb_info_add(window,
967                       (Efl_Util_Cb)callback,
968                       user_data,
969                       CBH_SCR_MODE);
970    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
971
972 #if X11
973    if (!_eflutil.atom.scr_mode)
974      _eflutil.atom.scr_mode = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
975 #endif /* end of X11 */
976
977    return EFL_UTIL_ERROR_NONE;
978 }
979
980 API int
981 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
982 {
983    Eina_Bool ret = EINA_FALSE;
984
985    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
986
987    ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
988    if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER;
989
990    return EFL_UTIL_ERROR_NONE;
991 }
992
993 API int
994 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
995 {
996    return EFL_UTIL_ERROR_NONE;
997 }
998
999 API void
1000 efl_util_input_deinitialize_generator(void)
1001 {
1002    return;
1003 }
1004
1005 API int
1006 efl_util_input_generate_key(const char *key_name,
1007                             int pressed)
1008 {
1009    return EFL_UTIL_ERROR_NONE;
1010 }
1011
1012 API int
1013 efl_util_input_generate_touch(int idx,
1014                               efl_util_input_touch_type_e touch_type,
1015                               int x,
1016                               int y)
1017 {
1018    return EFL_UTIL_ERROR_NONE;
1019 }
1020
1021 API efl_util_screenshot_h
1022 efl_util_screenshot_initialize(int width,
1023                                int height)
1024 {
1025    return 0;
1026 }
1027
1028 API tbm_surface_h
1029 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
1030 {
1031    return 0;
1032 }
1033
1034 API int
1035 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
1036 {
1037    return EFL_UTIL_ERROR_NONE;
1038 }