window screen mode support
[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 #endif /* end of WAYLAND */
36
37 /* callback handler index */
38 #define CBH_NOTI_LEV 0
39 #define CBH_SCR_MODE 1
40 #define CBH_MAX      2
41
42 typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *);
43
44 typedef struct _Efl_Util_Callback_Info
45 {
46    Evas_Object *win;
47    Efl_Util_Cb cb;
48    void *data;
49 } Efl_Util_Callback_Info;
50
51 typedef struct _Efl_Util_Wl_Surface_Lv_Info
52 {
53    void *surface; /* wl_surface */
54    int level;
55    Eina_Bool wait_for_done;
56 } Efl_Util_Wl_Surface_Lv_Info;
57
58 typedef struct _Efl_Util_Data
59 {
60    Ecore_Event_Handler *handler; /* x11 client message handler */
61    struct
62    {
63       Eina_List *info_list; /* list of callback info */
64       unsigned int atom; /* x11 atom */
65    } cb_handler[CBH_MAX];
66
67    /* wayland related stuffs */
68    struct
69    {
70       Eina_Bool init;
71       #if WAYLAND
72       struct wl_display *dpy;
73       struct
74       {
75          struct tizen_notification *proto;
76          Eina_Hash *hash;
77       } noti_lv;
78       #endif /* end of WAYLAND */
79    } wl;
80 } Efl_Util_Data;
81
82 static Efl_Util_Data _eflutil =
83 {
84    NULL,
85    {
86       { NULL, 0 }, /* handler for notification level */
87       { NULL, 0 }  /* handler for screen mode */
88    },
89    {
90       EINA_FALSE,
91       #if WAYLAND
92       NULL,
93       { NULL, NULL } /* tizen_notification protocol */
94       #endif /* end of WAYLAND */
95    }
96 };
97
98 static Eina_Bool               _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx);
99 static Eina_Bool               _cb_info_del_by_win(Evas_Object *win, int idx);
100 static Eina_List              *_cb_info_list_get(int idx);
101 static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx);
102 #if X11
103 static Efl_Util_Callback_Info *_cb_info_find_by_xwin(unsigned int xwin);
104 static Eina_Bool               _cb_x11_client_msg(void *data, int type, void *event);
105 #endif /* end of X11 */
106 #if WAYLAND
107 static Eina_Bool               _wl_init(void);
108 static void                    _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version);
109 static void                    _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name);
110 static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx);
111 static void                    _cb_wl_tz_noti_lv_done(void *data, struct tizen_notification *proto, struct wl_surface *surface, int32_t level, uint32_t state);
112
113 static const struct wl_registry_listener _wl_reg_listener =
114 {
115    _cb_wl_reg_global,
116    _cb_wl_reg_global_remove
117 };
118
119 struct tizen_notification_listener _wl_tz_noti_lv_listener =
120 {
121    _cb_wl_tz_noti_lv_done
122 };
123 #endif /* end of WAYLAND */
124
125 static Eina_Bool
126 _cb_info_add(Evas_Object *win,
127              Efl_Util_Cb cb,
128              void *data,
129              int idx)
130 {
131    Efl_Util_Callback_Info *info;
132
133    info = _cb_info_find_by_win(win, idx);
134    if (info)
135      {
136         _eflutil.cb_handler[idx].info_list
137            = eina_list_remove(_eflutil.cb_handler[idx].info_list,
138                               info);
139         free(info);
140      }
141
142    info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info));
143    if (!info) return EINA_FALSE;
144
145    info->win = win;
146    info->cb = cb;
147    info->data = data;
148
149    _eflutil.cb_handler[idx].info_list
150       = eina_list_append(_eflutil.cb_handler[idx].info_list,
151                          info);
152
153 #if X11
154    if (!_eflutil.handler)
155      _eflutil.handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
156                                                 _cb_x11_client_msg,
157                                                 NULL);
158 #endif /* end of X11 */
159
160    return EINA_TRUE;
161 }
162
163 static Eina_Bool
164 _cb_info_del_by_win(Evas_Object *win,
165                     int idx)
166 {
167    Efl_Util_Callback_Info *info;
168    unsigned int count;
169
170    info = _cb_info_find_by_win(win, idx);
171    if (!info) return EINA_FALSE;
172
173    _eflutil.cb_handler[idx].info_list
174       = eina_list_remove(_eflutil.cb_handler[idx].info_list,
175                          info);
176    free(info);
177
178    count = eina_list_count(_eflutil.cb_handler[idx].info_list);
179    if ((count == 0) && (_eflutil.handler))
180      {
181         ecore_event_handler_del(_eflutil.handler);
182         _eflutil.handler = NULL;
183      }
184
185    return EINA_TRUE;
186 }
187
188 static Eina_List *
189 _cb_info_list_get(int idx)
190 {
191    return _eflutil.cb_handler[idx].info_list;
192 }
193
194 static Efl_Util_Callback_Info *
195 _cb_info_find_by_win(Evas_Object *win,
196                      int idx)
197 {
198    Eina_List *l, *ll;
199    Efl_Util_Callback_Info *info;
200
201    l = _cb_info_list_get(idx);
202    EINA_LIST_FOREACH(l, ll, info)
203      {
204         if (info->win == win) return info;
205      }
206
207    return NULL;
208 }
209
210 #if X11
211 static Efl_Util_Callback_Info *
212 _cb_info_find_by_xwin(unsigned int xwin,
213                       int idx)
214 {
215    Eina_List *l, *ll;
216    Efl_Util_Callback_Info *info;
217    unsigned int xwin2;
218
219    l = _cb_info_list_get(idx);
220    EINA_LIST_FOREACH(l, ll, info)
221      {
222         xwin2 = elm_win_xwindow_get(info->win);
223         if (xwin == xwin2) return info;
224      }
225
226    return NULL;
227 }
228
229 static Eina_Bool
230 _cb_x11_client_msg(void *data,
231                    int type,
232                    void *event)
233 {
234    Ecore_X_Event_Client_Message *ev;
235    Ecore_X_Window xwin;
236    Efl_Util_Callback_Info *info;
237
238    ev = event;
239    if (!ev) return ECORE_CALLBACK_PASS_ON;
240
241    xwin = ev->win;
242    if (xwin == 0) return ECORE_CALLBACK_PASS_ON;
243
244    if (ev->message_type == _eflutil.atom.noti_lv)
245      {
246         info = _cb_info_find_by_xwin(xwin, CBH_NOTI_LEV);
247
248         /* permission denied */
249         if ((ev->data.l[1] == 0) &&
250             (info) &&
251             (info->cb))
252           {
253              info->cb(info->win,
254                       EFL_UTIL_ERROR_PERMISSION_DENIED,
255                       info->data);
256           }
257      }
258    else if (ev->message_type == _eflutil.atom.scr_mode)
259      {
260         info = _cb_info_find_by_xwin(xwin, CBH_SCR_MODE);
261
262         /* permission denied */
263         if ((ev->data.l[1] == 0) &&
264             (info) &&
265             (info->cb))
266           {
267              info->cb(info->win,
268                       EFL_UTIL_ERROR_PERMISSION_DENIED,
269                       info->data);
270           }
271      }
272    return ECORE_CALLBACK_PASS_ON;
273 }
274 #endif /* end of X11 */
275
276 #if WAYLAND
277 static Eina_Bool
278 _wl_init(void)
279 {
280    struct wl_registry *reg;
281
282    if (_eflutil.wl.init) return EINA_TRUE;
283
284    _eflutil.wl.dpy = ecore_wl_display_get();
285    EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.dpy, EINA_FALSE);
286
287    reg = wl_display_get_registry(_eflutil.wl.dpy);
288    EINA_SAFETY_ON_NULL_RETURN_VAL(reg, EINA_FALSE);
289
290    wl_registry_add_listener(reg, &_wl_reg_listener, NULL);
291
292    _eflutil.wl.init = EINA_TRUE;
293
294    return EINA_TRUE;
295 }
296
297 static void
298 _cb_wl_reg_global(void *data,
299                   struct wl_registry *reg,
300                   unsigned int name,
301                   const char *interface,
302                   unsigned int version)
303 {
304    if (!strcmp(interface, "tizen_notification"))
305      {
306         struct tizen_notification *proto;
307         proto = wl_registry_bind(reg,
308                                  name,
309                                  &tizen_notification_interface,
310                                  1);
311         if (!proto) return;
312
313         tizen_notification_add_listener(proto,
314                                         &_wl_tz_noti_lv_listener,
315                                         NULL);
316
317         _eflutil.wl.noti_lv.hash = eina_hash_pointer_new(free);
318         _eflutil.wl.noti_lv.proto = proto;
319      }
320 }
321
322 static void
323 _cb_wl_reg_global_remove(void *data,
324                          struct wl_registry *reg,
325                          unsigned int name)
326 {
327    _eflutil.wl.noti_lv.proto = NULL;
328    eina_hash_free(_eflutil.wl.noti_lv.hash);
329 }
330
331 static Efl_Util_Callback_Info *
332 _cb_info_find_by_wlsurf(void *wlsurf,
333                         int idx)
334 {
335    Eina_List *l, *ll;
336    Efl_Util_Callback_Info *info;
337    Ecore_Wl_Window *wlwin2 = NULL;
338    void *wlsurf2 = NULL;
339
340    l = _cb_info_list_get(idx);
341    EINA_LIST_FOREACH(l, ll, info)
342      {
343         wlwin2 = elm_win_wl_window_get(info->win);
344         wlsurf2 = ecore_wl_window_surface_get(wlwin2);
345         if (wlsurf== wlsurf2) return info;
346      }
347
348    return NULL;
349 }
350
351 static void
352 _cb_wl_tz_noti_lv_done(void *data,
353                        struct tizen_notification *proto,
354                        struct wl_surface *surface,
355                        int32_t level,
356                        uint32_t state)
357 {
358    Efl_Util_Wl_Surface_Lv_Info *lv_info;
359    Efl_Util_Callback_Info *cb_info;
360
361    lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
362    if (lv_info)
363      {
364         lv_info->level = level;
365         lv_info->wait_for_done = EINA_FALSE;
366      }
367
368    if (state != TIZEN_NOTIFICATION_ERROR_STATE_PERMISSION_DENIED) return;
369
370    cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV);
371    if (!cb_info) return;
372    if (!cb_info->cb) return;
373
374    cb_info->cb(cb_info->win,
375                EFL_UTIL_ERROR_PERMISSION_DENIED,
376                cb_info->data);
377 }
378 #endif /* end of WAYLAND */
379
380 API int
381 efl_util_set_notification_window_level(Evas_Object *window,
382                                        efl_util_notification_level_e level)
383 {
384    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
385    EINA_SAFETY_ON_FALSE_RETURN_VAL((level >= EFL_UTIL_NOTIFICATION_LEVEL_1) &&
386                                    (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP),
387                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
388
389 #if X11
390    Ecore_X_Window xwin = elm_win_xwindow_get(window);
391    if (xwin)
392      {
393         Ecore_X_Window_Type window_type;
394         if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
395           {
396              // success to get window type
397              if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
398                {
399                   // given EFL window's type is not notification type.
400                   return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
401                }
402           }
403         else
404           return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
405
406         utilx_set_system_notification_level(ecore_x_display_get(), xwin, level);
407         return EFL_UTIL_ERROR_NONE;
408      }
409 #endif /* end of X11 */
410
411 #if WAYLAND
412    Elm_Win_Type type;
413    Ecore_Wl_Window *wlwin;
414    struct wl_surface *surface;
415    Efl_Util_Wl_Surface_Lv_Info *lv_info;
416
417    type = elm_win_type_get(window);
418    EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
419                                    EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
420
421    wlwin = elm_win_wl_window_get(window);
422    if (wlwin)
423      {
424         _wl_init();
425
426         while (!_eflutil.wl.noti_lv.proto)
427           wl_display_dispatch(_eflutil.wl.dpy);
428
429         surface = ecore_wl_window_surface_get(wlwin);
430         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
431                                        EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
432
433         lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
434         if (!lv_info)
435           {
436              lv_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Lv_Info));
437              EINA_SAFETY_ON_NULL_RETURN_VAL(lv_info, EFL_UTIL_ERROR_OUT_OF_MEMORY);
438
439              lv_info->surface = surface;
440              lv_info->level = (int)level;
441              lv_info->wait_for_done = EINA_TRUE;
442
443              eina_hash_add(_eflutil.wl.noti_lv.hash,
444                            &surface,
445                            lv_info);
446           }
447         else
448           {
449              lv_info->level = (int)level;
450              lv_info->wait_for_done = EINA_TRUE;
451           }
452
453         tizen_notification_set_level(_eflutil.wl.noti_lv.proto,
454                                      surface,
455                                      (int)level);
456
457         return EFL_UTIL_ERROR_NONE;
458      }
459 #endif /* end of WAYLAND */
460
461    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
462 }
463
464 API int
465 efl_util_get_notification_window_level(Evas_Object *window,
466                                        efl_util_notification_level_e *level)
467 {
468    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
469    EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER);
470
471 #if X11
472    Ecore_X_Window_Type window_type;
473    Utilx_Notification_Level utilx_level;
474    Ecore_X_Window xwin = elm_win_xwindow_get(window);
475    if (xwin)
476      {
477         if (ecore_x_netwm_window_type_get(xwin, &window_type) == EINA_TRUE)
478           {
479              // success to get window type
480              if (window_type != ECORE_X_WINDOW_TYPE_NOTIFICATION)
481                {
482                   // given EFL window's type is not notification type.
483                   return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
484                }
485
486              utilx_level = utilx_get_system_notification_level(ecore_x_display_get(), xwin);
487              if (utilx_level == UTILX_NOTIFICATION_LEVEL_LOW)
488                *level = EFL_UTIL_NOTIFICATION_LEVEL_1;
489              else if(utilx_level == UTILX_NOTIFICATION_LEVEL_NORMAL)
490                *level = EFL_UTIL_NOTIFICATION_LEVEL_2;
491              else if(utilx_level == UTILX_NOTIFICATION_LEVEL_HIGH)
492                *level = EFL_UTIL_NOTIFICATION_LEVEL_3;
493              else
494                return EFL_UTIL_ERROR_INVALID_PARAMETER;
495           }
496         else
497           return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
498
499         return EFL_UTIL_ERROR_NONE;
500      }
501 #endif /* end of X11 */
502
503 #if WAYLAND
504    Elm_Win_Type type;
505    Ecore_Wl_Window *wlwin;
506    struct wl_surface *surface;
507    Efl_Util_Wl_Surface_Lv_Info *lv_info;
508
509    type = elm_win_type_get(window);
510    EINA_SAFETY_ON_FALSE_RETURN_VAL((type == ELM_WIN_NOTIFICATION),
511                                    EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
512
513    wlwin = elm_win_wl_window_get(window);
514    if (wlwin)
515      {
516         _wl_init();
517
518         while (!_eflutil.wl.noti_lv.proto)
519           wl_display_dispatch(_eflutil.wl.dpy);
520
521         surface = ecore_wl_window_surface_get(wlwin);
522         EINA_SAFETY_ON_NULL_RETURN_VAL(surface,
523                                        EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE);
524
525         lv_info = eina_hash_find(_eflutil.wl.noti_lv.hash, &surface);
526         if (lv_info)
527           {
528              if (lv_info->wait_for_done)
529                {
530                   if (ecore_wl_window_shell_surface_get(wlwin) ||
531                       ecore_wl_window_xdg_surface_get(wlwin))
532                     {
533                        while (lv_info->wait_for_done)
534                          {
535                             ecore_wl_flush();
536                             wl_display_dispatch(_eflutil.wl.dpy);
537                          }
538                     }
539                   else
540                     {
541                        *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
542                        return EFL_UTIL_ERROR_INVALID_PARAMETER;
543                     }
544                }
545
546             switch (lv_info->level)
547               {
548                  case TIZEN_NOTIFICATION_LEVEL_1:       *level = EFL_UTIL_NOTIFICATION_LEVEL_1;       break;
549                  case TIZEN_NOTIFICATION_LEVEL_2:       *level = EFL_UTIL_NOTIFICATION_LEVEL_2;       break;
550                  case TIZEN_NOTIFICATION_LEVEL_3:       *level = EFL_UTIL_NOTIFICATION_LEVEL_3;       break;
551                  case TIZEN_NOTIFICATION_LEVEL_NONE:    *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE;    break;
552                  case TIZEN_NOTIFICATION_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break;
553                  case TIZEN_NOTIFICATION_LEVEL_MEDIUM:  *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM;  break;
554                  case TIZEN_NOTIFICATION_LEVEL_HIGH:    *level = EFL_UTIL_NOTIFICATION_LEVEL_HIGH;    break;
555                  case TIZEN_NOTIFICATION_LEVEL_TOP:     *level = EFL_UTIL_NOTIFICATION_LEVEL_TOP;     break;
556                  default:                               *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
557                    return EFL_UTIL_ERROR_INVALID_PARAMETER;
558               }
559             return EFL_UTIL_ERROR_NONE;
560           }
561         else
562           *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT;
563
564         return EFL_UTIL_ERROR_NONE;
565      }
566 #endif /* end of WAYLAND */
567    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
568 }
569
570 API int
571 efl_util_set_notification_window_level_error_cb(Evas_Object *window,
572                                                 efl_util_notification_window_level_error_cb callback,
573                                                 void *user_data)
574 {
575    Eina_Bool ret = EINA_FALSE;
576
577    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
578    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
579
580    ret = _cb_info_add(window,
581                       (Efl_Util_Cb)callback,
582                       user_data,
583                       CBH_NOTI_LEV);
584    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
585
586 #if X11
587    if (!_eflutil.atom.noti_lv)
588      _eflutil.atom.noti_lv = ecore_x_atom_get("_E_NOTIFICATION_LEVEL_ACCESS_RESULT");
589 #endif /* end of X11 */
590
591    return EFL_UTIL_ERROR_NONE;
592 }
593
594 API int
595 efl_util_unset_notification_window_level_error_cb(Evas_Object *window)
596 {
597    Eina_Bool ret = EINA_FALSE;
598
599    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
600
601    ret = _cb_info_del_by_win(window, CBH_NOTI_LEV);
602    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
603
604    return EFL_UTIL_ERROR_NONE;
605 }
606
607 API int
608 efl_util_set_window_opaque_state(Evas_Object *window,
609                                  int opaque)
610 {
611    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
612    EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)),
613                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
614
615 #if X11
616    Ecore_X_Window xwin = elm_win_xwindow_get(window);
617    Ecore_X_Display *xdpy = ecore_x_display_get();
618    Utilx_Opaque_State state;
619    int ret;
620
621    EINA_SAFETY_ON_NULL_RETURN_VAL(xwin, EFL_UTIL_ERROR_INVALID_PARAMETER);
622    EINA_SAFETY_ON_NULL_RETURN_VAL(xdpy, EFL_UTIL_ERROR_INVALID_PARAMETER);
623
624    if (opaque)
625      state = UTILX_OPAQUE_STATE_ON;
626    else
627      state = UTILX_OPAQUE_STATE_OFF;
628
629    ret = utilx_set_window_opaque_state(xdpy, xwin, state);
630
631    if (!ret)
632      return EFL_UTIL_ERROR_INVALID_PARAMETER;
633    else
634      return EFL_UTIL_ERROR_NONE;
635 #endif /* end of X11 */
636
637 #if WAYLAND
638    Ecore_Wl_Window *wlwin;
639    int x, y, w, h;
640
641    wlwin = elm_win_wl_window_get(window);
642    if (wlwin)
643      {
644         _wl_init();
645
646         evas_object_geometry_get(window, &x, &y, &w, &h);
647
648         if (opaque)
649           ecore_wl_window_opaque_region_set(wlwin, x, y, w, h);
650         else
651           ecore_wl_window_opaque_region_set(wlwin, 0, 0, 0, 0);
652
653         return EFL_UTIL_ERROR_NONE;
654      }
655
656    return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE;
657 #endif /* end of WAYLAND */
658 }
659
660 API int
661 efl_util_set_window_screen_mode(Evas_Object *window,
662                                 efl_util_screen_mode_e mode)
663 {
664    Evas *e;
665    Ecore_Evas *ee;
666    int id;
667
668    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
669    EINA_SAFETY_ON_FALSE_RETURN_VAL(((mode >= EFL_UTIL_SCREEN_MODE_DEFAULT) &&
670                                     (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)),
671                                    EFL_UTIL_ERROR_INVALID_PARAMETER);
672
673    e = evas_object_evas_get(window);
674    EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
675
676    ee = ecore_evas_ecore_evas_get(e);
677    EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
678
679    id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
680    if (mode == EFL_UTIL_SCREEN_MODE_ALWAYS_ON)
681      {
682         if (id == -1)
683           ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "1");
684         else
685           ecore_evas_aux_hint_val_set(ee, id, "1");
686      }
687    else if (mode == EFL_UTIL_SCREEN_MODE_DEFAULT)
688      {
689         if (id == -1)
690           ecore_evas_aux_hint_add(ee, "wm.policy.win.lcd.lock", "0");
691         else
692           ecore_evas_aux_hint_val_set(ee, id, "0");
693      }
694    else
695      return EFL_UTIL_ERROR_INVALID_PARAMETER;
696
697    return EFL_UTIL_ERROR_NONE;
698 }
699
700 API int
701 efl_util_get_window_screen_mode(Evas_Object *window,
702                                 efl_util_screen_mode_e *mode)
703 {
704    Evas *e;
705    Ecore_Evas *ee;
706    const char *str;
707    int id;
708
709    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
710    EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER);
711
712    e = evas_object_evas_get(window);
713    EINA_SAFETY_ON_NULL_RETURN_VAL(e, EFL_UTIL_ERROR_INVALID_PARAMETER);
714
715    ee = ecore_evas_ecore_evas_get(e);
716    EINA_SAFETY_ON_NULL_RETURN_VAL(ee, EFL_UTIL_ERROR_INVALID_PARAMETER);
717
718    id = ecore_evas_aux_hint_id_get(ee, "wm.policy.win.lcd.lock");
719    EINA_SAFETY_ON_TRUE_RETURN_VAL((id == -1), EFL_UTIL_ERROR_INVALID_PARAMETER);
720
721    str = ecore_evas_aux_hint_val_get(ee, id);
722    EINA_SAFETY_ON_NULL_RETURN_VAL(str, EFL_UTIL_ERROR_INVALID_PARAMETER);
723
724    if (strncmp(str, "1", strlen("1")) == 0)
725      *mode = EFL_UTIL_SCREEN_MODE_ALWAYS_ON;
726    else
727      *mode = EFL_UTIL_SCREEN_MODE_DEFAULT;
728
729    return EFL_UTIL_ERROR_NONE;
730 }
731
732 API int
733 efl_util_set_window_screen_mode_error_cb(Evas_Object *window,
734                                          efl_util_window_screen_mode_error_cb callback,
735                                          void *user_data)
736 {
737    Eina_Bool ret = EINA_FALSE;
738
739    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
740    EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER);
741
742    ret = _cb_info_add(window,
743                       (Efl_Util_Cb)callback,
744                       user_data,
745                       CBH_SCR_MODE);
746    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
747
748 #if X11
749    if (!_eflutil.atom.scr_mode)
750      _eflutil.atom.scr_mode = ecore_x_atom_get("_E_SCREEN_MODE_ACCESS_RESULT");
751 #endif /* end of X11 */
752
753    return EFL_UTIL_ERROR_NONE;
754 }
755
756 API int
757 efl_util_unset_window_screen_mode_error_cb(Evas_Object *window)
758 {
759    Eina_Bool ret = EINA_FALSE;
760
761    EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER);
762
763    ret = _cb_info_del_by_win(window, CBH_SCR_MODE);
764    if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY;
765
766    return EFL_UTIL_ERROR_NONE;
767 }
768
769 API int
770 efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type)
771 {
772    return EFL_UTIL_ERROR_NONE;
773 }
774
775 API void
776 efl_util_input_deinitialize_generator(void)
777 {
778    return;
779 }
780
781 API int
782 efl_util_input_generate_key(const char *key_name,
783                             int pressed)
784 {
785    return EFL_UTIL_ERROR_NONE;
786 }
787
788 API int
789 efl_util_input_generate_touch(int idx,
790                               efl_util_input_touch_type_e touch_type,
791                               int x,
792                               int y)
793 {
794    return EFL_UTIL_ERROR_NONE;
795 }
796
797 API efl_util_screenshot_h
798 efl_util_screenshot_initialize(int width,
799                                int height)
800 {
801    return 0;
802 }
803
804 API tbm_surface_h
805 efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot)
806 {
807    return 0;
808 }
809
810 API int
811 efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot)
812 {
813    return EFL_UTIL_ERROR_NONE;
814 }