Addition of the window animation interface.
[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     }
917
918     switch (surface_type) {
919     case SHELL_SURFACE_TRANSIENT:
920         parent = shsurf->parent;
921         wl_list_insert(parent->layer_link.prev, &surface->layer_link);
922         break;
923     case SHELL_SURFACE_NONE:
924         break;
925     default:
926         if (! shsurf->layer_list)   {
927             ivi_shell_set_layer(shsurf, ICO_IVI_DEFAULT_LAYER);
928         }
929         break;
930     }
931
932     if (surface_type != SHELL_SURFACE_NONE) {
933         weston_surface_update_transform(surface);
934         ivi_shell_restack_ivi_layer(shell, shsurf);
935     }
936
937     if (shell_hook_map) {
938         /* Surface map hook routine         */
939         uifw_trace("map: call ivi_shell_hook_map(%08x, x/y=%d/%d, w/h=%d/%d)",
940                    (int)surface, sx, sy, width, height);
941         (void) (*shell_hook_map) (surface, &width, &height, &sx, &sy);
942         uifw_trace("map: ret  ivi_shell_hook_map(%08x, x/y=%d/%d, w/h=%d/%d)",
943                    (int)surface, sx, sy, width, height);
944     }
945
946     if (shell_hook_change)  {
947         /* Surface change hook routine      */
948         uifw_trace("map: call ivi_shell_hook_change(%08x)", (int)surface);
949         (void) (*shell_hook_change)(surface, -1, 1);    /* Send to Manager  */
950         uifw_trace("map: ret  ivi_shell_hook_change")
951     }
952     uifw_trace("map: Leave");
953 }
954
955 /*--------------------------------------------------------------------------*/
956 /**
957  * @brief   configure: surface change
958  *
959  * @param[in]   shell       ico_ivi_shell static table address
960  * @param[in]   surface     weston surface
961  * @param[in]   x           surface upper-left X position on screen
962  * @param[in]   y           surface upper-left Y position on screen
963  * @param[in]   width       surface width
964  * @param[in]   height      surface height
965  * @return      none
966  */
967 /*--------------------------------------------------------------------------*/
968 static void
969 configure(struct ivi_shell *shell, struct weston_surface *surface,
970           GLfloat x, GLfloat y, int32_t width, int32_t height)
971 {
972     enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
973     struct shell_surface *shsurf;
974
975     shsurf = get_shell_surface(surface);
976
977     uifw_trace("configure: Enter(%08x) [%08x] x/y=%d/%d, w/h=%d/%d",
978                (int)surface, (int)shsurf, (int)x, (int)y, width, height);
979
980     if (shsurf) {
981         surface_type = shsurf->type;
982         shsurf->geometry_x = (int)x;
983         shsurf->geometry_y = (int)y;
984         shsurf->geometry_width = width;
985         shsurf->geometry_height = height;
986         ivi_shell_surface_configure(shsurf, x, y, width, height);
987     }
988     else    {
989         surface->geometry.x = x;
990         surface->geometry.y = y;
991         surface->geometry.width = width;
992         surface->geometry.height = height;
993         surface->geometry.dirty = 1;
994     }
995
996     if (surface->output) {
997         weston_surface_update_transform(surface);
998     }
999
1000     uifw_trace("configure: Leave");
1001 }
1002
1003 /*--------------------------------------------------------------------------*/
1004 /**
1005  * @brief   shell_surface_configure: shell surface change
1006  *
1007  * @param[in]   es          weston surface
1008  * @param[in]   sx          surface upper-left X position on screen
1009  * @param[in]   sy          surface upper-left Y position on screen
1010  * @return      none
1011  */
1012 /*--------------------------------------------------------------------------*/
1013 static void
1014 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1015 {
1016     struct shell_surface *shsurf = get_shell_surface(es);
1017     struct ivi_shell *shell = shsurf->shell;
1018     int     type_changed = 0;
1019     int     num_mgr;
1020
1021     uifw_trace("shell_surface_configure: Enter(surf=%08x out=%08x buf=%08x)",
1022                (int)es, (int)es->output, (int)es->buffer);
1023
1024     if (shsurf->restrain)   {
1025         uifw_trace("shell_surface_configure: Leave(restrain)");
1026         return;
1027     }
1028
1029     if (shsurf->next_type != SHELL_SURFACE_NONE &&
1030         shsurf->type != shsurf->next_type) {
1031         set_surface_type(shsurf);
1032         type_changed = 1;
1033     }
1034
1035     if (! weston_surface_is_mapped(es)) {
1036         if ((es->geometry.width > 0) && (es->geometry.height >0))   {
1037             uifw_trace("shell_surface_configure: map Surface size(sx/sy=%d/%d w/h=%d/%d)",
1038                        sx, sy, es->buffer->width, es->buffer->height);
1039             map(shell, es, es->geometry.width, es->geometry.height, sx, sy);
1040         }
1041         else    {
1042             uifw_trace("shell_surface_configure: map Buffer size(sx/sy=%d/%d w/h=%d/%d)",
1043                        sx, sy, es->buffer->width, es->buffer->height);
1044             map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
1045         }
1046     }
1047     else    {
1048         if ((shsurf->mapped == 0) && (es->buffer != NULL))  {
1049             if ((es->geometry.width > 0) && (es->geometry.height >0))   {
1050                 uifw_trace("shell_surface_configure: map Surface size(sx/sy=%d/%d w/h=%d/%d)",
1051                            sx, sy, es->buffer->width, es->buffer->height);
1052                 map(shell, es, es->geometry.width, es->geometry.height, sx, sy);
1053             }
1054             else    {
1055                 uifw_trace("shell_surface_configure: map Buffer size(sx/sy=%d/%d w/h=%d/%d)",
1056                            sx, sy, es->buffer->width, es->buffer->height);
1057                 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
1058             }
1059         }
1060
1061         GLfloat from_x, from_y;
1062         GLfloat to_x, to_y;
1063
1064         weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
1065         weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
1066
1067         if ((es->geometry.width <= 0) || (es->geometry.height <= 0))    {
1068             num_mgr = 0;
1069         }
1070         else    {
1071             /* Surface change request from App  */
1072             uifw_trace("shell_surface_configure: App request change(sx/sy=%d/%d w/h=%d/%d)",
1073                        sx, sy, es->buffer->width, es->buffer->height);
1074             es->geometry.width = shsurf->geometry_width;
1075             es->geometry.height = shsurf->geometry_height;
1076             es->geometry.x = shsurf->geometry_x;
1077             es->geometry.y = shsurf->geometry_y;
1078             if (es->geometry.width > es->buffer->width) {
1079                 es->geometry.width = es->buffer->width;
1080                 es->geometry.x = shsurf->geometry_x +
1081                                  (shsurf->geometry_width - es->geometry.width)/2;
1082             }
1083             if (es->geometry.height > es->buffer->height)   {
1084                 es->geometry.height = es->buffer->height;
1085                 es->geometry.y = shsurf->geometry_y +
1086                                  (shsurf->geometry_height - es->geometry.height)/2;
1087             }
1088             ivi_shell_surface_configure(shsurf, es->geometry.x, es->geometry.y,
1089                                         es->geometry.width, es->geometry.height);
1090             uifw_trace("shell_surface_configure: w/h=%d/%d->%d/%d x/y=%d/%d->%d/%d",
1091                        shsurf->geometry_width, shsurf->geometry_height,
1092                        es->geometry.width, es->geometry.height,
1093                        shsurf->geometry_x, shsurf->geometry_y,
1094                        (int)es->geometry.x, (int)es->geometry.y);
1095             num_mgr = ico_ivi_send_surface_change(es,
1096                                                   shsurf->geometry_x + to_x -from_x,
1097                                                   shsurf->geometry_y + to_y - from_y,
1098                                                   es->buffer->width, es->buffer->height);
1099             uifw_trace("shell_surface_configure: ret ivi_shell_hook_change(%d)", num_mgr)
1100         }
1101         if (num_mgr <= 0)   {
1102             /* manager not exist, change surface        */
1103             uifw_trace("shell_surface_configure: configure to Buffer size(no Manager) "
1104                        "x=%d+%d-%d y=%d+%d-%d",
1105                        (int)es->geometry.x, (int)to_x, (int)from_x,
1106                        (int)es->geometry.y, (int)to_y, (int)from_y);
1107             if ((es->geometry.x > ICO_IVI_MAX_COORDINATE) &&
1108                 (es->geometry.y > ICO_IVI_MAX_COORDINATE) &&
1109                 (shsurf->visible))  {
1110                 es->geometry.x = 0;
1111                 es->geometry.y = 0;
1112             }
1113             configure(shell, es,
1114                       es->geometry.x + to_x - from_x,
1115                       es->geometry.y + to_y - from_y,
1116                       es->buffer->width, es->buffer->height);
1117         }
1118     }
1119     uifw_trace("shell_surface_configure: Leave(surf=%08x out=%08x buf=%08x)",
1120                (int)es, (int)es->output, (int)es->buffer);
1121 }
1122
1123 /*--------------------------------------------------------------------------*/
1124 /**
1125  * @brief   bind_shell: client bind shell
1126  *
1127  * @param[in]   client      client(ex.HomeScreen)
1128  * @param[in]   data        user data(ico_ivi_shell static table address)
1129  * @param[in]   version     interface version number(unused)
1130  * @param[in]   id          client object id
1131  * @return      none
1132  */
1133 /*--------------------------------------------------------------------------*/
1134 static void
1135 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1136 {
1137     struct ivi_shell *shell = data;
1138     struct wl_resource *resource;
1139
1140     uifw_trace("bind_shell: client=%08x id=%d", (int)client, (int)id);
1141
1142     resource = wl_client_add_object(client, &wl_shell_interface,
1143                                     &shell_implementation, id, shell);
1144
1145     resource->destroy = unbind_shell;
1146
1147     if (shell_hook_bind)    {
1148         (*shell_hook_bind)(client);
1149     }
1150 }
1151
1152 /*--------------------------------------------------------------------------*/
1153 /**
1154  * @brief   unbind_shell: client unbind shell
1155  *
1156  * @param[in]   resource    unbind request resource
1157  * @return      none
1158  */
1159 /*--------------------------------------------------------------------------*/
1160 static void
1161 unbind_shell(struct wl_resource *resource)
1162 {
1163     uifw_trace("unbind_shell");
1164
1165     if (shell_hook_unbind)  {
1166         (*shell_hook_unbind)(resource->client);
1167     }
1168     free(resource);
1169 }
1170
1171 /*--------------------------------------------------------------------------*/
1172 /**
1173  * @brief   unbind_ivi_shell: client unbind ico_ivi_shell
1174  *
1175  * @param[in]   resource    unbind request resource
1176  * @return      none
1177  */
1178 /*--------------------------------------------------------------------------*/
1179 static void
1180 unbind_ivi_shell(struct wl_resource *resource)
1181 {
1182     uifw_trace("unbind_ivi_shell");
1183     free(resource);
1184 }
1185
1186 /*--------------------------------------------------------------------------*/
1187 /**
1188  * @brief   bind_ivi_shell: client bind ico_ivi_shell
1189  *
1190  * @param[in]   client      client(ex.HomeScreen)
1191  * @param[in]   data        user data(ico_ivi_shell static table address)
1192  * @param[in]   version     interface version number(unused)
1193  * @param[in]   id          client object id
1194  * @return      none
1195  */
1196 /*--------------------------------------------------------------------------*/
1197 static void
1198 bind_ivi_shell(struct wl_client *client,
1199                void *data, uint32_t version, uint32_t id)
1200 {
1201     struct ivi_shell *shell = data;
1202     struct wl_resource *resource;
1203
1204     resource = wl_client_add_object(client, &ico_ivi_shell_interface,
1205                                     NULL, id, shell);
1206
1207     uifw_trace("bind_ivi_shell: client=%08x id=%d", (int)client, (int)id);
1208
1209     resource->destroy = unbind_ivi_shell;
1210 }
1211
1212 /*--------------------------------------------------------------------------*/
1213 /**
1214  * @brief   shell_destroy: destroy ico_ivi_shell
1215  *
1216  * @param[in]   listener    shell destroy listener
1217  * @param[in]   data        user data(unused)
1218  * @return      none
1219  */
1220 /*--------------------------------------------------------------------------*/
1221 static void
1222 shell_destroy(struct wl_listener *listener, void *data)
1223 {
1224     struct ivi_shell *shell =
1225         container_of(listener, struct ivi_shell, destroy_listener);
1226
1227     uifw_trace("shell_destroy");
1228
1229     free(shell);
1230 }
1231
1232 /*--------------------------------------------------------------------------*/
1233 /**
1234  * @brief   ivi_shell_restack_ivi_layer: rebuild compositor surface list
1235  *
1236  * @param[in]   shell       ico_ivi_shell static table address
1237  * @param[in]   shsurf      target shell surface(if NULL, no need change surface)
1238  * @return      none
1239  */
1240 /*--------------------------------------------------------------------------*/
1241 static void
1242 ivi_shell_restack_ivi_layer(struct ivi_shell *shell, struct shell_surface *shsurf)
1243 {
1244     struct shell_surface  *es;
1245     struct ivi_layer_list *el;
1246     float   new_x, new_y;
1247
1248     uifw_trace("ivi_shell_restack_ivi_layer: Enter[%08x]", (int)shsurf);
1249
1250     /* make compositor surface list     */
1251     wl_list_init(&shell->surface.surface_list);
1252     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1253         if (ico_option_flag() & ICO_OPTION_FLAG_UNVISIBLE)  {
1254             wl_list_for_each (es, &el->surface_list, ivi_layer) {
1255                 if (es->surface != NULL)    {
1256                     if ((el->visible == FALSE) || (es->visible == FALSE))   {
1257                         new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1258                         new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1259                     }
1260                     else if (es->surface->buffer)   {
1261                         if (es->geometry_width > es->surface->buffer->width) {
1262                             new_x = (float)(es->geometry_x +
1263                                     (es->geometry_width - es->surface->geometry.width)/2);
1264                         }
1265                         else    {
1266                             new_x = (float)es->geometry_x;
1267                         }
1268                         if (es->geometry_height > es->surface->buffer->height) {
1269                             new_y = (float) (es->geometry_y +
1270                                     (es->geometry_height - es->surface->geometry.height)/2);
1271                         }
1272                         else    {
1273                             new_y = (float)es->geometry_y;
1274                         }
1275                     }
1276                     else    {
1277                         new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
1278                         new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
1279                     }
1280                     wl_list_insert(shell->surface.surface_list.prev,
1281                                    &es->surface->layer_link);
1282                     if ((new_x != es->surface->geometry.x) ||
1283                         (new_y != es->surface->geometry.y)) {
1284                         weston_surface_damage_below(es->surface);
1285                         es->surface->geometry.x = new_x;
1286                         es->surface->geometry.y = new_y;
1287                         weston_surface_damage_below(es->surface);
1288                     }
1289                 }
1290             }
1291         }
1292         else    {
1293             if (el->visible != FALSE)   {
1294                 wl_list_for_each (es, &el->surface_list, ivi_layer) {
1295                     if ((es->visible != FALSE) && (es->surface) &&
1296                         (es->surface->output != NULL) &&
1297                         (es->surface->shader != NULL))  {
1298                         wl_list_insert(shell->surface.surface_list.prev,
1299                                        &es->surface->layer_link);
1300                     }
1301                 }
1302             }
1303         }
1304     }
1305
1306     /* damage(redraw) target surfacem if target exist   */
1307     if (shsurf) {
1308         weston_surface_damage_below(shsurf->surface);
1309     }
1310
1311     /* composit and draw screen(plane)  */
1312     weston_compositor_schedule_repaint(shell->compositor);
1313
1314     uifw_trace("ivi_shell_restack_ivi_layer: Leave");
1315 }
1316
1317 /*--------------------------------------------------------------------------*/
1318 /**
1319  * @brief   ivi_shell_set_active: surface active control
1320  *
1321  * @param[in]   shsurf      shell surface(if NULL, no active surface)
1322  * @param[in]   target      target device
1323  * @return      none
1324  */
1325 /*--------------------------------------------------------------------------*/
1326 WL_EXPORT void
1327 ivi_shell_set_active(struct shell_surface *shsurf, const int target)
1328 {
1329     struct ivi_shell *shell;
1330     struct weston_seat *seat;
1331     struct weston_surface *surface;
1332     int object = target;
1333     wl_fixed_t sx, sy;
1334
1335     uifw_trace("ivi_shell_set_active: Enter(%08x,%x)", (int)shsurf, target);
1336
1337     if (shsurf) {
1338         shell = shell_surface_get_shell(shsurf);
1339         surface = shsurf->surface;
1340         if (object == 0)    {
1341             surface = NULL;
1342             if (shell->active_pointer_shsurf == shsurf) {
1343                 object |= ICO_IVI_SHELL_ACTIVE_POINTER;
1344             }
1345             if (shell->active_keyboard_shsurf == shsurf)    {
1346                 object |= ICO_IVI_SHELL_ACTIVE_KEYBOARD;
1347             }
1348         }
1349         else    {
1350             if (object & ICO_IVI_SHELL_ACTIVE_POINTER) {
1351                 shell->active_pointer_shsurf = shsurf;
1352             }
1353             if (object & ICO_IVI_SHELL_ACTIVE_KEYBOARD)    {
1354                 shell->active_keyboard_shsurf = shsurf;
1355             }
1356         }
1357     }
1358     else    {
1359         shell = default_shell;
1360         surface = NULL;
1361         if (target == 0)    {
1362             object = ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD;
1363         }
1364         if (object & ICO_IVI_SHELL_ACTIVE_POINTER) {
1365             shell->active_pointer_shsurf = NULL;
1366         }
1367         if (object & ICO_IVI_SHELL_ACTIVE_KEYBOARD)    {
1368             shell->active_keyboard_shsurf = NULL;
1369         }
1370     }
1371
1372     wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1373         if ((object & ICO_IVI_SHELL_ACTIVE_POINTER) && (seat->seat.pointer))   {
1374             if (surface)    {
1375                 uifw_trace("ivi_shell_set_active: pointer set surface(%08x=>%08x)",
1376                            (int)seat->seat.pointer->focus, (int)&surface->surface);
1377                 if (seat->seat.pointer->focus != &surface->surface) {
1378                     weston_surface_from_global_fixed(surface,
1379                                                      seat->seat.pointer->x,
1380                                                      seat->seat.pointer->y,
1381                                                      &sx, &sy);
1382                     wl_pointer_set_focus(seat->seat.pointer, &surface->surface, sx, sy);
1383                 }
1384             }
1385             else    {
1386                 uifw_trace("ivi_shell_set_active: pointer reset surface(%08x)",
1387                            (int)seat->seat.pointer->focus);
1388                 wl_pointer_set_focus(seat->seat.pointer, NULL,
1389                                      wl_fixed_from_int(0), wl_fixed_from_int(0));
1390             }
1391         }
1392         if ((object & ICO_IVI_SHELL_ACTIVE_KEYBOARD) && (seat->has_keyboard))  {
1393             if (surface)    {
1394                 uifw_trace("ivi_shell_set_active: keyboard set surface(%08x=>%08x)",
1395                            (int)seat->seat.keyboard->focus, (int)&surface->surface);
1396                 if (seat->seat.keyboard->focus != &surface->surface)    {
1397                     wl_keyboard_set_focus(seat->seat.keyboard, &surface->surface);
1398                 }
1399             }
1400             else    {
1401                 uifw_trace("ivi_shell_set_active: keyboard reset surface(%08x)",
1402                            (int)seat->seat.keyboard);
1403                 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
1404             }
1405         }
1406         else    {
1407             uifw_trace("ivi_shell_set_active: seat[%08x] has no keyboard", (int)seat);
1408         }
1409     }
1410     uifw_trace("ivi_shell_set_active: Leave(%08x)", (int)shsurf);
1411 }
1412
1413 /*--------------------------------------------------------------------------*/
1414 /**
1415  * @brief   ivi_shell_set_client_attr : set client ttribute
1416  *
1417  * @param[in]   client      target client
1418  * @param[in]   attr        attribute
1419  * @param[in]   value       attribute value
1420  * @return      none
1421  */
1422 /*--------------------------------------------------------------------------*/
1423 WL_EXPORT void
1424 ivi_shell_set_client_attr(struct wl_client *client, const int attr, const int value)
1425 {
1426     struct shell_surface  *es;
1427     struct ivi_layer_list *el;
1428
1429     uifw_trace("ivi_shell_set_client_attr: Enter(%08x,%d,%d)", (int)client, attr, value);
1430
1431     wl_list_for_each (el, &default_shell->ivi_layer.link, link) {
1432         wl_list_for_each (es, &el->surface_list, ivi_layer) {
1433             if (es->wclient == client)   {
1434                 switch(attr)    {
1435                 case ICO_CLEINT_ATTR_NOCONFIGURE:
1436                     es->noconfigure = value;
1437                     uifw_trace("ivi_shell_set_client_attr: set surface %08x", (int)es);
1438                     break;
1439                 default:
1440                     break;
1441                 }
1442             }
1443         }
1444     }
1445     uifw_trace("ivi_shell_set_client_attr: Leave");
1446 }
1447
1448 /*--------------------------------------------------------------------------*/
1449 /**
1450  * @brief   ivi_shell_set_active: surface active control
1451  *
1452  * @param[in]   shsurf      shell surface(if NULL, no active surface)
1453  * @param[in]   restrain    restrain(1)/not restrain(0)
1454  * @return      none
1455  */
1456 /*--------------------------------------------------------------------------*/
1457 WL_EXPORT void
1458 ivi_shell_restrain_configure(struct shell_surface *shsurf, const int restrain)
1459 {
1460     uifw_trace("ivi_shell_restrain_configure: set %08x to %d",
1461                (int)shsurf, restrain);
1462     shsurf->restrain = restrain;
1463
1464     if (restrain == 0)  {
1465         ivi_shell_restack_ivi_layer(shell_surface_get_shell(shsurf), shsurf);
1466     }
1467 }
1468
1469 /*--------------------------------------------------------------------------*/
1470 /**
1471  * @brief   ivi_shell_default_animation: window default animation
1472  *
1473  * @param[out]  msec    animation time(ms)
1474  * @param[out]  fps     animation frame rate(fps)
1475  * @return      default animation name
1476  */
1477 /*--------------------------------------------------------------------------*/
1478 WL_EXPORT const char *
1479 ivi_shell_default_animation(int *msec, int *fps)
1480 {
1481     if (msec)   {
1482         *msec = default_shell->win_animation_time;
1483     }
1484     if (fps)   {
1485         *fps = default_shell->win_animation_fps;
1486     }
1487     return default_shell->win_animation;
1488 }
1489
1490 /*--------------------------------------------------------------------------*/
1491 /**
1492  * @brief   click_to_activate_binding: clieck and select surface
1493  *
1494  * @param[in]   seat        clicked target seat
1495  * @param[in]   button      click button(unused)
1496  * @param[in]   data        user data(ico_ivi_shell static table address)
1497  * @return      none
1498  */
1499 /*--------------------------------------------------------------------------*/
1500 static void
1501 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
1502 {
1503     struct ivi_shell *shell = data;
1504     struct shell_surface *shsurf;
1505     struct weston_surface *surface;
1506
1507     if ((! seat) || (! seat->pointer) || (! seat->pointer->focus))  {
1508         uifw_trace("click_to_activate_binding: Surface dose not exist");
1509     }
1510     else    {
1511         surface = (struct weston_surface *) seat->pointer->focus;
1512         shsurf = get_shell_surface(surface);
1513         if (! shsurf)   {
1514             uifw_trace("click_to_activate_binding: Shell surface dose not exist");
1515         }
1516         else if ((shsurf->type == SHELL_SURFACE_NONE) ||
1517                  (shsurf->visible == 0))    {
1518             uifw_trace("click_to_activate_binding: Surface[%08x] is not visible",
1519                        (int)shsurf);
1520         }
1521         else if (shell->active_pointer_shsurf != shsurf)    {
1522             if (shell_hook_select) {
1523                 /* surface select hook routine      */
1524                 uifw_trace("click_to_activate_binding: call ivi_shell_hook_select[%08x]",
1525                            (int)shsurf);
1526                 (void) (*shell_hook_select)(surface);
1527                 uifw_trace("click_to_activate_binding: ret  ivi_shell_hook_select")
1528             }
1529             else    {
1530                 ivi_shell_set_active(shsurf,
1531                                      ICO_IVI_SHELL_ACTIVE_POINTER |
1532                                          ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1533                 uifw_trace("click_to_activate_binding: no hook[%08x]", (int)shsurf);
1534             }
1535         }
1536         else    {
1537             uifw_trace("click_to_activate_binding: ShellSurface[%08x] already active",
1538                        (int)shsurf);
1539         }
1540     }
1541 }
1542
1543 /*--------------------------------------------------------------------------*/
1544 /**
1545  * @brief   ivi_shell_set_visible: surface visible control
1546  *
1547  * @param[in]   shsurf      shell surface
1548  * @param[in]   visible     visibility(1=visible/0=unvisible)
1549  * @return      none
1550  */
1551 /*--------------------------------------------------------------------------*/
1552 WL_EXPORT void
1553 ivi_shell_set_visible(struct shell_surface *shsurf, const int visible)
1554 {
1555     struct ivi_shell *shell = shell_surface_get_shell(shsurf);
1556     int next;
1557
1558     uifw_trace("ivi_shell_set_visible: [%08x] visible=%d", (int)shsurf, (int)visible);
1559
1560     if (visible < 0)    {
1561         next = shell->win_visible_on_create;
1562     }
1563     else    {
1564         next = visible;
1565     }
1566
1567     if ((shsurf->visible != FALSE) && (next == 0))  {
1568         /* change show ==> hide         */
1569         shsurf->visible = FALSE;
1570         ivi_shell_restack_ivi_layer(shell, shsurf);
1571     }
1572     else if ((shsurf->visible == FALSE) && (next != 0)) {
1573         /* change hide ==> show         */
1574         shsurf->visible = TRUE;
1575         ivi_shell_restack_ivi_layer(shell, shsurf);
1576     }
1577     else    {
1578         /* other case, no change        */
1579         uifw_trace("ivi_shell_set_visible: No change");
1580     }
1581 }
1582
1583 /*--------------------------------------------------------------------------*/
1584 /**
1585  * @brief   ivi_shell_is_visible: get surface visibility
1586  *
1587  * @param[in]   shsurf      shell surface
1588  * @return      visibility
1589  * @retval      true        visible
1590  * @retval      false       unvisible
1591  */
1592 /*--------------------------------------------------------------------------*/
1593 WL_EXPORT bool
1594 ivi_shell_is_visible(struct shell_surface *shsurf)
1595 {
1596     return(shsurf->visible);
1597 }
1598
1599 /*--------------------------------------------------------------------------*/
1600 /**
1601  * @brief   ivi_shell_set_layer: set(or change) surface layer
1602  *
1603  * @param[in]   shsurf      shell surface
1604  * @param[in]   layer       layer id
1605  * @return      none
1606  */
1607 /*--------------------------------------------------------------------------*/
1608 WL_EXPORT void
1609 ivi_shell_set_layer(struct shell_surface *shsurf, const int layer)
1610 {
1611     struct ivi_shell *shell;
1612     struct ivi_layer_list *el;
1613     struct ivi_layer_list *new_el;
1614
1615     uifw_trace("ivi_shell_set_layer: Enter([%08x],%08x,%d)",
1616                (int)shsurf, (int)shsurf->surface, layer);
1617
1618     shell = shell_surface_get_shell(shsurf);
1619
1620     /* check if same layer                      */
1621     if ((shsurf->layer_list != NULL) && (shsurf->layer_list->layer == layer))   {
1622         uifw_trace("ivi_shell_set_layer: Leave(Same Layer)");
1623         return;
1624     }
1625
1626     /* search existing layer                    */
1627     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1628         uifw_trace("ivi_shell_set_layer: el=%08x(%d)", (int)el, el->layer);
1629         if (el->layer == layer) break;
1630     }
1631
1632     if (&el->link == &shell->ivi_layer.link)    {
1633         /* layer not exist, create new layer    */
1634         uifw_trace("ivi_shell_set_layer: New Layer %d", layer);
1635         new_el = malloc(sizeof(struct ivi_layer_list));
1636         if (! new_el)   {
1637             uifw_trace("ivi_shell_set_layer: Leave(No Memory)");
1638             return;
1639         }
1640
1641         memset(new_el, 0, sizeof(struct ivi_layer_list));
1642         new_el->layer = layer;
1643         new_el->visible = TRUE;
1644         wl_list_init(&new_el->surface_list);
1645         wl_list_init(&new_el->link);
1646
1647         wl_list_remove(&shsurf->ivi_layer);
1648         wl_list_insert(&new_el->surface_list, &shsurf->ivi_layer);
1649         shsurf->layer_list = new_el;
1650
1651         wl_list_for_each (el, &shell->ivi_layer.link, link) {
1652             if (layer >= el->layer) break;
1653         }
1654         if (&el->link == &shell->ivi_layer.link)    {
1655             wl_list_insert(shell->ivi_layer.link.prev, &new_el->link);
1656         }
1657         else    {
1658             wl_list_insert(el->link.prev, &new_el->link);
1659         }
1660     }
1661     else    {
1662         uifw_trace("ivi_shell_set_layer: Add surface to Layer %d", layer);
1663         wl_list_remove(&shsurf->ivi_layer);
1664         wl_list_insert(&el->surface_list, &shsurf->ivi_layer);
1665         shsurf->layer_list = el;
1666     }
1667
1668     /* rebild compositor surface list       */
1669     ivi_shell_restack_ivi_layer(shell, shsurf);
1670
1671     uifw_trace("ivi_shell_set_layer: Leave");
1672 }
1673
1674 /*--------------------------------------------------------------------------*/
1675 /**
1676  * @brief   ivi_shell_set_raise: surface stack control
1677  *
1678  * @param[in]   shsurf      shell surface
1679  * @param[in]   raise       raise/lower(1=raise/0=lower)
1680  * @return      none
1681  */
1682 /*--------------------------------------------------------------------------*/
1683 WL_EXPORT void
1684 ivi_shell_set_raise(struct shell_surface *shsurf, const int raise)
1685 {
1686     uifw_trace("ivi_shell_set_raise: Enter(%08x,%d) layer_list=%08x",
1687                (int)shsurf->surface, raise, (int)shsurf->layer_list);
1688
1689     wl_list_remove(&shsurf->ivi_layer);
1690     if (raise)  {
1691         /* raise ... surface stack to top of layer          */
1692         wl_list_insert(&shsurf->layer_list->surface_list, &shsurf->ivi_layer);
1693         uifw_trace("ivi_shell_set_raise: Raise Link to Top");
1694     }
1695     else    {
1696         /* Lower ... surface stack to bottom of layer       */
1697         wl_list_insert(shsurf->layer_list->surface_list.prev, &shsurf->ivi_layer);
1698         uifw_trace("ivi_shell_set_raise: Lower Link to Bottom");
1699     }
1700
1701     /* rebild compositor surface list               */
1702     ivi_shell_restack_ivi_layer(shell_surface_get_shell(shsurf), shsurf);
1703
1704     uifw_trace("ivi_shell_set_raise: Leave");
1705 }
1706
1707 /*--------------------------------------------------------------------------*/
1708 /**
1709  * @brief   ivi_shell_set_toplevel: set surface type toplevel
1710  *
1711  * @param[in]   shsurf      shell surface
1712  * @return      none
1713  */
1714 /*--------------------------------------------------------------------------*/
1715 WL_EXPORT void
1716 ivi_shell_set_toplevel(struct shell_surface *shsurf)
1717 {
1718     uifw_trace("ivi_shell_set_toplevel: (%08x)", (int)shsurf->surface);
1719     set_toplevel(shsurf);
1720 }
1721
1722 /*--------------------------------------------------------------------------*/
1723 /**
1724  * @brief   ivi_shell_set_surface_type: set surface type
1725  *
1726  * @param[in]   shsurf      shell surface
1727  * @return      none
1728  */
1729 /*--------------------------------------------------------------------------*/
1730 WL_EXPORT void
1731 ivi_shell_set_surface_type(struct shell_surface *shsurf)
1732 {
1733     uifw_trace("ivi_shell_set_surfacetype: (%08x)", (int)shsurf->surface);
1734     set_surface_type(shsurf);
1735 }
1736
1737 /*--------------------------------------------------------------------------*/
1738 /**
1739  * @brief   ivi_shell_send_configure: send surface resize event
1740  *
1741  * @param[in]   shsurf      shell surface
1742  * @param[in]   id          client object id(unused)
1743  * @param[in]   edges       surface resize position
1744  * @param[in]   width       surface width
1745  * @param[in]   height      surface height
1746  * @return      none
1747  */
1748 /*--------------------------------------------------------------------------*/
1749 WL_EXPORT void
1750 ivi_shell_send_configure(struct shell_surface *shsurf, const int id,
1751                          const int edges, const int width, const int height)
1752 {
1753     /* send cgange event to manager     */
1754     uifw_trace("ivi_shell_send_configure: (%08x) edges=%x w/h=%d/%d map=%d",
1755                (int)shsurf->surface, edges, width, height, shsurf->mapped);
1756
1757     shsurf->geometry_width = width;
1758     shsurf->geometry_height = height;
1759
1760     if ((shsurf->mapped == 0) || (shsurf->noconfigure != 0) ||
1761         (width == 0) || (height == 0))  {
1762         return;
1763     }
1764
1765     /* send cgange event to application */
1766     uifw_trace("ivi_shell_send_configure: Send (%08x) w/h=%d/%d(old=%d/%d)",
1767                (int)shsurf->surface, width, height,
1768                shsurf->configure_app.width, shsurf->configure_app.height);
1769     shsurf->configure_app.width = width;
1770     shsurf->configure_app.height = height;
1771
1772     wl_shell_surface_send_configure(&shsurf->resource,
1773                                     WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,
1774                                     width, height);
1775 }
1776
1777 /*--------------------------------------------------------------------------*/
1778 /**
1779  * @brief   ivi_shell_set_positionsize: set surface position and size
1780  *
1781  * @param[in]   shsurf      shell surface
1782  * @param[in]   x           surface upper-left X position on screen
1783  * @param[in]   y           surface upper-left Y position on screen
1784  * @param[in]   width       surface width
1785  * @param[in]   height      surface height
1786  * @return      none
1787  */
1788 /*--------------------------------------------------------------------------*/
1789 WL_EXPORT void
1790 ivi_shell_set_positionsize(struct shell_surface *shsurf,
1791                            const int x, const int y, const int width, const int height)
1792 {
1793     shsurf->geometry_x = x;
1794     shsurf->geometry_y = y;
1795     shsurf->geometry_width = width;
1796     shsurf->geometry_height = height;
1797
1798     weston_compositor_schedule_repaint(shell_surface_get_shell(shsurf)->compositor);
1799 }
1800
1801 /*--------------------------------------------------------------------------*/
1802 /**
1803  * @brief   ivi_shell_set_layer_visible: layer visible control
1804  *
1805  * @param[in]   layer       layer id
1806  * @param[in]   visible     visibility(1=visible/0=unvisible)
1807  * @return      none
1808  */
1809 /*--------------------------------------------------------------------------*/
1810 WL_EXPORT void
1811 ivi_shell_set_layer_visible(const int layer, const int visible)
1812 {
1813     struct ivi_shell *shell;
1814     struct ivi_layer_list *el;
1815     struct ivi_layer_list *new_el;
1816     struct shell_surface  *es;
1817
1818     uifw_trace("ivi_shell_set_layer_visible: Enter(layer=%d, visible=%d)", layer, visible);
1819
1820     shell = shell_surface_get_shell(NULL);
1821
1822     /* Search Layer                             */
1823     wl_list_for_each (el, &shell->ivi_layer.link, link) {
1824         if (el->layer == layer) break;
1825     }
1826
1827     if (&el->link == &shell->ivi_layer.link)    {
1828         /* layer not exist, create new layer    */
1829         uifw_trace("ivi_shell_set_layer_visible: New Layer %d", layer);
1830         new_el = malloc(sizeof(struct ivi_layer_list));
1831         if (! new_el)   {
1832             uifw_trace("ivi_shell_set_layer_visible: Leave(No Memory)");
1833             return;
1834         }
1835
1836         memset(new_el, 0, sizeof(struct ivi_layer_list));
1837         new_el->layer = layer;
1838         new_el->visible = TRUE;
1839         wl_list_init(&new_el->surface_list);
1840         wl_list_init(&new_el->link);
1841
1842         wl_list_for_each (el, &shell->ivi_layer.link, link) {
1843             if (layer >= el->layer) break;
1844         }
1845         if (&el->link == &shell->ivi_layer.link)    {
1846             wl_list_insert(shell->ivi_layer.link.prev, &new_el->link);
1847         }
1848         else    {
1849             wl_list_insert(el->link.prev, &new_el->link);
1850         }
1851         uifw_trace("ivi_shell_set_layer_visible: Leave(new layer)");
1852         return;
1853     }
1854
1855     /* control all surface in layer */
1856     if ((el->visible != FALSE) && (visible == 0))   {
1857         /* layer change to NOT visible  */
1858         uifw_trace("ivi_shell_set_layer_visible: change to not visible");
1859         el->visible = FALSE;
1860     }
1861     else if ((el->visible == FALSE) && (visible != 0))  {
1862         /* layer change to visible      */
1863         uifw_trace("ivi_shell_set_layer_visible: change to visible");
1864         el->visible = TRUE;
1865     }
1866     else    {
1867         /* no change    */
1868         uifw_trace("ivi_shell_set_layer_visible: Leave(no Change %d=>%d)",
1869                    el->visible, visible);
1870         return;
1871     }
1872
1873     /* set damege area          */
1874     wl_list_for_each (es, &el->surface_list, ivi_layer) {
1875         if ((es->visible != FALSE) &&
1876             (es->surface->output != NULL) &&
1877             (es->surface->shader != NULL))  {
1878             /* Damage(redraw) target surface    */
1879             weston_surface_damage_below(es->surface);
1880         }
1881     }
1882
1883     /* rebild compositor surface list       */
1884     ivi_shell_restack_ivi_layer(shell, NULL);
1885
1886     uifw_trace("ivi_shell_set_layer_visible: Leave");
1887 }
1888
1889 /*--------------------------------------------------------------------------*/
1890 /**
1891  * @brief   ivi_shell_surface_configure: surface change
1892  *
1893  * @param[in]   shsurf      shell surface
1894  * @param[in]   x           surface upper-left X position on screen
1895  * @param[in]   y           surface upper-left Y position on screen
1896  * @param[in]   width       surface width
1897  * @param[in]   height      surface height
1898  * @return      none
1899  */
1900 /*--------------------------------------------------------------------------*/
1901 WL_EXPORT void
1902 ivi_shell_surface_configure(struct shell_surface *shsurf, const int x,
1903                             const int y, const int width, const int height)
1904 {
1905     int set_unvisible = 0;
1906
1907     if (ico_option_flag() & ICO_OPTION_FLAG_UNVISIBLE)  {
1908         if ((shsurf->surface != NULL) && (shsurf->surface->buffer != NULL) &&
1909             (shsurf->surface->output != NULL) && (shsurf->surface->shader != NULL))  {
1910             if ((shsurf->visible == FALSE) ||
1911                 ((shsurf->layer_list != NULL) &&
1912                  (shsurf->layer_list->visible == FALSE)))   {
1913                 set_unvisible = 1;
1914             }
1915         }
1916     }
1917     if (set_unvisible)  {
1918         uifw_trace("ivi_shell_surface_configure: %08x %d,%d(%d/%d) unvisible",
1919                    (int)shsurf, x, y, width, height);
1920         weston_surface_configure(shsurf->surface,
1921                                  ICO_IVI_MAX_COORDINATE+1, ICO_IVI_MAX_COORDINATE+1,
1922                                  width, height);
1923     }
1924     else    {
1925         uifw_trace("ivi_shell_surface_configure: %08x %d,%d(%d/%d) visible",
1926                    (int)shsurf, x, y, width, height);
1927         weston_surface_configure(shsurf->surface, x, y, width, height);
1928     }
1929 }
1930
1931 /*--------------------------------------------------------------------------*/
1932 /**
1933  * @brief   ivi_shell_hook_bind: regist hook function for shell bind
1934  *
1935  * @param[in]   hook_bind       hook function(if NULL, reset hook function)
1936  * @return      none
1937  */
1938 /*--------------------------------------------------------------------------*/
1939 WL_EXPORT void
1940 ivi_shell_hook_bind(void (*hook_bind)(struct wl_client *client))
1941 {
1942     uifw_trace("ivi_shell_hook_bind: Hook %08x", (int)hook_bind);
1943     shell_hook_bind = hook_bind;
1944 }
1945
1946 /*--------------------------------------------------------------------------*/
1947 /**
1948  * @brief   ivi_shell_hook_unbind: regist hook function for shell unbind
1949  *
1950  * @param[in]   hook_unbind     hook function(if NULL, reset hook function)
1951  * @return      none
1952  */
1953 /*--------------------------------------------------------------------------*/
1954 WL_EXPORT void
1955 ivi_shell_hook_unbind(void (*hook_unbind)(struct wl_client *client))
1956 {
1957     uifw_trace("ivi_shell_hook_unbind: Hook %08x", (int)hook_unbind);
1958     shell_hook_unbind = hook_unbind;
1959 }
1960
1961 /*--------------------------------------------------------------------------*/
1962 /**
1963  * @brief   ivi_shell_hook_create: regist hook function for create shell surface
1964  *
1965  * @param[in]   hook_create     hook function(if NULL, reset hook function)
1966  * @return      none
1967  */
1968 /*--------------------------------------------------------------------------*/
1969 WL_EXPORT void
1970 ivi_shell_hook_create(void (*hook_create)(struct wl_client *client,
1971                       struct wl_resource *resource, struct weston_surface *surface,
1972                       struct shell_surface *shsurf))
1973 {
1974     uifw_trace("ivi_shell_hook_create: Hook %08x", (int)hook_create);
1975     shell_hook_create = hook_create;
1976 }
1977
1978 /*--------------------------------------------------------------------------*/
1979 /**
1980  * @brief   ivi_shell_hook_destroy: regist hook function for destroy shell surface
1981  *
1982  * @param[in]   hook_destroy    hook function(if NULL, reset hook function)
1983  * @return      none
1984  */
1985 /*--------------------------------------------------------------------------*/
1986 WL_EXPORT void
1987 ivi_shell_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
1988 {
1989     uifw_trace("ivi_shell_hook_destroy: Hook %08x", (int)hook_destroy);
1990     shell_hook_destroy = hook_destroy;
1991 }
1992
1993 /*--------------------------------------------------------------------------*/
1994 /**
1995  * @brief   ivi_shell_hook_map: regist hook function for map shell surface
1996  *
1997  * @param[in]   hook_map        hook function(if NULL, reset hook function)
1998  * @return      none
1999  */
2000 /*--------------------------------------------------------------------------*/
2001 WL_EXPORT void
2002 ivi_shell_hook_map(void (*hook_map)(struct weston_surface *surface,
2003                         int32_t *width, int32_t *height, int32_t *sx, int32_t *sy))
2004 {
2005     uifw_trace("ivi_shell_hook_map: Hook %08x", (int)hook_map);
2006     shell_hook_map = hook_map;
2007 }
2008
2009 /*--------------------------------------------------------------------------*/
2010 /**
2011  * @brief   ivi_shell_hook_change: regist hook function for change shell surface
2012  *
2013  * @param[in]   hook_change     hook function(if NULL, reset hook function)
2014  * @return      none
2015  */
2016 /*--------------------------------------------------------------------------*/
2017 WL_EXPORT void
2018 ivi_shell_hook_change(void (*hook_change)(struct weston_surface *surface,
2019                                           const int to, const int manager))
2020 {
2021     uifw_trace("ivi_shell_hook_change: Hook %08x", (int)hook_change);
2022     shell_hook_change = hook_change;
2023 }
2024
2025 /*--------------------------------------------------------------------------*/
2026 /**
2027  * @brief   ivi_shell_hook_select: regist hook function for select(active) shell surface
2028  *
2029  * @param[in]   hook_select     hook function(if NULL, reset hook function)
2030  * @return      none
2031  */
2032 /*--------------------------------------------------------------------------*/
2033 WL_EXPORT void
2034 ivi_shell_hook_select(void (*hook_select)(struct weston_surface *surface))
2035 {
2036     uifw_trace("ivi_shell_hook_select: Hook %08x", (int)hook_select);
2037     shell_hook_select = hook_select;
2038 }
2039
2040 /*--------------------------------------------------------------------------*/
2041 /**
2042  * @brief   module_init: initialize ico_ivi_shell
2043  *                       this function called from ico_pluign_loader
2044  *
2045  * @param[in]   es          weston compositor
2046  * @return      result
2047  * @retval      0           sccess
2048  * @retval      -1          error
2049  */
2050 /*--------------------------------------------------------------------------*/
2051 WL_EXPORT int
2052 module_init(struct weston_compositor *ec)
2053 {
2054     struct ivi_shell *shell;
2055
2056     uifw_info("ico_ivi_shell: Enter(module_init)");
2057
2058     shell = malloc(sizeof *shell);
2059     if (shell == NULL)  return -1;
2060     default_shell = shell;
2061
2062     memset(shell, 0, sizeof *shell);
2063     shell->compositor = ec;
2064
2065     shell->destroy_listener.notify = shell_destroy;
2066     wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2067     ec->shell_interface.shell = shell;
2068     ec->shell_interface.create_shell_surface = create_shell_surface;
2069     ec->shell_interface.set_toplevel = set_toplevel;
2070     ec->shell_interface.set_transient = set_transient;
2071
2072     wl_list_init(&shell->ivi_layer.link);
2073     weston_layer_init(&shell->surface, &ec->cursor_layer.link);
2074
2075     uifw_trace("ico_ivi_shell: shell(%08x) ivi_layer.link.%08x=%08x/%08x",
2076                (int)shell, (int)&shell->ivi_layer.link,
2077                (int)shell->ivi_layer.link.next, (int)shell->ivi_layer.link.prev);
2078
2079     shell_configuration(shell);
2080
2081     if (wl_display_add_global(ec->wl_display, &wl_shell_interface, shell, bind_shell)
2082             == NULL)    {
2083         return -1;
2084     }
2085     if (wl_display_add_global(ec->wl_display, &ico_ivi_shell_interface,
2086                               shell, bind_ivi_shell) == NULL)   {
2087         return -1;
2088     }
2089
2090     weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
2091                                          click_to_activate_binding, shell);
2092
2093     uifw_info("ico_ivi_shell: Leave(module_init)");
2094     return 0;
2095 }
2096