Change of the interface of the multi-input-manager plugin.
[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    Jul-26-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 <EGL/egl.h>
50 #include <GLES2/gl2.h>
51 #include <GLES2/gl2ext.h>
52
53 #include <weston/compositor.h>
54 #include "ico_ivi_common.h"
55 #include "ico_ivi_shell.h"
56 #include "ico_window_mgr.h"
57 #include "desktop-shell-server-protocol.h"
58 #include "ico_window_mgr-server-protocol.h"
59
60 /* SurfaceID                            */
61 #define INIT_SURFACE_IDS    1024            /* SurfaceId table initiale size        */
62 #define ADD_SURFACE_IDS     512             /* SurfaceId table additional size      */
63 #define SURCAFE_ID_MASK     0x0ffff         /* SurfaceId bit mask pattern           */
64 #define UIFW_HASH           64              /* Hash value (2's compliment)          */
65
66 /* Internal fixed value                 */
67 #define ICO_WINDOW_MGR_APPID_FIXCOUNT   5   /* retry count of appid fix             */
68                                             /* show/hide animation with position    */
69 #define ICO_WINDOW_MGR_ANIMATION_POS    0x10000000
70
71 /* wl_buffer (inport from wayland-1.2.0/src/wayland-server.h)                       */
72 struct uifw_wl_buffer   {       /* struct wl_buffer */
73     struct wl_resource resource;
74     int32_t width, height;
75     uint32_t busy_count;
76 };
77
78 /* wl_drm_buffer (inport from mesa-9.1.3/src/egl/wayland/wayland-drm/wayland-drm.h) */
79 struct uifw_drm_buffer {
80     struct uifw_wl_buffer buffer;
81     void *drm;                  /* struct wl_drm    */
82     uint32_t format;
83     const void *driver_format;
84     int32_t offset[3];
85     int32_t stride[3];
86     void *driver_buffer;
87 };
88
89 /* __DRIimage (inport from mesa-9.1.3/src/mesa/drivers/dri/intel/intel_regions.h)   */
90 struct uifw_intel_region  {     /* struct intel_region  */
91    void *bo;                /**< buffer manager's buffer */
92    uint32_t refcount;       /**< Reference count for region */
93    uint32_t cpp;            /**< bytes per pixel */
94    uint32_t width;          /**< in pixels */
95    uint32_t height;         /**< in pixels */
96    uint32_t pitch;          /**< in bytes */
97    char *map;               /**< only non-NULL when region is actually mapped */
98    uint32_t map_refcount;   /**< Reference count for mapping */
99    uint32_t tiling;         /**< Which tiling mode the region is in */
100    uint32_t name;           /**< Global name for the bo */
101    void *screen;            /* screen   */
102 };
103 struct uifw_dri_image   {       /* struct __DRIimageRec */
104    struct uifw_intel_region *region;
105    int internal_format;
106    uint32_t dri_format;
107    uint32_t format;
108    uint32_t offset;
109    uint32_t strides[3];
110    uint32_t offsets[3];
111    void *planar_format; /* intel_image_format */
112    void *data;
113 };
114
115 /* gl_surface_state (inport from weston-1.2.1/src/gl-renderer.c)    */
116 enum buffer_type {
117     BUFFER_TYPE_NULL,
118     BUFFER_TYPE_SHM,
119     BUFFER_TYPE_EGL
120 };
121 struct uifw_gl_surface_state {      /* struct gl_surface_state  */
122     GLfloat color[4];
123     struct gl_shader *shader;
124
125     GLuint textures[3];
126     int num_textures;
127     int needs_full_upload;
128     pixman_region32_t texture_damage;
129
130     void *images[3];            /* EGLImageKHR */
131     GLenum target;
132     int num_images;
133
134     struct weston_buffer_reference buffer_ref;
135     enum buffer_type buffer_type;
136     int pitch; /* in pixels */
137     int height; /* in pixels */
138 };
139
140 /* Multi Windiw Manager                 */
141 struct ico_win_mgr {
142     struct weston_compositor *compositor;   /* Weston compositor                    */
143     void    *shell;                         /* shell(ico_ivi_shell) table address   */
144     int32_t surface_head;                   /* (HostID << 24) | (DisplayNo << 16)   */
145
146     struct wl_list  client_list;            /* Clients                              */
147     struct wl_list  manager_list;           /* Manager(ex.HomeScreen) list          */
148     int             num_manager;            /* Number of managers                   */
149     struct wl_list  ivi_layer_list;         /* Layer management table list          */
150     struct wl_list  map_list;               /* surface map list                     */
151     struct uifw_surface_map *free_maptable; /* free maped surface table list        */
152     struct weston_animation map_animation[ICO_IVI_MAX_DISPLAY];
153                                             /* animation for map check              */
154     struct uifw_win_surface *active_pointer_usurf;  /* Active Pointer Surface       */
155     struct uifw_win_surface *active_keyboard_usurf; /* Active Keyboard Surface      */
156
157     struct uifw_win_surface *idhash[UIFW_HASH];  /* UIFW SerfaceID                  */
158     struct uifw_win_surface *wshash[UIFW_HASH];  /* Weston Surface                  */
159
160     uint32_t surfaceid_count;               /* Number of surface id                 */
161     uint32_t surfaceid_max;                 /* Maximum number of surface id         */
162     uint16_t *surfaceid_map;                /* SurfaceId assign bit map             */
163
164     char    shell_init;                     /* shell initialize flag                */
165     char    res;                            /* (unused)                             */
166 };
167
168 /* Internal macros                      */
169 /* UIFW SurfaceID                       */
170 #define MAKE_IDHASH(v)  (((uint32_t)v) & (UIFW_HASH-1))
171 /* Weston Surface                       */
172 #define MAKE_WSHASH(v)  ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
173
174 /* function prototype                   */
175                                             /* get surface table from weston surface*/
176 static struct uifw_win_surface *find_uifw_win_surface_by_ws(
177                     struct weston_surface *wsurf);
178                                             /* get client table from weston client  */
179 static struct uifw_client* find_client_from_client(struct wl_client *client);
180                                             /* assign new surface id                */
181 static uint32_t generate_id(void);
182                                             /* bind shell client                    */
183 static void win_mgr_bind_client(struct wl_client *client, void *shell);
184                                             /* unind shell client                   */
185 static void win_mgr_unbind_client(struct wl_client *client);
186                                             /* get appid from pid                   */
187 static void win_mgr_get_client_appid(struct uifw_client *uclient);
188                                             /* create new surface                   */
189 static void win_mgr_register_surface(
190                     struct wl_client *client, struct wl_resource *resource,
191                     struct weston_surface *surface, struct shell_surface *shsurf);
192                                             /* surface destroy                      */
193 static void win_mgr_destroy_surface(struct weston_surface *surface);
194                                             /* map new surface                      */
195 static void win_mgr_map_surface(struct weston_surface *surface, int32_t *width,
196                                 int32_t *height, int32_t *sx, int32_t *sy);
197                                             /* send surface change event to manager */
198 static void win_mgr_change_surface(struct weston_surface *surface,
199                                    const int to, const int manager);
200                                             /* window manager surface configure     */
201 static void win_mgr_surface_configure(struct uifw_win_surface *usurf,
202                                       int x, int y, int width, int height);
203                                             /* shell surface configure              */
204 static void win_mgr_shell_configure(struct weston_surface *surface);
205                                             /* surface select                       */
206 static void win_mgr_select_surface(struct weston_surface *surface);
207                                             /* surface set title                    */
208 static void win_mgr_set_title(struct weston_surface *surface, const char *title);
209                                             /* surface move request from shell      */
210 static void win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy);
211                                             /* set raise                            */
212 static void win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise);
213                                             /* surface change from manager          */
214 static int win_mgr_surface_change_mgr(struct weston_surface *surface, const int x,
215                                       const int y, const int width, const int height);
216                                             /* create new layer                     */
217 static struct uifw_win_layer *win_mgr_create_layer(struct uifw_win_surface *usurf,
218                                                    const uint32_t layer);
219                                             /* set surface layer                    */
220 static void win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer);
221                                             /* set active surface                   */
222 static void win_mgr_set_active(struct uifw_win_surface *usurf, const int target);
223
224                                             /* declare manager                      */
225 static void uifw_declare_manager(struct wl_client *client, struct wl_resource *resource,
226                                  int manager);
227                                             /* set window layer                     */
228 static void uifw_set_window_layer(struct wl_client *client,
229                                   struct wl_resource *resource,
230                                   uint32_t surfaceid, uint32_t layer);
231                                             /* set surface size and position        */
232 static void uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
233                                   uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
234                                   int32_t width, int32_t height, int32_t flags);
235                                             /* show/hide and raise/lower surface    */
236 static void uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
237                              uint32_t surfaceid, int32_t visible, int32_t raise,
238                              int32_t flag);
239                                             /* set surface animation                */
240 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
241                                uint32_t surfaceid, int32_t type,
242                                const char *animation, int32_t time);
243                                             /* set surface attributes               */
244 static void uifw_set_attributes(struct wl_client *client, struct wl_resource *resource,
245                                 uint32_t surfaceid, uint32_t attributes);
246                                             /* surface visibility control with animation*/
247 static void uifw_visible_animation(struct wl_client *client, struct wl_resource *resource,
248                                    uint32_t surfaceid, int32_t visible,
249                                    int32_t x, int32_t y, int32_t width, int32_t height);
250                                             /* set active surface (form HomeScreen) */
251 static void uifw_set_active(struct wl_client *client, struct wl_resource *resource,
252                             uint32_t surfaceid, int32_t active);
253                                             /* layer visibility control             */
254 static void uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
255                                    uint32_t layer, int32_t visible);
256                                             /* get application surfaces             */
257 static void uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource,
258                               const char *appid);
259                                             /* check and change all mapped surface  */
260 static void win_mgr_check_surfacemap(struct weston_animation *animation,
261                                      struct weston_output *output, uint32_t msecs);
262                                             /* check and change mapped surface      */
263 static void win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event);
264                                             /* map surface to system application    */
265 static void uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
266                              uint32_t surfaceid, int32_t framerate);
267                                             /* unmap surface                        */
268 static void uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
269                                uint32_t surfaceid);
270                                             /* bind manager                         */
271 static void bind_ico_win_mgr(struct wl_client *client,
272                              void *data, uint32_t version, uint32_t id);
273                                             /* unbind manager                       */
274 static void unbind_ico_win_mgr(struct wl_resource *resource);
275                                             /* send event to manager                */
276 static int ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
277                                    const int param1, const int param2, const int param3,
278                                    const int param4, const int param5);
279                                             /* set surface transform                */
280 static int win_mgr_set_scale(struct uifw_win_surface *usurf);
281                                             /* convert animation name to Id value   */
282 static int ico_get_animation_name(const char *animation);
283                                             /* hook for animation                   */
284 static int  (*win_mgr_hook_animation)(const int op, void *data) = NULL;
285
286 /* static tables                        */
287 /* Multi Window Manager interface       */
288 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
289     uifw_declare_manager,
290     uifw_set_window_layer,
291     uifw_set_positionsize,
292     uifw_set_visible,
293     uifw_set_animation,
294     uifw_set_attributes,
295     uifw_visible_animation,
296     uifw_set_active,
297     uifw_set_layer_visible,
298     uifw_get_surfaces,
299     uifw_map_surface,
300     uifw_unmap_surface
301 };
302
303 /* plugin common value(without ico_plugin_loader)   */
304 static int  _ico_ivi_debug_flag = 0;            /* Debug flags                      */
305 static int  _ico_ivi_debug_level = 3;           /* Debug Level                      */
306 static char *_ico_ivi_animation_name = NULL;    /* Default animation name           */
307 static int  _ico_ivi_animation_time = 500;      /* Default animation time           */
308 static int  _ico_ivi_animation_fps = 15;        /* Animation frame rate             */
309 static int  _ico_ivi_background_layer = 0;      /* Background layer                 */
310 static int  _ico_ivi_default_layer = 1;         /* Deafult layer id at surface create*/
311 static int  _ico_ivi_input_layer = 101;         /* Input layer id                   */
312 static int  _ico_ivi_cursor_layer = 102;        /* Cursor layer id                  */
313 static int  _ico_ivi_startup_layer = 109;       /* Deafult layer id at system startup*/
314
315 /* static management table              */
316 static struct ico_win_mgr       *_ico_win_mgr = NULL;
317 static int                      _ico_num_nodes = 0;
318 static struct uifw_node_table   _ico_node_table[ICO_IVI_MAX_DISPLAY];
319
320
321 /*--------------------------------------------------------------------------*/
322 /**
323  * @brief   ico_ivi_debugflag: get debug flags
324  *
325  * @param       None
326  * @return      debug flags
327  */
328 /*--------------------------------------------------------------------------*/
329 WL_EXPORT   int
330 ico_ivi_debugflag(void)
331 {
332     return _ico_ivi_debug_flag;
333 }
334
335 /*--------------------------------------------------------------------------*/
336 /**
337  * @brief   ico_ivi_debuglevel: answer debug output level.
338  *
339  * @param       none
340  * @return      debug output level
341  * @retval      0       No debug output
342  * @retval      1       Only error output
343  * @retval      2       Error and Warning output
344  * @retval      3       Error, Warning and information output
345  * @retval      4       All output with debug write
346  */
347 /*--------------------------------------------------------------------------*/
348 WL_EXPORT   int
349 ico_ivi_debuglevel(void)
350 {
351     return _ico_ivi_debug_level;
352 }
353
354 /*--------------------------------------------------------------------------*/
355 /**
356  * @brief   ico_ivi_default_animation_name: get default animation name
357  *
358  * @param       None
359  * @return      Default animation name
360  */
361 /*--------------------------------------------------------------------------*/
362 WL_EXPORT   const char *
363 ico_ivi_default_animation_name(void)
364 {
365     return _ico_ivi_animation_name;
366 }
367
368 /*--------------------------------------------------------------------------*/
369 /**
370  * @brief   ico_ivi_default_animation_time: get default animation time
371  *
372  * @param       None
373  * @return      Default animation time(miri sec)
374  */
375 /*--------------------------------------------------------------------------*/
376 WL_EXPORT   int
377 ico_ivi_default_animation_time(void)
378 {
379     return _ico_ivi_animation_time;
380 }
381
382 /*--------------------------------------------------------------------------*/
383 /**
384  * @brief   ico_ivi_default_animation_fps: get default animation frame rate
385  *
386  * @param       None
387  * @return      Default animation frame rate(frames/sec)
388  */
389 /*--------------------------------------------------------------------------*/
390 WL_EXPORT   int
391 ico_ivi_default_animation_fps(void)
392 {
393     return _ico_ivi_animation_fps;
394 }
395
396 /*--------------------------------------------------------------------------*/
397 /**
398  * @brief   ico_ivi_get_mynode: Get my NodeId
399  *
400  * @param       None
401  * @return      NodeId of my node
402  */
403 /*--------------------------------------------------------------------------*/
404 WL_EXPORT   int
405 ico_ivi_get_mynode(void)
406 {
407     /* Reference Platform 0.90 only support 1 ECU   */
408     return 0;
409 }
410
411 /*--------------------------------------------------------------------------*/
412 /**
413  * @brief   ico_window_mgr_set_weston_surface: set weston surface
414  *
415  * @param[in]   usurf       UIFW surface
416  * @param[in]   x           X coordinate on screen
417  * @param[in]   y           Y coordinate on screen
418  * @param[in]   width       width
419  * @param[in]   height      height
420  * @return      none
421  */
422 /*--------------------------------------------------------------------------*/
423 WL_EXPORT   void
424 ico_window_mgr_set_weston_surface(struct uifw_win_surface *usurf,
425                                   int x, int y, int width, int height)
426 {
427     struct weston_surface *es = usurf->surface;
428     int     buf_width, buf_height;
429
430     if (es == NULL) {
431         uifw_trace("ico_window_mgr_set_weston_surface: usurf(%08x) has no surface",
432                    (int)usurf);
433         return;
434     }
435
436     if (es->buffer_ref.buffer != NULL)   {
437         buf_width = weston_surface_buffer_width(es);
438         buf_height = weston_surface_buffer_height(es);
439         if ((width <= 0) || (height <= 0))    {
440             width = buf_width;
441             usurf->width = buf_width;
442             height = buf_height;
443             usurf->height = buf_height;
444         }
445         if (usurf->width > buf_width)   {
446             width = buf_width;
447             x += (usurf->width - buf_width)/2;
448         }
449         if (usurf->height > buf_height) {
450             height = buf_height;
451             y += (usurf->height - buf_height)/2;
452         }
453         if (usurf->visible) {
454             x += usurf->node_tbl->disp_x;
455             y += usurf->node_tbl->disp_y;
456         }
457         else    {
458             x = ICO_IVI_MAX_COORDINATE+1;
459             y = ICO_IVI_MAX_COORDINATE+1;
460         }
461         if ((es->geometry.x != x) || (es->geometry.y != y) ||
462             (es->geometry.width != width) || (es->geometry.height != height))    {
463             weston_surface_damage_below(es);
464             win_mgr_surface_configure(usurf, x, y, width, height);
465         }
466         weston_surface_damage(es);
467         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
468     }
469 }
470
471 /*--------------------------------------------------------------------------*/
472 /**
473  * @brief   ico_window_mgr_set_weston_surface: set weston surface
474  *
475  * @param[in]   usurf       UIFW surface
476  * @param[in]   x           X coordinate on screen
477  * @param[in]   y           Y coordinate on screen
478  * @param[in]   width       width
479  * @param[in]   height      height
480  * @return      none
481  */
482 /*--------------------------------------------------------------------------*/
483 WL_EXPORT   void
484 ico_window_mgr_change_surface(struct uifw_win_surface *usurf,
485                               const int to, const int manager)
486 {
487     uifw_trace("ico_window_mgr_change_surface: Enter(%08x,%d,%d)",
488                usurf->surfaceid, to, manager);
489     win_mgr_change_surface(usurf->surface, to, manager);
490     uifw_trace("ico_window_mgr_change_surface: Leave");
491 }
492
493 /*--------------------------------------------------------------------------*/
494 /**
495  * @brief   ico_window_mgr_get_usurf: find UIFW surface by surface id
496  *
497  * @param[in]   surfaceid   UIFW surface id
498  * @return      UIFW surface table address
499  * @retval      !=NULL      success(surface table address)
500  * @retval      NULL        error(surface id dose not exist)
501  */
502 /*--------------------------------------------------------------------------*/
503 WL_EXPORT   struct uifw_win_surface *
504 ico_window_mgr_get_usurf(const uint32_t surfaceid)
505 {
506     struct uifw_win_surface *usurf;
507
508     usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
509
510     while (usurf)   {
511         if (usurf->surfaceid == surfaceid) {
512             return usurf;
513         }
514         usurf = usurf->next_idhash;
515     }
516     uifw_trace("ico_window_mgr_get_usurf: NULL");
517     return NULL;
518 }
519
520 /*--------------------------------------------------------------------------*/
521 /**
522  * @brief   ico_window_mgr_get_usurf_client: find UIFW surface by surface id/or client
523  *
524  * @param[in]   surfaceid   UIFW surface id
525  * @param[in]   client      Wayland client
526  * @return      UIFW surface table address
527  * @retval      !=NULL      success(surface table address)
528  * @retval      NULL        error(surface id or client dose not exist)
529  */
530 /*--------------------------------------------------------------------------*/
531 WL_EXPORT   struct uifw_win_surface *
532 ico_window_mgr_get_usurf_client(const uint32_t surfaceid, struct wl_client *client)
533 {
534     struct uifw_win_surface *usurf;
535     struct uifw_client *uclient;
536
537     if (surfaceid == ICO_WINDOW_MGR_V_MAINSURFACE) {
538         uclient = find_client_from_client(client);
539         if (uclient)    {
540             if (&uclient->surface_link != uclient->surface_link.next)   {
541                 usurf = container_of(uclient->surface_link.next,
542                                      struct uifw_win_surface, client_link);
543             }
544             else    {
545                 usurf = NULL;
546             }
547         }
548         else    {
549             usurf = NULL;
550         }
551     }
552     else    {
553         usurf = ico_window_mgr_get_usurf(surfaceid);
554     }
555     return usurf;
556 }
557
558 /*--------------------------------------------------------------------------*/
559 /**
560  * @brief   find_uifw_win_surface_by_ws: find UIFW surface by weston surface
561  *
562  * @param[in]   wsurf       Weston surface
563  * @return      UIFW surface table address
564  * @retval      !=NULL      success(surface table address)
565  * @retval      NULL        error(surface dose not exist)
566  */
567 /*--------------------------------------------------------------------------*/
568 static struct uifw_win_surface *
569 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
570 {
571     struct uifw_win_surface *usurf;
572
573     usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
574
575     while (usurf)   {
576         if (usurf->surface == wsurf) {
577             return usurf;
578         }
579         usurf = usurf->next_wshash;
580     }
581     uifw_trace("find_uifw_win_surface_by_ws: NULL");
582     return NULL;
583 }
584
585 /*--------------------------------------------------------------------------*/
586 /**
587  * @brief   find_client_from_client: find UIFW client by wayland client
588  *
589  * @param[in]   client      Wayland client
590  * @return      UIFW client table address
591  * @retval      !=NULL      success(client table address)
592  * @retval      NULL        error(client dose not exist)
593  */
594 /*--------------------------------------------------------------------------*/
595 static struct uifw_client*
596 find_client_from_client(struct wl_client *client)
597 {
598     struct uifw_client  *uclient;
599
600     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
601         if (uclient->client == client)  {
602             return(uclient);
603         }
604     }
605     uifw_trace("find_client_from_client: client.%08x is NULL", (int)client);
606     return NULL;
607 }
608
609 /*--------------------------------------------------------------------------*/
610 /**
611  * @brief   ico_window_mgr_get_appid: find application id by wayland client
612  *
613  * @param[in]   client      Wayland client
614  * @return      application id
615  * @retval      !=NULL      success(application id)
616  * @retval      NULL        error(client dose not exist)
617  */
618 /*--------------------------------------------------------------------------*/
619 WL_EXPORT   char *
620 ico_window_mgr_get_appid(struct wl_client* client)
621 {
622     struct uifw_client  *uclient;
623
624     uclient = find_client_from_client(client);
625
626     if (! uclient)  {
627         return NULL;
628     }
629     return uclient->appid;
630 }
631
632 /*--------------------------------------------------------------------------*/
633 /**
634  * @brief   ico_window_mgr_get_display_coordinate: get display coordinate
635  *
636  * @param[in]   displayno   display number
637  * @param[out]  x           relative X coordinate
638  * @param[out]  y           relative Y coordinate
639  * @return      none
640  */
641 /*--------------------------------------------------------------------------*/
642 WL_EXPORT   void
643 ico_window_mgr_get_display_coordinate(int displayno, int *x, int *y)
644 {
645     if ((displayno <= _ico_num_nodes) || (displayno < 0))   {
646         displayno = 0;
647     }
648     *x = _ico_node_table[displayno].disp_x;
649     *y = _ico_node_table[displayno].disp_y;
650 }
651
652 /*--------------------------------------------------------------------------*/
653 /**
654  * @brief   generate_id: generate uniq id for UIFW surface id
655  *
656  * @param       none
657  * @return      uniq id for UIFW surface id
658  */
659 /*--------------------------------------------------------------------------*/
660 static uint32_t
661 generate_id(void)
662 {
663     int     rep;
664     int     i;
665     int     map;
666     uint16_t *new_map;
667     uint32_t surfaceId;
668
669     /* next assign id                           */
670     _ico_win_mgr->surfaceid_count ++;
671
672     /* serach free id from bitmap               */
673     for (rep = 0; rep < (int)(_ico_win_mgr->surfaceid_max/16); rep++)   {
674         if (_ico_win_mgr->surfaceid_count >= _ico_win_mgr->surfaceid_max)   {
675             _ico_win_mgr->surfaceid_count = 0;
676         }
677         if (_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] != 0xffff)    {
678             /* find free id from bitmap         */
679             map = 1 << (_ico_win_mgr->surfaceid_count % 16);
680             for (i = (_ico_win_mgr->surfaceid_count % 16); i < 16; i++) {
681                 if ((_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] & map)
682                         == 0) {
683                     _ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] |= map;
684                     _ico_win_mgr->surfaceid_count
685                         = (_ico_win_mgr->surfaceid_count/16)*16 + i;
686
687                     surfaceId = (_ico_win_mgr->surfaceid_count + 1)
688                                 | _ico_win_mgr->surface_head;
689                     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
690                     return(surfaceId);
691                 }
692                 map = map << 1;
693             }
694         }
695         _ico_win_mgr->surfaceid_count += 16;
696     }
697
698     /* no free id in bitmap, extend bitmap      */
699     if ((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) > SURCAFE_ID_MASK)  {
700         /* too many surfaces, system error      */
701         uifw_trace("generate_id: SurffaceId Overflow(%d, Max=%d), Abort",
702                    _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
703         fprintf(stderr, "generate_id: SurffaceId Overflow(%d, Max=%d), Abort\n",
704                 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
705         abort();
706     }
707
708     new_map = (uint16_t *) malloc((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) / 8);
709     memcpy(new_map, _ico_win_mgr->surfaceid_map, _ico_win_mgr->surfaceid_max/8);
710     memset(&new_map[_ico_win_mgr->surfaceid_max/16], 0, ADD_SURFACE_IDS/8);
711     _ico_win_mgr->surfaceid_count = _ico_win_mgr->surfaceid_max;
712     new_map[_ico_win_mgr->surfaceid_count/16] |= 1;
713     _ico_win_mgr->surfaceid_max += ADD_SURFACE_IDS;
714     free(_ico_win_mgr->surfaceid_map);
715     _ico_win_mgr->surfaceid_map = new_map;
716
717     uifw_trace("generate_id: Extent SurfaceId=%d(Max.%d)",
718                _ico_win_mgr->surfaceid_count+1, _ico_win_mgr->surfaceid_max);
719     surfaceId = (_ico_win_mgr->surfaceid_count + 1) | _ico_win_mgr->surface_head;
720
721     uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
722     return(surfaceId);
723 }
724
725 /*--------------------------------------------------------------------------*/
726 /**
727  * @brief   win_mgr_bind_client: desktop_shell from client
728  *
729  * @param[in]   client          Wayland client
730  * @param[in]   shell           shell(ico_ivi_shell) table address
731  * @return      none
732  */
733 /*--------------------------------------------------------------------------*/
734 static void
735 win_mgr_bind_client(struct wl_client *client, void *shell)
736 {
737     struct uifw_client  *uclient;
738     int     newclient;
739     pid_t   pid;
740     uid_t   uid;
741     gid_t   gid;
742
743     uifw_trace("win_mgr_bind_client: Enter(client=%08x, shell=%08x)",
744                (int)client, (int)shell);
745
746     /* save shell table address             */
747     if (shell)  {
748         _ico_win_mgr->shell = shell;
749     }
750
751     /* set client                           */
752     uclient = find_client_from_client(client);
753     if (! uclient)  {
754         /* client not exist, create client management table             */
755         uifw_trace("win_mgr_bind_client: Create Client");
756         uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
757         if (!uclient)   {
758             uifw_error("win_mgr_bind_client: Error, No Memory");
759             return;
760         }
761         memset(uclient, 0, sizeof(struct uifw_client));
762         uclient->client = client;
763         wl_list_init(&uclient->surface_link);
764         newclient = 1;
765     }
766     else    {
767         newclient = 0;
768     }
769     wl_client_get_credentials(client, &pid, &uid, &gid);
770     uifw_trace("win_mgr_bind_client: client=%08x pid=%d uid=%d gid=%d",
771                (int)client, (int)pid, (int)uid, (int)gid);
772     if (pid > 0)    {
773         uclient->pid = (int)pid;
774         /* get applicationId from AppCore(AUL)  */
775         win_mgr_get_client_appid(uclient);
776
777         /* weston internal client, not manage   */
778         if (strcmp(uclient->appid, "weston") == 0)  {
779             free(uclient);
780             uifw_trace("win_mgr_bind_client: client=%08x is internal, delete", (int)client);
781         }
782         else if (newclient > 0)  {
783             wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
784         }
785     }
786     else    {
787         uifw_trace("win_mgr_bind_client: client=%08x pid dose not exist", (int)client);
788     }
789     uifw_trace("win_mgr_bind_client: Leave");
790 }
791
792 /*--------------------------------------------------------------------------*/
793 /**
794  * @brief   win_mgr_unbind_client: unbind desktop_shell from client
795  *
796  * @param[in]   client          Wayland client
797  * @return      none
798  */
799 /*--------------------------------------------------------------------------*/
800 static void
801 win_mgr_unbind_client(struct wl_client *client)
802 {
803     struct uifw_client  *uclient;
804
805     uifw_trace("win_mgr_unbind_client: Enter(client=%08x)", (int)client);
806
807     uclient = find_client_from_client(client);
808     if (uclient)    {
809         /* Client exist, Destory client management table             */
810         wl_list_remove(&uclient->link);
811         free(uclient);
812     }
813     uifw_trace("win_mgr_unbind_client: Leave");
814 }
815
816 /*--------------------------------------------------------------------------*/
817 /**
818  * @brief   win_mgr_get_client_appid: get applicationId from pid
819  *
820  * @param[in]   uclient     UIFW client management table
821  * @return      none
822  */
823 /*--------------------------------------------------------------------------*/
824 static void
825 win_mgr_get_client_appid(struct uifw_client *uclient)
826 {
827     int     fd;
828     int     size;
829     int     i;
830     int     j;
831     char    procpath[128];
832
833     memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
834     i = aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH);
835     uifw_trace("win_mgr_get_client_appid: aul_app_get_appid_bypid ret=%d "
836                "pid=%d appid=<%s>", i, uclient->pid, uclient->appid);
837     if (uclient->appid[0] != 0) {
838         /* OK, end of get appid         */
839         uclient->fixed_appid = ICO_WINDOW_MGR_APPID_FIXCOUNT;
840     }
841     else    {
842         /* client dose not exist in AppCore, search Linux process table */
843         uclient->fixed_appid ++;
844         memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
845         snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
846         fd = open(procpath, O_RDONLY);
847         if (fd >= 0)    {
848             size = read(fd, procpath, sizeof(procpath));
849             for (; size > 0; size--)    {
850                 if (procpath[size-1])   break;
851             }
852             if (size > 0)   {
853                 /* get program base name    */
854                 i = 0;
855                 for (j = 0; j < size; j++)  {
856                     if (procpath[j] == 0)   break;
857                     if (procpath[j] == '/') i = j + 1;
858                 }
859                 j = 0;
860                 for (; i < size; i++)   {
861                     uclient->appid[j] = procpath[i];
862                     if ((uclient->appid[j] == 0) ||
863                         (j >= (ICO_IVI_APPID_LENGTH-1)))    break;
864                     j++;
865                 }
866                 /* search application number in apprication start option    */
867                 if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
868                     for (; i < size; i++)   {
869                         if ((procpath[i] == 0) &&
870                             (procpath[i+1] == '@')) {
871                             strncpy(&uclient->appid[j], &procpath[i+1],
872                                     ICO_IVI_APPID_LENGTH - j - 2);
873                         }
874                     }
875                 }
876             }
877             close(fd);
878         }
879         for (i = strlen(uclient->appid)-1; i >= 0; i--) {
880             if (uclient->appid[i] != ' ')   break;
881         }
882         uclient->appid[i+1] = 0;
883         if (uclient->appid[0])  {
884             uifw_trace("win_mgr_get_client_appid: pid=%d appid=<%s> from "
885                        "Process table", uclient->pid, uclient->appid);
886         }
887         else    {
888             uifw_trace("win_mgr_get_client_appid: pid=%d dose not exist in Process table",
889                        uclient->pid);
890             sprintf(uclient->appid, "?%d?", uclient->pid);
891         }
892     }
893 }
894
895 /*--------------------------------------------------------------------------*/
896 /**
897  * @brief   ico_get_animation_name: convert animation name to Id value
898  *
899  * @param[in]   animation       animation name
900  * @return      animation Id value
901  */
902 /*--------------------------------------------------------------------------*/
903 static int
904 ico_get_animation_name(const char *animation)
905 {
906     int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
907
908     if (strcasecmp(animation, "none") == 0) {
909         return ICO_WINDOW_MGR_ANIMATION_NONE;
910     }
911
912     if (win_mgr_hook_animation) {
913         anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_NAME, (void *)animation);
914     }
915     if (anima <= 0) {
916         anima = ICO_WINDOW_MGR_ANIMATION_NONE;
917     }
918     return anima;
919 }
920
921 /*--------------------------------------------------------------------------*/
922 /**
923  * @brief   win_mgr_register_surface: create UIFW surface
924  *
925  * @param[in]   client          Wayland client
926  * @param[in]   resource        client resource
927  * @param[in]   surface         Weston surface
928  * @param[in]   shsurf          shell surface
929  * @return      none
930  */
931 /*--------------------------------------------------------------------------*/
932 static void
933 win_mgr_register_surface(struct wl_client *client, struct wl_resource *resource,
934                          struct weston_surface *surface, struct shell_surface *shsurf)
935 {
936     struct uifw_win_surface *usurf;
937     struct uifw_win_surface *phash;
938     struct uifw_win_surface *bhash;
939     uint32_t    hash;
940
941     uifw_trace("win_mgr_register_surface: Enter(surf=%08x,client=%08x,res=%08x)",
942                (int)surface, (int)client, (int)resource);
943
944     /* check new surface                    */
945     if (find_uifw_win_surface_by_ws(surface))   {
946         /* surface exist, NOP               */
947         uifw_trace("win_mgr_register_surface: Leave(Already Exist)");
948         return;
949     }
950
951     /* set default color and shader */
952     weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
953
954     /* create UIFW surface management table */
955     usurf = malloc(sizeof(struct uifw_win_surface));
956     if (! usurf)    {
957         uifw_error("win_mgr_register_surface: No Memory");
958         return;
959     }
960
961     memset(usurf, 0, sizeof(struct uifw_win_surface));
962
963     usurf->surfaceid = generate_id();
964     usurf->surface = surface;
965     usurf->shsurf = shsurf;
966     usurf->node_tbl = &_ico_node_table[0];  /* set default node table (display no=0)    */
967     wl_list_init(&usurf->ivi_layer);
968     wl_list_init(&usurf->client_link);
969     wl_list_init(&usurf->animation.animation.link);
970     wl_list_init(&usurf->surf_map);
971     usurf->animation.hide_anima = ico_get_animation_name(ico_ivi_default_animation_name());
972     usurf->animation.hide_time = ico_ivi_default_animation_time();;
973     usurf->animation.show_anima = usurf->animation.hide_anima;
974     usurf->animation.show_time = usurf->animation.hide_time;
975     usurf->animation.move_anima = usurf->animation.hide_anima;
976     usurf->animation.move_time = usurf->animation.hide_time;
977     usurf->animation.resize_anima = usurf->animation.hide_anima;
978     usurf->animation.resize_time = usurf->animation.hide_time;
979
980     if ((_ico_win_mgr->num_manager <= 0) ||
981         (ico_ivi_debugflag() & ICO_IVI_DEBUG_SHOW_SURFACE)) {
982         uifw_trace("win_mgr_register_surface: No Manager, Force visible");
983         usurf->visible = 1;
984     }
985     else    {
986         uifw_trace("win_mgr_register_surface: Manager exist, Not visible");
987         usurf->visible = 0;
988     }
989
990     /* set client                           */
991     usurf->uclient = find_client_from_client(client);
992     if (! usurf->uclient)  {
993         /* client not exist, create client management table */
994         uifw_trace("win_mgr_register_surface: Create Client");
995         win_mgr_bind_client(client, NULL);
996         usurf->uclient = find_client_from_client(client);
997         if (! usurf->uclient)  {
998             uifw_error("win_mgr_register_surface: No Memory");
999             return;
1000         }
1001     }
1002     wl_list_insert(usurf->uclient->surface_link.prev, &usurf->client_link);
1003
1004     /* make surface id hash table       */
1005     hash = MAKE_IDHASH(usurf->surfaceid);
1006     phash = _ico_win_mgr->idhash[hash];
1007     bhash = NULL;
1008     while (phash)   {
1009         bhash = phash;
1010         phash = phash->next_idhash;
1011     }
1012     if (bhash)  {
1013         bhash->next_idhash = usurf;
1014     }
1015     else    {
1016         _ico_win_mgr->idhash[hash] = usurf;
1017     }
1018
1019     /* make weston surface hash table   */
1020     hash = MAKE_WSHASH(usurf->surface);
1021     phash = _ico_win_mgr->wshash[hash];
1022     bhash = NULL;
1023     while (phash)   {
1024         bhash = phash;
1025         phash = phash->next_wshash;
1026     }
1027     if (bhash)  {
1028         bhash->next_wshash = usurf;
1029     }
1030     else    {
1031         _ico_win_mgr->wshash[hash] = usurf;
1032     }
1033     /* set default layer id             */
1034     win_mgr_set_layer(usurf, (_ico_win_mgr->num_manager > 0) ? _ico_ivi_default_layer :
1035                                                                _ico_ivi_startup_layer);
1036     uifw_trace("win_mgr_register_surface: Leave(surfaceId=%08x)", usurf->surfaceid);
1037 }
1038
1039 /*--------------------------------------------------------------------------*/
1040 /**
1041  * @brief   win_mgr_map_surface: map surface
1042  *
1043  * @param[in]   surface         Weston surface
1044  * @param[in]   width           surface width
1045  * @param[in]   height          surface height
1046  * @param[in]   sx              X coordinate on screen
1047  * @param[in]   sy              Y coordinate on screen
1048  * @return      none
1049  */
1050 /*--------------------------------------------------------------------------*/
1051 static void
1052 win_mgr_map_surface(struct weston_surface *surface, int32_t *width, int32_t *height,
1053                     int32_t *sx, int32_t *sy)
1054 {
1055     struct uifw_win_surface *usurf;
1056
1057     uifw_trace("win_mgr_map_surface: Enter(%08x, x/y=%d/%d w/h=%d/%d)",
1058                (int)surface, *sx, *sy, *width, *height);
1059
1060     usurf = find_uifw_win_surface_by_ws(surface);
1061
1062     if (usurf) {
1063         uifw_trace("win_mgr_map_surface: surf=%08x w/h=%d/%d vis=%d",
1064                    usurf->surfaceid, usurf->width, usurf->height, usurf->visible);
1065         if ((usurf->width > 0) && (usurf->height > 0)) {
1066             uifw_trace("win_mgr_map_surface: HomeScreen registed, PositionSize"
1067                        "(surf=%08x x/y=%d/%d w/h=%d/%d vis=%d",
1068                        usurf->surfaceid, usurf->x, usurf->y, usurf->width, usurf->height,
1069                        usurf->visible);
1070             *width = usurf->width;
1071             *height = usurf->height;
1072             win_mgr_surface_configure(usurf, usurf->node_tbl->disp_x + usurf->x,
1073                                       usurf->node_tbl->disp_y + usurf->y,
1074                                       usurf->width, usurf->height);
1075         }
1076         else    {
1077             uifw_trace("win_mgr_map_surface: HomeScreen not regist Surface, "
1078                        "Change PositionSize(surf=%08x x/y=%d/%d w/h=%d/%d)",
1079                        usurf->surfaceid, *sx, *sy, *width, *height);
1080             usurf->width = *width;
1081             usurf->height = *height;
1082             usurf->x = *sx;
1083             usurf->y = *sy;
1084             if (usurf->x < 0)   usurf->x = 0;
1085             if (usurf->y < 0)   usurf->y = 0;
1086
1087             if (_ico_win_mgr->num_manager > 0)  {
1088                 /* HomeScreen exist, coodinate set by HomeScreen                */
1089                 if (usurf->visible) {
1090                     win_mgr_surface_configure(usurf, usurf->node_tbl->disp_x + usurf->x,
1091                                               usurf->node_tbl->disp_y + usurf->y,
1092                                               usurf->width, usurf->height);
1093                 }
1094                 else    {
1095                     win_mgr_surface_configure(usurf, ICO_IVI_MAX_COORDINATE+1,
1096                                               ICO_IVI_MAX_COORDINATE+1,
1097                                               usurf->width, usurf->height);
1098                 }
1099                 uifw_trace("win_mgr_map_surface: Change size/position x/y=%d/%d w/h=%d/%d",
1100                            (int)surface->geometry.x, (int)surface->geometry.y,
1101                            surface->geometry.width, surface->geometry.height);
1102             }
1103             if ((_ico_win_mgr->num_manager <= 0) ||
1104                 (ico_ivi_debugflag() & ICO_IVI_DEBUG_SHOW_SURFACE)) {
1105                 uifw_trace("win_mgr_map_surface: Np HomeScreen, chaneg to Visible");
1106                 ico_window_mgr_set_visible(usurf, 1);
1107             }
1108         }
1109         usurf->mapped = 1;
1110         if (usurf->visible) {
1111             ico_window_mgr_restack_layer(NULL, FALSE);
1112         }
1113         uifw_trace("win_mgr_map_surface: Leave");
1114     }
1115     else    {
1116         uifw_trace("win_mgr_map_surface: Leave(No UIFW Surface)");
1117     }
1118 }
1119
1120 /*--------------------------------------------------------------------------*/
1121 /**
1122  * @brief   ico_window_mgr_restack_layer: restack surface list
1123  *
1124  * @param[in]   usurf           UIFW surface (if NULL, no surface)
1125  * @param[in]   omit_touch      omit touch layer flag (TRUE=omit/FALSE=not omit)
1126  * @return      none
1127  */
1128 /*--------------------------------------------------------------------------*/
1129 WL_EXPORT   void
1130 ico_window_mgr_restack_layer(struct uifw_win_surface *usurf, const int omit_touch)
1131 {
1132     struct uifw_win_surface  *eu;
1133     struct uifw_win_layer *el;
1134     int32_t buf_width, buf_height;
1135     float   new_x, new_y;
1136     struct weston_layer *wlayer;
1137     struct weston_surface  *surface, *surfacetmp;
1138     int     num_visible = 0;
1139     int     layer_type;
1140
1141     /* set layer type                   */
1142     ico_ivi_shell_set_layertype();
1143
1144     /* make compositor surface list     */
1145     wlayer = ico_ivi_shell_weston_layer();
1146
1147     uifw_trace("ico_window_mgr_restack_layer: Enter(surf=%08x,omit=%d) layer=%08x",
1148                (int)usurf, omit_touch, (int)wlayer);
1149
1150     /* remove all surfaces in panel_layer   */
1151     wl_list_for_each_safe(surface, surfacetmp, &wlayer->surface_list, layer_link)   {
1152         wl_list_remove(&surface->layer_link);
1153         wl_list_init(&surface->layer_link);
1154     }
1155     wl_list_init(&wlayer->surface_list);
1156
1157     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link)  {
1158         if (el->layer_type == ICO_WINDOW_MGR_LAYER_TYPE_CURSOR) continue;
1159         wl_list_for_each (eu, &el->surface_list, ivi_layer) {
1160             if (eu->surface == NULL)    continue;
1161
1162             /* target only panel or unknown layer   */
1163             layer_type = ico_ivi_shell_layertype(eu->surface);
1164             if ((layer_type != LAYER_TYPE_PANEL) && (layer_type != LAYER_TYPE_UNKNOWN)) {
1165                 continue;
1166             }
1167             wl_list_remove(&eu->surface->layer_link);
1168             wl_list_init(&eu->surface->layer_link);
1169
1170             if (eu->mapped != 0)    {
1171                 if ((el->visible == FALSE) || (eu->visible == FALSE) ||
1172                     ((omit_touch != FALSE) &&
1173                      (el->layer_type == ICO_WINDOW_MGR_LAYER_TYPE_INPUT)))  {
1174                     new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1175                     new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1176                 }
1177                 else if (eu->surface->buffer_ref.buffer)    {
1178                     buf_width = weston_surface_buffer_width(eu->surface);
1179                     buf_height = weston_surface_buffer_height(eu->surface);
1180                     if (eu->width > buf_width) {
1181                         new_x = (float)(eu->x +
1182                                 (eu->width - eu->surface->geometry.width)/2);
1183                     }
1184                     else    {
1185                         new_x = (float)eu->x;
1186                     }
1187                     if (eu->height > buf_height)    {
1188                         new_y = (float) (eu->y +
1189                                 (eu->height - eu->surface->geometry.height)/2);
1190                     }
1191                     else    {
1192                         new_y = (float)eu->y;
1193                     }
1194                     new_x += eu->node_tbl->disp_x + eu->xadd;
1195                     new_y += eu->node_tbl->disp_y + eu->yadd;
1196                     num_visible ++;
1197                 }
1198                 else    {
1199                     new_x = (float)(eu->x + eu->node_tbl->disp_x + eu->xadd);
1200                     new_y = (float)(eu->y + eu->node_tbl->disp_y + eu->yadd);
1201                 }
1202                 wl_list_insert(wlayer->surface_list.prev, &eu->surface->layer_link);
1203                 if ((eu->restrain_configure == 0) &&
1204                     ((new_x != eu->surface->geometry.x) ||
1205                      (new_y != eu->surface->geometry.y)))   {
1206                     weston_surface_damage_below(eu->surface);
1207                     weston_surface_set_position(eu->surface, (float)new_x, (float)new_y);
1208                     weston_surface_damage(eu->surface);
1209                 }
1210 #if 0           /* too many debug log   */
1211                 uifw_trace("ico_window_mgr_restack_layer:%3d(%d).%08x(%08x:%d) "
1212                            "x/y=%d/%d w/h=%d/%d",
1213                            el->layer, el->visible, eu->surfaceid, (int)eu->surface,
1214                            eu->visible, (int)eu->surface->geometry.x,
1215                            (int)eu->surface->geometry.y, eu->surface->geometry.width,
1216                            eu->surface->geometry.height);
1217 #endif
1218             }
1219         }
1220     }
1221
1222     /* damage(redraw) target surfacem if target exist   */
1223     if (usurf) {
1224         weston_surface_damage(usurf->surface);
1225     }
1226
1227     /* composit and draw screen(plane)  */
1228     if (omit_touch == FALSE)    {
1229         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1230
1231         if ((_ico_win_mgr->shell_init == 0) && (num_visible > 0) &&
1232             (_ico_win_mgr->shell != NULL) && (_ico_win_mgr->num_manager > 0))   {
1233             /* start shell fade         */
1234             _ico_win_mgr->shell_init = 1;
1235             ico_ivi_shell_startup(_ico_win_mgr->shell);
1236         }
1237     }
1238     uifw_trace("ico_window_mgr_restack_layer: Leave");
1239 }
1240
1241 /*--------------------------------------------------------------------------*/
1242 /**
1243  * @brief   win_mgr_create_layer: create new layer
1244  *
1245  * @param[in]   usurf       UIFW surface, (if need)
1246  * @param[in]   layer       layer id
1247  * @return      new layer
1248  * @retval      != NULL     success(layer management table)
1249  * @retval      == NULL     error(No Memory)
1250  */
1251 /*--------------------------------------------------------------------------*/
1252 static struct uifw_win_layer *
1253 win_mgr_create_layer(struct uifw_win_surface *usurf, const uint32_t layer)
1254 {
1255     struct uifw_win_layer *el;
1256     struct uifw_win_layer *new_el;
1257
1258     new_el = malloc(sizeof(struct uifw_win_layer));
1259     if (! new_el)   {
1260         uifw_trace("win_mgr_create_layer: Leave(No Memory)");
1261         return NULL;
1262     }
1263
1264     memset(new_el, 0, sizeof(struct uifw_win_layer));
1265     new_el->layer = layer;
1266     if ((int)layer == _ico_ivi_background_layer )   {
1267         new_el->layer_type = ICO_WINDOW_MGR_LAYER_TYPE_BACKGROUND;
1268     }
1269     else if ((int)layer == _ico_ivi_input_layer )   {
1270         new_el->layer_type = ICO_WINDOW_MGR_LAYER_TYPE_INPUT;
1271     }
1272     else if ((int)layer == _ico_ivi_cursor_layer )  {
1273         new_el->layer_type = ICO_WINDOW_MGR_LAYER_TYPE_CURSOR;
1274     }
1275     else    {
1276         new_el->layer_type = ICO_WINDOW_MGR_LAYER_TYPE_NORMAL;
1277     }
1278     new_el->visible = TRUE;
1279     wl_list_init(&new_el->surface_list);
1280     wl_list_init(&new_el->link);
1281
1282     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1283         if (layer >= el->layer) break;
1284     }
1285     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
1286         wl_list_insert(_ico_win_mgr->ivi_layer_list.prev, &new_el->link);
1287     }
1288     else    {
1289         wl_list_insert(el->link.prev, &new_el->link);
1290     }
1291
1292     if (usurf)  {
1293         wl_list_remove(&usurf->ivi_layer);
1294         wl_list_insert(&new_el->surface_list, &usurf->ivi_layer);
1295         usurf->win_layer = new_el;
1296     }
1297     return new_el;
1298 }
1299
1300 /*--------------------------------------------------------------------------*/
1301 /**
1302  * @brief   win_mgr_set_layer: set(or change) surface layer
1303  *
1304  * @param[in]   usurf       UIFW surface
1305  * @param[in]   layer       layer id
1306  * @return      none
1307  */
1308 /*--------------------------------------------------------------------------*/
1309 static void
1310 win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer)
1311 {
1312     struct uifw_win_layer *el;
1313     struct uifw_win_layer *new_el;
1314
1315     uifw_trace("win_mgr_set_layer: Enter(%08x,%08x,%x)",
1316                usurf->surfaceid, (int)usurf->surface, layer);
1317
1318     /* check if same layer                      */
1319     if ((usurf->win_layer != NULL) && (usurf->win_layer->layer == layer))   {
1320         uifw_trace("win_mgr_set_layer: Leave(Same Layer)");
1321         return;
1322     }
1323
1324     /* search existing layer                    */
1325     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1326         if (el->layer == layer) break;
1327     }
1328
1329     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
1330         /* layer not exist, create new layer    */
1331         uifw_trace("win_mgr_set_layer: New Layer %d", layer);
1332         new_el = win_mgr_create_layer(usurf, layer);
1333         if (! new_el)   {
1334             uifw_trace("win_mgr_set_layer: Leave(No Memory)");
1335             return;
1336         }
1337     }
1338     else    {
1339         uifw_trace("win_mgr_set_layer: Add surface to Layer %d", layer);
1340         wl_list_remove(&usurf->ivi_layer);
1341         wl_list_insert(&el->surface_list, &usurf->ivi_layer);
1342         usurf->win_layer = el;
1343     }
1344
1345     /* rebild compositor surface list       */
1346     if (usurf->visible) {
1347         ico_window_mgr_restack_layer(usurf, 0);
1348     }
1349     uifw_trace("win_mgr_set_layer: Leave");
1350 }
1351
1352 /*--------------------------------------------------------------------------*/
1353 /**
1354  * @brief   win_mgr_set_active: set(or change) active surface
1355  *
1356  * @param[in]   usurf       UIFW surface
1357  * @param[in]   target      target device
1358  * @return      none
1359  */
1360 /*--------------------------------------------------------------------------*/
1361 static void
1362 win_mgr_set_active(struct uifw_win_surface *usurf, const int target)
1363 {
1364     struct weston_seat *seat;
1365     struct weston_surface *surface;
1366     int object = target;
1367     wl_fixed_t sx, sy;
1368
1369     uifw_trace("win_mgr_set_active: Enter(%08x,%x)", (int)usurf, target);
1370
1371     if ((usurf) && (usurf->shsurf) && (usurf->surface)) {
1372         surface = usurf->surface;
1373         if ((target & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) == 0) {
1374             surface = NULL;
1375             if (_ico_win_mgr->active_pointer_usurf == usurf) {
1376                 object |= ICO_WINDOW_MGR_ACTIVE_POINTER;
1377             }
1378             if (_ico_win_mgr->active_keyboard_usurf == usurf)    {
1379                 object |= ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1380             }
1381         }
1382         else    {
1383             if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1384                 _ico_win_mgr->active_pointer_usurf = usurf;
1385             }
1386             if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD)    {
1387                 _ico_win_mgr->active_keyboard_usurf = usurf;
1388             }
1389         }
1390     }
1391     else    {
1392         surface = NULL;
1393         if (target == 0)    {
1394             object = ICO_WINDOW_MGR_ACTIVE_POINTER | ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1395         }
1396         if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1397             _ico_win_mgr->active_pointer_usurf = NULL;
1398         }
1399         if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD)    {
1400             _ico_win_mgr->active_keyboard_usurf = NULL;
1401         }
1402     }
1403
1404     wl_list_for_each(seat, &_ico_win_mgr->compositor->seat_list, link) {
1405         if ((object & ICO_WINDOW_MGR_ACTIVE_POINTER) && (seat->pointer))   {
1406             if (surface)    {
1407                 if (seat->pointer->focus != surface) {
1408                     uifw_trace("win_mgr_set_active: pointer change surface(%08x=>%08x)",
1409                                (int)seat->pointer->focus, (int)surface);
1410                     weston_surface_from_global_fixed(surface,
1411                                                      seat->pointer->x,
1412                                                      seat->pointer->y,
1413                                                      &sx, &sy);
1414                     weston_pointer_set_focus(seat->pointer, surface, sx, sy);
1415                 }
1416                 else    {
1417                     uifw_trace("win_mgr_set_active: pointer nochange surface(%08x)",
1418                                (int)surface);
1419                 }
1420             }
1421             else    {
1422                 uifw_trace("win_mgr_set_active: pointer reset surface(%08x)",
1423                            (int)seat->pointer->focus);
1424                 weston_pointer_set_focus(seat->pointer, NULL,
1425                                          wl_fixed_from_int(0), wl_fixed_from_int(0));
1426             }
1427         }
1428         if ((object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD) && (seat->keyboard))  {
1429             if (surface)    {
1430                 if (seat->keyboard->focus != surface)    {
1431                     weston_keyboard_set_focus(seat->keyboard, surface);
1432                     uifw_trace("win_mgr_set_active: keyboard change surface(%08x=>%08x)",
1433                                (int)seat->keyboard->focus, (int)surface);
1434                 }
1435                 else    {
1436                     uifw_trace("win_mgr_set_active: keyboard nochange surface(%08x)",
1437                                (int)surface);
1438                 }
1439             }
1440             else    {
1441                 uifw_trace("win_mgr_set_active: keyboard reset surface(%08x)",
1442                            (int)seat->keyboard);
1443                 weston_keyboard_set_focus(seat->keyboard, NULL);
1444             }
1445         }
1446     }
1447     uifw_trace("win_mgr_set_active: Leave(%08x)", (int)usurf);
1448 }
1449
1450 /*--------------------------------------------------------------------------*/
1451 /**
1452  * @brief   ico_window_mgr_ismykeyboard: check active keyboard
1453  *
1454  * @param[in]   usurf       UIFW surface
1455  * @return      check result
1456  * @retval      =1          usurf is active keyboard surface
1457  * @retval      =0          usurf is not active
1458  */
1459 /*--------------------------------------------------------------------------*/
1460 WL_EXPORT   int
1461 ico_window_mgr_ismykeyboard(struct uifw_win_surface *usurf)
1462 {
1463     return (_ico_win_mgr->active_keyboard_usurf == usurf) ? 1 : 0;
1464 }
1465
1466 /*--------------------------------------------------------------------------*/
1467 /**
1468  * @brief   uifw_declare_manager: declare manager(ex.SystemController) client
1469  *
1470  * @param[in]   client      Weyland client
1471  * @param[in]   resource    resource of request
1472  * @param[in]   manager     manager(1=manager, 0=not manager)
1473  * @return      none
1474  */
1475 /*--------------------------------------------------------------------------*/
1476 static void
1477 uifw_declare_manager(struct wl_client *client, struct wl_resource *resource, int manager)
1478 {
1479     struct uifw_manager* mgr;
1480     struct uifw_win_surface *usurf;
1481     struct uifw_client *uclient;
1482     struct uifw_win_layer *el;
1483
1484     uifw_trace("uifw_declare_manager: Enter client=%08x manager=%d",
1485                (int)client, manager);
1486
1487     uclient = find_client_from_client(client);
1488     if (! uclient)  {
1489         uifw_trace("uifw_declare_manager: Leave(unknown client=%08x)", (int)client);
1490         return;
1491     }
1492
1493     uclient->manager = manager;
1494
1495     /* client set to manager            */
1496     _ico_win_mgr->num_manager = 0;
1497     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
1498         if (mgr->resource == resource)  {
1499             if (mgr->manager != manager)    {
1500                 uifw_trace("uifw_declare_manager: Event Client.%08x Callback %d=>%d",
1501                            (int)client, mgr->manager, manager);
1502                 mgr->manager = manager;
1503
1504                 if (manager)    {
1505                     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1506                         wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
1507                             /* send window create event to manager  */
1508                             if (usurf->created != 0)    {
1509                                 uifw_trace("uifw_declare_manager: Send manager(%08x) "
1510                                            "WINDOW_CREATED(surf=%08x,pid=%d,appid=%s)",
1511                                            (int)resource, usurf->surfaceid,
1512                                            usurf->uclient->pid, usurf->uclient->appid);
1513                                 ico_window_mgr_send_window_created(resource,
1514                                                                    usurf->surfaceid,
1515                                                                    usurf->winname,
1516                                                                    usurf->uclient->pid,
1517                                                                    usurf->uclient->appid);
1518                             }
1519                         }
1520                     }
1521                 }
1522             }
1523         }
1524         if (mgr->manager)   {
1525             _ico_win_mgr->num_manager++;
1526         }
1527     }
1528     uifw_trace("uifw_declare_manager: Leave(managers=%d)", _ico_win_mgr->num_manager);
1529 }
1530
1531 /*--------------------------------------------------------------------------*/
1532 /**
1533  * @brief   uifw_set_window_layer: set layer id to surface
1534  *
1535  * @param[in]   client      Weyland client
1536  * @param[in]   resource    resource of request
1537  * @param[in]   surfaceid   UIFW surface id
1538  * @param[in]   layer       layer id
1539  * @return      none
1540  */
1541 /*--------------------------------------------------------------------------*/
1542 static void
1543 uifw_set_window_layer(struct wl_client *client, struct wl_resource *resource,
1544                       uint32_t surfaceid, uint32_t layer)
1545 {
1546     if (layer == ICO_WINDOW_MGR_V_LAYER_INPUT)  {
1547         layer = _ico_ivi_input_layer;
1548     }
1549     else if (layer == ICO_WINDOW_MGR_V_LAYER_CURSOR)    {
1550         layer = _ico_ivi_cursor_layer;
1551     }
1552
1553     uifw_trace("uifw_set_window_layer: Enter res=%08x surfaceid=%08x layer=%d",
1554                (int)resource, surfaceid, layer);
1555
1556     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1557
1558     if (! usurf)    {
1559         uifw_trace("uifw_set_window_layer: Leave(No Surface(id=%08x))", surfaceid);
1560         return;
1561     }
1562
1563     if (usurf->win_layer->layer != layer) {
1564         win_mgr_set_layer(usurf, layer);
1565         win_mgr_change_surface(usurf->surface, -1, 1);
1566     }
1567     uifw_trace("uifw_set_window_layer: Leave");
1568 }
1569
1570 /*--------------------------------------------------------------------------*/
1571 /**
1572  * @brief   uifw_set_positionsize: set surface position and size
1573  *
1574  * @param[in]   client      Weyland client
1575  * @param[in]   resource    resource of request
1576  * @param[in]   surfaceid   UIFW surface id
1577  * @param[in]   node        surface node id
1578  * @param[in]   x           X coordinate on screen(if bigger than 16383, no change)
1579  * @param[in]   y           Y coordinate on screen(if bigger than 16383, no change)
1580  * @param[in]   width       surface width(if bigger than 16383, no change)
1581  * @param[in]   height      surface height(if bigger than 16383, no change)
1582  * @param[in]   flags       with/without animation and client configure flag
1583  * @return      none
1584  */
1585 /*--------------------------------------------------------------------------*/
1586 static void
1587 uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
1588                       uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
1589                       int32_t width, int32_t height, int32_t flags)
1590 {
1591     struct uifw_client *uclient;
1592     struct uifw_win_surface *usurf;
1593     struct weston_surface *es;
1594     int     op;
1595     int     retanima;
1596
1597     uifw_trace("uifw_set_positionsize: Enter surf=%08x node=%x x/y/w/h=%d/%d/%d/%d flag=%x",
1598                surfaceid, node, x, y, width, height, flags);
1599
1600     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1601     if (! usurf)    {
1602         uifw_trace("uifw_set_positionsize: Leave(surf=%08x NOT Found)", surfaceid);
1603         return;
1604     }
1605
1606     uclient = find_client_from_client(client);
1607
1608     usurf->disable = 0;
1609     if (((int)node) >= _ico_num_nodes)  {
1610         uifw_trace("uifw_set_positionsize: node=%d dose not exist(max=%d)",
1611                    node, _ico_num_nodes);
1612         if ((ico_ivi_debugflag() & ICO_IVI_DEBUG_SHOW_SURFACE) == 0)    {
1613             if (usurf->visible) {
1614                 /* no display, change to hide   */
1615                 uifw_set_visible(client, resource, surfaceid, ICO_WINDOW_MGR_VISIBLE_HIDE,
1616                                  ICO_WINDOW_MGR_V_NOCHANGE, 0);
1617             }
1618             usurf->disable = 1;
1619         }
1620         node = 0;
1621     }
1622     usurf->node_tbl = &_ico_node_table[node];
1623
1624     es = usurf->surface;
1625     if (es)  {
1626         /* weston surface exist             */
1627         es = usurf->surface;
1628         retanima = ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA;
1629
1630         /* if x,y,width,height bigger then ICO_IVI_MAX_COORDINATE, no change    */
1631         if (x > ICO_IVI_MAX_COORDINATE)         x = usurf->x;
1632         if (y > ICO_IVI_MAX_COORDINATE)         y = usurf->y;
1633         if (width > ICO_IVI_MAX_COORDINATE)     width = usurf->width;
1634         if (height > ICO_IVI_MAX_COORDINATE)    height = usurf->height;
1635
1636         /* check animation                  */
1637         if ((usurf->animation.restrain_configure != 0) &&
1638             (x == usurf->x) && (y == usurf->y) &&
1639             (width == usurf->width) && (height == usurf->height))   {
1640             uifw_trace("uifw_set_positionsize: Leave(same position size at animation)");
1641             return;
1642         }
1643
1644         if (uclient)    {
1645             if ((surfaceid != ICO_WINDOW_MGR_V_MAINSURFACE) &&
1646                 (uclient->manager == 0)) uclient = NULL;
1647         }
1648         if (! uclient)  {
1649             if ((usurf->width > 0) && (usurf->height > 0))  {
1650                 win_mgr_surface_change_mgr(es, x, y, width, height);
1651                 uifw_trace("uifw_set_positionsize: Leave(Request from App)");
1652                 return;
1653             }
1654
1655             uifw_trace("uifw_set_positionsize: Initial Position/Size visible=%d",
1656                        usurf->visible);
1657             /* Initiale position is (0,0)   */
1658             weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x),
1659                                         (float)(usurf->node_tbl->disp_y));
1660         }
1661
1662         uifw_trace("uifw_set_positionsize: Old geometry x/y=%d/%d,w/h=%d/%d",
1663                    (int)es->geometry.x, (int)es->geometry.y,
1664                    (int)es->geometry.width, (int)es->geometry.height);
1665
1666         usurf->animation.pos_x = usurf->x;
1667         usurf->animation.pos_y = usurf->y;
1668         usurf->animation.pos_width = usurf->width;
1669         usurf->animation.pos_height = usurf->height;
1670         usurf->animation.no_configure = (flags & ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE) ? 1 : 0;
1671         usurf->x = x;
1672         usurf->y = y;
1673         usurf->width = width;
1674         usurf->height = height;
1675         if (_ico_win_mgr->num_manager <= 0) {
1676             /* no manager(HomeScreen), set geometory    */
1677             weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x + x),
1678                                         (float)(usurf->node_tbl->disp_y + y));
1679         }
1680         if ((es->output) && (es->buffer_ref.buffer) &&
1681             (es->geometry.width > 0) && (es->geometry.height > 0)) {
1682             uifw_trace("uifw_set_positionsize: Fixed Geometry, Change(Vis=%d)",
1683                        usurf->visible);
1684             if (usurf->visible) {
1685                 if ((flags & ICO_WINDOW_MGR_FLAGS_ANIMATION) &&
1686                     (win_mgr_hook_animation != NULL))   {
1687                     /* with animation   */
1688                     if ((x != (usurf->surface->geometry.x - usurf->node_tbl->disp_x)) ||
1689                         (y != (usurf->surface->geometry.y - usurf->node_tbl->disp_y)))  {
1690                         op = ICO_WINDOW_MGR_ANIMATION_OPMOVE;
1691                     }
1692                     else if ((width != usurf->surface->geometry.width) ||
1693                              (height != usurf->surface->geometry.height))   {
1694                         op = ICO_WINDOW_MGR_ANIMATION_OPRESIZE;
1695                     }
1696                     else    {
1697                         op = ICO_WINDOW_MGR_ANIMATION_OPNONE;
1698                     }
1699                     if (((op == ICO_WINDOW_MGR_ANIMATION_OPMOVE) &&
1700                          (usurf->animation.move_anima != ICO_WINDOW_MGR_ANIMATION_NONE)) ||
1701                         ((op == ICO_WINDOW_MGR_ANIMATION_OPRESIZE) &&
1702                          (usurf->animation.resize_anima != ICO_WINDOW_MGR_ANIMATION_NONE))) {
1703                         retanima = (*win_mgr_hook_animation)(op, (void *)usurf);
1704                         uifw_trace("uifw_set_positionsize: ret call anima = %d", retanima);
1705                     }
1706                 }
1707                 if ((retanima == ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA) ||
1708                     (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL))  {
1709                     ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1710                                                       usurf->width, usurf->height);
1711                 }
1712             }
1713         }
1714         if ((retanima == ICO_WINDOW_MGR_ANIMATION_RET_NOANIMA) ||
1715             (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL))  {
1716             win_mgr_change_surface(es,
1717                                    (flags & ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE) ? -1 : 0, 1);
1718         }
1719         uifw_trace("uifw_set_positionsize: Leave(OK,output=%08x)", (int)es->output);
1720     }
1721     else    {
1722         usurf->x = x;
1723         usurf->y = y;
1724         usurf->width = width;
1725         usurf->height = height;
1726         uifw_trace("uifw_set_positionsize: Leave(OK,but no buffer)");
1727     }
1728 }
1729
1730 /*--------------------------------------------------------------------------*/
1731 /**
1732  * @brief   uifw_set_visible: surface visible/raise control
1733  *
1734  * @param[in]   client      Weyland client
1735  * @param[in]   resource    resource of request
1736  * @param[in]   surfaceid   UIFW surface id
1737  * @param[in]   visible     visible(1=show/0=hide/other=no change)
1738  * @param[in]   raise       raise(1=raise/0=lower/other=no change)
1739  * @param[in]   flags       with/without animation
1740  * @return      none
1741  */
1742 /*--------------------------------------------------------------------------*/
1743 static void
1744 uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
1745                  uint32_t surfaceid, int32_t visible, int32_t raise, int32_t flags)
1746 {
1747     struct uifw_win_surface *usurf;
1748     struct uifw_client *uclient;
1749     int     restack;
1750     int     retanima;
1751
1752     uifw_trace("uifw_set_visible: Enter(surf=%08x,%d,%d,%x)",
1753                surfaceid, visible, raise, flags);
1754
1755     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1756     if ((! usurf) || (! usurf->surface))    {
1757         uifw_trace("uifw_set_visible: Leave(Surface Not Exist)");
1758         return;
1759     }
1760
1761     uclient = find_client_from_client(client);
1762     if (uclient)    {
1763         if ((surfaceid != ICO_WINDOW_MGR_V_MAINSURFACE) &&
1764             (uclient->manager == 0))    {
1765             uifw_trace("uifw_set_visible: Request from App(%s), not Manager",
1766                        uclient->appid);
1767             uclient = NULL;
1768         }
1769         else    {
1770             uifw_trace("uifw_set_visible: Request from Manager(%s)", uclient->appid);
1771         }
1772     }
1773     else    {
1774         uifw_trace("uifw_set_visible: Request from Unknown App, not Manager");
1775     }
1776
1777     restack = 0;
1778
1779     if ((usurf->disable == 0) && (visible == ICO_WINDOW_MGR_VISIBLE_SHOW))  {
1780
1781         if (! usurf->visible)  {
1782             usurf->visible = 1;
1783             uifw_trace("uifw_set_visible: Change to Visible");
1784
1785             ico_ivi_shell_set_toplevel(usurf->shsurf);
1786
1787             /* Weston surface configure                     */
1788             uifw_trace("uifw_set_visible: Visible to Weston WSurf=%08x,%d.%d/%d/%d/%d",
1789                        (int)usurf->surface, usurf->node_tbl->node, usurf->x, usurf->y,
1790                        usurf->width, usurf->height);
1791             ico_ivi_shell_set_surface_type(usurf->shsurf);
1792             ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1793                                               usurf->width, usurf->height);
1794
1795             restack = 1;                    /* need damage      */
1796
1797             if ((flags & (ICO_WINDOW_MGR_ANIMATION_POS|ICO_WINDOW_MGR_FLAGS_ANIMATION)) &&
1798                 (usurf->animation.show_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1799                 (win_mgr_hook_animation != NULL))   {
1800                 usurf->animation.pos_x = usurf->x;
1801                 usurf->animation.pos_y = usurf->y;
1802                 usurf->animation.pos_width = usurf->width;
1803                 usurf->animation.pos_height = usurf->height;
1804                 usurf->animation.no_configure = 0;
1805                 retanima = (*win_mgr_hook_animation)(
1806                                 (flags & ICO_WINDOW_MGR_ANIMATION_POS) ?
1807                                     ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS :
1808                                     ICO_WINDOW_MGR_ANIMATION_OPSHOW,
1809                                 (void *)usurf);
1810                 uifw_trace("uifw_set_visible: ret call anima = %d", retanima);
1811             }
1812         }
1813         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1814                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1815             uifw_trace("uifw_set_visible: Leave(No Change)");
1816             return;
1817         }
1818     }
1819     else if (visible == ICO_WINDOW_MGR_VISIBLE_HIDE)    {
1820
1821         if (usurf->visible)    {
1822
1823             /* Weston surface configure                     */
1824             weston_surface_damage_below(usurf->surface);
1825             ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1826                                               usurf->width, usurf->height);
1827
1828             retanima = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
1829             if ((flags & (ICO_WINDOW_MGR_FLAGS_ANIMATION|ICO_WINDOW_MGR_ANIMATION_POS)) &&
1830                 (usurf->animation.hide_anima != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1831                 (win_mgr_hook_animation != NULL))   {
1832                 usurf->animation.pos_x = usurf->x;
1833                 usurf->animation.pos_y = usurf->y;
1834                 usurf->animation.pos_width = usurf->width;
1835                 usurf->animation.pos_height = usurf->height;
1836                 usurf->animation.no_configure = 0;
1837                 retanima = (*win_mgr_hook_animation)(
1838                                 (flags & ICO_WINDOW_MGR_ANIMATION_POS) ?
1839                                     ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS :
1840                                     ICO_WINDOW_MGR_ANIMATION_OPHIDE,
1841                                 (void *)usurf);
1842             }
1843             if (retanima != ICO_WINDOW_MGR_ANIMATION_RET_ANIMANOCTL)    {
1844                 usurf->visible = 0;
1845                 uifw_trace("uifw_set_visible: Change to UnVisible");
1846                 /* change visible to unvisible, restack surface list    */
1847                 restack = 1;
1848                 /* Weston surface configure                     */
1849                 ico_window_mgr_set_weston_surface(usurf, usurf->x, usurf->y,
1850                                                   usurf->width, usurf->height);
1851             }
1852             else    {
1853                 uifw_trace("uifw_set_visible: UnVisible but animation");
1854             }
1855         }
1856         else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1857                  (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1858             uifw_trace("uifw_set_visible: Leave(No Change)");
1859             return;
1860         }
1861     }
1862     else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1863              (raise != ICO_WINDOW_MGR_RAISE_RAISE))  {
1864         uifw_trace("uifw_set_visible: Leave(No Change)");
1865         return;
1866     }
1867
1868     /* raise/lower                              */
1869     if ((raise == ICO_WINDOW_MGR_RAISE_LOWER) || (raise == ICO_WINDOW_MGR_RAISE_RAISE))  {
1870         win_mgr_set_raise(usurf, raise);
1871         if (usurf->visible == 0)    {
1872             restack |= 2;
1873         }
1874     }
1875     else    {
1876         raise = ICO_WINDOW_MGR_V_NOCHANGE;
1877     }
1878
1879     if (restack)    {
1880         ico_window_mgr_restack_layer(usurf, 0);
1881     }
1882
1883     /* send event(VISIBLE) to manager           */
1884     if (restack)    {
1885         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
1886                                 usurf,
1887                                 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ? 1 :
1888                                     ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ? 0 :
1889                                         ICO_WINDOW_MGR_V_NOCHANGE),
1890                                 raise, uclient ? 0 : 1, 0,0);
1891     }
1892     uifw_trace("uifw_set_visible: Leave(OK)");
1893 }
1894
1895 /*--------------------------------------------------------------------------*/
1896 /**
1897  * @brief   uifw_set_animation: set animation of surface visible/unvisible
1898  *
1899  * @param[in]   client      Weyland client
1900  * @param[in]   resource    resource of request
1901  * @param[in]   surfaceid   UIFW surface id
1902  * @param[in]   type        how to change surface
1903  * @param[in]   anmation    animation name
1904  * @param[in]   time        animation time(ms), if 0, default time
1905  * @return      none
1906  */
1907 /*--------------------------------------------------------------------------*/
1908 static void
1909 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
1910                    uint32_t surfaceid, int32_t type, const char *animation, int32_t time)
1911 {
1912     int animaid;
1913     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1914
1915     uifw_trace("uifw_set_transition: Enter(surf=%08x,type=%x,anim=%s,time=%d)",
1916                surfaceid, type, animation, time);
1917
1918     if (usurf) {
1919         if ((*animation != 0) && (*animation != ' '))   {
1920             animaid = ico_get_animation_name(animation);
1921             uifw_trace("uifw_set_animation: Leave(OK) type=%d", animaid);
1922             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
1923                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDE) ||
1924                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDEPOS))  {
1925                     usurf->animation.next_anima = animaid;
1926                 }
1927                 else    {
1928                     usurf->animation.hide_anima = animaid;
1929                 }
1930             }
1931             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
1932                 if ((usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOW) ||
1933                     (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOWPOS))  {
1934                     usurf->animation.next_anima = animaid;
1935                 }
1936                 else    {
1937                     usurf->animation.show_anima = animaid;
1938                 }
1939             }
1940             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
1941                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPMOVE)    {
1942                     usurf->animation.next_anima = animaid;
1943                 }
1944                 else    {
1945                     usurf->animation.move_anima = animaid;
1946                 }
1947             }
1948             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
1949                 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPRESIZE)  {
1950                     usurf->animation.next_anima = animaid;
1951                 }
1952                 else    {
1953                     usurf->animation.resize_anima = animaid;
1954                 }
1955             }
1956         }
1957         if ((time > 0) && (time != ICO_WINDOW_MGR_V_NOCHANGE))  {
1958             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE)  {
1959                 usurf->animation.hide_time = time;
1960             }
1961             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW)  {
1962                 usurf->animation.show_time = time;
1963             }
1964             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE)  {
1965                 usurf->animation.move_time = time;
1966             }
1967             if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE)    {
1968                 usurf->animation.resize_time = time;
1969             }
1970         }
1971     }
1972     else    {
1973         uifw_trace("uifw_set_animation: Leave(Surface(%08x) Not exist)", surfaceid);
1974     }
1975 }
1976
1977 /*--------------------------------------------------------------------------*/
1978 /**
1979  * @brief   uifw_set_attributes: set surface attributes
1980  *
1981  * @param[in]   client      Weyland client
1982  * @param[in]   resource    resource of request
1983  * @param[in]   surfaceid   UIFW surface id
1984  * @param[in]   attributes  surface attributes
1985  * @return      none
1986  */
1987 /*--------------------------------------------------------------------------*/
1988 static void
1989 uifw_set_attributes(struct wl_client *client, struct wl_resource *resource,
1990                     uint32_t surfaceid, uint32_t attributes)
1991 {
1992     struct uifw_win_surface *usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
1993
1994     uifw_trace("uifw_set_attributes: Enter(surf=%08x,attributes=%x)", surfaceid, attributes);
1995
1996     if (usurf) {
1997         usurf->attributes = attributes;
1998         if ((attributes & (ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT)) ==
1999             (ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT))   {
2000             usurf->attributes &=
2001                 ~(ICO_WINDOW_MGR_ATTR_ALIGN_LEFT|ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT);
2002         }
2003         if ((attributes & (ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM)) ==
2004             (ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM))   {
2005             usurf->attributes &=
2006                 ~(ICO_WINDOW_MGR_ATTR_ALIGN_TOP|ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM);
2007         }
2008     }
2009     uifw_trace("uifw_set_attributes: Leave");
2010 }
2011
2012 /*--------------------------------------------------------------------------*/
2013 /**
2014  * @brief   uifw_visible_animation: surface visibility control with animation
2015  *
2016  * @param[in]   client      Weyland client
2017  * @param[in]   resource    resource of request
2018  * @param[in]   surfaceid   surface id
2019  * @param[in]   visible     visible(1=show/0=hide)
2020  * @param[in]   x           X coordinate on screen(if bigger than 16383, no change)
2021  * @param[in]   y           Y coordinate on screen(if bigger than 16383, no change)
2022  * @param[in]   width       surface width(if bigger than 16383, no change)
2023  * @param[in]   height      surface height(if bigger than 16383, no change)
2024  * @return      none
2025  */
2026 /*--------------------------------------------------------------------------*/
2027 static void
2028 uifw_visible_animation(struct wl_client *client, struct wl_resource *resource,
2029                        uint32_t surfaceid, int32_t visible,
2030                        int32_t x, int32_t y, int32_t width, int32_t height)
2031 {
2032     struct uifw_win_surface *usurf;
2033
2034     uifw_trace("uifw_visible_animation: Enter(%08x,%d,x/y=%d/%d,w/h=%d/%d)",
2035                surfaceid, visible, x, y, width, height);
2036
2037     usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2038
2039     if ((! usurf) || (! usurf->surface))    {
2040         uifw_trace("uifw_visible_animation: Leave(Surface Not Exist)");
2041         return;
2042     }
2043
2044     usurf->animation.pos_x = x;
2045     usurf->animation.pos_y = y;
2046     if (width > 0)  usurf->animation.pos_width = width;
2047     else            usurf->animation.pos_width = 1;
2048     if (height > 0) usurf->animation.pos_height = height;
2049     else            usurf->animation.pos_height = 1;
2050     usurf->animation.no_configure = 0;
2051
2052     uifw_set_visible(client, resource, surfaceid, visible,
2053                      ICO_WINDOW_MGR_V_NOCHANGE, ICO_WINDOW_MGR_ANIMATION_POS);
2054
2055     uifw_trace("uifw_visible_animation: Leave");
2056 }
2057
2058 /*--------------------------------------------------------------------------*/
2059 /**
2060  * @brief   uifw_set_active: set active surface
2061  *
2062  * @param[in]   client      Weyland client
2063  * @param[in]   resource    resource of request
2064  * @param[in]   surfaceid   UIFW surface id
2065  * @param[in]   active      target device
2066  * @return      none
2067  */
2068 /*--------------------------------------------------------------------------*/
2069 static void
2070 uifw_set_active(struct wl_client *client, struct wl_resource *resource,
2071                 uint32_t surfaceid, int32_t active)
2072 {
2073     struct uifw_win_surface *usurf;
2074
2075     uifw_trace("uifw_set_active: Enter(surf=%08x,active=%x)", surfaceid, active);
2076
2077     if ((surfaceid > 0) &&
2078         ((active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) != 0)) {
2079         usurf = ico_window_mgr_get_usurf_client(surfaceid, client);
2080     }
2081     else    {
2082         usurf = NULL;
2083     }
2084     if (usurf) {
2085         switch (active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) {
2086         case ICO_WINDOW_MGR_ACTIVE_POINTER:
2087             if (usurf != _ico_win_mgr->active_pointer_usurf)  {
2088                 if (_ico_win_mgr->active_pointer_usurf)   {
2089                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2090                                             _ico_win_mgr->active_pointer_usurf,
2091                                             (_ico_win_mgr->active_keyboard_usurf ==
2092                                              _ico_win_mgr->active_pointer_usurf) ?
2093                                                 ICO_WINDOW_MGR_ACTIVE_KEYBOARD :
2094                                                 ICO_WINDOW_MGR_ACTIVE_NONE,
2095                                             0,0,0,0);
2096                 }
2097                 _ico_win_mgr->active_pointer_usurf = usurf;
2098                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2099                                         usurf,
2100                                         ICO_WINDOW_MGR_ACTIVE_POINTER |
2101                                         (_ico_win_mgr->active_keyboard_usurf == usurf) ?
2102                                             ICO_WINDOW_MGR_ACTIVE_KEYBOARD : 0,
2103                                         0,0,0,0);
2104                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER);
2105             }
2106             break;
2107         case ICO_WINDOW_MGR_ACTIVE_KEYBOARD:
2108             if (usurf != _ico_win_mgr->active_keyboard_usurf) {
2109                 if (_ico_win_mgr->active_keyboard_usurf)   {
2110                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2111                                             _ico_win_mgr->active_keyboard_usurf,
2112                                             (_ico_win_mgr->active_keyboard_usurf ==
2113                                              _ico_win_mgr->active_pointer_usurf) ?
2114                                                 ICO_WINDOW_MGR_ACTIVE_POINTER :
2115                                                 ICO_WINDOW_MGR_ACTIVE_NONE,
2116                                             0,0,0,0);
2117                 }
2118                 _ico_win_mgr->active_keyboard_usurf = usurf;
2119                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2120                                         usurf,
2121                                         ICO_WINDOW_MGR_ACTIVE_KEYBOARD |
2122                                         (_ico_win_mgr->active_pointer_usurf == usurf) ?
2123                                             ICO_WINDOW_MGR_ACTIVE_POINTER : 0,
2124                                         0,0,0,0);
2125                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2126             }
2127             break;
2128         default:
2129             if ((usurf != _ico_win_mgr->active_pointer_usurf) ||
2130                 (usurf != _ico_win_mgr->active_keyboard_usurf))   {
2131                 if (_ico_win_mgr->active_pointer_usurf)   {
2132                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2133                                             _ico_win_mgr->active_pointer_usurf,
2134                                             ICO_WINDOW_MGR_ACTIVE_NONE,
2135                                             0,0,0,0);
2136                     if (_ico_win_mgr->active_keyboard_usurf ==
2137                         _ico_win_mgr->active_pointer_usurf)   {
2138                         _ico_win_mgr->active_keyboard_usurf = NULL;
2139                     }
2140                 }
2141                 if (_ico_win_mgr->active_keyboard_usurf)   {
2142                     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2143                                             _ico_win_mgr->active_keyboard_usurf,
2144                                             ICO_WINDOW_MGR_ACTIVE_NONE,
2145                                             0,0,0,0);
2146                 }
2147                 _ico_win_mgr->active_pointer_usurf = usurf;
2148                 _ico_win_mgr->active_keyboard_usurf = usurf;
2149                 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2150                                         usurf,
2151                                         ICO_WINDOW_MGR_ACTIVE_POINTER |
2152                                             ICO_WINDOW_MGR_ACTIVE_KEYBOARD,
2153                                         0,0,0,0);
2154                 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
2155                                               ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2156             }
2157             break;
2158         }
2159         uifw_trace("uifw_set_active: Leave(Change Active)");
2160     }
2161     else    {
2162         win_mgr_set_active(NULL, active);
2163         uifw_trace("uifw_set_active: Leave(Reset active surface)");
2164     }
2165 }
2166
2167 /*--------------------------------------------------------------------------*/
2168 /**
2169  * @brief   uifw_set_layer_visible: layer visible control
2170  *
2171  * @param[in]   client      Weyland client
2172  * @param[in]   resource    resource of request
2173  * @param[in]   layer       layer id
2174  * @param[in]   visible     visible(1=show/0=hide)
2175  * @return      none
2176  */
2177 /*--------------------------------------------------------------------------*/
2178 static void
2179 uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
2180                        uint32_t layer, int32_t visible)
2181 {
2182     struct uifw_win_layer   *el;
2183     struct uifw_win_layer   *new_el;
2184     struct uifw_win_surface *usurf;
2185
2186     if (layer == ICO_WINDOW_MGR_V_LAYER_INPUT)  {
2187         layer = _ico_ivi_input_layer;
2188     }
2189     else if (layer == ICO_WINDOW_MGR_V_LAYER_CURSOR)    {
2190         layer = _ico_ivi_cursor_layer;
2191     }
2192
2193     uifw_trace("uifw_set_layer_visible: Enter(layer=%d, visilbe=%d)", layer, visible);
2194
2195     /* Search Layer                             */
2196     wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
2197         if (el->layer == layer) break;
2198     }
2199
2200     if (&el->link == &_ico_win_mgr->ivi_layer_list)    {
2201         /* layer not exist, create new layer    */
2202         uifw_trace("uifw_set_layer_visible: New Layer %d", layer);
2203         new_el = win_mgr_create_layer(NULL, layer);
2204         if (! new_el)   {
2205             uifw_trace("uifw_set_layer_visible: Leave(No Memory)");
2206             return;
2207         }
2208         new_el->visible = (visible != 0) ? TRUE : FALSE;
2209         ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
2210                                 layer, new_el->visible, 0,0,0);
2211         uifw_trace("uifw_set_layer_visible: Leave(new layer)");
2212         return;
2213     }
2214
2215     /* control all surface in layer */
2216     if ((el->visible != FALSE) && (visible == 0))   {
2217         /* layer change to NOT visible  */
2218         uifw_trace("uifw_set_layer_visible: change to not visible");
2219         el->visible = FALSE;
2220     }
2221     else if ((el->visible == FALSE) && (visible != 0))  {
2222         /* layer change to visible      */
2223         uifw_trace("uifw_set_layer_visible: change to visible");
2224         el->visible = TRUE;
2225     }
2226     else    {
2227         /* no change    */
2228         uifw_trace("uifw_set_layer_visible: Leave(no Change %d=>%d)",
2229                    el->visible, visible);
2230         return;
2231     }
2232
2233     /* set damege area          */
2234     wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
2235         if ((usurf->visible != FALSE) && (usurf->surface != NULL) &&
2236             (usurf->surface->output != NULL))  {
2237             /* Damage(redraw) target surface    */
2238             weston_surface_damage_below(usurf->surface);
2239         }
2240     }
2241
2242     /* rebild compositor surface list       */
2243     ico_window_mgr_restack_layer(NULL, 0);
2244
2245     /* send layer visible event to manager  */
2246     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
2247                             layer, el->visible, 0,0,0);
2248
2249     uifw_trace("uifw_set_layer_visible: Leave");
2250 }
2251
2252 /*--------------------------------------------------------------------------*/
2253 /**
2254  * @brief   uifw_get_surfaces: get application surfaces
2255  *
2256  * @param[in]   client      Weyland client
2257  * @param[in]   resource    resource of request
2258  * @param[in]   appid       application id
2259  * @return      none
2260  */
2261 /*--------------------------------------------------------------------------*/
2262 static void
2263 uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource, const char *appid)
2264 {
2265     struct uifw_client  *uclient;
2266     struct uifw_win_layer *el;
2267     struct uifw_win_surface *usurf;
2268     struct wl_array     reply;
2269     uint32_t            *up;
2270
2271     uifw_trace("uifw_get_surfaces: Enter(appid=%s)", appid);
2272
2273     wl_array_init(&reply);
2274
2275     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
2276         if (strcmp(uclient->appid, appid) == 0) break;
2277     }
2278     if (&uclient->link == &_ico_win_mgr->client_list)    {
2279         uifw_trace("uifw_get_surfaces: appid=%s dose not exist", appid);
2280     }
2281     else    {
2282         wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
2283             wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
2284                 if (usurf->uclient == uclient)  {
2285                     uifw_trace("uifw_get_surfaces: %s surf=%08x", appid, usurf->surfaceid);
2286                     up = (uint32_t *)wl_array_add(&reply, sizeof(uint32_t));
2287                     if (up) {
2288                         *up = usurf->surfaceid;
2289                     }
2290                 }
2291             }
2292         }
2293     }
2294     ico_window_mgr_send_app_surfaces(resource, appid, &reply);
2295
2296     wl_array_release(&reply);
2297     uifw_trace("uifw_get_surfaces: Leave");
2298 }
2299
2300 /*--------------------------------------------------------------------------*/
2301 /**
2302  * @brief   win_mgr_check_surfacemap: check and change all surface
2303  *
2304  * @param[in]   animation   weston animation table(unused)
2305  * @param[in]   outout      weston output table
2306  * @param[in]   mseces      current time(unused)
2307  * @return      none
2308  */
2309 /*--------------------------------------------------------------------------*/
2310 static void
2311 win_mgr_check_surfacemap(struct weston_animation *animation,
2312                             struct weston_output *output, uint32_t msecs)
2313 {
2314     struct uifw_surface_map *sm;
2315
2316     wl_list_for_each(sm, &_ico_win_mgr->map_list, map_link) {
2317         if (sm->usurf->surface->output == output)   {
2318             win_mgr_change_mapsurface(sm, 0);
2319         }
2320     }
2321 }
2322
2323 /*--------------------------------------------------------------------------*/
2324 /**
2325  * @brief   win_mgr_change_mapsurface: check and change mapped surface
2326  *
2327  * @param[in]   sm          map surface table
2328  * @param[in]   event       send event (if 0, send if changed)
2329  * @return      none
2330  */
2331 /*--------------------------------------------------------------------------*/
2332 static void
2333 win_mgr_change_mapsurface(struct uifw_surface_map *sm, int event)
2334 {
2335     struct uifw_drm_buffer  *drm_buffer;
2336     struct uifw_dri_image   *dri_image;
2337     struct uifw_intel_region  *dri_region;
2338     struct uifw_gl_surface_state *gl_state;
2339     struct weston_surface   *es;
2340     uint32_t    eglname = 0;
2341     int         width;
2342     int         height;
2343     int         stride;
2344     uint32_t    format;
2345
2346     /* check if buffered        */
2347     es = sm->usurf->surface;
2348     if ((es == NULL) || (es->buffer_ref.buffer == NULL) ||
2349         (es->buffer_ref.buffer->width <= 0) || (es->buffer_ref.buffer->height <= 0) ||
2350         (es->buffer_ref.buffer->legacy_buffer == NULL) || (es->renderer_state == NULL) ||
2351         (((struct uifw_drm_buffer *)es->buffer_ref.buffer->legacy_buffer)->driver_buffer
2352          == NULL))  {
2353         /* surface has no buffer, error         */
2354         uifw_trace("win_mgr_change_mapsurface: surface(%08x) has no buffer",
2355                    sm->usurf->surfaceid);
2356         sm->width = 0;
2357         sm->height = 0;
2358         sm->stride = 0;
2359         sm->eglname = 0;
2360         sm->format = 0;
2361         if (sm->initflag)   {
2362             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP;
2363         }
2364         else    {
2365             event = 0;
2366         }
2367     }
2368     else    {
2369         gl_state = (struct uifw_gl_surface_state *)es->renderer_state;
2370         if (gl_state->buffer_type == BUFFER_TYPE_SHM)   {
2371             event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR;
2372         }
2373         else if (gl_state->buffer_type != BUFFER_TYPE_EGL)   {
2374             event = 0;
2375         }
2376         else    {
2377             drm_buffer = (struct uifw_drm_buffer *)es->buffer_ref.buffer->legacy_buffer;
2378             dri_image = (struct uifw_dri_image *)drm_buffer->driver_buffer;
2379             dri_region = dri_image->region;
2380             width = es->buffer_ref.buffer->width;
2381             height = es->buffer_ref.buffer->height;
2382             stride = drm_buffer->stride[0];
2383             if (drm_buffer->format == 0x34325258)   {
2384                 format = EGL_TEXTURE_RGB;
2385             }
2386             else if (drm_buffer->format == 0x34325241)  {
2387                 format = EGL_TEXTURE_RGBA;
2388             }
2389             else    {
2390                 /* unknown format, error    */
2391                 format = EGL_NO_TEXTURE;
2392             }
2393             eglname = dri_region->name;
2394
2395             if ((sm->initflag == 0) && (width > 0) && (height > 0) && (stride > 0)) {
2396                 sm->initflag = 1;
2397                 event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP;
2398             }
2399             else    {
2400                 if ((width <= 0) || (height <= 0) || (stride <= 0)) {
2401                     event = 0;
2402                 }
2403                 else if (event == 0)    {
2404                     if ((sm->width != width) || (sm->height != height) ||
2405                         (sm->stride != stride)) {
2406                         event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_RESIZE;
2407                     }
2408                     else if ((eglname != sm->eglname) || (format != sm->format))    {
2409                         event = ICO_WINDOW_MGR_MAP_SURFACE_EVENT_CONTENTS;
2410                     }
2411                 }
2412             }
2413             sm->width = width;
2414             sm->height = height;
2415             sm->stride = stride;
2416             sm->eglname = eglname;
2417             sm->format = format;
2418             sm->eglname = eglname;
2419         }
2420     }
2421
2422     if (event != 0) {
2423 #if 0       /* too many log */
2424         uifw_trace("win_mgr_change_mapsurface: send MAP event(ev=%d surf=%08x name=%08x "
2425                    "w/h/s=%d/%d/%d format=%x",
2426                    event, sm->usurf->surfaceid, sm->eglname, sm->width, sm->height,
2427                    sm->stride, sm->format);
2428 #endif
2429         ico_window_mgr_send_map_surface(sm->uclient->mgr->resource, event,
2430                                         sm->usurf->surfaceid, sm->type, sm->eglname,
2431                                         sm->width, sm->height, sm->stride, sm->format);
2432         if (event == ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR)    {
2433             /* free map table if error  */
2434             wl_list_remove(&sm->surf_link);
2435             wl_list_remove(&sm->map_link);
2436             sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
2437             _ico_win_mgr->free_maptable = sm;
2438         }
2439     }
2440 }
2441
2442 /*--------------------------------------------------------------------------*/
2443 /**
2444  * @brief   uifw_map_surface: mapped surface buffer to system application
2445  *
2446  * @param[in]   client      Weyland client
2447  * @param[in]   resource    resource of request
2448  * @param[in]   surfaceid   surface id
2449  * @param[in]   framerate   frame rate of surface update(frame/sec)
2450  * @return      none
2451  */
2452 /*--------------------------------------------------------------------------*/
2453 static void
2454 uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
2455                  uint32_t surfaceid, int32_t framerate)
2456 {
2457     struct uifw_win_surface     *usurf;
2458     struct weston_surface       *es;
2459     struct uifw_surface_map     *sm;
2460     struct weston_buffer        *buffer;
2461     struct uifw_client          *uclient;
2462     struct uifw_drm_buffer      *drm_buffer;
2463     struct uifw_gl_surface_state *gl_state;
2464
2465     uifw_trace("uifw_map_surface: Enter(surface=%08x,fps=%d)", surfaceid, framerate);
2466
2467     usurf = ico_window_mgr_get_usurf(surfaceid);
2468     if (! usurf)    {
2469         /* surface dose not exist, error        */
2470         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2471                                         surfaceid, 1, 0, 0, 0, 0, 0);
2472         uifw_trace("uifw_map_surface: Leave(surface=%08x dose not exist)", surfaceid);
2473         return;
2474     }
2475     uclient = find_client_from_client(client);
2476     if ((! uclient) || (! uclient->mgr))    {
2477         /* client dose not exist, error         */
2478         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2479                                         surfaceid, 2, 0, 0, 0, 0, 0);
2480         uifw_trace("uifw_map_surface: Leave(client=%08x dose not exist)", (int)client);
2481         return;
2482     }
2483
2484     es = usurf->surface;
2485
2486     /* check if buffered        */
2487     if ((es == NULL) || (es->buffer_ref.buffer == NULL))    {
2488         /* surface has no buffer, error         */
2489         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2490                                         surfaceid, 3, 0, 0, 0, 0, 0);
2491         uifw_trace("uifw_map_surface: Leave(surface(%08x) has no buffer)", surfaceid);
2492         return;
2493     }
2494
2495     /* check buffer type        */
2496     gl_state = (struct uifw_gl_surface_state *)es->renderer_state;
2497     if ((gl_state == NULL) || (gl_state->buffer_type == BUFFER_TYPE_SHM))   {
2498         /* wl_shm_buffer not support    */
2499         ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2500                                         surfaceid, 4, 0, 0, 0, 0, 0);
2501         uifw_trace("uifw_map_surface: Leave(surface(%08x) is wl_shm_buffer, "
2502                    "not support)", surfaceid);
2503         return;
2504     }
2505
2506     /* create map table         */
2507     sm = _ico_win_mgr->free_maptable;
2508     if (sm) {
2509         _ico_win_mgr->free_maptable = (struct uifw_surface_map *)sm->usurf;
2510     }
2511     else    {
2512         sm = (struct uifw_surface_map *)malloc(sizeof(struct uifw_surface_map));
2513         if (! sm)   {
2514             ico_window_mgr_send_map_surface(resource, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_ERROR,
2515                                             surfaceid, 5, 0, 0, 0, 0, 0);
2516             uifw_trace("uifw_map_surface: Leave(malloc error)");
2517             return;
2518         }
2519     }
2520     memset(sm, 0, sizeof(struct uifw_surface_map));
2521
2522     wl_list_init(&sm->map_link);
2523     wl_list_init(&sm->surf_link);
2524     sm->usurf = usurf;
2525     sm->uclient = uclient;
2526     sm->type = ICO_WINDOW_MGR_MAP_TYPE_EGL;
2527     sm->eglname = 0;
2528     sm->framerate = framerate;
2529     wl_list_insert(_ico_win_mgr->map_list.next, &sm->map_link);
2530     wl_list_insert(usurf->surf_map.prev, &sm->surf_link);
2531
2532     buffer = es->buffer_ref.buffer;
2533     if (gl_state->buffer_type == BUFFER_TYPE_EGL) {
2534         sm->width = buffer->width;
2535         sm->height = buffer->height;
2536         drm_buffer = (struct uifw_drm_buffer *)buffer->legacy_buffer;
2537         if (drm_buffer != NULL) {
2538             sm->stride = drm_buffer->stride[0];
2539             if (drm_buffer->format == 0x34325258)   {
2540                 sm->format = EGL_TEXTURE_RGB;
2541             }
2542             else if (drm_buffer->format == 0x34325241)  {
2543                 sm->format = EGL_TEXTURE_RGBA;
2544             }
2545             else    {
2546                 /* unknown format, error    */
2547                 sm->format = EGL_NO_TEXTURE;
2548             }
2549             if ((sm->width > 0) && (sm->height > 0) && (sm->stride > 0) &&
2550                 (gl_state != NULL))  {
2551                 sm->initflag = 1;
2552             }
2553         }
2554     }
2555
2556     /* send map event                       */
2557     if (sm->initflag)   {
2558         win_mgr_change_mapsurface(sm, ICO_WINDOW_MGR_MAP_SURFACE_EVENT_MAP);
2559     }
2560     uifw_trace("uifw_map_surface: Leave");
2561 }
2562
2563 /*--------------------------------------------------------------------------*/
2564 /**
2565  * @brief   uifw_unmap_surface: unmap surface buffer
2566  *
2567  * @param[in]   client      Weyland client
2568  * @param[in]   resource    resource of request
2569  * @param[in]   surfaceid   surface id
2570  * @return      none
2571  */
2572 /*--------------------------------------------------------------------------*/
2573 static void
2574 uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
2575                    uint32_t surfaceid)
2576 {
2577     struct uifw_win_surface *usurf;
2578     struct uifw_surface_map *sm, *sm_tmp;
2579     struct uifw_client      *uclient;
2580
2581     uifw_trace("uifw_unmap_surface: Enter(surface=%08x)", surfaceid);
2582
2583     usurf = ico_window_mgr_get_usurf(surfaceid);
2584     if (! usurf)    {
2585         /* surface dose not exist, error        */
2586         uifw_trace("uifw_unmap_surface: Leave(surface=%08x dose not exist)", surfaceid);
2587         return;
2588     }
2589     if (client) {
2590         uclient = find_client_from_client(client);
2591         if ((! uclient) || (! uclient->mgr))    {
2592             /* client dose not exist, error         */
2593             uifw_trace("uifw_unmap_surface: Leave(client=%08x dose not exist)", (int)client);
2594             return;
2595         }
2596     }
2597     else    {
2598         uclient = NULL;
2599         wl_list_for_each(sm, &usurf->surf_map, surf_link) {
2600             if (sm->uclient->mgr != NULL) {
2601                 uifw_trace("uifw_unmap_surface: send MAP event(ev=%d surf=%08x name=%08x "
2602                            "w/h/s=%d/%d/%d format=%x",
2603                            ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP, surfaceid,
2604                            sm->eglname, sm->width, sm->height, sm->stride, sm->format);
2605                 ico_window_mgr_send_map_surface(sm->uclient->mgr->resource,
2606                                                 ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP,
2607                                                 surfaceid, sm->type, sm->eglname, sm->width,
2608                                                 sm->height, sm->stride, sm->format);
2609             }
2610         }
2611     }
2612
2613     wl_list_for_each_safe(sm, sm_tmp, &usurf->surf_map, surf_link) {
2614         if (((uclient != NULL) && (sm->uclient != uclient)))   continue;
2615         /* send unmap event                     */
2616         if ((uclient != NULL) && (uclient->mgr != NULL))    {
2617             uifw_trace("uifw_unmap_surface: send MAP event(ev=%d surf=%08x name=%08x "
2618                        "w/h/s=%d/%d/%d format=%x",
2619                        ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP, surfaceid,
2620                        sm->eglname, sm->width, sm->height, sm->stride, sm->format);
2621             ico_window_mgr_send_map_surface(uclient->mgr->resource,
2622                                             ICO_WINDOW_MGR_MAP_SURFACE_EVENT_UNMAP,
2623                                             surfaceid, sm->type, sm->eglname, sm->width,
2624                                             sm->height, sm->stride, sm->format);
2625         }
2626         wl_list_remove(&sm->surf_link);
2627         wl_list_remove(&sm->map_link);
2628         sm->usurf = (struct uifw_win_surface *)_ico_win_mgr->free_maptable;
2629         _ico_win_mgr->free_maptable = sm;
2630     }
2631     uifw_trace("uifw_unmap_surface: Leave");
2632 }
2633
2634 /*--------------------------------------------------------------------------*/
2635 /**
2636  * @brief   win_mgr_surface_change_mgr: surface chagen from manager(HomeScreen)
2637  *
2638  * @param[in]   surface     Weston surface
2639  * @param[in]   x           X coordinate on screen
2640  * @param[in]   y           Y coordinate on screen
2641  * @param[in]   width       surface width
2642  * @param[in]   height      surface height
2643  * @return      number of managers
2644  * @retval      > 0         number of managers
2645  * @retval      0           manager not exist
2646  */
2647 /*--------------------------------------------------------------------------*/
2648 static int
2649 win_mgr_surface_change_mgr(struct weston_surface *surface,
2650                            const int x, const int y, const int width, const int height)
2651 {
2652     int     num_mgr;
2653     struct uifw_win_surface *usurf;
2654
2655     uifw_trace("win_mgr_surface_change_mgr: Enter(%08x,x/y=%d/%d,w/h=%d/%d)",
2656                (int)surface, x, y, width, height);
2657
2658     usurf = find_uifw_win_surface_by_ws(surface);
2659     if (! usurf) {
2660         uifw_trace("win_mgr_surface_change_mgr: Leave(Not Exist)");
2661         return 0;
2662     }
2663
2664     num_mgr = ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
2665                                       usurf, x, y, width, height, 1);
2666
2667     uifw_trace("win_mgr_surface_change_mgr: Leave(%d)", num_mgr);
2668     return num_mgr;
2669 }
2670
2671 /*--------------------------------------------------------------------------*/
2672 /**
2673  * @brief   win_mgr_change_surface: surface change
2674  *
2675  * @param[in]   surface     Weston surface
2676  * @param[in]   to          destination(0=Client&Manager,1=Client,-1=Manager)
2677  * @param[in]   manager     request from manager(0=Client,1=Manager)
2678  * @return      none
2679  */
2680 /*--------------------------------------------------------------------------*/
2681 static void
2682 win_mgr_change_surface(struct weston_surface *surface, const int to, const int manager)
2683 {
2684     struct uifw_win_surface *usurf;
2685     struct weston_surface   *es;
2686     int     x;
2687     int     y;
2688     int     repaint = 0;
2689
2690     uifw_trace("win_mgr_change_surface: Enter(%08x,%d,%d)", (int)surface, to, manager);
2691
2692     /* Find surface         */
2693     usurf = find_uifw_win_surface_by_ws(surface);
2694     if (! usurf) {
2695         uifw_trace("win_mgr_change_surface: Leave(Not Exist)");
2696         return;
2697     }
2698     es = usurf->surface;
2699     if (! es)   {
2700         uifw_trace("win_mgr_change_surface: Leave(No weston surface)");
2701         return;
2702     }
2703
2704     /* set surface size     */
2705     uifw_debug("win_mgr_change_surface: set surface x/y=%d/%d=>%d/%d w/h=%d/%d=>%d/%d",
2706                (int)es->geometry.x, (int)es->geometry.y, usurf->x, usurf->y,
2707                usurf->width, usurf->height, es->geometry.width, es->geometry.height);
2708     if ((usurf->width <= 0) || (usurf->height <= 0))    {
2709         usurf->width = es->geometry.width;
2710         usurf->height = es->geometry.height;
2711     }
2712     win_mgr_set_scale(usurf);
2713     if (usurf->visible) {
2714         weston_surface_set_position(usurf->surface,
2715                                     (float)(usurf->node_tbl->disp_x +
2716                                             usurf->x + usurf->xadd),
2717                                     (float)(usurf->node_tbl->disp_y +
2718                                             usurf->y + usurf->yadd));
2719         ico_window_mgr_restack_layer(usurf, 0);
2720     }
2721     else    {
2722         weston_surface_set_position(usurf->surface, (float)(ICO_IVI_MAX_COORDINATE+1),
2723                                     (float)(ICO_IVI_MAX_COORDINATE+1));
2724     }
2725
2726     /* send wayland event to client     */
2727     if ((to >= 0) && (usurf->shsurf != NULL) && (manager !=0) &&
2728         (usurf->width > 0) && (usurf->height > 0))  {
2729         if ((usurf->width != usurf->conf_width) ||
2730             (usurf->height != usurf->conf_height))  {
2731             usurf->conf_width = usurf->width;
2732             usurf->conf_height = usurf->height;
2733             uifw_trace("win_mgr_change_surface: SURFACE_CONFIGURE %08x(%08x),w/h=%d/%d ",
2734                        usurf->surfaceid, (int)es, usurf->width, usurf->height);
2735             ico_ivi_shell_send_configure(es,
2736                                          WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,
2737                                          usurf->width, usurf->height);
2738         }
2739     }
2740
2741     if (usurf->visible) {
2742         x = usurf->node_tbl->disp_x + usurf->x;
2743         y = usurf->node_tbl->disp_y + usurf->y;
2744     }
2745     else    {
2746         x = ICO_IVI_MAX_COORDINATE+1;
2747         y = ICO_IVI_MAX_COORDINATE+1;
2748     }
2749     /* change geometry if request from manager  */
2750     if (manager)    {
2751         if ((usurf->width != es->geometry.width) ||
2752             (usurf->height != es->geometry.height) ||
2753             (es->geometry.x != (float)x) || (es->geometry.y != (float)y))   {
2754             win_mgr_surface_configure(usurf, (float)x, (float)y, usurf->width, usurf->height);
2755             repaint ++;
2756         }
2757     }
2758
2759     /* send manager event to HomeScreen */
2760     if (to <= 0)    {
2761         if (manager)    {
2762             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
2763                                     usurf, usurf->x, usurf->y,
2764                                     usurf->width, usurf->height, 0);
2765         }
2766         else    {
2767             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
2768                                     usurf, (int)es->geometry.x, (int)es->geometry.y,
2769                                     es->geometry.width, es->geometry.height, 1);
2770         }
2771     }
2772
2773     /* change geometry if request from client   */
2774     if (! manager)  {
2775         if ((usurf->width != es->geometry.width) || (usurf->height != es->geometry.height) ||
2776             (es->geometry.x != (float)x) || (es->geometry.y != (float)y))   {
2777             win_mgr_surface_configure(usurf, x, y, usurf->width, usurf->height);
2778             repaint ++;
2779         }
2780     }
2781
2782     if (repaint)    {
2783         uifw_trace("win_mgr_change_surface: repaint");
2784         weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
2785     }
2786     uifw_trace("win_mgr_change_surface: Leave(OK)");
2787 }
2788
2789 /*--------------------------------------------------------------------------*/
2790 /**
2791  * @brief   win_mgr_surface_configure: UIFW surface configure
2792  *
2793  * @param[in]   usurf       UIFW surface
2794  * @param[in]   x           X coordinate on screen
2795  * @param[in]   y           Y coordinate on screen
2796  * @param[in]   width       surface width
2797  * @param[in]   height      surface height
2798  * @return      none
2799  */
2800 /*--------------------------------------------------------------------------*/
2801 static void
2802 win_mgr_surface_configure(struct uifw_win_surface *usurf,
2803                           int x, int y, int width, int height)
2804 {
2805     struct weston_surface   *es;
2806
2807     es = usurf->surface;
2808     if ((es != NULL) && (es->buffer_ref.buffer))  {
2809         if (usurf->client_width == 0)   {
2810             usurf->client_width = es->geometry.width;
2811             if (usurf->client_width == 0)
2812                 usurf->client_width = weston_surface_buffer_width(es);
2813         }
2814         if (usurf->client_height == 0)  {
2815             usurf->client_height = es->geometry.height;
2816             if (usurf->client_height == 0)
2817                 usurf->client_height = weston_surface_buffer_height(es);
2818         }
2819
2820         /* not set geometry width/height    */
2821         win_mgr_set_scale(usurf);
2822         weston_surface_set_position(es, x + usurf->xadd, y + usurf->yadd);
2823     }
2824 }
2825
2826 /*--------------------------------------------------------------------------*/
2827 /**
2828  * @brief   win_mgr_shell_configure: shell surface configure
2829  *
2830  * @param[in]   surface     Weston surface
2831  * @return      none
2832  */
2833 /*--------------------------------------------------------------------------*/
2834 static void
2835 win_mgr_shell_configure(struct weston_surface *surface)
2836 {
2837     struct uifw_win_surface *usurf;
2838     int     buf_width;
2839     int     buf_height;
2840
2841     uifw_trace("win_mgr_shell_configure: Enter(%08x)", (int)surface);
2842
2843     /* Find UIFW surface        */
2844     usurf = find_uifw_win_surface_by_ws(surface);
2845     if (! usurf) {
2846         uifw_trace("win_mgr_shell_configure: Leave(Not Exist)");
2847         return;
2848     }
2849
2850     usurf->client_width = surface->geometry.width;
2851     usurf->client_height = surface->geometry.height;
2852     buf_width = weston_surface_buffer_width(surface);
2853     buf_height = weston_surface_buffer_height(surface);
2854     uifw_trace("win_mgr_shell_configure: %08x client w/h=%d/%d buf=%d/%d",
2855                usurf->surfaceid,
2856                usurf->client_width, usurf->client_height, buf_width, buf_height);
2857     if (usurf->client_width > buf_width)    usurf->client_width = buf_width;
2858     if (usurf->client_height > buf_height)  usurf->client_height = buf_height;
2859
2860     /* send event to manager    */
2861     win_mgr_change_surface(surface, -1, 0);
2862
2863     uifw_trace("win_mgr_shell_configure: Leave");
2864 }
2865
2866 /*--------------------------------------------------------------------------*/
2867 /**
2868  * @brief   win_mgr_select_surface: select surface by Bottun/Touch
2869  *
2870  * @param[in]   surface     Weston surface
2871  * @return      none
2872  */
2873 /*--------------------------------------------------------------------------*/
2874 static void
2875 win_mgr_select_surface(struct weston_surface *surface)
2876 {
2877     struct uifw_win_surface *usurf;
2878
2879     uifw_trace("win_mgr_select_surface: Enter(%08x)", (int)surface);
2880
2881     /* find surface         */
2882     usurf = find_uifw_win_surface_by_ws(surface);
2883     if (! usurf) {
2884         uifw_trace("win_mgr_select_surface: Leave(Not Exist)");
2885         return;
2886     }
2887     if (usurf != _ico_win_mgr->active_pointer_usurf)  {
2888
2889         /* send active event to manager     */
2890         if (ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2891                                     usurf, ICO_WINDOW_MGR_ACTIVE_SELECTED, 0,0,0,0) <= 0) {
2892             uifw_trace("win_mgr_select_surface: not found manager, set active");
2893             win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
2894                                         ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2895         }
2896     }
2897     uifw_trace("win_mgr_select_surface: Leave(OK)");
2898 }
2899
2900 /*--------------------------------------------------------------------------*/
2901 /**
2902  * @brief   win_mgr_set_title: set tile name to surface
2903  *
2904  * @param[in]   surface     weston surface
2905  * @param[in]   title       title name
2906  * @return      none
2907  */
2908 /*--------------------------------------------------------------------------*/
2909 static void
2910 win_mgr_set_title(struct weston_surface *surface, const char *title)
2911 {
2912     struct uifw_win_surface *usurf;
2913
2914     uifw_trace("win_mgr_set_title: Enter(%08x) name=%s", (int)surface, title);
2915
2916     usurf = find_uifw_win_surface_by_ws(surface);
2917     if (! usurf) {
2918         uifw_trace("win_mgr_set_title: Leave(Not Exist)");
2919         return;
2920     }
2921     if (((usurf->width > 0) && (usurf->height > 0)) &&
2922         ((usurf->created == 0) ||
2923          (strncmp(title, usurf->winname, ICO_IVI_WINNAME_LENGTH-1) != 0)))    {
2924         strncpy(usurf->winname, title, ICO_IVI_WINNAME_LENGTH-1);
2925         usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
2926         if (usurf->created == 0)    {
2927             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CREATED, usurf, 0,0,0,0,0);
2928             usurf->created = 1;
2929         }
2930         else    {
2931             ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_NAME, usurf, 0,0,0,0,0);
2932         }
2933     }
2934     else    {
2935         strncpy(usurf->winname, title, ICO_IVI_WINNAME_LENGTH-1);
2936         usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
2937     }
2938     uifw_trace("win_mgr_set_title: Leave");
2939 }
2940
2941 /*--------------------------------------------------------------------------*/
2942 /**
2943  * @brief   win_mgr_surface_move: set tile name to surface
2944  *
2945  * @param[in]   surface     weston surface
2946  * @param[in]   title       title name
2947  * @return      none
2948  */
2949 /*--------------------------------------------------------------------------*/
2950 static void
2951 win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy)
2952 {
2953     struct uifw_win_surface *usurf;
2954
2955     uifw_trace("win_mgr_surface_move: Enter(%08x) x/y=%d,%d", (int)surface, *dx, *dy);
2956
2957     usurf = find_uifw_win_surface_by_ws(surface);
2958     if (! usurf) {
2959         uifw_trace("win_mgr_surface_move: Leave(Not Exist)");
2960         return;
2961     }
2962     if (usurf->visible) {
2963         *dx = usurf->node_tbl->disp_x + usurf->x;
2964         *dy = usurf->node_tbl->disp_y + usurf->y;
2965     }
2966     else    {
2967         *dx = ICO_IVI_MAX_COORDINATE+1;
2968         *dy = ICO_IVI_MAX_COORDINATE+1;
2969     }
2970     uifw_trace("win_mgr_surface_move: Leave(change to x/y=%d/%d)", *dx, *dy);
2971 }
2972
2973 /*--------------------------------------------------------------------------*/
2974 /**
2975  * @brief   ico_window_mgr_set_visible: change surface visibility
2976  *
2977  * @param[in]   usurf       UIFW surface
2978  * @param[in]   visible     visible(=1)/unvisible(0)
2979  * @return      none
2980  */
2981 /*--------------------------------------------------------------------------*/
2982 WL_EXPORT   void
2983 ico_window_mgr_set_visible(struct uifw_win_surface *usurf, const int visible)
2984 {
2985     if (visible)    {
2986         if (usurf->visible == 0)    {
2987             uifw_trace("ico_window_mgr_set_visible: Chagne to Visible(%08x)", (int)usurf);
2988             usurf->visible = 1;
2989             /* change unvisible to visible, restack surface list    */
2990             ico_window_mgr_restack_layer(usurf, 0);
2991         }
2992     }
2993     else    {
2994         if (usurf->visible != 0)    {
2995             uifw_trace("ico_window_mgr_set_visible: Chagne to Unvisible(%08x)", (int)usurf);
2996             usurf->visible = 0;
2997             /* change visible to unvisible, restack surface list    */
2998             ico_window_mgr_restack_layer(usurf, 0);
2999         }
3000     }
3001     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
3002                             usurf, usurf->visible, usurf->raise, 0, 0,0);
3003 }
3004
3005 /*--------------------------------------------------------------------------*/
3006 /**
3007  * @brief   win_mgr_set_raise: change surface raise/lower
3008  *
3009  * @param[in]   usurf       UIFW surface
3010  * @param[in]   raise       raise(=1)/lower(0)
3011  * @return      none
3012  */
3013 /*--------------------------------------------------------------------------*/
3014 static void
3015 win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise)
3016 {
3017     uifw_trace("win_mgr_set_raise: Enter(%08x,%d) layer=%x",
3018                (int)usurf, raise, (int)usurf->win_layer->layer);
3019
3020     wl_list_remove(&usurf->ivi_layer);
3021     if (raise)  {
3022         /* raise ... surface stack to top of layer          */
3023         wl_list_insert(&usurf->win_layer->surface_list, &usurf->ivi_layer);
3024         usurf->raise = 1;
3025         uifw_trace("win_mgr_set_raise: Raise Link to Top");
3026     }
3027     else    {
3028         /* Lower ... surface stack to bottom of layer       */
3029         wl_list_insert(usurf->win_layer->surface_list.prev, &usurf->ivi_layer);
3030         usurf->raise = 0;
3031         uifw_trace("win_mgr_set_raise: Lower Link to Bottom");
3032     }
3033
3034     /* rebild compositor surface list               */
3035     if (usurf->visible) {
3036         ico_window_mgr_restack_layer(usurf, 0);
3037     }
3038     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
3039                             usurf, usurf->visible, usurf->raise, 0, 0,0);
3040
3041     uifw_trace("win_mgr_set_raise: Leave");
3042 }
3043
3044 /*--------------------------------------------------------------------------*/
3045 /**
3046  * @brief   win_mgr_destroy_surface: surface destroy
3047  *
3048  * @param[in]   surface     Weston surface
3049  * @return      none
3050  */
3051 /*--------------------------------------------------------------------------*/
3052 static void
3053 win_mgr_destroy_surface(struct weston_surface *surface)
3054 {
3055     struct uifw_win_surface *usurf;
3056     struct uifw_win_surface *phash;
3057     struct uifw_win_surface *bhash;
3058     uint32_t    hash;
3059
3060     usurf = find_uifw_win_surface_by_ws(surface);
3061     if (! usurf) {
3062         uifw_trace("win_mgr_destroy_surface: UIFW surface Not Exist");
3063         return;
3064     }
3065     uifw_trace("win_mgr_destroy_surface: Enter(%08x) %08x", (int)surface, usurf->surfaceid);
3066
3067     /* unmap surface                */
3068     if (&usurf->surf_map != usurf->surf_map.next)   {
3069         uifw_unmap_surface(NULL, NULL, usurf->surfaceid);
3070     }
3071
3072     /* destroy active surface       */
3073     if (usurf == _ico_win_mgr->active_pointer_usurf)  {
3074         _ico_win_mgr->active_pointer_usurf = NULL;
3075     }
3076     if (usurf == _ico_win_mgr->active_keyboard_usurf) {
3077         _ico_win_mgr->active_keyboard_usurf = NULL;
3078     }
3079
3080     /* destroy animation extenson   */
3081     if (win_mgr_hook_animation) {
3082         (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
3083     }
3084
3085     /* delete from layer list       */
3086     wl_list_remove(&usurf->ivi_layer);
3087     ico_window_mgr_restack_layer(NULL, 0);
3088
3089     /* delete from cleint list      */
3090     wl_list_remove(&usurf->client_link);
3091
3092     /* delete from hash table       */
3093     hash = MAKE_IDHASH(usurf->surfaceid);
3094     phash = _ico_win_mgr->idhash[hash];
3095     bhash = NULL;
3096     while ((phash) && (phash != usurf)) {
3097         bhash = phash;
3098         phash = phash->next_idhash;
3099     }
3100     if (bhash)  {
3101         bhash->next_idhash = usurf->next_idhash;
3102     }
3103     else    {
3104         _ico_win_mgr->idhash[hash] = usurf->next_idhash;
3105     }
3106
3107     hash = MAKE_WSHASH(usurf->surface);
3108     phash = _ico_win_mgr->wshash[hash];
3109     bhash = NULL;
3110     while ((phash) && (phash != usurf)) {
3111         bhash = phash;
3112         phash = phash->next_wshash;
3113     }
3114     if (bhash)  {
3115         bhash->next_wshash = usurf->next_wshash;
3116     }
3117     else    {
3118         _ico_win_mgr->wshash[hash] = usurf->next_wshash;
3119     }
3120
3121     ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_DESTROYED,
3122                            usurf, 0,0,0,0,0);
3123
3124     hash = usurf->surfaceid & SURCAFE_ID_MASK;
3125     _ico_win_mgr->surfaceid_map[(hash - 1)/16] &= ~(1 << ((hash - 1) % 16));
3126
3127     free(usurf);
3128     uifw_trace("win_mgr_destroy_surface: Leave(OK)");
3129 }
3130
3131 /*--------------------------------------------------------------------------*/
3132 /**
3133  * @brief   bind_ico_win_mgr: bind Multi Window Manager from client
3134  *
3135  * @param[in]   client      client
3136  * @param[in]   data        user data(unused)
3137  * @param[in]   version     protocol version(unused)
3138  * @param[in]   id          client object id
3139  * @return      none
3140  */
3141 /*--------------------------------------------------------------------------*/
3142 static void
3143 bind_ico_win_mgr(struct wl_client *client,
3144                  void *data, uint32_t version, uint32_t id)
3145 {
3146     struct wl_resource  *add_resource;
3147     struct uifw_manager *mgr;
3148     struct uifw_client  *uclient;
3149
3150     uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
3151
3152     add_resource = wl_resource_create(client, &ico_window_mgr_interface, 1, id);
3153     if (add_resource)   {
3154         wl_resource_set_implementation(add_resource, &ico_window_mgr_implementation,
3155                                        _ico_win_mgr, unbind_ico_win_mgr);
3156     }
3157
3158     /* Create client management tabel       */
3159     uclient = find_client_from_client(client);
3160     if (! uclient)  {
3161         win_mgr_bind_client(client, NULL);
3162         uclient = find_client_from_client(client);
3163     }
3164
3165     /* Manager                              */
3166     mgr = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
3167     if (! mgr)  {
3168         uifw_error("bind_ico_win_mgr: Error, No Memory");
3169         return;
3170     }
3171     memset(mgr, 0, sizeof(struct uifw_manager));
3172     mgr->resource = add_resource;
3173     if (uclient)    {
3174         uclient->mgr = mgr;
3175     }
3176     wl_list_insert(&_ico_win_mgr->manager_list, &mgr->link);
3177
3178     uifw_trace("bind_ico_win_mgr: Leave");
3179 }
3180
3181 /*--------------------------------------------------------------------------*/
3182 /**
3183  * @brief   unbind_ico_win_mgr: unbind Multi Window Manager from client
3184  *
3185  * @param[in]   resource    client resource
3186  * @return      none
3187  */
3188 /*--------------------------------------------------------------------------*/
3189 static void
3190 unbind_ico_win_mgr(struct wl_resource *resource)
3191 {
3192     struct uifw_manager *mgr, *itmp;
3193
3194     uifw_trace("unbind_ico_win_mgr: Enter");
3195
3196     /* Remove manager from manager list */
3197     _ico_win_mgr->num_manager = 0;
3198     wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link)    {
3199         if (mgr->resource == resource) {
3200             wl_list_remove(&mgr->link);
3201             free(mgr);
3202         }
3203         else    {
3204             if (mgr->manager)   {
3205                 _ico_win_mgr->num_manager++;
3206             }
3207         }
3208     }
3209     uifw_trace("unbind_ico_win_mgr: Leave");
3210 }
3211
3212 /*--------------------------------------------------------------------------*/
3213 /**
3214  * @brief   ico_win_mgr_send_to_mgr: send event to manager(HomeScreen)
3215  *
3216  * @param[in]   event       event code(if -1, not send event)
3217  * @param[in]   usurf       UIFW surface table
3218  * @param[in]   param1      parameter 1
3219  * @param[in]      :             :
3220  * @param[in]   param5      parameter 5
3221  * @return      number of managers
3222  * @retval      > 0         number of managers
3223  * @retval      0           manager not exist
3224  */
3225 /*--------------------------------------------------------------------------*/
3226 static int
3227 ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
3228                         const int param1, const int param2, const int param3,
3229                         const int param4, const int param5)
3230 {
3231     int     num_mgr = 0;
3232     struct uifw_manager* mgr;
3233
3234     /* if appid not fix, check and fix appid    */
3235     if ((usurf != NULL) &&
3236         (usurf->uclient->fixed_appid < ICO_WINDOW_MGR_APPID_FIXCOUNT)) {
3237         win_mgr_get_client_appid(usurf->uclient);
3238     }
3239
3240     /* send created if not send created event   */
3241     if ((usurf != NULL) && (usurf->created == 0) &&
3242         (((usurf->width > 0) && (usurf->height > 0)) ||
3243          ((event != ICO_WINDOW_MGR_WINDOW_CREATED) &&
3244           (event != ICO_WINDOW_MGR_WINDOW_NAME))))  {
3245         wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
3246             if (mgr->manager)   {
3247                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_CREATED"
3248                            "(surf=%08x,name=%s,pid=%d,appid=%s)", (int)mgr->resource,
3249                            usurf->surfaceid, usurf->winname, usurf->uclient->pid,
3250                            usurf->uclient->appid);
3251                 ico_window_mgr_send_window_created(mgr->resource, usurf->surfaceid,
3252                                                    usurf->winname, usurf->uclient->pid,
3253                                                    usurf->uclient->appid);
3254             }
3255         }
3256         usurf->created = 1;
3257     }
3258
3259     wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link)   {
3260         if (mgr->manager)   {
3261             num_mgr ++;
3262
3263             switch(event)   {
3264             case ICO_WINDOW_MGR_WINDOW_CREATED:
3265                 /* Do nothing anymore because sended window create event    */
3266                 break;
3267
3268             case ICO_WINDOW_MGR_WINDOW_NAME:
3269                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_NAME"
3270                            "(surf=%08x,name=%s)", (int)mgr->resource,
3271                            usurf->surfaceid, usurf->winname);
3272                 ico_window_mgr_send_window_name(mgr->resource, usurf->surfaceid,
3273                                                 usurf->winname);
3274                 break;
3275
3276             case ICO_WINDOW_MGR_WINDOW_DESTROYED:
3277                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) DESTROYED"
3278                            "(surf=%08x)", (int)mgr->resource, usurf->surfaceid);
3279                 ico_window_mgr_send_window_destroyed(mgr->resource, usurf->surfaceid);
3280                 break;
3281
3282             case ICO_WINDOW_MGR_WINDOW_VISIBLE:
3283                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) VISIBLE"
3284                            "(surf=%08x,vis=%d,raise=%d,hint=%d)",
3285                            (int)mgr->resource, usurf->surfaceid, param1, param2, param3);
3286                 ico_window_mgr_send_window_visible(mgr->resource,
3287                                                    usurf->surfaceid, param1, param2, param3);
3288                 break;
3289
3290             case ICO_WINDOW_MGR_WINDOW_CONFIGURE:
3291                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) CONFIGURE"
3292                            "(surf=%08x,app=%s,node=%x,layer=%x,x/y=%d/%d,w/h=%d/%d,hint=%d)",
3293                            (int)mgr->resource, usurf->surfaceid, usurf->uclient->appid,
3294                            usurf->node_tbl->node, usurf->win_layer->layer,
3295                            param1, param2, param3, param4, param5);
3296                 ico_window_mgr_send_window_configure(mgr->resource, usurf->surfaceid,
3297                                                      usurf->node_tbl->node,
3298                                                      usurf->win_layer->layer,
3299                                                      param1, param2, param3, param4, param5);
3300                 break;
3301
3302             case ICO_WINDOW_MGR_WINDOW_ACTIVE:
3303                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) ACTIVE"
3304                            "(surf=%08x,active=%d)", (int)mgr->resource, usurf->surfaceid,
3305                            param1);
3306                 ico_window_mgr_send_window_active(mgr->resource, usurf->surfaceid,
3307                                                   (uint32_t)param1);
3308                 break;
3309
3310             case ICO_WINDOW_MGR_LAYER_VISIBLE:
3311                 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) LAYER_VISIBLE"
3312                            "(layer=%x,visivle=%d)", (int)mgr->resource, param1, param2);
3313                 ico_window_mgr_send_layer_visible(mgr->resource, (uint32_t)param1, param2);
3314                 break;
3315
3316             default:
3317                 uifw_error("ico_win_mgr_send_to_mgr: Illegal event(%08x)", event);
3318                 break;
3319             }
3320         }
3321     }
3322     return num_mgr;
3323 }
3324
3325 /*--------------------------------------------------------------------------*/
3326 /**
3327  * @brief   win_mgr_set_scale: set surface transform scale
3328  *
3329  * @param[in]   usurf       UIFW surface
3330  * @return      chagne display
3331  * @retval      =1          change display
3332  * @retval      =0          no change
3333  */
3334 /*--------------------------------------------------------------------------*/
3335 static int
3336 win_mgr_set_scale(struct uifw_win_surface *usurf)
3337 {
3338     struct weston_surface   *es;
3339     float   scalex;
3340     float   scaley;
3341     int     ret = 0;
3342
3343     es = usurf->surface;
3344     if ((es != NULL) && (es->buffer_ref.buffer))  {
3345         if (usurf->client_width == 0)   usurf->client_width = es->geometry.width;
3346         if (usurf->client_height == 0)  usurf->client_height = es->geometry.height;
3347         scalex = (float)usurf->width / (float)usurf->client_width;
3348         scaley = (float)usurf->height / (float)usurf->client_height;
3349         uifw_debug("win_mgr_set_scale: %08x X=%4.2f(%d/%d) Y=%4.2f(%d/%d)",
3350                    usurf->surfaceid, scalex, usurf->width, usurf->client_width,
3351                    scaley, usurf->height, usurf->client_height);
3352         usurf->xadd = 0;
3353         usurf->yadd = 0;
3354         if (usurf->attributes & ICO_WINDOW_MGR_ATTR_FIXED_ASPECT)   {
3355             if (scalex > scaley)    {
3356                 scalex = scaley;
3357                 if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_LEFT) == 0)  {
3358                     usurf->xadd = (float)usurf->width - ((float)usurf->client_width * scalex);
3359                     if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_RIGHT) == 0) {
3360                         usurf->xadd /= 2;
3361                     }
3362                 }
3363             }
3364             else if (scalex < scaley)   {
3365                 scaley = scalex;
3366                 if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_TOP) == 0)   {
3367                     usurf->yadd = (float)usurf->height - ((float)usurf->client_height * scaley);
3368                     if ((usurf->attributes & ICO_WINDOW_MGR_ATTR_ALIGN_BOTTOM) == 0)    {
3369                         usurf->yadd /= 2;
3370                     }
3371                 }
3372             }
3373             uifw_trace("win_mgr_set_scale: %08x fixed aspect x/yadd=%d/%d",
3374                        usurf->surfaceid, usurf->xadd, usurf->yadd);
3375         }
3376         if ((scalex != usurf->scalex) || (scaley != usurf->scaley)) {
3377             usurf->scalex = scalex;
3378             usurf->scaley = scaley;
3379             if ((scalex != 1.0f) || (scaley != 1.0f))   {
3380                 weston_matrix_init(&usurf->transform.matrix);
3381                 weston_matrix_scale(&usurf->transform.matrix, scalex, scaley, 1.0f);
3382                 uifw_trace("win_mgr_set_scale: change scale(%d)", usurf->set_transform);
3383                 if (usurf->set_transform == 0)  {
3384                     usurf->set_transform = 1;
3385                     wl_list_init(&usurf->transform.link);
3386                     wl_list_insert(&es->geometry.transformation_list, &usurf->transform.link);
3387                 }
3388             }
3389             else if (usurf->set_transform != 0) {
3390                 uifw_trace("win_mgr_set_scale: reset transform");
3391                 usurf->set_transform = 0;
3392                 wl_list_remove(&usurf->transform.link);
3393             }
3394             weston_surface_geometry_dirty(es);
3395             weston_surface_update_transform(es);
3396             weston_surface_damage_below(es);
3397             weston_surface_damage(es);
3398             ret = 1;
3399         }
3400     }
3401     return ret;
3402 }
3403
3404 /*--------------------------------------------------------------------------*/
3405 /**
3406  * @brief   ico_window_mgr_get_uclient: get UIFW client table
3407  *
3408  * @param[in]   appid       application Id
3409  * @return      UIFW client table
3410  * @retval      !=NULL      success(UIFW client table address)
3411  * @retval      = NULL      error(appid not exist)
3412  */
3413 /*--------------------------------------------------------------------------*/
3414 WL_EXPORT   struct uifw_client *
3415 ico_window_mgr_get_uclient(const char *appid)
3416 {
3417     struct uifw_client *uclient;
3418
3419     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
3420         if (strcmp(uclient->appid, appid) == 0) {
3421             return uclient;
3422         }
3423     }
3424     return NULL;
3425 }
3426
3427 /*--------------------------------------------------------------------------*/
3428 /**
3429  * @brief   ico_window_mgr_get_client_usurf: get client UIFW surface table
3430  *
3431  * @param[in]   target      surface window name and application Id(winname@appid)
3432  * @return      UIFW surface table
3433  * @retval      !=NULL      success(UIFW surface table address)
3434  * @retval      = NULL      error(appid or winname not exist)
3435  */
3436 /*--------------------------------------------------------------------------*/
3437 WL_EXPORT   struct uifw_win_surface *
3438 ico_window_mgr_get_client_usurf(const char *target)
3439 {
3440     struct uifw_client      *uclient;
3441     struct uifw_win_surface *usurf;
3442     int     i, j;
3443     char    winname[ICO_IVI_WINNAME_LENGTH];
3444     char    appid[ICO_IVI_APPID_LENGTH];
3445
3446     /* get window name and application id   */
3447     j = 0;
3448     for (i = 0; target[i]; i++) {
3449         if (target[i] == '@')   {
3450             if (target[i+1] != '@') break;
3451             i ++;
3452         }
3453         if (j < (ICO_IVI_WINNAME_LENGTH-1)) {
3454             winname[j++] = target[i];
3455         }
3456     }
3457     winname[j] = 0;
3458     if (target[i] == '@')   {
3459         i ++;
3460     }
3461     else    {
3462         winname[0] = 0;
3463         i = 0;
3464     }
3465     j = 0;
3466     for ( ; target[i]; i++) {
3467         if ((target[i] == '@') && (target[i+1] == '@')) i ++;
3468         if (j < (ICO_IVI_APPID_LENGTH-1))  {
3469             appid[j++] = target[i];
3470         }
3471     }
3472     appid[j] = 0;
3473 #if 0           /* too many debug log   */
3474     uifw_debug("ico_window_mgr_get_client_usurf: target=<%s> appid=<%s> win=<%s>",
3475                target, appid, winname);
3476 #endif
3477
3478     wl_list_for_each (uclient, &_ico_win_mgr->client_list, link)    {
3479         if (strcmp(uclient->appid, appid) == 0) {
3480             wl_list_for_each (usurf, &uclient->surface_link, client_link)   {
3481                 if ((winname[0] == 0) ||
3482                     (strcmp(winname, usurf->winname) == 0)) {
3483                     return usurf;
3484                 }
3485             }
3486         }
3487     }
3488     return NULL;
3489 }
3490
3491 /*--------------------------------------------------------------------------*/
3492 /**
3493  * @brief   ico_window_mgr_set_hook_animation: set animation hook routine
3494  *
3495  * @param[in]   hook_animation  hook routine
3496  * @return      none
3497  */
3498 /*--------------------------------------------------------------------------*/
3499 WL_EXPORT   void
3500 ico_window_mgr_set_hook_animation(int (*hook_animation)(const int op, void *data))
3501 {
3502     win_mgr_hook_animation = hook_animation;
3503 }
3504
3505 /*--------------------------------------------------------------------------*/
3506 /**
3507  * @brief   module_init: initialize ico_window_mgr
3508  *                       this function called from ico_pluign_loader
3509  *
3510  * @param[in]   es          weston compositor
3511  * @param[in]   argc        number of arguments(unused)
3512  * @param[in]   argv        argument list(unused)
3513  * @return      result
3514  * @retval      0           sccess
3515  * @retval      -1          error
3516  */
3517 /*--------------------------------------------------------------------------*/
3518 WL_EXPORT   int
3519 module_init(struct weston_compositor *ec, int *argc, char *argv[])
3520 {
3521     int     nodeId;
3522     int     i;
3523     int     idx;
3524     char    *p;
3525     struct weston_output *output;
3526     struct weston_config_section *section;
3527     char    *displayno = NULL;
3528
3529     uifw_info("ico_window_mgr: Enter(module_init)");
3530
3531     /* get ivi debug level                      */
3532     section = weston_config_get_section(ec->config, "ivi-debug", NULL, NULL);
3533     if (section)    {
3534         weston_config_section_get_int(section, "flag", &_ico_ivi_debug_flag, 0);
3535         weston_config_section_get_int(section, "log", &_ico_ivi_debug_level, 3);
3536     }
3537
3538     /* get display number list                  */
3539     section = weston_config_get_section(ec->config, "ivi-display", NULL, NULL);
3540     if (section)    {
3541         weston_config_section_get_string(section, "displayno", &displayno, NULL);
3542     }
3543
3544     /* get layer id                             */
3545     section = weston_config_get_section(ec->config, "ivi-layer", NULL, NULL);
3546     if (section)    {
3547         weston_config_section_get_int(section, "default", &_ico_ivi_default_layer, 1);
3548         weston_config_section_get_int(section, "startup", &_ico_ivi_startup_layer, 109);
3549         weston_config_section_get_int(section, "input", &_ico_ivi_input_layer, 101);
3550         weston_config_section_get_int(section, "cursor", &_ico_ivi_cursor_layer, 102);
3551         weston_config_section_get_int(section, "background", &_ico_ivi_background_layer, 0);
3552     }
3553
3554     /* get animation default                    */
3555     section = weston_config_get_section(ec->config, "ivi-animation", NULL, NULL);
3556     if (section)    {
3557         weston_config_section_get_string(section, "default", &_ico_ivi_animation_name, NULL);
3558         weston_config_section_get_int(section, "time", &_ico_ivi_animation_time, 600);
3559         weston_config_section_get_int(section, "fps", &_ico_ivi_animation_fps, 15);
3560     }
3561     if (_ico_ivi_animation_time < 100)  _ico_ivi_animation_time = 600;
3562     if (_ico_ivi_animation_fps < 2)     _ico_ivi_animation_fps = 15;
3563
3564     /* create ico_window_mgr management table   */
3565     _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
3566     if (_ico_win_mgr == NULL)   {
3567         uifw_error("ico_window_mgr: malloc failed");
3568         return -1;
3569     }
3570
3571     memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
3572     _ico_win_mgr->surfaceid_map = (uint16_t *) malloc(INIT_SURFACE_IDS/8);
3573     if (! _ico_win_mgr->surfaceid_map)  {
3574         uifw_error("ico_window_mgr: malloc failed");
3575         return -1;
3576     }
3577     uifw_debug("ico_window_mgr: table=%08x", (int)_ico_win_mgr);
3578     memset(_ico_win_mgr->surfaceid_map, 0, INIT_SURFACE_IDS/8);
3579
3580     _ico_win_mgr->compositor = ec;
3581
3582     _ico_win_mgr->surfaceid_max = INIT_SURFACE_IDS;
3583     _ico_win_mgr->surfaceid_count = INIT_SURFACE_IDS;
3584
3585     uifw_trace("ico_window_mgr: wl_global_create(bind_ico_win_mgr)");
3586     if (wl_global_create(ec->wl_display, &ico_window_mgr_interface, 1,
3587                          _ico_win_mgr, bind_ico_win_mgr) == NULL)  {
3588         uifw_error("ico_window_mgr: Error(wl_global_create)");
3589         return -1;
3590     }
3591
3592     wl_list_init(&_ico_win_mgr->client_list);
3593     wl_list_init(&_ico_win_mgr->manager_list);
3594     wl_list_init(&_ico_win_mgr->ivi_layer_list);
3595     wl_list_init(&_ico_win_mgr->map_list);
3596
3597     _ico_win_mgr->free_maptable = NULL;
3598
3599     /* create display list                  */
3600     if (displayno != NULL)   {
3601         p = displayno;
3602     }
3603     else    {
3604         p = NULL;
3605     }
3606     _ico_num_nodes = 0;
3607     wl_list_for_each(output, &ec->output_list, link) {
3608         wl_list_init(&_ico_win_mgr->map_animation[_ico_num_nodes].link);
3609         _ico_win_mgr->map_animation[_ico_num_nodes].frame = win_mgr_check_surfacemap;
3610         wl_list_insert(output->animation_list.prev,
3611                        &_ico_win_mgr->map_animation[_ico_num_nodes].link);
3612         _ico_num_nodes++;
3613         if (_ico_num_nodes >= ICO_IVI_MAX_DISPLAY)   break;
3614     }
3615     memset(&_ico_node_table[0], 0, sizeof(_ico_node_table));
3616     i = 0;
3617     wl_list_for_each(output, &ec->output_list, link) {
3618         p = strtok(p, ",");
3619         if (p)  {
3620             idx = strtol(p, (char **)0, 0);
3621             uifw_trace("ico_window_mgr: config Display.%d is %d", i, idx);
3622             p = NULL;
3623             if ((idx < 0) || (idx >= _ico_num_nodes))   {
3624                 idx = i;
3625             }
3626         }
3627         else    {
3628             idx = i;
3629         }
3630         if (_ico_node_table[idx].node)  {
3631             for (idx = 0; idx < _ico_num_nodes; idx++)  {
3632                 if (_ico_node_table[idx].node == 0) break;
3633             }
3634             if (idx >= _ico_num_nodes)  {
3635                 uifw_error("ico_window_mgr: number of display overflow");
3636                 idx = 0;
3637             }
3638         }
3639         _ico_node_table[idx].node = idx + 0x100;
3640         _ico_node_table[idx].displayno = i;
3641         _ico_node_table[idx].disp_x = output->x;
3642         _ico_node_table[idx].disp_y = output->y;
3643         _ico_node_table[idx].disp_width = output->width;
3644         _ico_node_table[idx].disp_height = output->height;
3645         i ++;
3646         if (i >= _ico_num_nodes) break;
3647     }
3648     idx = 0;
3649     for (i = 0; i < _ico_num_nodes; i++)    {
3650         _ico_node_table[i].node &= 0x0ff;
3651         uifw_trace("ico_window_mgr: Display.%d no=%d x/y=%d/%d w/h=%d/%d",
3652                    i, _ico_node_table[i].displayno,
3653                    _ico_node_table[i].disp_x, _ico_node_table[i].disp_y,
3654                    _ico_node_table[i].disp_width, _ico_node_table[i].disp_height);
3655     }
3656     if (displayno)  free(displayno);
3657
3658     /* my node Id ... this version fixed 0  */
3659     nodeId = ico_ivi_get_mynode();
3660
3661     _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
3662     uifw_trace("ico_window_mgr: NoedId=%04x SurfaceIdBase=%08x",
3663                 nodeId, _ico_win_mgr->surface_head);
3664
3665     /* Hook to IVI-Shell                            */
3666     ico_ivi_shell_hook_bind(win_mgr_bind_client);
3667     ico_ivi_shell_hook_unbind(win_mgr_unbind_client);
3668     ico_ivi_shell_hook_create(win_mgr_register_surface);
3669     ico_ivi_shell_hook_destroy(win_mgr_destroy_surface);
3670     ico_ivi_shell_hook_map(win_mgr_map_surface);
3671     ico_ivi_shell_hook_configure(win_mgr_shell_configure);
3672     ico_ivi_shell_hook_select(win_mgr_select_surface);
3673     ico_ivi_shell_hook_title(win_mgr_set_title);
3674     ico_ivi_shell_hook_move(win_mgr_surface_move);
3675
3676     uifw_info("ico_window_mgr: animation name=%s time=%d fps=%d",
3677               _ico_ivi_animation_name, _ico_ivi_animation_time, _ico_ivi_animation_fps);
3678     uifw_info("ico_window_mgr: layer default=%d startup=%d background=%d",
3679               _ico_ivi_default_layer, _ico_ivi_startup_layer, _ico_ivi_background_layer);
3680     uifw_info("ico_window_mgr: layer input=%d cursor=%d",
3681               _ico_ivi_input_layer, _ico_ivi_cursor_layer);
3682     uifw_info("ico_window_mgr: debug flag=%x log level=%d",
3683               _ico_ivi_debug_flag, _ico_ivi_debug_level);
3684
3685     uifw_info("ico_window_mgr: Leave(module_init)");
3686
3687     return 0;
3688 }
3689