weston-ivi-shell: Bug fix. can not get notification of Create/Remove layer
[profile/ivi/wayland-ivi-extension.git] / weston-ivi-shell / src / ivi-controller.c
1 /*
2  * Copyright (C) 2013 DENSO CORPORATION
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include <sys/wait.h>
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <linux/input.h>
29 #include <cairo.h>
30
31 #include "compositor.h"
32 #include "ivi-controller-server-protocol.h"
33 #include "weston-layout.h"
34
35 struct ivishell;
36 struct ivilayer;
37 struct iviscreen;
38
39 struct link_layer {
40     struct ivilayer *layer;
41     struct wl_list link;
42 };
43
44 struct link_screen {
45     struct iviscreen *screen;
46     struct wl_list link;
47 };
48
49 struct ivisurface {
50     struct wl_list link;
51     struct wl_client *client;
52     struct ivishell *shell;
53     uint32_t update_count;
54     struct weston_layout_surface *layout_surface;
55     struct wl_listener surface_destroy_listener;
56     struct wl_list list_layer;
57 };
58
59 struct ivilayer {
60     struct wl_list link;
61     struct ivishell *shell;
62     struct weston_layout_layer *layout_layer;
63     struct wl_list list_screen;
64 };
65
66 struct iviscreen {
67     struct wl_list link;
68     struct ivishell *shell;
69     struct weston_layout_screen *layout_screen;
70     struct weston_output *output;
71 };
72
73 struct ivicontroller_surface {
74     struct wl_resource *resource;
75     uint32_t id;
76     uint32_t id_surface;
77     struct wl_client *client;
78     struct wl_list link;
79     struct ivishell *shell;
80 };
81
82 struct ivicontroller_layer {
83     struct wl_resource *resource;
84     uint32_t id;
85     uint32_t id_layer;
86     struct wl_client *client;
87     struct wl_list link;
88     struct ivishell *shell;
89 };
90
91 struct ivicontroller_screen {
92     struct wl_resource *resource;
93     uint32_t id;
94     uint32_t id_screen;
95     struct wl_client *client;
96     struct wl_list link;
97     struct ivishell *shell;
98 };
99
100 struct ivicontroller {
101     struct wl_resource *resource;
102     uint32_t id;
103     struct wl_client *client;
104     struct wl_list link;
105     struct ivishell *shell;
106 };
107
108 struct link_shell_weston_surface
109 {
110     struct wl_resource *resource;
111     struct wl_listener destroy_listener;
112     struct weston_surface *surface;
113     struct wl_list link;
114 };
115
116 struct ping_timer {
117     struct wl_event_source *source;
118     uint32_t serial;
119 };
120
121 struct shell_surface {
122     struct wl_resource *resource;
123
124     struct weston_surface *surface;
125     struct wl_listener surface_destroy_listener;
126
127     struct ivishell *shell;
128     struct ping_timer *ping_timer;
129
130     char *title, *class;
131     int32_t width;
132     int32_t height;
133     pid_t pid;
134     struct wl_list link;
135
136     const struct weston_shell_client *client;
137     struct weston_output *output;
138 };
139
140 struct ivishell {
141     struct wl_resource *resource;
142
143     struct wl_listener destroy_listener;
144
145     struct weston_compositor *compositor;
146
147     struct weston_surface *surface;
148
149     struct weston_process process;
150
151     struct weston_seat *seat;
152
153     struct wl_list list_surface;
154     struct wl_list list_layer;
155     struct wl_list list_screen;
156
157     struct wl_list list_weston_surface;
158
159     struct wl_list list_controller;
160     struct wl_list list_controller_surface;
161     struct wl_list list_controller_layer;
162     struct wl_list list_controller_screen;
163
164     struct {
165         struct weston_process process;
166         struct wl_client *client;
167         struct wl_resource *desktop_shell;
168
169         unsigned deathcount;
170         uint32_t deathstamp;
171     } child;
172
173     int state;
174     int previous_state;
175     int event_restriction;
176 };
177
178 static void
179 destroy_ivicontroller_surface(struct wl_resource *resource)
180 {
181     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
182     struct ivishell *shell = ivisurf->shell;
183     struct ivicontroller_surface *ctrlsurf = NULL;
184     struct ivicontroller_surface *next = NULL;
185     uint32_t id_surface = 0;
186
187     id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
188
189     wl_list_for_each_safe(ctrlsurf, next,
190                           &shell->list_controller_surface, link) {
191         if (id_surface != ctrlsurf->id_surface) {
192             continue;
193         }
194
195         wl_list_remove(&ctrlsurf->link);
196         free(ctrlsurf);
197         ctrlsurf = NULL;
198         break;
199     }
200 }
201
202 static void
203 destroy_ivicontroller_layer(struct wl_resource *resource)
204 {
205     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
206     struct ivishell *shell = ivilayer->shell;
207     struct ivicontroller_layer *ctrllayer = NULL;
208     struct ivicontroller_layer *next = NULL;
209     uint32_t id_layer = 0;
210
211     id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
212
213     wl_list_for_each_safe(ctrllayer, next,
214                           &shell->list_controller_layer, link) {
215         if (id_layer != ctrllayer->id_layer) {
216             continue;
217         }
218
219         wl_list_remove(&ctrllayer->link);
220         free(ctrllayer);
221         ctrllayer = NULL;
222         break;
223     }
224 }
225
226 static void
227 destroy_ivicontroller_screen(struct wl_resource *resource)
228 {
229     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
230     struct ivicontroller_screen *ctrlscrn = NULL;
231     struct ivicontroller_screen *next = NULL;
232
233     wl_list_for_each_safe(ctrlscrn, next,
234                           &iviscrn->shell->list_controller_screen, link) {
235 // TODO : Only Single display
236 #if 0
237         if (iviscrn->output->id != ctrlscrn->id_screen) {
238             continue;
239         }
240 #endif
241         wl_list_remove(&ctrlscrn->link);
242         free(ctrlscrn);
243         ctrlscrn = NULL;
244         break;
245     }
246 }
247
248 static void
249 unbind_resource_controller(struct wl_resource *resource)
250 {
251     struct ivicontroller *controller = wl_resource_get_user_data(resource);
252
253     wl_list_remove(&controller->link);
254
255     free(controller);
256     controller = NULL;
257 }
258
259 static struct ivisurface*
260 get_surface(struct wl_list *list_surf, uint32_t id_surface)
261 {
262     struct ivisurface *ivisurf = NULL;
263     uint32_t ivisurf_id = 0;
264
265     wl_list_for_each(ivisurf, list_surf, link) {
266         ivisurf_id = weston_layout_getIdOfSurface(ivisurf->layout_surface);
267         if (ivisurf_id == id_surface) {
268             return ivisurf;
269         }
270     }
271
272     return NULL;
273 }
274
275 static struct ivilayer*
276 get_layer(struct wl_list *list_layer, uint32_t id_layer)
277 {
278     struct ivilayer *ivilayer = NULL;
279     uint32_t ivilayer_id = 0;
280
281     wl_list_for_each(ivilayer, list_layer, link) {
282         ivilayer_id = weston_layout_getIdOfLayer(ivilayer->layout_layer);
283         if (ivilayer_id == id_layer) {
284             return ivilayer;
285         }
286     }
287
288     return NULL;
289 }
290
291 static const
292 struct ivi_controller_screen_interface controller_screen_implementation;
293
294 static struct ivicontroller_screen*
295 controller_screen_create(struct ivishell *shell,
296                          struct wl_client *client,
297                          struct iviscreen *iviscrn)
298 {
299     struct ivicontroller_screen *ctrlscrn = NULL;
300
301     ctrlscrn = calloc(1, sizeof *ctrlscrn);
302     if (ctrlscrn == NULL) {
303         weston_log("no memory to allocate controller screen\n");
304         return NULL;
305     }
306
307     ctrlscrn->client = client;
308     ctrlscrn->shell  = shell;
309 // FIXME
310 // TODO : Only Single display
311 #if 0
312     /* ctrlscrn->id_screen = iviscrn->id_screen; */
313 #else
314     ctrlscrn->id_screen = 0;
315 #endif
316
317     ctrlscrn->resource =
318         wl_resource_create(client, &ivi_controller_screen_interface, 1, 0);
319     if (ctrlscrn->resource == NULL) {
320         weston_log("couldn't new screen controller object");
321
322         free(ctrlscrn);
323         ctrlscrn = NULL;
324
325         return NULL;
326     }
327
328     wl_resource_set_implementation(ctrlscrn->resource,
329                                    &controller_screen_implementation,
330                                    iviscrn, destroy_ivicontroller_screen);
331
332     wl_list_init(&ctrlscrn->link);
333     wl_list_insert(&shell->list_controller_screen, &ctrlscrn->link);
334
335     return ctrlscrn;
336 }
337
338 static void
339 send_surface_add_event(struct ivisurface *ivisurf,
340                        struct wl_resource *resource)
341 {
342     weston_layout_layer_ptr *pArray = NULL;
343     uint32_t length = 0;
344     int32_t ans = 0;
345     int i = 0;
346     struct link_layer *link_layer = NULL;
347     struct link_layer *next = NULL;
348     struct ivicontroller_layer *ctrllayer = NULL;
349     struct ivilayer *ivilayer = NULL;
350     struct ivishell *shell = ivisurf->shell;
351     uint32_t id_layout_layer = 0;
352     int found = 0;
353
354     ans = weston_layout_getLayersUnderSurface(ivisurf->layout_surface,
355                                           &length, &pArray);
356     if (0 != ans) {
357         weston_log("failed to get layers at send_surface_add_event\n");
358         return;
359     }
360
361     /* Send Null to cancel added surface */
362     wl_list_for_each_safe(link_layer, next, &ivisurf->list_layer, link) {
363         for (i = 0, found = 0; i < (int)length; i++) {
364             if (pArray[i] == link_layer->layer->layout_layer) {
365                 /* No need to send event, if new layer doesn't be added. */
366                 found = 1;
367                 break;
368             }
369         }
370         if (found != 0) {
371             continue;
372         }
373
374         ivi_controller_surface_send_layer(resource, NULL);
375         wl_list_remove(&link_layer->link);
376         free(link_layer);
377         link_layer = NULL;
378     }
379
380     for (i = 0; i < (int)length; i++) {
381         found = 0;
382         wl_list_for_each(link_layer, &ivisurf->list_layer, link) {
383             if (pArray[i] == link_layer->layer->layout_layer) {
384                 /* No need to send event, if new layer doesn't be added. */
385                 found = 1;
386                 break;
387             }
388         }
389         if (found != -1) {
390             continue;
391         }
392
393         /* Create list_layer */
394         link_layer = calloc(1, sizeof(*link_layer));
395         if (NULL == link_layer) {
396             continue;
397         }
398         wl_list_init(&link_layer->link);
399         link_layer->layer = NULL;
400         wl_list_for_each(ivilayer, &shell->list_layer, link) {
401             if (ivilayer->layout_layer == pArray[i]) {
402                 link_layer->layer = ivilayer;
403                 break;
404             }
405         }
406
407         if (link_layer->layer == NULL) {
408             free(link_layer);
409             link_layer = NULL;
410             continue;
411         }
412         wl_list_insert(&ivisurf->list_layer, &link_layer->link);
413
414         /* Send new surface event */
415         id_layout_layer =
416             weston_layout_getIdOfLayer(link_layer->layer->layout_layer);
417         wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
418             if (id_layout_layer != ctrllayer->id_layer) {
419                 continue;
420             }
421             ivi_controller_surface_send_layer(resource, ctrllayer->resource);
422         }
423     }
424
425     free(pArray);
426     pArray = NULL;
427 }
428
429 static void
430 send_surface_event(struct wl_resource *resource,
431                    struct ivisurface *ivisurf,
432                    struct weston_layout_SurfaceProperties *prop,
433                    uint32_t mask)
434 {
435     if (mask & IVI_NOTIFICATION_OPACITY) {
436         ivi_controller_surface_send_opacity(resource,
437                                             prop->opacity);
438     }
439     if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
440         ivi_controller_surface_send_source_rectangle(resource,
441             prop->sourceX, prop->sourceY,
442             prop->sourceWidth, prop->sourceHeight);
443     }
444     if (mask & IVI_NOTIFICATION_DEST_RECT) {
445         ivi_controller_surface_send_destination_rectangle(resource,
446             prop->destX, prop->destY,
447             prop->destWidth, prop->destHeight);
448     }
449     if (mask & IVI_NOTIFICATION_ORIENTATION) {
450         ivi_controller_surface_send_orientation(resource,
451                                                 prop->orientation);
452     }
453     if (mask & IVI_NOTIFICATION_VISIBILITY) {
454         ivi_controller_surface_send_visibility(resource,
455                                                prop->visibility);
456     }
457     if (mask & IVI_NOTIFICATION_PIXELFORMAT) {
458         ivi_controller_surface_send_pixelformat(resource,
459                                                 prop->pixelformat);
460     }
461     if (mask & IVI_NOTIFICATION_ADD) {
462         send_surface_add_event(ivisurf, resource);
463     }
464 }
465
466 static void
467 send_surface_prop(struct weston_layout_surface *layout_surface,
468                   struct weston_layout_SurfaceProperties *prop,
469                   enum weston_layout_notification_mask mask,
470                   void *userdata)
471 {
472     struct ivisurface *ivisurf = userdata;
473     struct ivishell *shell = ivisurf->shell;
474     struct ivicontroller_surface *ctrlsurf = NULL;
475     uint32_t id_surface = 0;
476
477     id_surface = weston_layout_getIdOfSurface(layout_surface);
478
479     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
480         if (id_surface != ctrlsurf->id_surface) {
481             continue;
482         }
483         send_surface_event(ctrlsurf->resource, ivisurf, prop, mask);
484     }
485 }
486
487 static void
488 send_layer_add_event(struct ivilayer *ivilayer,
489                      struct wl_resource *resource)
490 {
491     weston_layout_screen_ptr *pArray = NULL;
492     uint32_t length = 0;
493     int32_t ans = 0;
494     int i = 0;
495     struct link_screen *link_scrn = NULL;
496     struct link_screen *next = NULL;
497     struct iviscreen *iviscrn = NULL;
498     struct ivishell *shell = ivilayer->shell;
499     int found = 0;
500     struct wl_client *client = wl_resource_get_client(resource);
501     struct wl_resource *resource_output = NULL;
502
503     ans = weston_layout_getScreensUnderLayer(ivilayer->layout_layer,
504                                           &length, &pArray);
505     if (0 != ans) {
506         weston_log("failed to get screens at send_layer_add_event\n");
507         return;
508     }
509
510     /* Send Null to cancel added layer */
511     wl_list_for_each_safe(link_scrn, next, &ivilayer->list_screen, link) {
512         for (i = 0, found = 0; i < (int)length; i++) {
513             if (pArray[i] == link_scrn->screen->layout_screen) {
514                 /* No need to send event, if new layer doesn't be added. */
515                 found = 1;
516                 break;
517             }
518         }
519         if (found != 0) {
520             continue;
521         }
522
523         ivi_controller_layer_send_screen(resource, NULL);
524         wl_list_remove(&link_scrn->link);
525         free(link_scrn);
526         link_scrn = NULL;
527     }
528
529     for (i = 0; i < (int)length; i++) {
530         found = 0;
531         wl_list_for_each(link_scrn, &ivilayer->list_screen, link) {
532             if (pArray[i] == link_scrn->screen->layout_screen) {
533                 /* No need to send event, if new screen doesn't be added. */
534                 found = 1;
535                 break;
536             }
537         }
538         if (found != 0) {
539             continue;
540         }
541
542         /* Create list_screen */
543         link_scrn = calloc(1, sizeof(*link_scrn));
544         if (NULL == link_scrn) {
545             continue;
546         }
547         wl_list_init(&link_scrn->link);
548         link_scrn->screen = NULL;
549         wl_list_for_each(iviscrn, &shell->list_screen, link) {
550             if (iviscrn->layout_screen == pArray[i]) {
551                 link_scrn->screen = iviscrn;
552                 break;
553             }
554         }
555
556         if (link_scrn->screen == NULL) {
557             free(link_scrn);
558             link_scrn = NULL;
559             continue;
560         }
561         wl_list_insert(&ivilayer->list_screen, &link_scrn->link);
562
563         /* Send new layer event */
564         resource_output =
565             wl_resource_find_for_client(&iviscrn->output->resource_list,
566                                  client);
567         if (resource_output != NULL) {
568             ivi_controller_layer_send_screen(resource, resource_output);
569         }
570     }
571
572     free(pArray);
573     pArray = NULL;
574 }
575
576 static void
577 send_layer_event(struct wl_resource *resource,
578                  struct ivilayer *ivilayer,
579                  struct weston_layout_LayerProperties *prop,
580                  uint32_t mask)
581 {
582     if (mask & IVI_NOTIFICATION_OPACITY) {
583         ivi_controller_layer_send_opacity(resource,
584                                           prop->opacity);
585     }
586     if (mask & IVI_NOTIFICATION_SOURCE_RECT) {
587         ivi_controller_layer_send_source_rectangle(resource,
588                                           prop->sourceX,
589                                           prop->sourceY,
590                                           prop->sourceWidth,
591                                           prop->sourceHeight);
592     }
593     if (mask & IVI_NOTIFICATION_DEST_RECT) {
594         ivi_controller_layer_send_destination_rectangle(resource,
595                                           prop->destX,
596                                           prop->destY,
597                                           prop->destWidth,
598                                           prop->destHeight);
599     }
600     if (mask & IVI_NOTIFICATION_ORIENTATION) {
601         ivi_controller_layer_send_orientation(resource,
602                                           prop->orientation);
603     }
604     if (mask & IVI_NOTIFICATION_VISIBILITY) {
605         ivi_controller_layer_send_visibility(resource,
606                                           prop->visibility);
607     }
608     if (mask & IVI_NOTIFICATION_ADD) {
609         send_layer_add_event(ivilayer, resource);
610     }
611 }
612
613 static void
614 send_layer_prop(struct weston_layout_layer *layer,
615                 struct weston_layout_LayerProperties *prop,
616                 enum weston_layout_notification_mask mask,
617                 void *userdata)
618 {
619     struct ivilayer *ivilayer = userdata;
620     struct ivicontroller_layer *ctrllayer = NULL;
621     struct ivishell *shell = ivilayer->shell;
622     uint32_t id_layout_layer = 0;
623
624     id_layout_layer = weston_layout_getIdOfLayer(layer);
625     wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
626         if (id_layout_layer != ctrllayer->id_layer) {
627             continue;
628         }
629         send_layer_event(ctrllayer->resource, ivilayer, prop, mask);
630     }
631 }
632
633 static void
634 controller_surface_set_opacity(struct wl_client *client,
635                    struct wl_resource *resource,
636                    wl_fixed_t opacity)
637 {
638     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
639     (void)client;
640     weston_layout_surfaceSetOpacity(ivisurf->layout_surface, (float)opacity);
641 }
642
643 static void
644 controller_surface_set_source_rectangle(struct wl_client *client,
645                    struct wl_resource *resource,
646                    int32_t x,
647                    int32_t y,
648                    int32_t width,
649                    int32_t height)
650 {
651     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
652     (void)client;
653     weston_layout_surfaceSetSourceRectangle(ivisurf->layout_surface,
654             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
655 }
656
657 static void
658 controller_surface_set_destination_rectangle(struct wl_client *client,
659                      struct wl_resource *resource,
660                      int32_t x,
661                      int32_t y,
662                      int32_t width,
663                      int32_t height)
664 {
665     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
666     (void)client;
667     weston_layout_surfaceSetDestinationRectangle(ivisurf->layout_surface,
668             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
669 }
670
671 static void
672 controller_surface_set_visibility(struct wl_client *client,
673                       struct wl_resource *resource,
674                       uint32_t visibility)
675 {
676     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
677     (void)client;
678     weston_layout_surfaceSetVisibility(ivisurf->layout_surface, visibility);
679 }
680
681 static void
682 controller_surface_set_configuration(struct wl_client *client,
683                    struct wl_resource *resource,
684                    int32_t width, int32_t height)
685 {
686     /* This interface has been supported yet. */
687     (void)client;
688     (void)resource;
689     (void)width;
690     (void)height;
691 }
692
693 static void
694 controller_surface_set_orientation(struct wl_client *client,
695                    struct wl_resource *resource,
696                    int32_t orientation)
697 {
698     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
699     (void)client;
700     weston_layout_surfaceSetOrientation(ivisurf->layout_surface, (uint32_t)orientation);
701 }
702
703 static void
704 controller_surface_screenshot(struct wl_client *client,
705                   struct wl_resource *resource,
706                   const char *filename)
707 {
708     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
709     (void)client;
710     weston_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
711 }
712
713 static void
714 controller_surface_send_stats(struct wl_client *client,
715                               struct wl_resource *resource)
716 {
717     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
718     pid_t pid;
719     uid_t uid;
720     gid_t gid;
721     wl_client_get_credentials(client, &pid, &uid, &gid);
722
723     ivi_controller_surface_send_stats(resource, 0, 0,
724                                       ivisurf->update_count, pid, "");
725 }
726
727 static void
728 controller_surface_destroy(struct wl_client *client,
729               struct wl_resource *resource,
730               int32_t destroy_scene_object)
731 {
732     struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
733     struct ivishell *shell = ivisurf->shell;
734     struct ivicontroller_surface *ctrlsurf = NULL;
735     uint32_t id_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
736     (void)client;
737     (void)destroy_scene_object;
738
739     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
740         if (ctrlsurf->id_surface != id_surface) {
741             continue;
742         }
743
744         if (!wl_list_empty(&ctrlsurf->link)) {
745             wl_list_remove(&ctrlsurf->link);
746         }
747         wl_resource_destroy(resource);
748         break;
749     }
750 }
751
752 static void
753 controller_surface_set_input_focus(struct wl_client *client,
754               struct wl_resource *resource,
755               int32_t enabled)
756 {
757     (void)client;
758     (void)resource;
759     (void)enabled;
760 }
761
762 static const
763 struct ivi_controller_surface_interface controller_surface_implementation = {
764     controller_surface_set_visibility,
765     controller_surface_set_opacity,
766     controller_surface_set_source_rectangle,
767     controller_surface_set_destination_rectangle,
768     controller_surface_set_configuration,
769     controller_surface_set_orientation,
770     controller_surface_screenshot,
771     controller_surface_send_stats,
772     controller_surface_destroy,
773     controller_surface_set_input_focus
774 };
775
776 static void
777 controller_layer_set_source_rectangle(struct wl_client *client,
778                    struct wl_resource *resource,
779                    int32_t x,
780                    int32_t y,
781                    int32_t width,
782                    int32_t height)
783 {
784     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
785     (void)client;
786     weston_layout_layerSetSourceRectangle(ivilayer->layout_layer,
787            (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
788 }
789
790 static void
791 controller_layer_set_destination_rectangle(struct wl_client *client,
792                  struct wl_resource *resource,
793                  int32_t x,
794                  int32_t y,
795                  int32_t width,
796                  int32_t height)
797 {
798     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
799     (void)client;
800     weston_layout_layerSetDestinationRectangle(ivilayer->layout_layer,
801             (uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height);
802 }
803
804 static void
805 controller_layer_set_visibility(struct wl_client *client,
806                     struct wl_resource *resource,
807                     uint32_t visibility)
808 {
809     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
810     (void)client;
811     weston_layout_layerSetVisibility(ivilayer->layout_layer, visibility);
812 }
813
814 static void
815 controller_layer_set_opacity(struct wl_client *client,
816                  struct wl_resource *resource,
817                  wl_fixed_t opacity)
818 {
819     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
820     (void)client;
821     weston_layout_layerSetOpacity(ivilayer->layout_layer, (float)opacity);
822 }
823
824 static void
825 controller_layer_set_configuration(struct wl_client *client,
826                  struct wl_resource *resource,
827                  int32_t width,
828                  int32_t height)
829 {
830     /* This interface has been supported yet. */
831     (void)client;
832     (void)resource;
833     (void)width;
834     (void)height;
835 }
836
837 static void
838 controller_layer_set_orientation(struct wl_client *client,
839                  struct wl_resource *resource,
840                  int32_t orientation)
841 {
842     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
843     (void)client;
844     weston_layout_layerSetOrientation(ivilayer->layout_layer, (uint32_t)orientation);
845 }
846
847 static void
848 controller_layer_clear_surfaces(struct wl_client *client,
849                     struct wl_resource *resource)
850 {
851     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
852     (void)client;
853     weston_layout_layerSetRenderOrder(ivilayer->layout_layer, NULL, 0);
854 }
855
856 static void
857 controller_layer_add_surface(struct wl_client *client,
858                  struct wl_resource *resource,
859                  struct wl_resource *surface)
860 {
861     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
862     struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
863     (void)client;
864     weston_layout_layerAddSurface(ivilayer->layout_layer, ivisurf->layout_surface);
865 }
866
867 static void
868 controller_layer_remove_surface(struct wl_client *client,
869                     struct wl_resource *resource,
870                     struct wl_resource *surface)
871 {
872     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
873     struct ivisurface *ivisurf = wl_resource_get_user_data(surface);
874     (void)client;
875     weston_layout_layerRemoveSurface(ivilayer->layout_layer, ivisurf->layout_surface);
876 }
877
878 static void
879 controller_layer_screenshot(struct wl_client *client,
880                 struct wl_resource *resource,
881                 const char *filename)
882 {
883     (void)client;
884     (void)resource;
885     (void)filename;
886 }
887
888 static void
889 controller_layer_set_render_order(struct wl_client *client,
890                                   struct wl_resource *resource,
891                                   struct wl_array *id_surfaces)
892 {
893     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
894     struct weston_layout_surface **layoutsurf_array = NULL;
895     struct ivisurface *ivisurf = NULL;
896     uint32_t *id_surface = NULL;
897     uint32_t id_layout_surface = 0;
898     int i = 0;
899     (void)client;
900
901     wl_array_for_each(id_surface, id_surfaces) {
902         wl_list_for_each(ivisurf, &ivilayer->shell->list_surface, link) {
903             id_layout_surface = weston_layout_getIdOfSurface(ivisurf->layout_surface);
904             if (*id_surface == id_layout_surface) {
905                 layoutsurf_array[i] = ivisurf->layout_surface;
906                 i++;
907                 break;
908             }
909         }
910     }
911
912     weston_layout_layerSetRenderOrder(ivilayer->layout_layer,
913                                    layoutsurf_array, id_surfaces->size);
914     free(layoutsurf_array);
915 }
916
917 static void
918 controller_layer_destroy(struct wl_client *client,
919               struct wl_resource *resource,
920               int32_t destroy_scene_object)
921 {
922     struct ivilayer *ivilayer = wl_resource_get_user_data(resource);
923     struct ivishell *shell = ivilayer->shell;
924     struct ivicontroller_layer *ctrllayer = NULL;
925     uint32_t id_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
926     (void)client;
927     (void)destroy_scene_object;
928
929     wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
930         if (ctrllayer->id_layer != id_layer) {
931             continue;
932         }
933
934         if (!wl_list_empty(&ctrllayer->link)) {
935             wl_list_remove(&ctrllayer->link);
936         }
937         wl_resource_destroy(resource);
938         break;
939     }
940
941     weston_layout_layerRemove(ivilayer->layout_layer);
942 }
943
944 static const
945 struct ivi_controller_layer_interface controller_layer_implementation = {
946     controller_layer_set_visibility,
947     controller_layer_set_opacity,
948     controller_layer_set_source_rectangle,
949     controller_layer_set_destination_rectangle,
950     controller_layer_set_configuration,
951     controller_layer_set_orientation,
952     controller_layer_screenshot,
953     controller_layer_clear_surfaces,
954     controller_layer_add_surface,
955     controller_layer_remove_surface,
956     controller_layer_set_render_order,
957     controller_layer_destroy
958 };
959
960 static void
961 controller_screen_destroy(struct wl_client *client,
962                           struct wl_resource *resource)
963 {
964     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
965     struct ivicontroller_screen *ctrlscrn = NULL;
966     struct ivicontroller_screen *next = NULL;
967 //    uint32_t id_screen = weston_layout_getIdOfScreen(iviscrn->layout_screen);
968     (void)client;
969
970     wl_list_for_each_safe(ctrlscrn, next,
971                           &iviscrn->shell->list_controller_screen, link) {
972 // TODO : Only Single display
973         destroy_ivicontroller_screen(ctrlscrn->resource);
974         wl_resource_destroy(ctrlscrn->resource);
975         break;
976     }
977 }
978
979 static void
980 controller_screen_clear(struct wl_client *client,
981                 struct wl_resource *resource)
982 {
983     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
984     (void)client;
985     weston_layout_screenSetRenderOrder(iviscrn->layout_screen, NULL, 0);
986 }
987
988 static void
989 controller_screen_add_layer(struct wl_client *client,
990                 struct wl_resource *resource,
991                 struct wl_resource *layer)
992 {
993     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
994     struct ivilayer *ivilayer = wl_resource_get_user_data(layer);
995     (void)client;
996     weston_layout_screenAddLayer(iviscrn->layout_screen, ivilayer->layout_layer);
997 }
998
999 static void
1000 controller_screen_screenshot(struct wl_client *client,
1001                 struct wl_resource *resource,
1002                 const char *filename)
1003 {
1004     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1005     (void)client;
1006     weston_layout_takeScreenshot(iviscrn->layout_screen, filename);
1007 }
1008
1009 static void
1010 controller_screen_set_render_order(struct wl_client *client,
1011                 struct wl_resource *resource,
1012                 struct wl_array *id_layers)
1013 {
1014     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
1015     struct weston_layout_layer **layoutlayer_array = NULL;
1016     struct ivilayer *ivilayer = NULL;
1017     uint32_t *id_layer = NULL;
1018     uint32_t id_layout_layer = 0;
1019     int i = 0;
1020     (void)client;
1021
1022     *layoutlayer_array = (struct weston_layout_layer*)calloc(
1023                             id_layers->size, sizeof(void*));
1024
1025     wl_array_for_each(id_layer, id_layers) {
1026         wl_list_for_each(ivilayer, &iviscrn->shell->list_layer, link) {
1027             id_layout_layer = weston_layout_getIdOfLayer(ivilayer->layout_layer);
1028             if (*id_layer == id_layout_layer) {
1029                 layoutlayer_array[i] = ivilayer->layout_layer;
1030                 i++;
1031                 break;
1032             }
1033         }
1034     }
1035
1036     weston_layout_screenSetRenderOrder(iviscrn->layout_screen,
1037                                     layoutlayer_array, id_layers->size);
1038     free(layoutlayer_array);
1039 }
1040
1041 static const
1042 struct ivi_controller_screen_interface controller_screen_implementation = {
1043     controller_screen_destroy,
1044     controller_screen_clear,
1045     controller_screen_add_layer,
1046     controller_screen_screenshot,
1047     controller_screen_set_render_order
1048 };
1049
1050 static void
1051 controller_commit_changes(struct wl_client *client,
1052                           struct wl_resource *resource)
1053 {
1054     int32_t ans = 0;
1055     (void)client;
1056     (void)resource;
1057
1058     ans = weston_layout_commitChanges();
1059     if (ans < 0) {
1060         weston_log("Failed to commit changes at controller_commit_changes\n");
1061     }
1062 }
1063
1064 static void
1065 controller_layer_create(struct wl_client *client,
1066                         struct wl_resource *resource,
1067                         uint32_t id_layer,
1068                         int32_t width,
1069                         int32_t height,
1070                         uint32_t id)
1071 {
1072     struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1073     struct ivishell *shell = ctrl->shell;
1074     struct weston_layout_layer *layout_layer = NULL;
1075     struct ivicontroller_layer *ctrllayer = NULL;
1076     struct ivilayer *ivilayer = NULL;
1077     struct weston_layout_LayerProperties prop;
1078
1079     ivilayer = get_layer(&shell->list_layer, id_layer);
1080     if (ivilayer == NULL) {
1081         layout_layer = weston_layout_layerCreateWithDimension(id_layer,
1082                            (uint32_t)width, (uint32_t)height);
1083         if (layout_layer == NULL) {
1084             weston_log("id_layer is already created\n");
1085             return;
1086         }
1087
1088         /* ivilayer will be created by layer_event_create */
1089         ivilayer = get_layer(&shell->list_layer, id_layer);
1090         if (ivilayer == NULL) {
1091             weston_log("couldn't get layer object\n");
1092             return;
1093         }
1094     }
1095
1096     ctrllayer = calloc(1, sizeof *ctrllayer);
1097     if (!ctrllayer) {
1098         weston_log("no memory to allocate client layer\n");
1099         return;
1100     }
1101
1102     ctrllayer->shell = shell;
1103     ctrllayer->client = client;
1104     ctrllayer->id = id;
1105     ctrllayer->id_layer = id_layer;
1106     ctrllayer->resource = wl_resource_create(client,
1107                                &ivi_controller_layer_interface, 1, id);
1108     if (ctrllayer->resource == NULL) {
1109         weston_log("couldn't get layer object\n");
1110         return;
1111     }
1112
1113     wl_list_init(&ctrllayer->link);
1114     wl_list_insert(&shell->list_controller_layer, &ctrllayer->link);
1115
1116     wl_resource_set_implementation(ctrllayer->resource,
1117                                    &controller_layer_implementation,
1118                                    ivilayer, destroy_ivicontroller_layer);
1119
1120     memset(&prop, 0, sizeof prop);
1121
1122     weston_layout_getPropertiesOfLayer(ivilayer->layout_layer, &prop);
1123
1124     wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1125         if (id_layer != ctrllayer->id_layer) {
1126             continue;
1127         }
1128         send_layer_event(ctrllayer->resource, ivilayer,
1129                          &prop, IVI_NOTIFICATION_ALL);
1130     }
1131 }
1132
1133 static void
1134 controller_surface_create(struct wl_client *client,
1135                           struct wl_resource *resource,
1136                           uint32_t id_surface,
1137                           uint32_t id)
1138 {
1139     struct ivicontroller *ctrl = wl_resource_get_user_data(resource);
1140     struct ivishell *shell = ctrl->shell;
1141     struct ivicontroller_surface *ctrlsurf = NULL;
1142     struct weston_layout_SurfaceProperties prop;
1143     struct ivisurface *ivisurf = NULL;
1144
1145     ctrlsurf = calloc(1, sizeof *ctrlsurf);
1146     if (!ctrlsurf) {
1147         weston_log("no memory to allocate controller surface\n");
1148         return;
1149     }
1150
1151     ctrlsurf->shell = shell;
1152     ctrlsurf->client = client;
1153     ctrlsurf->id = id;
1154     ctrlsurf->id_surface = id_surface;
1155     wl_list_init(&ctrlsurf->link);
1156     wl_list_insert(&shell->list_controller_surface, &ctrlsurf->link);
1157
1158     ctrlsurf->resource = wl_resource_create(client,
1159                                &ivi_controller_surface_interface, 1, id);
1160     if (ctrlsurf->resource == NULL) {
1161         weston_log("couldn't surface object");
1162         return;
1163     }
1164
1165     ivisurf = get_surface(&shell->list_surface, id_surface);
1166     if (ivisurf == NULL) {
1167         return;
1168     }
1169
1170     wl_resource_set_implementation(ctrlsurf->resource,
1171                                    &controller_surface_implementation,
1172                                    ivisurf, destroy_ivicontroller_surface);
1173
1174     memset(&prop, 0, sizeof prop);
1175
1176     weston_layout_getPropertiesOfSurface(ivisurf->layout_surface, &prop);
1177
1178     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1179         if (id_surface != ctrlsurf->id_surface) {
1180             continue;
1181         }
1182         send_surface_event(ctrlsurf->resource, ivisurf,
1183                            &prop, IVI_NOTIFICATION_ALL);
1184     }
1185 }
1186
1187 static const struct ivi_controller_interface controller_implementation = {
1188     controller_commit_changes,
1189     controller_layer_create,
1190     controller_surface_create
1191 };
1192
1193 static void
1194 add_client_to_resources(struct ivishell *shell,
1195                         struct wl_client *client,
1196                         struct ivicontroller *controller)
1197 {
1198     struct ivisurface* ivisurf = NULL;
1199     struct ivilayer* ivilayer = NULL;
1200     struct iviscreen* iviscrn = NULL;
1201     struct ivicontroller_screen *ctrlscrn = NULL;
1202     struct wl_resource *resource_output = NULL;
1203     uint32_t id_layout_surface = 0;
1204     uint32_t id_layout_layer = 0;
1205
1206     wl_list_for_each(ivisurf, &shell->list_surface, link) {
1207         id_layout_surface =
1208             weston_layout_getIdOfSurface(ivisurf->layout_surface);
1209
1210         ivi_controller_send_surface(controller->resource,
1211                                     id_layout_surface);
1212     }
1213
1214     wl_list_for_each(ivilayer, &shell->list_layer, link) {
1215         id_layout_layer =
1216             weston_layout_getIdOfLayer(ivilayer->layout_layer);
1217
1218         ivi_controller_send_layer(controller->resource,
1219                                   id_layout_layer);
1220     }
1221
1222     wl_list_for_each(iviscrn, &shell->list_screen, link) {
1223         resource_output = wl_resource_find_for_client(
1224                 &iviscrn->output->resource_list, client);
1225         if (resource_output == NULL) {
1226             continue;
1227         }
1228
1229         ctrlscrn = controller_screen_create(iviscrn->shell, client, iviscrn);
1230         if (ctrlscrn == NULL) {
1231             continue;
1232         }
1233
1234         ivi_controller_send_screen(controller->resource,
1235                                    wl_resource_get_id(resource_output),
1236                                    ctrlscrn->resource);
1237     }
1238 }
1239
1240 static void
1241 bind_ivi_controller(struct wl_client *client, void *data,
1242                     uint32_t version, uint32_t id)
1243 {
1244     struct ivishell *shell = data;
1245     struct ivicontroller *controller;
1246     (void)version;
1247
1248     controller = calloc(1, sizeof *controller);
1249     if (controller == NULL) {
1250         weston_log("no memory to allocate controller\n");
1251         return;
1252     }
1253
1254     controller->resource =
1255         wl_resource_create(client, &ivi_controller_interface, 1, id);
1256     wl_resource_set_implementation(controller->resource,
1257                                    &controller_implementation,
1258                                    controller, unbind_resource_controller);
1259
1260     controller->shell = shell;
1261     controller->client = client;
1262     controller->id = id;
1263
1264     wl_list_init(&controller->link);
1265     wl_list_insert(&shell->list_controller, &controller->link);
1266
1267     add_client_to_resources(shell, client, controller);
1268 }
1269
1270 static struct iviscreen*
1271 create_screen(struct ivishell *shell, struct weston_output *output)
1272 {
1273     struct iviscreen *iviscrn;
1274     iviscrn = calloc(1, sizeof *iviscrn);
1275     if (iviscrn == NULL) {
1276         weston_log("no memory to allocate client screen\n");
1277         return NULL;
1278     }
1279
1280     iviscrn->shell = shell;
1281     iviscrn->output = output;
1282
1283 // TODO : Only Single display
1284     iviscrn->layout_screen = weston_layout_getScreenFromId(0);
1285
1286     wl_list_init(&iviscrn->link);
1287
1288     return iviscrn;
1289 }
1290
1291 static void
1292 layer_event_create(struct weston_layout_layer *layout_layer,
1293                      void *userdata)
1294 {
1295     struct ivishell *shell = userdata;
1296     struct ivicontroller *controller = NULL;
1297     struct ivilayer *ivilayer = NULL;
1298     uint32_t id_layer = 0;
1299
1300     id_layer = weston_layout_getIdOfLayer(layout_layer);
1301
1302     ivilayer = calloc(1, sizeof *ivilayer);
1303     if (!ivilayer) {
1304         weston_log("no memory to allocate client layer\n");
1305         return;
1306     }
1307
1308     ivilayer->shell = shell;
1309     wl_list_init(&ivilayer->list_screen);
1310     wl_list_init(&ivilayer->link);
1311     wl_list_insert(&shell->list_layer, &ivilayer->link);
1312     ivilayer->layout_layer = layout_layer;
1313
1314     weston_layout_layerAddNotification(layout_layer, send_layer_prop, ivilayer);
1315
1316     wl_list_for_each(controller, &shell->list_controller, link) {
1317         ivi_controller_send_layer(controller->resource, id_layer);
1318     }
1319
1320     return;
1321 }
1322
1323 static void
1324 layer_event_remove(struct weston_layout_layer *layout_layer,
1325                      void *userdata)
1326 {
1327     struct ivishell *shell = userdata;
1328     struct ivicontroller_layer *ctrllayer = NULL;
1329     struct ivilayer *ivilayer = NULL;
1330     struct ivilayer *next = NULL;
1331     uint32_t id_layer = 0;
1332
1333     wl_list_for_each_safe(ivilayer, next, &shell->list_layer, link) {
1334         if (layout_layer != ivilayer->layout_layer) {
1335             continue;
1336         }
1337
1338         wl_list_remove(&ivilayer->link);
1339         free(ivilayer);
1340         ivilayer = NULL;
1341         break;
1342     }
1343
1344     id_layer = weston_layout_getIdOfLayer(layout_layer);
1345
1346     wl_list_for_each(ctrllayer, &shell->list_controller_layer, link) {
1347         if (id_layer != ctrllayer->id_layer) {
1348             continue;
1349         }
1350         ivi_controller_layer_send_destroyed(ctrllayer->resource);
1351     }
1352 }
1353
1354
1355 static void
1356 surface_event_create(struct weston_layout_surface *layout_surface,
1357                      void *userdata)
1358 {
1359     struct ivishell *shell = userdata;
1360     struct ivisurface *ivisurf = NULL;
1361     struct ivicontroller *controller = NULL;
1362     uint32_t id_surface = 0;
1363
1364     id_surface = weston_layout_getIdOfSurface(layout_surface);
1365
1366     ivisurf = get_surface(&shell->list_surface, id_surface);
1367     if (ivisurf != NULL)
1368     {
1369         weston_log("id_surface is already created\n");
1370         return;
1371     }
1372
1373     ivisurf = calloc(1, sizeof *ivisurf);
1374     if (ivisurf == NULL) {
1375         weston_log("no memory to allocate client surface\n");
1376         return;
1377     }
1378
1379     ivisurf->shell = shell;
1380     ivisurf->layout_surface = layout_surface;
1381     wl_list_init(&ivisurf->list_layer);
1382     wl_list_init(&ivisurf->link);
1383     wl_list_insert(&shell->list_surface, &ivisurf->link);
1384
1385     wl_list_for_each(controller, &shell->list_controller, link) {
1386         ivi_controller_send_surface(controller->resource,
1387                                     id_surface);
1388     }
1389
1390     weston_layout_surfaceAddNotification(layout_surface,
1391                                     &send_surface_prop, ivisurf);
1392
1393 }
1394
1395 static void
1396 surface_event_remove(struct weston_layout_surface *layout_surface,
1397                      void *userdata)
1398 {
1399     struct ivishell *shell = userdata;
1400     struct ivicontroller_surface *ctrlsurf = NULL;
1401     uint32_t id_surface = 0;
1402
1403     id_surface = weston_layout_getIdOfSurface(layout_surface);
1404
1405     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1406         if (id_surface != ctrlsurf->id_surface) {
1407             continue;
1408         }
1409         ivi_controller_surface_send_destroyed(ctrlsurf->resource);
1410     }
1411 }
1412
1413 static void
1414 surface_event_configure(struct weston_layout_surface *layout_surface,
1415                         void *userdata)
1416 {
1417     struct ivishell *shell = userdata;
1418     struct ivisurface *ivisurf = NULL;
1419     struct ivicontroller_surface *ctrlsurf = NULL;
1420     struct weston_layout_SurfaceProperties prop;
1421     uint32_t id_surface = 0;
1422
1423     id_surface = weston_layout_getIdOfSurface(layout_surface);
1424
1425     ivisurf = get_surface(&shell->list_surface, id_surface);
1426     if (ivisurf == NULL) {
1427         weston_log("id_surface is not created yet\n");
1428         return;
1429     }
1430
1431     memset(&prop, 0, sizeof prop);
1432     weston_layout_getPropertiesOfSurface(layout_surface, &prop);
1433
1434     wl_list_for_each(ctrlsurf, &shell->list_controller_surface, link) {
1435         if (id_surface != ctrlsurf->id_surface) {
1436             continue;
1437         }
1438         send_surface_event(ctrlsurf->resource, ivisurf,
1439                            &prop, IVI_NOTIFICATION_ALL);
1440     }
1441 }
1442
1443 static void
1444 init_ivi_shell(struct weston_compositor *ec, struct ivishell *shell)
1445 {
1446     struct weston_output *output = NULL;
1447     struct iviscreen *iviscrn = NULL;
1448     shell->compositor = ec;
1449
1450     wl_list_init(&ec->layer_list);
1451     wl_list_init(&shell->list_surface);
1452     wl_list_init(&shell->list_layer);
1453     wl_list_init(&shell->list_screen);
1454     wl_list_init(&shell->list_weston_surface);
1455     wl_list_init(&shell->list_controller);
1456     wl_list_init(&shell->list_controller_screen);
1457     wl_list_init(&shell->list_controller_layer);
1458     wl_list_init(&shell->list_controller_surface);
1459     shell->event_restriction = 0;
1460
1461     wl_list_for_each(output, &ec->output_list, link) {
1462         iviscrn = create_screen(shell, output);
1463         if (iviscrn != NULL) {
1464             wl_list_insert(&shell->list_screen, &iviscrn->link);
1465         }
1466     }
1467
1468     weston_layout_setNotificationCreateLayer(layer_event_create, shell);
1469     weston_layout_setNotificationRemoveLayer(layer_event_remove, shell);
1470
1471     weston_layout_setNotificationCreateSurface(surface_event_create, shell);
1472     weston_layout_setNotificationRemoveSurface(surface_event_remove, shell);
1473     weston_layout_setNotificationConfigureSurface(surface_event_configure, shell);
1474 }
1475
1476 WL_EXPORT int
1477 module_init(struct weston_compositor *ec,
1478             int *argc, char *argv[])
1479 {
1480     struct ivishell *shell;
1481     (void)argc;
1482     (void)argv;
1483
1484     shell = malloc(sizeof *shell);
1485     if (shell == NULL)
1486         return -1;
1487
1488     memset(shell, 0, sizeof *shell);
1489     init_ivi_shell(ec, shell);
1490
1491     if (wl_global_create(ec->wl_display, &ivi_controller_interface, 1,
1492                          shell, bind_ivi_controller) == NULL) {
1493         return -1;
1494     }
1495
1496     return 0;
1497 }