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