e_service_taskbar: support auto_placement request
[platform/upstream/enlightenment.git] / src / bin / e_policy_wl.c
1 #include "e_policy_wl.h"
2 #include "e.h"
3 #include "services/e_service_quickpanel.h"
4 #include "services/e_service_volume.h"
5 #include "services/e_service_lockscreen.h"
6 #include "services/e_service_indicator.h"
7 #include "services/e_service_cbhm.h"
8 #include "services/e_service_scrsaver.h"
9 #include "services/e_service_softkey.h"
10 #include "services/e_service_launcher.h"
11 #include "services/e_service_taskbar.h"
12 #include "services/e_service_kvm.h"
13 #include "e_policy_wl_display.h"
14 #include "e_policy_conformant_internal.h"
15 #include "e_policy_visibility.h"
16 #include "e_appinfo.h"
17
18 #include <device/display.h>
19 #include <wayland-server.h>
20 #include <tizen-extension-server-protocol.h>
21 #include <tizen-launch-server-protocol.h>
22 #include <tzsh_server.h>
23
24 typedef enum _Tzsh_Srv_Role
25 {
26    TZSH_SRV_ROLE_UNKNOWN = -1,
27    TZSH_SRV_ROLE_VOLUME,
28    TZSH_SRV_ROLE_QUICKPANEL_SYSTEM_DEFAULT,
29    TZSH_SRV_ROLE_QUICKPANEL_CONTEXT_MENU,
30    TZSH_SRV_ROLE_QUICKPANEL_APPS_MENU,
31    TZSH_SRV_ROLE_LOCKSCREEN,
32    TZSH_SRV_ROLE_INDICATOR,
33    TZSH_SRV_ROLE_SCREENSAVER_MNG,
34    TZSH_SRV_ROLE_SCREENSAVER,
35    TZSH_SRV_ROLE_CBHM,
36    TZSH_SRV_ROLE_SOFTKEY,
37    TZSH_SRV_ROLE_MAGNIFIER,
38    TZSH_SRV_ROLE_LAUNCHER,
39    TZSH_SRV_ROLE_TASKBAR,
40    TZSH_SRV_ROLE_KVM,
41    TZSH_SRV_ROLE_MAX
42 } Tzsh_Srv_Role;
43
44 typedef enum _Tzsh_Client_Handle_Type
45 {
46    TZSH_CLIENT_HANDLE_TYPE_NONE = 0,
47    TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL = 1,
48    TZSH_CLIENT_HANDLE_TYPE_SHARED_WIDGET_LAUNCH = 2,
49    TZSH_CLIENT_HANDLE_TYPE_SOFTKEY = 3,
50 } Tzsh_Client_Handle_Type;
51
52 typedef enum _Tzsh_Type
53 {
54    TZSH_TYPE_UNKNOWN = 0,
55    TZSH_TYPE_SRV,
56    TZSH_TYPE_CLIENT
57 } Tzsh_Type;
58
59 typedef enum _Tzlaunch_Effect_Type
60 {
61    TZLAUNCH_EFFECT_TYPE_LAUNCH = 0,
62    TZLAUNCH_EFFECT_TYPE_DEPTH_IN
63 } Tzlaunch_Effect_Type;
64
65 typedef struct _E_Policy_Wl_Tzpol
66 {
67    struct wl_resource *res_tzpol; /* tizen_policy_interface */
68    Eina_List          *psurfs;    /* list of E_Policy_Wl_Surface */
69    pid_t               pid;
70    Eina_Bool           bg_state;
71 } E_Policy_Wl_Tzpol;
72
73 typedef struct _E_Policy_Wl_Tz_Dpy_Pol
74 {
75    struct wl_resource *res_tz_dpy_pol;
76    Eina_List          *dpy_surfs;  // list of E_Policy_Wl_Dpy_Surface
77 } E_Policy_Wl_Tz_Dpy_Pol;
78
79 typedef struct _E_Policy_Wl_Tzsh
80 {
81    struct wl_resource *res_tzsh; /* tizen_ws_shell_interface */
82    Eina_List *service_list;
83    Eina_List *client_list;
84 } E_Policy_Wl_Tzsh;
85
86 typedef struct _E_Policy_Wl_Tzsh_Srv
87 {
88    E_Policy_Wl_Tzsh        *tzsh;
89    struct wl_resource *res_tzsh_srv;
90    Tzsh_Srv_Role       role;
91    const char         *name;
92    E_Pixmap *ep;
93    E_Client *ec;
94    E_Zone *zone;
95    Eina_List *events;
96 } E_Policy_Wl_Tzsh_Srv;
97
98 typedef struct _E_Policy_Wl_Tzsh_Client
99 {
100    E_Policy_Wl_Tzsh        *tzsh;
101    struct wl_resource *res_tzsh_client;
102    Tzsh_Client_Handle_Type handle_type;
103    E_Pixmap *ep;
104    E_Client *ec;
105    E_Zone *zone;
106    void *client_data;
107    Eina_List *events;
108 } E_Policy_Wl_Tzsh_Client;
109
110 typedef struct _E_Policy_Wl_Tzsh_Client_Data_Quickpanel
111 {
112    E_Quickpanel_Type type;
113 } E_Policy_Wl_Tzsh_Client_Data_Quickpanel;
114
115 typedef struct _E_Policy_Wl_Tzsh_Client_Data_Softkey
116 {
117    int show_state;
118 } E_Policy_Wl_Tzsh_Client_Data_Softkey;
119
120 typedef struct _E_Policy_Wl_Tzsh_Region
121 {
122    E_Policy_Wl_Tzsh        *tzsh;
123    struct wl_resource *res_tzsh_reg;
124    Eina_Tiler         *tiler;
125    struct wl_listener  destroy_listener;
126 } E_Policy_Wl_Tzsh_Region;
127
128 typedef struct _E_Policy_Wl_Tzsh_Extension
129 {
130    char                    *name;
131    E_Policy_Wl_Tzsh_Ext_Hook_Cb cb;
132 } E_Policy_Wl_Tzsh_Extension;
133
134 typedef struct _E_Policy_Wl_Surface
135 {
136    struct wl_resource *surf;
137    E_Policy_Wl_Tzpol       *tzpol;
138    E_Pixmap           *cp;
139    E_Client           *ec;
140    pid_t               pid;
141    Eina_Bool           pending_notilv;
142    int32_t             notilv;
143    Eina_List          *vislist; /* list of tizen_visibility_interface resources */
144    Eina_List          *poslist; /* list of tizen_position_inteface resources */
145    Eina_Bool           is_background;
146 } E_Policy_Wl_Surface;
147
148 typedef struct _E_Policy_Wl_Dpy_Surface
149 {
150    E_Policy_Wl_Tz_Dpy_Pol  *tz_dpy_pol;
151    struct wl_resource *surf;
152    E_Client           *ec;
153    Eina_Bool           set;
154    int32_t             brightness;
155 } E_Policy_Wl_Dpy_Surface;
156
157 typedef struct _E_Policy_Wl_Tzlaunch_Effect
158 {
159    struct wl_resource *res_tzlaunch_effect;  /* tizen_launch_effect */
160    Eina_List          *splash_list;            /* list of E_Policy_Wl_Tzlaunch_Splash */
161 } E_Policy_Wl_Tzlaunch_Effect;
162
163 typedef struct _E_Policy_Wl_Tzlaunch_Splash
164 {
165    struct wl_resource        *res_tzlaunch_splash; /* tizen_launch_image */
166    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;         /* launcher */
167
168    const char                *path;             /* image resource path */
169    uint32_t                   type;             /* 0: image, 1: edc */
170    uint32_t                   indicator;        /* 0: off, 1: on */
171    uint32_t                   angle;            /* 0, 90, 180, 270 : rotation angle */
172    uint32_t                   pid;
173
174    Evas_Object               *obj;              /* launch screen image */
175    E_Pixmap                  *ep;               /* pixmap for launch screen client */
176    E_Client                  *ec;               /* client for launch screen image */
177    Ecore_Timer               *timeout;          /* launch screen image hide timer */
178    Evas_Object               *indicator_obj;    /* plug object of indicator */
179
180    Eina_Bool                  valid;            /* validation check */
181    Eina_Bool                  replaced;
182    E_Comp_Object_Content_Type content_type;     /* type of content */
183
184    Eina_Bool                  custom_effect_callee; /* custom effect enabled */
185    const char                *appid;
186 } E_Policy_Wl_Tzlaunch_Splash;
187
188 typedef struct _E_Policy_Wl_Tzlaunch_Effect_Info
189 {
190    uint32_t                   pid;              /* pid */
191    int                        effect_type;       /* effect_type */
192 } E_Policy_Wl_Tzlaunch_Effect_Info;
193
194 typedef struct _E_Policy_Wl_Tzlaunch_Appinfo
195 {
196    struct wl_resource        *res_tzlaunch_appinfo; /* tizen_launch_appinfo */
197 } E_Policy_Wl_Tzlaunch_Appinfo;
198
199 typedef enum _Launch_Img_File_type
200 {
201    LAUNCH_IMG_FILE_TYPE_ERROR = -1,
202    LAUNCH_IMG_FILE_TYPE_IMAGE = 0,
203    LAUNCH_IMG_FILE_TYPE_EDJ
204 } Launch_Img_File_type;
205
206 typedef struct _E_Policy_Wl_Tz_Indicator
207 {
208    struct wl_resource *res_tz_indicator;
209    Eina_List          *ec_list;
210 } E_Policy_Wl_Tz_Indicator;
211
212 typedef struct _E_Policy_Wl_Tz_Clipboard
213 {
214    struct wl_resource *res_tz_clipboard;
215    Eina_List *ec_list;
216 } E_Policy_Wl_Tz_Clipboard;
217
218 typedef struct _E_Policy_Wl
219 {
220    Eina_List       *globals;                 /* list of wl_global */
221    Eina_Hash       *tzpols;                  /* list of E_Policy_Wl_Tzpol */
222
223    Eina_List       *tz_dpy_pols;             /* list of E_Policy_Wl_Tz_Dpy_Pol */
224    Eina_List       *pending_vis;             /* list of clients that have pending visibility change*/
225
226    /* tizen_ws_shell_interface */
227    Eina_List       *tzshs;                   /* list of E_Policy_Wl_Tzsh */
228    Eina_List       *tzsh_srvs;               /* list of E_Policy_Wl_Tzsh_Srv */
229    Eina_List       *tzsh_clients;            /* list of E_Policy_Wl_Tzsh_Client */
230    E_Policy_Wl_Tzsh_Srv *srvs[TZSH_SRV_ROLE_MAX]; /* list of registered E_Policy_Wl_Tzsh_Srv */
231    Eina_List       *tz_indicators;
232    Eina_List       *tz_clipboards;           /* list of E_Policy_Wl_Tz_Clipboard */
233
234    /* tizen_launch_effect_interface */
235    Eina_List       *tzlaunch_effect;        /* list of E_Policy_Wl_Tzlaunch_Effect */
236    Eina_List       *tzlaunch_effect_info;  /* list of E_Policy_Wl_Tzlaunch_Effect_Info */
237    /* tizen_launch_appinfo_interface */
238    Eina_List       *tzlaunch_appinfo;       /* list of E_Policy_Wl_Tzlaunch_Appinfo */
239    /* tizen_ws_shell_interface ver_2 */
240    Eina_List       *tzsh_extensions;           /* list of E_Policy_Wl_Tzsh_Extension */
241 } E_Policy_Wl;
242
243 typedef struct _E_Tzsh_QP_Event
244 {
245    int type;
246    int val;
247 } E_Tzsh_QP_Event;
248
249 static E_Policy_Wl *polwl = NULL;
250
251 static Eina_List *handlers = NULL;
252 static Eina_List *polwl_hooks_ec = NULL;
253 static Eina_List *hooks_cw = NULL;
254 static Eina_List *hooks_co = NULL;
255 static struct wl_resource *_scrsaver_mng_res = NULL; // TODO
256 static struct wl_resource *_indicator_srv_res = NULL;
257
258 static int _e_policy_wl_hooks_delete = 0;
259 static int _e_policy_wl_hooks_walking = 0;
260
261 static Eina_Inlist *_e_policy_wl_hooks[] =
262 {
263    [E_POLICY_WL_HOOK_BASE_OUTPUT_RESOLUTION_GET] = NULL,
264 };
265
266 EINTERN int E_EVENT_POLICY_INDICATOR_STATE_CHANGE = -1;
267 EINTERN int E_EVENT_POLICY_INDICATOR_OPACITY_MODE_CHANGE = -1;
268 EINTERN int E_EVENT_POLICY_INDICATOR_VISIBLE_STATE_CHANGE = -1;
269
270 enum _E_Policy_Hint_Type
271 {
272    E_POLICY_HINT_USER_GEOMETRY = 0,
273    E_POLICY_HINT_FIXED_RESIZE = 1,
274    E_POLICY_HINT_DEICONIFY_UPDATE = 2,
275    E_POLICY_HINT_ICONIFY = 3,
276    E_POLICY_HINT_ABOVE_LOCKSCREEN = 4,
277    E_POLICY_HINT_GESTURE_DISABLE = 5,
278    E_POLICY_HINT_EFFECT_DISABLE = 6,
279    E_POLICY_HINT_MSG_USE = 7,
280    E_COMP_HINT_ALWAYS_SELECTIVE = 8,
281    E_POLICY_HINT_DEPENDENT_ROTATION = 9,
282    E_POLICY_HINT_ROT_RENDER_NOPENDING = 10,
283    E_POLICY_HINT_ICONIFY_BUFFER_FLUSH = 11,
284    E_POLICY_HINT_TRANSIENT_FOR_ALWAYS_ON_TOP = 12,
285    E_POLICY_HINT_BELONG_TO_PARENT = 13,
286    E_POLICY_HINT_RESIZE_ASPECT_RATIO = 14,
287    E_POLICY_HINT_DECORATION_SIZE_HEADER = 15,
288    E_POLICY_HINT_DECORATION_SIZE_FOOTER = 16,
289    E_POLICY_HINT_VISIBILITY_IGNORE_GEOMETRY= 17,
290    E_POLICY_HINT_RESIZE_PPU = 18,
291    E_POLICY_HINT_DECORATION_SIZE_SHADOW_TOP = 19,
292    E_POLICY_HINT_DECORATION_SIZE_SHADOW_BOTTOM = 20,
293    E_POLICY_HINT_DECORATION_SIZE_SHADOW_LEFT = 21,
294    E_POLICY_HINT_DECORATION_SIZE_SHADOW_RIGHT = 22,
295 };
296
297 static const char *hint_names[] =
298 {
299    "wm.policy.win.user.geometry",
300    "wm.policy.win.fixed.resize",
301    "wm.policy.win.deiconify.update",
302    "wm.policy.win.iconify",
303    "wm.policy.win.above.lock",
304    "wm.policy.win.gesture.disable",
305    "wm.policy.win.effect.disable",
306    "wm.policy.win.msg.use",
307    "wm.comp.win.always.selective.mode",
308    "wm.policy.win.rot.dependent",
309    "wm.policy.win.rot.render.nopending",
310    "wm.policy.win.iconify.buffer.flush",
311    "wm.policy.win.transient_for.always_on_top",
312    "wm.policy.win.belong_to_parent",
313    "wm.policy.win.resize_aspect_ratio",
314    "wm.policy.win.decoration.size.header",
315    "wm.policy.win.decoration.size.footer",
316    "wm.policy.win.visibility.ignore_geometry",
317    "wm.policy.win.resize.ppu",
318    "wm.policy.win.decoration.size.shadow.top",
319    "wm.policy.win.decoration.size.shadow.bottom",
320    "wm.policy.win.decoration.size.shadow.left",
321    "wm.policy.win.decoration.size.shadow.right",
322 };
323
324 static void                _e_policy_wl_surf_del(E_Policy_Wl_Surface *psurf);
325 static void                _e_policy_wl_tzsh_srv_state_broadcast(E_Policy_Wl_Tzsh_Srv *tzsh_srv, Eina_Bool reg);
326 static Eina_Bool           _e_policy_wl_e_client_is_valid(E_Client *ec);
327 static E_Policy_Wl_Tzsh_Srv    *_e_policy_wl_tzsh_srv_add(E_Policy_Wl_Tzsh *tzsh, Tzsh_Srv_Role role, struct wl_resource *res_tzsh_srv, const char *name, E_Pixmap *ep, E_Client *ec);
328 static void                _e_policy_wl_tzsh_srv_del(E_Policy_Wl_Tzsh_Srv *tzsh_srv);
329 static E_Policy_Wl_Tzsh_Client *_e_policy_wl_tzsh_client_add(E_Policy_Wl_Tzsh *tzsh, struct wl_resource *res_tzsh_client, E_Pixmap *ep, E_Client *ec);
330 static void                _e_policy_wl_tzsh_client_del(E_Policy_Wl_Tzsh_Client *tzsh_client);
331 static void                _e_policy_wl_background_state_set(E_Policy_Wl_Surface *psurf, Eina_Bool state);
332
333 static void                _e_policy_wl_tzlaunch_effect_type_sync(E_Client *ec);
334 static int                 _e_policy_wl_tzlaunch_effect_type_get(const char* effect_type);
335 static void                _e_policy_wl_tzlaunch_effect_type_unset(uint32_t pid);
336
337 static void                _launch_effect_hide(uint32_t pid);
338 static void                _launch_effect_client_del(E_Client *ec);
339 static void                _launch_splash_off(E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash);
340
341 // --------------------------------------------------------
342 // E_Policy_Wl_Hook
343 // --------------------------------------------------------
344
345 static void
346 _e_policy_wl_hooks_clean()
347 {
348    E_Policy_Wl_Hook *epwh = NULL;
349    Eina_Inlist *l = NULL;
350    unsigned int x;
351
352    for (x = 0; x < E_POLICY_WL_HOOK_LAST; x++)
353      {
354         EINA_INLIST_FOREACH_SAFE(_e_policy_wl_hooks[x], l, epwh)
355           {
356              if (!epwh->delete_me) continue;
357              _e_policy_wl_hooks[x] = eina_inlist_remove(_e_policy_wl_hooks[x], EINA_INLIST_GET(epwh));
358              free(epwh);
359           }
360      }
361 }
362
363 static void
364 _e_policy_wl_hook_call(E_Policy_Wl_Hook_Point hookpoint, pid_t pid)
365 {
366    E_Policy_Wl_Hook *epwh = NULL;
367
368    _e_policy_wl_hooks_walking++;
369    EINA_INLIST_FOREACH(_e_policy_wl_hooks[hookpoint], epwh)
370      {
371         if (epwh->delete_me) continue;
372         epwh->func(epwh->data, pid);
373      }
374    _e_policy_wl_hooks_walking--;
375
376    if ((_e_policy_wl_hooks_walking == 0) && (_e_policy_wl_hooks_delete > 0))
377      _e_policy_wl_hooks_clean();
378 }
379
380 E_API E_Policy_Wl_Hook *
381 e_policy_wl_hook_add(E_Policy_Wl_Hook_Point hookpoint, E_Policy_Wl_Hook_Cb func, const void *data)
382 {
383    E_Policy_Wl_Hook *epwh = NULL;
384
385    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint < 0, NULL);
386    EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_POLICY_WL_HOOK_LAST, NULL);
387
388    epwh = E_NEW(E_Policy_Wl_Hook, 1);
389    EINA_SAFETY_ON_NULL_RETURN_VAL(epwh, NULL);
390
391    epwh->hookpoint = hookpoint;
392    epwh->func = func;
393    epwh->data = (void *)data;
394    _e_policy_wl_hooks[hookpoint] = eina_inlist_append(_e_policy_wl_hooks[hookpoint], EINA_INLIST_GET(epwh));
395
396    return epwh;
397 }
398
399 E_API void
400 e_policy_wl_hook_del(E_Policy_Wl_Hook *epwh)
401 {
402    epwh->delete_me = 1;
403    if (_e_policy_wl_hooks_walking == 0)
404      {
405         _e_policy_wl_hooks[epwh->hookpoint] = eina_inlist_remove(_e_policy_wl_hooks[epwh->hookpoint], EINA_INLIST_GET(epwh));
406         free(epwh);
407      }
408    else
409      _e_policy_wl_hooks_delete++;
410 }
411
412 // --------------------------------------------------------
413 // E_Policy_Wl_Tzpol
414 // --------------------------------------------------------
415 static Eina_Bool
416 _e_policy_wl_tzpol_background_state_check(pid_t pid)
417 {
418    E_Policy_Wl_Tzpol *tzpol;
419    Eina_Iterator *it;
420    Eina_Bool bg_state = EINA_FALSE;
421
422    if (pid <= 0)
423      return EINA_FALSE;
424
425    it = eina_hash_iterator_data_new(polwl->tzpols);
426    EINA_ITERATOR_FOREACH(it, tzpol)
427      {
428         if (tzpol->pid == pid)
429           {
430              if (tzpol->bg_state)
431                {
432                   bg_state = EINA_TRUE;
433                   break;
434                }
435           }
436      }
437    eina_iterator_free(it);
438
439    return bg_state;
440 }
441
442 static E_Policy_Wl_Tzpol *
443 _e_policy_wl_tzpol_add(struct wl_client *client, struct wl_resource *res_tzpol)
444 {
445    E_Policy_Wl_Tzpol *tzpol;
446    pid_t pid = 0;
447
448    tzpol = E_NEW(E_Policy_Wl_Tzpol, 1);
449    EINA_SAFETY_ON_NULL_RETURN_VAL(tzpol, NULL);
450
451    eina_hash_add(polwl->tzpols, &res_tzpol, tzpol);
452
453    tzpol->res_tzpol = res_tzpol;
454
455    wl_client_get_credentials(client, &pid, NULL, NULL);
456    tzpol->pid = pid;
457
458    tzpol->bg_state = _e_policy_wl_tzpol_background_state_check(pid);
459
460    return tzpol;
461 }
462
463 static void
464 _e_policy_wl_tzpol_del(void *data)
465 {
466    E_Policy_Wl_Tzpol *tzpol;
467    E_Policy_Wl_Surface *psurf;
468
469    tzpol = (E_Policy_Wl_Tzpol *)data;
470
471    EINA_LIST_FREE(tzpol->psurfs, psurf)
472      {
473         _e_policy_wl_surf_del(psurf);
474      }
475
476    memset(tzpol, 0x0, sizeof(E_Policy_Wl_Tzpol));
477    E_FREE(tzpol);
478 }
479
480 static E_Policy_Wl_Tzpol *
481 _e_policy_wl_tzpol_get(struct wl_resource *res_tzpol)
482 {
483    return (E_Policy_Wl_Tzpol *)eina_hash_find(polwl->tzpols, &res_tzpol);
484 }
485
486 static E_Policy_Wl_Surface *
487 _e_policy_wl_tzpol_surf_find(E_Policy_Wl_Tzpol *tzpol, E_Client *ec)
488 {
489    Eina_List *l;
490    E_Policy_Wl_Surface *psurf;
491
492    EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
493      {
494         if (psurf->ec == ec)
495           return psurf;
496      }
497
498    return NULL;
499 }
500
501 static Eina_Bool
502 _e_policy_wl_surf_is_valid(E_Policy_Wl_Surface *psurf)
503 {
504    E_Policy_Wl_Tzpol *tzpol;
505    E_Policy_Wl_Surface *psurf2;
506    Eina_Iterator *it;
507    Eina_List *l;
508
509    it = eina_hash_iterator_data_new(polwl->tzpols);
510    EINA_ITERATOR_FOREACH(it, tzpol)
511      EINA_LIST_FOREACH(tzpol->psurfs, l, psurf2)
512        {
513           if (psurf2 == psurf)
514             {
515                eina_iterator_free(it);
516                return EINA_TRUE;
517             }
518        }
519    eina_iterator_free(it);
520
521    return EINA_FALSE;
522 }
523
524 // --------------------------------------------------------
525 // E_Policy_Wl_Tzsh
526 // --------------------------------------------------------
527 #ifdef TZSH_DEBUG
528 static void
529 _print_tzsh_service_info(void)
530 {
531    E_Policy_Wl_Tzsh_Srv *tzsh_srv = NULL;
532    Eina_List *l = NULL;
533    int i = 0;
534
535    ELOGF("TZSH", "================ TZSH SERVICE LIST ================", NULL);
536    EINA_LIST_FOREACH(polwl->tzsh_srvs, l, tzsh_srv)
537      {
538         ELOGF("TZSH", "[%d] tzsh_service(%p). tzsh:%p, role:%d, name:%s", tzsh_srv->ec, i, tzsh_srv, tzsh_srv->tzsh, tzsh_srv->role, tzsh_srv->name);
539         i++;
540      }
541    ELOGF("TZSH", "---------------------------------------------------", NULL);
542 }
543
544 static void
545 _print_tzsh_client_info(void)
546 {
547    E_Policy_Wl_Tzsh_Client *tzsh_client = NULL;
548    Eina_List *l = NULL;
549    int i = 0;
550
551    ELOGF("TZSH", "================ TZSH CLIENT LIST  ================", NULL);
552    EINA_LIST_FOREACH(polwl->tzsh_clients, l, tzsh_client)
553      {
554         ELOGF("TZSH", "[%d] tzsh_client(%p). tzsh:%p", tzsh_client->ec, i, tzsh_client, tzsh_client->tzsh);
555         i++;
556      }
557    ELOGF("TZSH", "---------------------------------------------------", NULL);
558 }
559 #endif
560
561 static E_Policy_Wl_Tzsh *
562 _e_policy_wl_tzsh_add(struct wl_resource *res_tzsh)
563 {
564    E_Policy_Wl_Tzsh *tzsh;
565
566    tzsh = E_NEW(E_Policy_Wl_Tzsh, 1);
567    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh, NULL);
568
569    tzsh->res_tzsh = res_tzsh;
570
571    polwl->tzshs = eina_list_append(polwl->tzshs, tzsh);
572
573 #ifdef TZSH_DEBUG
574    _print_tzsh_service_info();
575    _print_tzsh_client_info();
576 #endif
577
578    return tzsh;
579 }
580
581 static void
582 _e_policy_wl_tzsh_del(E_Policy_Wl_Tzsh *tzsh)
583 {
584    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
585    E_Policy_Wl_Tzsh_Client *tzsh_client;
586    Eina_List *l, *ll;
587
588    polwl->tzshs = eina_list_remove(polwl->tzshs, tzsh);
589
590    if (tzsh->service_list)
591      {
592         EINA_LIST_FREE(tzsh->service_list, tzsh_srv)
593           {
594              EINA_LIST_FOREACH_SAFE(polwl->tzsh_srvs, l, ll, tzsh_srv)
595                {
596                   if (tzsh_srv->tzsh != tzsh) continue;
597                   _e_policy_wl_tzsh_srv_del(tzsh_srv);
598                   break;
599                }
600           }
601         tzsh->service_list = NULL;
602      }
603
604    if (tzsh->client_list)
605      {
606         EINA_LIST_FREE(tzsh->client_list, tzsh_client)
607           {
608              EINA_LIST_FOREACH_SAFE(polwl->tzsh_clients, l, ll, tzsh_client)
609                {
610                   if (tzsh_client->tzsh != tzsh) continue;
611                   _e_policy_wl_tzsh_client_del(tzsh_client);
612                   break;
613                }
614           }
615      }
616
617 #ifdef TZSH_DEBUG
618    _print_tzsh_service_info();
619    _print_tzsh_client_info();
620 #endif
621
622    memset(tzsh, 0x0, sizeof(E_Policy_Wl_Tzsh));
623    E_FREE(tzsh);
624 }
625
626 /* notify current registered services to the client */
627 static void
628 _e_policy_wl_tzsh_registered_srv_send(E_Policy_Wl_Tzsh *tzsh)
629 {
630    int i;
631
632    for (i = 0; i < TZSH_SRV_ROLE_MAX; i++)
633      {
634         if (!polwl->srvs[i]) continue;
635
636         tizen_ws_shell_send_service_register
637           (tzsh->res_tzsh, polwl->srvs[i]->name);
638      }
639 }
640
641 static Eina_Bool
642 _e_policy_wl_tzsh_srv_cb_client_zone_set(void *data, int type EINA_UNUSED, void *event)
643 {
644    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
645    E_Event_Client_Zone_Set *ev;
646
647    tzsh_srv = data;
648    ev = event;
649
650    if (tzsh_srv->ec != ev->ec)
651      goto end;
652
653    if (tzsh_srv->zone == ev->zone)
654      goto end;
655
656    ELOGF("TZSH", "Change Zone | e_policy_wl_tzsh_srv %p old(%p) new(%p)",
657          tzsh_srv->ec, tzsh_srv, tzsh_srv->zone, ev->zone);
658
659    tzsh_srv->zone = ev->zone;
660
661 end:
662    return ECORE_CALLBACK_PASS_ON;
663 }
664
665 // --------------------------------------------------------
666 // E_Policy_Wl_Tzsh_Srv
667 // --------------------------------------------------------
668 static E_Policy_Wl_Tzsh_Srv *
669 _e_policy_wl_tzsh_srv_add(E_Policy_Wl_Tzsh *tzsh, Tzsh_Srv_Role role, struct wl_resource *res_tzsh_srv, const char *name, E_Pixmap *ep, E_Client *ec)
670 {
671    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
672
673    tzsh_srv = E_NEW(E_Policy_Wl_Tzsh_Srv, 1);
674    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_srv, NULL);
675
676    tzsh_srv->tzsh = tzsh;
677    tzsh_srv->res_tzsh_srv = res_tzsh_srv;
678    tzsh_srv->role = role;
679    tzsh_srv->name = eina_stringshare_add(name);
680    tzsh_srv->ep = ep;
681    tzsh_srv->ec = ec;
682    tzsh_srv->zone = e_comp_zone_find_by_ec(ec);
683    e_object_ref(E_OBJECT(ec));
684    tzsh_srv->tzsh->service_list = eina_list_append(tzsh_srv->tzsh->service_list, tzsh_srv);
685
686    polwl->srvs[role] = tzsh_srv;
687    polwl->tzsh_srvs = eina_list_append(polwl->tzsh_srvs, tzsh_srv);
688
689 #ifdef TZSH_DEBUG
690    _print_tzsh_service_info();
691 #endif
692
693    _e_policy_wl_tzsh_srv_state_broadcast(tzsh_srv, EINA_TRUE);
694
695    E_LIST_HANDLER_APPEND(tzsh_srv->events, E_EVENT_CLIENT_ZONE_SET, _e_policy_wl_tzsh_srv_cb_client_zone_set, tzsh_srv);
696
697    return tzsh_srv;
698 }
699
700 static void
701 _e_policy_wl_tzsh_srv_del(E_Policy_Wl_Tzsh_Srv *tzsh_srv)
702 {
703    E_FREE_LIST(tzsh_srv->events, ecore_event_handler_del);
704
705    polwl->tzsh_srvs = eina_list_remove(polwl->tzsh_srvs, tzsh_srv);
706
707 #ifdef TZSH_DEBUG
708    _print_tzsh_service_info();
709 #endif
710
711    if (tzsh_srv->tzsh)
712      tzsh_srv->tzsh->service_list = eina_list_remove(tzsh_srv->tzsh->service_list, tzsh_srv);
713
714    if (polwl->srvs[tzsh_srv->role] == tzsh_srv)
715      polwl->srvs[tzsh_srv->role] = NULL;
716
717    _e_policy_wl_tzsh_srv_state_broadcast(tzsh_srv, EINA_FALSE);
718
719    if (tzsh_srv->name)
720      eina_stringshare_del(tzsh_srv->name);
721
722    if (tzsh_srv->role == TZSH_SRV_ROLE_INDICATOR)
723      {
724         E_Client *ec;
725         ec = tzsh_srv->ec;
726
727         if (ec && ec->internal)
728           {
729              e_pixmap_win_id_del(tzsh_srv->ep);
730              e_object_del(E_OBJECT(ec));
731           }
732
733         _indicator_srv_res = NULL;
734      }
735    else if (tzsh_srv->role == TZSH_SRV_ROLE_SOFTKEY)
736      {
737         E_Client *softkey_ec = NULL;
738
739         softkey_ec = tzsh_srv->ec;
740         if (softkey_ec)
741           {
742              e_service_softkey_client_unset(softkey_ec);
743           }
744      }
745    else if (tzsh_srv->role == TZSH_SRV_ROLE_MAGNIFIER)
746      {
747         E_Client *magnifier_ec = NULL;
748
749         magnifier_ec = tzsh_srv->ec;
750         if (magnifier_ec)
751           {
752              e_magnifier_owner_unset(magnifier_ec);
753              e_magnifier_del();
754           }
755      }
756    else if (tzsh_srv->role == TZSH_SRV_ROLE_LAUNCHER)
757      {
758         E_Client *launcher_ec = NULL;
759
760         launcher_ec = tzsh_srv->ec;
761         if (launcher_ec)
762           {
763              e_service_launcher_client_unset(launcher_ec);
764           }
765      }
766
767    if (tzsh_srv->ec)
768      {
769        e_object_unref(E_OBJECT(tzsh_srv->ec));
770        tzsh_srv->ec = NULL;
771      }
772    memset(tzsh_srv, 0x0, sizeof(E_Policy_Wl_Tzsh_Srv));
773    E_FREE(tzsh_srv);
774 }
775
776 static int
777 _e_policy_wl_tzsh_srv_role_get(const char *name)
778 {
779    Tzsh_Srv_Role role = TZSH_SRV_ROLE_UNKNOWN;
780
781    if      (!e_util_strcmp(name, "volume"                   )) role = TZSH_SRV_ROLE_VOLUME;
782    else if (!e_util_strcmp(name, "quickpanel_system_default")) role = TZSH_SRV_ROLE_QUICKPANEL_SYSTEM_DEFAULT;
783    else if (!e_util_strcmp(name, "quickpanel_context_menu"  )) role = TZSH_SRV_ROLE_QUICKPANEL_CONTEXT_MENU;
784    else if (!e_util_strcmp(name, "quickpanel_apps_menu"     )) role = TZSH_SRV_ROLE_QUICKPANEL_APPS_MENU;
785    else if (!e_util_strcmp(name, "lockscreen"               )) role = TZSH_SRV_ROLE_LOCKSCREEN;
786    else if (!e_util_strcmp(name, "indicator"                )) role = TZSH_SRV_ROLE_INDICATOR;
787    else if (!e_util_strcmp(name, "screensaver_manager"      )) role = TZSH_SRV_ROLE_SCREENSAVER_MNG;
788    else if (!e_util_strcmp(name, "screensaver"              )) role = TZSH_SRV_ROLE_SCREENSAVER;
789    else if (!e_util_strcmp(name, "cbhm"                     )) role = TZSH_SRV_ROLE_CBHM;
790    else if (!e_util_strcmp(name, "softkey"                  )) role = TZSH_SRV_ROLE_SOFTKEY;
791    else if (!e_util_strcmp(name, "magnifier"                )) role = TZSH_SRV_ROLE_MAGNIFIER;
792    else if (!e_util_strcmp(name, "launcher"                 )) role = TZSH_SRV_ROLE_LAUNCHER;
793    else if (!e_util_strcmp(name, "taskbar"                  )) role = TZSH_SRV_ROLE_TASKBAR;
794    else if (!e_util_strcmp(name, "KVM"                      )) role = TZSH_SRV_ROLE_KVM;
795
796    return role;
797 }
798
799 /* broadcast state of registered service to all subscribers */
800 static void
801 _e_policy_wl_tzsh_srv_state_broadcast(E_Policy_Wl_Tzsh_Srv *tzsh_srv, Eina_Bool reg)
802 {
803    E_Policy_Wl_Tzsh *tzsh;
804    Eina_List *l;
805
806    EINA_LIST_FOREACH(polwl->tzshs, l, tzsh)
807      {
808         if (tzsh_srv->tzsh == tzsh)
809           continue;
810
811         if (reg)
812           tizen_ws_shell_send_service_register
813             (tzsh->res_tzsh, tzsh_srv->name);
814         else
815           tizen_ws_shell_send_service_unregister
816             (tzsh->res_tzsh, tzsh_srv->name);
817      }
818 }
819
820 // --------------------------------------------------------
821 // E_Policy_Wl_Tzsh_Client
822 // --------------------------------------------------------
823 static Eina_Bool
824 _e_policy_wl_tzsh_client_cb_client_zone_set(void *data, int type EINA_UNUSED, void *event)
825 {
826    E_Policy_Wl_Tzsh_Client *tzsh_client;
827    E_Event_Client_Zone_Set *ev;
828
829    tzsh_client = data;
830    ev = event;
831
832    if (tzsh_client->ec != ev->ec)
833      goto end;
834
835    if (tzsh_client->zone == ev->zone)
836      goto end;
837
838    ELOGF("TZSH", "Change Zone | e_policy_wl_tzsh_client %p old(%p) new(%p)",
839          tzsh_client->ec, tzsh_client, tzsh_client->zone, ev->zone);
840
841    tzsh_client->zone = ev->zone;
842
843 end:
844    return ECORE_CALLBACK_PASS_ON;
845 }
846
847 static E_Policy_Wl_Tzsh_Client *
848 _e_policy_wl_tzsh_client_add(E_Policy_Wl_Tzsh *tzsh, struct wl_resource *res_tzsh_client, E_Pixmap *ep, E_Client *ec)
849 {
850    E_Policy_Wl_Tzsh_Client *tzsh_client;
851
852    tzsh_client = E_NEW(E_Policy_Wl_Tzsh_Client, 1);
853    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_client, NULL);
854
855    tzsh_client->tzsh = tzsh;
856    tzsh_client->res_tzsh_client = res_tzsh_client;
857    tzsh_client->ep = ep;
858    tzsh_client->ec = ec;
859    tzsh_client->zone = e_comp_zone_find_by_ec(ec);
860    tzsh_client->tzsh->client_list = eina_list_append(tzsh_client->tzsh->client_list, tzsh_client);
861
862    polwl->tzsh_clients = eina_list_append(polwl->tzsh_clients, tzsh_client);
863
864    E_LIST_HANDLER_APPEND(tzsh_client->events, E_EVENT_CLIENT_ZONE_SET, _e_policy_wl_tzsh_client_cb_client_zone_set, tzsh_client);
865
866 #ifdef TZSH_DEBUG
867    _print_tzsh_client_info();
868 #endif
869
870    return tzsh_client;
871 }
872
873 static void
874 _e_policy_wl_tzsh_client_del(E_Policy_Wl_Tzsh_Client *tzsh_client)
875 {
876    if (!tzsh_client) return;
877
878    E_FREE_LIST(tzsh_client->events, ecore_event_handler_del);
879
880    if (tzsh_client->tzsh)
881      tzsh_client->tzsh->service_list = eina_list_remove(tzsh_client->tzsh->service_list, tzsh_client);
882
883    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
884      return;
885
886    polwl->tzsh_clients = eina_list_remove(polwl->tzsh_clients, tzsh_client);
887 #ifdef TZSH_DEBUG
888    _print_tzsh_client_info();
889 #endif
890
891    if (tzsh_client->res_tzsh_client)
892      wl_resource_set_user_data(tzsh_client->res_tzsh_client, NULL);
893
894    memset(tzsh_client, 0x0, sizeof(E_Policy_Wl_Tzsh_Client));
895    E_FREE(tzsh_client);
896 }
897
898 static E_Policy_Wl_Tzsh_Extension*
899 _e_policy_wl_tzsh_extension_get(const char *name)
900 {
901    E_Policy_Wl_Tzsh_Extension *tzsh_ext;
902    Eina_List *l;
903
904    EINA_LIST_FOREACH(polwl->tzsh_extensions, l, tzsh_ext)
905      {
906         if (strcmp(tzsh_ext->name, name)) continue;
907
908         return tzsh_ext;
909      }
910
911    return NULL;
912 }
913
914
915 // --------------------------------------------------------
916 // E_Policy_Wl_Surface
917 // --------------------------------------------------------
918 static E_Policy_Wl_Surface *
919 _e_policy_wl_surf_add(E_Client *ec, struct wl_resource *res_tzpol)
920 {
921    E_Comp_Wl_Client_Data *cdata;
922    E_Policy_Wl_Surface *psurf = NULL;
923    E_Policy_Wl_Tzpol *tzpol;
924
925    tzpol = _e_policy_wl_tzpol_get(res_tzpol);
926    EINA_SAFETY_ON_NULL_RETURN_VAL(tzpol, NULL);
927
928    psurf = _e_policy_wl_tzpol_surf_find(tzpol, ec);
929    if (psurf) return psurf;
930
931    psurf = E_NEW(E_Policy_Wl_Surface, 1);
932    EINA_SAFETY_ON_NULL_RETURN_VAL(psurf, NULL);
933
934    psurf->tzpol = tzpol;
935    psurf->cp = ec->pixmap;
936    psurf->ec = ec;
937    psurf->pid = ec->netwm.pid;
938
939    cdata = e_client_cdata_get(ec);
940    if (wl_resource_get_client(cdata->surface) == wl_resource_get_client(res_tzpol))
941        psurf->surf = cdata->surface;
942
943    tzpol->psurfs = eina_list_append(tzpol->psurfs, psurf);
944
945    if (tzpol->bg_state)
946      _e_policy_wl_background_state_set(psurf, EINA_TRUE);
947
948    return psurf;
949 }
950
951 static void
952 _e_policy_wl_surf_del(E_Policy_Wl_Surface *psurf)
953 {
954    eina_list_free(psurf->vislist);
955    eina_list_free(psurf->poslist);
956
957    memset(psurf, 0x0, sizeof(E_Policy_Wl_Surface));
958    E_FREE(psurf);
959 }
960
961 static void
962 _e_policy_wl_surf_client_set(E_Client *ec)
963 {
964    E_Policy_Wl_Tzpol *tzpol;
965    E_Policy_Wl_Surface *psurf;
966    Eina_Iterator *it;
967
968    it = eina_hash_iterator_data_new(polwl->tzpols);
969    EINA_ITERATOR_FOREACH(it, tzpol)
970      {
971         psurf = _e_policy_wl_tzpol_surf_find(tzpol, ec);
972         if (psurf)
973           {
974              if ((psurf->ec) && (psurf->ec != ec))
975                {
976                   ELOGF("POLSURF",
977                         "CRI ERR!!|s:%8p|tzpol:%8p|ps:%8p|new_ec:%8p|new_cp:%8p",
978                         psurf->ec,
979                         psurf->surf,
980                         psurf->tzpol,
981                         psurf,
982                         ec,
983                         ec->pixmap);
984                }
985
986              psurf->ec = ec;
987           }
988      }
989    eina_iterator_free(it);
990
991    return;
992 }
993
994 static E_Pixmap *
995 _e_policy_wl_e_pixmap_get_from_id(struct wl_client *client, uint32_t id)
996 {
997    E_Pixmap *cp;
998    E_Client *ec;
999    struct wl_resource *res_surf;
1000
1001    res_surf = wl_client_get_object(client, id);
1002    if (!res_surf)
1003      {
1004         ERR("Could not get surface resource");
1005         return NULL;
1006      }
1007
1008    ec = e_client_from_surface_resource(res_surf);
1009    if (!ec)
1010      {
1011         ERR("Could not get surface's user data");
1012         return NULL;
1013      }
1014
1015    /* check E_Pixmap */
1016    cp = e_pixmap_find(E_PIXMAP_TYPE_WL, (uintptr_t)res_surf);
1017    if (cp != ec->pixmap)
1018      {
1019         ELOGF("POLWL",
1020               "CRI ERR!!|cp2:%8p|ec2:%8p|res_surf:%8p",
1021               ec,
1022               cp,
1023               e_pixmap_client_get(cp),
1024               res_surf);
1025         return NULL;
1026      }
1027
1028    return cp;
1029 }
1030
1031 static Eina_Bool
1032 _e_policy_wl_e_client_is_valid(E_Client *ec)
1033 {
1034    E_Client *ec2;
1035    Eina_List *l;
1036    Eina_Bool del = EINA_FALSE;
1037    Eina_Bool found = EINA_FALSE;
1038
1039    EINA_LIST_FOREACH(e_comp->clients, l, ec2)
1040      {
1041         if (ec2 == ec)
1042           {
1043              if (e_object_is_del(E_OBJECT(ec2)))
1044                del = EINA_TRUE;
1045              found = EINA_TRUE;
1046              break;
1047           }
1048      }
1049
1050    return ((!del) && (found));
1051 }
1052
1053 static Eina_List *
1054 _e_policy_wl_e_clients_find_by_pid(pid_t pid)
1055 {
1056    E_Client *ec;
1057    Eina_List *clients = NULL, *l;
1058
1059    EINA_LIST_FOREACH(e_comp->clients, l, ec)
1060      {
1061         if (e_object_is_del(E_OBJECT(ec))) continue;
1062         if (ec->netwm.pid != pid) continue;
1063         clients = eina_list_append(clients, ec);
1064      }
1065
1066    return clients;
1067 }
1068
1069 // --------------------------------------------------------
1070 // visibility
1071 // --------------------------------------------------------
1072 static void
1073 _tzvis_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzvis)
1074 {
1075    wl_resource_destroy(res_tzvis);
1076 }
1077
1078 static const struct tizen_visibility_interface _tzvis_iface =
1079 {
1080    _tzvis_iface_cb_destroy
1081 };
1082
1083 static void
1084 _tzvis_iface_cb_vis_destroy(struct wl_resource *res_tzvis)
1085 {
1086    E_Policy_Wl_Surface *psurf;
1087    Eina_Bool r;
1088
1089    psurf = wl_resource_get_user_data(res_tzvis);
1090    EINA_SAFETY_ON_NULL_RETURN(psurf);
1091
1092    r = _e_policy_wl_surf_is_valid(psurf);
1093    if (!r) return;
1094
1095    psurf->vislist = eina_list_remove(psurf->vislist, res_tzvis);
1096 }
1097
1098 static void
1099 _tzpol_iface_cb_vis_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
1100 {
1101    E_Client *ec;
1102    E_Policy_Wl_Surface *psurf;
1103    struct wl_resource *res_tzvis;
1104
1105    ec = e_client_from_surface_resource(surf);
1106    EINA_SAFETY_ON_NULL_RETURN(ec);
1107
1108    psurf = _e_policy_wl_surf_add(ec, res_tzpol);
1109    EINA_SAFETY_ON_NULL_RETURN(psurf);
1110
1111    res_tzvis = wl_resource_create(client,
1112                                   &tizen_visibility_interface,
1113                                   wl_resource_get_version(res_tzpol),
1114                                   id);
1115    if (!res_tzvis)
1116      {
1117         wl_client_post_no_memory(client);
1118         return;
1119      }
1120
1121    wl_resource_set_implementation(res_tzvis,
1122                                   &_tzvis_iface,
1123                                   psurf,
1124                                   _tzvis_iface_cb_vis_destroy);
1125
1126    psurf->vislist = eina_list_append(psurf->vislist, res_tzvis);
1127
1128    if (eina_list_data_find(polwl->pending_vis, ec))
1129      {
1130         e_policy_wl_visibility_send(ec, ec->visibility.obscured);
1131      }
1132 }
1133
1134 EINTERN void
1135 e_policy_wl_visibility_send(E_Client *ec, int vis)
1136 {
1137    E_Comp_Wl_Client_Data *cdata;
1138    E_Policy_Wl_Tzpol *tzpol;
1139    E_Policy_Wl_Surface *psurf;
1140    struct wl_resource *res_tzvis;
1141    Eina_List *l, *ll;
1142    Eina_Iterator *it;
1143    E_Client *ec2;
1144    Ecore_Window win;
1145    Eina_Bool sent = EINA_FALSE;
1146    int ver = 1;
1147    int sent_vis = E_VISIBILITY_UNKNOWN;
1148
1149    EINA_SAFETY_ON_TRUE_RETURN(vis == E_VISIBILITY_UNKNOWN);
1150    if (ec && (ec->visibility.last_sent_type == vis))
1151      return;
1152
1153    win = e_client_util_win_get(ec);
1154
1155    it = eina_hash_iterator_data_new(polwl->tzpols);
1156    EINA_ITERATOR_FOREACH(it, tzpol)
1157      EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
1158        {
1159           ec2 = e_pixmap_client_get(psurf->cp);
1160           if (ec2 != ec) continue;
1161
1162           EINA_LIST_FOREACH(psurf->vislist, ll, res_tzvis)
1163             {
1164                // below code is workaround for checking visibility by display off or not
1165                if (e_comp_client_zone_is_displaying(ec))
1166                   e_policy_aux_message_send(ec, "dpms_wm", "on", NULL);
1167                else
1168                   e_policy_aux_message_send(ec, "dpms_wm", "off", NULL);
1169
1170                ver = wl_resource_get_version(res_tzvis);
1171                sent_vis = vis;
1172
1173                if (vis == E_VISIBILITY_PRE_UNOBSCURED)
1174                  {
1175                     if (ver >= 5)
1176                       {
1177                          ec->visibility.last_sent_type = vis;
1178                          tizen_visibility_send_changed(res_tzvis, vis, 0);
1179                       }
1180                     else
1181                       sent_vis = -2;
1182                  }
1183                else
1184                  {
1185                     if ((vis >= E_VISIBILITY_UNOBSCURED) && (vis <= E_VISIBILITY_FULLY_OBSCURED))
1186                       {
1187                          ec->visibility.last_sent_type = vis;
1188                          tizen_visibility_send_notify(res_tzvis, vis);
1189                       }
1190                     else
1191                       sent_vis = -3;
1192                  }
1193
1194                cdata = e_client_cdata_get(ec);
1195                if (cdata && cdata->mapped)
1196                  {
1197                     _launch_effect_hide(ec->netwm.pid);
1198                  }
1199
1200                ELOGF("POL_VIS",
1201                      "SEND     |win:0x%08zx|res_tzvis:%8p|ver:%d|sent_vis:%d|pid:%d|cdata:%8p|title:%s, name:%s",
1202                      ec,
1203                      win,
1204                      res_tzvis,
1205                      ver,
1206                      sent_vis,
1207                      ec->netwm.pid, cdata, ec->icccm.title, ec->netwm.name);
1208                sent = EINA_TRUE;
1209             }
1210        }
1211    eina_iterator_free(it);
1212
1213    polwl->pending_vis = eina_list_remove(polwl->pending_vis, ec);
1214    if (!sent)
1215      polwl->pending_vis = eina_list_append(polwl->pending_vis, ec);
1216 }
1217
1218 EINTERN Eina_Bool
1219 e_policy_wl_iconify_state_supported_get(E_Client *ec)
1220 {
1221    E_Policy_Wl_Tzpol *tzpol;
1222    E_Policy_Wl_Surface *psurf;
1223    E_Client *ec2;
1224    Eina_List *l;
1225    Eina_Iterator *it;
1226    Eina_Bool found = EINA_FALSE;
1227
1228    it = eina_hash_iterator_data_new(polwl->tzpols);
1229    EINA_ITERATOR_FOREACH(it, tzpol)
1230       EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
1231         {
1232            ec2 = e_pixmap_client_get(psurf->cp);
1233            if (ec2 == ec)
1234              {
1235                 found = EINA_TRUE;
1236                 break;
1237              }
1238         }
1239    eina_iterator_free(it);
1240
1241    return found;
1242 }
1243
1244 E_API void
1245 e_policy_wl_iconify_state_change_send(E_Client *ec, int iconic)
1246 {
1247    E_Policy_Wl_Tzpol *tzpol;
1248    E_Policy_Wl_Surface *psurf;
1249    E_Client *ec2;
1250    Eina_List *l;
1251    Eina_Iterator *it;
1252
1253    if (ec->exp_iconify.skip_iconify) return;
1254    if (ec->exp_iconify.skip_by_remote) return;
1255
1256    if (e_config->transient.iconify)
1257      {
1258         E_Comp_Wl_Client_Data *cdata;
1259         E_Client *child;
1260         Eina_List *list = eina_list_clone(ec->transients);
1261
1262         EINA_LIST_FREE(list, child)
1263           {
1264              cdata = e_client_cdata_get(child);
1265              if (cdata && !cdata->mapped) continue;
1266
1267              if ((child->iconic == ec->iconic) &&
1268                  (e_client_is_iconified_by_client(child) == e_client_is_iconified_by_client(ec)))
1269                e_policy_wl_iconify_state_change_send(child, iconic);
1270
1271           }
1272      }
1273
1274    it = eina_hash_iterator_data_new(polwl->tzpols);
1275    EINA_ITERATOR_FOREACH(it, tzpol)
1276      EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
1277        {
1278           ec2 = e_pixmap_client_get(psurf->cp);
1279           if (ec2 != ec) continue;
1280           if (!psurf->surf) continue;
1281
1282           tizen_policy_send_iconify_state_changed(tzpol->res_tzpol, psurf->surf, iconic, 1);
1283           ELOGF("ICONIFY",
1284                 "SEND     |iconic:%d  |argb:%d       |sur:%p",
1285                 ec,
1286                 iconic, ec->argb, psurf->surf);
1287           ec->exp_iconify.last_sent_iconic = iconic;
1288           break;
1289        }
1290    eina_iterator_free(it);
1291 }
1292
1293 // --------------------------------------------------------
1294 // position
1295 // --------------------------------------------------------
1296 static void
1297 _tzpos_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpos)
1298 {
1299    wl_resource_destroy(res_tzpos);
1300 }
1301
1302 static void
1303 _tzpos_iface_cb_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpos, int32_t x, int32_t y)
1304 {
1305    E_Client *ec;
1306    E_Policy_Wl_Surface *psurf;
1307
1308    psurf = wl_resource_get_user_data(res_tzpos);
1309    EINA_SAFETY_ON_NULL_RETURN(psurf);
1310
1311    ec = e_pixmap_client_get(psurf->cp);
1312    EINA_SAFETY_ON_NULL_RETURN(ec);
1313    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1314
1315    if (e_policy_client_is_keyboard(ec))
1316      {
1317         ELOGF("TZPOL", "Keyboard pos set (%d, %d). No operation. return.", ec, x, y);
1318         return;
1319      }
1320
1321    if (!ec->lock_client_location)
1322      {
1323         if (e_client_pending_geometry_has(ec))
1324           {
1325              // if there is geometry pending list, add move job at the end of the list.
1326              // so client to be applied new position at the same time with the pending requests
1327              // pending geometries are flushed when 'wl surface commit' and matched serial are delivered.
1328              int w, h;
1329              e_client_pending_geometry_last_geometry_get(ec, NULL, NULL, &w, &h);
1330              e_comp_wl_commit_sync_client_geometry_add(ec, ec->surface_sync.serial, x, y, w, h);
1331           }
1332         else
1333           {
1334              ec->client.x = ec->desk->geom.x + x;
1335              ec->client.y = ec->desk->geom.y + y;
1336              e_client_pos_set(ec, ec->client.x, ec->client.y);
1337              ec->placed = 1;
1338              ec->changes.pos = 1;
1339           }
1340         ec->changes.tz_position = 1;
1341         EC_CHANGED(ec);
1342      }
1343
1344    e_policy_hook_call(E_POLICY_HOOK_CLIENT_POSITION_SET, ec);
1345 }
1346
1347 static const struct tizen_position_interface _tzpos_iface =
1348 {
1349    _tzpos_iface_cb_destroy,
1350    _tzpos_iface_cb_set,
1351 };
1352
1353 static void
1354 _tzpol_iface_cb_pos_destroy(struct wl_resource *res_tzpos)
1355 {
1356    E_Policy_Wl_Surface *psurf;
1357    Eina_Bool r;
1358
1359    psurf = wl_resource_get_user_data(res_tzpos);
1360    EINA_SAFETY_ON_NULL_RETURN(psurf);
1361
1362    r = _e_policy_wl_surf_is_valid(psurf);
1363    if (!r) return;
1364
1365    psurf->poslist = eina_list_remove(psurf->poslist, res_tzpos);
1366 }
1367
1368 static void
1369 _tzpol_iface_cb_pos_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
1370 {
1371    E_Client *ec;
1372    E_Policy_Wl_Surface *psurf;
1373    struct wl_resource *res_tzpos;
1374
1375    ec = e_client_from_surface_resource(surf);
1376    EINA_SAFETY_ON_NULL_RETURN(ec);
1377
1378    psurf = _e_policy_wl_surf_add(ec, res_tzpol);
1379    EINA_SAFETY_ON_NULL_RETURN(psurf);
1380
1381    res_tzpos = wl_resource_create(client,
1382                                   &tizen_position_interface,
1383                                   wl_resource_get_version(res_tzpol),
1384                                   id);
1385    if (!res_tzpos)
1386      {
1387         wl_client_post_no_memory(client);
1388         return;
1389      }
1390
1391    wl_resource_set_implementation(res_tzpos,
1392                                   &_tzpos_iface,
1393                                   psurf,
1394                                   _tzpol_iface_cb_pos_destroy);
1395
1396    psurf->poslist = eina_list_append(psurf->poslist, res_tzpos);
1397
1398    // if ec's pos is not same to client's geometry (ec->comp_data->shell.window),
1399    // then send tizen_position changed event
1400    if (ec->comp_data)
1401      {
1402         if ((ec->x != ec->comp_data->shell.window.x) ||
1403             (ec->y != ec->comp_data->shell.window.y))
1404           e_policy_wl_position_send(ec);
1405      }
1406 }
1407
1408 EINTERN void
1409 e_policy_wl_position_send(E_Client *ec)
1410 {
1411    E_Policy_Wl_Tzpol *tzpol;
1412    E_Policy_Wl_Surface *psurf;
1413    struct wl_resource *res_tzpos;
1414    Eina_List *l, *ll;
1415    Eina_Iterator *it;
1416    Ecore_Window win;
1417
1418    EINA_SAFETY_ON_NULL_RETURN(ec);
1419
1420    win = e_client_util_win_get(ec);
1421
1422    it = eina_hash_iterator_data_new(polwl->tzpols);
1423    EINA_ITERATOR_FOREACH(it, tzpol)
1424      EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
1425        {
1426           if (e_pixmap_client_get(psurf->cp) != ec) continue;
1427
1428           EINA_LIST_FOREACH(psurf->poslist, ll, res_tzpos)
1429             {
1430                tizen_position_send_changed(res_tzpos, ec->client.x, ec->client.y);
1431                ELOGF("TZPOS",
1432                      "SEND     |win:0x%08zx|res_tzpos:%8p|ec->x:%d, ec->y:%d, ec->client.x:%d, ec->client.y:%d",
1433                      ec,
1434                      win,
1435                      res_tzpos,
1436                      ec->x, ec->y,
1437                      ec->client.x, ec->client.y);
1438             }
1439        }
1440    eina_iterator_free(it);
1441 }
1442
1443 // --------------------------------------------------------
1444 // stack: activate, raise, lower
1445 // --------------------------------------------------------
1446
1447 E_API void
1448 e_policy_wl_activate(E_Client *ec)
1449 {
1450    EINA_SAFETY_ON_NULL_RETURN(ec);
1451    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1452
1453    ELOGF("TZPOL", "REAL ACTIVATE", ec);
1454
1455    e_policy_visibility_client_lower_job_cancel(ec);
1456
1457    if ((!starting) && (!ec->focused))
1458      {
1459         if (!e_policy_visibility_client_activate(ec))
1460           {
1461              if ((ec->iconic) && (!e_client_is_iconified_by_client(ec)))
1462                e_policy_wl_iconify_state_change_send(ec, 0);
1463
1464              if (!ec->visibility.force_obscured)
1465                e_client_activate(ec);
1466           }
1467      }
1468    else
1469      {
1470         if (!ec->lock_user_stacking)
1471           e_client_raise(ec);
1472      }
1473
1474    if (e_policy_client_is_lockscreen(ec))
1475      e_policy_stack_clients_restack_above_lockscreen(ec, EINA_TRUE);
1476    else
1477      e_policy_stack_check_above_lockscreen(ec, ec->layer);
1478 }
1479
1480 static void
1481 _tzpol_iface_cb_activate(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1482 {
1483    E_Client *ec;
1484    E_Comp_Wl_Client_Data *cdata;
1485
1486    ec = e_client_from_surface_resource(surf);
1487    EINA_SAFETY_ON_NULL_RETURN(ec);
1488    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1489
1490    ELOGF("TZPOL", "ACTIVATE", ec);
1491
1492    if (ec->parent)
1493      e_policy_stack_transient_child_raise(ec);
1494
1495    e_policy_hook_call(E_POLICY_HOOK_CLIENT_ACTIVE_REQ, ec);
1496
1497    ec->post_lower = EINA_FALSE;
1498    cdata = e_client_cdata_get(ec);
1499    if (cdata && !cdata->mapped)
1500      {
1501         if (e_config->raise_before_show)
1502           e_client_raise(ec);
1503         else
1504           ec->post_raise = EINA_TRUE;
1505      }
1506    e_policy_wl_activate(ec);
1507 }
1508
1509 EINTERN void
1510 e_policy_wl_stack_changed_send(E_Client *ec)
1511 {
1512    E_Client *above = NULL;
1513    E_Client *below = NULL;
1514    int above_pid = -1;
1515    int below_pid = -1;
1516
1517    above = e_client_above_get(ec);
1518    while (above)
1519      {
1520         if ((!e_object_is_del(E_OBJECT(above))) &&
1521             (!e_client_util_ignored_get(above)) &&
1522             (above->visible) &&
1523             (above->frame))
1524           break;
1525
1526         above = e_client_above_get(above);
1527      }
1528
1529    below = e_client_below_get(ec);
1530    while (below)
1531      {
1532         if ((!e_object_is_del(E_OBJECT(below))) &&
1533             (!e_client_util_ignored_get(below)) &&
1534             (below->visible) &&
1535             (below->frame))
1536           break;
1537
1538         below = e_client_below_get(below);
1539      }
1540
1541    if (above) above_pid = above->netwm.pid;
1542    if (below) below_pid = below->netwm.pid;
1543
1544    ELOGF("TZPOL", "Send stack_changed by activate_below. above(win:%zx, pid:%d), below(win:%zx, pid:%d)",
1545          ec, e_client_util_win_get(above), above_pid, e_client_util_win_get(below), below_pid);
1546
1547
1548    e_policy_aux_message_send_from_int(ec, "stack_changed", "activate_below", 2, above_pid, below_pid);
1549
1550 }
1551
1552 static void
1553 _tzpol_iface_cb_activate_below_by_res_id(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol,  uint32_t res_id, uint32_t below_res_id)
1554 {
1555    E_Client *ec = NULL;
1556    E_Client *below_ec = NULL;
1557    E_Client *parent_ec = NULL;
1558    E_Client *focus_ec = NULL;
1559    E_Comp_Wl_Client_Data *cdata;
1560    Eina_Bool check_ancestor = EINA_FALSE;
1561    Eina_Bool intercepted = EINA_FALSE;
1562
1563    ec = e_pixmap_find_client_by_res_id(res_id);
1564    EINA_SAFETY_ON_NULL_RETURN(ec);
1565    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1566
1567    below_ec = e_pixmap_find_client_by_res_id(below_res_id);
1568    EINA_SAFETY_ON_NULL_RETURN(below_ec);
1569    EINA_SAFETY_ON_NULL_RETURN(below_ec->frame);
1570
1571    ELOGF("TZPOL",
1572          "ACTIVATE_BELOW|win:0x%08zx(res_id:%d)|below_win:0x%08zx(res_id:%d)",
1573          NULL, e_client_util_win_get(ec), res_id, e_client_util_win_get(below_ec), below_res_id);
1574
1575    intercepted = e_policy_interceptor_call(E_POLICY_INTERCEPT_ACTIVATE_BELOW,
1576                                            ec, below_ec);
1577    if (intercepted)
1578      {
1579         ELOGF("TZPOL", "ACTIVATE_BELOW|Handled by Intercept function", ec);
1580         return;
1581      }
1582
1583    if (ec->layer > below_ec->layer) return;
1584
1585    parent_ec = ec->parent;
1586    while (parent_ec)
1587      {
1588         if (parent_ec == below_ec)
1589           {
1590              check_ancestor = EINA_TRUE;
1591              break;
1592           }
1593         parent_ec = parent_ec->parent;
1594      }
1595    if (check_ancestor) return;
1596
1597    if ((!starting) && (!ec->focused))
1598      {
1599         if ((ec->iconic) && (!e_client_is_iconified_by_client(ec)))
1600           e_policy_wl_iconify_state_change_send(ec, 0);
1601
1602         e_client_uniconify(ec);
1603      }
1604
1605    e_policy_stack_below(ec, below_ec);
1606
1607    cdata = e_client_cdata_get(ec);
1608    if (cdata && !cdata->mapped)
1609      {
1610         ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_FALSE, EINA_FALSE);
1611         e_client_post_raise_lower_set(ec, EINA_FALSE, EINA_FALSE);
1612      }
1613
1614    e_policy_wl_stack_changed_send(ec);
1615
1616    // check focus
1617    focus_ec = e_client_focused_get();
1618    if (focus_ec == below_ec)
1619      e_client_focus_latest_set(ec);
1620 }
1621
1622 static void
1623 _tzpol_iface_cb_activate_above_by_res_id(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol,  uint32_t res_id, uint32_t above_res_id)
1624 {
1625    E_Client *ec = NULL;
1626    E_Comp_Wl_Client_Data *cdata;
1627    E_Client *above_ec = NULL;
1628    E_Client *parent_ec = NULL;
1629    Eina_Bool check_ancestor = EINA_FALSE;
1630    Eina_Bool intercepted = EINA_FALSE;
1631
1632    ec = e_pixmap_find_client_by_res_id(res_id);
1633    EINA_SAFETY_ON_NULL_RETURN(ec);
1634    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1635
1636    above_ec = e_pixmap_find_client_by_res_id(above_res_id);
1637    EINA_SAFETY_ON_NULL_RETURN(above_ec);
1638    EINA_SAFETY_ON_NULL_RETURN(above_ec->frame);
1639
1640    ELOGF("TZPOL",
1641          "ACTIVATE_ABOVE|win:0x%08zx(res_id:%d)|above_win:0x%08zx(res_id:%d)",
1642          NULL, e_client_util_win_get(ec), res_id, e_client_util_win_get(above_ec), above_res_id);
1643
1644    intercepted = e_policy_interceptor_call(E_POLICY_INTERCEPT_ACTIVATE_ABOVE,
1645                                            ec, above_ec);
1646    if (intercepted)
1647      {
1648         ELOGF("TZPOL", "ACTIVATE_ABOVE|Handled by Intercept function", ec);
1649         return;
1650      }
1651
1652    if (ec->layer < above_ec->layer) return;
1653
1654    /* check child */
1655    parent_ec = above_ec->parent;
1656    while (parent_ec)
1657      {
1658         if (parent_ec == ec)
1659           {
1660              check_ancestor = EINA_TRUE;
1661              break;
1662           }
1663         parent_ec = parent_ec->parent;
1664      }
1665    if (check_ancestor) return;
1666
1667    if (ec->parent && (ec->parent == above_ec))
1668      {
1669         if (e_client_transient_policy_get(ec) == E_TRANSIENT_BELOW)
1670           {
1671              ELOGF("TZPOL", "ACTIVATE_ABOVE|Denied. Above is transient_below parent", ec);
1672              return;
1673           }
1674      }
1675
1676    if (!starting)
1677      {
1678         if ((ec->iconic) && (!e_client_is_iconified_by_client(ec)))
1679           e_policy_wl_iconify_state_change_send(ec, 0);
1680
1681         e_client_uniconify(ec);
1682      }
1683
1684    e_policy_stack_above(ec, above_ec);
1685
1686    cdata = e_client_cdata_get(ec);
1687    if (cdata && !cdata->mapped)
1688      {
1689         ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_FALSE, EINA_FALSE);
1690         e_client_post_raise_lower_set(ec, EINA_FALSE, EINA_FALSE);
1691      }
1692 }
1693
1694 static void
1695 _tzpol_iface_cb_raise(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1696 {
1697    E_Client *ec;
1698    E_Comp_Wl_Client_Data *cdata;
1699
1700    ec = e_client_from_surface_resource(surf);
1701    EINA_SAFETY_ON_NULL_RETURN(ec);
1702    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1703
1704    ELOGF("TZPOL", "RAISE", ec);
1705
1706    if (ec->parent)
1707      e_policy_stack_transient_child_raise(ec);
1708
1709    e_policy_hook_call(E_POLICY_HOOK_CLIENT_RAISE_REQ, ec);
1710
1711    e_client_raise(ec);
1712
1713    cdata = e_client_cdata_get(ec);
1714    if (cdata && !cdata->mapped)
1715      {
1716         if (e_config->raise_before_show)
1717           {
1718              ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_FALSE, EINA_FALSE);
1719              e_client_post_raise_lower_set(ec, EINA_FALSE, EINA_FALSE);
1720           }
1721         else
1722           {
1723              ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_TRUE, EINA_FALSE);
1724              e_client_post_raise_lower_set(ec, EINA_TRUE, EINA_FALSE);
1725           }
1726      }
1727
1728    e_policy_hook_call(E_POLICY_HOOK_CLIENT_RAISE_REQ_DONE, ec);
1729 }
1730
1731 static void
1732 _tzpol_iface_cb_lower(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1733 {
1734    E_Client *ec = NULL;
1735    E_Comp_Wl_Client_Data *cdata;
1736
1737    ec = e_client_from_surface_resource(surf);
1738    EINA_SAFETY_ON_NULL_RETURN(ec);
1739    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1740
1741    ELOGF("TZPOL", "LOWER", ec);
1742
1743    if (ec->parent)
1744      e_policy_stack_transient_child_lower(ec);
1745
1746    e_policy_hook_call(E_POLICY_HOOK_CLIENT_LOWER_REQ, ec);
1747
1748    if (e_policy_visibility_client_lower(ec))
1749      return;
1750
1751    cdata = e_client_cdata_get(ec);
1752    if (cdata && !cdata->mapped)
1753      {
1754         ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_FALSE, EINA_TRUE);
1755         e_client_post_raise_lower_set(ec, EINA_FALSE, EINA_TRUE);
1756      }
1757
1758    e_client_lower(ec);
1759
1760 #ifdef REFACTOR_FOCUS_POLICY
1761    // This code is executed at E_CLIENT_HOOK_LOWER callback
1762    // at e_focus_policy_topmost.c and at e_focus_policy_history.c
1763 #else
1764    if (ec->focused)
1765      {
1766         if (!e_config->calc_vis_without_effect)
1767           e_client_revert_focus(ec);
1768      }
1769 #endif
1770 }
1771
1772 static void
1773 _tzpol_iface_cb_lower_by_res_id(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol,  uint32_t res_id)
1774 {
1775    E_Client *ec = NULL;
1776    E_Comp_Wl_Client_Data *cdata;
1777
1778    ec = e_pixmap_find_client_by_res_id(res_id);
1779    EINA_SAFETY_ON_NULL_RETURN(ec);
1780    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1781
1782    ELOGF("TZPOL", "LOWER by res id:%d", ec, res_id);
1783
1784    if (ec->parent)
1785      e_policy_stack_transient_child_lower(ec);
1786
1787    e_client_lower(ec);
1788
1789    cdata = e_client_cdata_get(ec);
1790    if (cdata && !cdata->mapped)
1791      {
1792         ELOGF("TZPOL", "POST_RAISE_LOWER SET... raise:%d, lower:%d", ec, EINA_FALSE, EINA_TRUE);
1793         e_client_post_raise_lower_set(ec, EINA_FALSE, EINA_TRUE);
1794      }
1795 }
1796
1797 // --------------------------------------------------------
1798 // focus
1799 // --------------------------------------------------------
1800 static void
1801 _tzpol_iface_cb_focus_skip_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1802 {
1803    E_Client *ec;
1804
1805    ec = e_client_from_surface_resource(surf);
1806    EINA_SAFETY_ON_NULL_RETURN(ec);
1807
1808    e_client_focus_skip_set(ec, EINA_TRUE, EINA_TRUE);
1809 }
1810
1811 static void
1812 _tzpol_iface_cb_focus_skip_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1813 {
1814    E_Client *ec;
1815
1816    ec = e_client_from_surface_resource(surf);
1817    EINA_SAFETY_ON_NULL_RETURN(ec);
1818
1819    e_client_focus_skip_set(ec, EINA_FALSE, EINA_TRUE);
1820 }
1821
1822 // --------------------------------------------------------
1823 // role
1824 // --------------------------------------------------------
1825 static void
1826 _tzpol_iface_cb_role_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf, const char *role)
1827 {
1828    E_Client *ec;
1829    E_Comp_Wl_Client_Data *cdata;
1830
1831    EINA_SAFETY_ON_NULL_RETURN(role);
1832
1833    ec = e_client_from_surface_resource(surf);
1834    EINA_SAFETY_ON_NULL_RETURN(ec);
1835    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
1836
1837    ELOGF("TZPOL", "ROLE SET (role:%s)", ec, role);
1838    e_client_window_role_set(ec, role);
1839
1840    /* TODO: support multiple roles */
1841    if (!e_util_strcmp("tv-volume-popup", role))
1842      {
1843         e_client_layer_set(ec, E_LAYER_CLIENT_NOTIFICATION_LOW);
1844         ec->lock_client_location = 1;
1845      }
1846    else if (!e_util_strcmp("e_demo", role))
1847      {
1848         e_client_layer_set(ec, E_LAYER_CLIENT_NOTIFICATION_HIGH);
1849         ec->lock_client_location = 1;
1850      }
1851    else if (!e_util_strcmp("cbhm", role))
1852      {
1853         cdata = e_client_cdata_get(ec);
1854         if (!cdata) return;
1855         e_comp_wl->selection.cbhm = cdata->surface;
1856      }
1857    else if (!e_util_strcmp("wl_pointer-cursor", role))
1858      {
1859         ELOGF("TZPOL", "Set CURSOR role", ec);
1860         e_client_layer_set(ec, E_LAYER_CLIENT_CURSOR);
1861         ec->is_cursor = EINA_TRUE;
1862         e_client_desk_iconify_skip_set(ec, EINA_TRUE);
1863      }
1864 }
1865
1866 static void
1867 _tzpol_iface_cb_type_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t type)
1868 {
1869    E_Client *ec;
1870    E_Window_Type win_type;
1871
1872    ec = e_client_from_surface_resource(surf);
1873    EINA_SAFETY_ON_NULL_RETURN(ec);
1874
1875    switch (type)
1876      {
1877       /* TODO: support other types */
1878       case TIZEN_POLICY_WIN_TYPE_TOPLEVEL:
1879          win_type = E_WINDOW_TYPE_NORMAL;
1880          if (ec->layer != E_LAYER_CLIENT_NORMAL)
1881            {
1882               e_client_layer_set(ec, E_LAYER_CLIENT_NORMAL);
1883            }
1884          break;
1885
1886       case TIZEN_POLICY_WIN_TYPE_NOTIFICATION:
1887          win_type = E_WINDOW_TYPE_NOTIFICATION;
1888          break;
1889
1890       case TIZEN_POLICY_WIN_TYPE_UTILITY:
1891          win_type = E_WINDOW_TYPE_UTILITY;
1892          break;
1893
1894       case TIZEN_POLICY_WIN_TYPE_DIALOG:
1895          win_type = E_WINDOW_TYPE_DIALOG;
1896          break;
1897
1898       case TIZEN_POLICY_WIN_TYPE_DESKTOP:
1899          win_type = E_WINDOW_TYPE_DESKTOP;
1900          e_client_desk_iconify_skip_set(ec, EINA_TRUE);
1901          if (ec->layer != E_LAYER_CLIENT_DESKTOP)
1902            {
1903               e_client_layer_set(ec, E_LAYER_CLIENT_DESKTOP);
1904            }
1905          break;
1906
1907       default: return;
1908      }
1909
1910    ELOGF("TZPOL",
1911          "TYPE_SET |win:0x%08zx|s:%8p|res_tzpol:%8p|tizen_win_type:%d, e_win_type:%d",
1912          ec,
1913          e_client_util_win_get(ec),
1914          surf,
1915          res_tzpol,
1916          type, win_type);
1917
1918    ec->netwm.type = win_type;
1919
1920    EC_CHANGED(ec);
1921 }
1922 // --------------------------------------------------------
1923 // conformant
1924 // --------------------------------------------------------
1925 static void
1926 _tzpol_iface_cb_conformant_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf)
1927 {
1928    E_Client *ec;
1929
1930    ec = e_client_from_surface_resource(surf);
1931    EINA_SAFETY_ON_NULL_RETURN(ec);
1932
1933    e_policy_conformant_client_add(ec, res_tzpol);
1934 }
1935
1936 static void
1937 _tzpol_iface_cb_conformant_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
1938 {
1939    E_Client *ec;
1940
1941    ec = e_client_from_surface_resource(surf);
1942    EINA_SAFETY_ON_NULL_RETURN(ec);
1943
1944    e_policy_conformant_client_del(ec);
1945 }
1946
1947 static void
1948 _tzpol_iface_cb_conformant_get(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf)
1949 {
1950    E_Client *ec;
1951
1952    ec = e_client_from_surface_resource(surf);
1953    EINA_SAFETY_ON_NULL_RETURN(ec);
1954
1955    tizen_policy_send_conformant(res_tzpol, surf, e_policy_conformant_client_check(ec));
1956 }
1957
1958 // --------------------------------------------------------
1959 // notification level
1960 // --------------------------------------------------------
1961 static void
1962 _tzpol_notilv_set(E_Client *ec, int lv)
1963 {
1964    short cur_ly;
1965    short ly;
1966
1967    switch (lv)
1968      {
1969       case  0: ly = E_LAYER_CLIENT_NOTIFICATION_LOW;    break;
1970       case  1: ly = E_LAYER_CLIENT_NOTIFICATION_NORMAL; break;
1971       case  2: ly = E_LAYER_CLIENT_NOTIFICATION_TOP;    break;
1972       case -1: ly = E_LAYER_CLIENT_NORMAL;              break;
1973       case 10: ly = E_LAYER_CLIENT_NOTIFICATION_LOW;    break;
1974       case 20: ly = E_LAYER_CLIENT_NOTIFICATION_NORMAL; break;
1975       case 30: ly = E_LAYER_CLIENT_NOTIFICATION_HIGH;   break;
1976       case 40: ly = E_LAYER_CLIENT_NOTIFICATION_TOP;    break;
1977       default: ly = E_LAYER_CLIENT_NOTIFICATION_LOW;    break;
1978      }
1979
1980    if (e_config->use_desk_area)
1981      cur_ly = e_client_desk_area_original_layer_get(ec);
1982    else
1983      cur_ly = e_client_layer_get(ec);
1984
1985    if (cur_ly != ly)
1986      {
1987         if (ly == E_LAYER_CLIENT_NORMAL)
1988           e_policy_animatable_lock(ec, E_POLICY_ANIMATABLE_LAYER, 0);
1989         else
1990           e_policy_animatable_lock(ec, E_POLICY_ANIMATABLE_LAYER, 1);
1991
1992         e_client_layer_set(ec, ly);
1993      }
1994    e_policy_hook_call(E_POLICY_HOOK_CLIENT_NOTILAYER_SET, ec);
1995 }
1996
1997 static void
1998 _tzpol_iface_cb_notilv_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t lv)
1999 {
2000    E_Client *ec;
2001    E_Policy_Wl_Surface *psurf;
2002    pid_t pid = 0;
2003    uid_t uid = 0;
2004    Eina_Bool res;
2005
2006    ec = e_client_from_surface_resource(surf);
2007    EINA_SAFETY_ON_NULL_RETURN(ec);
2008
2009    psurf = _e_policy_wl_surf_add(ec, res_tzpol);
2010    EINA_SAFETY_ON_NULL_RETURN(psurf);
2011
2012    wl_client_get_credentials(client, &pid, &uid, NULL);
2013    res = e_security_privilege_check(pid, uid,
2014                                     E_PRIVILEGE_NOTIFICATION_LEVEL_SET);
2015    if (!res)
2016      {
2017         ELOGF("TZPOL",
2018               "Privilege Check Failed! DENY set_notification_level",
2019               ec);
2020
2021         tizen_policy_send_notification_done
2022            (res_tzpol,
2023             surf,
2024             -1,
2025             TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED);
2026         return;
2027      }
2028
2029    ELOGF("TZPOL", "NOTI_LEVEL|level:%d", ec, lv);
2030    _tzpol_notilv_set(ec, lv);
2031
2032    psurf->notilv = lv;
2033
2034    tizen_policy_send_notification_done
2035      (res_tzpol, surf, lv, TIZEN_POLICY_ERROR_STATE_NONE);
2036
2037    if (e_policy_client_is_lockscreen(ec))
2038      e_policy_stack_clients_restack_above_lockscreen(ec, EINA_TRUE);
2039    else
2040      e_policy_stack_check_above_lockscreen(ec, ec->layer);
2041 }
2042
2043 EINTERN void
2044 e_policy_wl_notification_level_fetch(E_Client *ec)
2045 {
2046    E_Pixmap *cp;
2047    E_Policy_Wl_Surface *psurf;
2048    E_Policy_Wl_Tzpol *tzpol;
2049    Eina_Iterator *it;
2050    Eina_List *l;
2051    Eina_Bool changed_stack = EINA_FALSE;
2052
2053    EINA_SAFETY_ON_NULL_RETURN(ec);
2054
2055    cp = ec->pixmap;
2056    EINA_SAFETY_ON_NULL_RETURN(cp);
2057
2058    // TODO: use pending_notilv_list instead of loop
2059    it = eina_hash_iterator_data_new(polwl->tzpols);
2060    EINA_ITERATOR_FOREACH(it, tzpol)
2061      EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
2062        {
2063           if (psurf->cp != cp) continue;
2064           if (!psurf->pending_notilv) continue;
2065
2066           psurf->pending_notilv = EINA_FALSE;
2067           _tzpol_notilv_set(ec, psurf->notilv);
2068           changed_stack = EINA_TRUE;
2069        }
2070    eina_iterator_free(it);
2071
2072    if (changed_stack && e_policy_client_is_lockscreen(ec))
2073      e_policy_stack_clients_restack_above_lockscreen(ec, EINA_TRUE);
2074 }
2075
2076 // --------------------------------------------------------
2077 // transient for
2078 // --------------------------------------------------------
2079 static void
2080 _tzpol_iface_cb_transient_for_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, uint32_t child_id, uint32_t parent_id)
2081 {
2082    E_Client *ec, *parent_ec;
2083    E_Comp_Wl_Client_Data *cdata, *p_cdata;
2084
2085    ELOGF("TZPOL",
2086          "TF_SET   |res_tzpol:%8p|parent_id:%8d  |child_id:%8d",
2087          NULL, res_tzpol, parent_id, child_id);
2088
2089    ec = e_pixmap_find_client_by_res_id(child_id);
2090    EINA_SAFETY_ON_NULL_RETURN(ec);
2091    cdata = e_client_cdata_get(ec);
2092
2093    parent_ec = e_pixmap_find_client_by_res_id(parent_id);
2094    EINA_SAFETY_ON_NULL_RETURN(parent_ec);
2095    p_cdata = e_client_cdata_get(parent_ec);
2096
2097    ELOGF("TZPOL",
2098          "          |res_tzpol:%8p|parent_surf:%8p|child_surf:%8p",
2099          NULL, res_tzpol, (p_cdata ? p_cdata->surface : NULL), (cdata ? cdata->surface : NULL));
2100
2101    e_policy_stack_transient_for_set(ec, parent_ec);
2102    tizen_policy_send_transient_for_done(res_tzpol, child_id);
2103 }
2104
2105 static void
2106 _tzpol_iface_cb_transient_for_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, uint32_t child_id)
2107 {
2108    E_Client *ec;
2109
2110    ELOGF("TZPOL",
2111          "TF_UNSET |res_tzpol:%8p|child:%d",
2112          NULL, res_tzpol, child_id);
2113
2114    ec = e_pixmap_find_client_by_res_id(child_id);
2115    EINA_SAFETY_ON_NULL_RETURN(ec);
2116
2117    e_policy_stack_transient_for_set(ec, NULL);
2118    tizen_policy_send_transient_for_done(res_tzpol, child_id);
2119 }
2120
2121 // --------------------------------------------------------
2122 // window screen mode
2123 // --------------------------------------------------------
2124 static void
2125 _tzpol_iface_cb_win_scrmode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
2126 {
2127    E_Client *ec;
2128    pid_t pid = 0;
2129    uid_t uid = 0;
2130    Eina_Bool res;
2131
2132    ec = e_client_from_surface_resource(surf);
2133    EINA_SAFETY_ON_NULL_RETURN(ec);
2134
2135    wl_client_get_credentials(client, &pid, &uid, NULL);
2136    res = e_security_privilege_check(pid, uid,
2137                                     E_PRIVILEGE_SCREEN_MODE_SET);
2138    if (!res)
2139      {
2140         ELOGF("TZPOL",
2141               "Privilege Check Failed! DENY set_screen_mode",
2142               ec);
2143
2144         tizen_policy_send_window_screen_mode_done
2145            (res_tzpol,
2146             surf,
2147             -1,
2148             TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED);
2149         return;
2150      }
2151
2152    ELOGF("TZPOL", "SCR_MODE |mode:%d", ec, mode);
2153
2154    e_policy_display_screen_mode_set(ec, mode);
2155    e_policy_wl_win_scrmode_apply();
2156
2157    tizen_policy_send_window_screen_mode_done
2158      (res_tzpol, surf, mode, TIZEN_POLICY_ERROR_STATE_NONE);
2159 }
2160
2161 EINTERN void
2162 e_policy_wl_win_scrmode_apply(void)
2163 {
2164    e_policy_display_screen_mode_apply();
2165 }
2166
2167 // --------------------------------------------------------
2168 // subsurface
2169 // --------------------------------------------------------
2170
2171 static const struct wl_subsurface_interface _tzpol_subsurface_fake_impl;
2172
2173 static void
2174 _tzpol_iface_cb_subsurf_place_below_parent(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *subsurf)
2175 {
2176    if (wl_resource_instance_of(subsurf, &wl_subsurface_interface, &_tzpol_subsurface_fake_impl))
2177      return;
2178
2179    e_comp_wl_subsurface_resource_place_below_parent(subsurf);
2180 }
2181
2182 static void
2183 _tzpol_iface_cb_subsurf_stand_alone_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *subsurf)
2184 {
2185    if (wl_resource_instance_of(subsurf, &wl_subsurface_interface, &_tzpol_subsurface_fake_impl))
2186      return;
2187
2188    e_comp_wl_subsurface_resource_stand_alone_mode_set(subsurf);
2189 }
2190
2191 static void
2192 _tzpol_subsurface_fake_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
2193 {
2194    wl_resource_destroy(resource);
2195 }
2196
2197 static void
2198 _tzpol_subsurface_fake_cb_position_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, int32_t x EINA_UNUSED, int32_t y EINA_UNUSED)
2199 {
2200 }
2201
2202 static void
2203 _tzpol_subsurface_fake_cb_place_above(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, struct wl_resource *sibling_resource EINA_UNUSED)
2204 {
2205 }
2206
2207 static void
2208 _tzpol_subsurface_fake_cb_place_below(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, struct wl_resource *sibling_resource EINA_UNUSED)
2209 {
2210 }
2211
2212 static void
2213 _tzpol_subsurface_fake_cb_sync_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED)
2214 {
2215 }
2216
2217 static void
2218 _tzpol_subsurface_fake_cb_desync_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED)
2219 {
2220 }
2221
2222 static const struct wl_subsurface_interface _tzpol_subsurface_fake_impl =
2223 {
2224    _tzpol_subsurface_fake_cb_destroy,
2225    _tzpol_subsurface_fake_cb_position_set,
2226    _tzpol_subsurface_fake_cb_place_above,
2227    _tzpol_subsurface_fake_cb_place_below,
2228    _tzpol_subsurface_fake_cb_sync_set,
2229    _tzpol_subsurface_fake_cb_desync_set,
2230 };
2231
2232 static Eina_Bool
2233 _tzpol_subsurface_add_with_fake_impl(struct wl_client *client, uint32_t id)
2234 {
2235    struct wl_resource *resource;
2236
2237    resource = wl_resource_create(client, &wl_subsurface_interface, 1, id);
2238    if (!resource)
2239      return EINA_FALSE;
2240
2241    wl_resource_set_implementation(resource,
2242                                   &_tzpol_subsurface_fake_impl,
2243                                   NULL, NULL);
2244
2245    return EINA_TRUE;
2246 }
2247
2248 static void
2249 _tzpol_iface_cb_subsurface_get(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface, uint32_t parent_id)
2250 {
2251    E_Client *ec, *epc;
2252    E_Comp_Wl_Client_Data *cdata;
2253    Eina_Bool res;
2254
2255    ELOGF("TZPOL",
2256          "SUBSURF   |wl_surface@%d|parent_id:%d",
2257          NULL, wl_resource_get_id(surface), parent_id);
2258
2259    ec = e_client_from_surface_resource(surface);
2260
2261    epc = e_pixmap_find_client_by_res_id(parent_id);
2262    if ((!epc) ||
2263        (e_object_is_del(E_OBJECT(epc))))
2264      {
2265         ELOGF("TZPOL", "SUBSURF   | Invalid parent(%p). "
2266               "Create with fake implementation", ec, epc);
2267         cdata = e_client_cdata_get(ec);
2268         if ((cdata) &&
2269             (cdata->sub.watcher))
2270           {
2271              tizen_subsurface_watcher_send_message(cdata->sub.watcher,
2272                                                    TIZEN_SUBSURFACE_WATCHER_MSG_PARENT_ID_INVALID);
2273           }
2274
2275         /* We have to create a subsurface resource here even though it's error case
2276          * because server will send the fatal error when a client destroy a subsurface object.
2277          * Otherwise, server will kill a client by the fatal error.
2278          */
2279         if (!_tzpol_subsurface_add_with_fake_impl(client, id))
2280           wl_resource_post_no_memory(resource);
2281
2282         return;
2283      }
2284
2285    /* This check code is for detecting an error case which tries to create
2286     * sub-surface relationship with invalid parent. */
2287    if ((!epc->comp_data) ||
2288        (!epc->comp_data->wl_surface))
2289      {
2290         ELOGF("TZPOL", "Parent(%p internal? %s) doesn't have comp_data. "
2291               "Possibly it's not the surface created by client. "
2292               "Cannot be the parent of sub-surface.",
2293               ec, epc, epc->internal ? "TRUE" : "FALSE");
2294         wl_resource_post_error(resource,
2295                                WL_SUBSURFACE_ERROR_BAD_SURFACE,
2296                                "Invalid parent_id@%d. Possibly it's not the "
2297                                "surface created by client.(internal? %s) "
2298                                "Cannot be the parent of sub-surface.",
2299                                parent_id, epc->internal ? "TRUE" : "FALSE");
2300         return;
2301      }
2302
2303    res = e_comp_wl_subsurface_add(resource, id, surface,
2304                                   epc->comp_data->wl_surface);
2305    if (!res)
2306      {
2307         ERR("Failed to add subsurface for surface@%d", wl_resource_get_id(surface));
2308         return;
2309      }
2310
2311    /* ec's parent comes from another process */
2312    cdata = e_client_cdata_get(ec);
2313    if (cdata)
2314      cdata->has_extern_parent = EINA_TRUE;
2315 }
2316
2317 static void
2318 _tzpol_iface_cb_opaque_state_set(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface, int32_t state)
2319 {
2320    E_Client *ec;
2321
2322    ec = e_client_from_surface_resource(surface);
2323    EINA_SAFETY_ON_NULL_RETURN(ec);
2324
2325    ELOGF("TZPOL", "OPAQUE   |opaque_state:%d", ec, state);
2326    if(ec->visibility.opaque == state)
2327      return;
2328    ec->visibility.opaque = state;
2329
2330    EC_CHANGED(ec);
2331 }
2332
2333 // --------------------------------------------------------
2334 // iconify
2335 // --------------------------------------------------------
2336
2337 E_API void
2338 e_policy_wl_iconify(E_Client *ec)
2339 {
2340    EINA_SAFETY_ON_NULL_RETURN(ec);
2341    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
2342
2343    ELOGF("TZPOL", "Set ICONIFY BY CLIENT", ec);
2344
2345    if (e_policy_visibility_client_iconify(ec))
2346      {
2347         ec->exp_iconify.by_client = 1;
2348         e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT);
2349         return;
2350      }
2351    ec->exp_iconify.by_client = 1;
2352    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_ICONIFY_BY_CLIENT);
2353
2354    e_client_iconify(ec);
2355
2356    EC_CHANGED(ec);
2357 }
2358
2359 EINTERN void
2360 e_policy_wl_uniconify(E_Client *ec)
2361 {
2362    EINA_SAFETY_ON_NULL_RETURN(ec);
2363    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
2364
2365    if (e_policy_visibility_client_uniconify(ec, 1))
2366      return;
2367
2368    if ((ec->iconic) && (!e_client_is_iconified_by_client(ec)))
2369      e_policy_wl_iconify_state_change_send(ec, 0);
2370
2371    if (ec->visibility.force_obscured)
2372      {
2373         ec->exp_iconify.by_client = 0;
2374         e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
2375         return;
2376      }
2377
2378    e_client_uniconify(ec);
2379    ELOGF("TZPOL", "Un-Set ICONIFY BY CLIENT", ec);
2380    ec->exp_iconify.by_client = 0;
2381    e_client_iconified_type_set(ec, E_ICONIFIED_TYPE_NONE);
2382
2383    EC_CHANGED(ec);
2384 }
2385
2386 static void
2387 _tzpol_iface_cb_iconify(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
2388 {
2389    E_Client *ec;
2390
2391    ec = e_client_from_surface_resource(surf);
2392    EINA_SAFETY_ON_NULL_RETURN(ec);
2393
2394    ELOGF("TZPOL", "ICONIFY", ec);
2395
2396    e_policy_hook_call(E_POLICY_HOOK_CLIENT_ICONIFY_REQ, ec);
2397    e_policy_wl_iconify(ec);
2398 }
2399
2400 static void
2401 _tzpol_iface_cb_uniconify(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
2402 {
2403    E_Client *ec;
2404
2405    ec = e_client_from_surface_resource(surf);
2406    EINA_SAFETY_ON_NULL_RETURN(ec);
2407
2408    ELOGF("TZPOL", "UNICONIFY", ec);
2409
2410    e_policy_hook_call(E_POLICY_HOOK_CLIENT_UNICONIFY_REQ, ec);
2411    e_policy_wl_uniconify(ec);
2412 }
2413
2414 static void
2415 _e_policy_wl_allowed_aux_hint_send(struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id)
2416 {
2417    E_Client *ec;
2418
2419    ec = e_client_from_surface_resource(surf);
2420    EINA_SAFETY_ON_NULL_RETURN(ec);
2421
2422    ELOGF("TZPOL", "SEND     |res_tzpol:%8p|id:%d, hint allowed ", ec, res_tzpol, id);
2423    tizen_policy_send_allowed_aux_hint(res_tzpol, surf, id);
2424 }
2425
2426 static void
2427 _e_policy_wl_aux_hint_apply(E_Client *ec)
2428 {
2429    E_Comp_Wl_Client_Data *cdata;
2430    E_Comp_Wl_Aux_Hint *hint;
2431    Eina_List *l;
2432
2433    cdata = e_client_cdata_get(ec);
2434    if (!cdata) return;
2435    if (!cdata->aux_hint.changed) return;
2436
2437    EINA_LIST_FOREACH(cdata->aux_hint.hints, l, hint)
2438      {
2439         if (!hint->changed) continue;
2440         EC_CHANGED(ec);
2441
2442         if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_USER_GEOMETRY]))
2443           {
2444              if (hint->deleted)
2445                {
2446                   e_policy_user_geometry_set(ec, E_POLICY_USERGEOM_HINT, EINA_FALSE);
2447                   continue;
2448                }
2449
2450              if (!strcmp(hint->val, "1"))
2451                {
2452                   e_policy_user_geometry_set(ec, E_POLICY_USERGEOM_HINT, EINA_TRUE);
2453                }
2454              else if (strcmp(hint->val, "1"))
2455                {
2456                   e_policy_user_geometry_set(ec, E_POLICY_USERGEOM_HINT, EINA_FALSE);
2457                }
2458           }
2459         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_FIXED_RESIZE]))
2460           {
2461              /* TODO: support other aux_hints */
2462           }
2463         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_DEICONIFY_UPDATE]))
2464           {
2465              if (!strcmp(hint->val, "1"))
2466                ec->exp_iconify.deiconify_update = EINA_TRUE;
2467              else
2468                ec->exp_iconify.deiconify_update = EINA_FALSE;
2469
2470           }
2471         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_GESTURE_DISABLE]))
2472           {
2473              if (hint->deleted)
2474                {
2475                   ec->gesture_disable = EINA_FALSE;
2476                   continue;
2477                }
2478
2479              if (atoi(hint->val) == 1)
2480                {
2481                   ec->gesture_disable = EINA_TRUE;
2482                }
2483              else
2484                {
2485                   ec->gesture_disable = EINA_FALSE;
2486                }
2487           }
2488         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_ICONIFY]))
2489           {
2490              if (hint->deleted)
2491                {
2492                   ec->exp_iconify.skip_iconify = 0;
2493                   EC_CHANGED(ec);
2494                   continue;
2495                }
2496
2497              if (!strcmp(hint->val, "disable"))
2498                {
2499                   ec->exp_iconify.skip_iconify = 1;
2500                   EC_CHANGED(ec);
2501                }
2502              else if (!strcmp(hint->val, "enable"))
2503                {
2504                   ec->exp_iconify.skip_iconify = 0;
2505                   EC_CHANGED(ec);
2506                }
2507           }
2508         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_ABOVE_LOCKSCREEN]))
2509           {
2510              if ((hint->deleted) ||
2511                  (!strcmp(hint->val, "0")))
2512                {
2513                   E_Layer original_layer = ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved_layer;
2514                   if (ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].set &&
2515                       ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved)
2516                     {
2517                        // restore original layer
2518                        if (original_layer != evas_object_layer_get(ec->frame))
2519                          {
2520                             Eina_Bool pend = EINA_FALSE;
2521                             pend = e_policy_visibility_client_layer_lower(ec, original_layer);
2522                             if (!pend)
2523                               {
2524                                  e_client_layer_set(ec, original_layer);
2525                               }
2526                          }
2527                     }
2528                   ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].set = 0;
2529                   ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved = 0;
2530                   ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved_layer = 0;
2531                   EC_CHANGED(ec);
2532                }
2533              else if (!strcmp(hint->val, "1"))
2534                {
2535                   if (!ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved)
2536                     {
2537                        ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].set = 1;
2538                        ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved = 0;
2539                        ec->changable_layer[E_CHANGABLE_LAYER_TYPE_ABOVE_NOTIFICATION].saved_layer = ec->layer;
2540                        EC_CHANGED(ec);
2541                     }
2542                }
2543           }
2544         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_EFFECT_DISABLE]))
2545           {
2546              if ((hint->deleted) ||
2547                  (!strcmp(hint->val, "0")))
2548                {
2549                   e_policy_animatable_lock(ec, E_POLICY_ANIMATABLE_HINT, 0);
2550                }
2551              else if (!strcmp(hint->val, "1"))
2552                {
2553                   e_policy_animatable_lock(ec, E_POLICY_ANIMATABLE_HINT, 1);
2554                }
2555           }
2556         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_MSG_USE]))
2557           {
2558              if ((hint->deleted) || (!strcmp(hint->val, "0")))
2559                cdata->aux_hint.use_msg = EINA_FALSE;
2560              else if (!strcmp(hint->val, "1"))
2561                cdata->aux_hint.use_msg = EINA_TRUE;
2562           }
2563         else if (!strcmp(hint->hint, hint_names[E_COMP_HINT_ALWAYS_SELECTIVE]))
2564           {
2565              if ((hint->deleted) || (!strcmp(hint->val, "0")))
2566                cdata->never_hwc = EINA_FALSE;
2567              else if (!strcmp(hint->val, "1"))
2568                cdata->never_hwc = EINA_TRUE;
2569
2570              e_comp_render_queue();
2571           }
2572         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_DEPENDENT_ROTATION]))
2573           {
2574              if ((hint->deleted) || (!strcmp(hint->val, "0")))
2575                ec->e.state.rot.type = E_CLIENT_ROTATION_TYPE_NORMAL;
2576              else if (!strcmp(hint->val, "1"))
2577                ec->e.state.rot.type = E_CLIENT_ROTATION_TYPE_DEPENDENT;
2578           }
2579         else if (!strcmp(hint->hint, hint_names[E_POLICY_HINT_ROT_RENDER_NOPENDING]))
2580           {
2581              if ((hint->deleted) || (!strcmp(hint->val, "0")))
2582                {
2583                   ELOGF("ROTATION", "nopending render:0", ec);
2584                   ec->e.state.rot.nopending_render = 0;
2585                }
2586              else if (!strcmp(hint->val, "1"))
2587                {
2588                   ELOGF("ROTATION", "nopending render:1", ec);
2589                   ec->e.state.rot.nopending_render = 1;
2590                }
2591           }
2592         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_ICONIFY_BUFFER_FLUSH], strlen(hint->hint)))
2593           {
2594              if (!strncmp(hint->val, "1", 1))
2595                ec->exp_iconify.buffer_flush = EINA_TRUE;
2596              else
2597                ec->exp_iconify.buffer_flush = EINA_FALSE;
2598           }
2599         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_TRANSIENT_FOR_ALWAYS_ON_TOP], strlen(hint->hint)))
2600           {
2601              if (!strncmp(hint->val, "1", 1))
2602                {
2603                   ELOGF("TF_SET", "Transient for Always_on_top enabled", ec);
2604                   ec->transient_for_always_on_top = EINA_TRUE;
2605                }
2606              else
2607                {
2608                   ELOGF("TF_SET", "Transient for Always_on_top disabled", ec);
2609                   ec->transient_for_always_on_top = EINA_FALSE;
2610                }
2611           }
2612         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_BELONG_TO_PARENT], strlen(hint->hint)))
2613           {
2614              if (!strncmp(hint->val, "1", 1))
2615                {
2616                   ELOGF("TF_SET", "Set belong_to_parent", ec);
2617                   e_client_belong_to_parent_set(ec, EINA_TRUE);
2618                }
2619              else
2620                {
2621                   ELOGF("TF_SET", "Unset belong_to_parent", ec);
2622                   e_client_belong_to_parent_set(ec, EINA_FALSE);
2623                }
2624           }
2625         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_RESIZE_ASPECT_RATIO], strlen(hint->hint)))
2626           {
2627              if (!strncmp(hint->val, "1", 1))
2628                {
2629                   ELOGF("RESIZE", "Set resize aspect ratio.. ratio(%dx%d)", ec, ec->w, ec->h);
2630                   ec->manage_resize.enable_aspect_ratio = EINA_TRUE;
2631                   ec->manage_resize.aw = ec->w;
2632                   ec->manage_resize.ah = ec->h;
2633                }
2634              else
2635                {
2636                   ELOGF("RESIZE", "Unset resize aspect ratio", ec);
2637                   ec->manage_resize.enable_aspect_ratio = EINA_FALSE;
2638                }
2639           }
2640         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_HEADER], strlen(hint->hint)))
2641           {
2642              int height = atoi(hint->val);
2643              if (height > 0)
2644                {
2645                   ELOGF("CSD", "Set decoration HEADER size.. size(%d)", ec, height);
2646                   ec->manage_resize.header_h = height;
2647                }
2648              else
2649                {
2650                   ELOGF("CSD", "Unset decoration HEADER size", ec);
2651                   ec->manage_resize.header_h = 0;
2652                }
2653           }
2654         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_FOOTER], strlen(hint->hint)))
2655           {
2656              int height = atoi(hint->val);
2657              if (height > 0)
2658                {
2659                   ELOGF("CSD", "Set decoration FOOTER size.. size(%d)", ec, height);
2660                   ec->manage_resize.footer_h = height;
2661                }
2662              else
2663                {
2664                   ELOGF("CSD", "Unset decoration FOOTER size", ec);
2665                   ec->manage_resize.footer_h = 0;
2666                }
2667           }
2668         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_VISIBILITY_IGNORE_GEOMETRY], strlen(hint->hint)))
2669           {
2670              if (!strncmp(hint->val, "1", 1))
2671                {
2672                   ELOGF("POL_VIS", "Set ignore_geometry.. value(%s)", ec, hint->val);
2673                   ec->visibility.ignore_geometry = EINA_TRUE;
2674                }
2675              else
2676                {
2677                   ELOGF("POL_VIS", "UNSet ignore_geometry.. value(%s)", ec, hint->val);
2678                   ec->visibility.ignore_geometry = EINA_FALSE;
2679                }
2680           }
2681         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_RESIZE_PPU], strlen(hint->hint)))
2682           {
2683              int ppu = atoi(hint->val);
2684              if (ppu < 1) ppu = 1;
2685
2686              ELOGF("RESIZE", "Set resize unit. size:%d", ec, ppu);
2687              e_client_resize_unit_size_set(ec, ppu);
2688           }
2689         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_SHADOW_TOP], strlen(hint->hint)))
2690           {
2691              int size = atoi(hint->val);
2692              if (size > 0)
2693                {
2694                   ELOGF("CSD", "Set decoration SHADOW top.. size(%d)", ec, size);
2695                   ec->manage_resize.shadow.t = size;
2696                }
2697              else
2698                {
2699                   ELOGF("CSD", "Unset decoration SHADOW top", ec);
2700                   ec->manage_resize.shadow.t = 0;
2701                }
2702           }
2703         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_SHADOW_BOTTOM], strlen(hint->hint)))
2704           {
2705              int size = atoi(hint->val);
2706              if (size > 0)
2707                {
2708                   ELOGF("CSD", "Set decoration SHADOW bottom.. size(%d)", ec, size);
2709                   ec->manage_resize.shadow.b = size;
2710                }
2711              else
2712                {
2713                   ELOGF("CSD", "Unset decoration SHADOW bottom", ec);
2714                   ec->manage_resize.shadow.b = 0;
2715                }
2716           }
2717         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_SHADOW_LEFT], strlen(hint->hint)))
2718           {
2719              int size = atoi(hint->val);
2720              if (size > 0)
2721                {
2722                   ELOGF("CSD", "Set decoration SHADOW left.. size(%d)", ec, size);
2723                   ec->manage_resize.shadow.l = size;
2724                }
2725              else
2726                {
2727                   ELOGF("CSD", "Unset decoration SHADOW left", ec);
2728                   ec->manage_resize.shadow.l = 0;
2729                }
2730           }
2731         else if (!strncmp(hint->hint, hint_names[E_POLICY_HINT_DECORATION_SIZE_SHADOW_RIGHT], strlen(hint->hint)))
2732           {
2733              int size = atoi(hint->val);
2734              if (size > 0)
2735                {
2736                   ELOGF("CSD", "Set decoration SHADOW right.. size(%d)", ec, size);
2737                   ec->manage_resize.shadow.r = size;
2738                }
2739              else
2740                {
2741                   ELOGF("CSD", "Unset decoration SHADOW right", ec);
2742                   ec->manage_resize.shadow.r = 0;
2743                }
2744           }
2745      }
2746
2747    e_policy_hook_call(E_POLICY_HOOK_CLIENT_AUX_HINT_CHANGED, ec);
2748 }
2749
2750 static void
2751 _tzpol_iface_cb_aux_hint_add(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *name, const char *value)
2752 {
2753    E_Client *ec;
2754    Eina_Bool res = EINA_FALSE;
2755
2756    ec = e_client_from_surface_resource(surf);
2757    EINA_SAFETY_ON_NULL_RETURN(ec);
2758
2759    res = e_hints_aux_hint_add(ec, id, name, value);
2760
2761    ELOGF("TZPOL", "HINT_ADD |res_tzpol:%8p|id:%d, name:%s, val:%s, res:%d", ec, res_tzpol, id, name, value, res);
2762
2763    if (res)
2764      {
2765         _e_policy_wl_aux_hint_apply(ec);
2766         _e_policy_wl_allowed_aux_hint_send(res_tzpol, surf, id);
2767      }
2768 }
2769
2770 static void
2771 _tzpol_iface_cb_aux_hint_change(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *value)
2772 {
2773    E_Client *ec;
2774    Eina_Bool res = EINA_FALSE;
2775
2776    ec = e_client_from_surface_resource(surf);
2777    EINA_SAFETY_ON_NULL_RETURN(ec);
2778
2779    res = e_hints_aux_hint_change(ec, id, value);
2780
2781    ELOGF("TZPOL", "HINT_CHD |res_tzpol:%8p|id:%d, val:%s, result:%d", ec, res_tzpol, id, value, res);
2782
2783    if (res)
2784      {
2785         _e_policy_wl_aux_hint_apply(ec);
2786         _e_policy_wl_allowed_aux_hint_send(res_tzpol, surf, id);
2787      }
2788 }
2789
2790 static void
2791 _tzpol_iface_cb_aux_hint_del(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id)
2792 {
2793    E_Client *ec;
2794    unsigned int res = -1;
2795
2796    ec = e_client_from_surface_resource(surf);
2797    EINA_SAFETY_ON_NULL_RETURN(ec);
2798
2799    res = e_hints_aux_hint_del(ec, id);
2800    ELOGF("TZPOL", "HINT_DEL |res_tzpol:%8p|id:%d, result:%d", ec, res_tzpol, id, res);
2801
2802    if (res)
2803      _e_policy_wl_aux_hint_apply(ec);
2804 }
2805
2806 static void
2807 _tzpol_iface_cb_supported_aux_hints_get(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf)
2808 {
2809    E_Client *ec;
2810    const Eina_List *hints_list;
2811    const Eina_List *l;
2812    struct wl_array hints;
2813    const char *hint_name;
2814    int len;
2815    char *p;
2816
2817    ec = e_client_from_surface_resource(surf);
2818    EINA_SAFETY_ON_NULL_RETURN(ec);
2819
2820    hints_list = e_hints_aux_hint_supported_get();
2821
2822    wl_array_init(&hints);
2823    EINA_LIST_FOREACH(hints_list, l, hint_name)
2824      {
2825         len = strlen(hint_name) + 1;
2826         p = wl_array_add(&hints, len);
2827
2828         if (p == NULL)
2829           break;
2830         strncpy(p, hint_name, len);
2831      }
2832
2833    tizen_policy_send_supported_aux_hints(res_tzpol, surf, &hints, eina_list_count(hints_list));
2834    ELOGF("TZPOL",
2835          "SEND     |res_tzpol:%8p|supported_hints size:%d",
2836          ec,
2837          res_tzpol,
2838          eina_list_count(hints_list));
2839    wl_array_release(&hints);
2840 }
2841
2842 static void
2843 _e_policy_wl_background_state_apply(E_Client *ec, Eina_Bool state)
2844 {
2845    if (!ec) return;
2846
2847    ELOGF("TZPOL",
2848          "BACKGROUND STATE %s for PID(%u), iconic:%d",
2849          ec,
2850          state?"SET":"UNSET", ec->netwm.pid, ec->iconic);
2851
2852    if (state)
2853      {
2854         ec->bg_state = EINA_TRUE;
2855         evas_object_hide(ec->frame);
2856         e_pixmap_image_clear(ec->pixmap, 1);
2857      }
2858    else
2859      {
2860         ec->bg_state = EINA_FALSE;
2861         if (!ec->iconic)
2862           {
2863              E_Comp_Wl_Client_Data *cdata;
2864              cdata = e_client_cdata_get(ec);
2865              if (cdata && cdata->mapped)
2866                {
2867                   evas_object_show(ec->frame);
2868                   e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
2869                }
2870           }
2871      }
2872
2873    EC_CHANGED(ec);
2874    e_comp_visibility_calculation_set(EINA_TRUE);
2875 }
2876
2877 static void
2878 _e_policy_wl_background_state_set(E_Policy_Wl_Surface *psurf, Eina_Bool state)
2879 {
2880    psurf->is_background = state;
2881    ELOGF("TZPOL", "Set psurf(%p)'s background_state to %d", NULL, psurf, state);
2882
2883    if (state)
2884      {
2885         if (psurf->ec)
2886           _e_policy_wl_background_state_apply(psurf->ec, EINA_TRUE);
2887      }
2888    else
2889      {
2890         if (psurf->ec)
2891           _e_policy_wl_background_state_apply(psurf->ec, EINA_FALSE);
2892      }
2893 }
2894
2895 static void
2896 _e_policy_wl_tzlaunch_effect_type_sync(E_Client *ec)
2897 {
2898    Eina_List *l;
2899    E_Policy_Wl_Tzlaunch_Effect_Info *effect_info;
2900
2901    EINA_SAFETY_ON_NULL_RETURN(ec);
2902
2903    EINA_LIST_FOREACH(polwl->tzlaunch_effect_info, l, effect_info)
2904      {
2905         if (effect_info->pid == ec->netwm.pid)
2906           {
2907              ELOGF("TZPOL",
2908                    "Launchscreen effect type sync | pid (%d) effect_type (%d)",
2909                    ec, ec->netwm.pid, effect_info->effect_type);
2910              ec->effect_type = effect_info->effect_type;
2911              _e_policy_wl_tzlaunch_effect_type_unset(ec->netwm.pid);
2912              break;
2913           }
2914      }
2915 }
2916
2917 static int
2918 _e_policy_wl_tzlaunch_effect_type_get(const char * effect_type)
2919 {
2920    Tzlaunch_Effect_Type type = TZLAUNCH_EFFECT_TYPE_LAUNCH;
2921
2922    if      (!e_util_strcmp(effect_type, "launch"    )) type = TZLAUNCH_EFFECT_TYPE_LAUNCH;
2923    else if (!e_util_strcmp(effect_type, "depth-in" )) type = TZLAUNCH_EFFECT_TYPE_DEPTH_IN;
2924
2925    return type;
2926 }
2927
2928 static void
2929 _e_policy_wl_tzlaunch_effect_type_unset(uint32_t pid)
2930 {
2931    Eina_List *l;
2932    E_Policy_Wl_Tzlaunch_Effect_Info *effect_info;
2933
2934    EINA_LIST_FOREACH(polwl->tzlaunch_effect_info, l, effect_info)
2935      {
2936         if (effect_info->pid == pid)
2937           {
2938              ELOGF("TZPOL",
2939                    "Launchscreen effect type unset | pid (%d)",
2940                    NULL, pid);
2941              polwl->tzlaunch_effect_info = eina_list_remove(polwl->tzlaunch_effect_info, effect_info);
2942              memset(effect_info, 0x0, sizeof(E_Policy_Wl_Tzlaunch_Effect_Info));
2943              E_FREE(effect_info);
2944              break;
2945           }
2946      }
2947 }
2948
2949 static void
2950 _e_policy_wl_tzpol_background_state_set(E_Policy_Wl_Tzpol *tzpol, Eina_Bool bg_state, pid_t pid)
2951 {
2952    Eina_List *l;
2953    E_Policy_Wl_Surface *psurf;
2954
2955    if (!tzpol) return;
2956
2957    tzpol->bg_state = bg_state;
2958    ELOGF("TZPOL", "Set tzpol(%p)'s background_state to %d", NULL, tzpol, bg_state);
2959
2960    EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
2961      {
2962         if (psurf->pid == pid)
2963           {
2964              if (psurf->is_background == bg_state)
2965                continue;
2966
2967              _e_policy_wl_background_state_set(psurf, bg_state);
2968           }
2969      }
2970 }
2971
2972 static void
2973 _e_policy_wl_tzpols_background_state_set(Eina_Bool bg_state, pid_t pid)
2974 {
2975    E_Policy_Wl_Tzpol *tzpol;
2976    Eina_Iterator *it;
2977
2978    it = eina_hash_iterator_data_new(polwl->tzpols);
2979    EINA_ITERATOR_FOREACH(it, tzpol)
2980      {
2981         if (tzpol->pid == pid)
2982           {
2983              _e_policy_wl_tzpol_background_state_set(tzpol, bg_state, pid);
2984           }
2985      }
2986    eina_iterator_free(it);
2987 }
2988
2989 static void
2990 _tzpol_iface_cb_background_state_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, uint32_t pid)
2991 {
2992    E_Policy_Wl_Tzpol *tzpol;
2993
2994    tzpol = _e_policy_wl_tzpol_get(res_tzpol);
2995    EINA_SAFETY_ON_NULL_RETURN(tzpol);
2996
2997    ELOGF("TZPOL", "Register PID(%u) for BACKGROUND STATE res_tzpol:%p tzpol:%p", NULL, pid, res_tzpol, tzpol);
2998
2999    _e_policy_wl_tzpols_background_state_set(EINA_TRUE, pid);
3000 }
3001
3002 static void
3003 _tzpol_iface_cb_background_state_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, uint32_t pid)
3004 {
3005    E_Policy_Wl_Tzpol *tzpol;
3006
3007    tzpol = _e_policy_wl_tzpol_get(res_tzpol);
3008    EINA_SAFETY_ON_NULL_RETURN(tzpol);
3009
3010    ELOGF("TZPOL", "Unregister PID(%u) for BACKGROUND STATE res_tzpol:%p tzpol:%p", NULL, pid, res_tzpol, tzpol);
3011
3012    _e_policy_wl_tzpols_background_state_set(EINA_FALSE, pid);
3013 }
3014
3015 static void
3016 _e_policy_wl_floating_mode_apply(E_Client *ec, Eina_Bool floating)
3017 {
3018    if (ec->floating == floating) return;
3019
3020    ec->floating = floating;
3021    ec->lock_client_location = EINA_FALSE;
3022
3023    if (ec->frame)
3024      {
3025         if (floating)
3026           {
3027              ec->floating_saved_layer = ec->layer;
3028              e_client_layer_set(ec, E_LAYER_CLIENT_ABOVE);
3029           }
3030         else
3031           {
3032              e_client_layer_set(ec, ec->floating_saved_layer);
3033           }
3034      }
3035
3036    EC_CHANGED(ec);
3037 }
3038
3039 static void
3040 _tzpol_iface_cb_floating_mode_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf)
3041 {
3042    E_Client *ec;
3043
3044    ec = e_client_from_surface_resource(surf);
3045    EINA_SAFETY_ON_NULL_RETURN(ec);
3046
3047    ELOGF("TZPOL", "FLOATING Set", ec);
3048
3049    _e_policy_wl_floating_mode_apply(ec, EINA_TRUE);
3050 }
3051
3052 static void
3053 _tzpol_iface_cb_floating_mode_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf)
3054 {
3055    E_Client *ec;
3056
3057    ec = e_client_from_surface_resource(surf);
3058    EINA_SAFETY_ON_NULL_RETURN(ec);
3059
3060    ELOGF("TZPOL", "FLOATING Unset", ec);
3061
3062    e_client_pending_geometry_flush(ec);
3063
3064    _e_policy_wl_floating_mode_apply(ec, EINA_FALSE);
3065 }
3066
3067 static void
3068 _tzpol_iface_cb_stack_mode_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
3069 {
3070    E_Client *ec;
3071
3072    ec = e_client_from_surface_resource(surf);
3073    EINA_SAFETY_ON_NULL_RETURN(ec);
3074
3075    ELOGF("TZPOL", "STACK Mode Set. mode:%d", ec, mode);
3076
3077    if (ec->frame)
3078      {
3079         if (mode == TIZEN_POLICY_STACK_MODE_ABOVE)
3080           {
3081              e_client_layer_set(ec, E_LAYER_CLIENT_ABOVE);
3082           }
3083         else if (mode == TIZEN_POLICY_STACK_MODE_BELOW)
3084           {
3085              e_client_layer_set(ec, E_LAYER_CLIENT_BELOW);
3086           }
3087         else
3088           {
3089              e_client_layer_set(ec, E_LAYER_CLIENT_NORMAL);
3090           }
3091         EC_CHANGED(ec);
3092
3093         e_policy_hook_call(E_POLICY_HOOK_CLIENT_STACK_MODE_SET, ec);
3094      }
3095 }
3096
3097 // --------------------------------------------------------
3098 // E_Policy_Wl_Tz_Dpy_Pol
3099 // --------------------------------------------------------
3100 static E_Policy_Wl_Tz_Dpy_Pol *
3101 _e_policy_wl_tz_dpy_pol_add(struct wl_resource *res_tz_dpy_pol)
3102 {
3103    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3104
3105    tz_dpy_pol = E_NEW(E_Policy_Wl_Tz_Dpy_Pol, 1);
3106    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_dpy_pol, NULL);
3107
3108    tz_dpy_pol->res_tz_dpy_pol = res_tz_dpy_pol;
3109
3110    polwl->tz_dpy_pols = eina_list_append(polwl->tz_dpy_pols, tz_dpy_pol);
3111
3112    return tz_dpy_pol;
3113 }
3114
3115 static void
3116 _e_policy_wl_tz_dpy_pol_del(E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol)
3117 {
3118    E_Policy_Wl_Dpy_Surface *dpy_surf;
3119
3120    EINA_SAFETY_ON_NULL_RETURN(tz_dpy_pol);
3121
3122    polwl->tz_dpy_pols = eina_list_remove(polwl->tz_dpy_pols, tz_dpy_pol);
3123
3124    EINA_LIST_FREE(tz_dpy_pol->dpy_surfs, dpy_surf)
3125      {
3126         E_FREE(dpy_surf);
3127      }
3128
3129    E_FREE(tz_dpy_pol);
3130 }
3131
3132 static E_Policy_Wl_Tz_Dpy_Pol *
3133 _e_policy_wl_tz_dpy_pol_get(struct wl_resource *res_tz_dpy_pol)
3134 {
3135    Eina_List *l;
3136    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3137
3138    EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
3139      {
3140         if (tz_dpy_pol->res_tz_dpy_pol == res_tz_dpy_pol)
3141           return tz_dpy_pol;
3142      }
3143
3144    return NULL;
3145 }
3146
3147 // --------------------------------------------------------
3148 // E_Policy_Wl_Dpy_Surface
3149 // --------------------------------------------------------
3150 static E_Policy_Wl_Dpy_Surface *
3151 _e_policy_wl_dpy_surf_find(E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol, E_Client *ec)
3152 {
3153    Eina_List *l;
3154    E_Policy_Wl_Dpy_Surface *dpy_surf;
3155
3156    EINA_LIST_FOREACH(tz_dpy_pol->dpy_surfs, l, dpy_surf)
3157      {
3158         if (dpy_surf->ec == ec)
3159           return dpy_surf;
3160      }
3161
3162    return NULL;
3163 }
3164
3165 static E_Policy_Wl_Dpy_Surface *
3166 _e_policy_wl_dpy_surf_add(E_Client *ec, struct wl_resource *res_tz_dpy_pol)
3167 {
3168    E_Policy_Wl_Tz_Dpy_Pol  *tz_dpy_pol = NULL;
3169    E_Policy_Wl_Dpy_Surface *dpy_surf   = NULL;
3170    E_Comp_Wl_Client_Data *cdata;
3171
3172    tz_dpy_pol = _e_policy_wl_tz_dpy_pol_get(res_tz_dpy_pol);
3173    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_dpy_pol, NULL);
3174
3175    dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
3176    if (dpy_surf)
3177      return dpy_surf;
3178
3179    dpy_surf = E_NEW(E_Policy_Wl_Dpy_Surface, 1);
3180    EINA_SAFETY_ON_NULL_RETURN_VAL(dpy_surf, NULL);
3181
3182    cdata = e_client_cdata_get(ec);
3183    dpy_surf->surf = cdata->surface;
3184    dpy_surf->tz_dpy_pol = tz_dpy_pol;
3185    dpy_surf->ec = ec;
3186    dpy_surf->brightness = -1;
3187
3188    tz_dpy_pol->dpy_surfs = eina_list_append(tz_dpy_pol->dpy_surfs, dpy_surf);
3189    return dpy_surf;
3190 }
3191
3192 static void
3193 _e_policy_wl_dpy_surf_del(E_Client *ec)
3194 {
3195    Eina_List *l;
3196    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3197    E_Policy_Wl_Dpy_Surface *dpy_surf;
3198
3199    EINA_SAFETY_ON_NULL_RETURN(ec);
3200
3201    EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
3202      {
3203         dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
3204         if (dpy_surf)
3205           {
3206              tz_dpy_pol->dpy_surfs = eina_list_remove(tz_dpy_pol->dpy_surfs, dpy_surf);
3207              E_FREE(dpy_surf);
3208           }
3209      }
3210 }
3211
3212 // --------------------------------------------------------
3213 // brightness
3214 // --------------------------------------------------------
3215 static Eina_Bool
3216 _e_policy_system_brightness_get(int *brightness)
3217 {
3218    int error;
3219    int sys_brightness = -1;
3220
3221    if (!brightness) return EINA_FALSE;
3222
3223    error = device_display_get_brightness(0, &sys_brightness);
3224    if (error != DEVICE_ERROR_NONE)
3225      {
3226         // error
3227         return EINA_FALSE;
3228      }
3229
3230    *brightness = sys_brightness;
3231
3232    return EINA_TRUE;
3233 }
3234
3235 static Eina_Bool
3236 _e_policy_system_brightness_set(int brightness)
3237 {
3238    Eina_Bool ret;
3239    int error;
3240    int num_of_dpy;
3241    int id;
3242
3243    ret = EINA_TRUE;
3244
3245    error = device_display_get_numbers(&num_of_dpy);
3246    if (error != DEVICE_ERROR_NONE)
3247      {
3248         // error
3249         return EINA_FALSE;
3250      }
3251
3252    for (id = 0; id < num_of_dpy; id++)
3253      {
3254         error = device_display_set_brightness(id, brightness);
3255         if (error != DEVICE_ERROR_NONE)
3256           {
3257              // error
3258              ret = EINA_FALSE;
3259              break;
3260           }
3261      }
3262
3263    return ret;
3264 }
3265
3266 static Eina_Bool
3267 _e_policy_change_system_brightness(int new_brightness)
3268 {
3269    Eina_Bool ret;
3270    int sys_brightness;
3271
3272    if (!e_policy_system_info.brightness.use_client)
3273      {
3274         // save system brightness
3275         ret = _e_policy_system_brightness_get(&sys_brightness);
3276         if (!ret)
3277           {
3278              return EINA_FALSE;
3279           }
3280         e_policy_system_info.brightness.system = sys_brightness;
3281      }
3282
3283    ret = _e_policy_system_brightness_set(new_brightness);
3284    if (!ret)
3285      {
3286         return EINA_FALSE;
3287      }
3288    e_policy_system_info.brightness.client = new_brightness;
3289    e_policy_system_info.brightness.use_client = EINA_TRUE;
3290
3291    return EINA_TRUE;
3292 }
3293
3294 static Eina_Bool
3295 _e_policy_restore_system_brightness(void)
3296 {
3297    Eina_Bool ret;
3298
3299    if (!e_policy_system_info.brightness.use_client) return EINA_TRUE;
3300
3301    // restore system brightness
3302    ret = _e_policy_system_brightness_set(e_policy_system_info.brightness.system);
3303    if (!ret)
3304      {
3305         return EINA_FALSE;
3306      }
3307    e_policy_system_info.brightness.use_client = EINA_FALSE;
3308
3309    // Todo:
3310    // if there are another window which set brighteness, then we change brighteness of it
3311    // if no, then we rollback system brightness
3312
3313    return EINA_TRUE;
3314 }
3315
3316 EINTERN Eina_Bool
3317 e_policy_wl_win_brightness_apply(E_Client *ec)
3318 {
3319    Eina_Bool ret;
3320    Eina_List *l;
3321    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3322    E_Policy_Wl_Dpy_Surface *dpy_surf = NULL;
3323    int ec_visibility;
3324
3325    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
3326    if (e_object_is_del(E_OBJECT(ec)))
3327      ec_visibility = E_VISIBILITY_FULLY_OBSCURED;
3328    else
3329      ec_visibility = ec->visibility.obscured;
3330
3331    EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
3332      {
3333         dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
3334         if (dpy_surf)
3335           break;
3336      }
3337
3338    if (!dpy_surf) return EINA_FALSE;
3339    if (!dpy_surf->set) return EINA_FALSE;
3340
3341    // use system brightness
3342    if (dpy_surf->brightness < 0)
3343      {
3344         ELOGF("TZ_DPY_POL", "Restore system brightness. Win(0x%08zx)'s brightness:%d", ec, e_client_util_win_get(ec), dpy_surf->brightness);
3345         ret = _e_policy_restore_system_brightness();
3346         return ret;
3347      }
3348
3349    if (ec_visibility == E_VISIBILITY_UNOBSCURED)
3350      {
3351         ELOGF("TZ_DPY_POL", "Change system brightness(%d). Win(0x%08zx) is un-obscured", ec, dpy_surf->brightness, e_client_util_win_get(ec));
3352         ret = _e_policy_change_system_brightness(dpy_surf->brightness);
3353         if (!ret) return EINA_FALSE;
3354      }
3355    else
3356      {
3357         ELOGF("TZ_DPY_POL", "Restore system brightness. Win(0x%08zx) is obscured", ec, e_client_util_win_get(ec));
3358         ret = _e_policy_restore_system_brightness();
3359         if (!ret) return EINA_FALSE;
3360      }
3361
3362    return EINA_TRUE;
3363 }
3364
3365 static void
3366 _tz_dpy_pol_iface_cb_brightness_set(struct wl_client *client, struct wl_resource *res_tz_dpy_pol, struct wl_resource *surf, int32_t brightness)
3367 {
3368    E_Client *ec;
3369    E_Policy_Wl_Dpy_Surface *dpy_surf;
3370    pid_t pid = 0;
3371    uid_t uid = 0;
3372    Eina_Bool res;
3373
3374    ec = e_client_from_surface_resource(surf);
3375    EINA_SAFETY_ON_NULL_RETURN(ec);
3376
3377    dpy_surf = _e_policy_wl_dpy_surf_add(ec, res_tz_dpy_pol);
3378    EINA_SAFETY_ON_NULL_RETURN(dpy_surf);
3379
3380    wl_client_get_credentials(client, &pid, &uid, NULL);
3381    res = e_security_privilege_check(pid, uid,
3382                                     E_PRIVILEGE_BRIGHTNESS_SET);
3383    if (!res)
3384      {
3385         ELOGF("TZ_DPY_POL",
3386               "Privilege Check Failed! DENY set_brightness",
3387               ec);
3388
3389         tizen_display_policy_send_window_brightness_done
3390            (res_tz_dpy_pol,
3391             surf,
3392             -1,
3393             TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED);
3394         return;
3395      }
3396    ELOGF("TZ_DPY_POL", "Set Win(0x%08zx)'s brightness:%d", ec, e_client_util_win_get(ec), brightness);
3397    dpy_surf->set = EINA_TRUE;
3398    dpy_surf->brightness = brightness;
3399
3400    e_policy_wl_win_brightness_apply(ec);
3401
3402    tizen_display_policy_send_window_brightness_done
3403       (res_tz_dpy_pol, surf, brightness, TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE);
3404 }
3405
3406 static void
3407 _tz_dpy_pol_iface_cb_destroy(struct wl_client *client, struct wl_resource *resource)
3408 {
3409    wl_resource_destroy(resource);
3410 }
3411
3412 static void
3413 _tzpol_iface_cb_subsurf_watcher_destroy(struct wl_resource *resource)
3414 {
3415    E_Client *ec;
3416    E_Comp_Wl_Client_Data *cdata;
3417
3418    if (!(ec = wl_resource_get_user_data(resource))) return;
3419    cdata = e_client_cdata_get(ec);
3420    if (!cdata) return;
3421
3422    cdata->sub.watcher = NULL;
3423 }
3424
3425 static void
3426 _tzpol_subsurf_watcher_iface_cb_destroy(struct wl_client *client, struct wl_resource *resource)
3427 {
3428    wl_resource_destroy(resource);
3429 }
3430
3431 static const struct tizen_subsurface_watcher_interface _tzpol_subsurf_watcher_iface =
3432 {
3433    _tzpol_subsurf_watcher_iface_cb_destroy,
3434 };
3435
3436 static void
3437 _tzpol_iface_cb_subsurf_watcher_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surface)
3438 {
3439    E_Client *ec;
3440    E_Comp_Wl_Client_Data *cdata;
3441    struct wl_resource *res;
3442
3443    if (!(ec = e_client_from_surface_resource(surface))) return;
3444    if (e_object_is_del(E_OBJECT(ec))) return;
3445    cdata = e_client_cdata_get(ec);
3446    if (!cdata) return;
3447
3448    if (!(res = wl_resource_create(client, &tizen_subsurface_watcher_interface, 1, id)))
3449      {
3450         wl_resource_post_no_memory(res_tzpol);
3451         return;
3452      }
3453
3454    cdata->sub.watcher = res;
3455
3456    wl_resource_set_implementation(res,
3457                                   &_tzpol_subsurf_watcher_iface,
3458                                   ec,
3459                                   _tzpol_iface_cb_subsurf_watcher_destroy);
3460 }
3461
3462 static void
3463 _tzpol_iface_cb_parent_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *child, struct wl_resource *parent)
3464 {
3465    E_Client *ec, *parent_ec;
3466
3467    ELOGF("TZPOL",
3468          "PARENT_SET   |res_tzpol:%8p|parent_surf:%8p|child_surf:%8p",
3469          NULL, res_tzpol, parent, child);
3470
3471    ec = e_client_from_surface_resource(child);
3472    EINA_SAFETY_ON_NULL_RETURN(ec);
3473
3474    parent_ec = e_client_from_surface_resource(parent);
3475    e_policy_stack_parent_set(ec, parent_ec);
3476 }
3477
3478 static void
3479 _tzpol_iface_cb_ack_conformant_region(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surface, uint32_t serial)
3480 {
3481    E_Client *ec;
3482
3483    if (!(ec = e_client_from_surface_resource(surface))) return;
3484
3485    e_policy_conformant_client_ack(ec, res_tzpol, serial);
3486 }
3487
3488 static void
3489 _tzpol_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzpol)
3490 {
3491    wl_resource_destroy(res_tzpol);
3492 }
3493
3494 static void
3495 _tzpol_iface_cb_has_video(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surface, uint32_t has)
3496 {
3497    E_Client *ec;
3498    E_Comp_Wl_Client_Data *cdata;
3499
3500    if (!(ec = e_client_from_surface_resource(surface))) return;
3501    if (e_object_is_del(E_OBJECT(ec))) return;
3502    cdata = e_client_cdata_get(ec);
3503    if (!cdata) return;
3504    if (cdata->has_video_client == has) return;
3505
3506    ELOGF("TZPOL", "video client has(%d)", ec, has);
3507
3508    cdata->has_video_client = has;
3509 }
3510
3511 static void
3512 _tzpol_iface_cb_set_appid(struct wl_client *client, struct wl_resource *res_tzpol, int32_t pid, const char *appid)
3513 {
3514    E_Policy_Wl_Tzpol *tzpol;
3515    E_Appinfo *eai;
3516
3517    tzpol = _e_policy_wl_tzpol_get(res_tzpol);
3518    EINA_SAFETY_ON_NULL_RETURN(tzpol);
3519
3520    ELOGF("TZPOL", "Set appid(%s) pid(%d)", NULL, appid, pid);
3521
3522    if (!(eai = e_appinfo_find_with_appid(appid)))
3523      {
3524         eai = e_appinfo_new();
3525         e_appinfo_appid_set(eai, appid);
3526         e_appinfo_owner_set(eai, E_APPINFO_OWNER_CLIENT);
3527      }
3528    EINA_SAFETY_ON_NULL_RETURN(eai);
3529
3530    e_appinfo_pid_set(eai, pid);
3531 }
3532
3533 static void
3534 _tzpol_iface_cb_show(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
3535 {
3536    E_Client *ec;
3537    E_Comp_Wl_Client_Data *cdata;
3538
3539    ec = e_client_from_surface_resource(surf);
3540    EINA_SAFETY_ON_NULL_RETURN(ec);
3541    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
3542
3543    ELOGF("TZPOL", "Prepare SHOW (wait for buffer attach)", ec);
3544
3545    cdata = e_client_cdata_get(ec);
3546    if (cdata && !cdata->mapped)
3547      {
3548         if (e_config->raise_before_show)
3549           {
3550              e_client_raise(ec);
3551              ec->post_raise = EINA_FALSE;
3552           }
3553      }
3554 }
3555
3556 static void
3557 _tzpol_iface_cb_hide(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
3558 {
3559    E_Client *ec;
3560
3561    ec = e_client_from_surface_resource(surf);
3562    EINA_SAFETY_ON_NULL_RETURN(ec);
3563    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
3564
3565    ELOGF("TZPOL", "Prepare HIDE (wait for NULL buffer attach)", ec);
3566 }
3567
3568 static void
3569 _tzpol_iface_cb_set_transient_for_below(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol, uint32_t child_id, uint32_t parent_id)
3570 {
3571    E_Client *ec, *parent_ec;
3572    E_Comp_Wl_Client_Data *cdata, *p_cdata;
3573
3574    ELOGF("TZPOL",
3575          "TF_SET(B) |res_tzpol:%8p|parent_id:%8d  |child_id:%8d",
3576          NULL, res_tzpol, parent_id, child_id);
3577
3578    ec = e_pixmap_find_client_by_res_id(child_id);
3579    EINA_SAFETY_ON_NULL_RETURN(ec);
3580    parent_ec = e_pixmap_find_client_by_res_id(parent_id);
3581
3582    cdata = e_client_cdata_get(ec);
3583    p_cdata = e_client_cdata_get(parent_ec);
3584    ELOGF("TZPOL",
3585          "          |res_tzpol:%8p|parent_surf:%8p|child_surf:%8p",
3586          NULL, res_tzpol, (p_cdata ? p_cdata->surface : NULL), (cdata ? cdata->surface : NULL));
3587
3588    e_policy_stack_transient_for_below_set(ec, parent_ec, EINA_TRUE);
3589 }
3590
3591 static void
3592 _tzpol_iface_cb_set_parent_with_below(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *child, struct wl_resource *parent)
3593 {
3594    E_Client *ec, *parent_ec;
3595
3596    ELOGF("TZPOL",
3597          "PARENT_SET(B)|res_tzpol:%8p|parent_surf:%8p|child_surf:%8p",
3598          NULL, res_tzpol, parent, child);
3599
3600    ec = e_client_from_surface_resource(child);
3601    EINA_SAFETY_ON_NULL_RETURN(ec);
3602
3603    if (parent)
3604      parent_ec = e_client_from_surface_resource(parent);
3605    else
3606      parent_ec = NULL;
3607
3608    e_policy_stack_transient_for_below_set(ec, parent_ec, EINA_FALSE);
3609 }
3610
3611 static void
3612 _tzpol_iface_cb_set_maximize_direction(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf, uint32_t direction)
3613 {
3614    E_Client *ec;
3615
3616    ec = e_client_from_surface_resource(surf);
3617    EINA_SAFETY_ON_NULL_RETURN(ec);
3618    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
3619
3620    ELOGF("TZPOL", "Set Maximize_direction. direction:%d", ec, direction);
3621
3622    if (direction == TIZEN_POLICY_MAXIMIZE_DIRECTION_NONE)
3623      {
3624         ec->maximize_dir = E_MAXIMIZE_DIRECTION_NONE;
3625         e_client_unmaximize(ec, E_MAXIMIZE_BOTH);
3626      }
3627    else if (direction == TIZEN_POLICY_MAXIMIZE_DIRECTION_ALL)
3628      {
3629         ec->maximize_dir = E_MAXIMIZE_DIRECTION_ALL;
3630         e_client_maximize(ec, E_MAXIMIZE_EXPAND | E_MAXIMIZE_BOTH);
3631      }
3632    else if (direction == TIZEN_POLICY_MAXIMIZE_DIRECTION_LEFT)
3633      {
3634         ec->maximize_dir = E_MAXIMIZE_DIRECTION_LEFT;
3635         e_client_maximize(ec, E_MAXIMIZE_EXPAND | E_MAXIMIZE_LEFT);
3636      }
3637    else if (direction == TIZEN_POLICY_MAXIMIZE_DIRECTION_RIGHT)
3638      {
3639         ec->maximize_dir = E_MAXIMIZE_DIRECTION_RIGHT;
3640         e_client_maximize(ec, E_MAXIMIZE_EXPAND | E_MAXIMIZE_RIGHT);
3641      }
3642    else
3643      {
3644         ELOGF("TZPOL", "Not supported direction:%d", ec, direction);
3645      }
3646 }
3647
3648 static void
3649 _e_policy_set_pin_mode(E_Client *ec, Eina_Bool pinned)
3650 {
3651    EINA_SAFETY_ON_NULL_RETURN(ec);
3652    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
3653
3654    ELOGF("TZPOL", "Set Pin mode to %d", ec, pinned);
3655    e_client_pinned_set(ec, pinned);
3656 }
3657
3658 static void
3659 _tzpol_iface_cb_set_pin_mode(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
3660 {
3661    E_Client *ec;
3662
3663    ec = e_client_from_surface_resource(surf);
3664    _e_policy_set_pin_mode(ec, EINA_TRUE);
3665 }
3666
3667 static void
3668 _tzpol_iface_cb_unset_pin_mode(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf)
3669 {
3670    E_Client *ec;
3671
3672    ec = e_client_from_surface_resource(surf);
3673    _e_policy_set_pin_mode(ec, EINA_FALSE);
3674 }
3675
3676 static void
3677 _tzpol_iface_cb_set_layout(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzpol EINA_UNUSED, struct wl_resource *surf, uint32_t num_cols, uint32_t num_rows, uint32_t column, uint32_t row, uint32_t col_span, uint32_t row_span)
3678 {
3679    E_Client *ec;
3680
3681    int unit_w, unit_h;
3682    int x, y, w, h;
3683    ec = e_client_from_surface_resource(surf);
3684    if (!ec) return;
3685
3686    unit_w = ec->desk->geom.w / num_cols;
3687    unit_h = ec->desk->geom.h / num_rows;
3688
3689    x = unit_w * column;
3690    y = unit_h * row;
3691    w = unit_w * col_span;
3692    h = unit_h * row_span;
3693
3694    // TODO: We may need to adjust the last size if the unit size is not devided exactly
3695
3696    ELOGF("TZPOL", "TIZEN_POLICY_SET_LAYOUT... total_layout(%d,%d) -> unit_size(%dx%d). request(%d,%d,%d,%d) -> geo(%d,%d,%dx%d)",
3697          ec, num_cols, num_rows, unit_w, unit_h, column, row, col_span, row_span, x, y, w, h);
3698
3699    // Apply shadow size (left, right, top, bottom)
3700    x -= ec->manage_resize.shadow.l;
3701    y -= ec->manage_resize.shadow.t;
3702    w = w + ec->manage_resize.shadow.l + ec->manage_resize.shadow.r;
3703    h = h + ec->manage_resize.shadow.t + ec->manage_resize.shadow.b;
3704
3705    ELOGF("TZPOL", "Consider Shadow size(l:%d,r:%d,t:%d,b:%d). new (%d,%d,%dx%d)",
3706          ec, ec->manage_resize.shadow.l, ec->manage_resize.shadow.r, ec->manage_resize.shadow.t, ec->manage_resize.shadow.b, x, y, w, h);
3707
3708    e_client_layout_apply(ec, EINA_TRUE);
3709    e_client_frame_geometry_set(ec, x, y, w, h);
3710
3711    if (!ec->visible)
3712      {
3713         E_Comp_Wl_Client_Data *cdata;
3714         cdata = e_client_cdata_get(ec);
3715         if (cdata && cdata->shell.configure_send && cdata->shell.surface)
3716           {
3717              cdata->shell.configure_send(cdata->shell.surface, 0, w, h);
3718           }
3719      }
3720 }
3721
3722 // --------------------------------------------------------
3723 // tizen_policy_interface
3724 // --------------------------------------------------------
3725 static const struct tizen_policy_interface _tzpol_iface =
3726 {
3727    _tzpol_iface_cb_vis_get,
3728    _tzpol_iface_cb_pos_get,
3729    _tzpol_iface_cb_activate,
3730    _tzpol_iface_cb_activate_below_by_res_id,
3731    _tzpol_iface_cb_raise,
3732    _tzpol_iface_cb_lower,
3733    _tzpol_iface_cb_lower_by_res_id,
3734    _tzpol_iface_cb_focus_skip_set,
3735    _tzpol_iface_cb_focus_skip_unset,
3736    _tzpol_iface_cb_role_set,
3737    _tzpol_iface_cb_type_set,
3738    _tzpol_iface_cb_conformant_set,
3739    _tzpol_iface_cb_conformant_unset,
3740    _tzpol_iface_cb_conformant_get,
3741    _tzpol_iface_cb_notilv_set,
3742    _tzpol_iface_cb_transient_for_set,
3743    _tzpol_iface_cb_transient_for_unset,
3744    _tzpol_iface_cb_win_scrmode_set,
3745    _tzpol_iface_cb_subsurf_place_below_parent,
3746    _tzpol_iface_cb_subsurf_stand_alone_set,
3747    _tzpol_iface_cb_subsurface_get,
3748    _tzpol_iface_cb_opaque_state_set,
3749    _tzpol_iface_cb_iconify,
3750    _tzpol_iface_cb_uniconify,
3751    _tzpol_iface_cb_aux_hint_add,
3752    _tzpol_iface_cb_aux_hint_change,
3753    _tzpol_iface_cb_aux_hint_del,
3754    _tzpol_iface_cb_supported_aux_hints_get,
3755    _tzpol_iface_cb_background_state_set,
3756    _tzpol_iface_cb_background_state_unset,
3757    _tzpol_iface_cb_floating_mode_set,
3758    _tzpol_iface_cb_floating_mode_unset,
3759    _tzpol_iface_cb_stack_mode_set,
3760    _tzpol_iface_cb_activate_above_by_res_id,
3761    _tzpol_iface_cb_subsurf_watcher_get,
3762    _tzpol_iface_cb_parent_set,
3763    _tzpol_iface_cb_ack_conformant_region,
3764    _tzpol_iface_cb_destroy,
3765    _tzpol_iface_cb_has_video,
3766    _tzpol_iface_cb_set_appid,
3767    _tzpol_iface_cb_show,
3768    _tzpol_iface_cb_hide,
3769    _tzpol_iface_cb_set_transient_for_below,
3770    _tzpol_iface_cb_set_parent_with_below,
3771    _tzpol_iface_cb_set_maximize_direction,
3772    _tzpol_iface_cb_set_pin_mode,
3773    _tzpol_iface_cb_unset_pin_mode,
3774    _tzpol_iface_cb_set_layout
3775 };
3776
3777 static void
3778 _tzpol_cb_unbind(struct wl_resource *res_tzpol)
3779 {
3780    E_Policy_Wl_Tzpol *tzpol;
3781
3782    tzpol = _e_policy_wl_tzpol_get(res_tzpol);
3783    EINA_SAFETY_ON_NULL_RETURN(tzpol);
3784
3785    eina_hash_del_by_key(polwl->tzpols, &res_tzpol);
3786 }
3787
3788 static void
3789 _tzpol_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
3790 {
3791    E_Policy_Wl_Tzpol *tzpol;
3792    struct wl_resource *res_tzpol;
3793
3794    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
3795
3796    res_tzpol = wl_resource_create(client,
3797                                   &tizen_policy_interface,
3798                                   ver,
3799                                   id);
3800    EINA_SAFETY_ON_NULL_GOTO(res_tzpol, err);
3801
3802    tzpol = _e_policy_wl_tzpol_add(client, res_tzpol);
3803    EINA_SAFETY_ON_NULL_GOTO(tzpol, err);
3804
3805    wl_resource_set_implementation(res_tzpol,
3806                                   &_tzpol_iface,
3807                                   NULL,
3808                                   _tzpol_cb_unbind);
3809    return;
3810
3811 err:
3812    ERR("Could not create tizen_policy_interface res: %m");
3813    wl_client_post_no_memory(client);
3814 }
3815
3816 // --------------------------------------------------------
3817 // tizen_display_policy_interface
3818 // --------------------------------------------------------
3819 static const struct tizen_display_policy_interface _tz_dpy_pol_iface =
3820 {
3821    _tz_dpy_pol_iface_cb_brightness_set,
3822    _tz_dpy_pol_iface_cb_destroy,
3823 };
3824
3825 static void
3826 _tz_dpy_pol_cb_unbind(struct wl_resource *res_tz_dpy_pol)
3827 {
3828    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3829
3830    tz_dpy_pol = _e_policy_wl_tz_dpy_pol_get(res_tz_dpy_pol);
3831    EINA_SAFETY_ON_NULL_RETURN(tz_dpy_pol);
3832
3833    _e_policy_wl_tz_dpy_pol_del(tz_dpy_pol);
3834 }
3835
3836 static void
3837 _tz_dpy_pol_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
3838 {
3839    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
3840    struct wl_resource *res_tz_dpy_pol;
3841
3842    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
3843
3844    res_tz_dpy_pol = wl_resource_create(client,
3845                                        &tizen_display_policy_interface,
3846                                        ver,
3847                                        id);
3848    EINA_SAFETY_ON_NULL_GOTO(res_tz_dpy_pol, err);
3849
3850    tz_dpy_pol = _e_policy_wl_tz_dpy_pol_add(res_tz_dpy_pol);
3851    EINA_SAFETY_ON_NULL_GOTO(tz_dpy_pol, err);
3852
3853    wl_resource_set_implementation(res_tz_dpy_pol,
3854                                   &_tz_dpy_pol_iface,
3855                                   NULL,
3856                                   _tz_dpy_pol_cb_unbind);
3857    return;
3858
3859 err:
3860    ERR("Could not create tizen_display_policy_interface res: %m");
3861    wl_client_post_no_memory(client);
3862 }
3863
3864 // --------------------------------------------------------
3865 // tizen_ws_shell_interface::service
3866 // --------------------------------------------------------
3867 static void
3868 _tzsh_srv_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_srv)
3869 {
3870    wl_resource_destroy(res_tzsh_srv);
3871 }
3872
3873 static void
3874 _tzsh_srv_iface_cb_region_set(struct wl_client *client, struct wl_resource *res_tzsh_srv, int32_t type, int32_t angle, struct wl_resource *res_reg)
3875 {
3876    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
3877    E_Policy_Wl_Tzsh_Region *tzsh_reg;
3878
3879    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
3880    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
3881
3882    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
3883      return;
3884
3885    tzsh_reg = wl_resource_get_user_data(res_reg);
3886    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg);
3887
3888    if ((tzsh_srv->role == TZSH_SRV_ROLE_QUICKPANEL_SYSTEM_DEFAULT) ||
3889        (tzsh_srv->role == TZSH_SRV_ROLE_QUICKPANEL_CONTEXT_MENU) ||
3890        (tzsh_srv->role == TZSH_SRV_ROLE_QUICKPANEL_APPS_MENU))
3891      {
3892         EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
3893         EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->ec);
3894
3895         e_service_quickpanel_region_set(tzsh_srv->ec,
3896                                         type,
3897                                         angle,
3898                                         tzsh_reg->tiler);
3899      }
3900    else if (tzsh_srv->role == TZSH_SRV_ROLE_VOLUME)
3901      e_service_volume_region_set(type, angle, tzsh_reg->tiler);
3902    else if (tzsh_srv->role == TZSH_SRV_ROLE_SOFTKEY)
3903      {
3904         if (e_config->use_softkey_service)
3905           {
3906              EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
3907              EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->ec);
3908
3909              e_service_softkey_handler_region_set(tzsh_srv->ec, angle, tzsh_reg->tiler);
3910           }
3911      }
3912 }
3913
3914 static void
3915 _tzsh_srv_indicator_cb_resource_destroy(struct wl_resource *resource)
3916 {
3917    if (_indicator_srv_res == resource)
3918      _indicator_srv_res = NULL;
3919 }
3920
3921 static void
3922 _tzsh_srv_indicator_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
3923 {
3924    _indicator_srv_res = NULL;
3925    wl_resource_destroy(resource);
3926 }
3927
3928 static const struct tws_service_indicator_interface _tzsh_srv_indicator_iface =
3929 {
3930    _tzsh_srv_indicator_cb_destroy,
3931 };
3932
3933 static void
3934 _tzsh_srv_iface_cb_indicator_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
3935 {
3936    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
3937    struct wl_resource *res;
3938
3939    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
3940    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
3941
3942    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
3943      return;
3944
3945    res = wl_resource_create(client, &tws_service_indicator_interface, 1, id);
3946    if (!res)
3947      {
3948         wl_client_post_no_memory(client);
3949         return;
3950      }
3951    _indicator_srv_res = res;
3952
3953    wl_resource_set_implementation(res, &_tzsh_srv_indicator_iface, tzsh_srv,
3954                                   _tzsh_srv_indicator_cb_resource_destroy);
3955 }
3956
3957 static void
3958 _tzsh_srv_qp_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
3959 {
3960    wl_resource_destroy(resource);
3961 }
3962
3963 static void
3964 _tzsh_srv_qp_cb_msg(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t msg)
3965 {
3966    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
3967
3968    tzsh_srv = wl_resource_get_user_data(resource);
3969
3970    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
3971    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
3972
3973 #define EC  tzsh_srv->ec
3974    EINA_SAFETY_ON_NULL_RETURN(EC);
3975
3976    switch (msg)
3977      {
3978       case TWS_SERVICE_QUICKPANEL_MSG_SHOW:
3979          e_service_quickpanel_show(EC);
3980          break;
3981       case TWS_SERVICE_QUICKPANEL_MSG_HIDE:
3982          e_service_quickpanel_hide(EC);
3983          break;
3984       default:
3985          ERR("Unknown message!! msg %d", msg);
3986          break;
3987      }
3988 #undef EC
3989 }
3990
3991 static void
3992 _tzsh_srv_qp_cb_effect_type_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t type)
3993 {
3994    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
3995
3996    tzsh_srv = wl_resource_get_user_data(resource);
3997
3998    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
3999    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4000
4001 #define EC  tzsh_srv->ec
4002    EINA_SAFETY_ON_NULL_RETURN(EC);
4003    e_service_quickpanel_effect_type_set(EC, type);
4004 #undef EC
4005 }
4006
4007 static void
4008 _tzsh_srv_qp_cb_scroll_lock_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t lock)
4009 {
4010    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4011
4012    tzsh_srv = wl_resource_get_user_data(resource);
4013
4014    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4015    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4016
4017 #define EC  tzsh_srv->ec
4018    EINA_SAFETY_ON_NULL_RETURN(EC);
4019    e_service_quickpanel_scroll_lock_set(EC, lock);
4020 #undef EC
4021 }
4022
4023 static const struct tws_service_quickpanel_interface _tzsh_srv_qp_iface =
4024 {
4025    _tzsh_srv_qp_cb_destroy,
4026    _tzsh_srv_qp_cb_msg,
4027    _tzsh_srv_qp_cb_effect_type_set,
4028    _tzsh_srv_qp_cb_scroll_lock_set,
4029 };
4030
4031 static void
4032 _tzsh_srv_iface_cb_quickpanel_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4033 {
4034    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4035    struct wl_resource *res;
4036
4037    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4038    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4039
4040    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4041      return;
4042
4043    res = wl_resource_create(client,
4044                             &tws_service_quickpanel_interface,
4045                             wl_resource_get_version(res_tzsh_srv),
4046                             id);
4047    if (!res)
4048      {
4049         wl_client_post_no_memory(client);
4050         return;
4051      }
4052
4053    wl_resource_set_implementation(res, &_tzsh_srv_qp_iface, tzsh_srv, NULL);
4054 }
4055
4056
4057
4058 static void
4059 _tzsh_srv_softkey_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4060 {
4061    wl_resource_destroy(resource);
4062 }
4063
4064 static void
4065 _tzsh_srv_softkey_cb_msg_send(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t msg)
4066 {
4067    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4068    E_Service_Softkey *softkey_service;
4069    E_Zone *zone;
4070
4071    tzsh_srv = wl_resource_get_user_data(resource);
4072
4073    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4074    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4075
4076    zone = tzsh_srv->zone;
4077    EINA_SAFETY_ON_NULL_RETURN(zone);
4078
4079    softkey_service = e_service_softkey_get(zone);
4080    EINA_SAFETY_ON_NULL_RETURN(softkey_service);
4081
4082    switch (msg)
4083      {
4084       case TWS_SERVICE_SOFTKEY_MSG_SHOW:
4085          e_service_softkey_show(softkey_service);
4086          break;
4087       case TWS_SERVICE_SOFTKEY_MSG_HIDE:
4088          e_service_softkey_hide(softkey_service);
4089          break;
4090       default:
4091          ERR("Unknown message!! msg %d", msg);
4092          break;
4093      }
4094 }
4095
4096 static const struct tws_service_softkey_interface _tzsh_srv_softkey_iface =
4097 {
4098    _tzsh_srv_softkey_cb_destroy,
4099    _tzsh_srv_softkey_cb_msg_send,
4100 };
4101
4102 static void
4103 _tzsh_srv_iface_cb_softkey_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4104 {
4105    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4106    E_Service_Softkey *softkey_service = NULL;
4107    struct wl_resource *res;
4108
4109    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4110    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4111
4112    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4113      return;
4114
4115    res = wl_resource_create(client, &tws_service_softkey_interface, 1, id);
4116    if (!res)
4117      {
4118         wl_client_post_no_memory(client);
4119         return;
4120      }
4121
4122    ELOGF("TZSH", "[SOFTKEY SERVICE] resource created. res:%p, res_tzsh_srv:%p, id:%d", NULL, res, res_tzsh_srv, id);
4123
4124    if (tzsh_srv->tzsh)
4125      {
4126         E_Zone *zone = tzsh_srv->zone;
4127         if (zone)
4128           softkey_service = e_service_softkey_get(zone);
4129         ELOGF("TZSH", "[SOFTKEY SERVICE] resource set. res:%p, softkey_service:%p, softkey_ec:%p", NULL, res, softkey_service, tzsh_srv->ec);
4130         if (softkey_service)
4131           {
4132              e_service_softkey_wl_resource_set(softkey_service, res);
4133              e_service_softkey_restore_visible_request(softkey_service);
4134           }
4135      }
4136
4137    wl_resource_set_implementation(res, &_tzsh_srv_softkey_iface, tzsh_srv, NULL);
4138 }
4139
4140 static void
4141 _tzsh_srv_magnifier_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4142 {
4143    wl_resource_destroy(resource);
4144 }
4145
4146 static void
4147 _tzsh_srv_magnifier_cb_zoom_geometry_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t angle, int32_t x, int32_t y, uint32_t w, uint32_t h)
4148 {
4149    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4150    E_Client *ec;
4151
4152    tzsh_srv = wl_resource_get_user_data(resource);
4153
4154    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4155    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4156    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->ec);
4157
4158    ELOGF("TZSH", "[MAGNIFIER] Set Geometry. angle:%d, geo:%d,%d,%dx%d", tzsh_srv->ec, angle, x, y, w, h);
4159
4160    ec = tzsh_srv->ec;
4161    // angle: 0, 90, 180, 270
4162    e_magnifier_zoom_obj_geometry_set(ec, angle, x, y, w, h);
4163 }
4164
4165 static void
4166 _tzsh_srv_magnifier_cb_ratio_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t ratio)
4167 {
4168    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4169    E_Client *ec;
4170
4171    tzsh_srv = wl_resource_get_user_data(resource);
4172
4173    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4174    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4175    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->ec);
4176
4177    ELOGF("TZSH", "[MAGNIFIER] Set Ratio. ratio:%d", tzsh_srv->ec, ratio);
4178
4179    ec = tzsh_srv->ec;
4180    // ratio : 100 ~ 200 (each 10)
4181    e_magnifier_zoom_obj_ratio_set(ec, ratio);
4182 }
4183
4184 static void
4185 _tzsh_srv_magnifier_cb_enable_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t enable)
4186 {
4187    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4188    E_Client *ec;
4189
4190    tzsh_srv = wl_resource_get_user_data(resource);
4191
4192    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4193    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4194    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->ec);
4195
4196    ELOGF("TZSH", "[MAGNIFIER] Set Enable. enable:%d", tzsh_srv->ec, enable);
4197
4198    ec = tzsh_srv->ec;
4199
4200    if (enable)
4201      e_magnifier_show(ec);
4202    else
4203      e_magnifier_hide(ec);
4204 }
4205
4206 static const struct tws_service_magnifier_interface _tzsh_srv_magnifier_iface =
4207 {
4208    _tzsh_srv_magnifier_cb_destroy,
4209    _tzsh_srv_magnifier_cb_zoom_geometry_set,
4210    _tzsh_srv_magnifier_cb_ratio_set,
4211    _tzsh_srv_magnifier_cb_enable_set,
4212 };
4213
4214 static void
4215 _tzsh_srv_iface_cb_magnifier_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4216 {
4217    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4218    struct wl_resource *res;
4219
4220    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4221    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4222
4223    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4224      return;
4225
4226    res = wl_resource_create(client, &tws_service_magnifier_interface, 1, id);
4227    if (!res)
4228      {
4229         wl_client_post_no_memory(client);
4230         return;
4231      }
4232
4233    ELOGF("TZSH", "[MAGNIFIER] resource created. res:%p, res_tzsh_srv:%p, id:%d", NULL, res, res_tzsh_srv, id);
4234    wl_resource_set_implementation(res, &_tzsh_srv_magnifier_iface, tzsh_srv, NULL);
4235 }
4236
4237 //////////////////////////////////////////////////////////////////////////////////////////////////////
4238 static void
4239 _tzsh_srv_scrsaver_cb_release(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4240 {
4241    wl_resource_destroy(resource);
4242 }
4243
4244 static const struct tws_service_screensaver_interface _tzsh_srv_scrsaver_iface =
4245 {
4246    _tzsh_srv_scrsaver_cb_release
4247 };
4248
4249 static void
4250 _tzsh_srv_iface_cb_scrsaver_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4251 {
4252    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4253    struct wl_resource *res;
4254
4255    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4256    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4257
4258    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4259      return;
4260
4261    res = wl_resource_create(client, &tws_service_screensaver_interface, 1, id);
4262    if (!res)
4263      {
4264         wl_client_post_no_memory(client);
4265         return;
4266      }
4267
4268    wl_resource_set_implementation(res, &_tzsh_srv_scrsaver_iface, tzsh_srv, NULL);
4269 }
4270
4271 static void
4272 _tzsh_srv_scrsaver_mng_cb_resource_destroy(struct wl_resource *resource)
4273 {
4274    if (_scrsaver_mng_res == resource)
4275      {
4276         _scrsaver_mng_res = NULL;
4277         e_screensaver_disable();
4278      }
4279 }
4280
4281 static void
4282 _tzsh_srv_scrsaver_mng_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4283 {
4284    _scrsaver_mng_res = NULL;
4285    wl_resource_destroy(resource);
4286    e_screensaver_disable();
4287 }
4288
4289 static void
4290 _tzsh_srv_scrsaver_mng_cb_enable(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4291 {
4292    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4293
4294    tzsh_srv = wl_resource_get_user_data(resource);
4295
4296    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4297    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4298
4299    e_screensaver_enable();
4300 }
4301
4302 static void
4303 _tzsh_srv_scrsaver_mng_cb_disable(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4304 {
4305    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4306
4307    tzsh_srv = wl_resource_get_user_data(resource);
4308
4309    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4310    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4311
4312    e_screensaver_disable();
4313 }
4314
4315 static void
4316 _tzsh_srv_scrsaver_mng_cb_idle_time_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t time)
4317 {
4318    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4319    double timeout;
4320
4321    tzsh_srv = wl_resource_get_user_data(resource);
4322
4323    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4324    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4325
4326    /* convert time to seconds (double) from milliseconds (unsigned int) */
4327    timeout = (double)time * 0.001f;
4328
4329    e_screensaver_timeout_set(timeout);
4330 }
4331
4332 static void
4333 _tzsh_srv_scrsaver_mng_cb_state_get(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t type)
4334 {
4335    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4336    uint32_t val = 0;
4337    double timeout;
4338
4339    tzsh_srv = wl_resource_get_user_data(resource);
4340
4341    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4342    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4343
4344    switch (type)
4345      {
4346       case TWS_SERVICE_SCREENSAVER_MANAGER_STATE_TYPE_IDLE_TIMEOUT:
4347         /* convert time to milliseconds (unsigned int) from seconds (double) */
4348         timeout = e_screensaver_timeout_get();
4349         val = (uint32_t)(timeout * 1000);
4350         break;
4351       default:
4352         break;
4353      }
4354
4355    tws_service_screensaver_manager_send_state_get_done(resource, type, val, 0);
4356 }
4357
4358 static const struct tws_service_screensaver_manager_interface _tzsh_srv_scrsaver_mng_iface =
4359 {
4360    _tzsh_srv_scrsaver_mng_cb_destroy,
4361    _tzsh_srv_scrsaver_mng_cb_enable,
4362    _tzsh_srv_scrsaver_mng_cb_disable,
4363    _tzsh_srv_scrsaver_mng_cb_idle_time_set,
4364    _tzsh_srv_scrsaver_mng_cb_state_get
4365 };
4366
4367 static void
4368 _tzsh_srv_iface_cb_scrsaver_mng_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4369 {
4370    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4371    struct wl_resource *res;
4372
4373    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4374    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4375
4376    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4377      return;
4378
4379    res = wl_resource_create(client, &tws_service_screensaver_manager_interface, 1, id);
4380    if (!res)
4381      {
4382         wl_client_post_no_memory(client);
4383         return;
4384      }
4385
4386    _scrsaver_mng_res = res;
4387
4388    wl_resource_set_implementation(res, &_tzsh_srv_scrsaver_mng_iface, tzsh_srv,
4389                                   _tzsh_srv_scrsaver_mng_cb_resource_destroy);
4390 }
4391
4392 static void
4393 _tzsh_srv_cbhm_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4394 {
4395    wl_resource_destroy(resource);
4396 }
4397
4398 static void
4399 _tzsh_srv_cbhm_cb_msg(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t msg)
4400 {
4401    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4402
4403    tzsh_srv = wl_resource_get_user_data(resource);
4404
4405    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4406    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4407
4408 #define EC  tzsh_srv->ec
4409    EINA_SAFETY_ON_NULL_RETURN(EC);
4410
4411    switch (msg)
4412      {
4413       case TWS_SERVICE_CBHM_MSG_SHOW:
4414          e_service_cbhm_show();
4415          break;
4416       case TWS_SERVICE_CBHM_MSG_HIDE:
4417          e_service_cbhm_hide();
4418          break;
4419       case TWS_SERVICE_CBHM_MSG_DATA_SELECTED:
4420          e_service_cbhm_data_selected();
4421          break;
4422       default:
4423          ERR("Unknown message!! msg %d", msg);
4424          break;
4425      }
4426 #undef EC
4427 }
4428
4429 static const struct tws_service_cbhm_interface _tzsh_srv_cbhm_iface =
4430 {
4431    _tzsh_srv_cbhm_cb_destroy,
4432    _tzsh_srv_cbhm_cb_msg
4433 };
4434
4435 static void
4436 _tzsh_srv_iface_cb_cbhm_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4437 {
4438    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4439    struct wl_resource *res;
4440
4441    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4442    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4443
4444    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4445      return;
4446
4447    res = wl_resource_create(client, &tws_service_cbhm_interface, 1, id);
4448    if (!res)
4449      {
4450         wl_client_post_no_memory(client);
4451         return;
4452      }
4453
4454    wl_resource_set_implementation(res, &_tzsh_srv_cbhm_iface, tzsh_srv, NULL);
4455 }
4456
4457
4458 static void
4459 _tzsh_srv_iface_cb_launcher_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4460 {
4461    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4462    struct wl_resource *res;
4463
4464    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4465    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4466    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4467
4468    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4469      return;
4470
4471    res = wl_resource_create(client, &tws_service_launcher_interface, 1, id);
4472    if (!res)
4473      {
4474         wl_client_post_no_memory(client);
4475         return;
4476      }
4477
4478    if (tzsh_srv->ec)
4479      e_service_launcher_resource_set(tzsh_srv->ec, res);
4480 }
4481
4482 static void
4483 _tzsh_srv_taskbar_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4484 {
4485    wl_resource_destroy(resource);
4486 }
4487
4488 static void
4489 _tzsh_srv_taskbar_cb_place_type_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t place_type)
4490 {
4491    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4492    E_Client *ec;
4493
4494    tzsh_srv = wl_resource_get_user_data(resource);
4495    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4496    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4497
4498    ec = tzsh_srv->ec;
4499    EINA_SAFETY_ON_NULL_RETURN(ec);
4500
4501    e_service_taskbar_place_type_set(ec, place_type);
4502 }
4503
4504 static void
4505 _tzsh_srv_taskbar_cb_size_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t width, uint32_t height)
4506 {
4507    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4508    E_Client *ec;
4509
4510    tzsh_srv = wl_resource_get_user_data(resource);
4511    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4512    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4513
4514    ec = tzsh_srv->ec;
4515    EINA_SAFETY_ON_NULL_RETURN(ec);
4516
4517    e_service_taskbar_size_set(ec, width, height);
4518 }
4519
4520 static void
4521 _tzsh_srv_taskbar_cb_auto_placement_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t auto_placement)
4522 {
4523    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4524    E_Client *ec;
4525
4526    tzsh_srv = wl_resource_get_user_data(resource);
4527    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4528    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4529
4530    ec = tzsh_srv->ec;
4531    EINA_SAFETY_ON_NULL_RETURN(ec);
4532
4533    e_service_taskbar_auto_placement_set(ec, auto_placement);
4534 }
4535
4536 static const struct tws_service_taskbar_interface _tzsh_srv_taskbar_iface =
4537 {
4538    _tzsh_srv_taskbar_cb_destroy,
4539    _tzsh_srv_taskbar_cb_place_type_set,
4540    _tzsh_srv_taskbar_cb_size_set,
4541    _tzsh_srv_taskbar_cb_auto_placement_set,
4542 };
4543
4544 static void
4545 _tzsh_srv_iface_cb_taskbar_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4546 {
4547    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4548    struct wl_resource *res;
4549
4550    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4551    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4552    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4553
4554    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4555      return;
4556
4557    res = wl_resource_create(client,
4558                             &tws_service_taskbar_interface,
4559                             1,
4560                             id);
4561    if (!res)
4562      {
4563         wl_client_post_no_memory(client);
4564         return;
4565      }
4566
4567    wl_resource_set_implementation(res, &_tzsh_srv_taskbar_iface, tzsh_srv, NULL);
4568 }
4569
4570 static void
4571 _tzsh_srv_kvm_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4572 {
4573    wl_resource_destroy(resource);
4574 }
4575
4576 static void
4577 _tzsh_srv_kvm_cb_perform_drop(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4578 {
4579    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4580    E_Client *ec;
4581
4582    tzsh_srv = wl_resource_get_user_data(resource);
4583    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4584
4585    ec = tzsh_srv->ec;
4586    EINA_SAFETY_ON_NULL_RETURN(ec);
4587
4588    if (!e_comp_wl->drag) return;
4589
4590    e_service_kvm_drop_perform(ec);
4591 }
4592
4593 static void
4594 _tzsh_srv_kvm_cb_cancel_drag(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4595 {
4596    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4597    E_Client *ec;
4598
4599    tzsh_srv = wl_resource_get_user_data(resource);
4600    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4601
4602    ec = tzsh_srv->ec;
4603    EINA_SAFETY_ON_NULL_RETURN(ec);
4604
4605    if (!e_comp_wl->drag) return;
4606
4607    e_service_kvm_drag_cancel(ec);
4608 }
4609
4610 static void
4611 _tzsh_srv_kvm_cb_perform_drag_enter(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4612 {
4613    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4614    E_Client *ec;
4615
4616    tzsh_srv = wl_resource_get_user_data(resource);
4617    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4618
4619    ec = tzsh_srv->ec;
4620    EINA_SAFETY_ON_NULL_RETURN(ec);
4621
4622    if (!e_comp_wl->drag) return;
4623
4624    e_service_kvm_perform_drag_enter(ec);
4625 }
4626
4627 static void
4628 _tzsh_srv_kvm_cb_perform_drag_leave(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4629 {
4630    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4631    E_Client *ec;
4632
4633    tzsh_srv = wl_resource_get_user_data(resource);
4634    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4635
4636    ec = tzsh_srv->ec;
4637    EINA_SAFETY_ON_NULL_RETURN(ec);
4638
4639    if (!e_comp_wl->drag) return;
4640
4641    e_service_kvm_perform_drag_leave(ec);
4642 }
4643
4644 static void
4645 _tzsh_srv_kvm_cb_secondary_selection_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4646 {
4647    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4648    E_Client *ec;
4649
4650    tzsh_srv = wl_resource_get_user_data(resource);
4651    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4652
4653    ec = tzsh_srv->ec;
4654    EINA_SAFETY_ON_NULL_RETURN(ec);
4655
4656    e_service_kvm_secondary_selection_set(ec, EINA_TRUE);
4657 }
4658
4659 static void
4660 _tzsh_srv_kvm_cb_secondary_selection_unset(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
4661 {
4662    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4663    E_Client *ec;
4664
4665    tzsh_srv = wl_resource_get_user_data(resource);
4666    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4667
4668    ec = tzsh_srv->ec;
4669    EINA_SAFETY_ON_NULL_RETURN(ec);
4670
4671    e_service_kvm_secondary_selection_set(ec, EINA_FALSE);
4672 }
4673
4674 static const struct tws_service_kvm_interface _tzsh_srv_kvm_iface =
4675 {
4676    _tzsh_srv_kvm_cb_destroy,
4677    _tzsh_srv_kvm_cb_perform_drop,
4678    _tzsh_srv_kvm_cb_cancel_drag,
4679    _tzsh_srv_kvm_cb_perform_drag_enter,
4680    _tzsh_srv_kvm_cb_perform_drag_leave,
4681    _tzsh_srv_kvm_cb_secondary_selection_set,
4682    _tzsh_srv_kvm_cb_secondary_selection_unset,
4683 };
4684
4685 static void
4686 _tzsh_srv_iface_cb_kvm_get(struct wl_client *client, struct wl_resource *res_tzsh_srv, uint32_t id)
4687 {
4688    E_Service_Kvm *service = NULL;
4689    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4690    struct wl_resource *res;
4691    E_Client *ec;
4692
4693    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4694    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4695    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv->tzsh);
4696
4697    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4698      return;
4699
4700    res = wl_resource_create(client,
4701                             &tws_service_kvm_interface,
4702                             1,
4703                             id);
4704    if (!res)
4705      {
4706         wl_client_post_no_memory(client);
4707         return;
4708      }
4709
4710    ELOGF("KVM", "multi control resource created, res:%p, tzsh_srv:%p, res_tzsh_srv:%p", NULL, res, tzsh_srv, res_tzsh_srv);
4711
4712    ec = tzsh_srv->ec;
4713    if (ec)
4714      service = e_service_kvm_get();
4715
4716    if (service)
4717      {
4718         ELOGF("KVM", "multi control resource set. res:%p, service:%p, ec:%p", NULL, res, service, ec);
4719         e_service_kvm_wl_resource_set(service, res);
4720      }
4721
4722    wl_resource_set_implementation(res, &_tzsh_srv_kvm_iface, tzsh_srv, NULL);
4723 }
4724
4725 static const struct tws_service_interface _tzsh_srv_iface =
4726 {
4727    _tzsh_srv_iface_cb_destroy,
4728    _tzsh_srv_iface_cb_region_set,
4729    _tzsh_srv_iface_cb_indicator_get,
4730    _tzsh_srv_iface_cb_quickpanel_get,
4731    _tzsh_srv_iface_cb_scrsaver_mng_get,
4732    _tzsh_srv_iface_cb_scrsaver_get,
4733    _tzsh_srv_iface_cb_cbhm_get,
4734    _tzsh_srv_iface_cb_softkey_get,
4735    _tzsh_srv_iface_cb_magnifier_get,
4736    _tzsh_srv_iface_cb_launcher_get,
4737    _tzsh_srv_iface_cb_taskbar_get,
4738    _tzsh_srv_iface_cb_kvm_get,
4739 };
4740
4741 static Eina_Bool
4742 _e_policy_wl_tzsh_service_check_privilege(struct wl_client *client, int role)
4743 {
4744    const char *privilege;
4745    pid_t pid;
4746    uid_t uid;
4747    Eina_Bool res;
4748
4749    switch (role)
4750      {
4751       case TZSH_SRV_ROLE_QUICKPANEL_SYSTEM_DEFAULT:
4752       case TZSH_SRV_ROLE_QUICKPANEL_CONTEXT_MENU:
4753       case TZSH_SRV_ROLE_QUICKPANEL_APPS_MENU:
4754          privilege = E_PRIVILEGE_QUICKPANEL_SERVICE;
4755          break;
4756       case TZSH_SRV_ROLE_VOLUME:
4757          privilege = E_PRIVILEGE_VOLUME_SERVICE;
4758          break;
4759       case TZSH_SRV_ROLE_LOCKSCREEN:
4760          privilege = E_PRIVILEGE_LOCKSCREEN_SERVICE;
4761          break;
4762       case TZSH_SRV_ROLE_INDICATOR:
4763          privilege = E_PRIVILEGE_INDICATOR_SERVICE;
4764          break;
4765       case TZSH_SRV_ROLE_SCREENSAVER_MNG:
4766       case TZSH_SRV_ROLE_SCREENSAVER:
4767          privilege = E_PRIVILEGE_SCREENSAVER_SERVICE;
4768          break;
4769       case TZSH_SRV_ROLE_CBHM:
4770          privilege = E_PRIVILEGE_CBHM_SERVICE;
4771          break;
4772       case TZSH_SRV_ROLE_SOFTKEY:
4773          privilege = E_PRIVILEGE_SOFTKEY_SERVICE;
4774          break;
4775       case TZSH_SRV_ROLE_MAGNIFIER:
4776          privilege = E_PRIVILEGE_MAGNIFIER_SERVICE;
4777          break;
4778       case TZSH_SRV_ROLE_LAUNCHER:
4779          privilege = E_PRIVILEGE_LAUNCHER_SERVICE;
4780          break;
4781       case TZSH_SRV_ROLE_TASKBAR:
4782          privilege = E_PRIVILEGE_TASKBAR_SERVICE;
4783          break;
4784          /* TODO: need to check privilege
4785       case TZSH_SRV_ROLE_KVM:
4786          privilege = E_PRIVILEGE_KVM_SERVICE;
4787          break;
4788          */
4789       default:
4790          return EINA_TRUE;
4791      }
4792
4793    wl_client_get_credentials(client, &pid, &uid, NULL);
4794    res = e_security_privilege_check(pid,
4795                                     uid,
4796                                     privilege);
4797    return res;
4798 }
4799
4800 static void
4801 _tzsh_cb_srv_destroy(struct wl_resource *res_tzsh_srv)
4802 {
4803    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4804
4805    tzsh_srv = wl_resource_get_user_data(res_tzsh_srv);
4806    EINA_SAFETY_ON_NULL_RETURN(tzsh_srv);
4807
4808    if (!eina_list_data_find(polwl->tzsh_srvs, tzsh_srv))
4809      return;
4810
4811    _e_policy_wl_tzsh_srv_del(tzsh_srv);
4812 }
4813
4814 static void
4815 _tzsh_iface_cb_srv_create(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id, uint32_t surf_id, const char *name)
4816 {
4817    E_Policy_Wl_Tzsh *tzsh;
4818    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
4819    struct wl_resource *res_tzsh_srv;
4820    E_Client *ec;
4821    E_Pixmap *cp;
4822    int role;
4823    Eina_Bool res;
4824
4825    role = _e_policy_wl_tzsh_srv_role_get(name);
4826    if (role == TZSH_SRV_ROLE_UNKNOWN)
4827      {
4828         wl_resource_post_error
4829           (res_tzsh,
4830            WL_DISPLAY_ERROR_INVALID_OBJECT,
4831            "Invalid res_tzsh");
4832         return;
4833      }
4834
4835    /* check whether client has a privilege */
4836    res = _e_policy_wl_tzsh_service_check_privilege(client, role);
4837    if (!res)
4838      {
4839         ERR("Could not get privilege of resource: %m");
4840         tizen_ws_shell_send_error(res_tzsh,
4841                                   TIZEN_WS_SHELL_ERROR_PERMISSION_DENIED);
4842         return;
4843      }
4844
4845    /* to avoid sending a wayland error after tzsh ERROR_NONE for every cases
4846     * such as invalid object or no memory error, tzsh ERROR_NONE should be sent
4847     * first to clients without privilege problem.
4848     */
4849    tizen_ws_shell_send_error(res_tzsh, TIZEN_WS_SHELL_ERROR_NONE);
4850
4851    tzsh = wl_resource_get_user_data(res_tzsh);
4852    if (!tzsh)
4853      {
4854         wl_resource_post_error
4855           (res_tzsh,
4856            WL_DISPLAY_ERROR_INVALID_OBJECT,
4857            "Invalid res_tzsh's user data");
4858         return;
4859      }
4860
4861    cp = _e_policy_wl_e_pixmap_get_from_id(client, surf_id);
4862    if (!cp)
4863      {
4864         if (role == TZSH_SRV_ROLE_INDICATOR)
4865           cp = e_pixmap_new(E_PIXMAP_TYPE_NONE, 0);
4866
4867         if (!cp)
4868           {
4869              wl_resource_post_error
4870                (res_tzsh,
4871                 WL_DISPLAY_ERROR_INVALID_OBJECT,
4872                 "Invalid surface id");
4873              return;
4874           }
4875      }
4876
4877    ec = e_pixmap_client_get(cp);
4878    if (!ec)
4879      {
4880         if (role == TZSH_SRV_ROLE_INDICATOR)
4881           {
4882              ec = e_client_new(cp, 0, 1);
4883              if (ec) ec->ignored = 1;
4884           }
4885      }
4886
4887    if (ec)
4888      {
4889         if (!_e_policy_wl_e_client_is_valid(ec))
4890           {
4891              wl_resource_post_error
4892                (res_tzsh,
4893                 WL_DISPLAY_ERROR_INVALID_OBJECT,
4894                 "Invalid surface id");
4895              return;
4896           }
4897      }
4898
4899    res_tzsh_srv = wl_resource_create(client,
4900                                      &tws_service_interface,
4901                                      wl_resource_get_version(res_tzsh),
4902                                      id);
4903    if (!res_tzsh_srv)
4904      {
4905         ERR("Could not create tws_service resource: %m");
4906         wl_client_post_no_memory(client);
4907         return;
4908      }
4909
4910    tzsh_srv = _e_policy_wl_tzsh_srv_add(tzsh,
4911                                         role,
4912                                         res_tzsh_srv,
4913                                         name,
4914                                         cp,
4915                                         ec);
4916    if (!tzsh_srv)
4917      {
4918         ERR("Could not create WS_Shell_Service");
4919         wl_client_post_no_memory(client);
4920         wl_resource_destroy(res_tzsh_srv);
4921         return;
4922      }
4923
4924    wl_resource_set_implementation(res_tzsh_srv,
4925                                   &_tzsh_srv_iface,
4926                                   tzsh_srv,
4927                                   _tzsh_cb_srv_destroy);
4928
4929    if (tzsh_srv->ec->maximized)
4930      e_client_maximize(ec, E_MAXIMIZE_FULLSCREEN | E_MAXIMIZE_BOTH);
4931
4932    if (role == TZSH_SRV_ROLE_QUICKPANEL_SYSTEM_DEFAULT)
4933      e_service_quickpanel_client_add(tzsh_srv->ec, E_SERVICE_QUICKPANEL_TYPE_SYSTEM_DEFAULT);
4934    else if (role == TZSH_SRV_ROLE_QUICKPANEL_CONTEXT_MENU)
4935      e_service_quickpanel_client_add(tzsh_srv->ec, E_SERVICE_QUICKPANEL_TYPE_CONTEXT_MENU);
4936    else if (role == TZSH_SRV_ROLE_QUICKPANEL_APPS_MENU)
4937      e_service_quickpanel_client_add(tzsh_srv->ec, E_SERVICE_QUICKPANEL_TYPE_APPS_MENU);
4938    else if (role == TZSH_SRV_ROLE_VOLUME)
4939      e_service_volume_client_set(tzsh_srv->ec);
4940    else if (role == TZSH_SRV_ROLE_LOCKSCREEN)
4941      e_service_lockscreen_client_set(tzsh_srv->ec);
4942    else if (role == TZSH_SRV_ROLE_SCREENSAVER_MNG)
4943      e_service_scrsaver_client_set(tzsh_srv->ec);
4944    else if (role == TZSH_SRV_ROLE_SCREENSAVER)
4945      e_service_scrsaver_client_set(tzsh_srv->ec);
4946    else if (role == TZSH_SRV_ROLE_INDICATOR)
4947      e_mod_indicator_client_set(tzsh_srv->ec);
4948    else if (role == TZSH_SRV_ROLE_CBHM)
4949      e_service_cbhm_client_set(tzsh_srv->ec);
4950    else if (role == TZSH_SRV_ROLE_SOFTKEY)
4951      e_service_softkey_client_set(tzsh_srv->ec);
4952    else if (role == TZSH_SRV_ROLE_MAGNIFIER)
4953      {
4954         e_magnifier_new();
4955         e_magnifier_owner_set(tzsh_srv->ec);
4956      }
4957    else if (role == TZSH_SRV_ROLE_LAUNCHER)
4958      e_service_launcher_client_set(tzsh_srv->ec);
4959    else if (role == TZSH_SRV_ROLE_TASKBAR)
4960      e_service_taskbar_client_set(tzsh_srv->ec);
4961    else if (role == TZSH_SRV_ROLE_KVM)
4962      e_service_kvm_client_set(tzsh_srv->ec);
4963
4964    e_client_desk_iconify_skip_set(tzsh_srv->ec, EINA_TRUE);
4965 }
4966
4967 // --------------------------------------------------------
4968 // tizen_ws_shell common
4969 // --------------------------------------------------------
4970 EINTERN Eina_Bool
4971 e_tzsh_extension_add(const char *name, E_Policy_Wl_Tzsh_Ext_Hook_Cb cb)
4972 {
4973    E_Policy_Wl_Tzsh_Extension *tzsh_ext;
4974
4975    if (_e_policy_wl_tzsh_extension_get(name))
4976      {
4977         ERR("Already exists the %s extension\n", name);
4978         return EINA_FALSE;
4979      }
4980
4981    tzsh_ext = E_NEW(E_Policy_Wl_Tzsh_Extension, 1);
4982    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_ext, EINA_FALSE);
4983
4984    tzsh_ext->name = strndup(name, 512);
4985    tzsh_ext->cb = cb;
4986
4987    polwl->tzsh_extensions = eina_list_append(polwl->tzsh_extensions, tzsh_ext);
4988    ELOGF("TZSH",
4989          "EXTENSION_ADD | name:%s | cb:%p",
4990          NULL,
4991          name, cb);
4992
4993    return EINA_TRUE;
4994 }
4995
4996 EINTERN void
4997 e_tzsh_extension_del(const char *name)
4998 {
4999    E_Policy_Wl_Tzsh_Extension *tzsh_ext;
5000
5001    tzsh_ext = _e_policy_wl_tzsh_extension_get(name);
5002    if (!tzsh_ext)
5003      {
5004         ERR("Cannot find the %s extension\n", name);
5005         return;
5006      }
5007
5008    polwl->tzsh_extensions = eina_list_remove(polwl->tzsh_extensions, tzsh_ext);
5009    memset(tzsh_ext, 0x0, sizeof(E_Policy_Wl_Tzsh_Extension));
5010    E_FREE(tzsh_ext);
5011
5012    ELOGF("TZSH",
5013          "EXTENSION_DEL | name:%s",
5014          NULL,
5015          name);
5016 }
5017
5018 // --------------------------------------------------------
5019 // tizen_ws_shell_interface::region
5020 // --------------------------------------------------------
5021 static void
5022 _tzsh_reg_cb_shell_destroy(struct wl_listener *listener, void *data)
5023 {
5024    E_Policy_Wl_Tzsh_Region *tzsh_reg;
5025
5026    tzsh_reg = container_of(listener, E_Policy_Wl_Tzsh_Region, destroy_listener);
5027    if (tzsh_reg->destroy_listener.notify)
5028      {
5029         wl_list_remove(&tzsh_reg->destroy_listener.link);
5030         tzsh_reg->destroy_listener.notify = NULL;
5031      }
5032
5033    if (tzsh_reg->res_tzsh_reg)
5034      {
5035         wl_resource_destroy(tzsh_reg->res_tzsh_reg);
5036         tzsh_reg->res_tzsh_reg = NULL;
5037      }
5038 }
5039
5040 static void
5041 _tzsh_reg_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_reg)
5042 {
5043    wl_resource_destroy(res_tzsh_reg);
5044 }
5045
5046 static void
5047 _tzsh_reg_iface_cb_add(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_reg, int32_t x, int32_t y, int32_t w, int32_t h)
5048 {
5049    E_Policy_Wl_Tzsh_Region *tzsh_reg;
5050    Eina_Tiler *src;
5051    int area_w = 0, area_h = 0;
5052
5053    tzsh_reg = wl_resource_get_user_data(res_tzsh_reg);
5054    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg);
5055    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg->tiler);
5056
5057    eina_tiler_area_size_get(tzsh_reg->tiler, &area_w, &area_h);
5058    src = eina_tiler_new(area_w, area_h);
5059    eina_tiler_tile_size_set(src, 1, 1);
5060    eina_tiler_rect_add(src, &(Eina_Rectangle){x, y, w, h});
5061    eina_tiler_union(tzsh_reg->tiler, src);
5062    eina_tiler_free(src);
5063 }
5064
5065 static void
5066 _tzsh_reg_iface_cb_subtract(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_reg, int32_t x, int32_t y, int32_t w, int32_t h)
5067 {
5068    E_Policy_Wl_Tzsh_Region *tzsh_reg;
5069    Eina_Tiler *src;
5070    int area_w = 0, area_h = 0;
5071
5072    tzsh_reg = wl_resource_get_user_data(res_tzsh_reg);
5073    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg);
5074    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg->tiler);
5075
5076    eina_tiler_area_size_get(tzsh_reg->tiler, &area_w, &area_h);
5077    src = eina_tiler_new(area_w, area_h);
5078    eina_tiler_tile_size_set(src, 1, 1);
5079    eina_tiler_rect_add(src, &(Eina_Rectangle){x, y, w, h});
5080    eina_tiler_subtract(tzsh_reg->tiler, src);
5081    eina_tiler_free(src);
5082 }
5083
5084 static const struct tws_region_interface _tzsh_reg_iface =
5085 {
5086    _tzsh_reg_iface_cb_destroy,
5087    _tzsh_reg_iface_cb_add,
5088    _tzsh_reg_iface_cb_subtract
5089 };
5090
5091 static void
5092 _tzsh_reg_cb_destroy(struct wl_resource *res_tzsh_reg)
5093 {
5094    E_Policy_Wl_Tzsh_Region *tzsh_reg;
5095
5096    tzsh_reg = wl_resource_get_user_data(res_tzsh_reg);
5097    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg);
5098
5099    if (tzsh_reg->destroy_listener.notify)
5100      {
5101         wl_list_remove(&tzsh_reg->destroy_listener.link);
5102         tzsh_reg->destroy_listener.notify = NULL;
5103      }
5104    eina_tiler_free(tzsh_reg->tiler);
5105
5106    E_FREE(tzsh_reg);
5107 }
5108
5109 static void
5110 _tzsh_iface_cb_reg_create(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id)
5111 {
5112    E_Policy_Wl_Tzsh *tzsh;
5113    E_Policy_Wl_Tzsh_Region *tzsh_reg = NULL;
5114    Eina_Tiler *tz = NULL;
5115    struct wl_resource *res_tzsh_reg;
5116    int zw = 0, zh = 0;
5117
5118    tzsh = wl_resource_get_user_data(res_tzsh);
5119    if (!tzsh)
5120      {
5121         wl_resource_post_error
5122           (res_tzsh,
5123            WL_DISPLAY_ERROR_INVALID_OBJECT,
5124            "Invalid res_tzsh's user data");
5125         return;
5126      }
5127
5128    tzsh_reg = E_NEW(E_Policy_Wl_Tzsh_Region, 1);
5129    EINA_SAFETY_ON_NULL_RETURN(tzsh_reg);
5130
5131    e_zone_useful_geometry_get(e_zone_current_get(),
5132                               NULL, NULL, &zw, &zh);
5133
5134    tz = eina_tiler_new(zw, zh);
5135    EINA_SAFETY_ON_NULL_GOTO(tz, err);
5136    tzsh_reg->tiler = tz;
5137
5138    eina_tiler_tile_size_set(tzsh_reg->tiler, 1, 1);
5139
5140    if (!(res_tzsh_reg = wl_resource_create(client,
5141                                            &tws_region_interface,
5142                                            wl_resource_get_version(res_tzsh),
5143                                            id)))
5144      {
5145         ERR("Could not create tws_service resource: %m");
5146         wl_client_post_no_memory(client);
5147         goto err;
5148      }
5149
5150    wl_resource_set_implementation(res_tzsh_reg,
5151                                   &_tzsh_reg_iface,
5152                                   tzsh_reg,
5153                                   _tzsh_reg_cb_destroy);
5154
5155    tzsh_reg->tzsh = tzsh;
5156    tzsh_reg->res_tzsh_reg = res_tzsh_reg;
5157    tzsh_reg->destroy_listener.notify = _tzsh_reg_cb_shell_destroy;
5158
5159    wl_resource_add_destroy_listener(res_tzsh,
5160                                     &tzsh_reg->destroy_listener);
5161    return;
5162
5163 err:
5164    if (tzsh_reg->tiler) eina_tiler_free(tzsh_reg->tiler);
5165    E_FREE(tzsh_reg);
5166 }
5167
5168 // --------------------------------------------------------
5169 // tizen_ws_shell_interface::indicator
5170 // --------------------------------------------------------
5171 static E_Client *
5172 _e_tzsh_indicator_find_topvisible_client(E_Zone *zone)
5173 {
5174    E_Client *ec;
5175    Evas_Object *o;
5176    int ex, ey, ew, eh;
5177
5178    o = evas_object_top_get(e_comp->evas);
5179    for (; o; o = evas_object_below_get(o))
5180      {
5181         ec = evas_object_data_get(o, "E_Client");
5182
5183         /* check e_client and skip e_clients not intersects with zone */
5184         if (!ec) continue;
5185         if (e_object_is_del(E_OBJECT(ec))) continue;
5186         if (e_client_util_ignored_get(ec)) continue;
5187         if (!e_zone_has_ec(zone, ec)) continue;
5188         if (!ec->frame) continue;
5189
5190         if (!ec->visible) continue;
5191         if (ec->visibility.skip) continue;
5192         if ((ec->visibility.obscured != E_VISIBILITY_UNOBSCURED) &&
5193             (ec->visibility.obscured != E_VISIBILITY_PARTIALLY_OBSCURED) &&
5194             (!eina_list_data_find(e_comp->launchscrns, ec)))
5195           continue;
5196
5197         if (e_comp_wl_subsurface_check(ec)) continue;
5198
5199         e_client_geometry_get(ec, &ex, &ey, &ew, &eh);
5200         if (!E_CONTAINS(ex, ey, ew, eh, zone->x, zone->y, zone->w, zone->h))
5201           continue;
5202
5203         return ec;
5204
5205      }
5206
5207    return NULL;
5208 }
5209
5210 EINTERN void
5211 e_tzsh_indicator_srv_property_change_send(E_Client *ec, int angle)
5212 {
5213    int opacity;
5214
5215    if (!ec) return;
5216    if (!_indicator_srv_res)
5217      {
5218         ELOGF("TZ_IND", "NO indicator service", NULL);
5219         return;
5220      }
5221
5222    opacity = ec->indicator.opacity_mode;
5223
5224    ELOGF("TZ_IND", "SEND indicator info. angle:%d, opacity:%d", ec, angle, opacity);
5225    tws_service_indicator_send_property_change(_indicator_srv_res, angle, opacity);
5226 }
5227
5228 EINTERN void
5229 e_tzsh_indicator_srv_property_update(E_Client *ec)
5230 {
5231    E_Client *ec_ind_owner;
5232    if (!_indicator_srv_res) return;
5233
5234    ec_ind_owner = e_mod_indicator_owner_get();
5235    if (ec != ec_ind_owner) return;
5236
5237    if (ec->e.state.rot.ang.next != -1)
5238      e_tzsh_indicator_srv_property_change_send(ec, ec->e.state.rot.ang.next);
5239    else
5240      e_tzsh_indicator_srv_property_change_send(ec, ec->e.state.rot.ang.curr);
5241 }
5242
5243 EINTERN void
5244 e_tzsh_indicator_srv_ower_win_update(E_Zone *zone)
5245 {
5246    E_Client *ec = NULL;
5247    E_Client *ec_cur_owner = NULL;
5248
5249    if (!zone) return;
5250    if (!_indicator_srv_res) return;
5251
5252    ec_cur_owner = e_mod_indicator_owner_get();
5253    ec = _e_tzsh_indicator_find_topvisible_client(zone);
5254
5255    if (ec != ec_cur_owner)
5256      {
5257         ELOGF("TZ_IND", "Changed OWNER. win:%zx, state:%d, opacity:%d, vtype:%d", NULL, e_client_util_win_get(ec),
5258               ec ? ec->indicator.state:-1, ec ? ec->indicator.opacity_mode:-1, ec ? ec->indicator.visible_type:-1);
5259         e_mod_indicator_owner_set(ec);
5260
5261         if (ec && !ec->e.state.rot.pending_show)
5262           {
5263              ELOGF("TZ_IND", "Property Update. name:%s curr:%d, next:%d", NULL, ec->icccm.name?:"NULL",
5264                    ec->e.state.rot.ang.curr, ec->e.state.rot.ang.next);
5265              e_tzsh_indicator_srv_property_update(ec);
5266           }
5267      }
5268 }
5269
5270 // --------------------------------------------------------
5271 // tizen_ws_shell_interface::quickpanel
5272 // --------------------------------------------------------
5273 static void
5274 _tzsh_client_data_quickpanel_type_set(E_Policy_Wl_Tzsh_Client_Data_Quickpanel *quickpanel_client, E_Quickpanel_Type type)
5275 {
5276    if (quickpanel_client)
5277      quickpanel_client->type = type;
5278 }
5279
5280 static E_Quickpanel_Type
5281 _tzsh_client_data_quickpanel_type_get(E_Policy_Wl_Tzsh_Client_Data_Quickpanel *quickpanel_client)
5282 {
5283    if (!quickpanel_client)
5284      return E_QUICKPANEL_TYPE_UNKNOWN;
5285    else
5286      return quickpanel_client->type;
5287 }
5288
5289 static void
5290 _e_tzsh_qp_state_change_send(struct wl_resource *res_tzsh_client, int type, int value)
5291 {
5292    struct wl_array states;
5293    E_Tzsh_QP_Event *ev;
5294
5295    if (!res_tzsh_client) return;
5296
5297    wl_array_init(&states);
5298    ev = wl_array_add(&states, sizeof(E_Tzsh_QP_Event));
5299    if (!ev) return;
5300
5301    ev->type = type;
5302    ev->val = value;
5303
5304    tws_quickpanel_send_state_changed(res_tzsh_client, &states);
5305
5306    wl_array_release(&states);
5307 }
5308
5309 static Eina_Bool
5310 _e_tzsh_qp_client_data_type_check(E_Policy_Wl_Tzsh_Client *tzsh_client, E_Quickpanel_Type type)
5311 {
5312    E_Policy_Wl_Tzsh_Client_Data_Quickpanel *tzsh_client_quickpanel;
5313
5314    if (!tzsh_client)
5315      return EINA_FALSE;
5316
5317    if (tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL)
5318      return EINA_FALSE;
5319
5320    tzsh_client_quickpanel = (E_Policy_Wl_Tzsh_Client_Data_Quickpanel*)tzsh_client->client_data;
5321    if (!tzsh_client_quickpanel)
5322      return EINA_FALSE;
5323
5324    if (_tzsh_client_data_quickpanel_type_get(tzsh_client_quickpanel) != type)
5325      return EINA_FALSE;
5326
5327    return EINA_TRUE;
5328 }
5329
5330 E_API void
5331 e_tzsh_qp_state_visible_update(E_Client *ec, Eina_Bool vis, E_Quickpanel_Type type)
5332 {
5333    E_Policy_Wl_Tzsh_Client *tzsh_client;
5334    Eina_List *l;
5335    int val;
5336
5337    if (!ec) return;
5338    if (e_object_is_del(E_OBJECT(ec))) return;
5339
5340    EINA_LIST_FOREACH(polwl->tzsh_clients, l, tzsh_client)
5341      {
5342         /* check for type of qp */
5343         if (!_e_tzsh_qp_client_data_type_check(tzsh_client, type))
5344           continue;
5345         if (!tzsh_client->tzsh) continue;
5346         if (!tzsh_client->ec) continue;
5347
5348         if (tzsh_client->ep == ec->pixmap)
5349           {
5350              if (tzsh_client->ec != ec)
5351                {
5352                   ELOGF("TZSH",
5353                         "CRI ERR!!|tzsh_client_ep:%8p|tzsh_client_ec:%8p|tzsh_client:%8p|tzsh:%8p",
5354                         ec,
5355                         tzsh_client->ep,
5356                         tzsh_client->ec,
5357                         tzsh_client,
5358                         tzsh_client->tzsh);
5359                   continue;
5360                }
5361
5362              val = vis ? TWS_QUICKPANEL_STATE_VALUE_VISIBLE_SHOW : TWS_QUICKPANEL_STATE_VALUE_VISIBLE_HIDE;
5363              _e_tzsh_qp_state_change_send(tzsh_client->res_tzsh_client,
5364                                           TWS_QUICKPANEL_STATE_TYPE_VISIBILITY,
5365                                           val);
5366           }
5367      }
5368 }
5369
5370 EINTERN void
5371 e_tzsh_qp_state_scrollable_update(E_Client *ec, Eina_Bool scrollable, E_Quickpanel_Type type)
5372 {
5373    E_Policy_Wl_Tzsh_Client *tzsh_client;
5374    Eina_List *l;
5375    int val;
5376
5377    if (!ec) return;
5378    if (e_object_is_del(E_OBJECT(ec))) return;
5379
5380    EINA_LIST_FOREACH(polwl->tzsh_clients, l, tzsh_client)
5381      {
5382         /* check for type of qp */
5383         if (!_e_tzsh_qp_client_data_type_check(tzsh_client, type))
5384           continue;
5385         if (!tzsh_client->tzsh) continue;
5386         if (!tzsh_client->ec) continue;
5387
5388         if (tzsh_client->ep == ec->pixmap)
5389           {
5390              if (tzsh_client->ec != ec)
5391                {
5392                   ELOGF("TZSH",
5393                         "CRI ERR!!|tzsh_client_ep:%8p|tzsh_client_ec:%8p|tzsh_client:%8p|tzsh:%8p",
5394                         ec,
5395                         tzsh_client->ep,
5396                         tzsh_client->ec,
5397                         tzsh_client,
5398                         tzsh_client->tzsh);
5399                   continue;
5400                }
5401
5402              val = scrollable ? TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_SET : TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_UNSET;
5403              _e_tzsh_qp_state_change_send(tzsh_client->res_tzsh_client,
5404                                           TWS_QUICKPANEL_STATE_TYPE_SCROLLABLE,
5405                                           val);
5406           }
5407      }
5408 }
5409
5410 E_API void
5411 e_tzsh_qp_state_orientation_update(E_Client *ec, int ridx, E_Quickpanel_Type type)
5412 {
5413    E_Policy_Wl_Tzsh_Client *tzsh_client;
5414    Eina_List *l;
5415    int val;
5416
5417    if (!ec) return;
5418    if (e_object_is_del(E_OBJECT(ec))) return;
5419
5420    EINA_LIST_FOREACH(polwl->tzsh_clients, l, tzsh_client)
5421      {
5422         /* check for type of qp */
5423         if (!_e_tzsh_qp_client_data_type_check(tzsh_client, type))
5424           continue;
5425         if (!tzsh_client->tzsh) continue;
5426         if (!tzsh_client->ec) continue;
5427
5428         if (tzsh_client->ep == ec->pixmap)
5429           {
5430              if (tzsh_client->ec != ec)
5431                {
5432                   ELOGF("TZSH",
5433                         "CRI ERR!!|tzsh_client_ep:%8p|tzsh_client_ec:%8p|tzsh_client:%8p|tzsh:%8p",
5434                         ec,
5435                         tzsh_client->ep,
5436                         tzsh_client->ec,
5437                         tzsh_client,
5438                         tzsh_client->tzsh);
5439                   continue;
5440                }
5441
5442              val = TWS_QUICKPANEL_STATE_VALUE_ORIENTATION_0 + ridx;
5443              _e_tzsh_qp_state_change_send(tzsh_client->res_tzsh_client,
5444                                           TWS_QUICKPANEL_STATE_TYPE_ORIENTATION,
5445                                           val);
5446           }
5447      }
5448 }
5449
5450 static void
5451 _tzsh_qp_iface_cb_release(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp)
5452 {
5453    wl_resource_destroy(res_tzsh_qp);
5454 }
5455
5456 static E_Quickpanel_Type
5457 _e_tzsh_qp_type_get(E_Policy_Wl_Tzsh_Client *tzsh_client)
5458 {
5459    E_Policy_Wl_Tzsh_Client_Data_Quickpanel *tzsh_client_quickpanel;
5460    tzsh_client_quickpanel = (E_Policy_Wl_Tzsh_Client_Data_Quickpanel*)tzsh_client->client_data;
5461    if (!tzsh_client_quickpanel)
5462      return E_QUICKPANEL_TYPE_UNKNOWN;
5463    else
5464      return _tzsh_client_data_quickpanel_type_get(tzsh_client_quickpanel);
5465 }
5466
5467
5468 static void
5469 _tzsh_qp_iface_cb_show(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp)
5470 {
5471    E_Policy_Wl_Tzsh_Client *tzsh_client;
5472    E_Client *ec;
5473
5474    ELOGF("TZ_QUICKPANEL", "Request to Show Quickpanel", NULL);
5475
5476    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5477    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5478    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5479    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5480    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5481
5482    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5483    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5484
5485    ec = tzsh_client->ec;
5486
5487    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5488      return;
5489
5490    e_qp_client_show(ec, qp_type);
5491 }
5492
5493 static void
5494 _tzsh_qp_iface_cb_hide(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp)
5495 {
5496    E_Policy_Wl_Tzsh_Client *tzsh_client;
5497    E_Client *ec;
5498
5499    ELOGF("TZ_QUICKPANEL", "Request to Hide Quickpanel", NULL);
5500
5501    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5502    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5503    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5504    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5505    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5506
5507    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5508    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5509
5510    ec = tzsh_client->ec;
5511
5512    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5513      return;
5514
5515    e_qp_client_hide(ec, qp_type);
5516 }
5517
5518 static void
5519 _tzsh_qp_iface_cb_enable(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp)
5520 {
5521    E_Policy_Wl_Tzsh_Client *tzsh_client;
5522    E_Client *ec;
5523
5524    ELOGF("TZ_QUICKPANEL", "Request to Set scrollable state of Quickpanel to 1", NULL);
5525
5526    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5527    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5528    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5529    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5530    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5531
5532    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5533    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5534
5535    ec = tzsh_client->ec;
5536
5537    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5538      return;
5539
5540    e_qp_client_scrollable_state_set(ec, qp_type, E_QUICKPANEL_CLIENT_SCROLL_STATE_SET);
5541 }
5542
5543 static void
5544 _tzsh_qp_iface_cb_disable(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp)
5545 {
5546    E_Policy_Wl_Tzsh_Client *tzsh_client;
5547    E_Client *ec;
5548
5549    ELOGF("TZ_QUICKPANEL", "Request to Set scrollable state of Quickpanel to 0", NULL);
5550
5551    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5552    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5553    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5554    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5555    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5556
5557    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5558    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5559
5560    ec = tzsh_client->ec;
5561
5562    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5563      return;
5564
5565    e_qp_client_scrollable_state_set(ec, qp_type, E_QUICKPANEL_CLIENT_SCROLL_STATE_UNSET);
5566 }
5567
5568 static void
5569 _tzsh_qp_iface_cb_state_get(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp, int32_t type)
5570 {
5571    E_Policy_Wl_Tzsh_Client *tzsh_client;
5572    E_Client *ec;
5573    Eina_Bool vis;
5574    E_Quickpanel_Client_Scroll_State scrollable;
5575    int ridx;
5576    int val = TWS_QUICKPANEL_STATE_VALUE_UNKNOWN;
5577
5578    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5579    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5580    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5581    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5582    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5583
5584    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5585    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5586
5587    ec = tzsh_client->ec;
5588
5589    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5590      return;
5591
5592    switch (type)
5593      {
5594       case TWS_QUICKPANEL_STATE_TYPE_VISIBILITY:
5595         val = TWS_QUICKPANEL_STATE_VALUE_VISIBLE_HIDE;
5596         vis = e_qp_visible_get(ec, qp_type);
5597         if (vis) val = TWS_QUICKPANEL_STATE_VALUE_VISIBLE_SHOW;
5598         break;
5599       case TWS_QUICKPANEL_STATE_TYPE_SCROLLABLE:
5600         scrollable = e_qp_client_scrollable_state_get(ec, qp_type);
5601         if (scrollable == E_QUICKPANEL_CLIENT_SCROLL_STATE_UNSET)
5602           val = TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_UNSET;
5603         else if (scrollable == E_QUICKPANEL_CLIENT_SCROLL_STATE_SET)
5604           val = TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_SET;
5605         else if (scrollable == E_QUICKPANEL_CLIENT_SCROLL_STATE_RETAIN)
5606           val = TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_RETAIN;
5607         else
5608           val = TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_SET;
5609         break;
5610       case TWS_QUICKPANEL_STATE_TYPE_ORIENTATION:
5611         ridx = e_qp_orientation_get(ec, qp_type);
5612         val = TWS_QUICKPANEL_STATE_VALUE_ORIENTATION_0 + ridx;
5613         break;
5614       default:
5615         break;
5616      }
5617
5618    tws_quickpanel_send_state_get_done(res_tzsh_qp, type, val, 0);
5619 }
5620
5621 static void
5622 _tzsh_qp_iface_cb_type_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp, uint32_t type)
5623 {
5624    E_Policy_Wl_Tzsh_Client *tzsh_client;
5625    E_Client *ec;
5626
5627    ELOGF("TZ_QUICKPANEL", "Request to Set type of Quickpanel to %d", NULL, type);
5628
5629    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5630    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5631    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5632    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5633    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5634
5635    E_Policy_Wl_Tzsh_Client_Data_Quickpanel *tzsh_client_quickpanel;
5636    tzsh_client_quickpanel = (E_Policy_Wl_Tzsh_Client_Data_Quickpanel*)tzsh_client->client_data;
5637    EINA_SAFETY_ON_NULL_RETURN(tzsh_client_quickpanel);
5638
5639    E_Quickpanel_Type qp_type = _tzsh_client_data_quickpanel_type_get(tzsh_client_quickpanel);
5640    EINA_SAFETY_ON_TRUE_RETURN(qp_type != E_QUICKPANEL_TYPE_UNKNOWN);
5641
5642    _tzsh_client_data_quickpanel_type_set(tzsh_client_quickpanel, type);
5643
5644    ec = tzsh_client->ec;
5645
5646    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5647      return;
5648
5649    /* Since various types of qp are supported, one ec can be used for handler for
5650     * two or more qp types. So e_qp_client_add function is called at the callback
5651     * of qp_type_set, because it is easy to add the E_QP_Client instance after setting
5652     * of qp type is completed.
5653     */
5654    e_qp_client_add(ec, type);
5655 }
5656
5657 static void
5658 _tzsh_qp_iface_cb_scrollable_state_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_qp, int32_t state)
5659 {
5660    E_Policy_Wl_Tzsh_Client *tzsh_client;
5661    E_Client *ec;
5662
5663    ELOGF("TZ_QUICKPANEL", "Request to Set scrollable state to %d", NULL, state);
5664
5665    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5666    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5667    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5668    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5669    EINA_SAFETY_ON_TRUE_RETURN(tzsh_client->handle_type != TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL);
5670
5671    E_Quickpanel_Type qp_type = _e_tzsh_qp_type_get(tzsh_client);
5672    EINA_SAFETY_ON_TRUE_RETURN(qp_type == E_QUICKPANEL_TYPE_UNKNOWN);
5673
5674    ec = tzsh_client->ec;
5675    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5676      return;
5677
5678    if (state == TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_UNSET)
5679      e_qp_client_scrollable_state_set(ec, qp_type, E_QUICKPANEL_CLIENT_SCROLL_STATE_UNSET);
5680    else if (state == TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_SET)
5681      e_qp_client_scrollable_state_set(ec, qp_type, E_QUICKPANEL_CLIENT_SCROLL_STATE_SET);
5682    else if (state == TWS_QUICKPANEL_STATE_VALUE_SCROLLABLE_RETAIN)
5683      e_qp_client_scrollable_state_set(ec, qp_type, E_QUICKPANEL_CLIENT_SCROLL_STATE_RETAIN);
5684 }
5685
5686 static const struct tws_quickpanel_interface _tzsh_qp_iface =
5687 {
5688    _tzsh_qp_iface_cb_release,
5689    _tzsh_qp_iface_cb_show,
5690    _tzsh_qp_iface_cb_hide,
5691    _tzsh_qp_iface_cb_enable,
5692    _tzsh_qp_iface_cb_disable,
5693    _tzsh_qp_iface_cb_state_get,
5694    _tzsh_qp_iface_cb_type_set,
5695    _tzsh_qp_iface_cb_scrollable_state_set
5696 };
5697
5698 static void
5699 _tzsh_cb_qp_destroy(struct wl_resource *res_tzsh_qp)
5700 {
5701    E_Policy_Wl_Tzsh_Client *tzsh_client;
5702
5703    tzsh_client = wl_resource_get_user_data(res_tzsh_qp);
5704    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5705
5706    E_Quickpanel_Type qp_type =
5707      _tzsh_client_data_quickpanel_type_get((E_Policy_Wl_Tzsh_Client_Data_Quickpanel*)tzsh_client->client_data);
5708    e_qp_client_del(tzsh_client->ec, qp_type);
5709
5710    E_FREE(tzsh_client->client_data);
5711
5712    tzsh_client->res_tzsh_client = NULL;
5713    _e_policy_wl_tzsh_client_del(tzsh_client);
5714 }
5715
5716 static E_Policy_Wl_Tzsh_Client_Data_Quickpanel *
5717 _tzsh_client_data_quickpanel_new(void)
5718 {
5719    E_Policy_Wl_Tzsh_Client_Data_Quickpanel *tzsh_client_quickpanel;
5720
5721    tzsh_client_quickpanel = E_NEW(E_Policy_Wl_Tzsh_Client_Data_Quickpanel, 1);
5722    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_client_quickpanel, NULL);
5723
5724    tzsh_client_quickpanel->type = E_QUICKPANEL_TYPE_UNKNOWN;
5725    return tzsh_client_quickpanel;
5726 }
5727
5728 static void
5729 _tzsh_iface_cb_qp_get(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id, uint32_t surf_id)
5730 {
5731    E_Policy_Wl_Tzsh *tzsh;
5732    E_Policy_Wl_Tzsh_Client *tzsh_client;
5733    struct wl_resource *res_tzsh_qp;
5734    E_Client *ec;
5735    E_Pixmap *cp;
5736
5737    tzsh = wl_resource_get_user_data(res_tzsh);
5738    if (!tzsh)
5739      {
5740         wl_resource_post_error
5741           (res_tzsh,
5742            WL_DISPLAY_ERROR_INVALID_OBJECT,
5743            "Invalid res_tzsh's user data");
5744         return;
5745      }
5746
5747    cp = _e_policy_wl_e_pixmap_get_from_id(client, surf_id);
5748    if (!cp)
5749      {
5750         wl_resource_post_error
5751           (res_tzsh,
5752            WL_DISPLAY_ERROR_INVALID_OBJECT,
5753            "Invalid surface id");
5754         return;
5755      }
5756
5757    ec = e_pixmap_client_get(cp);
5758    if (ec)
5759      {
5760         if (!_e_policy_wl_e_client_is_valid(ec))
5761           {
5762              wl_resource_post_error
5763                (res_tzsh,
5764                 WL_DISPLAY_ERROR_INVALID_OBJECT,
5765                 "Invalid surface id");
5766              return;
5767           }
5768      }
5769
5770    res_tzsh_qp = wl_resource_create(client,
5771                                     &tws_quickpanel_interface,
5772                                     wl_resource_get_version(res_tzsh),
5773                                     id);
5774    if (!res_tzsh_qp)
5775      {
5776         ERR("Could not create tws_quickpanel resource: %m");
5777         wl_client_post_no_memory(client);
5778         return;
5779      }
5780
5781    tzsh_client = _e_policy_wl_tzsh_client_add(tzsh, res_tzsh_qp, cp, ec);
5782    if (!tzsh_client)
5783      {
5784         ERR("Could not create tzsh_client");
5785         wl_client_post_no_memory(client);
5786         return;
5787      }
5788
5789    tzsh_client->handle_type = TZSH_CLIENT_HANDLE_TYPE_QUICKPANEL;
5790    tzsh_client->client_data = _tzsh_client_data_quickpanel_new();
5791    if (!tzsh_client->client_data)
5792      {
5793         ERR("Could not create tzsh_client");
5794         wl_client_post_no_memory(client);
5795         return;
5796      }
5797
5798    /* Since various types of qp are supported, one ec can be used for handler for
5799     * two or more qp types. So e_qp_client_add function is called at the callback
5800     * of qp_type_set, because it is easy to add the E_QP_Client instance after setting
5801     * of qp type is completed.
5802     */
5803    //e_qp_client_add(tzsh->ec);
5804
5805    wl_resource_set_implementation(res_tzsh_qp,
5806                                   &_tzsh_qp_iface,
5807                                   tzsh_client,
5808                                   _tzsh_cb_qp_destroy);
5809 }
5810
5811 static void _tzsh_iface_cb_extension_get(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id, const char *name)
5812 {
5813    E_Policy_Wl_Tzsh *tzsh;
5814    E_Policy_Wl_Tzsh_Extension *tzsh_ext;
5815    struct wl_resource *res_ext;
5816
5817    tzsh = wl_resource_get_user_data(res_tzsh);
5818    if (!tzsh)
5819      {
5820         wl_resource_post_error
5821           (res_tzsh,
5822            WL_DISPLAY_ERROR_INVALID_OBJECT,
5823            "Invalid res_tzsh's user data");
5824         return;
5825      }
5826
5827    tzsh_ext = _e_policy_wl_tzsh_extension_get(name);
5828    if (!tzsh_ext)
5829       {
5830          ERR("Could not find tzsh_extension(%s)", name);
5831          wl_resource_post_error
5832            (res_tzsh,
5833             WL_DISPLAY_ERROR_INVALID_OBJECT,
5834             "unregistered ext:%s", name);
5835       }
5836    else
5837       {
5838          res_ext = tzsh_ext->cb(client, res_tzsh, id);
5839          if (!res_ext)
5840             {
5841                ERR("Could not create extension(%s) resource", name);
5842                wl_resource_post_error
5843                  (res_tzsh,
5844                   WL_DISPLAY_ERROR_INVALID_OBJECT,
5845                   "Unknown error:%s", name);
5846             }
5847       }
5848 }
5849
5850 // --------------------------------------------------------
5851 // tizen_ws_shell_interface::softkey
5852 // --------------------------------------------------------
5853 static void
5854 _tzsh_softkey_iface_cb_release(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey)
5855 {
5856    wl_resource_destroy(res_tzsh_softkey);
5857 }
5858
5859 static void
5860 _tzsh_softkey_iface_cb_support_check(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey)
5861 {
5862    E_Policy_Wl_Tzsh_Client *tzsh_client;
5863    int support;
5864
5865    ELOGF("TZ_SOFTKEY", "Request to Check supporting softkey", NULL);
5866
5867    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
5868    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5869    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5870    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5871
5872    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5873      return;
5874
5875    if (e_config->use_softkey || e_config->use_softkey_service)
5876      support = 1;
5877    else
5878      support = 0;
5879
5880    ELOGF("TZ_SOFTKEY", "Send SUPPORT_CHECK_DONE. support:%d", NULL, support);
5881    tws_softkey_send_support_check_done(res_tzsh_softkey, support);
5882 }
5883
5884 static void
5885 _tzsh_softkey_show(E_Policy_Wl_Tzsh_Client *tzsh_client)
5886 {
5887    E_Zone *zone;
5888    E_Client *ec;
5889
5890    zone = tzsh_client->zone;
5891    if (!zone) return;
5892    ec = tzsh_client->ec;
5893    if (!ec) return;
5894
5895    if (e_config->use_softkey)
5896      {
5897         E_Policy_Softkey *softkey;
5898         softkey = e_policy_softkey_get(zone);
5899         if (softkey)
5900           {
5901              ELOGF("TZ_SOFTKEY", "SHOW softkey", ec);
5902              e_policy_softkey_show(softkey);
5903           }
5904      }
5905
5906    if (e_config->use_softkey_service)
5907      {
5908         E_Service_Softkey *softkey_service;
5909         softkey_service = e_service_softkey_get(zone);
5910         if (softkey_service)
5911           {
5912              ELOGF("TZ_SOFTKEY", "Request to SHOW softkey service. (service:%p)", ec, softkey_service);
5913              e_service_softkey_visible_set(softkey_service, 1);
5914           }
5915         else
5916           {
5917              ELOGF("TZ_SOFTKEY", "There is no softkey service. store show request", ec);
5918              e_service_softkey_store_visible_request(ec, 1);
5919           }
5920      }
5921 }
5922
5923 static void
5924 _tzsh_softkey_iface_cb_show(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey)
5925 {
5926    E_Policy_Wl_Tzsh_Client *tzsh_client;
5927
5928    ELOGF("TZ_SOFTKEY", "Request to Show softkey", NULL);
5929
5930    if (!e_config->use_softkey && !e_config->use_softkey_service)
5931      return;
5932
5933    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
5934    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
5935    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
5936    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
5937
5938    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
5939      return;
5940
5941    E_Policy_Wl_Tzsh_Client_Data_Softkey *tzsh_client_data_softkey;
5942    tzsh_client_data_softkey = (E_Policy_Wl_Tzsh_Client_Data_Softkey*)tzsh_client->client_data;
5943    EINA_SAFETY_ON_NULL_RETURN(tzsh_client_data_softkey);
5944
5945    if (tzsh_client_data_softkey->show_state == 1)
5946      return;
5947
5948    tzsh_client_data_softkey->show_state = 1;
5949    _tzsh_softkey_show(tzsh_client);
5950 }
5951
5952 static void
5953 _tzsh_softkey_hide(E_Policy_Wl_Tzsh_Client *tzsh_client)
5954 {
5955    E_Zone *zone;
5956    E_Client *ec;
5957
5958    zone = tzsh_client->zone;
5959    if (!zone) return;
5960    ec = tzsh_client->ec;
5961    if (!ec) return;
5962
5963    if (e_config->use_softkey)
5964      {
5965         E_Policy_Softkey *softkey;
5966         softkey = e_policy_softkey_get(zone);
5967         if (softkey)
5968           {
5969              ELOGF("TZ_SOFTKEY", "HIDE softkey", NULL);
5970              e_policy_softkey_hide(softkey);
5971           }
5972      }
5973
5974    if (e_config->use_softkey_service)
5975      {
5976         E_Service_Softkey *softkey_service;
5977         softkey_service = e_service_softkey_get(zone);
5978         if (softkey_service)
5979           {
5980              ELOGF("TZ_SOFTKEY", "Request to HIDE softkey service. (service:%p)", ec, softkey_service);
5981              e_service_softkey_visible_set(softkey_service, 0);
5982           }
5983         else
5984           {
5985              ELOGF("TZ_SOFTKEY", "There is no softkey service. store hide request", ec);
5986              e_service_softkey_store_visible_request(ec, 0);
5987           }
5988      }
5989 }
5990
5991 static void
5992 _tzsh_softkey_iface_cb_hide(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey)
5993 {
5994    E_Policy_Wl_Tzsh_Client *tzsh_client;
5995
5996    ELOGF("TZ_SOFTKEY", "Request to Hide softkey", NULL);
5997
5998    if (!e_config->use_softkey && !e_config->use_softkey_service)
5999      return;
6000
6001    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
6002    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6003    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
6004    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
6005
6006    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
6007      return;
6008
6009    E_Policy_Wl_Tzsh_Client_Data_Softkey *tzsh_client_data_softkey;
6010    tzsh_client_data_softkey = (E_Policy_Wl_Tzsh_Client_Data_Softkey*)tzsh_client->client_data;
6011    EINA_SAFETY_ON_NULL_RETURN(tzsh_client_data_softkey);
6012
6013    if (tzsh_client_data_softkey->show_state == 0)
6014      return;
6015
6016    tzsh_client_data_softkey->show_state = 0;
6017    _tzsh_softkey_hide(tzsh_client);
6018 }
6019
6020 static void
6021 _tzsh_softkey_iface_cb_state_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey, int32_t type, int32_t val)
6022 {
6023    E_Policy_Wl_Tzsh_Client *tzsh_client;
6024    E_Policy_Softkey_Expand expand;
6025    E_Policy_Softkey_Opacity opacity;
6026
6027    ELOGF("TZ_SOFTKEY", "Request to Set state (tz_type:%d, tz_val:%d)", NULL, type, val);
6028
6029    if (!e_config->use_softkey && !e_config->use_softkey_service)
6030      return;
6031
6032    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
6033    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6034    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
6035    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
6036
6037    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
6038      return;
6039
6040    if (e_config->use_softkey)
6041      {
6042         E_Policy_Softkey *softkey;
6043         softkey = e_policy_softkey_get(tzsh_client->zone);
6044         if (!softkey) return;
6045
6046         switch (type)
6047           {
6048            case TWS_SOFTKEY_STATE_EXPAND:
6049               if (val == TWS_SOFTKEY_STATE_EXPAND_ON)
6050                 expand = E_POLICY_SOFTKEY_EXPAND_ON;
6051               else
6052                 expand = E_POLICY_SOFTKEY_EXPAND_OFF;
6053
6054               ELOGF("TZ_SOFTKEY", "Set EXPAND state to %d", NULL, expand);
6055               e_policy_softkey_expand_set(softkey, expand);
6056               break;
6057
6058            case TWS_SOFTKEY_STATE_OPACITY:
6059               if (val == TWS_SOFTKEY_STATE_OPACITY_TRANSPARENT)
6060                 opacity = E_POLICY_SOFTKEY_OPACITY_TRANSPARENT;
6061               else
6062                 opacity = E_POLICY_SOFTKEY_OPACITY_OPAQUE;
6063
6064               ELOGF("TZ_SOFTKEY", "Set OPACITY state to %d", NULL, opacity);
6065               e_policy_softkey_opacity_set(softkey, opacity);
6066               break;
6067
6068            default:
6069               break;
6070           }
6071      }
6072
6073    if (e_config->use_softkey_service)
6074      {
6075         E_Service_Softkey *softkey_service;
6076
6077         softkey_service = e_service_softkey_get(tzsh_client->zone);
6078         if (!softkey_service) return;
6079
6080         switch (type)
6081           {
6082            case TWS_SOFTKEY_STATE_EXPAND:
6083               if (val == TWS_SOFTKEY_STATE_EXPAND_ON)
6084                 expand = E_POLICY_SOFTKEY_EXPAND_ON;
6085               else
6086                 expand = E_POLICY_SOFTKEY_EXPAND_OFF;
6087
6088               ELOGF("TZ_SOFTKEY", "Request to Change EXPAND state to %d. (service:%p)", NULL, expand, softkey_service);
6089               e_service_softkey_expand_set(softkey_service, expand);
6090               break;
6091
6092            case TWS_SOFTKEY_STATE_OPACITY:
6093               if (val == TWS_SOFTKEY_STATE_OPACITY_TRANSPARENT)
6094                 opacity = E_POLICY_SOFTKEY_OPACITY_TRANSPARENT;
6095               else
6096                 opacity = E_POLICY_SOFTKEY_OPACITY_OPAQUE;
6097
6098               ELOGF("TZ_SOFTKEY", "Request to Change OPACITY state to %d. (service:%p)", NULL, opacity, softkey_service);
6099               e_service_softkey_opacity_set(softkey_service, opacity);
6100               break;
6101
6102            default:
6103               break;
6104           }
6105      }
6106 }
6107
6108 static void
6109 _tzsh_softkey_iface_cb_state_get(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh_softkey, int32_t type)
6110 {
6111    E_Policy_Wl_Tzsh_Client *tzsh_client;
6112    E_Policy_Softkey_Expand expand;
6113    E_Policy_Softkey_Opacity opacity;
6114    E_Zone *zone;
6115    int visible;
6116    int val;
6117
6118    ELOGF("TZ_SOFTKEY", "Request to Get state (tz_type:%d)", NULL, type);
6119
6120    if (!e_config->use_softkey && !e_config->use_softkey_service)
6121      return;
6122
6123    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
6124    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6125    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
6126    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
6127    zone = tzsh_client->zone;
6128    EINA_SAFETY_ON_NULL_RETURN(zone);
6129
6130    if (!eina_list_data_find(polwl->tzsh_clients, tzsh_client))
6131      return;
6132
6133    if (e_config->use_softkey)
6134      {
6135         E_Policy_Softkey *softkey;
6136         softkey = e_policy_softkey_get(zone);
6137         if (!softkey) return;
6138
6139         switch (type)
6140           {
6141            case TWS_SOFTKEY_STATE_VISIBLE:
6142               visible = e_policy_softkey_visible_get(softkey);
6143               if (visible)
6144                 val = TWS_SOFTKEY_STATE_VISIBLE_SHOW;
6145               else
6146                 val = TWS_SOFTKEY_STATE_VISIBLE_HIDE;
6147
6148               ELOGF("TZ_SOFTKEY", "Send current VISIBLE state: %d (tz_val:%d)", NULL, visible, val);
6149               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6150               break;
6151
6152            case TWS_SOFTKEY_STATE_EXPAND:
6153               e_policy_softkey_expand_get(softkey, &expand);
6154               if (expand == E_POLICY_SOFTKEY_EXPAND_ON)
6155                 val = TWS_SOFTKEY_STATE_EXPAND_ON;
6156               else
6157                 val = TWS_SOFTKEY_STATE_EXPAND_OFF;
6158
6159               ELOGF("TZ_SOFTKEY", "Send current EXPAND state: %d (tz_val:%d)", NULL, expand, val);
6160               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6161               break;
6162
6163            case TWS_SOFTKEY_STATE_OPACITY:
6164               e_policy_softkey_opacity_get(softkey, &opacity);
6165               if (opacity == E_POLICY_SOFTKEY_OPACITY_TRANSPARENT)
6166                 val = TWS_SOFTKEY_STATE_OPACITY_TRANSPARENT;
6167               else
6168                 val = TWS_SOFTKEY_STATE_OPACITY_OPAQUE;
6169
6170               ELOGF("TZ_SOFTKEY", "Send current OPACITY state: %d (tz_val:%d)", NULL, opacity, val);
6171               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6172               break;
6173
6174            default:
6175               break;
6176           }
6177      }
6178
6179    if (e_config->use_softkey_service)
6180      {
6181         E_Service_Softkey *softkey_service;
6182         softkey_service = e_service_softkey_get(zone);
6183         if (!softkey_service) return;
6184
6185         switch (type)
6186           {
6187            case TWS_SOFTKEY_STATE_VISIBLE:
6188               visible = e_service_softkey_visible_get(softkey_service);
6189               if (visible)
6190                 val = TWS_SOFTKEY_STATE_VISIBLE_SHOW;
6191               else
6192                 val = TWS_SOFTKEY_STATE_VISIBLE_HIDE;
6193
6194               ELOGF("TZ_SOFTKEY", "Send service's current VISIBLE state: %d (tz_val:%d)", NULL, visible, val);
6195               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6196               break;
6197
6198            case TWS_SOFTKEY_STATE_EXPAND:
6199               e_service_softkey_expand_get(softkey_service, &expand);
6200               if (expand == E_POLICY_SOFTKEY_EXPAND_ON)
6201                 val = TWS_SOFTKEY_STATE_EXPAND_ON;
6202               else
6203                 val = TWS_SOFTKEY_STATE_EXPAND_OFF;
6204
6205               ELOGF("TZ_SOFTKEY", "Send service's current EXPAND state: %d (tz_val:%d)", NULL, expand, val);
6206               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6207               break;
6208
6209            case TWS_SOFTKEY_STATE_OPACITY:
6210               e_service_softkey_opacity_get(softkey_service, &opacity);
6211               if (opacity == E_POLICY_SOFTKEY_OPACITY_TRANSPARENT)
6212                 val = TWS_SOFTKEY_STATE_OPACITY_TRANSPARENT;
6213               else
6214                 val = TWS_SOFTKEY_STATE_OPACITY_OPAQUE;
6215
6216               ELOGF("TZ_SOFTKEY", "Send service's current OPACITY state: %d (tz_val:%d)", NULL, opacity, val);
6217               tws_softkey_send_state_get_done(res_tzsh_softkey, type, val, 0);
6218               break;
6219
6220            default:
6221               break;
6222           }
6223      }
6224 }
6225
6226 static const struct tws_softkey_interface _tzsh_softkey_iface =
6227 {
6228    _tzsh_softkey_iface_cb_release,
6229    _tzsh_softkey_iface_cb_support_check,
6230    _tzsh_softkey_iface_cb_show,
6231    _tzsh_softkey_iface_cb_hide,
6232    _tzsh_softkey_iface_cb_state_set,
6233    _tzsh_softkey_iface_cb_state_get
6234 };
6235
6236 static E_Policy_Wl_Tzsh_Client_Data_Softkey *
6237 _tzsh_client_data_softkey_new(void)
6238 {
6239    E_Policy_Wl_Tzsh_Client_Data_Softkey *tzsh_client_data_softkey;
6240
6241    tzsh_client_data_softkey = E_NEW(E_Policy_Wl_Tzsh_Client_Data_Softkey, 1);
6242    EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_client_data_softkey, NULL);
6243
6244    tzsh_client_data_softkey->show_state = 1;
6245    return tzsh_client_data_softkey;
6246 }
6247
6248 static void
6249 _tzsh_cb_softkey_destroy(struct wl_resource *res_tzsh_softkey)
6250 {
6251    E_Policy_Wl_Tzsh_Client *tzsh_client;
6252
6253    tzsh_client = wl_resource_get_user_data(res_tzsh_softkey);
6254    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6255
6256    E_Policy_Wl_Tzsh_Client_Data_Softkey *tzsh_client_data_softkey;
6257    tzsh_client_data_softkey = (E_Policy_Wl_Tzsh_Client_Data_Softkey*)tzsh_client->client_data;
6258    if (tzsh_client_data_softkey)
6259      {
6260         if (tzsh_client_data_softkey->show_state == 0)
6261           {
6262              ELOGF("TZ_SOFTKEY", "Request to Show softkey by destroying client", NULL);
6263              _tzsh_softkey_show(tzsh_client);
6264           }
6265      }
6266    E_FREE(tzsh_client->client_data);
6267
6268    tzsh_client->res_tzsh_client = NULL;
6269    _e_policy_wl_tzsh_client_del(tzsh_client);
6270 }
6271
6272
6273 static void
6274 _tzsh_iface_cb_softkey_get(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id, uint32_t surf_id)
6275 {
6276    E_Policy_Wl_Tzsh *tzsh;
6277    E_Policy_Wl_Tzsh_Client *tzsh_client;
6278    struct wl_resource *res_tzsh_softkey;
6279    E_Client *ec;
6280    E_Pixmap *cp;
6281    pid_t pid;
6282    uid_t uid;
6283
6284    tzsh = wl_resource_get_user_data(res_tzsh);
6285    if (!tzsh)
6286      {
6287         wl_resource_post_error
6288            (res_tzsh,
6289             WL_DISPLAY_ERROR_INVALID_OBJECT,
6290             "Invalid res_tzsh's user data");
6291         return;
6292      }
6293
6294    wl_client_get_credentials(client, &pid, &uid, NULL);
6295    if (!e_security_privilege_check(pid, uid, E_PRIVILEGE_SOFTKEY))
6296      {
6297         ERR("Could not get privilege of resource: %m");
6298         tizen_ws_shell_send_error(tzsh->res_tzsh, TIZEN_WS_SHELL_ERROR_PERMISSION_DENIED);
6299         return;
6300      }
6301    else
6302      tizen_ws_shell_send_error(tzsh->res_tzsh, TIZEN_WS_SHELL_ERROR_NONE);
6303
6304    cp = _e_policy_wl_e_pixmap_get_from_id(client, surf_id);
6305    if (!cp)
6306      {
6307         wl_resource_post_error
6308            (res_tzsh,
6309             WL_DISPLAY_ERROR_INVALID_OBJECT,
6310             "Invalid surface id");
6311         return;
6312      }
6313
6314    ec = e_pixmap_client_get(cp);
6315    if (ec)
6316      {
6317         if (!_e_policy_wl_e_client_is_valid(ec))
6318           {
6319              wl_resource_post_error
6320                 (res_tzsh,
6321                  WL_DISPLAY_ERROR_INVALID_OBJECT,
6322                  "Invalid surface id");
6323              return;
6324           }
6325      }
6326
6327    res_tzsh_softkey = wl_resource_create(client,
6328                                          &tws_softkey_interface,
6329                                          wl_resource_get_version(res_tzsh),
6330                                          id);
6331    if (!res_tzsh_softkey)
6332      {
6333         ERR("Could not create tws_softkey resource: %m");
6334         wl_client_post_no_memory(client);
6335         return;
6336      }
6337
6338    tzsh_client = _e_policy_wl_tzsh_client_add(tzsh, res_tzsh_softkey, cp, ec);
6339    if (!tzsh_client)
6340      {
6341         ERR("Could not create tzsh_client");
6342         wl_client_post_no_memory(client);
6343         return;
6344      }
6345
6346    tzsh_client->handle_type = TZSH_CLIENT_HANDLE_TYPE_SOFTKEY;
6347    tzsh_client->client_data = _tzsh_client_data_softkey_new();
6348    if (!tzsh_client->client_data)
6349      {
6350         ERR("Could not create tzsh_client");
6351         _e_policy_wl_tzsh_client_del(tzsh_client);
6352         wl_resource_destroy(res_tzsh_softkey);
6353         wl_client_post_no_memory(client);
6354         return;
6355      }
6356
6357    wl_resource_set_implementation(res_tzsh_softkey,
6358                                   &_tzsh_softkey_iface,
6359                                   tzsh_client,
6360                                   _tzsh_cb_softkey_destroy);
6361 }
6362
6363 // --------------------------------------------------------
6364 // tizen_ws_shell_interface::shared_widget_launch
6365 // --------------------------------------------------------
6366 EINTERN Eina_Bool
6367 e_tzsh_shared_widget_launch_prepare_send(E_Client *callee_ec,
6368                                          uint32_t state,
6369                                          uint32_t serial)
6370 {
6371    E_Policy_Wl_Tzsh_Client *tzsh_client;
6372    Eina_List *l;
6373    Eina_Bool res = EINA_FALSE;
6374
6375    EINA_SAFETY_ON_NULL_RETURN_VAL(callee_ec, EINA_FALSE);
6376    EINA_SAFETY_ON_TRUE_RETURN_VAL(e_object_is_del(E_OBJECT(callee_ec)), EINA_FALSE);
6377
6378    EINA_LIST_FOREACH(polwl->tzsh_clients, l, tzsh_client)
6379      {
6380         if (!tzsh_client->tzsh) continue;
6381         if (!tzsh_client->ec) continue;
6382         if (tzsh_client->ec != callee_ec) continue;
6383
6384         tws_shared_widget_launch_send_prepare_shared_widget(tzsh_client->res_tzsh_client,
6385                                                             state,
6386                                                             serial);
6387
6388         res = EINA_TRUE;
6389         break;
6390      }
6391
6392    return res;
6393 }
6394
6395 static void
6396 _tzsh_swl_iface_cb_release(struct wl_client *client,
6397                            struct wl_resource *res_tzsh_swl)
6398 {
6399    ELOGF("TZSH_SWL", "Release", NULL);
6400
6401    wl_resource_destroy(res_tzsh_swl);
6402 }
6403
6404 static void
6405 _tzsh_swl_iface_cb_prepare_shared_widget_done(struct wl_client *client,
6406                                               struct wl_resource *res_tzsh_swl,
6407                                               const char *shared_widget_info,
6408                                               uint32_t state,
6409                                               uint32_t serial)
6410 {
6411    E_Policy_Wl_Tzsh_Client *tzsh_client;
6412
6413    ELOGF("TZSH_SWL", "Done", NULL);
6414
6415    tzsh_client = wl_resource_get_user_data(res_tzsh_swl);
6416    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6417    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->tzsh);
6418    EINA_SAFETY_ON_NULL_RETURN(tzsh_client->ec);
6419    EINA_SAFETY_ON_NULL_RETURN(eina_list_data_find(polwl->tzsh_clients, tzsh_client));
6420
6421    // send prepare event to caller
6422    e_service_launcher_prepare_send_with_shared_widget_info(tzsh_client->ec,
6423                                                            shared_widget_info,
6424                                                            state,
6425                                                            serial);
6426 }
6427
6428 static const struct tws_shared_widget_launch_interface _tzsh_swl_iface =
6429 {
6430    _tzsh_swl_iface_cb_release,
6431    _tzsh_swl_iface_cb_prepare_shared_widget_done,
6432 };
6433
6434 static void
6435 _tzsh_cb_swl_destroy(struct wl_resource *res_tzsh_swl)
6436 {
6437    E_Policy_Wl_Tzsh_Client *tzsh_client;
6438
6439    ELOGF("TZSH_SWL", "Destroy", NULL);
6440
6441    tzsh_client = wl_resource_get_user_data(res_tzsh_swl);
6442    EINA_SAFETY_ON_NULL_RETURN(tzsh_client);
6443
6444    e_service_launcher_release_shared_widget_launch(tzsh_client->ec);
6445
6446    tzsh_client->res_tzsh_client = NULL;
6447    _e_policy_wl_tzsh_client_del(tzsh_client);
6448 }
6449
6450 static void
6451 _tzsh_iface_cb_shared_widget_launch_get(struct wl_client *client,
6452                                         struct wl_resource *res_tzsh,
6453                                         uint32_t id,
6454                                         uint32_t surf_id)
6455 {
6456    E_Policy_Wl_Tzsh *tzsh;
6457    E_Policy_Wl_Tzsh_Client *tzsh_client;
6458    struct wl_resource *res_tzsh_swl;
6459    E_Client *ec;
6460    E_Pixmap *cp;
6461
6462    tzsh = wl_resource_get_user_data(res_tzsh);
6463    if (!tzsh)
6464      {
6465         wl_resource_post_error
6466            (res_tzsh,
6467             WL_DISPLAY_ERROR_INVALID_OBJECT,
6468             "Invalid res_tzsh's user data");
6469         return;
6470      }
6471
6472    cp = _e_policy_wl_e_pixmap_get_from_id(client, surf_id);
6473    if (!cp)
6474      {
6475         wl_resource_post_error
6476            (res_tzsh,
6477             WL_DISPLAY_ERROR_INVALID_OBJECT,
6478             "Invalid surface id");
6479         return;
6480      }
6481
6482    ec = e_pixmap_client_get(cp);
6483    if (ec)
6484      {
6485         if (!_e_policy_wl_e_client_is_valid(ec))
6486           {
6487              wl_resource_post_error
6488                 (res_tzsh,
6489                  WL_DISPLAY_ERROR_INVALID_OBJECT,
6490                  "Invalid surface id");
6491              return;
6492           }
6493      }
6494
6495    res_tzsh_swl = wl_resource_create(client,
6496                                      &tws_shared_widget_launch_interface,
6497                                      wl_resource_get_version(res_tzsh),
6498                                      id);
6499    if (!res_tzsh_swl)
6500      {
6501         ERR("Could not create tws_shared_widget_launch resource: %m");
6502         wl_client_post_no_memory(client);
6503         return;
6504      }
6505
6506    tzsh_client = _e_policy_wl_tzsh_client_add(tzsh, res_tzsh_swl, cp, ec);
6507    if (!tzsh_client)
6508      {
6509         ERR("Could not create tzsh_client");
6510         wl_client_post_no_memory(client);
6511         return;
6512      }
6513
6514    tzsh_client->handle_type = TZSH_CLIENT_HANDLE_TYPE_SHARED_WIDGET_LAUNCH;
6515
6516    wl_resource_set_implementation(res_tzsh_swl,
6517                                   &_tzsh_swl_iface,
6518                                   tzsh_client,
6519                                   _tzsh_cb_swl_destroy);
6520 }
6521
6522 // --------------------------------------------------------
6523 // tizen_ws_shell_interface
6524 // --------------------------------------------------------
6525 static void
6526 _tzsh_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzsh)
6527 {
6528    wl_resource_destroy(res_tzsh);
6529 }
6530
6531 static const struct tizen_ws_shell_interface _tzsh_iface =
6532 {
6533    _tzsh_iface_cb_destroy,
6534    _tzsh_iface_cb_srv_create,
6535    _tzsh_iface_cb_reg_create,
6536    _tzsh_iface_cb_qp_get,
6537    _tzsh_iface_cb_extension_get,
6538    _tzsh_iface_cb_softkey_get,
6539    _tzsh_iface_cb_shared_widget_launch_get,
6540 };
6541
6542 static void
6543 _tzsh_cb_unbind(struct wl_resource *res_tzsh)
6544 {
6545    E_Policy_Wl_Tzsh *tzsh;
6546
6547    tzsh = wl_resource_get_user_data(res_tzsh);
6548    EINA_SAFETY_ON_NULL_RETURN(tzsh);
6549
6550    _e_policy_wl_tzsh_del(tzsh);
6551 }
6552
6553 static void
6554 _tzsh_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
6555 {
6556    E_Policy_Wl_Tzsh *tzsh;
6557    struct wl_resource *res_tzsh;
6558
6559    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
6560
6561    res_tzsh = wl_resource_create(client,
6562                                  &tizen_ws_shell_interface,
6563                                  ver,
6564                                  id);
6565    EINA_SAFETY_ON_NULL_GOTO(res_tzsh, err);
6566
6567    tzsh = _e_policy_wl_tzsh_add(res_tzsh);
6568    EINA_SAFETY_ON_NULL_GOTO(tzsh, err);
6569
6570    wl_resource_set_implementation(res_tzsh,
6571                                   &_tzsh_iface,
6572                                   tzsh,
6573                                   _tzsh_cb_unbind);
6574
6575    _e_policy_wl_tzsh_registered_srv_send(tzsh);
6576    return;
6577
6578 err:
6579    ERR("Could not create tizen_ws_shell_interface res: %m");
6580    wl_client_post_no_memory(client);
6581 }
6582
6583 // --------------------------------------------------------
6584 // tizen_launch_effect_interface
6585 // --------------------------------------------------------
6586 #define SPLASH_GROUP_NAME "effect"
6587 #define SPLASH_CONFIG_CUSTOM_EFFECT_CALLEE "_CUSTOM_EFFECT_CALLEE_"
6588
6589 static void
6590 _launch_effect_hide(uint32_t pid)
6591 {
6592    Eina_List *l, *ll;
6593    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;
6594    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
6595
6596    if(pid <= 0) return;
6597
6598    EINA_LIST_FOREACH(polwl->tzlaunch_effect, l, tzlaunch_effect)
6599      {
6600         EINA_LIST_FOREACH(tzlaunch_effect->splash_list, ll, tzlaunch_splash)
6601            if (tzlaunch_splash->pid == pid)
6602              {
6603                 _launch_splash_off(tzlaunch_splash);
6604              }
6605      }
6606 }
6607
6608 static void
6609 _launch_effect_client_del(E_Client *ec)
6610 {
6611    Eina_List *l, *ll;
6612    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;
6613    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
6614
6615    EINA_LIST_FOREACH(polwl->tzlaunch_effect, l, tzlaunch_effect)
6616      {
6617         EINA_LIST_FOREACH(tzlaunch_effect->splash_list, ll, tzlaunch_splash)
6618            if (tzlaunch_splash->ec == ec)
6619              {
6620                 _launch_splash_off(tzlaunch_splash);
6621              }
6622      }
6623 }
6624
6625 static void
6626 _launchscreen_splash_cb_indicator_resized(Ecore_Evas *ee)
6627 {
6628    Evas_Coord_Size size = {0, 0};
6629    Evas_Object *indicator_obj;
6630    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
6631
6632    tzlaunch_splash = ecore_evas_data_get(ee, "tzlaunch_splash");
6633    if (!tzlaunch_splash) return;
6634
6635    indicator_obj = tzlaunch_splash->indicator_obj;
6636
6637    ecore_evas_geometry_get(ee, NULL, NULL, &(size.w), &(size.h));
6638    ELOGF("TZPOL", "Launchscreen indicator_obj resized(%d x %d)",
6639          NULL,
6640          size.w, size.h);
6641    evas_object_size_hint_min_set(indicator_obj, size.w, size.h);
6642    evas_object_size_hint_max_set(indicator_obj, size.w, size.h);
6643    e_comp_object_indicator_size_set(tzlaunch_splash->ec->frame, size.w, size.h);
6644 }
6645
6646 static void
6647 _launchscreen_splash_cb_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
6648 {
6649    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash = data;
6650
6651    if ((tzlaunch_splash) && (tzlaunch_splash->obj == obj))
6652      tzlaunch_splash->obj = NULL;
6653 }
6654
6655 static void
6656 _launchscreen_splash_cb_hide(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
6657 {
6658    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash = data;
6659
6660    if ((tzlaunch_splash) && (tzlaunch_splash->obj == obj))
6661      _launch_splash_off(tzlaunch_splash);
6662 }
6663
6664 static void
6665 _launch_splash_off(E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash)
6666 {
6667    E_Client *ec = NULL;
6668    Evas_Object *obj = NULL;
6669
6670    if (!tzlaunch_splash->valid) return;
6671    if (!tzlaunch_splash->ec) return;
6672
6673    ec = tzlaunch_splash->ec;
6674    obj = tzlaunch_splash->obj;
6675
6676    tzlaunch_splash->obj = NULL;
6677    tzlaunch_splash->ec = NULL;
6678    tzlaunch_splash->valid = EINA_FALSE;
6679    if (tzlaunch_splash->timeout) ecore_timer_del(tzlaunch_splash->timeout);
6680    tzlaunch_splash->timeout = NULL;
6681
6682    eina_stringshare_del(tzlaunch_splash->appid);
6683    tzlaunch_splash->appid = NULL;
6684    eina_stringshare_del(tzlaunch_splash->path);
6685    tzlaunch_splash->path = NULL;
6686
6687
6688    ELOGF("TZPOL",
6689          "Launchscreen hide | pid %d, replaced:%d, tzlaunch_pixmap:%p, ec_pixmap:%p",
6690          ec, tzlaunch_splash->pid, tzlaunch_splash->replaced, tzlaunch_splash->ep, ec->pixmap);
6691
6692    if (tzlaunch_splash->indicator_obj)
6693      {
6694         e_comp_object_indicator_unswallow(ec->frame, tzlaunch_splash->indicator_obj);
6695         evas_object_del(tzlaunch_splash->indicator_obj);
6696         evas_object_unref(tzlaunch_splash->indicator_obj);
6697         tzlaunch_splash->indicator_obj = NULL;
6698      }
6699
6700    if ((ec->pixmap) &&
6701        (ec->pixmap == tzlaunch_splash->ep))
6702      {
6703         /* case 1: Surface for this pid is not created until timeout or
6704          * launchscreen resource is destroied.
6705          */
6706         if (ec->visible)
6707           {
6708              ec->visible = EINA_FALSE;
6709              evas_object_hide(ec->frame);
6710              ec->ignored = EINA_TRUE;
6711           }
6712
6713         e_comp->launchscrns = eina_list_remove(e_comp->launchscrns, ec);
6714
6715         e_pixmap_win_id_del(tzlaunch_splash->ep);
6716         e_object_del(E_OBJECT(ec));
6717         ec = NULL;
6718      }
6719
6720    if (ec)
6721      {
6722         if (!e_util_strcmp("wl_pointer-cursor", ec->icccm.window_role))
6723           {
6724              // if Launchscreen is replaced to cursor, than hide
6725              e_comp_object_content_unset(ec->frame);
6726              ec->visible = EINA_FALSE;
6727              evas_object_hide(ec->frame);
6728              ec->ignored = EINA_TRUE;
6729           }
6730         else if (!tzlaunch_splash->replaced)
6731           {
6732              if (ec->focused)
6733                e_comp_wl_feed_focus_in(ec);
6734
6735              /* to send launch,done event to launchscreen client */
6736              if (!e_object_is_del(E_OBJECT(ec)))
6737                {
6738                   if (ec->first_mapped)
6739                     {
6740                        ELOGF("LAUNCH", "SHOW real win by replaced splash ec", ec);
6741                        e_comp_object_signal_emit(ec->frame, "e,action,launch_real,done", "e");
6742                     }
6743                   e_comp_object_signal_emit(ec->frame, "e,action,launch,done", "e");
6744                }
6745           }
6746
6747         e_comp->launchscrns = eina_list_remove(e_comp->launchscrns, ec);
6748      }
6749
6750    if (obj)
6751      evas_object_unref(obj);
6752
6753    tzlaunch_splash->ep = NULL;
6754    tzlaunch_splash->replaced = EINA_FALSE;
6755 }
6756
6757 static Eina_Bool
6758 _launchscreen_splash_timeout(void *data)
6759 {
6760    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
6761    tzlaunch_splash = (E_Policy_Wl_Tzlaunch_Splash *)data;
6762
6763    EINA_SAFETY_ON_NULL_RETURN_VAL(tzlaunch_splash, 0);
6764
6765    _launch_splash_off(tzlaunch_splash);
6766
6767    return ECORE_CALLBACK_CANCEL;
6768 }
6769
6770 static Eina_Bool
6771 _launchscreen_splash_setup(E_Policy_Wl_Tzlaunch_Splash *splash,
6772                            const char *pfname, uint32_t ftype,
6773                            uint32_t depth, uint32_t angle,
6774                            uint32_t indicator, const char *effect_type,
6775                            const char *theme_type, struct wl_array *options,
6776                            struct wl_array *extra_config)
6777 {
6778    E_Client *ec = NULL;
6779    E_Comp_Object_Content_Type content_type = 0;
6780    Eina_Bool intercepted = EINA_FALSE;
6781
6782    EINA_SAFETY_ON_NULL_RETURN_VAL(splash->ec, EINA_FALSE);
6783    EINA_SAFETY_ON_NULL_RETURN_VAL(splash->ec->frame, EINA_FALSE);
6784
6785    ec = splash->ec;
6786    ec->effect_type = _e_policy_wl_tzlaunch_effect_type_get(effect_type);
6787
6788    ELOGF("TZPOL",
6789          "Launchscreen setup START| path %s(%d), indicator(%d), angle(%d), effect_type(%s), theme_type(%s)",
6790          ec, pfname, ftype, indicator, angle, effect_type, theme_type);
6791    ELOGF("TZPOL",
6792          "Launchscreen setup | options %p extra_config:%p",
6793          ec, options, extra_config);
6794
6795    splash->path = eina_stringshare_add(pfname);
6796    splash->type = ftype;
6797    splash->indicator = indicator;
6798    splash->angle = angle;
6799
6800    if (indicator)
6801      {
6802         /* To configure indicator options */
6803         ec->indicator.state = TIZEN_INDICATOR_STATE_ON;
6804         ec->indicator.visible_type = TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN;
6805         ec->indicator.opacity_mode = TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT;
6806      }
6807
6808    intercepted = e_policy_interceptor_call(E_POLICY_INTERCEPT_LAUNCHSCREEN_OBJECT_SETUP,
6809                                            ec,
6810                                            pfname, ftype, depth,
6811                                            angle, indicator, options);
6812    if (intercepted)
6813      {
6814         splash->obj = e_comp_object_content_get(ec->frame);
6815
6816         ELOGF("TZPOL",
6817               "Launchscreen setup | was INTERCEPTED : content(%p)",
6818               ec, splash->obj);
6819      }
6820    else //Do original setup process
6821      {
6822         if (splash->type == LAUNCH_IMG_FILE_TYPE_IMAGE)
6823           {
6824              Evas_Load_Error err;
6825
6826              content_type = E_COMP_OBJECT_CONTENT_TYPE_EXT_IMAGE;
6827              splash->obj = evas_object_image_add(e_comp->evas);
6828              EINA_SAFETY_ON_NULL_RETURN_VAL(splash->obj, EINA_FALSE);
6829
6830              evas_object_image_file_set(splash->obj, splash->path, NULL);
6831
6832              err = evas_object_image_load_error_get(splash->obj);
6833              if (err != EVAS_LOAD_ERROR_NONE)
6834                {
6835                   ELOGF("TZPOL",
6836                         "Launchscreen setup | fail to load image %s : %s",
6837                         ec, splash->path, evas_load_error_str(err));
6838                   evas_object_del(splash->obj);
6839                   splash->obj = NULL;
6840                   return EINA_FALSE;
6841                }
6842
6843              evas_object_image_fill_set(splash->obj, 0, 0, e_comp->w, e_comp->h);
6844              evas_object_image_filled_set(splash->obj, EINA_TRUE);
6845           }
6846         else
6847           {
6848              content_type = E_COMP_OBJECT_CONTENT_TYPE_EXT_EDJE;
6849              splash->obj = edje_object_add(e_comp->evas);
6850              EINA_SAFETY_ON_NULL_RETURN_VAL(splash->obj, EINA_FALSE);
6851
6852              if (!edje_object_file_set(splash->obj, splash->path, SPLASH_GROUP_NAME))
6853                {
6854                   Edje_Load_Error err;
6855
6856                   err = edje_object_load_error_get(splash->obj);
6857                   ELOGF("TZPOL",
6858                         "Launchscreen setup | fail to load edje %s : %s",
6859                         ec, splash->path, edje_load_error_str(err));
6860                   evas_object_del(splash->obj);
6861                   splash->obj = NULL;
6862                   return EINA_FALSE;
6863
6864                }
6865
6866              evas_object_move(splash->obj, 0, 0);
6867              evas_object_resize(splash->obj, e_comp->w, e_comp->h);
6868           }
6869
6870         if (depth == 32) ec->argb = EINA_TRUE;
6871         else ec->argb = EINA_FALSE;
6872         ELOGF("COMP", "Set argb:%d", ec, ec->argb);
6873
6874         //set splash->obj to a content of ec->frame
6875         if (!e_comp_object_content_set(ec->frame, splash->obj, content_type))
6876           {
6877              ERR("Launchscreen setup | setting comp object content failed ec(%p) obj(%p)",
6878                  ec, splash->obj);
6879              return EINA_FALSE;
6880           }
6881      }
6882
6883
6884    /* Post job of setup content_type */
6885
6886    //Parse extra config
6887    if ((extra_config) && (extra_config->size))
6888      {
6889         char *p_char;
6890         int len = 0;
6891         int size = extra_config->size;
6892
6893         while (size > 0)
6894           {
6895              p_char = extra_config->data + len;
6896              len = strlen(p_char) + 1;
6897              size -= len;
6898
6899              if (!e_util_strcmp(p_char, SPLASH_CONFIG_CUSTOM_EFFECT_CALLEE))
6900                {
6901                   //parse next data(appid) from array
6902                   if (size > 0)
6903                     {
6904                        p_char = p_char + len;
6905                        len = strlen(p_char) + 1;
6906                        size -= len;
6907
6908                        splash->appid = eina_stringshare_add(p_char);
6909                        splash->custom_effect_callee = EINA_TRUE;
6910
6911                        ELOGF("TZPOL",
6912                              "Launchscreen setup | custom effect callee set appid(%s)",
6913                              ec, splash->appid);
6914                     }
6915                   else break;
6916                }
6917           }
6918      }
6919
6920    //Setup indicator
6921    if (indicator)
6922      {
6923         Evas_Object *indicator_obj = NULL;
6924         Eina_Bool ret = EINA_FALSE;
6925
6926         e_mod_indicator_owner_set(ec);
6927         e_tzsh_indicator_srv_property_update(ec);
6928
6929         indicator_obj = ecore_evas_extn_plug_new(e_comp->ee);
6930         if (!indicator_obj)
6931           {
6932              ELOGF("TZPOL",
6933                    "Launchscreen setup | Failed to create ecore_evas_plug for indicator",
6934                    ec);
6935           }
6936         else
6937           {
6938              if (e_config->indicator_plug_name)
6939                {
6940                   ret = ecore_evas_extn_plug_connect(indicator_obj, e_config->indicator_plug_name, 0, EINA_FALSE);
6941                   if (ret)
6942                     {
6943                        Ecore_Evas *ee;
6944
6945                        ee = ecore_evas_object_ecore_evas_get(indicator_obj);
6946                        ecore_evas_data_set(ee, "tzlaunch_splash", splash);
6947                        ecore_evas_callback_resize_set(ee,
6948                                                       _launchscreen_splash_cb_indicator_resized);
6949                        e_comp_object_indicator_swallow(ec->frame, indicator_obj);
6950                        evas_object_ref(indicator_obj);
6951                        ELOGF("TZPOL",
6952                              "Launchscreen launch | Succeeded to add indicator object plug_name(%s) indicator_obj(%p)",
6953                              ec, e_config->indicator_plug_name, indicator_obj);
6954                     }
6955                   else
6956                     {
6957                        evas_object_del(indicator_obj);
6958                        indicator_obj = NULL;
6959                     }
6960                }
6961
6962              if (!indicator_obj)
6963                {
6964                   ELOGF("TZPOL",
6965                         "Launchscreen launch | Failed to add indicator object plug_name(%s)",
6966                         ec, e_config->indicator_plug_name?:"NO PLUG NAME");
6967                }
6968           }
6969
6970         splash->indicator_obj = indicator_obj;
6971      }
6972
6973    //ref splash object
6974    if (splash->obj)
6975      {
6976         evas_object_ref(splash->obj);
6977
6978         evas_object_event_callback_add(splash->obj,
6979                                        EVAS_CALLBACK_DEL,
6980                                        _launchscreen_splash_cb_del, splash);
6981         evas_object_event_callback_add(splash->obj,
6982                                        EVAS_CALLBACK_HIDE,
6983                                        _launchscreen_splash_cb_hide, splash);
6984      }
6985
6986    splash->valid = EINA_TRUE;
6987    splash->content_type = e_comp_object_content_type_get(ec->frame);
6988
6989    return EINA_TRUE;
6990 }
6991
6992 static void
6993 _tzlaunch_splash_iface_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzlaunch_splash)
6994 {
6995    wl_resource_destroy(res_tzlaunch_splash);
6996 }
6997
6998 static void
6999 _tzlaunch_splash_iface_cb_launch(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzlaunch_splash,
7000                                  const char *pfname, uint32_t ftype,
7001                                  uint32_t depth, uint32_t angle,
7002                                  uint32_t indicator, const char *effect_type,
7003                                  const char *theme_type, struct wl_array *options)
7004 {
7005    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
7006    Eina_Bool res = EINA_FALSE;
7007
7008    tzlaunch_splash = wl_resource_get_user_data(res_tzlaunch_splash);
7009    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_splash);
7010
7011    ELOGF("TZPOL","Launchscreen launch | START", NULL);
7012
7013
7014    res = _launchscreen_splash_setup(tzlaunch_splash,
7015                                     pfname, ftype,
7016                                     depth, angle,
7017                                     indicator, effect_type,
7018                                     theme_type, options, NULL);
7019
7020    ELOGF("TZPOL","Launchscreen launch | END res:%d ", NULL, res);
7021
7022    if (!res)
7023      {
7024         ERR("Launchscreen launch | Could not complete %s", __FUNCTION__);
7025         if (tzlaunch_splash->obj)
7026           {
7027              evas_object_del(tzlaunch_splash->obj);
7028              tzlaunch_splash->obj = NULL;
7029           }
7030      }
7031 }
7032
7033 static void
7034 _tzlaunch_splash_iface_cb_owner(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tzlaunch_splash, uint32_t pid)
7035 {
7036    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
7037    E_Client *pre_ec = NULL, *new_ec = NULL, *old_ec;
7038    Eina_List *clients, *l;
7039
7040    tzlaunch_splash = wl_resource_get_user_data(res_tzlaunch_splash);
7041    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_splash);
7042    EINA_SAFETY_ON_FALSE_RETURN(tzlaunch_splash->valid);
7043
7044    /* use ec was already created */
7045    clients = _e_policy_wl_e_clients_find_by_pid(pid);
7046    EINA_LIST_FOREACH(clients, l, pre_ec)
7047      {
7048         if (pre_ec == tzlaunch_splash->ec) continue;
7049         if (!pre_ec->ignored) continue;
7050         if (pre_ec->is_cursor) continue;
7051         new_ec = pre_ec;
7052         break;
7053      }
7054    eina_list_free(clients);
7055
7056    old_ec = tzlaunch_splash->ec;
7057    if (new_ec)
7058      {
7059         if (e_comp_object_content_set(new_ec->frame,
7060                                       tzlaunch_splash->obj,
7061                                       tzlaunch_splash->content_type))
7062           {
7063              e_client_unignore(new_ec);
7064              new_ec->visible = EINA_TRUE;
7065              if (new_ec->new_client)
7066                e_comp->new_clients--;
7067              new_ec->new_client = EINA_FALSE;
7068              new_ec->argb = old_ec->argb;
7069              ELOGF("COMP", "Set argb:%d", new_ec, new_ec->argb);
7070              new_ec->effect_type = old_ec->effect_type;
7071              new_ec->use_splash = EINA_TRUE;
7072              new_ec->icccm.title = eina_stringshare_add("launchscreen");
7073
7074              e_comp->launchscrns = eina_list_append(e_comp->launchscrns, new_ec);
7075
7076              if (tzlaunch_splash->custom_effect_callee)
7077                {
7078                   e_service_launcher_callee_register(new_ec, tzlaunch_splash->appid, tzlaunch_splash->path, SPLASH_GROUP_NAME);
7079                }
7080
7081              evas_object_show(new_ec->frame);
7082              e_client_raise(new_ec);
7083
7084              tzlaunch_splash->ec = new_ec;
7085              tzlaunch_splash->replaced = EINA_TRUE;
7086
7087              ELOGF("TZPOL",
7088                    "Launchscreen client changed | old(%p) new(%p) using obj(%p)",
7089                    new_ec,
7090                    old_ec, new_ec, tzlaunch_splash->obj);
7091
7092              if (tzlaunch_splash->indicator_obj)
7093                {
7094                   e_mod_indicator_owner_set(new_ec);
7095                   e_tzsh_indicator_srv_property_update(new_ec);
7096                   e_comp_object_indicator_unswallow(old_ec->frame, tzlaunch_splash->indicator_obj);
7097                   e_comp_object_indicator_swallow(new_ec->frame, tzlaunch_splash->indicator_obj);
7098                }
7099
7100              /* delete ec was created for launchscreen */
7101              e_comp->launchscrns = eina_list_remove(e_comp->launchscrns, old_ec);
7102
7103              e_pixmap_win_id_del(tzlaunch_splash->ep);
7104              e_object_del(E_OBJECT(old_ec));
7105              tzlaunch_splash->ep = NULL;
7106           }
7107         else
7108           ERR("Can't set external content for new_ec(%p)", new_ec);
7109      }
7110    else
7111      {
7112         old_ec->ignored = EINA_FALSE;
7113         old_ec->visible = EINA_TRUE;
7114         if (old_ec->new_client)
7115           e_comp->new_clients--;
7116         old_ec->new_client = EINA_FALSE;
7117         old_ec->icccm.accepts_focus = EINA_TRUE;
7118
7119         if (tzlaunch_splash->custom_effect_callee)
7120           {
7121              e_service_launcher_callee_register(old_ec, tzlaunch_splash->appid, tzlaunch_splash->path, SPLASH_GROUP_NAME);
7122           }
7123
7124         evas_object_show(old_ec->frame);
7125         e_client_raise(old_ec);
7126      }
7127
7128    EC_CHANGED(tzlaunch_splash->ec);
7129    e_comp_visibility_calculation_set(EINA_TRUE);
7130
7131    if (tzlaunch_splash->timeout)
7132      {
7133         ecore_timer_del(tzlaunch_splash->timeout);
7134         tzlaunch_splash->timeout = NULL;
7135      }
7136    if (!e_config->launchscreen_without_timer)
7137      tzlaunch_splash->timeout = ecore_timer_add(e_config->launchscreen_timeout, _launchscreen_splash_timeout, tzlaunch_splash);
7138
7139    ELOGF("TZPOL", "Launchscreen img(%d) set owner pid: %d",
7140          tzlaunch_splash->ec,
7141          wl_resource_get_id(res_tzlaunch_splash), pid);
7142
7143    tzlaunch_splash->pid = pid;
7144    tzlaunch_splash->ec->netwm.pid = pid;
7145    tzlaunch_splash->ec->use_splash = EINA_TRUE;
7146 }
7147
7148 static void
7149 _tzlaunch_splash_iface_cb_launch_v2(struct wl_client *client EINA_UNUSED,
7150                                     struct wl_resource *res_tzlaunch_splash,
7151                                     const char *pfname, uint32_t ftype,
7152                                     uint32_t depth, uint32_t angle,
7153                                     uint32_t indicator, const char *effect_type,
7154                                     const char *theme_type, struct wl_array *options,
7155                                     struct wl_array *extra_config)
7156 {
7157    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
7158    Eina_Bool res = EINA_FALSE;
7159
7160    tzlaunch_splash = wl_resource_get_user_data(res_tzlaunch_splash);
7161    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_splash);
7162
7163    ELOGF("TZPOL","Launchscreen launch_v2 | START", NULL);
7164
7165    res = _launchscreen_splash_setup(tzlaunch_splash,
7166                                     pfname, ftype,
7167                                     depth, angle,
7168                                     indicator, effect_type,
7169                                     theme_type, options, extra_config);
7170
7171    ELOGF("TZPOL","Launchscreen launch_v2 | END res:%d ", NULL, res);
7172
7173    if (!res)
7174      {
7175         ERR("Launchscreen launch_v2 | Could not complete %s", __FUNCTION__);
7176         if (tzlaunch_splash->obj)
7177           {
7178              evas_object_del(tzlaunch_splash->obj);
7179              tzlaunch_splash->obj = NULL;
7180           }
7181      }
7182
7183 }
7184
7185 static const struct tizen_launch_splash_interface _tzlaunch_splash_iface =
7186 {
7187    _tzlaunch_splash_iface_cb_destroy,
7188    _tzlaunch_splash_iface_cb_launch,
7189    _tzlaunch_splash_iface_cb_owner,
7190    _tzlaunch_splash_iface_cb_launch_v2,
7191 };
7192
7193 static E_Policy_Wl_Tzlaunch_Splash *
7194 _tzlaunch_splash_add(struct wl_resource *res_tzlaunch_effect, struct wl_resource *res_tzlaunch_splash)
7195 {
7196    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;
7197    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
7198
7199    tzlaunch_splash = E_NEW(E_Policy_Wl_Tzlaunch_Splash, 1);
7200    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_splash, error);
7201
7202    tzlaunch_effect = wl_resource_get_user_data(res_tzlaunch_effect);
7203    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_effect, error);
7204
7205    tzlaunch_effect->splash_list = eina_list_append(tzlaunch_effect->splash_list, tzlaunch_splash);
7206
7207    tzlaunch_splash->tzlaunch_effect  = tzlaunch_effect;
7208    tzlaunch_splash->res_tzlaunch_splash = res_tzlaunch_splash;
7209
7210    tzlaunch_splash->replaced = EINA_FALSE;
7211    tzlaunch_splash->ep = e_pixmap_new(E_PIXMAP_TYPE_EXT_OBJECT, 0);
7212    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_splash->ep, error);
7213    tzlaunch_splash->ec = e_client_new(tzlaunch_splash->ep, 0, 1);
7214    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_splash->ec, error);
7215
7216    tzlaunch_splash->ec->icccm.title = eina_stringshare_add("Launchscreen");
7217    tzlaunch_splash->ec->icccm.name = eina_stringshare_add("Launchscreen");
7218    tzlaunch_splash->ec->ignored = EINA_TRUE;
7219
7220    e_comp->launchscrns = eina_list_append(e_comp->launchscrns, tzlaunch_splash->ec);
7221
7222    return tzlaunch_splash;
7223 error:
7224    if (tzlaunch_splash)
7225      {
7226         ERR("Could not initialize launchscreen client");
7227         if (tzlaunch_splash->ep)
7228           e_pixmap_win_id_del(tzlaunch_splash->ep);
7229         if (tzlaunch_splash->ec)
7230           e_object_del(E_OBJECT(tzlaunch_splash->ec));
7231         E_FREE(tzlaunch_splash);
7232      }
7233    return NULL;
7234 }
7235
7236
7237 static void
7238 _tzlaunch_splash_destroy(struct wl_resource *res_tzlaunch_splash)
7239 {
7240    E_Policy_Wl_Tzlaunch_Splash *tzlaunch_splash;
7241    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;
7242
7243    EINA_SAFETY_ON_NULL_RETURN(res_tzlaunch_splash);
7244
7245    tzlaunch_splash = wl_resource_get_user_data(res_tzlaunch_splash);
7246    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_splash);
7247
7248    if (tzlaunch_splash->obj)
7249      {
7250         evas_object_event_callback_del_full(tzlaunch_splash->obj, EVAS_CALLBACK_DEL, _launchscreen_splash_cb_del, tzlaunch_splash);
7251         evas_object_event_callback_del_full(tzlaunch_splash->obj, EVAS_CALLBACK_HIDE, _launchscreen_splash_cb_hide, tzlaunch_splash);
7252      }
7253
7254    _launch_splash_off(tzlaunch_splash);
7255
7256    tzlaunch_effect = tzlaunch_splash->tzlaunch_effect;
7257    tzlaunch_effect->splash_list = eina_list_remove(tzlaunch_effect->splash_list, tzlaunch_splash);
7258
7259    eina_stringshare_del(tzlaunch_splash->appid);
7260    eina_stringshare_del(tzlaunch_splash->path);
7261    memset(tzlaunch_splash, 0x0, sizeof(E_Policy_Wl_Tzlaunch_Splash));
7262    E_FREE(tzlaunch_splash);
7263 }
7264
7265 static void
7266 _tzlaunch_effect_iface_cb_create_splash_img(struct wl_client *client, struct wl_resource *res_tzlaunch_effect, uint32_t id)
7267 {
7268
7269    E_Policy_Wl_Tzlaunch_Splash *plaunch_splash;
7270    struct wl_resource *res_tzlaunch_splash;
7271
7272    res_tzlaunch_splash = wl_resource_create(client,
7273                                          &tizen_launch_splash_interface,
7274                                          wl_resource_get_version(res_tzlaunch_effect),
7275                                          id);
7276    if (!res_tzlaunch_splash)
7277      {
7278         wl_resource_post_error
7279            (res_tzlaunch_effect,
7280             WL_DISPLAY_ERROR_INVALID_OBJECT,
7281             "Invalid res_tzlaunch effect's user data");
7282         return;
7283      }
7284
7285    plaunch_splash = _tzlaunch_splash_add(res_tzlaunch_effect, res_tzlaunch_splash);
7286    EINA_SAFETY_ON_NULL_GOTO(plaunch_splash, err);
7287
7288    ELOGF("TZPOL", "Launchscreen effect create splash img. res_tzlaunch_effect:%p, res_tzlaunch_splash:%p", plaunch_splash->ec, res_tzlaunch_effect, res_tzlaunch_splash);
7289
7290    wl_resource_set_implementation(res_tzlaunch_splash,
7291                                   &_tzlaunch_splash_iface,
7292                                   plaunch_splash,
7293                                   _tzlaunch_splash_destroy);
7294
7295    return;
7296
7297 err:
7298    ERR("Could not create tizen_launch_splash_interface res: %m");
7299    wl_client_post_no_memory(client);
7300 }
7301
7302 static void
7303 _tzlaunch_effect_iface_cb_type_set(struct wl_client *client, struct wl_resource *res_tzlaunch_effect,
7304                                                const char *effect_type, uint32_t pid, struct wl_array *options)
7305 {
7306    Eina_List *clients, *l;
7307    E_Client *_ec = NULL;
7308    int effect_set = 0;
7309    int tzlaunch_effect_type = _e_policy_wl_tzlaunch_effect_type_get(effect_type);
7310
7311    clients = _e_policy_wl_e_clients_find_by_pid(pid);
7312    EINA_LIST_FOREACH(clients, l, _ec)
7313      {
7314         if (_ec)
7315           {
7316              _ec->effect_type = tzlaunch_effect_type;
7317              effect_set = 1;
7318              ELOGF("TZPOL",
7319                     "Launchscreen effect type set | exist ec | effect (%d) pid (%d)",
7320                     _ec, tzlaunch_effect_type, pid);
7321           }
7322      }
7323    eina_list_free(clients);
7324
7325    if (effect_set)
7326      _e_policy_wl_tzlaunch_effect_type_unset(pid);
7327    else
7328      {
7329         E_Policy_Wl_Tzlaunch_Effect_Info *tzlaunch_effect_info;
7330
7331         tzlaunch_effect_info = E_NEW(E_Policy_Wl_Tzlaunch_Effect_Info, 1);
7332         EINA_SAFETY_ON_NULL_RETURN(tzlaunch_effect_info);
7333         tzlaunch_effect_info->pid = pid;
7334         tzlaunch_effect_info->effect_type = tzlaunch_effect_type;
7335         polwl->tzlaunch_effect_info = eina_list_append(polwl->tzlaunch_effect_info, tzlaunch_effect_info);
7336
7337         ELOGF("TZPOL",
7338               "Launchscreen effect type set | no match ec | effect (%d) pid (%d)",
7339               NULL, tzlaunch_effect_type, pid);
7340      }
7341 }
7342
7343 static void
7344 _tzlaunch_effect_iface_cb_type_unset(struct wl_client *client, struct wl_resource *res_tzlaunch_effect,
7345                                                  uint32_t pid)
7346 {
7347    _e_policy_wl_tzlaunch_effect_type_unset(pid);
7348 }
7349
7350 static void
7351 _tzlaunch_effect_iface_cb_destroy(struct wl_client *client, struct wl_resource *resource)
7352 {
7353    wl_resource_destroy(resource);
7354 }
7355
7356 static const struct tizen_launch_effect_interface _tzlaunch_effect_iface =
7357 {
7358    _tzlaunch_effect_iface_cb_create_splash_img,
7359    _tzlaunch_effect_iface_cb_type_set,
7360    _tzlaunch_effect_iface_cb_type_unset,
7361    _tzlaunch_effect_iface_cb_destroy,
7362 };
7363
7364 static void
7365 _tzlaunch_effect_del(E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect)
7366 {
7367    E_Policy_Wl_Tzlaunch_Splash *plaunch_splash;
7368    Eina_List *l, *ll;
7369
7370    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_effect);
7371
7372    // remove tzlaunch created splash list
7373    EINA_LIST_FOREACH_SAFE(tzlaunch_effect->splash_list, l, ll, plaunch_splash)
7374      {
7375         if (plaunch_splash->tzlaunch_effect != tzlaunch_effect) continue;
7376         wl_resource_destroy(plaunch_splash->res_tzlaunch_splash);
7377         break;
7378      }
7379
7380    polwl->tzlaunch_effect = eina_list_remove(polwl->tzlaunch_effect, tzlaunch_effect);
7381
7382    memset(tzlaunch_effect, 0x0, sizeof(E_Policy_Wl_Tzlaunch_Effect));
7383    E_FREE(tzlaunch_effect);
7384 }
7385
7386 static E_Policy_Wl_Tzlaunch_Effect *
7387 _tzlaunch_effect_add(struct wl_resource *res_tzlaunch_effect)
7388 {
7389    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect;
7390
7391    tzlaunch_effect = E_NEW(E_Policy_Wl_Tzlaunch_Effect, 1);
7392    EINA_SAFETY_ON_NULL_RETURN_VAL(tzlaunch_effect, NULL);
7393
7394    tzlaunch_effect->res_tzlaunch_effect = res_tzlaunch_effect;
7395
7396    polwl->tzlaunch_effect = eina_list_append(polwl->tzlaunch_effect, tzlaunch_effect);
7397
7398    return tzlaunch_effect;
7399 }
7400
7401 static void
7402 _tzlaunch_effect_cb_unbind(struct wl_resource *res_tzlaunch_effect)
7403 {
7404    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect = NULL;
7405    Eina_List *l, *ll;
7406
7407    EINA_LIST_FOREACH_SAFE(polwl->tzlaunch_effect, l, ll, tzlaunch_effect)
7408      {
7409         if (tzlaunch_effect->res_tzlaunch_effect != res_tzlaunch_effect) continue;
7410         _tzlaunch_effect_del(tzlaunch_effect);
7411         break;
7412      }
7413 }
7414
7415 static void
7416 _tzlaunch_effect_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
7417 {
7418    E_Policy_Wl_Tzlaunch_Effect *tzlaunch_effect = NULL;
7419    struct wl_resource *res_tzlaunch_effect;
7420
7421    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
7422
7423    res_tzlaunch_effect = wl_resource_create(client,
7424                                      &tizen_launch_effect_interface,
7425                                      ver,
7426                                      id);
7427    EINA_SAFETY_ON_NULL_GOTO(res_tzlaunch_effect, err);
7428
7429    tzlaunch_effect = _tzlaunch_effect_add(res_tzlaunch_effect);
7430    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_effect, err);
7431
7432    wl_resource_set_implementation(res_tzlaunch_effect,
7433                                   &_tzlaunch_effect_iface,
7434                                   tzlaunch_effect,
7435                                   _tzlaunch_effect_cb_unbind);
7436
7437    return;
7438
7439 err:
7440    ERR("Could not create tizen_launch_effect_interface res: %m");
7441    wl_client_post_no_memory(client);
7442 }
7443
7444 // --------------------------------------------------------
7445 // tizen_launch_appinfo_interface
7446 // --------------------------------------------------------
7447 static void
7448 _tzlaunch_appinfo_iface_cb_register_pid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7449                                             uint32_t pid)
7450 {
7451    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7452    E_Appinfo *eai = NULL;
7453
7454    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7455    if (!tzlaunch_appinfo)
7456      {
7457         wl_resource_post_error(res_tzlaunch_appinfo,
7458                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7459                                "Invalid tzlaunch_appinfo's user data");
7460         return;
7461      }
7462
7463    if (pid <= 0)
7464      {
7465         ELOGF("TZ_APPINFO", "registered pid is invalid. pid:%u", NULL, pid);
7466         return;
7467      }
7468
7469    eai = e_appinfo_find_with_pid(pid);
7470    if (!eai)
7471      {
7472         eai = e_appinfo_new();
7473         EINA_SAFETY_ON_NULL_RETURN(eai);
7474
7475         if (!e_appinfo_pid_set(eai, pid))
7476           {
7477              ELOGF("TZ_APPINFO", "failed to set pid is invalid. pid:%u", NULL, pid);
7478              e_appinfo_del(eai);
7479              return;
7480           }
7481      }
7482
7483    e_appinfo_owner_set(eai, E_APPINFO_OWNER_CLIENT);
7484 }
7485
7486 static void
7487 _tzlaunch_appinfo_iface_cb_deregister_pid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7488                                             uint32_t pid)
7489 {
7490    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7491    E_Appinfo *eai = NULL;
7492
7493    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7494    if (!tzlaunch_appinfo)
7495      {
7496         wl_resource_post_error(res_tzlaunch_appinfo,
7497                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7498                                "Invalid tzlaunch_appinfo's user data");
7499         return;
7500      }
7501
7502    eai = e_appinfo_find_with_pid(pid);
7503    EINA_SAFETY_ON_NULL_RETURN(eai);
7504
7505    e_appinfo_del(eai);
7506 }
7507
7508 static void
7509 _tzlaunch_appinfo_iface_cb_set_appid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7510                                       uint32_t pid, const char *appid)
7511 {
7512    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7513    E_Appinfo *eai = NULL;
7514    int width = 0;
7515    int height = 0;
7516
7517    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7518    if (!tzlaunch_appinfo)
7519      {
7520         wl_resource_post_error(res_tzlaunch_appinfo,
7521                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7522                                "Invalid tzlaunch_appinfo's user data");
7523         return;
7524      }
7525
7526    if (pid <= 0)
7527      {
7528         ELOGF("TZ_APPINFO", "set pid is invalid. pid:%u", NULL, pid);
7529         return;
7530      }
7531
7532    eai = e_appinfo_find_with_pid(pid);
7533    EINA_SAFETY_ON_NULL_RETURN(eai);
7534
7535    if (!e_appinfo_appid_set(eai, appid))
7536      {
7537         ELOGF("TZ_APPINFO", "failed to set appid, appid:%s", NULL, appid);
7538         return;
7539      }
7540
7541    /* about base  output resolution */
7542    if (e_config->configured_output_resolution.use)
7543      {
7544
7545         // 1. send HOOK with pid
7546         _e_policy_wl_hook_call(E_POLICY_WL_HOOK_BASE_OUTPUT_RESOLUTION_GET, pid);
7547         // 2. module must set the base_output_resolution.
7548         if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
7549           {
7550              ELOGF("TZ_APPINFO", "failed to set base_output_resolution in module, pid:%u, appid:%s", NULL, pid, appid);
7551              return;
7552           }
7553         // 3. server has to get the base_screern_resolution via e_appinfo_base_output_resolution_get.
7554         //    3-1. if success, use the base_rescreen_resolution
7555         //    3-2. if fail, get the base_output_resolution from the E_Comp_Wl_Output.
7556
7557         // 4. send output.
7558         if (!e_comp_wl_pid_output_configured_resolution_send(pid, width, height))
7559           {
7560              ELOGF("TZ_APPINFO", "failed to send output_configured_resolution, pid:%u, appid:%s", NULL, pid, appid);
7561              return;
7562           }
7563      }
7564
7565    return;
7566 }
7567
7568 static void
7569 _tzlaunch_appinfo_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo)
7570 {
7571    wl_resource_destroy(res_tzlaunch_appinfo);
7572 }
7573
7574 static void
7575 _tzlaunch_appinfo_iface_cb_get_base_output_resolution(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7576                                     uint32_t pid)
7577 {
7578    E_Appinfo *eai = NULL;
7579    int width = 0, height = 0;
7580
7581    if (pid <= 0)
7582      {
7583         ELOGF("TZ_APPINFO", "requested pid is invalid. pid:%u", NULL, pid);
7584         goto err;
7585      }
7586
7587    eai = e_appinfo_find_with_pid(pid);
7588    if (!eai)
7589      {
7590         ELOGF("TZ_APPINFO", "cannot find pid. pid:%u", NULL, pid);
7591         goto err;
7592      }
7593
7594    if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
7595      {
7596         ELOGF("TZ_APPINFO", "cannot read size. pid:%u", NULL, pid);
7597         goto err;
7598      }
7599
7600    tizen_launch_appinfo_send_base_output_resolution_done(res_tzlaunch_appinfo, pid, width, height);
7601    ELOGF("TZ_APPINFO", "send Output base_output_resolution size(%d, %d) : pid(%u)", NULL, width, height, pid);
7602
7603    return;
7604
7605 err:
7606    width = e_config->configured_output_resolution.w;
7607    height = e_config->configured_output_resolution.h;
7608    ELOGF("TZ_APPINFO", "send Output base_output_resolution size(%d, %d) : pid(%u)", NULL, width, height, pid);
7609    tizen_launch_appinfo_send_base_output_resolution_done(res_tzlaunch_appinfo, pid, width, height);
7610
7611    return;
7612 }
7613
7614 static void
7615 _tzlaunch_appinfo_iface_cb_register_appid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7616                                           const char *appid)
7617 {
7618    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7619    E_Appinfo *eai = NULL;
7620
7621    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7622    if (!tzlaunch_appinfo)
7623      {
7624         wl_resource_post_error(res_tzlaunch_appinfo,
7625                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7626                                "Invalid tzlaunch_appinfo's user data");
7627         return;
7628      }
7629
7630    if ((eai = e_appinfo_find_with_appid(appid)))
7631      {
7632         ELOGF("TZ_APPINFO", "appid:%s is already registered!", NULL, appid);
7633         return;
7634      }
7635
7636    eai = e_appinfo_new();
7637    EINA_SAFETY_ON_NULL_RETURN(eai);
7638
7639    if (!e_appinfo_appid_set(eai, appid))
7640      {
7641         ELOGF("TZ_APPINFO", "Failed to register appid:%s", NULL, appid);
7642         e_appinfo_del(eai);
7643         return;
7644      }
7645
7646    e_appinfo_owner_set(eai, E_APPINFO_OWNER_CLIENT);
7647 }
7648
7649 static void
7650 _tzlaunch_appinfo_iface_cb_deregister_appid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7651                                             const char *appid)
7652 {
7653    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7654    E_Appinfo *eai = NULL;
7655
7656    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7657    if (!tzlaunch_appinfo)
7658      {
7659         wl_resource_post_error(res_tzlaunch_appinfo,
7660                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7661                                "Invalid tzlaunch_appinfo's user data");
7662         return;
7663      }
7664
7665    eai = e_appinfo_find_with_appid(appid);
7666    EINA_SAFETY_ON_NULL_RETURN(eai);
7667
7668    e_appinfo_del(eai);
7669 }
7670
7671 static void
7672 _tzlaunch_appinfo_iface_cb_set_pid(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7673                                    const char *appid, uint32_t pid)
7674 {
7675    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7676    E_Appinfo *eai = NULL;
7677
7678    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7679    if (!tzlaunch_appinfo)
7680      {
7681         wl_resource_post_error(res_tzlaunch_appinfo,
7682                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7683                                "Invalid tzlaunch_appinfo's user data");
7684         return;
7685      }
7686
7687    eai = e_appinfo_find_with_appid(appid);
7688    EINA_SAFETY_ON_NULL_RETURN(eai);
7689
7690    if (!e_appinfo_pid_set(eai, pid))
7691      {
7692         ELOGF("TZ_APPINFO", "Failed to set pid:%u for appid:%s", NULL, pid, appid);
7693         return;
7694      }
7695 }
7696
7697 static void
7698 _tzlaunch_appinfo_iface_cb_ready_metadata(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7699                                           const char *appid, uint32_t pid)
7700 {
7701    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7702    E_Appinfo *eai = NULL;
7703    int width = 0, height = 0;
7704
7705    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7706    if (!tzlaunch_appinfo)
7707      {
7708         wl_resource_post_error(res_tzlaunch_appinfo,
7709                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7710                                "Invalid tzlaunch_appinfo's user data");
7711         return;
7712      }
7713
7714    eai = e_appinfo_find_with_appid(appid);
7715    EINA_SAFETY_ON_NULL_RETURN(eai);
7716
7717    e_appinfo_ready_metadata(eai, pid);
7718
7719    /* about base  output resolution */
7720    if (e_config->configured_output_resolution.use)
7721      {
7722         // 1. send HOOK with pid
7723         _e_policy_wl_hook_call(E_POLICY_WL_HOOK_BASE_OUTPUT_RESOLUTION_GET, pid);
7724         // 2. module must set the base_output_resolution.
7725         if (!e_appinfo_base_output_resolution_get(eai, &width, &height))
7726           {
7727              ELOGF("TZ_APPINFO", "failed to set base_output_resolution in module, pid:%u, appid:%s", NULL, pid, appid);
7728              return;
7729           }
7730         // 3. server has to get the base_screern_resolution via e_appinfo_base_output_resolution_get.
7731         //    3-1. if success, use the base_rescreen_resolution
7732         //    3-2. if fail, get the base_output_resolution from the E_Comp_Wl_Output.
7733
7734         // 4. send output.
7735         if (!e_comp_wl_pid_output_configured_resolution_send(pid, width, height))
7736           {
7737              ELOGF("TZ_APPINFO", "failed to send output_configured_resolution, pid:%u, appid:%s", NULL, pid, appid);
7738              return;
7739           }
7740      }
7741 }
7742
7743 static void
7744 _tzlaunch_appinfo_iface_cb_set_auto_placement(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo,
7745                                               uint32_t pid)
7746 {
7747    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7748    E_Appinfo *eai = NULL;
7749
7750    tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo);
7751    if (!tzlaunch_appinfo)
7752      {
7753         wl_resource_post_error(res_tzlaunch_appinfo,
7754                                WL_DISPLAY_ERROR_INVALID_OBJECT,
7755                                "Invalid tzlaunch_appinfo's user data");
7756         return;
7757      }
7758
7759    eai = e_appinfo_find_with_pid(pid);
7760    EINA_SAFETY_ON_NULL_RETURN(eai);
7761
7762    ELOGF("TZ_APPINFO", "Set auto placement. pid(%d)", NULL, pid);
7763    e_appinfo_auto_placement_set(eai, EINA_TRUE);
7764 }
7765
7766 static const struct tizen_launch_appinfo_interface _tzlaunch_appinfo_iface =
7767 {
7768    _tzlaunch_appinfo_iface_cb_destroy,
7769    _tzlaunch_appinfo_iface_cb_register_pid,
7770    _tzlaunch_appinfo_iface_cb_deregister_pid,
7771    _tzlaunch_appinfo_iface_cb_set_appid,
7772    _tzlaunch_appinfo_iface_cb_get_base_output_resolution,
7773    _tzlaunch_appinfo_iface_cb_register_appid,
7774    _tzlaunch_appinfo_iface_cb_deregister_appid,
7775    _tzlaunch_appinfo_iface_cb_set_pid,
7776    _tzlaunch_appinfo_iface_cb_ready_metadata,
7777    _tzlaunch_appinfo_iface_cb_set_auto_placement,
7778 };
7779
7780 static void
7781 _tzlaunch_appinfo_del(E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo)
7782 {
7783    EINA_SAFETY_ON_NULL_RETURN(tzlaunch_appinfo);
7784
7785    polwl->tzlaunch_appinfo = eina_list_remove(polwl->tzlaunch_appinfo, tzlaunch_appinfo);
7786
7787    memset(tzlaunch_appinfo, 0x0, sizeof(E_Policy_Wl_Tzlaunch_Appinfo));
7788    E_FREE(tzlaunch_appinfo);
7789 }
7790
7791 static E_Policy_Wl_Tzlaunch_Appinfo *
7792 _tzlaunch_appinfo_add(struct wl_resource *res_tzlaunch_appinfo)
7793 {
7794    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo;
7795
7796    tzlaunch_appinfo = E_NEW(E_Policy_Wl_Tzlaunch_Appinfo, 1);
7797    EINA_SAFETY_ON_NULL_RETURN_VAL(tzlaunch_appinfo, NULL);
7798
7799    tzlaunch_appinfo->res_tzlaunch_appinfo = res_tzlaunch_appinfo;
7800
7801    polwl->tzlaunch_appinfo = eina_list_append(polwl->tzlaunch_appinfo, tzlaunch_appinfo);
7802
7803    return tzlaunch_appinfo;
7804 }
7805
7806 static void
7807 _tzlaunch_appinfo_cb_unbind(struct wl_resource *res_tzlaunch_appinfo)
7808 {
7809    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7810    Eina_List *l, *ll;
7811
7812    EINA_LIST_FOREACH_SAFE(polwl->tzlaunch_appinfo, l, ll, tzlaunch_appinfo)
7813      {
7814         if (tzlaunch_appinfo->res_tzlaunch_appinfo != res_tzlaunch_appinfo) continue;
7815         _tzlaunch_appinfo_del(tzlaunch_appinfo);
7816         break;
7817      }
7818 }
7819
7820 static void
7821 _tzlaunch_appinfo_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
7822 {
7823    E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL;
7824    struct wl_resource *res_tzlaunch_appinfo;
7825
7826    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
7827
7828    res_tzlaunch_appinfo = wl_resource_create(client,
7829                                      &tizen_launch_appinfo_interface,
7830                                      ver,
7831                                      id);
7832    EINA_SAFETY_ON_NULL_GOTO(res_tzlaunch_appinfo, err);
7833
7834    tzlaunch_appinfo = _tzlaunch_appinfo_add(res_tzlaunch_appinfo);
7835    EINA_SAFETY_ON_NULL_GOTO(tzlaunch_appinfo, err);
7836
7837    wl_resource_set_implementation(res_tzlaunch_appinfo,
7838                                   &_tzlaunch_appinfo_iface,
7839                                   tzlaunch_appinfo,
7840                                   _tzlaunch_appinfo_cb_unbind);
7841
7842    return;
7843
7844 err:
7845    ERR("Could not create tizen_launch_appinfo_interface res: %m");
7846    wl_client_post_no_memory(client);
7847 }
7848
7849 static Eina_Bool
7850 _e_policy_wl_cb_hook_intercept_show_helper(void *data, E_Client *ec)
7851 {
7852    E_Policy_Wl_Tzpol *tzpol;
7853    E_Policy_Wl_Surface *psurf;
7854    Eina_Iterator *it;
7855    Eina_Bool ret = EINA_TRUE;
7856
7857    it = eina_hash_iterator_data_new(polwl->tzpols);
7858    EINA_ITERATOR_FOREACH(it, tzpol)
7859      {
7860         psurf = _e_policy_wl_tzpol_surf_find(tzpol, ec);
7861         if (psurf)
7862           {
7863              if (psurf->is_background)
7864                {
7865                   ELOGF("TZPOL",
7866                         "BACKGROUND State is On, Deny Show",
7867                         ec);
7868                   ret = EINA_FALSE;
7869                   break;
7870                }
7871           }
7872      }
7873    eina_iterator_free(it);
7874
7875    return ret;
7876 }
7877
7878 static Eina_Bool
7879 _e_policy_wl_cb_scrsaver_on(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
7880 {
7881    if (_scrsaver_mng_res)
7882      tws_service_screensaver_manager_send_idle(_scrsaver_mng_res);
7883    return ECORE_CALLBACK_PASS_ON;
7884 }
7885
7886 static Eina_Bool
7887 _e_policy_wl_cb_scrsaver_off(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
7888 {
7889    if (_scrsaver_mng_res)
7890      tws_service_screensaver_manager_send_active(_scrsaver_mng_res);
7891    return ECORE_CALLBACK_PASS_ON;
7892 }
7893
7894 // --------------------------------------------------------
7895 // E_Policy_Wl_Tz_Indicator
7896 // --------------------------------------------------------
7897 static E_Policy_Wl_Tz_Indicator *
7898 _e_policy_wl_tz_indicator_add(struct wl_resource *res_tz_indicator)
7899 {
7900    E_Policy_Wl_Tz_Indicator *tz_indicator;
7901
7902    tz_indicator = E_NEW(E_Policy_Wl_Tz_Indicator, 1);
7903    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_indicator, NULL);
7904
7905    tz_indicator->res_tz_indicator = res_tz_indicator;
7906
7907    polwl->tz_indicators = eina_list_append(polwl->tz_indicators, tz_indicator);
7908
7909    return tz_indicator;
7910 }
7911
7912 static void
7913 _e_policy_wl_tz_indicator_del(E_Policy_Wl_Tz_Indicator *tz_indicator)
7914 {
7915    EINA_SAFETY_ON_NULL_RETURN(tz_indicator);
7916
7917    polwl->tz_indicators = eina_list_remove(polwl->tz_indicators, tz_indicator);
7918    E_FREE(tz_indicator);
7919 }
7920
7921 static E_Policy_Wl_Tz_Indicator *
7922 _e_policy_wl_tz_indicator_get(struct wl_resource *res_tz_indicator)
7923 {
7924    Eina_List *l;
7925    E_Policy_Wl_Tz_Indicator *tz_indicator;
7926
7927    EINA_LIST_FOREACH(polwl->tz_indicators, l, tz_indicator)
7928      {
7929         if (tz_indicator->res_tz_indicator == res_tz_indicator)
7930           return tz_indicator;
7931      }
7932    return NULL;
7933 }
7934
7935 static E_Policy_Wl_Tz_Indicator *
7936 _e_policy_wl_tz_indicator_get_from_client(E_Client *ec)
7937 {
7938    Eina_List *l;
7939    E_Policy_Wl_Tz_Indicator *tz_indicator;
7940
7941    EINA_LIST_FOREACH(polwl->tz_indicators, l, tz_indicator)
7942      {
7943         if (eina_list_data_find(tz_indicator->ec_list, ec))
7944           return tz_indicator;
7945      }
7946
7947    return NULL;
7948 }
7949
7950 static Eina_Bool
7951 _e_policy_wl_tz_indicator_set_client(struct wl_resource *res_tz_indicator, E_Client *ec)
7952 {
7953    E_Policy_Wl_Tz_Indicator *tz_indicator = NULL;
7954
7955    tz_indicator = _e_policy_wl_tz_indicator_get(res_tz_indicator);
7956    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_indicator, EINA_FALSE);
7957
7958    if (!eina_list_data_find(tz_indicator->ec_list, ec))
7959      tz_indicator->ec_list = eina_list_append(tz_indicator->ec_list, ec);
7960
7961    return EINA_TRUE;
7962 }
7963
7964 static void
7965 _e_policy_wl_tz_indicator_unset_client(E_Client *ec)
7966 {
7967    Eina_List *l;
7968    E_Policy_Wl_Tz_Indicator *tz_indicator;
7969
7970    EINA_SAFETY_ON_NULL_RETURN(ec);
7971
7972    EINA_LIST_FOREACH(polwl->tz_indicators, l, tz_indicator)
7973      {
7974         if (eina_list_data_find(tz_indicator->ec_list, ec))
7975           tz_indicator->ec_list = eina_list_remove(tz_indicator->ec_list, ec);
7976      }
7977 }
7978
7979 static void
7980 _tz_indicator_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_indicator)
7981 {
7982    wl_resource_destroy(res_tz_indicator);
7983 }
7984
7985 static void
7986 _tz_indicator_cb_state_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_indicator, struct wl_resource *surf, int32_t state)
7987 {
7988    E_Client *ec;
7989    E_Indicator_State ind_state;
7990
7991    ec = e_client_from_surface_resource(surf);
7992    EINA_SAFETY_ON_NULL_RETURN(ec);
7993    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
7994
7995    if (state == TIZEN_INDICATOR_STATE_ON)
7996      ind_state = E_INDICATOR_STATE_ON;
7997    else if (state == TIZEN_INDICATOR_STATE_OFF)
7998      ind_state = E_INDICATOR_STATE_OFF;
7999    else
8000      ind_state = E_INDICATOR_STATE_UNKNOWN;
8001
8002    ELOGF("TZ_IND", "TZ_STATE:%d, E_STATE:%d", ec, state, ind_state);
8003    _e_policy_wl_tz_indicator_set_client(res_tz_indicator, ec);
8004    ec->indicator.state = ind_state;
8005
8006    e_policy_event_simple(ec, E_EVENT_POLICY_INDICATOR_STATE_CHANGE);
8007 }
8008
8009 static void
8010 _tz_indicator_cb_opacity_mode_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_indicator, struct wl_resource *surf, int32_t mode)
8011 {
8012    E_Client *ec;
8013    E_Indicator_Opacity_Mode op_mode;
8014
8015    ec = e_client_from_surface_resource(surf);
8016    EINA_SAFETY_ON_NULL_RETURN(ec);
8017    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
8018
8019    switch (mode)
8020      {
8021       case TIZEN_INDICATOR_OPACITY_MODE_OPAQUE:
8022         op_mode = E_INDICATOR_OPACITY_MODE_OPAQUE;
8023         break;
8024
8025       case TIZEN_INDICATOR_OPACITY_MODE_TRANSLUCENT:
8026         op_mode = E_INDICATOR_OPACITY_MODE_TRANSLUCENT;
8027         break;
8028
8029       case TIZEN_INDICATOR_OPACITY_MODE_TRANSPARENT:
8030         op_mode = E_INDICATOR_OPACITY_MODE_TRANSPARENT;
8031         break;
8032
8033       case TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT:
8034         op_mode = E_INDICATOR_OPACITY_MODE_BG_TRANSPARENT;
8035         break;
8036
8037       default:
8038         op_mode = E_INDICATOR_OPACITY_MODE_OPAQUE;
8039         break;
8040      }
8041
8042    ELOGF("TZ_IND", "TZ_OP_MODE:%d, E_OP_MODE:%d", ec, mode, op_mode);
8043    _e_policy_wl_tz_indicator_set_client(res_tz_indicator, ec);
8044
8045    if (ec->indicator.opacity_mode == op_mode) return;
8046
8047    ec->indicator.opacity_mode = op_mode;
8048    e_tzsh_indicator_srv_property_change_send(ec, ec->e.state.rot.ang.curr);
8049
8050    e_policy_event_simple(ec, E_EVENT_POLICY_INDICATOR_OPACITY_MODE_CHANGE);
8051 }
8052
8053 static void
8054 _tz_indicator_cb_visible_type_set(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_indicator, struct wl_resource *surf, int32_t vtype)
8055 {
8056    E_Client *ec;
8057    E_Indicator_Visible_Type vis_type;
8058
8059    ec = e_client_from_surface_resource(surf);
8060    EINA_SAFETY_ON_NULL_RETURN(ec);
8061    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
8062
8063    if (vtype == TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN)
8064      vis_type = E_INDICATOR_VISIBLE_TYPE_SHOWN;
8065    else
8066      vis_type = E_INDICATOR_VISIBLE_TYPE_HIDDEN;
8067
8068    ELOGF("TZ_IND", "TZ_VIS_TYPE:%d, E_VIS_TYPE:%d", ec, vtype, vis_type);
8069    _e_policy_wl_tz_indicator_set_client(res_tz_indicator, ec);
8070    ec->indicator.visible_type = vis_type;
8071
8072    e_policy_event_simple(ec, E_EVENT_POLICY_INDICATOR_VISIBLE_STATE_CHANGE);
8073 }
8074
8075 // --------------------------------------------------------
8076 // tizen_indicator_interface
8077 // --------------------------------------------------------
8078 static const struct tizen_indicator_interface _tz_indicator_iface =
8079 {
8080    _tz_indicator_cb_destroy,
8081    _tz_indicator_cb_state_set,
8082    _tz_indicator_cb_opacity_mode_set,
8083    _tz_indicator_cb_visible_type_set,
8084 };
8085
8086 static void
8087 _tz_indicator_cb_unbind(struct wl_resource *res_tz_indicator)
8088 {
8089    E_Policy_Wl_Tz_Indicator *tz_indicator;
8090
8091    tz_indicator = _e_policy_wl_tz_indicator_get(res_tz_indicator);
8092    EINA_SAFETY_ON_NULL_RETURN(tz_indicator);
8093
8094    _e_policy_wl_tz_indicator_del(tz_indicator);
8095 }
8096
8097 static void
8098 _tz_indicator_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
8099 {
8100    E_Policy_Wl_Tz_Indicator *tz_indicator_pol;
8101    struct wl_resource *res_tz_indicator;
8102
8103    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
8104
8105    res_tz_indicator = wl_resource_create(client,
8106                                          &tizen_indicator_interface,
8107                                          ver,
8108                                          id);
8109    EINA_SAFETY_ON_NULL_GOTO(res_tz_indicator, err);
8110
8111    tz_indicator_pol = _e_policy_wl_tz_indicator_add(res_tz_indicator);
8112    EINA_SAFETY_ON_NULL_GOTO(tz_indicator_pol, err);
8113
8114    wl_resource_set_implementation(res_tz_indicator,
8115                                   &_tz_indicator_iface,
8116                                   NULL,
8117                                   _tz_indicator_cb_unbind);
8118    return;
8119
8120 err:
8121    ERR("Could not create tizen_indicator_interface res: %m");
8122    wl_client_post_no_memory(client);
8123 }
8124
8125 EINTERN void
8126 e_policy_wl_indicator_flick_send(E_Client *ec)
8127 {
8128    E_Comp_Wl_Client_Data *cdata;
8129    E_Policy_Wl_Tz_Indicator *tz_indicator;
8130    struct wl_resource *surf;
8131
8132    tz_indicator = _e_policy_wl_tz_indicator_get_from_client(ec);
8133    EINA_SAFETY_ON_NULL_RETURN(tz_indicator);
8134
8135    cdata = e_client_cdata_get(ec);
8136    if (cdata)
8137      surf = cdata->surface;
8138    else
8139      surf = NULL;
8140
8141    ELOGF("TZ_IND", "SEND FLICK EVENT", ec);
8142    tizen_indicator_send_flick(tz_indicator->res_tz_indicator, surf, 0);
8143 }
8144
8145
8146 // --------------------------------------------------------
8147 // E_Policy_Wl_Tz_Clipboard
8148 // --------------------------------------------------------
8149 static E_Policy_Wl_Tz_Clipboard *
8150 _e_policy_wl_tz_clipboard_add(struct wl_resource *res_tz_clipboard)
8151 {
8152    E_Policy_Wl_Tz_Clipboard *tz_clipboard;
8153
8154    tz_clipboard = E_NEW(E_Policy_Wl_Tz_Clipboard, 1);
8155    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_clipboard, NULL);
8156
8157    tz_clipboard->res_tz_clipboard = res_tz_clipboard;
8158    polwl->tz_clipboards = eina_list_append(polwl->tz_clipboards, tz_clipboard);
8159
8160    return tz_clipboard;
8161 }
8162
8163 static void
8164 _e_policy_wl_tz_clipboard_del(E_Policy_Wl_Tz_Clipboard *tz_clipboard)
8165 {
8166    EINA_SAFETY_ON_NULL_RETURN(tz_clipboard);
8167
8168    polwl->tz_clipboards = eina_list_remove(polwl->tz_clipboards, tz_clipboard);
8169    E_FREE(tz_clipboard);
8170 }
8171
8172 static E_Policy_Wl_Tz_Clipboard *
8173 _e_policy_wl_tz_clipboard_get_from_client(E_Client *ec)
8174 {
8175    Eina_List *l;
8176    E_Policy_Wl_Tz_Clipboard *tz_clipboard;
8177
8178    EINA_LIST_FOREACH(polwl->tz_clipboards, l, tz_clipboard)
8179      {
8180         if (eina_list_data_find(tz_clipboard->ec_list, ec))
8181           return tz_clipboard;
8182      }
8183
8184    return NULL;
8185 }
8186
8187 static Eina_Bool
8188 _e_policy_wl_tz_clipboard_set_client(struct wl_resource *res_tz_clipboard, E_Client *ec)
8189 {
8190    E_Policy_Wl_Tz_Clipboard *tz_clipboard = NULL;
8191
8192    tz_clipboard = wl_resource_get_user_data(res_tz_clipboard);
8193    EINA_SAFETY_ON_NULL_RETURN_VAL(tz_clipboard, EINA_FALSE);
8194
8195    if (!eina_list_data_find(tz_clipboard->ec_list, ec))
8196      {
8197         tz_clipboard->ec_list = eina_list_append(tz_clipboard->ec_list, ec);
8198      }
8199    return EINA_TRUE;
8200 }
8201
8202 static void
8203 _e_policy_wl_tz_clipboard_unset_client(E_Client *ec)
8204 {
8205    Eina_List *l;
8206    E_Policy_Wl_Tz_Clipboard *tz_clipboard = NULL;
8207
8208    EINA_SAFETY_ON_NULL_RETURN(ec);
8209
8210    EINA_LIST_FOREACH(polwl->tz_clipboards, l, tz_clipboard)
8211      {
8212         if (eina_list_data_find(tz_clipboard->ec_list, ec))
8213           {
8214              tz_clipboard->ec_list = eina_list_remove(tz_clipboard->ec_list, ec);
8215           }
8216      }
8217 }
8218
8219 // --------------------------------------------------------
8220 // tizen_clipboard_interface
8221 // --------------------------------------------------------
8222 static void
8223 _tz_clipboard_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_clipboard)
8224 {
8225    wl_resource_destroy(res_tz_clipboard);
8226 }
8227
8228 static void
8229 _tz_clipboard_cb_show(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_clipboard, struct wl_resource *surf)
8230 {
8231    E_Client *ec;
8232
8233    ec = e_client_from_surface_resource(surf);
8234    EINA_SAFETY_ON_NULL_RETURN(ec);
8235    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
8236
8237    _e_policy_wl_tz_clipboard_set_client(res_tz_clipboard, ec);
8238    e_service_cbhm_parent_set(ec, EINA_TRUE);
8239    e_service_cbhm_show();
8240 }
8241
8242 static void
8243 _tz_clipboard_cb_hide(struct wl_client *client EINA_UNUSED, struct wl_resource *res_tz_clipboard, struct wl_resource *surf)
8244 {
8245    E_Client *ec;
8246
8247    ec = e_client_from_surface_resource(surf);
8248    EINA_SAFETY_ON_NULL_RETURN(ec);
8249    EINA_SAFETY_ON_NULL_RETURN(ec->frame);
8250
8251    e_service_cbhm_parent_set(ec, EINA_FALSE);
8252    e_service_cbhm_hide();
8253 }
8254
8255 static void
8256 _tz_clipboard_cb_data_only_set(struct wl_client *client, struct wl_resource *res_tz_clipboard, uint32_t set)
8257 {
8258    E_Policy_Wl_Tz_Clipboard *tz_clipboard = NULL;
8259    struct wl_client *_wc;
8260    struct wl_resource *data_res;
8261    pid_t pid = 0;
8262    uid_t uid = 0;
8263    Eina_Bool res;
8264    Eina_List *clients;
8265    E_Client *ec, *found = NULL;
8266    E_Comp_Wl_Client_Data *cdata;
8267
8268    tz_clipboard = wl_resource_get_user_data(res_tz_clipboard);
8269    EINA_SAFETY_ON_NULL_RETURN(tz_clipboard);
8270
8271    if (tz_clipboard->ec_list)
8272      {
8273         ELOGF("TZPOL",
8274               "Unable to set data only mode for wl_client(%p) : "
8275               "ec_list exists",
8276               NULL, client);
8277         goto send_deny;
8278      }
8279
8280    if (!(data_res = e_comp_wl_data_find_for_client(client)))
8281      {
8282         ELOGF("TZPOL",
8283               "Unable to set data only mode for wl_client(%p) : "
8284               "no wl_data_device resource",
8285               NULL, client);
8286         goto send_deny;
8287      }
8288
8289    clients = _e_policy_wl_e_clients_find_by_pid(pid);
8290    if (clients)
8291      {
8292         EINA_LIST_FREE(clients, ec)
8293           {
8294              if (found) continue;
8295              cdata = e_client_cdata_get(ec);
8296              if (cdata && cdata->surface)
8297                {
8298                   _wc = wl_resource_get_client(cdata->surface);
8299                   if (_wc == client)
8300                     found = ec;
8301                }
8302           }
8303      }
8304
8305    if (found)
8306      {
8307         ELOGF("TZPOL",
8308               "Unable to set data only mode for wl_client(%p) : "
8309               "have ec(%p)",
8310               NULL, client, ec);
8311         goto send_deny;
8312      }
8313
8314    /* Privilege Check */
8315    wl_client_get_credentials(client, &pid, &uid, NULL);
8316    res = e_security_privilege_check(pid, uid,
8317                                     E_PRIVILEGE_DATA_ONLY_SET);
8318    if (!res)
8319      {
8320         ELOGF("TZPOL",
8321               "Privilege Check Failed! DENY data_only_set",
8322               NULL);
8323         goto send_deny;
8324      }
8325
8326    ELOGF("TZPOL",
8327          "Set data only mode :%d for wl_client(%p)",
8328          NULL, set, client);
8329    e_comp_wl_data_device_only_set(data_res, !(set == 0));
8330    tizen_clipboard_send_allowed_data_only(res_tz_clipboard, (uint32_t)1);
8331    return;
8332
8333 send_deny:
8334    tizen_clipboard_send_allowed_data_only(res_tz_clipboard, (uint32_t)0);
8335 }
8336
8337 static const struct tizen_clipboard_interface _tz_clipboard_iface =
8338 {
8339    _tz_clipboard_cb_destroy,
8340    _tz_clipboard_cb_show,
8341    _tz_clipboard_cb_hide,
8342    _tz_clipboard_cb_data_only_set,
8343 };
8344
8345 static void
8346 _tz_clipboard_cb_unbind(struct wl_resource *res_tz_clipboard)
8347 {
8348    E_Policy_Wl_Tz_Clipboard *tz_clipboard;
8349
8350    tz_clipboard = wl_resource_get_user_data(res_tz_clipboard);
8351    EINA_SAFETY_ON_NULL_RETURN(tz_clipboard);
8352
8353    _e_policy_wl_tz_clipboard_del(tz_clipboard);
8354 }
8355
8356 static void
8357 _tz_clipboard_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
8358 {
8359    E_Policy_Wl_Tz_Clipboard *tz_clipboard_pol;
8360    struct wl_resource *res_tz_clipboard;
8361
8362    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
8363
8364    res_tz_clipboard = wl_resource_create(client,
8365                                          &tizen_clipboard_interface,
8366                                          ver,
8367                                          id);
8368    EINA_SAFETY_ON_NULL_GOTO(res_tz_clipboard, err);
8369
8370    tz_clipboard_pol = _e_policy_wl_tz_clipboard_add(res_tz_clipboard);
8371    EINA_SAFETY_ON_NULL_GOTO(tz_clipboard_pol, err);
8372
8373    wl_resource_set_implementation(res_tz_clipboard,
8374                                   &_tz_clipboard_iface,
8375                                   tz_clipboard_pol,
8376                                   _tz_clipboard_cb_unbind);
8377    return;
8378
8379 err:
8380    ERR("Could not create tizen_clipboard_interface res: %m");
8381    wl_client_post_no_memory(client);
8382 }
8383
8384 EINTERN void
8385 e_policy_wl_clipboard_data_selected_send(E_Client *ec)
8386 {
8387    E_Comp_Wl_Client_Data *cdata;
8388    E_Policy_Wl_Tz_Clipboard *tz_clipboard;
8389
8390    EINA_SAFETY_ON_NULL_RETURN(ec);
8391
8392    tz_clipboard = _e_policy_wl_tz_clipboard_get_from_client(ec);
8393    EINA_SAFETY_ON_NULL_RETURN(tz_clipboard);
8394
8395    cdata = e_client_cdata_get(ec);
8396    tizen_clipboard_send_data_selected(tz_clipboard->res_tz_clipboard,
8397                                       cdata ? cdata->surface : NULL);
8398 }
8399
8400 static void
8401 _e_policy_wl_cb_hook_shell_surface_ready(void *d, E_Client *ec)
8402 {
8403    E_Comp_Wl_Client_Data *cdata;
8404
8405    if (EINA_UNLIKELY(!ec))
8406      return;
8407
8408    e_policy_client_maximize(ec);
8409
8410    e_client_base_output_resolution_transform_adjust(ec);
8411
8412    cdata = e_client_cdata_get(ec);
8413    if ((cdata->shell.configure_send) &&
8414        (cdata->shell.surface))
8415      {
8416         int w = 0, h = 0;
8417         if (ec->lock_client_size)
8418           {
8419              w = ec->w;
8420              h = ec->h;
8421           }
8422         cdata->shell.configure_send(cdata->shell.surface, 0, w, h);
8423      }
8424 }
8425
8426 static void
8427 _e_policy_wl_cb_hook_alpha_change(void *data, E_Client *ec)
8428 {
8429    if (!ec) return;
8430    if (!ec->argb) return;
8431    if (!ec->transients) return;
8432    if (!e_policy_visibility_client_is_uniconify_render_running(ec)) return;
8433
8434    E_Client *child;
8435    Eina_List *list = eina_list_clone(ec->transients);
8436
8437    EINA_LIST_FREE(list, child)
8438      {
8439         if (e_client_transient_policy_get(child) == E_TRANSIENT_BELOW)
8440           {
8441              ELOGF("POL_VIS", "Uniconify below child(win:%zx, ec:%p) by changing alpha", ec, e_client_util_win_get(child), child);
8442              e_policy_client_uniconify_by_visibility(child);
8443           }
8444      }
8445 }
8446
8447 static void
8448 _e_policy_wl_client_cb_resize_end(void *data EINA_UNUSED, E_Client *ec)
8449 {
8450    int x, y, w, h;
8451
8452    if (e_object_is_del(E_OBJECT(ec))) return;
8453    if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
8454
8455    if (ec->manage_resize.resize_obj)
8456      {
8457         x = ec->manage_resize.x;
8458         y = ec->manage_resize.y;
8459         w = ec->manage_resize.w;
8460         h = ec->manage_resize.h;
8461      }
8462    else
8463      {
8464         x = ec->x;
8465         y = ec->y;
8466         w = ec->w;
8467         h = ec->h;
8468         e_client_geometry_get(ec, &x, &y, &w, &h);
8469      }
8470
8471    E_Policy_Wl_Tzpol *tzpol;
8472    E_Policy_Wl_Surface *psurf;
8473    Eina_List *l;
8474    Eina_Iterator *it;
8475    int ver = -1;
8476
8477    it = eina_hash_iterator_data_new(polwl->tzpols);
8478    EINA_ITERATOR_FOREACH(it, tzpol)
8479      {
8480         EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
8481           {
8482              if (e_pixmap_client_get(psurf->cp) != ec) continue;
8483              if (!psurf->surf) continue;
8484
8485              ver = wl_resource_get_version(tzpol->res_tzpol);
8486              if (ver < 10)
8487                {
8488                   // interactive_resize_done event is supported since ver 10
8489                   continue;
8490                }
8491
8492              tizen_policy_send_interactive_resize_done(tzpol->res_tzpol,
8493                                                        psurf->surf, x, y, w, h,
8494                                                        ec->e.state.rot.ang.curr);
8495           }
8496      }
8497    eina_iterator_free(it);
8498 }
8499
8500 static void
8501 _e_policy_wl_client_cb_move_end(void *data EINA_UNUSED, E_Client *ec)
8502 {
8503    if (e_object_is_del(E_OBJECT(ec))) return;
8504    if (e_pixmap_type_get(ec->pixmap) != E_PIXMAP_TYPE_WL) return;
8505
8506    int x, y, w, h;
8507    x = ec->x;
8508    y = ec->y;
8509    w = ec->w;
8510    h = ec->h;
8511    e_client_geometry_get(ec, &x, &y, &w, &h);
8512
8513    E_Policy_Wl_Tzpol *tzpol;
8514    E_Policy_Wl_Surface *psurf;
8515    Eina_List *l;
8516    Eina_Iterator *it;
8517    int ver = -1;
8518
8519    it = eina_hash_iterator_data_new(polwl->tzpols);
8520    EINA_ITERATOR_FOREACH(it, tzpol)
8521      {
8522         EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
8523           {
8524              if (e_pixmap_client_get(psurf->cp) != ec) continue;
8525              if (!psurf->surf) continue;
8526
8527              ver = wl_resource_get_version(tzpol->res_tzpol);
8528              if (ver < 10)
8529                {
8530                   // interactive_move_done event is supported since ver 10
8531                   continue;
8532                }
8533
8534              tizen_policy_send_interactive_move_done(tzpol->res_tzpol,
8535                                                      psurf->surf,
8536                                                      x, y, w, h,
8537                                                      ec->e.state.rot.ang.curr);
8538           }
8539      }
8540    eina_iterator_free(it);
8541 }
8542
8543 void
8544 e_policy_wl_generate_request(E_Client *ec, E_Policy_Wl_Gen_Request type)
8545 {
8546    E_Comp_Wl_Client_Data *cdata = NULL;
8547    if (!ec) return;
8548
8549    cdata = e_client_cdata_get(ec);
8550    if (!cdata) return;
8551    if (!cdata->wl_surface) return;
8552
8553    ELOGF("POL", "Generate operation (type:%d)", ec, type);
8554    switch (type)
8555      {
8556       case E_POLICY_WL_GENERATE_REQUEST_LOWER:
8557          _tzpol_iface_cb_lower(NULL, NULL, cdata->wl_surface);
8558          break;
8559       case E_POLICY_WL_GENERATE_REQUEST_ACTIVATE:
8560          _tzpol_iface_cb_activate(NULL, NULL, cdata->wl_surface);
8561          break;
8562       case E_POLICY_WL_GENERATE_REQUEST_ICONIFY:
8563          _tzpol_iface_cb_iconify(NULL, NULL, cdata->wl_surface);
8564          break;
8565       case E_POLICY_WL_GENERATE_REQUEST_UNICONIFY:
8566          _tzpol_iface_cb_uniconify(NULL, NULL, cdata->wl_surface);
8567          break;
8568       default:
8569          break;
8570      }
8571 }
8572
8573 EINTERN void
8574 e_policy_wl_aux_hint_apply(E_Client *ec)
8575 {
8576    _e_policy_wl_aux_hint_apply(ec);
8577 }
8578
8579 // --------------------------------------------------------
8580 // public functions
8581 // --------------------------------------------------------
8582 EINTERN void
8583 e_policy_wl_client_add(E_Client *ec)
8584 {
8585    EINA_SAFETY_ON_NULL_RETURN(ec);
8586    if (!ec->pixmap) return;
8587
8588    _e_policy_wl_surf_client_set(ec);
8589    _e_policy_wl_tzlaunch_effect_type_sync(ec);
8590 }
8591
8592 EINTERN void
8593 e_policy_wl_client_del(E_Client *ec)
8594 {
8595    EINA_SAFETY_ON_NULL_RETURN(ec);
8596    if (!ec->pixmap) return;
8597
8598    e_policy_wl_pixmap_del(ec->pixmap);
8599    _e_policy_wl_dpy_surf_del(ec);
8600    _e_policy_wl_tz_indicator_unset_client(ec);
8601    _e_policy_wl_tz_clipboard_unset_client(ec);
8602    _launch_effect_client_del(ec);
8603
8604    polwl->pending_vis = eina_list_remove(polwl->pending_vis, ec);
8605 }
8606
8607 EINTERN void
8608 e_policy_wl_pixmap_del(E_Pixmap *cp)
8609 {
8610    E_Policy_Wl_Tzpol *tzpol;
8611    E_Policy_Wl_Surface *psurf;
8612    Eina_List *l, *ll;
8613    Eina_Iterator *it;
8614
8615    it = eina_hash_iterator_data_new(polwl->tzpols);
8616    EINA_ITERATOR_FOREACH(it, tzpol)
8617      EINA_LIST_FOREACH_SAFE(tzpol->psurfs, l, ll, psurf)
8618        {
8619           if (psurf->cp != cp) continue;
8620           tzpol->psurfs = eina_list_remove_list(tzpol->psurfs, l);
8621           _e_policy_wl_surf_del(psurf);
8622        }
8623    eina_iterator_free(it);
8624 }
8625
8626 EINTERN void
8627 e_policy_wl_aux_message_send(E_Client *ec,
8628                              const char *key,
8629                              const char *val,
8630                              Eina_List *options)
8631 {
8632    E_Comp_Wl_Client_Data *cdata;
8633    E_Policy_Wl_Tzpol *tzpol;
8634    E_Policy_Wl_Surface *psurf;
8635    Eina_List *l;
8636    Eina_Iterator *it;
8637    struct wl_array opt_array;
8638    const char *option;
8639    int len;
8640    char *p;
8641
8642    if (e_object_is_del(E_OBJECT(ec))) return;
8643    cdata = e_client_cdata_get(ec);
8644    if (!cdata) return;
8645    if (!cdata->aux_hint.use_msg) return;
8646
8647    wl_array_init(&opt_array);
8648    EINA_LIST_FOREACH(options, l, option)
8649      {
8650         len = strlen(option) + 1;
8651         p = wl_array_add(&opt_array, len);
8652
8653         if (p == NULL)
8654           break;
8655         strncpy(p, option, len);
8656      }
8657
8658    it = eina_hash_iterator_data_new(polwl->tzpols);
8659    EINA_ITERATOR_FOREACH(it, tzpol)
8660       EINA_LIST_FOREACH(tzpol->psurfs, l, psurf)
8661         {
8662            if (e_pixmap_client_get(psurf->cp) != ec) continue;
8663            if (!psurf->surf) continue;
8664
8665            tizen_policy_send_aux_message(tzpol->res_tzpol,
8666                                          psurf->surf,
8667                                          key, val, &opt_array);
8668           ELOGF("TZPOL",
8669                 "SEND     |res_tzpol:%8p|aux message key:%s val:%s opt_count:%d",
8670                 ec,
8671                 tzpol->res_tzpol,
8672                 key, val, eina_list_count(options));
8673         }
8674    eina_iterator_free(it);
8675    wl_array_release(&opt_array);
8676 }
8677
8678 EINTERN void
8679 e_policy_wl_aux_hint_init(void)
8680 {
8681    int i, n;
8682    E_Config_Aux_Hint_Supported *auxhint;
8683    Eina_List *l;
8684
8685    n = (sizeof(hint_names) / sizeof(char *));
8686
8687    for (i = 0; i < n; i++)
8688      {
8689         e_hints_aux_hint_supported_add(hint_names[i]);
8690      }
8691
8692    EINA_LIST_FOREACH(e_config->aux_hint_supported, l, auxhint)
8693      {
8694         if (!auxhint->name) continue;
8695         e_hints_aux_hint_supported_add(auxhint->name);
8696      }
8697
8698    return;
8699 }
8700
8701 EINTERN Eina_Bool
8702 e_policy_wl_defer_job(void)
8703 {
8704    struct wl_global *global = NULL;
8705    EINA_SAFETY_ON_NULL_GOTO(polwl, err);
8706
8707    if (!e_config->global_object_not_provide.launch_effect)
8708      {
8709         global = wl_global_create(e_comp_wl->wl.disp,
8710                                   &tizen_launch_effect_interface,
8711                                   1,
8712                                   NULL,
8713                                   _tzlaunch_effect_cb_bind);
8714         EINA_SAFETY_ON_NULL_GOTO(global, err);
8715
8716         polwl->globals = eina_list_append(polwl->globals, global);
8717      }
8718
8719    global = wl_global_create(e_comp_wl->wl.disp,
8720                              &tizen_launch_appinfo_interface,
8721                              2,
8722                              NULL,
8723                              _tzlaunch_appinfo_cb_bind);
8724    EINA_SAFETY_ON_NULL_GOTO(global, err);
8725
8726    polwl->globals = eina_list_append(polwl->globals, global);
8727
8728    return EINA_TRUE;
8729
8730 err:
8731    return EINA_FALSE;
8732 }
8733
8734 EINTERN Eina_Bool
8735 e_policy_wl_init(void)
8736 {
8737    struct wl_global *global;
8738
8739    EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
8740    EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl->wl.disp, EINA_FALSE);
8741
8742    polwl = E_NEW(E_Policy_Wl, 1);
8743    EINA_SAFETY_ON_NULL_RETURN_VAL(polwl, EINA_FALSE);
8744
8745    /* create globals */
8746    global = wl_global_create(e_comp_wl->wl.disp,
8747                              &tizen_policy_interface,
8748                              12,
8749                              NULL,
8750                              _tzpol_cb_bind);
8751    EINA_SAFETY_ON_NULL_GOTO(global, err);
8752    polwl->globals = eina_list_append(polwl->globals, global);
8753
8754    global = wl_global_create(e_comp_wl->wl.disp,
8755                              &tizen_display_policy_interface,
8756                              1,
8757                              NULL,
8758                              _tz_dpy_pol_cb_bind);
8759    EINA_SAFETY_ON_NULL_GOTO(global, err);
8760    polwl->globals = eina_list_append(polwl->globals, global);
8761
8762    global = wl_global_create(e_comp_wl->wl.disp,
8763                              &tizen_ws_shell_interface,
8764                              4,
8765                              NULL,
8766                              _tzsh_cb_bind);
8767
8768    EINA_SAFETY_ON_NULL_GOTO(global, err);
8769    polwl->globals = eina_list_append(polwl->globals, global);
8770
8771    global = wl_global_create(e_comp_wl->wl.disp,
8772                              &tizen_indicator_interface,
8773                              1,
8774                              NULL,
8775                              _tz_indicator_cb_bind);
8776    EINA_SAFETY_ON_NULL_GOTO(global, err);
8777    polwl->globals = eina_list_append(polwl->globals, global);
8778
8779    global = wl_global_create(e_comp_wl->wl.disp,
8780                              &tizen_clipboard_interface,
8781                              2,
8782                              NULL,
8783                              _tz_clipboard_cb_bind);
8784    EINA_SAFETY_ON_NULL_GOTO(global, err);
8785    polwl->globals = eina_list_append(polwl->globals, global);
8786
8787    polwl->tzpols = eina_hash_pointer_new(_e_policy_wl_tzpol_del);
8788
8789    E_COMP_OBJECT_INTERCEPT_HOOK_APPEND(hooks_co, E_COMP_OBJECT_INTERCEPT_HOOK_SHOW_HELPER, _e_policy_wl_cb_hook_intercept_show_helper, NULL);
8790
8791    E_LIST_HANDLER_APPEND(handlers, E_EVENT_SCREENSAVER_ON,  _e_policy_wl_cb_scrsaver_on,  NULL);
8792    E_LIST_HANDLER_APPEND(handlers, E_EVENT_SCREENSAVER_OFF, _e_policy_wl_cb_scrsaver_off, NULL);
8793
8794    E_COMP_WL_HOOK_APPEND(hooks_cw, E_COMP_WL_HOOK_SHELL_SURFACE_READY, _e_policy_wl_cb_hook_shell_surface_ready, NULL);
8795    E_COMP_WL_HOOK_APPEND(hooks_cw, E_COMP_WL_HOOK_CLIENT_ALPHA_CHANGE, _e_policy_wl_cb_hook_alpha_change, NULL);
8796
8797    E_LIST_HOOK_APPEND(polwl_hooks_ec, E_CLIENT_HOOK_RESIZE_END, _e_policy_wl_client_cb_resize_end, NULL);
8798    E_LIST_HOOK_APPEND(polwl_hooks_ec, E_CLIENT_HOOK_MOVE_END, _e_policy_wl_client_cb_move_end, NULL);
8799
8800    E_EVENT_POLICY_INDICATOR_STATE_CHANGE = ecore_event_type_new();
8801    E_EVENT_POLICY_INDICATOR_OPACITY_MODE_CHANGE = ecore_event_type_new();
8802    E_EVENT_POLICY_INDICATOR_VISIBLE_STATE_CHANGE = ecore_event_type_new();
8803
8804    e_service_softkey_client_remove_handler_add();
8805
8806    e_policy_display_init();
8807
8808    return EINA_TRUE;
8809
8810 err:
8811    if (polwl)
8812      {
8813         EINA_LIST_FREE(polwl->globals, global)
8814           wl_global_destroy(global);
8815
8816         E_FREE(polwl);
8817      }
8818    return EINA_FALSE;
8819 }
8820
8821 EINTERN void
8822 e_policy_wl_shutdown(void)
8823 {
8824    E_Policy_Wl_Tzsh *tzsh;
8825    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
8826    E_Policy_Wl_Tzsh_Extension *tzsh_extension;
8827    E_Policy_Wl_Tzlaunch_Effect_Info *effect_info;
8828    E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
8829    E_Policy_Wl_Tz_Indicator *tz_indicator;
8830    struct wl_global *global;
8831    int i;
8832
8833    e_policy_display_shutdown();
8834
8835    EINA_SAFETY_ON_NULL_RETURN(polwl);
8836
8837    E_FREE_LIST(polwl_hooks_ec, e_client_hook_del);
8838    E_FREE_LIST(hooks_cw, e_comp_wl_hook_del);
8839    E_FREE_LIST(hooks_co, e_comp_object_intercept_hook_del);
8840    E_FREE_LIST(handlers, ecore_event_handler_del);
8841
8842    e_service_softkey_client_remove_handler_del();
8843
8844    polwl->pending_vis = eina_list_free(polwl->pending_vis);
8845
8846    for (i = 0; i < TZSH_SRV_ROLE_MAX; i++)
8847      {
8848         tzsh_srv = polwl->srvs[i];
8849         if (!tzsh_srv) continue;
8850
8851         wl_resource_destroy(tzsh_srv->res_tzsh_srv);
8852      }
8853
8854    EINA_LIST_FREE(polwl->tzshs, tzsh)
8855      wl_resource_destroy(tzsh->res_tzsh);
8856
8857    EINA_LIST_FREE(polwl->tz_dpy_pols, tz_dpy_pol)
8858      {
8859         E_Policy_Wl_Dpy_Surface *dpy_surf;
8860         EINA_LIST_FREE(tz_dpy_pol->dpy_surfs, dpy_surf)
8861           {
8862              E_FREE(dpy_surf);
8863           }
8864         wl_resource_destroy(tz_dpy_pol->res_tz_dpy_pol);
8865      }
8866
8867    EINA_LIST_FREE(polwl->tzlaunch_effect_info, effect_info)
8868      {
8869         E_FREE(effect_info);
8870      }
8871
8872    EINA_LIST_FREE(polwl->tz_indicators, tz_indicator)
8873      {
8874         eina_list_free(tz_indicator->ec_list);
8875         wl_resource_destroy(tz_indicator->res_tz_indicator);
8876      }
8877
8878    EINA_LIST_FREE(polwl->tzsh_extensions, tzsh_extension)
8879      {
8880         free(tzsh_extension->name);
8881      }
8882
8883    EINA_LIST_FREE(polwl->globals, global)
8884      wl_global_destroy(global);
8885
8886    E_FREE_FUNC(polwl->tzpols, eina_hash_free);
8887
8888    E_FREE(polwl);
8889 }