64d7a0f93d8f0db9d755d5e70d0af0d0a6cd21e6
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_ivi_shell.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   Weston(Wayland) IVI Shell
26  * @brief   Shell for IVI(In-Vehicle Infotainment).
27  *
28  * @date    Feb-08-2013
29  */
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdbool.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <linux/input.h>
37 #include <assert.h>
38 #include <signal.h>
39 #include <math.h>
40 #include <sys/types.h>
41 #include <sys/time.h>
42 #include <time.h>
43
44 #include <wayland-server.h>
45 #include <weston/compositor.h>
46 #include "ico_ivi_common.h"
47 #include "ico_ivi_shell.h"
48 #include "ico_ivi_shell-server-protocol.h"
49
50 /* Layer management                 */
51 struct  ivi_layer_list  {
52     int     layer;                  /* Layer.ID                             */
53     int     visible;
54     struct wl_list surface_list;    /* Surfacae list                        */
55     struct wl_list link;            /* Link pointer for layer list          */
56 };
57
58 /* Static table for Shell           */
59 struct shell_surface;
60 struct ivi_shell {
61     struct weston_compositor *compositor;
62     struct wl_listener destroy_listener;
63     struct weston_layer surface;            /* Surface list                 */
64     struct ivi_layer_list ivi_layer;        /* Layer list                   */
65     char win_animation[ICO_WINDOW_ANIMATION_LEN];
66                                             /* Default animation name       */
67     int win_animation_time;                 /* animation time(ms)           */
68     int win_animation_fps;                  /* animation frame rate(fps)    */
69     int win_visible_on_create;              /* Visible on create surface    */
70     struct shell_surface *active_pointer_shsurf;
71                                             /* Pointer active shell surface */
72     struct shell_surface *active_keyboard_shsurf;
73                                             /* Keyboard active shell surface*/
74 };
75
76 /* Surface type                     */
77 enum shell_surface_type {
78     SHELL_SURFACE_NONE,             /* Surface type undefine                */
79     SHELL_SURFACE_TOPLEVEL,         /* Top level surface for application    */
80     SHELL_SURFACE_TRANSIENT,        /* Child surface                        */
81     SHELL_SURFACE_FULLSCREEN,       /* Full screen surface                  */
82     SHELL_SURFACE_MAXIMIZED,        /* maximum screen                       */
83     SHELL_SURFACE_POPUP             /* pop up screen                        */
84 };
85
86 /* Shell surface table              */
87 struct shell_surface {
88     struct wl_resource  resource;
89
90     struct weston_surface *surface;
91     struct wl_listener surface_destroy_listener;
92     struct weston_surface *parent;
93     struct ivi_shell *shell;
94
95     enum    shell_surface_type type;
96     enum    shell_surface_type next_type;
97     char    *title;
98     char    *class;
99
100     int     geometry_x;
101     int     geometry_y;
102     int     geometry_width;
103     int     geometry_height;
104     char    visible;
105     char    mapped;
106     char    noconfigure;
107     char    restrain;
108     struct ivi_layer_list *layer_list;
109     struct wl_list        ivi_layer;
110
111     struct {
112         unsigned short  x;
113         unsigned short  y;
114         unsigned short  width;
115         unsigned short  height;
116     }       configure_app;
117
118     struct {
119         struct weston_transform transform;
120         struct weston_matrix rotation;
121     } rotation;
122
123     struct {
124         int32_t  x;
125         int32_t  y;
126         uint32_t flags;
127     } transient;
128
129     struct wl_list link;
130     struct wl_client    *wclient;
131     const struct weston_shell_client *client;
132 };
133
134 static struct ivi_shell *default_shell = NULL;
135
136
137 /* static function prototype    */
138 static void bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id);
139 static void unbind_shell(struct wl_resource *resource);
140 static struct shell_surface *get_shell_surface(struct weston_surface *surface);
141 static struct ivi_shell *shell_surface_get_shell(struct shell_surface *shsurf);
142 static void ivi_shell_restack_ivi_layer(struct ivi_shell *shell,
143                                         struct shell_surface *shsurf);
144
145 static void (*shell_hook_bind)(struct wl_client *client) = NULL;
146 static void (*shell_hook_unbind)(struct wl_client *client) = NULL;
147 static void (*shell_hook_create)(struct wl_client *client, struct wl_resource *resource,
148                                  struct weston_surface *surface,
149                                  struct shell_surface *shsurf) = NULL;
150 static void (*shell_hook_destroy)(struct weston_surface *surface) = NULL;
151 static void (*shell_hook_map)(struct weston_surface *surface, int32_t *width,
152                               int32_t *height, int32_t *sx, int32_t *sy) = NULL;
153 static void (*shell_hook_change)(struct weston_surface *surface, const int to,
154                                  const int manager) = NULL;
155 static void (*shell_hook_select)(struct weston_surface *surface) = NULL;
156
157
158 /*--------------------------------------------------------------------------*/
159 /**
160  * @brief   shell_configuration: initiale configuration ico_ivi_shell
161  *
162  * @param[in]   shell   ico_ivi_shell static table area
163  * @return      none
164  */
165 /*--------------------------------------------------------------------------*/
166 static void
167 shell_configuration(struct ivi_shell *shell)
168 {
169     int     config_fd;
170     char    *win_animation = NULL;
171     int     win_animation_time = 800;
172     int     win_animation_fps = 15;
173
174     struct config_key shell_keys[] = {
175         { "animation",          CONFIG_KEY_STRING, &win_animation },
176         { "animation_time",     CONFIG_KEY_INTEGER, &win_animation_time },
177         { "animation_fps",      CONFIG_KEY_INTEGER, &win_animation_fps },
178         { "visible_on_create",  CONFIG_KEY_INTEGER, &shell->win_visible_on_create },
179     };
180
181     struct config_section cs[] = {
182         { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
183     };
184
185     config_fd = open_config_file(ICO_IVI_PLUGIN_CONFIG);
186     parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), shell);
187     close(config_fd);
188
189     if (win_animation)  {
190         strncpy(shell->win_animation, win_animation, sizeof(shell->win_animation)-1);
191     }
192     if (win_animation_time < 100)   win_animation_time = 100;
193     shell->win_animation_time = win_animation_time;
194     if (win_animation_fps > 30)     win_animation_fps = 30;
195     if (win_animation_fps < 5)      win_animation_fps = 5;
196     shell->win_animation_fps = win_animation_fps;
197     uifw_info("shell_configuration: Anima=%s,%dms,%dfps Visible=%d Debug=%d",
198               shell->win_animation, shell->win_animation_time, shell->win_animation_fps,
199               shell->win_visible_on_create, ico_ivi_debuglevel());
200 }
201
202 /*--------------------------------------------------------------------------*/
203 /**
204  * @brief   send_configure: send configure(resize) event to client applicstion
205  *
206  * @param[in]   surface     weston surface
207  * @param[in]   edges       surface resize position
208  * @param[in]   width       surface width
209  * @param[in]   height      surface height
210  * @return      none
211  */
212 /*--------------------------------------------------------------------------*/
213 static void
214 send_configure(struct weston_surface *surface,
215                uint32_t edges, int32_t width, int32_t height)
216 {
217     struct shell_surface *shsurf = get_shell_surface(surface);
218
219     uifw_trace("send_configure: %08x edges=%x w/h=%d/%d map=%d",
220                (int)shsurf->surface, edges, width, height, shsurf->mapped);
221     if (shsurf->mapped == 0)    return;
222
223     shsurf->configure_app.width = width;
224     shsurf->configure_app.height = height;
225     wl_shell_surface_send_configure(&shsurf->resource,
226                                     edges, width, height);
227 }
228
229 static const struct weston_shell_client shell_client = {
230     send_configure
231 };
232
233 /*--------------------------------------------------------------------------*/
234 /**
235  * @brief   reset_shell_surface_type: reset surface type
236  *
237  * @param[in]   shsurf      shell surface
238  * @return      always 0
239  */
240 /*--------------------------------------------------------------------------*/
241 static int
242 reset_shell_surface_type(struct shell_surface *shsurf)
243 {
244     uifw_trace("reset_shell_surface_type: [%08x]", (int)shsurf);
245     shsurf->type = SHELL_SURFACE_NONE;
246     return 0;
247 }
248
249 /*--------------------------------------------------------------------------*/
250 /**
251  * @brief   set_surface_type: set surface type
252  *
253  * @param[in]   shsurf      shell surface
254  * @return      none
255  */
256 /*--------------------------------------------------------------------------*/
257 static void
258 set_surface_type(struct shell_surface *shsurf)
259 {
260     struct weston_surface *surface = shsurf->surface;
261     struct weston_surface *pes = shsurf->parent;
262     struct shell_surface *psh;
263
264     uifw_trace("set_surface_type: [%08x] (%08x) type=%x",
265                (int)shsurf, (int)surface, (int)shsurf->next_type);
266
267     reset_shell_surface_type(shsurf);
268
269     shsurf->type = shsurf->next_type;
270     shsurf->next_type = SHELL_SURFACE_NONE;
271
272     switch (shsurf->type) {
273     case SHELL_SURFACE_TOPLEVEL:
274         break;
275     case SHELL_SURFACE_TRANSIENT:
276         psh = get_shell_surface(pes);
277         if (psh)    {
278             shsurf->geometry_x = psh->geometry_x + shsurf->transient.x;
279             shsurf->geometry_y = psh->geometry_y + shsurf->transient.y;
280         }
281         else    {
282             shsurf->geometry_x = pes->geometry.x + shsurf->transient.x;
283             shsurf->geometry_y = pes->geometry.y + shsurf->transient.y;
284         }
285         break;
286     default:
287         break;
288     }
289 }
290
291 /*--------------------------------------------------------------------------*/
292 /**
293  * @brief   shell_surface_pong: recceive pong(ping reply) (NOP)
294  *
295  * @param[in]   client      wayland client
296  * @param[in]   resource    pong resource
297  * @param[in]   serial      event serial number
298  * @return      none
299  */
300 /*--------------------------------------------------------------------------*/
301 static void
302 shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
303 {
304     uifw_trace("shell_surface_pong: NOP[%08x]", (int)resource->data);
305 }
306
307 /*--------------------------------------------------------------------------*/
308 /**
309  * @brief   shell_surface_move: recceive move request (NOP)
310  *
311  * @param[in]   client          wayland client
312  * @param[in]   resource        move request resource
313  * @param[in]   seat_resource   seat resource
314  * @param[in]   serial          event serial number
315  * @return      none
316  */
317 /*--------------------------------------------------------------------------*/
318 static void
319 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
320                    struct wl_resource *seat_resource, uint32_t serial)
321 {
322     uifw_trace("shell_surface_move: [%08x] NOP", (int)resource->data);
323 }
324
325 /*--------------------------------------------------------------------------*/
326 /**
327  * @brief   shell_surface_resize: recceive resize request (NOP)
328  *
329  * @param[in]   client          wayland client
330  * @param[in]   resource        resize request resource
331  * @param[in]   seat_resource   seat resource
332  * @param[in]   serial          event serial number
333  * @param[in]   edges           resize position
334  * @return      none
335  */
336 /*--------------------------------------------------------------------------*/
337 static void
338 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
339                      struct wl_resource *seat_resource, uint32_t serial,
340                      uint32_t edges)
341 {
342     uifw_trace("shell_surface_resize: [%08x] NOP", (int)resource->data);
343 }
344
345 /*--------------------------------------------------------------------------*/
346 /**
347  * @brief   set_toplevel: set surface to TopLevel
348  *
349  * @param[in]   shsurf          shell surface
350  * @return      none
351  */
352 /*--------------------------------------------------------------------------*/
353 static void
354 set_toplevel(struct shell_surface *shsurf)
355 {
356     shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
357 }
358
359 /*--------------------------------------------------------------------------*/
360 /**
361  * @brief   shell_surface_set_toplevel: set surface to TopLevel(client interface)
362  *
363  * @param[in]   client          wayland client
364  * @param[in]   resource        set toplevel request resource
365  * @return      none
366  */
367 /*--------------------------------------------------------------------------*/
368 static void
369 shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *resource)
370 {
371     struct shell_surface *shsurf = resource->data;
372
373     uifw_trace("shell_surface_set_toplevel: Set TopLevel[%08x] surf=%08x",
374                (int)shsurf, (int)shsurf->surface);
375
376     set_toplevel(shsurf);
377 }
378
379 /*--------------------------------------------------------------------------*/
380 /**
381  * @brief   set_transient: set surface to child
382  *
383  * @param[in]   shsurf          shell surface
384  * @param[in]   parent          parent surface
385  * @param[in]   x               relative X position from a parent
386  * @param[in]   y               relative Y position from a parent
387  * @param[in]   flags           flag(unused)
388  * @return      none
389  */
390 /*--------------------------------------------------------------------------*/
391 static void
392 set_transient(struct shell_surface *shsurf,
393               struct weston_surface *parent, int x, int y, uint32_t flags)
394 {
395     /* assign to parents output */
396     shsurf->parent = parent;
397     shsurf->transient.x = x;
398     shsurf->transient.y = y;
399     shsurf->transient.flags = flags;
400     shsurf->next_type = SHELL_SURFACE_TRANSIENT;
401 }
402
403 /*--------------------------------------------------------------------------*/
404 /**
405  * @brief   shell_surface_set_transient: set surface to child(client interface)
406  *
407  * @param[in]   client          wayland client
408  * @param[in]   resource        set transient request resource
409  * @param[in]   parent_resource parent surface resource
410  * @param[in]   x               relative X position from a parent
411  * @param[in]   y               relative Y position from a parent
412  * @param[in]   flags           flag(unused)
413  * @return      none
414  */
415 /*--------------------------------------------------------------------------*/
416 static void
417 shell_surface_set_transient(struct wl_client *client, struct wl_resource *resource,
418                             struct wl_resource *parent_resource,
419                             int x, int y, uint32_t flags)
420 {
421     struct shell_surface *shsurf = resource->data;
422     struct weston_surface *parent = parent_resource->data;
423
424     uifw_trace("shell_surface_set_transient: Set Transient[%08x] surf=%08x",
425                (int)shsurf, (int)shsurf->surface);
426     set_transient(shsurf, parent, x, y, flags);
427 }
428
429 /*--------------------------------------------------------------------------*/
430 /**
431  * @brief   shell_surface_set_fullscreen: set surface to full screen(same as toplevel)
432  *
433  * @param[in]   client          wayland client
434  * @param[in]   resource        set fullscreen request resource
435  * @param[in]   method          method(unused)
436  * @param[in]   framerate       frame rate(unused)
437  * @param[in]   output_resource output resource(unused)
438  * @return      none
439  */
440 /*--------------------------------------------------------------------------*/
441 static void
442 shell_surface_set_fullscreen(struct wl_client *client, struct wl_resource *resource,
443                              uint32_t method, uint32_t framerate,
444                              struct wl_resource *output_resource)
445 {
446     struct shell_surface *shsurf = resource->data;
447     uifw_trace("shell_surface_set_fullscreen: "
448                "NOP(same as set_toplevel)[%08x]", (int)shsurf);
449     shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
450 }
451
452 /*--------------------------------------------------------------------------*/
453 /**
454  * @brief   shell_surface_set_popup: set surface to popup(same as toplevel)
455  *
456  * @param[in]   client          wayland client
457  * @param[in]   resource        set popup request resource
458  * @param[in]   seat_resource   seat resource(unused)
459  * @param[in]   serial          event serial number(unused)
460  * @param[in]   parent_resource parent resource(unused)
461  * @param[in]   x               relative X position from a parent(unused)
462  * @param[in]   y               relative Y position from a parent(unused)
463  * @param[in]   flags           flag(unused)
464  * @return      none
465  */
466 /*--------------------------------------------------------------------------*/
467 static void
468 shell_surface_set_popup(struct wl_client *client, struct wl_resource *resource,
469                         struct wl_resource *seat_resource, uint32_t serial,
470                         struct wl_resource *parent_resource,
471                         int32_t x, int32_t y, uint32_t flags)
472 {
473     struct shell_surface *shsurf = resource->data;
474     uifw_trace("shell_surface_set_popup: NOP(same as set_toplevel)[%08x]", (int)shsurf);
475     shsurf->next_type = SHELL_SURFACE_POPUP;
476 }
477
478 /*--------------------------------------------------------------------------*/
479 /**
480  * @brief   shell_surface_set_maximized: set surface to maximized(same as toplevel)
481  *
482  * @param[in]   client          wayland client
483  * @param[in]   resource        set maximized request resource
484  * @param[in]   output_resource output resource(unused)
485  * @return      none
486  */
487 /*--------------------------------------------------------------------------*/
488 static void
489 shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource,
490                             struct wl_resource *output_resource )
491 {
492     struct shell_surface *shsurf = resource->data;
493     uifw_trace("shell_surface_set_maximized: NOP(same as set_toplevel)[%08x]", (int)shsurf);
494     shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
495 }
496
497 /*--------------------------------------------------------------------------*/
498 /**
499  * @brief   shell_surface_set_title: set surface title
500  *
501  * @param[in]   client      wayland client
502  * @param[in]   resource    set title request resource
503  * @param[in]   title       surface title
504  * @return      none
505  */
506 /*--------------------------------------------------------------------------*/
507 static void
508 shell_surface_set_title(struct wl_client *client,
509                         struct wl_resource *resource, const char *title)
510 {
511     struct shell_surface *shsurf = resource->data;
512
513     uifw_trace("shell_surface_set_title: [%08x] %s", (int)shsurf, title);
514
515     if (shsurf->title)  {
516         free(shsurf->title);
517     }
518     shsurf->title = strdup(title);
519 }
520
521 /*--------------------------------------------------------------------------*/
522 /**
523  * @brief   shell_surface_set_class: set surface class name
524  *
525  * @param[in]   client      wayland client
526  * @param[in]   resource    set class request resource
527  * @param[in]   class       surface class name
528  * @return      none
529  */
530 /*--------------------------------------------------------------------------*/
531 static void
532 shell_surface_set_class(struct wl_client *client,
533                         struct wl_resource *resource, const char *class)
534 {
535     struct shell_surface *shsurf = resource->data;
536
537     uifw_trace("shell_surface_set_class: [%08x] %s", (int)shsurf, class);
538
539     if (shsurf->class)  {
540         free(shsurf->class);
541     }
542     shsurf->class = strdup(class);
543 }
544
545 /*--------------------------------------------------------------------------*/
546 /**
547  * @brief   shell_surface_raise: raise surface
548  *
549  * @param[in]   client      wayland client
550  * @param[in]   resource    set class request resource
551  * @return      none
552  */
553 /*--------------------------------------------------------------------------*/
554 static void
555 shell_surface_raise(struct wl_client *client, struct wl_resource *resource)
556 {
557     struct shell_surface *shsurf = resource->data;
558
559     uifw_trace("shell_surface_raise: [%08x]", (int)shsurf);
560
561     ivi_shell_set_raise(shsurf, 1);
562 }
563
564 static const struct wl_shell_surface_interface shell_surface_implementation = {
565     shell_surface_pong,
566     shell_surface_move,
567     shell_surface_resize,
568     shell_surface_set_toplevel,
569     shell_surface_set_transient,
570     shell_surface_set_fullscreen,
571     shell_surface_set_popup,
572     shell_surface_set_maximized,
573     shell_surface_set_title,
574     shell_surface_set_class,
575     shell_surface_raise
576 };
577
578 /*--------------------------------------------------------------------------*/
579 /**
580  * @brief   shell_surface_get_shell: get ico_ivi_shell static table
581  *
582  * @param[in]   shsurf      shell surface(if NULL, return default)
583  * @return      ico_ivi_shell static table address
584  */
585 /*--------------------------------------------------------------------------*/
586 static struct ivi_shell *
587 shell_surface_get_shell(struct shell_surface *shsurf)
588 {
589     if (shsurf) {
590         return shsurf->shell;
591     }
592     return default_shell;
593 }
594
595 /*--------------------------------------------------------------------------*/
596 /**
597  * @brief   destroy_shell_surface: destroy surface
598  *
599  * @param[in]   shsurf      shell surface
600  * @return      none
601  */
602 /*--------------------------------------------------------------------------*/
603 static void
604 destroy_shell_surface(struct shell_surface *shsurf)
605 {
606     uifw_trace("destroy_shell_surface: Enter[%08x]", (int)shsurf);
607
608     if (shsurf->visible != FALSE)   {
609         shsurf->visible = FALSE;
610         ivi_shell_restack_ivi_layer(shell_surface_get_shell(shsurf), shsurf);
611     }
612
613     wl_list_remove(&shsurf->ivi_layer);
614
615     if (shell_hook_destroy) {
616         /* call sufrace destory hook routine    */
617         uifw_trace("destroy_shell_surface: call ivi_shell_hook_destroy(%08x)",
618                    (int)shsurf->surface);
619         (void) (*shell_hook_destroy) (shsurf->surface);
620         uifw_trace("destroy_shell_surface: ret");
621     }
622
623     wl_list_remove(&shsurf->surface_destroy_listener.link);
624     shsurf->surface->configure = NULL;
625
626     wl_list_remove(&shsurf->link);
627     free(shsurf);
628
629     uifw_trace("destroy_shell_surface: Leave");
630 }
631
632 /*--------------------------------------------------------------------------*/
633 /**
634  * @brief   shell_destroy_shell_surface: destroy surface(client interface)
635  *
636  * @param[in]   resource    destroy request resource
637  * @return      none
638  */
639 /*--------------------------------------------------------------------------*/
640 static void
641 shell_destroy_shell_surface(struct wl_resource *resource)
642 {
643     struct shell_surface *shsurf = resource->data;
644
645     uifw_trace("shell_destroy_shell_surface: Enter [%08x]", (int)shsurf);
646
647     destroy_shell_surface(shsurf);
648
649     uifw_trace("shell_destroy_shell_surface: Leave");
650 }
651
652 /*--------------------------------------------------------------------------*/
653 /**
654  * @brief   shell_handle_surface_destroy: destroy surface(listener interface)
655  *
656  * @param[in]   listener    listener
657  * @param[in]   data        user data(unused)
658  * @return      none
659  */
660 /*--------------------------------------------------------------------------*/
661 static void
662 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
663 {
664     struct shell_surface *shsurf = container_of(listener, struct shell_surface,
665                                                 surface_destroy_listener);
666
667     uifw_trace("shell_handle_surface_destroy: Enter [%08x] data=%08x",
668                (int)shsurf, (int)data);
669
670     if (shsurf->resource.client) {
671         wl_resource_destroy(&shsurf->resource);
672     } else {
673         wl_signal_emit(&shsurf->resource.destroy_signal, &shsurf->resource);
674         destroy_shell_surface(shsurf);
675     }
676     uifw_trace("shell_handle_surface_destroy: Leave");
677 }
678
679 static void
680 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
681
682 /*--------------------------------------------------------------------------*/
683 /**
684  * @brief   get_shell_surface: get shell surface
685  *
686  * @param[in]   surface     weston surface
687  * @return      shell surface address
688  */
689 /*--------------------------------------------------------------------------*/
690 static struct shell_surface *
691 get_shell_surface(struct weston_surface *surface)
692 {
693     if (surface->configure == shell_surface_configure)
694         return surface->private;
695     else
696         return NULL;
697 }
698
699 /*--------------------------------------------------------------------------*/
700 /**
701  * @brief   create_shell_surface: create shell surface
702  *
703  * @param[in]   surface     weston surface
704  * @param[in]   client      client
705  * @return      created shell surface address
706  */
707 /*--------------------------------------------------------------------------*/
708 static  struct shell_surface *
709 create_shell_surface(void *shell, struct weston_surface *surface,
710                      const struct weston_shell_client *client)
711 {
712     struct shell_surface *shsurf;
713
714     if (surface->configure) {
715         uifw_warn("create_shell_surface: surface->configure already set");
716         return NULL;
717     }
718
719     shsurf = calloc(1, sizeof *shsurf);
720     if (!shsurf) {
721         uifw_error("create_shell_surface: no memory to allocate shell surface");
722         return NULL;
723     }
724
725     uifw_trace("create_shell_surface: (%08x) [%08x] client=%08x (visible=%d)",
726                (int)surface, (int)shsurf, (int)client,
727                ((struct ivi_shell *)shell)->win_visible_on_create);
728
729     surface->configure = shell_surface_configure;
730     surface->private = shsurf;
731
732     shsurf->shell = (struct ivi_shell *) shell;
733     shsurf->surface = surface;
734     shsurf->visible = shsurf->shell->win_visible_on_create;
735
736     /* set default color and shader */
737     weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
738
739     wl_signal_init(&shsurf->resource.destroy_signal);
740     shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
741     wl_signal_add(&surface->surface.resource.destroy_signal,
742                   &shsurf->surface_destroy_listener);
743
744     /* init link so its safe to always remove it in destroy_shell_surface */
745     wl_list_init(&shsurf->link);
746
747     /* empty when not in use */
748     wl_list_init(&shsurf->rotation.transform.link);
749     weston_matrix_init(&shsurf->rotation.rotation);
750
751     shsurf->type = SHELL_SURFACE_NONE;
752     shsurf->next_type = SHELL_SURFACE_NONE;
753
754     shsurf->client = client;
755
756     wl_list_init(&shsurf->ivi_layer);
757
758     return shsurf;
759 }
760
761 /*--------------------------------------------------------------------------*/
762 /**
763  * @brief   shell_get_shell_surface: create shell surface(client interface)
764  *
765  * @param[in]   client              client
766  * @param[in]   resource            get shell surface request resource
767  * @param[in]   id                  created shell surface object id in the client
768  * @param[in]   surface_resource    weston surface resource
769  * @return      none
770  */
771 /*--------------------------------------------------------------------------*/
772 static void
773 shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
774                         uint32_t id, struct wl_resource *surface_resource)
775 {
776     struct weston_surface *surface = surface_resource->data;
777     struct ivi_shell *shell = resource->data;
778     struct shell_surface *shsurf;
779
780     if (get_shell_surface(surface)) {
781         wl_resource_post_error(surface_resource,
782                                WL_DISPLAY_ERROR_INVALID_OBJECT,
783                                "ivi_shell::get_shell_surface already requested");
784         return;
785     }
786
787     uifw_trace("shell_get_shell_surface: Enter (%08x) client=%08x",
788                (int)surface, (int)client);
789
790     shsurf = create_shell_surface(shell, surface, &shell_client);
791     if (!shsurf) {
792         wl_resource_post_error(surface_resource,
793                                WL_DISPLAY_ERROR_INVALID_OBJECT,
794                                "surface->configure already set");
795         return;
796     }
797
798     shsurf->wclient = client;
799     shsurf->resource.destroy = shell_destroy_shell_surface;
800     shsurf->resource.object.id = id;
801     shsurf->resource.object.interface = &wl_shell_surface_interface;
802     shsurf->resource.object.implementation =
803         (void (**)(void)) &shell_surface_implementation;
804     shsurf->resource.data = shsurf;
805
806     wl_client_add_resource(client, &shsurf->resource);
807
808     wl_list_init(&shsurf->ivi_layer);
809     uifw_trace("shell_get_shell_surface: Init shsurf(%08x) weston_surf=%08x",
810                (int)shsurf, (int)surface);
811
812     if (shell_hook_create)  {
813         /* call surface create hook routine     */
814         uifw_trace("shell_get_shell_surface: call ivi_shell_hook_create(%08x,,%08x,%08x)",
815                    (int)client, (int)surface, (int)shsurf);
816         (void) (*shell_hook_create)(client, resource, surface, shsurf);
817         uifw_trace("shell_get_shell_surface: ret  ivi_shell_hook_create");
818     }
819     uifw_trace("shell_get_shell_surface: Leave");
820 }
821
822 static const struct wl_shell_interface shell_implementation = {
823     shell_get_shell_surface
824 };
825
826 /*--------------------------------------------------------------------------*/
827 /**
828  * @brief   weston_surface_set_initial_position: set surface initial position
829  *
830  * @param[in]   surface     weston surface
831  * @param[in]   shell       ico_ivi_shell static table address
832  * @return      none
833  */
834 /*--------------------------------------------------------------------------*/
835 static void
836 weston_surface_set_initial_position(struct weston_surface *surface, struct ivi_shell *shell)
837 {
838     struct weston_output *output, *target_output;
839
840     if (shell->win_visible_on_create)   {
841         wl_list_for_each (output, &shell->compositor->output_list, link)    {
842             target_output = output;
843             break;
844         }
845         if (! target_output)    {
846             weston_surface_set_position(surface, (float)(10 + random() % 400),
847                                         (float)(10 + random() % 400));
848         }
849         else    {
850             int range_x = target_output->width - surface->geometry.width;
851             int range_y = target_output->height - surface->geometry.height;
852             if (range_x < 0)    range_x = 400;
853             if (range_y < 0)    range_y = 400;
854             weston_surface_set_position(surface, (float)(random() % range_x),
855                                         (float)(random() % range_y));
856         }
857     }
858     else    {
859         weston_surface_set_position(surface, (float)0.0, (float)0.0);
860     }
861 }
862
863 /*--------------------------------------------------------------------------*/
864 /**
865  * @brief   map: surface initial mapping to screen
866  *
867  * @param[in]   shell       ico_ivi_shell static table address
868  * @param[in]   surface     weston surface
869  * @param[in]   width       surface width
870  * @param[in]   height      surface height
871  * @param[in]   sx          surface upper-left X position on screen
872  * @param[in]   sy          surface upper-left Y position on screen
873  * @return      none
874  */
875 /*--------------------------------------------------------------------------*/
876 static void
877 map(struct ivi_shell *shell, struct weston_surface *surface,
878     int32_t width, int32_t height, int32_t sx, int32_t sy)
879 {
880     struct shell_surface *shsurf = get_shell_surface(surface);
881     enum shell_surface_type surface_type = shsurf->type;
882     struct weston_surface *parent;
883
884     uifw_trace("map: Enter(%08x) sx/sy=%d/%d, w/h=%d/%d",
885                (int)surface, ((int)sx)/256, ((int)sy)/256, width, height);
886
887     shsurf->mapped = 1;
888     surface->geometry.width = width;
889     surface->geometry.height = height;
890     shsurf->geometry_x = sx;
891     shsurf->geometry_y = sy;
892     shsurf->geometry_width = width;
893     shsurf->geometry_height = height;
894     surface->geometry.dirty = 1;
895
896     /* initial positioning, see also configure() */
897     switch (surface_type) {
898     case SHELL_SURFACE_TOPLEVEL:
899         weston_surface_set_initial_position(surface, shell);
900         uifw_trace("map: TopLevel x/y=%d/%d w/h=%d/%d",
901                    (int)surface->geometry.x, (int)surface->geometry.y,
902                    (int)surface->geometry.width, (int)surface->geometry.height);
903         shsurf->geometry_x = surface->geometry.x;
904         shsurf->geometry_x = surface->geometry.y;
905         break;
906     case SHELL_SURFACE_NONE:
907         weston_surface_set_position(surface, (float)(surface->geometry.x + sx),
908                                     (float)(surface->geometry.y + sy));
909         break;
910     default:
911         ;
912     }
913     if ((ico_option_flag() & ICO_OPTION_FLAG_UNVISIBLE) && (shsurf->visible == FALSE))   {
914         surface->geometry.x = (float)(ICO_IVI_MAX_COORDINATE+1);
915         surface->geometry.y = (float)(ICO_IVI_MAX_COORDINATE+1);
916         surface->geometry.dirty = 1;
917     }
918
919     switch (surface_type) {
920     case SHELL_SURFACE_TRANSIENT:
921         parent = shsurf->parent;
922         wl_list_insert(parent->layer_link.prev, &surface->layer_link);
923         break;
924     case SHELL_SURFACE_NONE:
925         break;
926     default:
927         if (! shsurf->layer_list)   {
928             ivi_shell_set_layer(shsurf, ICO_IVI_DEFAULT_LAYER);
929         }
930         break;
931     }
932
933     if (surface_type != SHELL_SURFACE_NONE) {
934         weston_surface_update_transform(surface);
935         ivi_shell_restack_ivi_layer(shell, shsurf);
936     }
937
938     if (shell_hook_map) {
939         /* Surface map hook routine         */
940         uifw_trace("map: call ivi_shell_hook_map(%08x, x/y=%d/%d, w/h=%d/%d)",
941                    (int)surface, sx, sy, width, height);
942         (void) (*shell_hook_map) (surface, &width, &height, &sx, &sy);
943         uifw_trace("map: ret  ivi_shell_hook_map(%08x, x/y=%d/%d, w/h=%d/%d)",
944                    (int)surface, sx, sy, width, height);
945     }
946
947     if (shell_hook_change)  {
948         /* Surface change hook routine      */
949         uifw_trace("map: call ivi_shell_hook_change(%08x)", (int)surface);
950         (void) (*shell_hook_change)(surface, -1, 1);    /* Send to Manager  */
951         uifw_trace("map: ret  ivi_shell_hook_change")
952     }
953     uifw_trace("map: Leave");
954 }
955
956 /*--------------------------------------------------------------------------*/
957 /**
958  * @brief   configure: surface change
959  *
960  * @param[in]   shell       ico_ivi_shell static table address
961  * @param[in]   surface     weston surface
962  * @param[in]   x           surface upper-left X position on screen
963  * @param[in]   y           surface upper-left Y position on screen
964  * @param[in]   width       surface width
965  * @param[in]   height      surface height
966  * @return      none
967  */
968 /*--------------------------------------------------------------------------*/
969 static void
970 configure(struct ivi_shell *shell, struct weston_surface *surface,
971           GLfloat x, GLfloat y, int32_t width, int32_t height)
972 {
973     enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
974     struct shell_surface *shsurf;
975
976     shsurf = get_shell_surface(surface);
977
978     uifw_trace("configure: Enter(%08x) [%08x] x/y=%d/%d, w/h=%d/%d",
979                (int)surface, (int)shsurf, (int)x, (int)y, width, height);
980
981     if (shsurf) {
982         surface_type = shsurf->type;
983         shsurf->geometry_x = (int)x;
984         shsurf->geometry_y = (int)y;
985         shsurf->geometry_width = width;
986         shsurf->geometry_height = height;
987         ivi_shell_surface_configure(shsurf, x, y, width, height);
988     }
989     else    {
990         weston_surface_configure(surface, x, y, width, height);
991     }
992
993     if (surface->output) {
994         weston_surface_update_transform(surface);
995     }
996
997     uifw_trace("configure: Leave");
998 }
999
1000 /*--------------------------------------------------------------------------*/
1001 /**
1002  * @brief   shell_surface_configure: shell surface change
1003  *
1004  * @param[in]   es          weston surface
1005  * @param[in]   sx          surface upper-left X position on screen
1006  * @param[in]   sy          surface upper-left Y position on screen
1007  * @return      none
1008  */
1009 /*--------------------------------------------------------------------------*/
1010 static void
1011 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1012 {
1013     struct shell_surface *shsurf = get_shell_surface(es);
1014     struct ivi_shell *shell = shsurf->shell;
1015     int     type_changed = 0;
1016     int     num_mgr;
1017     int     dx, dy, dw, dh;
1018
1019     uifw_trace("shell_surface_configure: Enter(surf=%08x out=%08x buf=%08x)",
1020                (int)es, (int)es->output, (int)es->buffer);
1021
1022     if (! es->buffer)   {
1023         uifw_trace("shell_surface_configure: Leave(no buffer)");
1024         return;
1025     }
1026     if (shsurf->restrain)   {
1027         uifw_trace("shell_surface_configure: Leave(restrain)");
1028         return;
1029     }
1030
1031     if (shsurf->next_type != SHELL_SURFACE_NONE &&
1032         shsurf->type != shsurf->next_type) {
1033         set_surface_type(shsurf);
1034         type_changed = 1;
1035     }
1036
1037     if (! weston_surface_is_mapped(es)) {
1038         if ((es->geometry.width > 0) && (es->geometry.height >0))   {
1039             uifw_trace("shell_surface_configure: map Surface size(sx/sy=%d/%d w/h=%d/%d)",
1040                        sx, sy, es->buffer->width, es->buffer->height);
1041             map(shell, es, es->geometry.width, es->geometry.height, sx, sy);
1042         }
1043         else    {
1044             uifw_trace("shell_surface_configure: map Buffer size(sx/sy=%d/%d w/h=%d/%d)",
1045                        sx, sy, es->buffer->width, es->buffer->height);
1046             map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
1047         }
1048     }
1049     else    {
1050         if (shsurf->mapped == 0)    {
1051             if ((es->geometry.width > 0) && (es->geometry.height >0))   {
1052                 uifw_trace("shell_surface_configure: map Surface size(sx/sy=%d/%d w/h=%d/%d)",
1053                            sx, sy, es->buffer->width, es->buffer->height);
1054                 map(shell, es, es->geometry.width, es->geometry.height, sx, sy);
1055             }
1056             else    {
1057                 uifw_trace("shell_surface_configure: map Buffer size(sx/sy=%d/%d w/h=%d/%d)",
1058                            sx, sy, es->buffer->width, es->buffer->height);
1059                 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
1060             }
1061         }
1062
1063         GLfloat from_x, from_y;
1064         GLfloat to_x, to_y;
1065
1066         weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
1067         weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
1068
1069         if ((es->geometry.width <= 0) || (es->geometry.height <= 0))    {
1070             num_mgr = 0;
1071         }
1072         else    {
1073             /* Surface change request from App  */
1074             uifw_trace("shell_surface_configure: App request change(sx/sy=%d/%d w/h=%d/%d)",
1075                        sx, sy, es->buffer->width, es->buffer->height);
1076             dx = shsurf->geometry_x;
1077             dy = shsurf->geometry_y;
1078             dw = shsurf->geometry_width;
1079             dh = shsurf->geometry_height;
1080             if (dw > es->buffer->width) {
1081                 dw = es->buffer->width;
1082                 dx = shsurf->geometry_x + (shsurf->geometry_width - dw)/2;
1083             }
1084             if (dh > es->buffer->height)   {
1085                 dh = es->buffer->height;
1086                 dy = shsurf->geometry_y + (shsurf->geometry_height - dh)/2;
1087             }
1088             weston_surface_configure(es, dx, dy, dw, dh);
1089             ivi_shell_surface_configure(shsurf, es->geometry.x, es->geometry.y,
1090                                         es->geometry.width, es->geometry.height);
1091             uifw_trace("shell_surface_configure: w/h=%d/%d->%d/%d x/y=%d/%d->%d/%d",
1092                        shsurf->geometry_width, shsurf->geometry_height,
1093                        es->geometry.width, es->geometry.height,
1094                        shsurf->geometry_x, shsurf->geometry_y,
1095                        (int)es->geometry.x, (int)es->geometry.y);
1096             num_mgr = ico_ivi_send_surface_change(es,
1097                                                   shsurf->geometry_x + to_x -from_x,
1098                                                   shsurf->geometry_y + to_y - from_y,
1099                                                   es->buffer->width, es->buffer->height);
1100             uifw_trace("shell_surface_configure: ret ivi_shell_hook_change(%d)", num_mgr)
1101         }
1102         if (num_mgr <= 0)   {
1103             /* manager not exist, change surface        */
1104             uifw_trace("shell_surface_configure: configure to Buffer size(no Manager) "
1105                        "x=%d+%d-%d y=%d+%d-%d",
1106                        (int)es->geometry.x, (int)to_x, (int)from_x,
1107                        (int)es->geometry.y, (int)to_y, (int)from_y);
1108             if ((es->geometry.x > ICO_IVI_MAX_COORDINATE) &&
1109                 (es->geometry.y > ICO_IVI_MAX_COORDINATE) &&
1110                 (shsurf->visible))  {
1111                 es->geometry.x = 0;
1112                 es->geometry.y = 0;
1113                 es->geometry.dirty = 1;
1114             }
1115             configure(shell, es,
1116                       es->geometry.x + to_x - from_x,
1117                       es->geometry.y + to_y - from_y,
1118                       es->buffer->width, es->buffer->height);
1119         }
1120     }
1121     uifw_trace("shell_surface_configure: Leave(surf=%08x out=%08x buf=%08x)",
1122                (int)es, (int)es->output, (int)es->buffer);
1123 }
1124
1125 /*--------------------------------------------------------------------------*/
1126 /**
1127  * @brief   bind_shell: client bind shell
1128  *
1129  * @param[in]   client      client(ex.HomeScreen)
1130  * @param[in]   data        user data(ico_ivi_shell static table address)
1131  * @param[in]   version     interface version number(unused)
1132  * @param[in]   id          client object id
1133  * @return      none
1134  */
1135 /*--------------------------------------------------------------------------*/
1136 static void
1137 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1138 {
1139     struct ivi_shell *shell = data;
1140     struct wl_resource *resource;
1141
1142     uifw_trace("bind_shell: client=%08x id=%d", (int)client, (int)id);
1143
1144     resource = wl_client_add_object(client, &wl_shell_interface,
1145                                     &shell_implementation, id, shell);
1146
1147     resource->destroy = unbind_shell;
1148
1149     if (shell_hook_bind)    {
1150         (*shell_hook_bind)(client);
1151     }
1152 }
1153
1154 /*--------------------------------------------------------------------------*/
1155 /**
1156  * @brief   unbind_shell: client unbind shell
1157  *
1158  * @param[in]   resource    unbind request resource
1159  * @return      none
1160  */
1161 /*--------------------------------------------------------------------------*/
1162 static void
1163 unbind_shell(struct wl_resource *resource)
1164 {
1165     uifw_trace("unbind_shell");
1166
1167     if (shell_hook_unbind)  {
1168         (*shell_hook_unbind)(resource->client);
1169     }
1170     free(resource);
1171 }
1172
1173 /*--------------------------------------------------------------------------*/
1174 /**
1175  * @brief   unbind_ivi_shell: client unbind ico_ivi_shell
1176  *
1177  * @param[in]   resource    unbind request resource
1178  * @return      none
1179  */
1180 /*--------------------------------------------------------------------------*/
1181 static void
1182 unbind_ivi_shell(struct wl_resource *resource)
1183 {
1184     uifw_trace("unbind_ivi_shell");
1185     free(resource);
1186 }
1187
1188 /*--------------------------------------------------------------------------*/
1189 /**
1190  * @brief   bind_ivi_shell: client bind ico_ivi_shell
1191  *
1192  * @param[in]   client      client(ex.HomeScreen)
1193  * @param[in]   data        user data(ico_ivi_shell static table address)
1194  * @param[in]   version     interface version number(unused)
1195  * @param[in]   id          client object id
1196  * @return      none
1197  */
1198 /*--------------------------------------------------------------------------*/
1199 static void
1200 bind_ivi_shell(struct wl_client *client,
1201                void *data, uint32_t version, uint32_t id)
1202 {
1203     struct ivi_shell *shell = data;
1204     struct wl_resource *resource;
1205
1206     resource = wl_client_add_object(client, &ico_ivi_shell_interface,
1207                                     NULL, id, shell);
1208
1209     uifw_trace("bind_ivi_shell: client=%08x id=%d", (int)client, (int)id);
1210
1211     resource->destroy = unbind_ivi_shell;
1212 }
1213
1214 /*--------------------------------------------------------------------------*/
1215 /**
1216  * @brief   shell_destroy: destroy ico_ivi_shell
1217  *
1218  * @param[in]   listener    shell destroy listener
1219  * @param[in]   data        user data(unused)
1220  * @return      none
1221  */
1222 /*--------------------------------------------------------------------------*/
1223 static void
1224 shell_destroy(struct wl_listener *listener, void *data)
1225 {
1226     struct ivi_shell *shell =
1227         container_of(listener, struct ivi_shell, destroy_listener);
1228
1229     uifw_trace("shell_destroy");
1230
1231     free(shell);
1232 }
1233
1234 /*--------------------------------------------------------------------------*/
1235 /**
1236  * @brief   ivi_shell_restack_ivi_layer: rebuild compositor surface list
1237  *
1238  * @param[in]   shell       ico_ivi_shell static table address
1239  * @param[in]   shsurf      target shell surface(if NULL, no need change surface)
1240  * @return      none
1241  */
1242 /*--------------------------------------------------------------------------*/
1243 static void
1244 ivi_shell_restack_ivi_layer(struct ivi_shell *shell, struct shell_surface *shsurf)
1245 {
1246     struct shell_surface  *es;
1247     struct ivi_layer_list *el;
1248     float   new_x, new_y;
1249
1250     uifw_trace("ivi_shell_restack_ivi_layer: Enter[%08x]", (int)shsurf);
1251
1252     /* make compositor surface list     */
1253     wl_list_init(&shell->surface.surface_list);
1254     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1255         if (ico_option_flag() & ICO_OPTION_FLAG_UNVISIBLE)  {
1256             wl_list_for_each (es, &el->surface_list, ivi_layer) {
1257                 if (es->surface != NULL)    {
1258                     if ((el->visible == FALSE) || (es->visible == FALSE))   {
1259                         new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1260                         new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1261                     }
1262                     else if (es->surface->buffer)   {
1263                         if (es->geometry_width > es->surface->buffer->width) {
1264                             new_x = (float)(es->geometry_x +
1265                                     (es->geometry_width - es->surface->geometry.width)/2);
1266                         }
1267                         else    {
1268                             new_x = (float)es->geometry_x;
1269                         }
1270                         if (es->geometry_height > es->surface->buffer->height) {
1271                             new_y = (float) (es->geometry_y +
1272                                     (es->geometry_height - es->surface->geometry.height)/2);
1273                         }
1274                         else    {
1275                             new_y = (float)es->geometry_y;
1276                         }
1277                     }
1278                     else    {
1279                         new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1280                         new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1281                     }
1282                     wl_list_insert(shell->surface.surface_list.prev,
1283                                    &es->surface->layer_link);
1284                     if ((new_x != es->surface->geometry.x) ||
1285                         (new_y != es->surface->geometry.y)) {
1286                         weston_surface_damage_below(es->surface);
1287                         es->surface->geometry.x = new_x;
1288                         es->surface->geometry.y = new_y;
1289                         es->surface->geometry.dirty = 1;
1290                         weston_surface_damage_below(es->surface);
1291                     }
1292                 }
1293             }
1294         }
1295         else    {
1296             if (el->visible != FALSE)   {
1297                 wl_list_for_each (es, &el->surface_list, ivi_layer) {
1298                     if ((es->visible != FALSE) && (es->surface) &&
1299                         (es->surface->output != NULL) &&
1300                         (es->surface->shader != NULL))  {
1301                         wl_list_insert(shell->surface.surface_list.prev,
1302                                        &es->surface->layer_link);
1303                     }
1304                 }
1305             }
1306         }
1307     }
1308
1309     /* damage(redraw) target surfacem if target exist   */
1310     if (shsurf) {
1311         weston_surface_damage_below(shsurf->surface);
1312     }
1313
1314     /* composit and draw screen(plane)  */
1315     weston_compositor_schedule_repaint(shell->compositor);
1316
1317     uifw_trace("ivi_shell_restack_ivi_layer: Leave");
1318 }
1319
1320 /*--------------------------------------------------------------------------*/
1321 /**
1322  * @brief   ivi_shell_set_active: surface active control
1323  *
1324  * @param[in]   shsurf      shell surface(if NULL, no active surface)
1325  * @param[in]   target      target device
1326  * @return      none
1327  */
1328 /*--------------------------------------------------------------------------*/
1329 WL_EXPORT void
1330 ivi_shell_set_active(struct shell_surface *shsurf, const int target)
1331 {
1332     struct ivi_shell *shell;
1333     struct weston_seat *seat;
1334     struct weston_surface *surface;
1335     int object = target;
1336     wl_fixed_t sx, sy;
1337
1338     uifw_trace("ivi_shell_set_active: Enter(%08x,%x)", (int)shsurf, target);
1339
1340     if (shsurf) {
1341         shell = shell_surface_get_shell(shsurf);
1342         surface = shsurf->surface;
1343         if (object == 0)    {
1344             surface = NULL;
1345             if (shell->active_pointer_shsurf == shsurf) {
1346                 object |= ICO_IVI_SHELL_ACTIVE_POINTER;
1347             }
1348             if (shell->active_keyboard_shsurf == shsurf)    {
1349                 object |= ICO_IVI_SHELL_ACTIVE_KEYBOARD;
1350             }
1351         }
1352         else    {
1353             if (object & ICO_IVI_SHELL_ACTIVE_POINTER) {
1354                 shell->active_pointer_shsurf = shsurf;
1355             }
1356             if (object & ICO_IVI_SHELL_ACTIVE_KEYBOARD)    {
1357                 shell->active_keyboard_shsurf = shsurf;
1358             }
1359         }
1360     }
1361     else    {
1362         shell = default_shell;
1363         surface = NULL;
1364         if (target == 0)    {
1365             object = ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD;
1366         }
1367         if (object & ICO_IVI_SHELL_ACTIVE_POINTER) {
1368             shell->active_pointer_shsurf = NULL;
1369         }
1370         if (object & ICO_IVI_SHELL_ACTIVE_KEYBOARD)    {
1371             shell->active_keyboard_shsurf = NULL;
1372         }
1373     }
1374
1375     wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1376         if ((object & ICO_IVI_SHELL_ACTIVE_POINTER) && (seat->seat.pointer))   {
1377             if (surface)    {
1378                 uifw_trace("ivi_shell_set_active: pointer set surface(%08x=>%08x)",
1379                            (int)seat->seat.pointer->focus, (int)&surface->surface);
1380                 if (seat->seat.pointer->focus != &surface->surface) {
1381                     weston_surface_from_global_fixed(surface,
1382                                                      seat->seat.pointer->x,
1383                                                      seat->seat.pointer->y,
1384                                                      &sx, &sy);
1385                     wl_pointer_set_focus(seat->seat.pointer, &surface->surface, sx, sy);
1386                 }
1387             }
1388             else    {
1389                 uifw_trace("ivi_shell_set_active: pointer reset surface(%08x)",
1390                            (int)seat->seat.pointer->focus);
1391                 wl_pointer_set_focus(seat->seat.pointer, NULL,
1392                                      wl_fixed_from_int(0), wl_fixed_from_int(0));
1393             }
1394         }
1395         if ((object & ICO_IVI_SHELL_ACTIVE_KEYBOARD) && (seat->has_keyboard))  {
1396             if (surface)    {
1397                 uifw_trace("ivi_shell_set_active: keyboard set surface(%08x=>%08x)",
1398                            (int)seat->seat.keyboard->focus, (int)&surface->surface);
1399                 if (seat->seat.keyboard->focus != &surface->surface)    {
1400                     wl_keyboard_set_focus(seat->seat.keyboard, &surface->surface);
1401                 }
1402             }
1403             else    {
1404                 uifw_trace("ivi_shell_set_active: keyboard reset surface(%08x)",
1405                            (int)seat->seat.keyboard);
1406                 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
1407             }
1408         }
1409         else    {
1410             uifw_trace("ivi_shell_set_active: seat[%08x] has no keyboard", (int)seat);
1411         }
1412     }
1413     uifw_trace("ivi_shell_set_active: Leave(%08x)", (int)shsurf);
1414 }
1415
1416 /*--------------------------------------------------------------------------*/
1417 /**
1418  * @brief   ivi_shell_set_client_attr : set client ttribute
1419  *
1420  * @param[in]   client      target client
1421  * @param[in]   attr        attribute
1422  * @param[in]   value       attribute value
1423  * @return      none
1424  */
1425 /*--------------------------------------------------------------------------*/
1426 WL_EXPORT void
1427 ivi_shell_set_client_attr(struct wl_client *client, const int attr, const int value)
1428 {
1429     struct shell_surface  *es;
1430     struct ivi_layer_list *el;
1431
1432     uifw_trace("ivi_shell_set_client_attr: Enter(%08x,%d,%d)", (int)client, attr, value);
1433
1434     wl_list_for_each (el, &default_shell->ivi_layer.link, link) {
1435         wl_list_for_each (es, &el->surface_list, ivi_layer) {
1436             if (es->wclient == client)   {
1437                 switch(attr)    {
1438                 case ICO_CLEINT_ATTR_NOCONFIGURE:
1439                     es->noconfigure = value;
1440                     uifw_trace("ivi_shell_set_client_attr: set surface %08x", (int)es);
1441                     break;
1442                 default:
1443                     break;
1444                 }
1445             }
1446         }
1447     }
1448     uifw_trace("ivi_shell_set_client_attr: Leave");
1449 }
1450
1451 /*--------------------------------------------------------------------------*/
1452 /**
1453  * @brief   ivi_shell_set_active: surface active control
1454  *
1455  * @param[in]   shsurf      shell surface(if NULL, no active surface)
1456  * @param[in]   restrain    restrain(1)/not restrain(0)
1457  * @return      none
1458  */
1459 /*--------------------------------------------------------------------------*/
1460 WL_EXPORT void
1461 ivi_shell_restrain_configure(struct shell_surface *shsurf, const int restrain)
1462 {
1463     uifw_trace("ivi_shell_restrain_configure: set %08x to %d",
1464                (int)shsurf, restrain);
1465     shsurf->restrain = restrain;
1466
1467     if (restrain == 0)  {
1468         shell_surface_configure(shsurf->surface, shsurf->geometry_x, shsurf->geometry_y);
1469         ivi_shell_restack_ivi_layer(shell_surface_get_shell(shsurf), shsurf);
1470     }
1471 }
1472
1473 /*--------------------------------------------------------------------------*/
1474 /**
1475  * @brief   ivi_shell_is_restrain: check surface restrain
1476  *
1477  * @param[in]   shsurf      shell surface(if NULL, no active surface)
1478  * @return      restrain
1479  * @retval      =1          surface currently restrain
1480  * @retval      =0          not restrain
1481  */
1482 /*--------------------------------------------------------------------------*/
1483 WL_EXPORT int
1484 ivi_shell_is_restrain(struct shell_surface *shsurf)
1485 {
1486     return shsurf->restrain;
1487 }
1488
1489 /*--------------------------------------------------------------------------*/
1490 /**
1491  * @brief   ivi_shell_default_animation: window default animation
1492  *
1493  * @param[out]  msec    animation time(ms)
1494  * @param[out]  fps     animation frame rate(fps)
1495  * @return      default animation name
1496  */
1497 /*--------------------------------------------------------------------------*/
1498 WL_EXPORT const char *
1499 ivi_shell_default_animation(int *msec, int *fps)
1500 {
1501     if (msec)   {
1502         *msec = default_shell->win_animation_time;
1503     }
1504     if (fps)   {
1505         *fps = default_shell->win_animation_fps;
1506     }
1507     return default_shell->win_animation;
1508 }
1509
1510 /*--------------------------------------------------------------------------*/
1511 /**
1512  * @brief   click_to_activate_binding: clieck and select surface
1513  *
1514  * @param[in]   seat        clicked target seat
1515  * @param[in]   button      click button(unused)
1516  * @param[in]   data        user data(ico_ivi_shell static table address)
1517  * @return      none
1518  */
1519 /*--------------------------------------------------------------------------*/
1520 static void
1521 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
1522 {
1523     struct ivi_shell *shell = data;
1524     struct shell_surface *shsurf;
1525     struct weston_surface *surface;
1526
1527     if ((! seat) || (! seat->pointer) || (! seat->pointer->focus))  {
1528         uifw_trace("click_to_activate_binding: Surface dose not exist");
1529     }
1530     else    {
1531         surface = (struct weston_surface *) seat->pointer->focus;
1532         shsurf = get_shell_surface(surface);
1533         if (! shsurf)   {
1534             uifw_trace("click_to_activate_binding: Shell surface dose not exist");
1535         }
1536         else if ((shsurf->type == SHELL_SURFACE_NONE) ||
1537                  (shsurf->visible == 0))    {
1538             uifw_trace("click_to_activate_binding: Surface[%08x] is not visible",
1539                        (int)shsurf);
1540         }
1541         else if (shell->active_pointer_shsurf != shsurf)    {
1542             if (shell_hook_select) {
1543                 /* surface select hook routine      */
1544                 uifw_trace("click_to_activate_binding: call ivi_shell_hook_select[%08x]",
1545                            (int)shsurf);
1546                 (void) (*shell_hook_select)(surface);
1547                 uifw_trace("click_to_activate_binding: ret  ivi_shell_hook_select")
1548             }
1549             else    {
1550                 ivi_shell_set_active(shsurf,
1551                                      ICO_IVI_SHELL_ACTIVE_POINTER |
1552                                          ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1553                 uifw_trace("click_to_activate_binding: no hook[%08x]", (int)shsurf);
1554             }
1555         }
1556         else    {
1557             uifw_trace("click_to_activate_binding: ShellSurface[%08x] already active",
1558                        (int)shsurf);
1559         }
1560     }
1561 }
1562
1563 /*--------------------------------------------------------------------------*/
1564 /**
1565  * @brief   ivi_shell_set_visible: surface visible control
1566  *
1567  * @param[in]   shsurf      shell surface
1568  * @param[in]   visible     visibility(1=visible/0=unvisible/-1=system default)
1569  * @return      none
1570  */
1571 /*--------------------------------------------------------------------------*/
1572 WL_EXPORT void
1573 ivi_shell_set_visible(struct shell_surface *shsurf, const int visible)
1574 {
1575     struct ivi_shell *shell = shell_surface_get_shell(shsurf);
1576     int next;
1577
1578     uifw_trace("ivi_shell_set_visible: [%08x] (%08x) visible=%d",
1579                (int)shsurf, (int)shsurf->surface, (int)visible);
1580
1581     if (visible < 0)    {
1582         next = shell->win_visible_on_create;
1583     }
1584     else    {
1585         next = visible;
1586     }
1587
1588     if ((shsurf->visible != FALSE) && (next == 0))  {
1589         /* change show ==> hide         */
1590         shsurf->visible = FALSE;
1591         ivi_shell_restack_ivi_layer(shell, shsurf);
1592     }
1593     else if ((shsurf->visible == FALSE) && (next != 0)) {
1594         /* change hide ==> show         */
1595         shsurf->visible = TRUE;
1596         ivi_shell_restack_ivi_layer(shell, shsurf);
1597     }
1598     else    {
1599         /* other case, no change        */
1600         uifw_trace("ivi_shell_set_visible: No change");
1601     }
1602 }
1603
1604 /*--------------------------------------------------------------------------*/
1605 /**
1606  * @brief   ivi_shell_is_visible: get surface visibility
1607  *
1608  * @param[in]   shsurf      shell surface
1609  * @return      visibility
1610  * @retval      true        visible
1611  * @retval      false       unvisible
1612  */
1613 /*--------------------------------------------------------------------------*/
1614 WL_EXPORT bool
1615 ivi_shell_is_visible(struct shell_surface *shsurf)
1616 {
1617     return(shsurf->visible);
1618 }
1619
1620 /*--------------------------------------------------------------------------*/
1621 /**
1622  * @brief   ivi_shell_set_layer: set(or change) surface layer
1623  *
1624  * @param[in]   shsurf      shell surface
1625  * @param[in]   layer       layer id
1626  * @return      none
1627  */
1628 /*--------------------------------------------------------------------------*/
1629 WL_EXPORT void
1630 ivi_shell_set_layer(struct shell_surface *shsurf, const int layer)
1631 {
1632     struct ivi_shell *shell;
1633     struct ivi_layer_list *el;
1634     struct ivi_layer_list *new_el;
1635
1636     uifw_trace("ivi_shell_set_layer: Enter([%08x],%08x,%d)",
1637                (int)shsurf, (int)shsurf->surface, layer);
1638
1639     shell = shell_surface_get_shell(shsurf);
1640
1641     /* check if same layer                      */
1642     if ((shsurf->layer_list != NULL) && (shsurf->layer_list->layer == layer))   {
1643         uifw_trace("ivi_shell_set_layer: Leave(Same Layer)");
1644         return;
1645     }
1646
1647     /* search existing layer                    */
1648     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1649         if (el->layer == layer) break;
1650     }
1651
1652     if (&el->link == &shell->ivi_layer.link)    {
1653         /* layer not exist, create new layer    */
1654         uifw_trace("ivi_shell_set_layer: New Layer %d", layer);
1655         new_el = malloc(sizeof(struct ivi_layer_list));
1656         if (! new_el)   {
1657             uifw_trace("ivi_shell_set_layer: Leave(No Memory)");
1658             return;
1659         }
1660
1661         memset(new_el, 0, sizeof(struct ivi_layer_list));
1662         new_el->layer = layer;
1663         new_el->visible = TRUE;
1664         wl_list_init(&new_el->surface_list);
1665         wl_list_init(&new_el->link);
1666
1667         wl_list_remove(&shsurf->ivi_layer);
1668         wl_list_insert(&new_el->surface_list, &shsurf->ivi_layer);
1669         shsurf->layer_list = new_el;
1670
1671         wl_list_for_each (el, &shell->ivi_layer.link, link) {
1672             if (layer >= el->layer) break;
1673         }
1674         if (&el->link == &shell->ivi_layer.link)    {
1675             wl_list_insert(shell->ivi_layer.link.prev, &new_el->link);
1676         }
1677         else    {
1678             wl_list_insert(el->link.prev, &new_el->link);
1679         }
1680     }
1681     else    {
1682         uifw_trace("ivi_shell_set_layer: Add surface to Layer %d", layer);
1683         wl_list_remove(&shsurf->ivi_layer);
1684         wl_list_insert(&el->surface_list, &shsurf->ivi_layer);
1685         shsurf->layer_list = el;
1686     }
1687
1688     /* rebild compositor surface list       */
1689     ivi_shell_restack_ivi_layer(shell, shsurf);
1690
1691     uifw_trace("ivi_shell_set_layer: Leave");
1692 }
1693
1694 /*--------------------------------------------------------------------------*/
1695 /**
1696  * @brief   ivi_shell_set_raise: surface stack control
1697  *
1698  * @param[in]   shsurf      shell surface
1699  * @param[in]   raise       raise/lower(1=raise/0=lower)
1700  * @return      none
1701  */
1702 /*--------------------------------------------------------------------------*/
1703 WL_EXPORT void
1704 ivi_shell_set_raise(struct shell_surface *shsurf, const int raise)
1705 {
1706     uifw_trace("ivi_shell_set_raise: Enter(%08x,%d) layer_list=%08x",
1707                (int)shsurf->surface, raise, (int)shsurf->layer_list);
1708
1709     wl_list_remove(&shsurf->ivi_layer);
1710     if (raise)  {
1711         /* raise ... surface stack to top of layer          */
1712         wl_list_insert(&shsurf->layer_list->surface_list, &shsurf->ivi_layer);
1713         uifw_trace("ivi_shell_set_raise: Raise Link to Top");
1714     }
1715     else    {
1716         /* Lower ... surface stack to bottom of layer       */
1717         wl_list_insert(shsurf->layer_list->surface_list.prev, &shsurf->ivi_layer);
1718         uifw_trace("ivi_shell_set_raise: Lower Link to Bottom");
1719     }
1720
1721     /* rebild compositor surface list               */
1722     ivi_shell_restack_ivi_layer(shell_surface_get_shell(shsurf), shsurf);
1723
1724     uifw_trace("ivi_shell_set_raise: Leave");
1725 }
1726
1727 /*--------------------------------------------------------------------------*/
1728 /**
1729  * @brief   ivi_shell_set_toplevel: set surface type toplevel
1730  *
1731  * @param[in]   shsurf      shell surface
1732  * @return      none
1733  */
1734 /*--------------------------------------------------------------------------*/
1735 WL_EXPORT void
1736 ivi_shell_set_toplevel(struct shell_surface *shsurf)
1737 {
1738     uifw_trace("ivi_shell_set_toplevel: (%08x)", (int)shsurf->surface);
1739     set_toplevel(shsurf);
1740 }
1741
1742 /*--------------------------------------------------------------------------*/
1743 /**
1744  * @brief   ivi_shell_set_surface_type: set surface type
1745  *
1746  * @param[in]   shsurf      shell surface
1747  * @return      none
1748  */
1749 /*--------------------------------------------------------------------------*/
1750 WL_EXPORT void
1751 ivi_shell_set_surface_type(struct shell_surface *shsurf)
1752 {
1753     uifw_trace("ivi_shell_set_surfacetype: (%08x)", (int)shsurf->surface);
1754     set_surface_type(shsurf);
1755 }
1756
1757 /*--------------------------------------------------------------------------*/
1758 /**
1759  * @brief   ivi_shell_send_configure: send surface resize event
1760  *
1761  * @param[in]   shsurf      shell surface
1762  * @param[in]   id          client object id(unused)
1763  * @param[in]   edges       surface resize position
1764  * @param[in]   width       surface width
1765  * @param[in]   height      surface height
1766  * @return      none
1767  */
1768 /*--------------------------------------------------------------------------*/
1769 WL_EXPORT void
1770 ivi_shell_send_configure(struct shell_surface *shsurf, const int id,
1771                          const int edges, const int width, const int height)
1772 {
1773     /* send cgange event to manager     */
1774     uifw_trace("ivi_shell_send_configure: (%08x) edges=%x w/h=%d/%d map=%d",
1775                (int)shsurf->surface, edges, width, height, shsurf->mapped);
1776
1777     shsurf->geometry_width = width;
1778     shsurf->geometry_height = height;
1779
1780     if ((shsurf->mapped == 0) || (shsurf->noconfigure != 0) ||
1781         (width == 0) || (height == 0))  {
1782         return;
1783     }
1784
1785     /* send cgange event to application */
1786     uifw_trace("ivi_shell_send_configure: Send (%08x) w/h=%d/%d(old=%d/%d)",
1787                (int)shsurf->surface, width, height,
1788                shsurf->configure_app.width, shsurf->configure_app.height);
1789     shsurf->configure_app.width = width;
1790     shsurf->configure_app.height = height;
1791
1792     wl_shell_surface_send_configure(&shsurf->resource,
1793                                     WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,
1794                                     width, height);
1795 }
1796
1797 /*--------------------------------------------------------------------------*/
1798 /**
1799  * @brief   ivi_shell_get_positionsize: get surface position and size
1800  *
1801  * @param[in]   shsurf      shell surface
1802  * @param[out]  x           surface upper-left X position on screen
1803  * @param[out]  y           surface upper-left Y position on screen
1804  * @param[out]  width       surface width
1805  * @param[out]  height      surface height
1806  * @return      none
1807  */
1808 /*--------------------------------------------------------------------------*/
1809 WL_EXPORT void
1810 ivi_shell_get_positionsize(struct shell_surface *shsurf,
1811                            int *x, int *y, int *width, int *height)
1812 {
1813     *x = shsurf->geometry_x;
1814     *y = shsurf->geometry_y;
1815     *width = shsurf->geometry_width;
1816     *height = shsurf->geometry_height;
1817 }
1818
1819 /*--------------------------------------------------------------------------*/
1820 /**
1821  * @brief   ivi_shell_set_positionsize: set surface position and size
1822  *
1823  * @param[in]   shsurf      shell surface
1824  * @param[in]   x           surface upper-left X position on screen
1825  * @param[in]   y           surface upper-left Y position on screen
1826  * @param[in]   width       surface width
1827  * @param[in]   height      surface height
1828  * @return      none
1829  */
1830 /*--------------------------------------------------------------------------*/
1831 WL_EXPORT void
1832 ivi_shell_set_positionsize(struct shell_surface *shsurf,
1833                            const int x, const int y, const int width, const int height)
1834 {
1835     shsurf->geometry_x = x;
1836     shsurf->geometry_y = y;
1837     shsurf->geometry_width = width;
1838     shsurf->geometry_height = height;
1839
1840     weston_compositor_schedule_repaint(shell_surface_get_shell(shsurf)->compositor);
1841 }
1842
1843 /*--------------------------------------------------------------------------*/
1844 /**
1845  * @brief   ivi_shell_set_layer_visible: layer visible control
1846  *
1847  * @param[in]   layer       layer id
1848  * @param[in]   visible     visibility(1=visible/0=unvisible)
1849  * @return      none
1850  */
1851 /*--------------------------------------------------------------------------*/
1852 WL_EXPORT void
1853 ivi_shell_set_layer_visible(const int layer, const int visible)
1854 {
1855     struct ivi_shell *shell;
1856     struct ivi_layer_list *el;
1857     struct ivi_layer_list *new_el;
1858     struct shell_surface  *es;
1859
1860     uifw_trace("ivi_shell_set_layer_visible: Enter(layer=%d, visible=%d)", layer, visible);
1861
1862     shell = shell_surface_get_shell(NULL);
1863
1864     /* Search Layer                             */
1865     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1866         if (el->layer == layer) break;
1867     }
1868
1869     if (&el->link == &shell->ivi_layer.link)    {
1870         /* layer not exist, create new layer    */
1871         uifw_trace("ivi_shell_set_layer_visible: New Layer %d", layer);
1872         new_el = malloc(sizeof(struct ivi_layer_list));
1873         if (! new_el)   {
1874             uifw_trace("ivi_shell_set_layer_visible: Leave(No Memory)");
1875             return;
1876         }
1877
1878         memset(new_el, 0, sizeof(struct ivi_layer_list));
1879         new_el->layer = layer;
1880         new_el->visible = TRUE;
1881         wl_list_init(&new_el->surface_list);
1882         wl_list_init(&new_el->link);
1883
1884         wl_list_for_each (el, &shell->ivi_layer.link, link) {
1885             if (layer >= el->layer) break;
1886         }
1887         if (&el->link == &shell->ivi_layer.link)    {
1888             wl_list_insert(shell->ivi_layer.link.prev, &new_el->link);
1889         }
1890         else    {
1891             wl_list_insert(el->link.prev, &new_el->link);
1892         }
1893         uifw_trace("ivi_shell_set_layer_visible: Leave(new layer)");
1894         return;
1895     }
1896
1897     /* control all surface in layer */
1898     if ((el->visible != FALSE) && (visible == 0))   {
1899         /* layer change to NOT visible  */
1900         uifw_trace("ivi_shell_set_layer_visible: change to not visible");
1901         el->visible = FALSE;
1902     }
1903     else if ((el->visible == FALSE) && (visible != 0))  {
1904         /* layer change to visible      */
1905         uifw_trace("ivi_shell_set_layer_visible: change to visible");
1906         el->visible = TRUE;
1907     }
1908     else    {
1909         /* no change    */
1910         uifw_trace("ivi_shell_set_layer_visible: Leave(no Change %d=>%d)",
1911                    el->visible, visible);
1912         return;
1913     }
1914
1915     /* set damege area          */
1916     wl_list_for_each (es, &el->surface_list, ivi_layer) {
1917         if ((es->visible != FALSE) &&
1918             (es->surface->output != NULL) &&
1919             (es->surface->shader != NULL))  {
1920             /* Damage(redraw) target surface    */
1921             weston_surface_damage_below(es->surface);
1922         }
1923     }
1924
1925     /* rebild compositor surface list       */
1926     ivi_shell_restack_ivi_layer(shell, NULL);
1927
1928     uifw_trace("ivi_shell_set_layer_visible: Leave");
1929 }
1930
1931 /*--------------------------------------------------------------------------*/
1932 /**
1933  * @brief   ivi_shell_surface_configure: surface change
1934  *
1935  * @param[in]   shsurf      shell surface
1936  * @param[in]   x           surface upper-left X position on screen
1937  * @param[in]   y           surface upper-left Y position on screen
1938  * @param[in]   width       surface width
1939  * @param[in]   height      surface height
1940  * @return      none
1941  */
1942 /*--------------------------------------------------------------------------*/
1943 WL_EXPORT void
1944 ivi_shell_surface_configure(struct shell_surface *shsurf, const int x,
1945                             const int y, const int width, const int height)
1946 {
1947     int set_unvisible = 0;
1948
1949     if (ico_option_flag() & ICO_OPTION_FLAG_UNVISIBLE)  {
1950         if ((shsurf->surface != NULL) && (shsurf->surface->buffer != NULL) &&
1951             (shsurf->surface->output != NULL) && (shsurf->surface->shader != NULL))  {
1952             if ((shsurf->visible == FALSE) ||
1953                 ((shsurf->layer_list != NULL) &&
1954                  (shsurf->layer_list->visible == FALSE)))   {
1955                 set_unvisible = 1;
1956             }
1957         }
1958     }
1959     if (set_unvisible)  {
1960         uifw_trace("ivi_shell_surface_configure: %08x %d,%d(%d/%d) unvisible",
1961                    (int)shsurf, x, y, width, height);
1962         weston_surface_configure(shsurf->surface,
1963                                  ICO_IVI_MAX_COORDINATE+1, ICO_IVI_MAX_COORDINATE+1,
1964                                  width, height);
1965     }
1966     else    {
1967         uifw_trace("ivi_shell_surface_configure: %08x %d,%d(%d/%d) visible",
1968                    (int)shsurf, x, y, width, height);
1969         weston_surface_configure(shsurf->surface, x, y, width, height);
1970     }
1971 }
1972
1973 /*--------------------------------------------------------------------------*/
1974 /**
1975  * @brief   ivi_shell_hook_bind: regist hook function for shell bind
1976  *
1977  * @param[in]   hook_bind       hook function(if NULL, reset hook function)
1978  * @return      none
1979  */
1980 /*--------------------------------------------------------------------------*/
1981 WL_EXPORT void
1982 ivi_shell_hook_bind(void (*hook_bind)(struct wl_client *client))
1983 {
1984     uifw_trace("ivi_shell_hook_bind: Hook %08x", (int)hook_bind);
1985     shell_hook_bind = hook_bind;
1986 }
1987
1988 /*--------------------------------------------------------------------------*/
1989 /**
1990  * @brief   ivi_shell_hook_unbind: regist hook function for shell unbind
1991  *
1992  * @param[in]   hook_unbind     hook function(if NULL, reset hook function)
1993  * @return      none
1994  */
1995 /*--------------------------------------------------------------------------*/
1996 WL_EXPORT void
1997 ivi_shell_hook_unbind(void (*hook_unbind)(struct wl_client *client))
1998 {
1999     uifw_trace("ivi_shell_hook_unbind: Hook %08x", (int)hook_unbind);
2000     shell_hook_unbind = hook_unbind;
2001 }
2002
2003 /*--------------------------------------------------------------------------*/
2004 /**
2005  * @brief   ivi_shell_hook_create: regist hook function for create shell surface
2006  *
2007  * @param[in]   hook_create     hook function(if NULL, reset hook function)
2008  * @return      none
2009  */
2010 /*--------------------------------------------------------------------------*/
2011 WL_EXPORT void
2012 ivi_shell_hook_create(void (*hook_create)(struct wl_client *client,
2013                       struct wl_resource *resource, struct weston_surface *surface,
2014                       struct shell_surface *shsurf))
2015 {
2016     uifw_trace("ivi_shell_hook_create: Hook %08x", (int)hook_create);
2017     shell_hook_create = hook_create;
2018 }
2019
2020 /*--------------------------------------------------------------------------*/
2021 /**
2022  * @brief   ivi_shell_hook_destroy: regist hook function for destroy shell surface
2023  *
2024  * @param[in]   hook_destroy    hook function(if NULL, reset hook function)
2025  * @return      none
2026  */
2027 /*--------------------------------------------------------------------------*/
2028 WL_EXPORT void
2029 ivi_shell_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
2030 {
2031     uifw_trace("ivi_shell_hook_destroy: Hook %08x", (int)hook_destroy);
2032     shell_hook_destroy = hook_destroy;
2033 }
2034
2035 /*--------------------------------------------------------------------------*/
2036 /**
2037  * @brief   ivi_shell_hook_map: regist hook function for map shell surface
2038  *
2039  * @param[in]   hook_map        hook function(if NULL, reset hook function)
2040  * @return      none
2041  */
2042 /*--------------------------------------------------------------------------*/
2043 WL_EXPORT void
2044 ivi_shell_hook_map(void (*hook_map)(struct weston_surface *surface,
2045                         int32_t *width, int32_t *height, int32_t *sx, int32_t *sy))
2046 {
2047     uifw_trace("ivi_shell_hook_map: Hook %08x", (int)hook_map);
2048     shell_hook_map = hook_map;
2049 }
2050
2051 /*--------------------------------------------------------------------------*/
2052 /**
2053  * @brief   ivi_shell_hook_change: regist hook function for change shell surface
2054  *
2055  * @param[in]   hook_change     hook function(if NULL, reset hook function)
2056  * @return      none
2057  */
2058 /*--------------------------------------------------------------------------*/
2059 WL_EXPORT void
2060 ivi_shell_hook_change(void (*hook_change)(struct weston_surface *surface,
2061                                           const int to, const int manager))
2062 {
2063     uifw_trace("ivi_shell_hook_change: Hook %08x", (int)hook_change);
2064     shell_hook_change = hook_change;
2065 }
2066
2067 /*--------------------------------------------------------------------------*/
2068 /**
2069  * @brief   ivi_shell_hook_select: regist hook function for select(active) shell surface
2070  *
2071  * @param[in]   hook_select     hook function(if NULL, reset hook function)
2072  * @return      none
2073  */
2074 /*--------------------------------------------------------------------------*/
2075 WL_EXPORT void
2076 ivi_shell_hook_select(void (*hook_select)(struct weston_surface *surface))
2077 {
2078     uifw_trace("ivi_shell_hook_select: Hook %08x", (int)hook_select);
2079     shell_hook_select = hook_select;
2080 }
2081
2082 /*--------------------------------------------------------------------------*/
2083 /**
2084  * @brief   module_init: initialize ico_ivi_shell
2085  *                       this function called from ico_pluign_loader
2086  *
2087  * @param[in]   es          weston compositor
2088  * @return      result
2089  * @retval      0           sccess
2090  * @retval      -1          error
2091  */
2092 /*--------------------------------------------------------------------------*/
2093 WL_EXPORT int
2094 module_init(struct weston_compositor *ec)
2095 {
2096     struct ivi_shell *shell;
2097
2098     uifw_info("ico_ivi_shell: Enter(module_init)");
2099
2100     shell = malloc(sizeof *shell);
2101     if (shell == NULL)  return -1;
2102     default_shell = shell;
2103
2104     memset(shell, 0, sizeof *shell);
2105     shell->compositor = ec;
2106
2107     shell->destroy_listener.notify = shell_destroy;
2108     wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2109     ec->shell_interface.shell = shell;
2110     ec->shell_interface.create_shell_surface = create_shell_surface;
2111     ec->shell_interface.set_toplevel = set_toplevel;
2112     ec->shell_interface.set_transient = set_transient;
2113
2114     wl_list_init(&shell->ivi_layer.link);
2115     weston_layer_init(&shell->surface, &ec->cursor_layer.link);
2116
2117     uifw_trace("ico_ivi_shell: shell(%08x) ivi_layer.link.%08x=%08x/%08x",
2118                (int)shell, (int)&shell->ivi_layer.link,
2119                (int)shell->ivi_layer.link.next, (int)shell->ivi_layer.link.prev);
2120
2121     shell_configuration(shell);
2122
2123     if (wl_display_add_global(ec->wl_display, &wl_shell_interface, shell, bind_shell)
2124             == NULL)    {
2125         return -1;
2126     }
2127     if (wl_display_add_global(ec->wl_display, &ico_ivi_shell_interface,
2128                               shell, bind_ivi_shell) == NULL)   {
2129         return -1;
2130     }
2131
2132     weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
2133                                          click_to_activate_binding, shell);
2134
2135     uifw_info("ico_ivi_shell: Leave(module_init)");
2136     return 0;
2137 }
2138