527cdbac03879098f064971241391bd04c4367a1
[src/agl-compositor.git] / src / shell.c
1 /*
2  * Copyright © 2019 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #include "ivi-compositor.h"
27 #include "policy.h"
28
29 #include <assert.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <signal.h>
33 #include <string.h>
34 #include <sys/socket.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 #include <libweston/libweston.h>
38 #include <libweston/config-parser.h>
39
40 #include "shared/os-compatibility.h"
41
42 #include "agl-shell-server-protocol.h"
43 #include "agl-shell-desktop-server-protocol.h"
44
45 static void
46 create_black_surface_view(struct ivi_output *output);
47
48 static void
49 insert_black_surface(struct ivi_output *output);
50
51 void
52 ivi_set_desktop_surface(struct ivi_surface *surface)
53 {
54         struct desktop_client *dclient;
55         struct ivi_compositor *ivi = surface->ivi;
56         assert(surface->role == IVI_SURFACE_ROLE_NONE);
57
58         surface->role = IVI_SURFACE_ROLE_DESKTOP;
59         wl_list_insert(&surface->ivi->surfaces, &surface->link);
60
61         /* advertise to all desktop clients the new surface */
62         wl_list_for_each(dclient, &ivi->desktop_clients, link) {
63                 const char *app_id =
64                         weston_desktop_surface_get_app_id(surface->dsurface);
65                 agl_shell_desktop_send_application(dclient->resource, app_id);
66         }
67 }
68
69 void
70 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
71 {
72         struct ivi_compositor *ivi = surface->ivi;
73         assert(surface->role == IVI_SURFACE_ROLE_NONE);
74
75         surface->role = IVI_SURFACE_ROLE_POPUP;
76         wl_list_insert(&ivi->surfaces, &surface->link);
77 }
78
79 static void
80 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
81                                       int x, int y, const char *app_id)
82 {
83         struct ivi_compositor *ivi = ioutput->ivi;
84         size_t len_app_id = strlen(app_id);
85
86         struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
87
88         p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
89         memcpy(p_popup->app_id, app_id, len_app_id);
90         p_popup->ioutput = ioutput;
91         p_popup->x = x;
92         p_popup->y = y;
93
94         wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
95 }
96
97 static void
98 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
99 {
100         free(p_popup->app_id);
101         wl_list_remove(&p_popup->link);
102         free(p_popup);
103 }
104
105 bool
106 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
107 {
108         struct ivi_compositor *ivi = surface->ivi;
109         struct pending_popup *p_popup, *next_p_popup;
110         const char *_app_id =
111                         weston_desktop_surface_get_app_id(surface->dsurface);
112
113         wl_list_for_each_safe(p_popup, next_p_popup,
114                               &ivi->popup_pending_apps, link) {
115                 if (!strcmp(_app_id, p_popup->app_id)) {
116                         surface->popup.output = p_popup->ioutput;
117                         surface->popup.x = p_popup->x;
118                         surface->popup.y = p_popup->y;
119
120                         ivi_remove_pending_desktop_surface_popup(p_popup);
121                         return true;
122                 }
123         }
124
125         return false;
126 }
127
128 void
129 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
130 {
131         struct ivi_output *out;
132
133         wl_list_for_each(out, &ivi->outputs, link) {
134                 create_black_surface_view(out);
135                 insert_black_surface(out);
136         }
137 }
138
139 int
140 ivi_shell_init(struct ivi_compositor *ivi)
141 {
142         weston_layer_init(&ivi->hidden, ivi->compositor);
143         weston_layer_init(&ivi->background, ivi->compositor);
144         weston_layer_init(&ivi->normal, ivi->compositor);
145         weston_layer_init(&ivi->panel, ivi->compositor);
146         weston_layer_init(&ivi->popup, ivi->compositor);
147         weston_layer_init(&ivi->fullscreen, ivi->compositor);
148
149         weston_layer_set_position(&ivi->hidden,
150                                   WESTON_LAYER_POSITION_HIDDEN);
151         weston_layer_set_position(&ivi->background,
152                                   WESTON_LAYER_POSITION_BACKGROUND);
153         weston_layer_set_position(&ivi->normal,
154                                   WESTON_LAYER_POSITION_NORMAL);
155         weston_layer_set_position(&ivi->panel,
156                                   WESTON_LAYER_POSITION_UI);
157         weston_layer_set_position(&ivi->popup,
158                                   WESTON_LAYER_POSITION_TOP_UI);
159         weston_layer_set_position(&ivi->fullscreen,
160                                   WESTON_LAYER_POSITION_FULLSCREEN);
161
162         return 0;
163 }
164
165 static void
166 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
167 {
168         struct ivi_surface *surface;
169
170         wl_list_for_each(surface, &ivi->surfaces, link) {
171                 const char *app_id =
172                         weston_desktop_surface_get_app_id(surface->dsurface);
173                 agl_shell_desktop_send_application(resource, app_id);
174         }
175 }
176
177 static void
178 client_exec(const char *command, int fd)
179 {
180         sigset_t sig;
181         char s[32];
182
183         /* Don't give the child our signal mask */
184         sigfillset(&sig);
185         sigprocmask(SIG_UNBLOCK, &sig, NULL);
186
187         /* Launch clients as the user; don't give them the wrong euid */
188         if (seteuid(getuid()) == -1) {
189                 weston_log("seteuid failed: %s\n", strerror(errno));
190                 return;
191         }
192
193         /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
194          * clobbering fd, as we'll exit/exec either way.
195          */
196         fd = dup(fd);
197         if (fd == -1) {
198                 weston_log("dup failed: %s\n", strerror(errno));
199                 return;
200         }
201
202         snprintf(s, sizeof s, "%d", fd);
203         setenv("WAYLAND_SOCKET", s, 1);
204
205         execl("/bin/sh", "/bin/sh", "-c", command, NULL);
206         weston_log("executing '%s' failed: %s", command, strerror(errno));
207 }
208
209 static struct wl_client *
210 launch_shell_client(struct ivi_compositor *ivi, const char *command)
211 {
212         struct wl_client *client;
213         int sock[2];
214         pid_t pid;
215
216         weston_log("launching' %s'\n", command);
217
218         if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
219                 weston_log("socketpair failed while launching '%s': %s\n",
220                            command, strerror(errno));
221                 return NULL;
222         }
223
224         pid = fork();
225         if (pid == -1) {
226                 close(sock[0]);
227                 close(sock[1]);
228                 weston_log("fork failed while launching '%s': %s\n",
229                            command, strerror(errno));
230                 return NULL;
231         }
232
233         if (pid == 0) {
234                 client_exec(command, sock[1]);
235                 _Exit(EXIT_FAILURE);
236         }
237         close(sock[1]);
238
239         client = wl_client_create(ivi->compositor->wl_display, sock[0]);
240         if (!client) {
241                 close(sock[0]);
242                 weston_log("Failed to create wayland client for '%s'",
243                            command);
244                 return NULL;
245         }
246
247         return client;
248 }
249
250 int
251 ivi_launch_shell_client(struct ivi_compositor *ivi)
252 {
253         struct weston_config_section *section;
254         char *command = NULL;
255
256         section = weston_config_get_section(ivi->config, "shell-client",
257                                             NULL, NULL);
258         if (section)
259                 weston_config_section_get_string(section, "command",
260                                                  &command, NULL);
261
262         if (!command)
263                 return -1;
264
265         ivi->shell_client.client = launch_shell_client(ivi, command);
266         if (!ivi->shell_client.client)
267                 return -1;
268
269         return 0;
270 }
271
272 static void
273 destroy_black_view(struct wl_listener *listener, void *data)
274 {
275         struct fullscreen_view *fs =
276                 wl_container_of(listener, fs, fs_destroy);
277
278
279         if (fs && fs->fs) {
280                 if (fs->fs->view && fs->fs->view->surface) {
281                         weston_surface_destroy(fs->fs->view->surface);
282                         fs->fs->view = NULL;
283                 }
284
285                 free(fs->fs);
286                 wl_list_remove(&fs->fs_destroy.link);
287         }
288 }
289
290
291 static void
292 create_black_surface_view(struct ivi_output *output)
293 {
294         struct weston_surface *surface = NULL;
295         struct weston_view *view;
296         struct ivi_compositor *ivi = output->ivi;
297         struct weston_compositor *wc= ivi->compositor;
298         struct weston_output *woutput = output->output;
299
300         surface = weston_surface_create(wc);
301         view = weston_view_create(surface);
302
303         assert(view || surface);
304
305         weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
306         weston_surface_set_size(surface, woutput->width, woutput->height);
307         weston_view_set_position(view, woutput->x, woutput->y);
308
309         output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
310         output->fullscreen_view.fs->view = view;
311
312         output->fullscreen_view.fs_destroy.notify = destroy_black_view;
313         wl_signal_add(&woutput->destroy_signal,
314                       &output->fullscreen_view.fs_destroy);
315 }
316
317 static void
318 remove_black_surface(struct ivi_output *output)
319 {
320         struct weston_view *view = output->fullscreen_view.fs->view;
321
322         assert(view->is_mapped == true ||
323                view->surface->is_mapped == true);
324
325         view->is_mapped = false;
326         view->surface->is_mapped = false;
327
328         weston_layer_entry_remove(&view->layer_link);
329         weston_view_update_transform(view);
330
331         weston_output_damage(output->output);
332 }
333
334 static void
335 insert_black_surface(struct ivi_output *output)
336 {
337         struct weston_view *view = output->fullscreen_view.fs->view;
338
339         if (view->is_mapped || view->surface->is_mapped)
340                 return;
341
342         weston_layer_entry_remove(&view->layer_link);
343         weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
344                                   &view->layer_link);
345
346         view->is_mapped = true;
347         view->surface->is_mapped = true;
348
349         weston_view_update_transform(view);
350         weston_output_damage(output->output);
351 }
352
353 static void
354 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
355 {
356         struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
357         struct ivi_output *output;
358         struct ivi_surface *surface, *tmp;
359
360         /* Init already finished. Do nothing */
361         if (ivi->shell_client.ready)
362                 return;
363
364         ivi->shell_client.ready = true;
365
366         wl_list_for_each(output, &ivi->outputs, link) {
367                 remove_black_surface(output);
368                 ivi_layout_init(ivi, output);
369         }
370
371         wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
372                 wl_list_remove(&surface->link);
373
374                 if (ivi_check_pending_desktop_surface_popup(surface)) {
375                         ivi_set_desktop_surface_popup(surface);
376                 } else {
377                         ivi_set_desktop_surface(surface);
378                         ivi_layout_desktop_committed(surface);
379                 }
380         }
381 }
382
383 static void
384 shell_set_background(struct wl_client *client,
385                      struct wl_resource *shell_res,
386                      struct wl_resource *surface_res,
387                      struct wl_resource *output_res)
388 {
389         struct weston_head *head = weston_head_from_resource(output_res);
390         struct weston_output *woutput = weston_head_get_output(head);
391         struct ivi_output *output = to_ivi_output(woutput);
392         struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
393         struct weston_desktop_surface *dsurface;
394         struct ivi_surface *surface;
395
396         dsurface = weston_surface_get_desktop_surface(wsurface);
397         if (!dsurface) {
398                 wl_resource_post_error(shell_res,
399                                        AGL_SHELL_ERROR_INVALID_ARGUMENT,
400                                        "surface must be a desktop surface");
401                 return;
402         }
403
404         surface = weston_desktop_surface_get_user_data(dsurface);
405         if (surface->role != IVI_SURFACE_ROLE_NONE) {
406                 wl_resource_post_error(shell_res,
407                                        AGL_SHELL_ERROR_INVALID_ARGUMENT,
408                                        "surface already has another ivi role");
409                 return;
410         }
411
412         if (output->background) {
413                 wl_resource_post_error(shell_res,
414                                        AGL_SHELL_ERROR_BACKGROUND_EXISTS,
415                                        "output already has background");
416                 return;
417         }
418
419         surface->role = IVI_SURFACE_ROLE_BACKGROUND;
420         surface->bg.output = output;
421         wl_list_remove(&surface->link);
422         wl_list_init(&surface->link);
423
424         output->background = surface;
425
426         weston_desktop_surface_set_maximized(dsurface, true);
427         weston_desktop_surface_set_size(dsurface,
428                                         output->output->width,
429                                         output->output->height);
430 }
431
432 static void
433 shell_set_panel(struct wl_client *client,
434                 struct wl_resource *shell_res,
435                 struct wl_resource *surface_res,
436                 struct wl_resource *output_res,
437                 uint32_t edge)
438 {
439         struct weston_head *head = weston_head_from_resource(output_res);
440         struct weston_output *woutput = weston_head_get_output(head);
441         struct ivi_output *output = to_ivi_output(woutput);
442         struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
443         struct weston_desktop_surface *dsurface;
444         struct ivi_surface *surface;
445         struct ivi_surface **member;
446         int32_t width = 0, height = 0;
447
448         dsurface = weston_surface_get_desktop_surface(wsurface);
449         if (!dsurface) {
450                 wl_resource_post_error(shell_res,
451                                        AGL_SHELL_ERROR_INVALID_ARGUMENT,
452                                        "surface must be a desktop surface");
453                 return;
454         }
455
456         surface = weston_desktop_surface_get_user_data(dsurface);
457         if (surface->role != IVI_SURFACE_ROLE_NONE) {
458                 wl_resource_post_error(shell_res,
459                                        AGL_SHELL_ERROR_INVALID_ARGUMENT,
460                                        "surface already has another ivi role");
461                 return;
462         }
463
464         switch (edge) {
465         case AGL_SHELL_EDGE_TOP:
466                 member = &output->top;
467                 break;
468         case AGL_SHELL_EDGE_BOTTOM:
469                 member = &output->bottom;
470                 break;
471         case AGL_SHELL_EDGE_LEFT:
472                 member = &output->left;
473                 break;
474         case AGL_SHELL_EDGE_RIGHT:
475                 member = &output->right;
476                 break;
477         default:
478                 wl_resource_post_error(shell_res,
479                                        AGL_SHELL_ERROR_INVALID_ARGUMENT,
480                                        "invalid edge for panel");
481                 return;
482         }
483
484         if (*member) {
485                 wl_resource_post_error(shell_res,
486                                        AGL_SHELL_ERROR_BACKGROUND_EXISTS,
487                                        "output already has panel on this edge");
488                 return;
489         }
490
491         surface->role = IVI_SURFACE_ROLE_PANEL;
492         surface->panel.output = output;
493         surface->panel.edge = edge;
494         wl_list_remove(&surface->link);
495         wl_list_init(&surface->link);
496
497         *member = surface;
498
499         switch (surface->panel.edge) {
500         case AGL_SHELL_EDGE_TOP:
501         case AGL_SHELL_EDGE_BOTTOM:
502                 width = woutput->width;
503                 break;
504         case AGL_SHELL_EDGE_LEFT:
505         case AGL_SHELL_EDGE_RIGHT:
506                 height = woutput->height;
507                 break;
508         }
509
510         weston_desktop_surface_set_size(dsurface, width, height);
511 }
512
513
514 static void
515 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
516                           const char *data, uint32_t app_state)
517 {
518         struct desktop_client *dclient;
519         uint32_t app_role;
520         struct ivi_surface *surf = ivi_find_app(ivi, app_id);
521         struct ivi_policy *policy = ivi->policy;
522
523         /* FIXME: should queue it here and see when binding agl-shell-desktop
524          * if there are any to be sent */
525         if (!surf)
526                 return;
527
528         if (policy && policy->api.surface_advertise_state_change &&
529             !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
530                 return;
531         }
532
533         app_role = surf->role;
534         if (app_role == IVI_SURFACE_ROLE_POPUP)
535                 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
536
537         wl_list_for_each(dclient, &ivi->desktop_clients, link)
538                 agl_shell_desktop_send_state_app(dclient->resource, app_id,
539                                                  data, app_state, app_role);
540 }
541
542 static void
543 shell_activate_app(struct wl_client *client,
544                    struct wl_resource *shell_res,
545                    const char *app_id,
546                    struct wl_resource *output_res)
547 {
548         struct weston_head *head = weston_head_from_resource(output_res);
549         struct weston_output *woutput = weston_head_get_output(head);
550         struct ivi_output *output = to_ivi_output(woutput);
551
552         ivi_layout_activate(output, app_id);
553 }
554
555 static void
556 shell_desktop_activate_app(struct wl_client *client,
557                            struct wl_resource *shell_res,
558                            const char *app_id, const char *data,
559                            struct wl_resource *output_res)
560 {
561         struct weston_head *head = weston_head_from_resource(output_res);
562         struct weston_output *woutput = weston_head_get_output(head);
563         struct ivi_output *output = to_ivi_output(woutput);
564
565         ivi_layout_activate(output, app_id);
566         shell_advertise_app_state(output->ivi, app_id,
567                                   data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
568 }
569
570 static void
571 shell_deactivate_app(struct wl_client *client,
572                    struct wl_resource *shell_res,
573                    const char *app_id)
574 {
575         struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
576         struct ivi_compositor *ivi = dclient->ivi;
577
578         ivi_layout_deactivate(ivi, app_id);
579         shell_advertise_app_state(ivi, app_id,
580                                   NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
581 }
582
583 static const struct agl_shell_interface agl_shell_implementation = {
584         .ready = shell_ready,
585         .set_background = shell_set_background,
586         .set_panel = shell_set_panel,
587         .activate_app = shell_activate_app,
588 };
589
590 static void
591 shell_desktop_set_app_property(struct wl_client *client,
592                                struct wl_resource *shell_res,
593                                const char *app_id, uint32_t role,
594                                int x, int y, struct wl_resource *output_res)
595 {
596         struct weston_head *head = weston_head_from_resource(output_res);
597         struct weston_output *woutput = weston_head_get_output(head);
598         struct ivi_output *output = to_ivi_output(woutput);
599
600         /* temporary store the app_id such that, when created to be check against */
601         if (role == AGL_SHELL_DESKTOP_APP_ROLE_POPUP)
602                 ivi_set_pending_desktop_surface_popup(output, x, y, app_id);
603 }
604
605 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
606         .activate_app = shell_desktop_activate_app,
607         .set_app_property = shell_desktop_set_app_property,
608         .deactivate_app = shell_deactivate_app,
609 };
610
611 static void
612 unbind_agl_shell(struct wl_resource *resource)
613 {
614         struct ivi_compositor *ivi;
615         struct ivi_output *output;
616         struct ivi_surface *surf, *surf_tmp;
617
618         ivi = wl_resource_get_user_data(resource);
619         wl_list_for_each(output, &ivi->outputs, link) {
620                 /* reset the active surf if there's one present */
621                 if (output->active) {
622                         output->active->view->is_mapped = false;
623                         output->active->view->surface->is_mapped = false;
624
625                         weston_layer_entry_remove(&output->active->view->layer_link);
626                         output->active = NULL;
627                 }
628
629                 insert_black_surface(output);
630         }
631
632         wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
633                 wl_list_remove(&surf->link);
634                 wl_list_init(&surf->link);
635         }
636
637         wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
638                 wl_list_remove(&surf->link);
639                 wl_list_init(&surf->link);
640         }
641
642         wl_list_init(&ivi->surfaces);
643         wl_list_init(&ivi->pending_surfaces);
644
645         ivi->shell_client.ready = false;
646         ivi->shell_client.resource = NULL;
647         ivi->shell_client.client = NULL;
648 }
649
650 static void
651 bind_agl_shell(struct wl_client *client,
652                void *data, uint32_t version, uint32_t id)
653 {
654         struct ivi_compositor *ivi = data;
655         struct wl_resource *resource;
656
657         resource = wl_resource_create(client, &agl_shell_interface,
658                                       1, id);
659         if (!resource) {
660                 wl_client_post_no_memory(client);
661                 return;
662         }
663
664 #if 0
665         if (ivi->shell_client.client != client) {
666                 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
667                                        "client not authorized to use agl_shell");
668                 return;
669         }
670 #endif
671
672         if (ivi->shell_client.resource) {
673                 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
674                                        "agl_shell has already been bound");
675                 return;
676         }
677
678         wl_resource_set_implementation(resource, &agl_shell_implementation,
679                                        ivi, unbind_agl_shell);
680         ivi->shell_client.resource = resource;
681 }
682
683 static void
684 unbind_agl_shell_desktop(struct wl_resource *resource)
685 {
686         struct desktop_client *dclient = wl_resource_get_user_data(resource);
687
688         wl_list_remove(&dclient->link);
689         free(dclient);
690 }
691
692 static void
693 bind_agl_shell_desktop(struct wl_client *client,
694                        void *data, uint32_t version, uint32_t id)
695 {
696         struct ivi_compositor *ivi = data;
697         struct wl_resource *resource;
698         struct desktop_client *dclient = zalloc(sizeof(*dclient));
699
700         if (!dclient) {
701                 wl_client_post_no_memory(client);
702                 return;
703         }
704
705         resource = wl_resource_create(client, &agl_shell_desktop_interface,
706                                       version, id);
707         dclient->ivi = ivi;
708         if (!resource) {
709                 wl_client_post_no_memory(client);
710                 return;
711         }
712
713         wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
714                                        dclient, unbind_agl_shell_desktop);
715
716         dclient->resource = resource;
717         wl_list_insert(&ivi->desktop_clients, &dclient->link);
718
719         /* advertise xdg surfaces */
720         ivi_shell_advertise_xdg_surfaces(ivi, resource);
721 }
722
723 int
724 ivi_shell_create_global(struct ivi_compositor *ivi)
725 {
726         ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
727                                           &agl_shell_interface, 1,
728                                           ivi, bind_agl_shell);
729         if (!ivi->agl_shell) {
730                 weston_log("Failed to create wayland global.\n");
731                 return -1;
732         }
733
734         ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
735                                                   &agl_shell_desktop_interface, 1,
736                                                   ivi, bind_agl_shell_desktop);
737         if (!ivi->agl_shell_desktop) {
738                 weston_log("Failed to create wayland global (agl_shell_desktop).\n");
739                 return -1;
740         }
741
742         return 0;
743 }