Addition of the window animation interface.
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_window_mgr.c
1 /*
2  * Copyright © 2010-2011 Intel Corporation
3  * Copyright © 2008-2011 Kristian Høgsberg
4  * Copyright © 2013 TOYOTA MOTOR CORPORATION.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and
7  * its documentation for any purpose is hereby granted without fee, provided
8  * that the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the copyright holders not be used in
11  * advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission.  The copyright holders make
13  * no representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  */
24 /**
25  * @brief   Multi Window Manager (Weston(Wayland) PlugIn)
26  *
27  * @date    Feb-08-2013
28  */
29
30 #define _GNU_SOURCE
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdbool.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <linux/input.h>
38 #include <assert.h>
39 #include <signal.h>
40 #include <math.h>
41 #include <time.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45 #include <wayland-server.h>
46 #include <aul/aul.h>
47 #include <bundle.h>
48
49 #include <weston/compositor.h>
50 #include "ico_ivi_common.h"
51 #include "ico_ivi_shell.h"
52 #include "ico_window_mgr.h"
53 #include "ico_ivi_shell-server-protocol.h"
54 #include "ico_window_mgr-server-protocol.h"
55
56 /* SurfaceID                        */
57 #define INIT_SURFACE_IDS    1024            /* SurfaceId table initiale size        */
58 #define ADD_SURFACE_IDS     512             /* SurfaceId table additional size      */
59 #define SURCAFE_ID_MASK     0x0ffff         /* SurfaceId bit mask pattern           */
60 #define UIFW_HASH    64                     /* Hash value (2's compliment)          */
61
62 /* Client attribute table           */
63 #define MAX_CLIENT_ATTR     4
64 struct uifw_client_attr {
65     char    appid[ICO_IVI_APPID_LENGTH];    /* ApplicationId                        */
66     struct _uifw_client_attr_value {
67         short   attr;
68         short   res;
69         int     value;
70     }       attrs[MAX_CLIENT_ATTR];
71     struct wl_list  link;
72 };
73
74 /* Manager table                    */
75 struct uifw_manager {
76     struct wl_resource *resource;           /* Manager resource                     */
77     int     eventcb;                        /* Event send flag                      */
78     struct wl_list link;                    /* link to next manager                 */
79 };
80
81 /* Multi Windiw Manager                           */
82 struct ico_win_mgr {
83     struct weston_compositor *compositor;   /* Weston compositor                    */
84     int32_t surface_head;                   /* (HostID << 24) | (DisplayNo << 16)   */
85
86     struct wl_list  client_list;            /* Clients                              */
87     struct wl_list  manager_list;           /* Manager(ex.HomeScreen) list          */
88     int             num_manager;            /* Number of managers                   */
89     struct wl_list  surface_list;           /* Surface list                         */
90     struct wl_list  client_attr_list;       /* Client attribute list                */
91     struct uifw_win_surface *active_pointer_surface;    /* Active Pointer Surface   */
92     struct uifw_win_surface *active_keyboard_surface;   /* Active Keyboard Surface  */
93
94     struct uifw_win_surface *idhash[UIFW_HASH];  /* UIFW SerfaceID                  */
95     struct uifw_win_surface *wshash[UIFW_HASH];  /* Weston Surface                  */
96
97     uint32_t surfaceid_count;               /* Number of surface id                 */
98     uint32_t surfaceid_max;                 /* Maximum number of surface id         */
99     uint16_t *surfaceid_map;                /* SurfaceId assign bit map             */
100 };
101
102 /* Internal macros                      */
103 /* UIFW SurfaceID                       */
104 #define MAKE_IDHASH(v)  (((uint32_t)v) & (UIFW_HASH-1))
105 /* Weston Surface                       */
106 #define MAKE_WSHASH(v)  ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
107
108 /* function prototype                   */
109                                             /* weston compositor interface          */
110 int module_init(struct weston_compositor *ec);
111                                             /* get surface table from surfece id    */
112 static struct uifw_win_surface* find_uifw_win_surface_by_id(uint32_t surfaceid);
113                                             /* get surface table from weston surface*/
114 static struct uifw_win_surface* find_uifw_win_surface_by_ws(
115                     struct weston_surface *wsurf);
116                                             /* get client table from weston client  */
117 static struct uifw_client* find_client_from_client(struct wl_client* client);
118                                             /* assign new surface id                */
119 static uint32_t generate_id(void);
120                                             /* bind shell client                    */
121 static void bind_shell_client(struct wl_client *client);
122                                             /* unind shell client                   */
123 static void unbind_shell_client(struct wl_client *client);
124                                             /* create new surface                   */
125 static void client_register_surface(
126                     struct wl_client *client, struct wl_resource *resource,
127                     struct weston_surface *surface, struct shell_surface *shsurf);
128                                             /* map new surface                      */
129 static void win_mgr_map_surface(struct weston_surface *surface, int32_t *width,
130                                 int32_t *height, int32_t *sx, int32_t *sy);
131                                             /* set applicationId for RemoteUI       */
132 static void uifw_set_user(struct wl_client *client, struct wl_resource *resource,
133                           int pid, const char *appid);
134                                             /* set/reset event flag                 */
135 static void uifw_set_eventcb(struct wl_client *client, struct wl_resource *resource,
136                              int eventcb);
137                                             /* set window layer                     */
138 static void uifw_set_window_layer(struct wl_client *client,
139                                   struct wl_resource *resource,
140                                   uint32_t surfaceid, int layer);
141                                             /* set surface size and position        */
142 static void uifw_set_positionsize(struct wl_client *client,
143                                   struct wl_resource *resource, uint32_t surfaceid,
144                                   int32_t x, int32_t y, int32_t width, int32_t height);
145                                             /* show/hide and raise/lower surface    */
146 static void uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
147                              uint32_t surfaceid, int32_t visible, int32_t raise);
148                                             /* set surface animation                */
149 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
150                                uint32_t surfaceid, int32_t change, const char *animation);
151                                             /* set active surface (form HomeScreen) */
152 static void uifw_set_active(struct wl_client *client, struct wl_resource *resource,
153                             uint32_t surfaceid, uint32_t target);
154                                             /* layer visibility control             */
155 static void uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
156                                    int32_t layer, int32_t visible);
157                                             /* send surface change event to manager */
158 static void uifw_set_client_attr(struct wl_client *client, struct wl_resource *resource,
159                                  const char *appid, int32_t attr, int32_t value);
160                                             /* set client application attribute     */
161 static void win_mgr_surface_change(struct weston_surface *surface,
162                                    const int to, const int manager);
163                                             /* surface change from manager          */
164 static int win_mgr_surface_change_mgr(struct weston_surface *surface, const int x,
165                                       const int y, const int width, const int height);
166                                             /* surface destory                      */
167 static void win_mgr_surface_destroy(struct weston_surface *surface);
168                                             /* bind manager                         */
169 static void bind_ico_win_mgr(struct wl_client *client,
170                              void *data, uint32_t version, uint32_t id);
171                                             /* unbind manager                       */
172 static void unbind_ico_win_mgr(struct wl_resource *resource);
173                                             /* convert surfaceId to nodeId          */
174 static int ico_winmgr_usurf_2_node(const int surfaceid);
175                                             /* send event to manager                */
176 static int ico_win_mgr_send_to_mgr(const int event, const int surfaceid,
177                                    const char *appid, const int param1,
178                                    const int param2, const int param3, const int param4,
179                                    const int param5, const int param6);
180                                             /* convert animation name to type value */
181 static int ico_get_animation_type(const char *animation);
182                                             /* hook for set user                    */
183 static void (*win_mgr_hook_set_user)
184                 (struct wl_client *client, const char *appid) = NULL;
185                                             /* hook for surface create              */
186 static void (*win_mgr_hook_create)
187                 (struct wl_client *client, struct weston_surface *surface,
188                  int surfaceId, const char *appid) = NULL;
189                                             /* hook for surface destory             */
190 static void (*win_mgr_hook_destroy)(struct weston_surface *surface) = NULL;
191                                             /* hook for animation                   */
192 static int  (*win_mgr_hook_animation)(const int op, void *data) = NULL;
193
194 /* static tables                        */
195 /* Multi Window Manager interface       */
196 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
197     uifw_set_user,
198     uifw_set_eventcb,
199     uifw_set_window_layer,
200     uifw_set_positionsize,
201     uifw_set_visible,
202     uifw_set_animation,
203     uifw_set_active,
204     uifw_set_layer_visible,
205     uifw_set_client_attr
206 };
207
208 /* static management table              */
209 static struct ico_win_mgr *_ico_win_mgr = NULL;
210
211
212 /*--------------------------------------------------------------------------*/
213 /**
214  * @brief   find_uifw_win_surface_by_id: find UIFW surface by surface id
215  *
216  * @param[in]   surfaceid   UIFW surface id
217  * @return      UIFW surface table address
218  * @retval      !=NULL      success(surface table address)
219  * @retval      NULL        error(surface id dose not exist)
220  */
221 /*--------------------------------------------------------------------------*/
222 static struct uifw_win_surface*
223 find_uifw_win_surface_by_id(uint32_t surfaceid)
224 {
225     struct uifw_win_surface* usurf;
226
227     usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
228
229     while (usurf)   {
230         if (usurf->id == surfaceid) {
231             return usurf;
232         }
233         usurf = usurf->next_idhash;
234     }
235     uifw_trace("find_uifw_win_surface_by_id: NULL");
236     return NULL;
237 }
238
239
240 /*--------------------------------------------------------------------------*/
241 /**
242  * @brief   find_uifw_win_surface_by_ws: find UIFW srurace by weston surface
243  *
244  * @param[in]   wsurf       Weston surface
245  * @return      UIFW surface table address
246  * @retval      !=NULL      success(surface table address)
247  * @retval      NULL        error(surface dose not exist)
248  */
249 /*--------------------------------------------------------------------------*/
250 static struct uifw_win_surface*
251 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
252 {
253     struct uifw_win_surface* usurf;
254
255     usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
256
257     while (usurf)   {
258         if (usurf->surface == wsurf) {
259             return usurf;
260         }
261         usurf = usurf->next_wshash;
262     }
263     uifw_trace("find_uifw_win_surface_by_ws: NULL");
264     return NULL;
265 }
266
267 /*--------------------------------------------------------------------------*/
268 /**
269  * @brief   find_client_from_client: find UIFW client by wayland client
270  *
271  * @param[in]   client      Wayland client
272  * @return      UIFW client table address
273  * @retval      !=NULL      success(client table address)
274  * @retval      NULL        error(client dose not exist)
275  */
276 /*--------------------------------------------------------------------------*/
277 static struct uifw_client*
278 find_client_from_client(struct wl_client* client)
279 {
280     struct uifw_client  *uclient;
281
282     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
283         if (uclient->client == client)  {
284             return(uclient);
285         }
286     }
287     uifw_trace("find_client_from_client: NULL");
288     return NULL;
289 }
290
291 /*--------------------------------------------------------------------------*/
292 /**
293  * @brief   ico_window_mgr_appid: find application id by wayland client
294  *
295  * @param[in]   client      Wayland client
296  * @return      application id
297  * @retval      !=NULL      success(application id)
298  * @retval      NULL        error(client dose not exist)
299  */
300 /*--------------------------------------------------------------------------*/
301 WL_EXPORT   char *
302 ico_window_mgr_appid(struct wl_client* client)
303 {
304     struct uifw_client  *uclient;
305
306     uclient = find_client_from_client(client);
307
308     if (! uclient)  {
309         return NULL;
310     }
311     return uclient->appid;
312 }
313
314 /*--------------------------------------------------------------------------*/
315 /**
316  * @brief   generate_id: generate uniq id for UIFW surface id
317  *
318  * @param       none
319  * @return      uniq id for UIFW surface id
320  */
321 /*--------------------------------------------------------------------------*/
322 static uint32_t
323 generate_id(void)
324 {
325     int     rep;
326     int     i;
327     int     map;
328     uint16_t *new_map;
329     uint32_t surfaceId;
330
331     /* next assign id                           */
332     _ico_win_mgr->surfaceid_count ++;
333
334     /* serach free id from bitmap               */
335     for (rep = 0; rep < (int)(_ico_win_mgr->surfaceid_max/16); rep++)   {
336         if (_ico_win_mgr->surfaceid_count >= _ico_win_mgr->surfaceid_max)   {
337             _ico_win_mgr->surfaceid_count = 0;
338         }
339         if (_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] != 0xffff)    {
340             /* find free id from bitmap         */
341             map = 1 << (_ico_win_mgr->surfaceid_count % 16);
342             for (i = (_ico_win_mgr->surfaceid_count % 16); i < 16; i++) {
343                 if ((_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] & map)
344                         == 0) {
345                     _ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] |= map;
346                     _ico_win_mgr->surfaceid_count
347                         = (_ico_win_mgr->surfaceid_count/16)*16 + i;
348
349                     surfaceId = (_ico_win_mgr->surfaceid_count + 1)
350                                 | _ico_win_mgr->surface_head;
351                     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
352                     return(surfaceId);
353                 }
354                 map = map << 1;
355             }
356         }
357         _ico_win_mgr->surfaceid_count += 16;
358     }
359
360     /* no free id in bitmap, extend bitmap      */
361     if ((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) > SURCAFE_ID_MASK)  {
362         /* too many surfaces, system error      */
363         uifw_trace("generate_id: SurffaceId Overflow(%d, Max=%d), Abort",
364                    _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
365         fprintf(stderr, "generate_id: SurffaceId Overflow(%d, Max=%d), Abort\n",
366                 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
367         abort();
368     }
369
370     new_map = (uint16_t *) malloc((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) / 8);
371     memcpy(new_map, _ico_win_mgr->surfaceid_map, _ico_win_mgr->surfaceid_max/8);
372     memset(&new_map[_ico_win_mgr->surfaceid_max/16], 0, ADD_SURFACE_IDS/8);
373     _ico_win_mgr->surfaceid_count = _ico_win_mgr->surfaceid_max;
374     new_map[_ico_win_mgr->surfaceid_count/16] |= 1;
375     _ico_win_mgr->surfaceid_max += ADD_SURFACE_IDS;
376     free(_ico_win_mgr->surfaceid_map);
377     _ico_win_mgr->surfaceid_map = new_map;
378
379     uifw_trace("generate_id: Extent SurfaceId=%d(Max.%d)",
380                _ico_win_mgr->surfaceid_count+1, _ico_win_mgr->surfaceid_max);
381     surfaceId = (_ico_win_mgr->surfaceid_count + 1) | _ico_win_mgr->surface_head;
382
383     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
384     return(surfaceId);
385 }
386
387 /*--------------------------------------------------------------------------*/
388 /**
389  * @brief   bind_shell_client: ico_ivi_shell from client
390  *
391  * @param[in]   client          Wayland client
392  * @return      none
393  */
394 /*--------------------------------------------------------------------------*/
395 static void
396 bind_shell_client(struct wl_client *client)
397 {
398     struct uifw_client  *uclient;
399     struct uifw_client_attr *lattr;
400     pid_t   pid;
401     uid_t   uid;
402     gid_t   gid;
403     int     fd;
404     int     size;
405     int     i;
406     int     j;
407     char    procpath[128];
408
409     uifw_trace("bind_shell_client: Enter(client=%08x)", (int)client);
410
411     /* set client                           */
412     uclient = find_client_from_client(client);
413     if (! uclient)  {
414         /* client not exist, create client management table             */
415         uifw_trace("bind_shell_client: Create Client");
416         uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
417         if (!uclient)   {
418             uifw_error("bind_shell_client: Error, No Memory");
419             return;
420         }
421         memset(uclient, 0, sizeof(struct uifw_client));
422         uclient->client = client;
423         wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
424     }
425     wl_client_get_credentials(client, &pid, &uid, &gid);
426     uifw_trace("bind_shell_client: client=%08x pid=%d uid=%d gid=%d",
427                (int)client, (int)pid, (int)uid, (int)gid);
428     if (pid > 0)    {
429         uclient->pid = (int)pid;
430         /* get applicationId from AppCore(AUL)  */
431         if (aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH)
432                         == AUL_R_OK)    {
433             uifw_trace("bind_shell_client: client=%08x pid=%d appid=<%s>",
434                        (int)client, uclient->pid, uclient->appid);
435         }
436         else    {
437             /* client dose not exist in AppCore, search Linux process table */
438             uifw_trace("bind_shell_client: pid=%d dose not exist in AppCore(AUL)",
439                        uclient->pid);
440
441             memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
442             snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
443             fd = open(procpath, O_RDONLY);
444             if (fd >= 0)    {
445                 size = read(fd, procpath, sizeof(procpath));
446                 for (; size > 0; size--)    {
447                     if (procpath[size-1])   break;
448                 }
449                 if (size > 0)   {
450                     /* get program base name    */
451                     i = 0;
452                     for (j = 0; j < size; j++)  {
453                         if (procpath[j] == 0)   break;
454                         if (procpath[j] == '/') i = j + 1;
455                     }
456                     j = 0;
457                     for (; i < size; i++)   {
458                         uclient->appid[j] = procpath[i];
459                         if ((uclient->appid[j] == 0) ||
460                             (j >= (ICO_IVI_APPID_LENGTH-1)))    break;
461                         j++;
462                     }
463                     /* search application number in apprication start option    */
464                     if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
465                         for (; i < size; i++)   {
466                             if ((procpath[i] == 0) &&
467                                 (procpath[i+1] == '@')) {
468                                 strncpy(&uclient->appid[j], &procpath[i+1],
469                                         ICO_IVI_APPID_LENGTH - j - 2);
470                             }
471                         }
472                     }
473                 }
474                 close(fd);
475             }
476             if (uclient->appid[0])  {
477                 uifw_trace("bind_shell_client: client=%08x pid=%d appid=<%s> from "
478                            "Process table", (int)client, uclient->pid, uclient->appid);
479             }
480             else    {
481                 uifw_trace("bind_shell_client: pid=%d dose not exist in Process table",
482                            uclient->pid);
483                 sprintf(uclient->appid, "?%d?", uclient->pid);
484             }
485         }
486
487         wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link)    {
488             if (strcmp(lattr->appid, uclient->appid) == 0)  {
489                 for (i = 0; i < MAX_CLIENT_ATTR; i++)   {
490                     switch (lattr->attrs[i].attr)   {
491                     case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
492                         uclient->noconfigure = lattr->attrs[i].value;
493                         ivi_shell_set_client_attr(uclient->client,
494                                                   ICO_CLEINT_ATTR_NOCONFIGURE,
495                                                   lattr->attrs[i].value);
496                         uifw_trace("bind_shell_client: set to ivi-shell");
497                         break;
498                     default:
499                         break;
500                     }
501                 }
502                 break;
503             }
504         }
505     }
506     else    {
507         uifw_trace("bind_shell_client: client=%08x pid dose not exist", (int)client);
508     }
509     uifw_trace("bind_shell_client: Leave");
510 }
511
512 /*--------------------------------------------------------------------------*/
513 /**
514  * @brief   unbind_shell_client: unbind ico_ivi_shell from client
515  *
516  * @param[in]   client          Wayland client
517  * @return      none
518  */
519 /*--------------------------------------------------------------------------*/
520 static void
521 unbind_shell_client(struct wl_client *client)
522 {
523     struct uifw_client  *uclient;
524
525     uifw_trace("unbind_shell_client: Enter(client=%08x)", (int)client);
526
527     uclient = find_client_from_client(client);
528     if (uclient)    {
529         /* Client exist, Destory client management table             */
530         wl_list_remove(&uclient->link);
531         free(uclient);
532     }
533     uifw_trace("unbind_shell_client: Leave");
534 }
535
536 /*--------------------------------------------------------------------------*/
537 /**
538  * @brief   ico_get_animation_type: convert animation name to type value
539  *
540  * @param[in]   animation       animation name
541  * @return      animation type value
542  */
543 /*--------------------------------------------------------------------------*/
544 static int
545 ico_get_animation_type(const char *animation)
546 {
547     int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
548
549     if (strcasecmp(animation, "none") == 0) {
550         return ICO_WINDOW_MGR_ANIMATION_NONE;
551     }
552
553     if (win_mgr_hook_animation) {
554         anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_TYPE, (void *)animation);
555     }
556     if (anima <= 0) {
557         anima = ICO_WINDOW_MGR_ANIMATION_NONE;
558     }
559     return anima;
560 }
561
562 /*--------------------------------------------------------------------------*/
563 /**
564  * @brief   client_register_surface: create UIFW surface
565  *
566  * @param[in]   client          Wayland client
567  * @param[in]   resource        client resource
568  * @param[in]   surface         Weston surface
569  * @param[in]   shsurf          shell surface
570  * @return      none
571  */
572 /*--------------------------------------------------------------------------*/
573 static void
574 client_register_surface(struct wl_client *client, struct wl_resource *resource,
575                         struct weston_surface *surface, struct shell_surface *shsurf)
576 {
577     struct uifw_win_surface *us;
578     struct uifw_win_surface *phash;
579     struct uifw_win_surface *bhash;
580     struct uifw_client_attr *lattr;
581     uint32_t    hash;
582     int         i;
583
584     uifw_trace("client_register_surface: Enter(surf=%08x,client=%08x,res=%08x)",
585                (int)surface, (int)client, (int)resource);
586
587     /* check new surface                    */
588     if (find_uifw_win_surface_by_ws(surface))   {
589         /* surface exist, NOP               */
590         uifw_trace("client_register_surface: Leave(Already Exist)");
591         return;
592     }
593
594     /* create UIFW surface management table */
595     us = malloc(sizeof(struct uifw_win_surface));
596     if (!us)    {
597         uifw_error("client_register_surface: No Memory");
598         return;
599     }
600
601     memset(us, 0, sizeof(struct uifw_win_surface));
602
603     us->id = generate_id();
604     us->surface = surface;
605     us->shsurf = shsurf;
606     wl_list_init(&us->animation.animation.link);
607     us->animation.type = ico_get_animation_type(ivi_shell_default_animation(NULL, NULL));
608     us->animation.type_next = us->animation.type;
609
610     if (_ico_win_mgr->num_manager <= 0) {
611         uifw_trace("client_register_surface: No Manager, Force visible");
612         ivi_shell_set_visible(shsurf, 1);   /* NOT exist HomeScreen     */
613     }
614     else    {
615         uifw_trace("client_register_surface: Manager exist, Not visible");
616         ivi_shell_set_visible(shsurf, -1);  /* Exist HomeScreen         */
617     }
618
619     /* set client                           */
620     us->uclient = find_client_from_client(client);
621     if (! us->uclient)  {
622         /* client not exist, create client management table */
623         uifw_trace("client_register_surface: Create Client");
624         bind_shell_client(client);
625         us->uclient = find_client_from_client(client);
626         if (! us->uclient)  {
627             uifw_error("client_register_surface: No Memory");
628             return;
629         }
630     }
631     wl_list_insert(&_ico_win_mgr->surface_list, &us->link);
632
633     /* make surface id hash table       */
634     hash = MAKE_IDHASH(us->id);
635     phash = _ico_win_mgr->idhash[hash];
636     bhash = NULL;
637     while (phash)   {
638         bhash = phash;
639         phash = phash->next_idhash;
640     }
641     if (bhash)  {
642         bhash->next_idhash = us;
643     }
644     else    {
645         _ico_win_mgr->idhash[hash] = us;
646     }
647
648     /* make weston surface hash table   */
649     hash = MAKE_WSHASH(us->surface);
650     phash = _ico_win_mgr->wshash[hash];
651     bhash = NULL;
652     while (phash)   {
653         bhash = phash;
654         phash = phash->next_wshash;
655     }
656     if (bhash)  {
657         bhash->next_wshash = us;
658     }
659     else    {
660         _ico_win_mgr->wshash[hash] = us;
661     }
662     /* set default layer id             */
663     ivi_shell_set_layer(shsurf, 0);
664
665     /* set client attribute             */
666     wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link)    {
667         if (strcmp(lattr->appid, us->uclient->appid) == 0)  {
668             for (i = 0; i < MAX_CLIENT_ATTR; i++)   {
669                 switch (lattr->attrs[i].attr)   {
670                 case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
671                     us->uclient->noconfigure = lattr->attrs[i].value;
672                     ivi_shell_set_client_attr(us->uclient->client,
673                                               ICO_CLEINT_ATTR_NOCONFIGURE,
674                                               lattr->attrs[i].value);
675                     uifw_trace("client_register_surface: set attr(%d=%d) to %08x",
676                                lattr->attrs[i].attr, lattr->attrs[i].value, us->id);
677                     break;
678                 default:
679                     break;
680                 }
681             }
682             break;
683         }
684     }
685
686     /* send event to manager            */
687     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CREATED,
688                             us->id, us->uclient->appid, us->uclient->pid, 0,0,0,0,0);
689
690     if (win_mgr_hook_create) {
691         /* call surface create hook for other plugin  */
692         (void) (*win_mgr_hook_create)(client, surface, us->id, us->uclient->appid);
693     }
694     uifw_trace("client_register_surface: Leave(surfaceId=%08x)", us->id);
695 }
696
697 /*--------------------------------------------------------------------------*/
698 /**
699  * @brief   win_mgr_map_surface: map surface
700  *
701  * @param[in]   surface         Weston surface
702  * @param[in]   width           surface width
703  * @param[in]   height          surface height
704  * @param[in]   sx              X coordinate on screen
705  * @param[in]   sy              Y coordinate on screen
706  * @return      none
707  */
708 /*--------------------------------------------------------------------------*/
709 static void
710 win_mgr_map_surface(struct weston_surface *surface, int32_t *width, int32_t *height,
711                     int32_t *sx, int32_t *sy)
712 {
713     struct uifw_win_surface *usurf;
714
715     uifw_trace("win_mgr_map_surface: Enter(%08x, x/y=%d/%d w/h=%d/%d)",
716                (int)surface, *sx, *sy, *width, *height);
717
718     usurf = find_uifw_win_surface_by_ws(surface);
719
720     if (usurf) {
721         uifw_trace("win_mgr_map_surface: surf=%08x w/h=%d/%d vis=%d",
722                    usurf->id, usurf->width, usurf->height,
723                    ivi_shell_is_visible(usurf->shsurf));
724
725         if ((usurf->width > 0) && (usurf->height > 0)) {
726             uifw_trace("win_mgr_map_surface: HomeScreen registed, PositionSize"
727                        "(surf=%08x x/y=%d/%d w/h=%d/%d vis=%d",
728                        usurf->id, usurf->x, usurf->y, usurf->width, usurf->height,
729                        ivi_shell_is_visible(usurf->shsurf));
730             *width = usurf->width;
731             *height = usurf->height;
732             surface->geometry.x = usurf->x;
733             surface->geometry.y = usurf->y;
734         }
735         else    {
736             uifw_trace("win_mgr_map_surface: HomeScreen not regist Surface, "
737                        "Change PositionSize(surf=%08x x/y=%d/%d w/h=%d/%d)",
738                        usurf->id, *sx, *sy, *width, *height);
739             usurf->width = *width;
740             usurf->height = *height;
741             usurf->x = *sx;
742             usurf->y = *sy;
743             if (usurf->x < 0)   usurf->x = 0;
744             if (usurf->y < 0)   usurf->y = 0;
745
746             if (_ico_win_mgr->num_manager > 0)  {
747                 /* HomeScreen exist, coodinate set by HomeScreen                */
748                 surface->geometry.x = 0;
749                 surface->geometry.y = 0;
750
751                 /* change surface size, because HomeScreen change surface size  */
752                 *width = 1;
753                 *height = 1;
754                 uifw_trace("win_mgr_map_surface: Change size and position");
755             }
756             else    {
757                 uifw_trace("win_mgr_map_surface: Np HomeScreen, chaneg to Visible");
758                 ivi_shell_set_visible(usurf->shsurf, 1);
759             }
760         }
761         ivi_shell_set_positionsize(usurf->shsurf,
762                                    usurf->x, usurf->y, usurf->width, usurf->height);
763         uifw_trace("win_mgr_map_surface: Leave");
764     }
765     else    {
766         uifw_trace("win_mgr_map_surface: Leave(No Window Manager Surface)");
767     }
768 }
769
770 /*--------------------------------------------------------------------------*/
771 /**
772  * @briefdwi    uifw_set_user: set user id (for RemoteUI)
773  *
774  * @param[in]   client      Weyland client
775  * @param[in]   resource    resource of request
776  * @param[in]   pid         client process id
777  * @param[in]   appid       application id
778  * @return      none
779  */
780 /*--------------------------------------------------------------------------*/
781 static void
782 uifw_set_user(struct wl_client *client, struct wl_resource *resource,
783               int pid, const char *appid)
784 {
785     struct uifw_client  *uclient;
786
787     uifw_trace("uifw_set_user: Enter(client=%08x pid=%d appid=%s)",
788                 (int)client, pid, appid);
789
790     uclient = find_client_from_client(client);
791     if (uclient)    {
792         uclient->pid = pid;
793         memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
794         strncpy(uclient->appid, appid, ICO_IVI_APPID_LENGTH-1);
795         uclient->resource = resource;
796         uifw_trace("uifw_set_user: Leave(Client Exist, change PID/AppId)");
797         return;
798     }
799
800     uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
801     if (! uclient)  {
802         uifw_trace("uifw_set_user: Leave(Error, No Memory)");
803         return;
804     }
805
806     memset(uclient, 0, sizeof(struct uifw_client));
807     uclient->client = client;
808     uclient->pid = pid;
809     memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
810     strncpy(uclient->appid, appid, ICO_IVI_APPID_LENGTH-1);
811     uclient->resource = resource;
812
813     wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
814
815     if (win_mgr_hook_set_user) {
816         (void) (*win_mgr_hook_set_user) (client, uclient->appid);
817     }
818     uifw_trace("uifw_set_user: Leave");
819 }
820
821 /*--------------------------------------------------------------------------*/
822 /**
823  * @brief   uifw_set_eventcb: set event callback flag for HomeScreen
824  *
825  * @param[in]   client      Weyland client
826  * @param[in]   resource    resource of request
827  * @param[in]   eventcb     event callback flag(1=callback, 0=no callback)
828  * @return      none
829  */
830 /*--------------------------------------------------------------------------*/
831 static void
832 uifw_set_eventcb(struct wl_client *client, struct wl_resource *resource, int eventcb)
833 {
834     struct uifw_manager* mgr;
835     struct uifw_win_surface *usurf;
836     struct uifw_client *uclient;
837
838     uifw_trace("uifw_set_eventcb: Enter client=%08x eventcb=%d",
839                (int)client, eventcb);
840
841     uclient = find_client_from_client(client);
842     if (uclient)    {
843         uclient->manager = eventcb;
844     }
845
846     /* client set to manager            */
847     _ico_win_mgr->num_manager = 0;
848     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
849         if (mgr->resource == resource)  {
850             if (mgr->eventcb != eventcb)    {
851                 uifw_trace("uifw_set_eventcb: Event Callback %d=>%d",
852                            mgr->eventcb, eventcb);
853                 mgr->eventcb = eventcb;
854
855                 if (eventcb)    {
856                     wl_list_for_each (usurf, &_ico_win_mgr->surface_list, link) {
857                         /* send window create event to manager  */
858                         uifw_trace("uifw_set_eventcb: Send manager(%08x) WINDOW_CREATED"
859                                    "(surf=%08x,pid=%d,appid=%s)", (int)resource, usurf->id,
860                                    usurf->uclient->pid, usurf->uclient->appid);
861                         ico_window_mgr_send_window_created(resource,
862                             usurf->id, usurf->uclient->pid, usurf->uclient->appid);
863                     }
864                 }
865             }
866         }
867         if (mgr->eventcb)   {
868             _ico_win_mgr->num_manager++;
869         }
870     }
871     uifw_trace("uifw_set_eventcb: Leave(managers=%d)", _ico_win_mgr->num_manager);
872 }
873
874 /*--------------------------------------------------------------------------*/
875 /**
876  * @brief   uifw_set_window_layer: set layer id to surface
877  *
878  * @param[in]   client      Weyland client
879  * @param[in]   resource    resource of request
880  * @param[in]   surfaceid   UIFW surface id
881  * @param[in]   layer       layer id
882  * @return      none
883  */
884 /*--------------------------------------------------------------------------*/
885 static void
886 uifw_set_window_layer(struct wl_client *client, struct wl_resource *resource,
887                       uint32_t surfaceid, int32_t layer)
888 {
889     uifw_trace("uifw_set_window_layer: Enter res=%08x surfaceid=%08x layer=%d",
890                (int)resource, surfaceid, layer);
891
892     struct uifw_win_surface *usurf = find_uifw_win_surface_by_id(surfaceid);
893
894     if (! usurf)    {
895         uifw_trace("uifw_set_window_layer: Leave(No Surface(id=%08x)", surfaceid);
896         return;
897     }
898     else if (usurf->layer != layer) {
899         usurf->layer = layer;
900         uifw_trace("uifw_set_window_layer: Set Layer(%d) to Shell Surface", layer);
901         ivi_shell_set_layer(usurf->shsurf, layer);
902
903         win_mgr_surface_change(usurf->surface, 1, 1);
904     }
905     uifw_trace("uifw_set_window_layer: Leave");
906 }
907
908 /*--------------------------------------------------------------------------*/
909 /**
910  * @brief   uifw_set_weston_surface: set weston surface from UIFW surface
911  *
912  * @param[in]   usurf       UIFW surface
913  * @return      none
914  */
915 /*--------------------------------------------------------------------------*/
916 static void
917 uifw_set_weston_surface(struct uifw_win_surface *usurf)
918 {
919     struct weston_surface *es = usurf->surface;
920     int     width = usurf->width;
921     int     height = usurf->height;
922     int     x = usurf->x;
923     int     y = usurf->y;
924
925     if ((es != NULL) && (es->buffer != NULL))   {
926         if (usurf->width > es->buffer->width)   {
927             width = es->buffer->width;
928             x += (usurf->width - es->buffer->width)/2;
929         }
930         if (usurf->height > es->buffer->height) {
931             height = es->buffer->height;
932             y += (usurf->height - es->buffer->height)/2;
933         }
934     }
935     ivi_shell_set_positionsize(usurf->shsurf,
936                                usurf->x, usurf->y, usurf->width, usurf->height);
937     uifw_trace("uifw_set_weston_surface: w/h=%d/%d->%d/%d x/y=%d/%d->%d/%d",
938                usurf->width, usurf->height, width, height, usurf->x, usurf->y, x, y);
939     ivi_shell_surface_configure(usurf->shsurf, x, y, width, height);
940 }
941
942 /*--------------------------------------------------------------------------*/
943 /**
944  * @brief   uifw_set_positionsize: set surface position and size
945  *
946  * @param[in]   client      Weyland client
947  * @param[in]   resource    resource of request
948  * @param[in]   surfaceid   UIFW surface id
949  * @param[in]   x           X coordinate on screen(if bigger than 16383, no change)
950  * @param[in]   y           Y coordinate on screen(if bigger than 16383, no change)
951  * @param[in]   width       surface width(if bigger than 16383, no change)
952  * @param[in]   height      surface height(if bigger than 16383, no change)
953  * @return      none
954  */
955 /*--------------------------------------------------------------------------*/
956 static void
957 uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
958                       uint32_t surfaceid,
959                       int32_t x, int32_t y, int32_t width, int32_t height)
960 {
961     struct uifw_client *uclient;
962
963     uifw_trace("uifw_set_positionsize: Enter res=%08x surf=%08x x/y/w/h=%d/%d/%d/%d",
964                (int)resource, surfaceid, x, y, width, height);
965
966     struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
967
968     if (usurf && (usurf->surface))  {
969         /* weston surface exist             */
970         struct weston_surface *es = usurf->surface;
971
972         /* if x,y,width,height bigger then ICO_IVI_MAX_COORDINATE, no change    */
973         if (x > ICO_IVI_MAX_COORDINATE)         x = usurf->x;
974         if (y > ICO_IVI_MAX_COORDINATE)         y = usurf->y;
975         if (width > ICO_IVI_MAX_COORDINATE)     width = usurf->width;
976         if (height > ICO_IVI_MAX_COORDINATE)    height = usurf->height;
977
978         /* check animation                  */
979         if ((usurf->animation.type != ICO_WINDOW_MGR_ANIMATION_NONE) &&
980             (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
981             (win_mgr_hook_animation != NULL) &&
982             (x == usurf->x) && (y == usurf->y) &&
983             (width == usurf->width) && (height == usurf->height))   {
984             uifw_trace("uifw_set_positionsize: Leave(same position size at animation)");
985             return;
986         }
987
988         uclient = find_client_from_client(client);
989         if (uclient)    {
990             if (! uclient->manager) uclient = NULL;
991         }
992         if (! uclient)  {
993             if ((usurf->width > 0) && (usurf->height > 0))  {
994                 win_mgr_surface_change_mgr(es, x, y, width, height);
995                 uifw_trace("uifw_set_positionsize: Leave(Request from App)");
996                 return;
997             }
998
999             uifw_trace("uifw_set_positionsize: Initial Position/Size visible=%d",
1000                        ivi_shell_is_visible(usurf->shsurf));
1001             /* Initiale position is (0,0)   */
1002             es->geometry.x = 0;
1003             es->geometry.y = 0;
1004         }
1005
1006         uifw_trace("uifw_set_positionsize: Old geometry x/y=%d/%d,w/h=%d/%d",
1007                    (int)es->geometry.x, (int)es->geometry.y,
1008                    (int)es->geometry.width, (int)es->geometry.height);
1009
1010         usurf->x = x;
1011         usurf->y = y;
1012         usurf->width = width;
1013         usurf->height = height;
1014         ivi_shell_set_positionsize(usurf->shsurf, x, y, width, height);
1015         if (_ico_win_mgr->num_manager <= 0) {
1016             /* no manager(HomeScreen), set geometory    */
1017             es->geometry.x = x;
1018             es->geometry.y = y;
1019         }
1020         if ((es->output) && (es->buffer) &&
1021             (es->geometry.width > 0) && (es->geometry.height > 0)) {
1022             uifw_trace("uifw_set_positionsize: Fixed Geometry, Change(Vis=%d)",
1023                        ivi_shell_is_visible(usurf->shsurf));
1024             uifw_set_weston_surface(usurf);
1025             weston_surface_damage_below(es);
1026             weston_surface_damage(es);
1027             weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1028         }
1029         win_mgr_surface_change(es, 0, 1);
1030
1031         uifw_trace("uifw_set_positionsize: Leave(OK,output=%x)", (int)es->output);
1032     }
1033     else    {
1034         uifw_trace("uifw_set_positionsize: Leave(surf=%08x NOT Found)", surfaceid);
1035     }
1036 }
1037
1038 /*--------------------------------------------------------------------------*/
1039 /**
1040  * @brief   uifw_set_visible: surface visible/raise control
1041  *
1042  * @param[in]   client      Weyland client
1043  * @param[in]   resource    resource of request
1044  * @param[in]   surfaceid   UIFW surface id
1045  * @param[in]   visible     visible(1=show/0=hide/other=no change)
1046  * @param[in]   raise       raise(1=raise/0=lower/other=no change)
1047  * @return      none
1048  */
1049 /*--------------------------------------------------------------------------*/
1050 static void
1051 uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
1052                  uint32_t surfaceid, int32_t visible, int32_t raise)
1053 {
1054     struct uifw_win_surface* usurf;
1055     struct uifw_client *uclient;
1056     int         animation;
1057
1058     uifw_trace("uifw_set_visible: Enter(surf=%08x,%d,%d)", surfaceid, visible, raise);
1059
1060     uclient = find_client_from_client(client);
1061     if (uclient)    {
1062         if (! uclient->manager) {
1063             uifw_trace("uifw_set_visible: Request from App(%s), not Manager",
1064                        uclient->appid);
1065             uclient = NULL;
1066         }
1067         else    {
1068             uifw_trace("uifw_set_visible: Request from Manager(%s)", uclient->appid);
1069         }
1070     }
1071     else    {
1072         uifw_trace("uifw_set_visible: Request from Unknown App, not Manager");
1073     }
1074
1075     usurf = find_uifw_win_surface_by_id(surfaceid);
1076
1077     if ((! usurf) || (! usurf->surface))    {
1078         uifw_trace("uifw_set_visible: Leave(Surface Not Exist)");
1079         return;
1080     }
1081
1082     if ((visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ||
1083         (visible == ICO_WINDOW_MGR_VISIBLE_SHOW_WO_ANIMATION))  {
1084         if ((usurf->width <= 0) || (usurf->height <= 0))    {
1085             /* not declare surface geometry, initialize     */
1086             usurf->width = usurf->surface->geometry.width;
1087             usurf->height = usurf->surface->geometry.height;
1088             uifw_trace("uifw_set_visible: Set w/h=%d/%d", usurf->width, usurf->height);
1089         }
1090         if (! ivi_shell_is_visible(usurf->shsurf))  {
1091             if (uclient)    {
1092                 /* manager exist, change to visible         */
1093                 ivi_shell_set_visible(usurf->shsurf, 1);
1094             }
1095             uifw_trace("uifw_set_visible: Change to Visible");
1096
1097             ivi_shell_set_toplevel(usurf->shsurf);
1098
1099             /* Weston surface configure                     */
1100             uifw_trace("uifw_set_visible: Visible to Weston WSurf=%08x,%d/%d/%d/%d",
1101                        (int)usurf->surface, usurf->x, usurf->y,
1102                        usurf->width, usurf->height);
1103             uifw_set_weston_surface(usurf);
1104             ivi_shell_set_surface_type(usurf->shsurf);
1105
1106             if ((visible == ICO_WINDOW_MGR_VISIBLE_SHOW) &&
1107                 (usurf->animation.type != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1108                 (win_mgr_hook_animation != NULL))   {
1109                 animation = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPIN,
1110                                                       (void *)usurf);
1111             }
1112         }
1113         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1114                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1115             uifw_trace("uifw_set_visible: Leave(No Change)");
1116             return;
1117         }
1118     }
1119     else if ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ||
1120              (visible == ICO_WINDOW_MGR_VISIBLE_HIDE_WO_ANIMATION)) {
1121
1122         if (ivi_shell_is_visible(usurf->shsurf))    {
1123
1124             /* Weston surface configure                     */
1125             uifw_set_weston_surface(usurf);
1126
1127             animation = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
1128             if ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) &&
1129                 (usurf->animation.type > 0) &&
1130                 (win_mgr_hook_animation != NULL))   {
1131                 animation = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPOUT,
1132                                                       (void *)usurf);
1133             }
1134             if (animation != ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW)    {
1135                 ivi_shell_set_visible(usurf->shsurf, 0);
1136                 uifw_trace("uifw_set_visible: Change to UnVisible");
1137             }
1138             else    {
1139                 uifw_trace("uifw_set_visible: UnVisible but animation");
1140             }
1141         }
1142         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1143                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1144             uifw_trace("uifw_set_visible: Leave(No Change)");
1145             return;
1146         }
1147     }
1148     else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1149              (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1150         uifw_trace("uifw_set_visible: Leave(No Change)");
1151         return;
1152     }
1153
1154     /* raise/lower                              */
1155     if ((raise == ICO_WINDOW_MGR_RAISE_LOWER) || (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1156         ivi_shell_set_raise(usurf->shsurf, raise);
1157     }
1158
1159     if ((usurf->surface) && (usurf->surface->buffer) && (usurf->surface->output))   {
1160         weston_surface_damage_below(usurf->surface);
1161         weston_surface_damage(usurf->surface);
1162         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1163     }
1164     /* send event(VISIBLE) to manager           */
1165     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
1166                             surfaceid, NULL,
1167                             (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ||
1168                               (visible == ICO_WINDOW_MGR_VISIBLE_SHOW_WO_ANIMATION) ? 1 :
1169                                 ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ||
1170                                    (visible == ICO_WINDOW_MGR_VISIBLE_HIDE_WO_ANIMATION) ? 0 :
1171                                      ICO_WINDOW_MGR_VISIBLE_NOCHANGE),
1172                             raise, uclient ? 0 : 1, 0,0,0);
1173
1174     uifw_trace("uifw_set_visible: Leave(OK)");
1175 }
1176
1177 /*--------------------------------------------------------------------------*/
1178 /**
1179  * @brief   uifw_set_animation: set animation of surface visible/unvisible
1180  *
1181  * @param[in]   client      Weyland client
1182  * @param[in]   resource    resource of request
1183  * @param[in]   surfaceid   UIFW surface id
1184  * @param[in]   change      change type(show/hide,reeize,move)
1185  * @param[in]   anmation    animation name
1186  * @return      none
1187  */
1188 /*--------------------------------------------------------------------------*/
1189 static void
1190 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
1191                    uint32_t surfaceid, int32_t change, const char *animation)
1192 {
1193     struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
1194
1195     uifw_trace("uifw_set_transition: Enter(surf=%08x, change=%d, animation=%s)",
1196                surfaceid, change, animation);
1197
1198     if (usurf) {
1199         if (change != ICO_WINDOW_MGR_ANIMATION_CHANGE_VISIBLE)  {
1200             uifw_trace("uifw_set_animation: Leave(change type(%d9 not support)", change);
1201         }
1202         else    {
1203             usurf->animation.type_next = ico_get_animation_type(animation);
1204             uifw_trace("uifw_set_animation: Leave(OK) type=%d", usurf->animation.type_next);
1205             if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE)  {
1206                 usurf->animation.type = usurf->animation.type_next;
1207             }
1208         }
1209     }
1210     else    {
1211         uifw_trace("uifw_set_animation: Leave(Surface(%08x) Not exist)", surfaceid);
1212     }
1213 }
1214
1215 /*--------------------------------------------------------------------------*/
1216 /**
1217  * @brief   uifw_set_active: set active surface
1218  *
1219  * @param[in]   client      Weyland client
1220  * @param[in]   resource    resource of request
1221  * @param[in]   surfaceid   UIFW surface id
1222  * @param[in]   target      target device
1223  * @return      none
1224  */
1225 /*--------------------------------------------------------------------------*/
1226 static void
1227 uifw_set_active(struct wl_client *client, struct wl_resource *resource,
1228                 uint32_t surfaceid, uint32_t target)
1229 {
1230     struct uifw_win_surface* usurf;
1231
1232     uifw_trace("uifw_set_active: Enter(surf=%08x,target=%x)", surfaceid, target);
1233
1234     if ((surfaceid > 0) &&
1235         ((target & (ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD)) != 0)) {
1236         usurf = find_uifw_win_surface_by_id(surfaceid);
1237     }
1238     else    {
1239         usurf = NULL;
1240     }
1241     if (usurf) {
1242         switch (target & (ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD)) {
1243         case ICO_IVI_SHELL_ACTIVE_POINTER:
1244             if (usurf != _ico_win_mgr->active_pointer_surface)  {
1245                 if (_ico_win_mgr->active_pointer_surface)   {
1246                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1247                                             _ico_win_mgr->active_pointer_surface->id, NULL,
1248                                             (_ico_win_mgr->active_keyboard_surface ==
1249                                              _ico_win_mgr->active_pointer_surface) ?
1250                                                 ICO_IVI_SHELL_ACTIVE_KEYBOARD :
1251                                                 ICO_IVI_SHELL_ACTIVE_NONE,
1252                                             0,0,0,0,0);
1253                 }
1254                 _ico_win_mgr->active_pointer_surface = usurf;
1255                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1256                                         surfaceid, NULL,
1257                                         ICO_IVI_SHELL_ACTIVE_POINTER |
1258                                         (_ico_win_mgr->active_keyboard_surface == usurf) ?
1259                                             ICO_IVI_SHELL_ACTIVE_KEYBOARD : 0,
1260                                         0,0,0,0,0);
1261                 ivi_shell_set_active(usurf->shsurf, ICO_IVI_SHELL_ACTIVE_POINTER);
1262             }
1263             break;
1264         case ICO_IVI_SHELL_ACTIVE_KEYBOARD:
1265             if (usurf != _ico_win_mgr->active_keyboard_surface) {
1266                 if (_ico_win_mgr->active_keyboard_surface)   {
1267                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1268                                             _ico_win_mgr->active_keyboard_surface->id, NULL,
1269                                             (_ico_win_mgr->active_keyboard_surface ==
1270                                              _ico_win_mgr->active_pointer_surface) ?
1271                                                 ICO_IVI_SHELL_ACTIVE_POINTER :
1272                                                 ICO_IVI_SHELL_ACTIVE_NONE,
1273                                             0,0,0,0,0);
1274                 }
1275                 _ico_win_mgr->active_keyboard_surface = usurf;
1276                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1277                                         surfaceid, NULL,
1278                                         ICO_IVI_SHELL_ACTIVE_KEYBOARD |
1279                                         (_ico_win_mgr->active_pointer_surface == usurf) ?
1280                                             ICO_IVI_SHELL_ACTIVE_POINTER : 0,
1281                                         0,0,0,0,0);
1282                 ivi_shell_set_active(usurf->shsurf, ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1283             }
1284             break;
1285         default:
1286             if ((usurf != _ico_win_mgr->active_pointer_surface) ||
1287                 (usurf != _ico_win_mgr->active_keyboard_surface))   {
1288                 if (_ico_win_mgr->active_pointer_surface)   {
1289                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1290                                             _ico_win_mgr->active_pointer_surface->id,
1291                                             NULL, ICO_IVI_SHELL_ACTIVE_NONE,
1292                                             0,0,0,0,0);
1293                     if (_ico_win_mgr->active_keyboard_surface ==
1294                         _ico_win_mgr->active_pointer_surface)   {
1295                         _ico_win_mgr->active_keyboard_surface = NULL;
1296                     }
1297                 }
1298                 if (_ico_win_mgr->active_keyboard_surface)   {
1299                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1300                                             _ico_win_mgr->active_keyboard_surface->id,
1301                                             NULL, ICO_IVI_SHELL_ACTIVE_NONE,
1302                                             0,0,0,0,0);
1303                 }
1304                 _ico_win_mgr->active_pointer_surface = usurf;
1305                 _ico_win_mgr->active_keyboard_surface = usurf;
1306                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1307                                         surfaceid, NULL,
1308                                         ICO_IVI_SHELL_ACTIVE_POINTER |
1309                                             ICO_IVI_SHELL_ACTIVE_KEYBOARD,
1310                                         0,0,0,0,0);
1311                 ivi_shell_set_active(usurf->shsurf,
1312                                      ICO_IVI_SHELL_ACTIVE_POINTER |
1313                                          ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1314             }
1315             break;
1316         }
1317         uifw_trace("uifw_set_active: Leave(Change Active)");
1318     }
1319     else    {
1320         ivi_shell_set_active(NULL, target);
1321         uifw_trace("uifw_set_active: Leave(Reset active surface)");
1322     }
1323 }
1324
1325 /*--------------------------------------------------------------------------*/
1326 /**
1327  * @brief   uifw_set_layer_visible: layer visible control
1328  *
1329  * @param[in]   client      Weyland client
1330  * @param[in]   resource    resource of request
1331  * @param[in]   layer       layer id
1332  * @param[in]   visible     visible(1=show/0=hide)
1333  * @return      none
1334  */
1335 /*--------------------------------------------------------------------------*/
1336 static void
1337 uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
1338                        int32_t layer, int32_t visible)
1339 {
1340     uifw_trace("uifw_set_layer_visible: Enter(layer=%d, visilbe=%d)", layer, visible);
1341
1342     ivi_shell_set_layer_visible(layer, visible);
1343
1344     uifw_trace("uifw_set_layer_visible: Leave");
1345 }
1346
1347 /*--------------------------------------------------------------------------*/
1348 /**
1349  * @brief   uifw_set_client_attr: set client application attribute
1350  *
1351  * @param[in]   client      Weyland client
1352  * @param[in]   resource    resource of request
1353  * @param[in]   appid       client application name
1354  * @param[in]   attr        attribute
1355  * @param[in]   value       attribute value
1356  * @return      none
1357  */
1358 /*--------------------------------------------------------------------------*/
1359 static void
1360 uifw_set_client_attr(struct wl_client *client, struct wl_resource *resource,
1361                      const char *appid, int32_t attr, int32_t value)
1362 {
1363     struct uifw_client_attr *lattr;
1364     struct uifw_client  *uclient;
1365     int     idx, freeidx;
1366
1367     uifw_trace("uifw_set_client_attr: Enter(appid=%s, attr=%d, value=%d)",
1368                appid, attr, value);
1369
1370     freeidx = -1;
1371     wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link)    {
1372         if (strcmp(lattr->appid, appid) == 0)   {
1373             for (idx = 0; idx < MAX_CLIENT_ATTR; idx++) {
1374                 if (lattr->attrs[idx].attr == attr) {
1375                     lattr->attrs[idx].value = value;
1376                     freeidx = 999;
1377                     break;
1378                 }
1379                 if ((freeidx < 0) && (lattr->attrs[idx].attr < 0))  {
1380                     freeidx = idx;
1381                 }
1382             }
1383             if ((idx >= MAX_CLIENT_ATTR) && (freeidx >= 0)) {
1384                 lattr->attrs[freeidx].attr = attr;
1385                 lattr->attrs[freeidx].value = value;
1386             }
1387             else    {
1388                 freeidx = 998;
1389             }
1390             break;
1391         }
1392     }
1393     if (freeidx < 0)    {
1394         lattr = malloc(sizeof(struct uifw_client_attr));
1395         if (lattr)  {
1396             memset(lattr, 0, sizeof(struct uifw_client_attr));
1397             strncpy(lattr->appid, appid, ICO_IVI_APPID_LENGTH-1);
1398             for (idx = 1; idx < MAX_CLIENT_ATTR; idx++) {
1399                 lattr->attrs[idx].attr = -1;
1400             }
1401             lattr->attrs[0].attr = attr;
1402             lattr->attrs[0].value = value;
1403             wl_list_insert(&_ico_win_mgr->client_attr_list, &lattr->link);
1404         }
1405     }
1406
1407     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
1408         if (strcmp(uclient->appid, appid) == 0) {
1409             switch(attr)    {
1410             case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
1411                 uclient->noconfigure = value;
1412                 ivi_shell_set_client_attr(uclient->client,
1413                                           ICO_CLEINT_ATTR_NOCONFIGURE, value);
1414                 uifw_trace("uifw_set_client_attr: set to ivi-shell");
1415                 break;
1416             default:
1417                 uifw_trace("uifw_set_client_attr: Unknown attr(%d)", attr);
1418                 break;
1419             }
1420             break;
1421         }
1422     }
1423     uifw_trace("uifw_set_client_attr: Leave");
1424 }
1425
1426 /*--------------------------------------------------------------------------*/
1427 /**
1428  * @brief   win_mgr_surface_change_mgr: surface chagen from manager(HomeScreen)
1429  *
1430  * @param[in]   surface     Weston surface
1431  * @param[in]   x           X coordinate on screen
1432  * @param[in]   y           Y coordinate on screen
1433  * @param[in]   width       surface width
1434  * @param[in]   height      surface height
1435  * @return      number of managers
1436  * @retval      > 0         number of managers
1437  * @retval      0           manager not exist
1438  */
1439 /*--------------------------------------------------------------------------*/
1440 static int
1441 win_mgr_surface_change_mgr(struct weston_surface *surface,
1442                            const int x, const int y, const int width, const int height)
1443 {
1444     int     num_mgr;
1445     struct uifw_win_surface *usurf;
1446
1447     uifw_trace("win_mgr_surface_change_mgr: Enter(%08x,x/y=%d/%d,w/h=%d/%d)",
1448                (int)surface, x, y, width, height);
1449
1450     usurf = find_uifw_win_surface_by_ws(surface);
1451     if (! usurf) {
1452         uifw_trace("win_mgr_surface_change_mgr: Leave(Not Exist)");
1453         return 0;
1454     }
1455
1456     num_mgr = ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
1457                                       usurf->id, usurf->uclient->appid, usurf->layer,
1458                                       x, y, width, height, 1);
1459
1460     uifw_trace("win_mgr_surface_change_mgr: Leave(%d)", num_mgr);
1461     return num_mgr;
1462 }
1463
1464 /*--------------------------------------------------------------------------*/
1465 /**
1466  * @brief   win_mgr_surface_change: surface change
1467  *
1468  * @param[in]   surface     Weston surface
1469  * @param[in]   to          destination(0=Client&Manager,1=Client,-1=Manager)
1470  * @param[in]   manager     request from manager(0=Client,1=Manager)
1471  * @return      none
1472  */
1473 /*--------------------------------------------------------------------------*/
1474 static void
1475 win_mgr_surface_change(struct weston_surface *surface, const int to, const int manager)
1476 {
1477     struct uifw_win_surface *usurf;
1478
1479     uifw_trace("win_mgr_surface_change: Enter(%08x,%d,%d)", (int)surface, to, manager);
1480
1481     /* Find surface         */
1482     usurf = find_uifw_win_surface_by_ws(surface);
1483     if (! usurf) {
1484         uifw_trace("win_mgr_surface_change: Leave(Not Exist)");
1485         return;
1486     }
1487
1488     /* send wayland event to client     */
1489     if ((to >= 0) && (usurf->shsurf != NULL) && (manager !=0))    {
1490         uifw_trace("win_mgr_surface_change: Send SHELL_SURFACE_CONFIGURE(%08x,w/h=%d/%d)",
1491                    usurf->id, usurf->width, usurf->height);
1492         ivi_shell_send_configure(usurf->shsurf, usurf->id,
1493                                  (WL_SHELL_SURFACE_RESIZE_RIGHT |
1494                                   WL_SHELL_SURFACE_RESIZE_BOTTOM),
1495                                  usurf->width, usurf->height);
1496     }
1497
1498     /* send manager event to HomeScreen */
1499     if (to <= 0)    {
1500         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
1501                                 usurf->id, usurf->uclient->appid, usurf->layer,
1502                                 usurf->x, usurf->y, usurf->width, usurf->height,
1503                                 (manager != 0) ? 0 : 1);
1504     }
1505     uifw_trace("win_mgr_surface_change: Leave(OK)");
1506 }
1507
1508 /*--------------------------------------------------------------------------*/
1509 /**
1510  * @brief   win_mgr_surface_select: select surface by Bottun/Touch
1511  *
1512  * @param[in]   surface     Weston surface
1513  * @return      none
1514  */
1515 /*--------------------------------------------------------------------------*/
1516 static void
1517 win_mgr_surface_select(struct weston_surface *surface)
1518 {
1519     struct uifw_win_surface *usurf;
1520
1521     uifw_trace("win_mgr_surface_select: Enter(%08x)", (int)surface);
1522
1523     /* find surface         */
1524     usurf = find_uifw_win_surface_by_ws(surface);
1525     if (! usurf) {
1526         uifw_trace("win_mgr_surface_select: Leave(Not Exist)");
1527         return;
1528     }
1529
1530     /* send active event to manager     */
1531     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1532                             usurf->id, NULL, ICO_IVI_SHELL_ACTIVE_SELECTED, 0,0,0,0,0);
1533
1534     uifw_trace("win_mgr_surface_select: Leave(OK)");
1535 }
1536
1537 /*--------------------------------------------------------------------------*/
1538 /**
1539  * @brief   win_mgr_surface_destroy: surface destroy
1540  *
1541  * @param[in]   surface     Weston surface
1542  * @return      none
1543  */
1544 /*--------------------------------------------------------------------------*/
1545 static void
1546 win_mgr_surface_destroy(struct weston_surface *surface)
1547 {
1548     struct uifw_win_surface *usurf;
1549     struct uifw_win_surface *phash;
1550     struct uifw_win_surface *bhash;
1551     uint32_t    hash;
1552
1553     uifw_trace("win_mgr_surface_destroy: Enter(%08x)", (int)surface);
1554
1555     usurf = find_uifw_win_surface_by_ws(surface);
1556     if (! usurf) {
1557         uifw_trace("win_mgr_surface_destroy: Leave(Not Exist)");
1558         return;
1559     }
1560
1561     /* destory animation extenson   */
1562     if (win_mgr_hook_animation) {
1563         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
1564     }
1565     hash = MAKE_IDHASH(usurf->id);
1566     phash = _ico_win_mgr->idhash[hash];
1567     bhash = NULL;
1568     while ((phash) && (phash != usurf)) {
1569         bhash = phash;
1570         phash = phash->next_idhash;
1571     }
1572     if (bhash)  {
1573         bhash->next_idhash = usurf->next_idhash;
1574     }
1575     else    {
1576         _ico_win_mgr->idhash[hash] = usurf->next_idhash;
1577     }
1578
1579     hash = MAKE_WSHASH(usurf->surface);
1580     phash = _ico_win_mgr->wshash[hash];
1581     bhash = NULL;
1582     while ((phash) && (phash != usurf)) {
1583         bhash = phash;
1584         phash = phash->next_wshash;
1585     }
1586     if (bhash)  {
1587         bhash->next_wshash = usurf->next_wshash;
1588     }
1589     else    {
1590         _ico_win_mgr->wshash[hash] = usurf->next_wshash;
1591     }
1592
1593     wl_list_remove(&usurf->link);
1594     wl_list_init(&usurf->link);
1595
1596     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_DESTROYED,
1597                            usurf->id, NULL, 0,0,0,0,0,0);
1598
1599     hash = usurf->id & SURCAFE_ID_MASK;
1600     _ico_win_mgr->surfaceid_map[(hash - 1)/16] &= ~(1 << ((hash - 1) % 16));
1601
1602     free(usurf);
1603
1604     if (win_mgr_hook_destroy) {
1605         (void) (*win_mgr_hook_destroy) (surface);
1606     }
1607     uifw_trace("win_mgr_surface_destroy: Leave(OK)");
1608 }
1609
1610 /*--------------------------------------------------------------------------*/
1611 /**
1612  * @brief   bind_ico_win_mgr: bind Multi Window Manager from client
1613  *
1614  * @param[in]   client      client
1615  * @param[in]   data        user data(unused)
1616  * @param[in]   version     protocol version(unused)
1617  * @param[in]   id          client object id
1618  * @return      none
1619  */
1620 /*--------------------------------------------------------------------------*/
1621 static void
1622 bind_ico_win_mgr(struct wl_client *client,
1623                  void *data, uint32_t version, uint32_t id)
1624 {
1625     struct wl_resource *add_resource;
1626     struct uifw_manager *nm;
1627
1628     uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
1629
1630     add_resource = wl_client_add_object(client, &ico_window_mgr_interface,
1631                                         &ico_window_mgr_implementation, id, _ico_win_mgr);
1632     add_resource->destroy = unbind_ico_win_mgr;
1633
1634     /* Manager                                      */
1635     nm = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
1636     memset(nm, 0, sizeof(struct uifw_manager));
1637     nm->resource = add_resource;
1638     wl_list_insert(&_ico_win_mgr->manager_list, &nm->link);
1639
1640     uifw_trace("bind_ico_win_mgr: Leave");
1641 }
1642
1643 /*--------------------------------------------------------------------------*/
1644 /**
1645  * @brief   unbind_ico_win_mgr: unbind Multi Window Manager from client
1646  *
1647  * @param[in]   resource    client resource
1648  * @return      none
1649  */
1650 /*--------------------------------------------------------------------------*/
1651 static void
1652 unbind_ico_win_mgr(struct wl_resource *resource)
1653 {
1654     struct uifw_manager *mgr, *itmp;
1655
1656     uifw_trace("unbind_ico_win_mgr: Enter");
1657
1658     /* Remove manager from manager list */
1659     _ico_win_mgr->num_manager = 0;
1660     wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link)    {
1661         if (mgr->resource == resource) {
1662             wl_list_remove(&mgr->link);
1663             free(mgr);
1664         }
1665         else    {
1666             if (mgr->eventcb)   {
1667                 _ico_win_mgr->num_manager++;
1668             }
1669         }
1670     }
1671
1672     free(resource);
1673     uifw_trace("unbind_ico_win_mgr: Leave");
1674 }
1675
1676 /*--------------------------------------------------------------------------*/
1677 /**
1678  * @brief   ico_winmgr_usurf_2_node: get surface nodeId
1679  *
1680  * @param[in]   surfaceid   UIFW surface id
1681  * @return      node id
1682  * @retval      >= 0        success(surface node id)
1683  * @retval      < 0         error(surface id dose not exist)
1684  */
1685 /*--------------------------------------------------------------------------*/
1686 static  int
1687 ico_winmgr_usurf_2_node(const int surfaceid)
1688 {
1689     /* currently support single ECU system  */
1690     return(ICO_IVI_SURFACEID_2_NODEID(surfaceid));
1691 }
1692
1693 /*--------------------------------------------------------------------------*/
1694 /**
1695  * @brief   ico_win_mgr_send_to_mgr: send event to manager(HomeScreen)
1696  *
1697  * @param[in]   event       event code(if -1, not send event)
1698  * @param[in]   surfaceid   UIFW surface id
1699  * @param[in]   appid       applicationId
1700  * @param[in]   param1      parameter 1
1701  * @param[in]      :             :
1702  * @param[in]   param6      parameter 6
1703  * @return      number of managers
1704  * @retval      > 0         number of managers
1705  * @retval      0           manager not exist
1706  */
1707 /*--------------------------------------------------------------------------*/
1708 static int
1709 ico_win_mgr_send_to_mgr(const int event, const int surfaceid, const char *appid,
1710                         const int param1, const int param2, const int param3,
1711                         const int param4, const int param5, const int param6)
1712 {
1713     int     num_mgr = 0;
1714     struct uifw_manager* mgr;
1715
1716     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1717         if (mgr->eventcb)   {
1718             num_mgr ++;
1719             switch(event)   {
1720             case ICO_WINDOW_MGR_WINDOW_CREATED:
1721                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_CREATED"
1722                            "(surf=%08x,pid=%d,appid=%s)",
1723                            (int)mgr->resource, surfaceid, param1, appid);
1724                 ico_window_mgr_send_window_created(mgr->resource, surfaceid, param1, appid);
1725                 break;
1726
1727             case ICO_WINDOW_MGR_WINDOW_VISIBLE:
1728                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) VISIBLE"
1729                            "(surf=%08x,vis=%d,raise=%d,hint=%d)",
1730                            (int)mgr->resource, surfaceid, param1, param2, param3);
1731                 ico_window_mgr_send_window_visible(mgr->resource,
1732                                                    surfaceid, param1, param2, param3);
1733                 break;
1734
1735             case ICO_WINDOW_MGR_WINDOW_CONFIGURE:
1736                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) CONFIGURE"
1737                            "(surf=%08x,app=%s,layer=%d,x/y=%d/%d,w/h=%d/%d,hint=%d)",
1738                            (int)mgr->resource, surfaceid, appid,
1739                            param1, param2, param3, param4, param5, param6);
1740                 ico_window_mgr_send_window_configure(mgr->resource, surfaceid, appid,
1741                                                      param1, param2, param3, param4,
1742                                                      param5, param6);
1743                 break;
1744
1745             case ICO_WINDOW_MGR_WINDOW_DESTROYED:
1746                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) DESTROYED "
1747                            "surf=%08x", (int)mgr->resource, surfaceid);
1748                 ico_window_mgr_send_window_destroyed(mgr->resource, surfaceid);
1749                 break;
1750
1751             case ICO_WINDOW_MGR_WINDOW_ACTIVE:
1752                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) ACTIVE surf=%08x "
1753                            "active=%d", (int)mgr->resource, surfaceid, param1);
1754                 ico_window_mgr_send_window_active(mgr->resource, surfaceid,
1755                                                   (uint32_t)param1);
1756                 break;
1757
1758             default:
1759                 break;
1760             }
1761         }
1762     }
1763     return num_mgr;
1764 }
1765
1766 /*--------------------------------------------------------------------------*/
1767 /**
1768  * @brief   ico_win_mgr_hook_set_user: set hook function for set user
1769  *
1770  * @param[in]   hook_set_user   hook function
1771  * @return      none
1772  */
1773 /*--------------------------------------------------------------------------*/
1774 WL_EXPORT void
1775 ico_win_mgr_hook_set_user(void (*hook_set_user)(struct wl_client *client,
1776                                                 const char *appid))
1777 {
1778     uifw_trace("ico_win_mgr_hook_set_user: Hook %08x", (int)hook_set_user);
1779     win_mgr_hook_set_user = hook_set_user;
1780 }
1781
1782 /*--------------------------------------------------------------------------*/
1783 /**
1784  * @brief   ico_win_mgr_hook_create: set hook function for create surface
1785  *
1786  * @param[in]   hook_create     hook function
1787  * @return      none
1788  */
1789 /*--------------------------------------------------------------------------*/
1790 WL_EXPORT void
1791 ico_win_mgr_hook_create(void (*hook_create)(struct wl_client *client,
1792                                             struct weston_surface *surface,
1793                                             int surfaceId, const char *appid))
1794 {
1795     uifw_trace("ico_win_mgr_hook_create: Hook %08x", (int)hook_create);
1796     win_mgr_hook_create = hook_create;
1797 }
1798
1799 /*--------------------------------------------------------------------------*/
1800 /**
1801  * @brief   ico_win_mgr_hook_destroy: set hook function for destroy surface
1802  *
1803  * @param[in]   hook_destroy        hook function
1804  * @return      none
1805  */
1806 /*--------------------------------------------------------------------------*/
1807 WL_EXPORT void
1808 ico_win_mgr_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
1809 {
1810     uifw_trace("ico_win_mgr_hook_destroy: Hook %08x", (int)hook_destroy);
1811     win_mgr_hook_destroy = hook_destroy;
1812 }
1813
1814 /*--------------------------------------------------------------------------*/
1815 /**
1816  * @brief   ico_window_mgr_set_animation: set animation hook routine
1817  *
1818  * @param[in]   hook_animation  hook routine
1819  * @return      none
1820  */
1821 /*--------------------------------------------------------------------------*/
1822 WL_EXPORT void
1823 ico_window_mgr_set_animation(int (*hook_animation)(const int op, void *data))
1824 {
1825     win_mgr_hook_animation = hook_animation;
1826 }
1827
1828 /*--------------------------------------------------------------------------*/
1829 /**
1830  * @brief   module_init: initialize ico_window_mgr
1831  *                       this function called from ico_pluign_loader
1832  *
1833  * @param[in]   es          weston compositor
1834  * @return      result
1835  * @retval      0           sccess
1836  * @retval      -1          error
1837  */
1838 /*--------------------------------------------------------------------------*/
1839 WL_EXPORT int
1840 module_init(struct weston_compositor *ec)
1841 {
1842     int     nodeId;
1843
1844     uifw_info("ico_window_mgr: Enter(module_init)");
1845
1846     _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
1847     if (_ico_win_mgr == NULL)   {
1848         uifw_error("ico_window_mgr: malloc failed");
1849         return -1;
1850     }
1851
1852     memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
1853     _ico_win_mgr->surfaceid_map = (uint16_t *) malloc(INIT_SURFACE_IDS/8);
1854     if (! _ico_win_mgr->surfaceid_map)  {
1855         uifw_error("ico_window_mgr: malloc failed");
1856         return -1;
1857     }
1858     uifw_trace("ico_window_mgr: sh=%08x", (int)_ico_win_mgr);
1859     memset(_ico_win_mgr->surfaceid_map, 0, INIT_SURFACE_IDS/8);
1860
1861     _ico_win_mgr->compositor = ec;
1862
1863     _ico_win_mgr->surfaceid_max = INIT_SURFACE_IDS;
1864     _ico_win_mgr->surfaceid_count = INIT_SURFACE_IDS;
1865
1866     uifw_trace("ico_window_mgr: wl_display_add_global(bind_ico_win_mgr)");
1867     if (wl_display_add_global(ec->wl_display, &ico_window_mgr_interface,
1868                               _ico_win_mgr, bind_ico_win_mgr) == NULL)  {
1869         uifw_error("ico_window_mgr: Error(wl_display_add_global)");
1870         return -1;
1871     }
1872
1873     wl_list_init(&_ico_win_mgr->surface_list);
1874     wl_list_init(&_ico_win_mgr->client_list);
1875     wl_list_init(&_ico_win_mgr->manager_list);
1876     wl_list_init(&_ico_win_mgr->client_attr_list);
1877
1878     nodeId = ico_ivi_get_mynode();
1879     _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
1880     uifw_trace("ico_window_mgr: NoedId=%08x SurfaceIdBase=%08x",
1881                 nodeId, _ico_win_mgr->surface_head);
1882
1883     /* Regist usurf_2_node to ivi_common plugin     */
1884     ico_ivi_set_usurf_2_node(ico_winmgr_usurf_2_node);
1885
1886     /* Regist send_to_mgr to ivi_common plugin      */
1887     ico_ivi_set_send_to_mgr(ico_win_mgr_send_to_mgr);
1888     ico_ivi_set_send_surface_change(win_mgr_surface_change_mgr);
1889
1890     /* Hook to IVI-Shell                            */
1891     ivi_shell_hook_bind(bind_shell_client);
1892     ivi_shell_hook_unbind(unbind_shell_client);
1893     ivi_shell_hook_create(client_register_surface);
1894     ivi_shell_hook_destroy(win_mgr_surface_destroy);
1895     ivi_shell_hook_map(win_mgr_map_surface);
1896     ivi_shell_hook_change(win_mgr_surface_change);
1897     ivi_shell_hook_select(win_mgr_surface_select);
1898
1899     uifw_info("ico_window_mgr: Leave(module_init)");
1900
1901     return 0;
1902 }
1903