2 * Copyright © 2019, 2022 Collabora, Ltd.
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:
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.
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
26 #include "ivi-compositor.h"
34 #include <sys/socket.h>
35 #include <sys/types.h>
38 #include <libweston/libweston.h>
39 #include <libweston/config-parser.h>
42 #include "shared/os-compatibility.h"
43 #include "shared/helpers.h"
44 #include "shared/process-util.h"
46 #include "agl-shell-server-protocol.h"
47 #include "agl-shell-desktop-server-protocol.h"
50 create_black_curtain_view(struct ivi_output *output);
53 reverse_orientation(uint32_t orientation);
56 split_orientation_to_string(uint32_t orientation);
59 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
60 struct ivi_surface *surface)
62 struct desktop_client *dclient;
63 static bool display_adv = false;
65 if (surface->advertised_on_launch)
68 /* advertise to all desktop clients the new surface */
69 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
71 weston_desktop_surface_get_app_id(surface->dsurface);
74 weston_log("WARNING app_is is null, unable to advertise\n");
79 agl_shell_desktop_send_application(dclient->resource, app_id);
80 surface->advertised_on_launch = true;
85 ivi_set_desktop_surface(struct ivi_surface *surface)
87 struct ivi_compositor *ivi = surface->ivi;
88 assert(surface->role == IVI_SURFACE_ROLE_NONE);
90 surface->role = IVI_SURFACE_ROLE_DESKTOP;
91 wl_list_insert(&surface->ivi->surfaces, &surface->link);
93 agl_shell_desktop_advertise_application_id(ivi, surface);
97 ivi_set_background_surface(struct ivi_surface *surface)
99 struct ivi_compositor *ivi = surface->ivi;
100 assert(surface->role == IVI_SURFACE_ROLE_BACKGROUND);
102 wl_list_insert(&surface->ivi->surfaces, &surface->link);
103 agl_shell_desktop_advertise_application_id(ivi, surface);
107 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
109 struct ivi_compositor *ivi = surface->ivi;
110 assert(surface->role == IVI_SURFACE_ROLE_NONE);
112 surface->role = IVI_SURFACE_ROLE_POPUP;
113 wl_list_insert(&ivi->surfaces, &surface->link);
115 agl_shell_desktop_advertise_application_id(ivi, surface);
119 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
121 struct ivi_compositor *ivi = surface->ivi;
122 assert(surface->role == IVI_SURFACE_ROLE_NONE);
124 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
125 wl_list_insert(&ivi->surfaces, &surface->link);
127 agl_shell_desktop_advertise_application_id(ivi, surface);
131 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
133 struct ivi_compositor *ivi = surface->ivi;
134 struct weston_view *view;
135 struct ivi_output *output = surface->remote.output;
137 assert(surface->role == IVI_SURFACE_ROLE_NONE);
139 /* remote type are the same as desktop just that client can tell
140 * the compositor to start on another output */
141 surface->role = IVI_SURFACE_ROLE_REMOTE;
143 /* if thew black surface view is mapped on the mean we need
144 * to remove it in order to start showing the 'remote' surface
145 * just being added */
146 view = output->fullscreen_view.fs->view;
147 if (view->is_mapped || view->surface->is_mapped)
148 remove_black_curtain(output);
150 wl_list_insert(&ivi->surfaces, &surface->link);
155 ivi_set_desktop_surface_split(struct ivi_surface *surface)
157 struct ivi_compositor *ivi = surface->ivi;
158 assert(surface->role == IVI_SURFACE_ROLE_NONE);
160 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
161 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
163 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
165 wl_list_insert(&ivi->surfaces, &surface->link);
167 agl_shell_desktop_advertise_application_id(ivi, surface);
170 static struct pending_popup *
171 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
172 int width, int height, const char *app_id)
174 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
175 size_t len_app_id = strlen(app_id);
179 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
180 if (!p_popup->app_id) {
184 memcpy(p_popup->app_id, app_id, len_app_id);
185 p_popup->ioutput = ioutput;
191 p_popup->bb.width = width;
192 p_popup->bb.height = height;
198 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
199 int width, int height, const char *app_id, struct pending_popup *p_popup)
201 size_t len_app_id = strlen(app_id);
203 wl_list_remove(&p_popup->link);
204 wl_list_init(&p_popup->link);
206 memset(p_popup->app_id, 0, strlen(app_id) + 1);
207 free(p_popup->app_id);
209 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
210 if (!p_popup->app_id)
212 memcpy(p_popup->app_id, app_id, len_app_id);
214 p_popup->ioutput = ioutput;
220 p_popup->bb.width = width;
221 p_popup->bb.height = height;
224 static struct pending_fullscreen *
225 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
227 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
228 size_t len_app_id = strlen(app_id);
232 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
233 if (!p_fullscreen->app_id) {
237 memcpy(p_fullscreen->app_id, app_id, len_app_id);
239 p_fullscreen->ioutput = ioutput;
244 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
245 struct pending_fullscreen *p_fullscreen)
247 size_t len_app_id = strlen(app_id);
249 wl_list_remove(&p_fullscreen->link);
250 wl_list_init(&p_fullscreen->link);
252 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
253 free(p_fullscreen->app_id);
255 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
256 if (!p_fullscreen->app_id)
258 memcpy(p_fullscreen->app_id, app_id, len_app_id);
260 p_fullscreen->ioutput = ioutput;
263 static struct pending_remote *
264 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
266 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
267 size_t len_app_id = strlen(app_id);
271 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
272 if (!p_remote->app_id) {
276 memcpy(p_remote->app_id, app_id, len_app_id);
278 p_remote->ioutput = ioutput;
283 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
284 struct pending_remote *p_remote)
286 size_t len_app_id = strlen(app_id);
288 wl_list_remove(&p_remote->link);
289 wl_list_init(&p_remote->link);
291 memset(p_remote->app_id, 0, strlen(app_id) + 1);
292 free(p_remote->app_id);
294 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
295 if (!p_remote->app_id)
297 memcpy(p_remote->app_id, app_id, len_app_id);
299 p_remote->ioutput = ioutput;
303 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
304 int by, int width, int height, const char *app_id)
306 struct ivi_compositor *ivi = ioutput->ivi;
307 struct pending_popup *p_popup = NULL;
308 struct pending_popup *popup;
310 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
311 if (!strcmp(app_id, popup->app_id))
315 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
317 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
321 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
325 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
328 struct ivi_compositor *ivi = ioutput->ivi;
329 struct pending_fullscreen *p_fullscreen = NULL;
330 struct pending_fullscreen *fullscreen;
332 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
333 if (!strcmp(app_id, fullscreen->app_id))
334 p_fullscreen = fullscreen;
337 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
339 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
343 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
347 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
348 const char *app_id, uint32_t orientation)
350 struct ivi_compositor *ivi = ioutput->ivi;
351 struct ivi_surface *surf;
352 size_t len_app_id = strlen(app_id);
353 struct pending_split *split;
355 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
356 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
359 /* more than one is un-supported, do note we need to do
360 * conversion for surface roles instead of using the protocol ones */
361 wl_list_for_each(surf, &ivi->surfaces, link)
362 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
363 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
366 split = zalloc(sizeof(*split));
369 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
370 if (!split->app_id) {
374 memcpy(split->app_id, app_id, len_app_id);
376 split->ioutput = ioutput;
377 split->orientation = orientation;
379 wl_list_insert(&ivi->split_pending_apps, &split->link);
383 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
386 struct ivi_compositor *ivi = ioutput->ivi;
387 struct pending_remote *remote;
388 struct pending_remote *p_remote = NULL;
390 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
391 if (!strcmp(app_id, remote->app_id))
395 p_remote = ivi_ensure_remote(ioutput, app_id);
397 ivi_update_remote(ioutput, app_id, p_remote);
401 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
406 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
409 wl_list_remove(&split->link);
414 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
417 wl_list_remove(&fs->link);
422 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
424 free(p_popup->app_id);
425 wl_list_remove(&p_popup->link);
430 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
432 free(remote->app_id);
433 wl_list_remove(&remote->link);
438 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
440 return surface->ivi->keep_pending_surfaces;
444 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
446 struct ivi_compositor *ivi = surface->ivi;
447 struct pending_popup *p_popup, *next_p_popup;
448 const char *_app_id =
449 weston_desktop_surface_get_app_id(surface->dsurface);
451 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
454 wl_list_for_each_safe(p_popup, next_p_popup,
455 &ivi->popup_pending_apps, link) {
456 if (!strcmp(_app_id, p_popup->app_id)) {
457 surface->popup.output = p_popup->ioutput;
458 surface->popup.x = p_popup->x;
459 surface->popup.y = p_popup->y;
461 surface->popup.bb.x = p_popup->bb.x;
462 surface->popup.bb.y = p_popup->bb.y;
463 surface->popup.bb.width = p_popup->bb.width;
464 surface->popup.bb.height = p_popup->bb.height;
466 if (!ivi_compositor_keep_pending_surfaces(surface))
467 ivi_remove_pending_desktop_surface_popup(p_popup);
476 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
478 struct pending_split *split_surf, *next_split_surf;
479 struct ivi_compositor *ivi = surface->ivi;
480 const char *_app_id =
481 weston_desktop_surface_get_app_id(surface->dsurface);
483 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
486 wl_list_for_each_safe(split_surf, next_split_surf,
487 &ivi->split_pending_apps, link) {
488 if (!strcmp(_app_id, split_surf->app_id)) {
489 surface->split.output = split_surf->ioutput;
490 surface->split.orientation = split_surf->orientation;
491 if (!ivi_compositor_keep_pending_surfaces(surface))
492 ivi_remove_pending_desktop_surface_split(split_surf);
501 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
503 struct pending_fullscreen *fs_surf, *next_fs_surf;
504 struct ivi_compositor *ivi = surface->ivi;
505 const char *_app_id =
506 weston_desktop_surface_get_app_id(surface->dsurface);
508 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
511 wl_list_for_each_safe(fs_surf, next_fs_surf,
512 &ivi->fullscreen_pending_apps, link) {
513 if (!strcmp(_app_id, fs_surf->app_id)) {
514 surface->fullscreen.output = fs_surf->ioutput;
515 if (!ivi_compositor_keep_pending_surfaces(surface))
516 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
525 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
527 struct pending_remote *remote_surf, *next_remote_surf;
528 struct ivi_compositor *ivi = surface->ivi;
529 const char *_app_id =
530 weston_desktop_surface_get_app_id(surface->dsurface);
532 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
535 wl_list_for_each_safe(remote_surf, next_remote_surf,
536 &ivi->remote_pending_apps, link) {
537 if (!strcmp(_app_id, remote_surf->app_id)) {
538 surface->remote.output = remote_surf->ioutput;
539 if (!ivi_compositor_keep_pending_surfaces(surface))
540 ivi_remove_pending_desktop_surface_remote(remote_surf);
548 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
549 enum ivi_surface_role *role)
551 struct ivi_compositor *ivi = surface->ivi;
552 struct wl_list *role_pending_list;
553 struct pending_popup *p_popup;
554 struct pending_split *p_split;
555 struct pending_fullscreen *p_fullscreen;
556 struct pending_remote *p_remote;
558 weston_desktop_surface_get_app_id(surface->dsurface);
560 role_pending_list = &ivi->popup_pending_apps;
561 wl_list_for_each(p_popup, role_pending_list, link) {
562 if (app_id && !strcmp(app_id, p_popup->app_id)) {
563 *role = IVI_SURFACE_ROLE_POPUP;
568 role_pending_list = &ivi->split_pending_apps;
569 wl_list_for_each(p_split, role_pending_list, link) {
570 if (app_id && !strcmp(app_id, p_split->app_id)) {
571 *role = IVI_SURFACE_ROLE_SPLIT_V;
576 role_pending_list = &ivi->fullscreen_pending_apps;
577 wl_list_for_each(p_fullscreen, role_pending_list, link) {
578 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
579 *role = IVI_SURFACE_ROLE_FULLSCREEN;
584 role_pending_list = &ivi->remote_pending_apps;
585 wl_list_for_each(p_remote, role_pending_list, link) {
586 if (app_id && !strcmp(app_id, p_remote->app_id)) {
587 *role = IVI_SURFACE_ROLE_REMOTE;
592 /* else, we are a regular desktop surface */
593 *role = IVI_SURFACE_ROLE_DESKTOP;
597 ivi_check_pending_app_type(struct ivi_surface *surface, enum ivi_surface_role role)
599 struct pending_app *papp;
600 const char *app_id = NULL;
602 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
606 wl_list_for_each(papp, &surface->ivi->pending_apps, link) {
607 if (strcmp(app_id, papp->app_id) == 0 && papp->role == role)
616 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
620 ret = ivi_check_pending_desktop_surface_popup(surface);
622 ivi_set_desktop_surface_popup(surface);
623 ivi_layout_popup_committed(surface);
627 ret = ivi_check_pending_desktop_surface_split(surface);
629 ivi_set_desktop_surface_split(surface);
630 ivi_layout_split_committed(surface);
634 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
636 ivi_set_desktop_surface_fullscreen(surface);
637 ivi_layout_fullscreen_committed(surface);
641 ret = ivi_check_pending_desktop_surface_remote(surface);
643 ivi_set_desktop_surface_remote(surface);
644 ivi_layout_remote_committed(surface);
648 /* new way of doing it */
649 struct pending_app *papp =
650 ivi_check_pending_app_type(surface, IVI_SURFACE_ROLE_TILE);
652 struct pending_app_tile *papp_tile =
653 container_of(papp, struct pending_app_tile, base);
655 // handle the currently active surface
656 if (papp->ioutput->active) {
657 int width_prev_app = 0;
659 if (papp_tile->width > 0) {
660 if (papp_tile->orientation == AGL_SHELL_TILE_ORIENTATION_TOP ||
661 papp_tile->orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
662 width_prev_app = papp->ioutput->area.height - papp_tile->width;
664 width_prev_app = papp->ioutput->area.width - papp_tile->width;
666 _ivi_set_shell_surface_split(papp->ioutput->active, NULL,
667 reverse_orientation(papp_tile->orientation),
668 width_prev_app, false, false);
671 surface->role = IVI_SURFACE_ROLE_TILE;
672 surface->current_completed_output = papp->ioutput;
673 wl_list_insert(&surface->ivi->surfaces, &surface->link);
675 _ivi_set_shell_surface_split(surface, papp->ioutput,
676 papp_tile->orientation, papp_tile->width,
677 papp_tile->sticky, true);
679 /* remove it from pending */
680 wl_list_remove(&papp->link);
687 /* if we end up here means we have a regular desktop app and
688 * try to activate it */
689 ivi_set_desktop_surface(surface);
690 ivi_layout_desktop_committed(surface);
694 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
696 struct ivi_output *out;
698 wl_list_for_each(out, &ivi->outputs, link) {
699 create_black_curtain_view(out);
700 insert_black_curtain(out);
705 ivi_shell_init(struct ivi_compositor *ivi)
707 weston_layer_init(&ivi->hidden, ivi->compositor);
708 weston_layer_init(&ivi->background, ivi->compositor);
709 weston_layer_init(&ivi->normal, ivi->compositor);
710 weston_layer_init(&ivi->panel, ivi->compositor);
711 weston_layer_init(&ivi->popup, ivi->compositor);
712 weston_layer_init(&ivi->fullscreen, ivi->compositor);
714 weston_layer_set_position(&ivi->hidden,
715 WESTON_LAYER_POSITION_HIDDEN);
716 weston_layer_set_position(&ivi->background,
717 WESTON_LAYER_POSITION_BACKGROUND);
718 weston_layer_set_position(&ivi->normal,
719 WESTON_LAYER_POSITION_NORMAL);
720 weston_layer_set_position(&ivi->panel,
721 WESTON_LAYER_POSITION_UI);
722 weston_layer_set_position(&ivi->popup,
723 WESTON_LAYER_POSITION_TOP_UI);
724 weston_layer_set_position(&ivi->fullscreen,
725 WESTON_LAYER_POSITION_FULLSCREEN);
732 ivi_surf_destroy(struct ivi_surface *surf)
734 struct weston_surface *wsurface = surf->view->surface;
736 if (weston_surface_is_mapped(wsurface)) {
737 weston_desktop_surface_unlink_view(surf->view);
738 weston_view_destroy(surf->view);
741 wl_list_remove(&surf->link);
746 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
748 struct weston_view *view, *view_next;
750 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
751 struct ivi_surface *ivi_surf =
752 get_ivi_shell_surface(view->surface);
754 ivi_surf_destroy(ivi_surf);
759 ivi_shell_finalize(struct ivi_compositor *ivi)
761 struct ivi_output *output;
763 ivi_shell_destroy_views_on_layer(&ivi->hidden);
764 weston_layer_fini(&ivi->hidden);
766 ivi_shell_destroy_views_on_layer(&ivi->background);
767 weston_layer_fini(&ivi->background);
769 ivi_shell_destroy_views_on_layer(&ivi->normal);
770 weston_layer_fini(&ivi->normal);
772 ivi_shell_destroy_views_on_layer(&ivi->panel);
773 weston_layer_fini(&ivi->panel);
775 ivi_shell_destroy_views_on_layer(&ivi->popup);
776 weston_layer_fini(&ivi->popup);
778 wl_list_for_each(output, &ivi->outputs, link) {
779 if (output->fullscreen_view.fs &&
780 output->fullscreen_view.fs->view) {
781 weston_surface_unref(output->fullscreen_view.fs->view->surface);
782 output->fullscreen_view.fs->view = NULL;
785 weston_layer_fini(&ivi->fullscreen);
789 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
791 struct ivi_surface *surface;
793 wl_list_for_each(surface, &ivi->surfaces, link) {
795 weston_desktop_surface_get_app_id(surface->dsurface);
796 if (app_id == NULL) {
797 weston_log("WARNING app_is is null, unable to advertise\n");
800 agl_shell_desktop_send_application(resource, app_id);
804 static struct wl_client *
805 client_launch(struct weston_compositor *compositor,
806 struct weston_process *proc,
808 weston_process_cleanup_func_t cleanup)
810 struct wl_client *client = NULL;
811 struct custom_env child_env;
812 struct fdstr wayland_socket;
813 const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket";
814 const char *fail_seteuid = "Couldn't call seteuid";
821 struct ivi_compositor *ivi;
822 size_t written __attribute__((unused));
824 weston_log("launching '%s'\n", path);
825 str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
827 custom_env_init_from_environ(&child_env);
828 custom_env_add_from_exec_string(&child_env, path);
830 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
831 wayland_socket.fds) < 0) {
832 weston_log("client_launch: "
833 "socketpair failed while launching '%s': %s\n",
834 path, strerror(errno));
835 custom_env_fini(&child_env);
838 fdstr_update_str1(&wayland_socket);
839 custom_env_set_env_var(&child_env, "WAYLAND_SOCKET",
840 wayland_socket.str1);
842 argp = custom_env_get_argp(&child_env);
843 envp = custom_env_get_envp(&child_env);
848 /* Put the client in a new session so it won't catch signals
849 * intended for the parent. Sharing a session can be
850 * confusing when launching weston under gdb, as the ctrl-c
851 * intended for gdb will pass to the child, and weston
852 * will cleanly shut down when the child exits.
856 /* do not give our signal mask to the new process */
857 sigfillset(&allsigs);
858 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
860 /* Launch clients as the user. Do not launch clients with wrong euid. */
861 if (seteuid(getuid()) == -1) {
862 written = write(STDERR_FILENO, fail_seteuid, strlen(fail_seteuid));
866 ret = fdstr_clear_cloexec_fd1(&wayland_socket);
868 written = write(STDERR_FILENO, fail_cloexec, strlen(fail_cloexec));
872 execve(argp[0], argp, envp);
875 written = write(STDERR_FILENO, fail_exec, strlen(fail_exec));
879 close(wayland_socket.fds[1]);
880 ivi = weston_compositor_get_user_data(compositor);
881 client = wl_client_create(compositor->wl_display,
882 wayland_socket.fds[0]);
884 custom_env_fini(&child_env);
885 close(wayland_socket.fds[0]);
887 weston_log("client_launch: "
888 "wl_client_create failed while launching '%s'.\n",
894 proc->cleanup = cleanup;
895 wl_list_insert(&ivi->child_process_list, &proc->link);
899 fdstr_close_all(&wayland_socket);
900 weston_log("client_launch: "
901 "fork failed while launching '%s': %s\n", path,
906 custom_env_fini(&child_env);
912 struct process_info {
913 struct weston_process proc;
918 sigchld_handler(int signal_number, void *data)
920 struct weston_process *p;
921 struct ivi_compositor *ivi = data;
925 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
926 wl_list_for_each(p, &ivi->child_process_list, link) {
931 if (&p->link == &ivi->child_process_list) {
932 weston_log("unknown child process exited\n");
936 wl_list_remove(&p->link);
937 wl_list_init(&p->link);
938 p->cleanup(p, status);
941 if (pid < 0 && errno != ECHILD)
942 weston_log("waitpid error %s\n", strerror(errno));
949 process_handle_sigchld(struct weston_process *process, int status)
951 struct process_info *pinfo =
952 container_of(process, struct process_info, proc);
955 * There are no guarantees whether this runs before or after
956 * the wl_client destructor.
959 if (WIFEXITED(status)) {
960 weston_log("%s exited with status %d\n", pinfo->path,
961 WEXITSTATUS(status));
962 } else if (WIFSIGNALED(status)) {
963 weston_log("%s died on signal %d\n", pinfo->path,
966 weston_log("%s disappeared\n", pinfo->path);
974 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section,
975 struct wl_client **client)
977 struct process_info *pinfo;
978 struct weston_config_section *section;
979 char *command = NULL;
981 section = weston_config_get_section(ivi->config, cmd_section, NULL, NULL);
983 weston_config_section_get_string(section, "command", &command, NULL);
988 pinfo = zalloc(sizeof *pinfo);
992 pinfo->path = strdup(command);
996 *client = client_launch(ivi->compositor, &pinfo->proc, command, process_handle_sigchld);
1012 destroy_black_curtain_view(struct wl_listener *listener, void *data)
1014 struct fullscreen_view *fs =
1015 wl_container_of(listener, fs, fs_destroy);
1019 wl_list_remove(&fs->fs_destroy.link);
1026 curtain_get_label(struct weston_surface *surface, char *buf, size_t len)
1028 return snprintf(buf, len, "%s", "black curtain");
1032 curtain_surface_committed(struct weston_surface *es, int32_t sx, int32_t sy)
1039 create_black_curtain_view(struct ivi_output *output)
1041 struct weston_surface *surface = NULL;
1042 struct weston_view *view;
1043 struct ivi_compositor *ivi = output->ivi;
1044 struct weston_compositor *ec = ivi->compositor;
1045 struct weston_output *woutput = output->output;
1046 struct weston_buffer_reference *buffer_ref;
1051 surface = weston_surface_create(ec);
1055 view = weston_view_create(surface);
1059 buffer_ref = weston_buffer_create_solid_rgba(ec, 0.0, 0.0, 0.0, 1.0);
1060 if (buffer_ref == NULL)
1063 surface->committed = curtain_surface_committed;
1064 surface->committed_private = NULL;
1065 weston_surface_set_size(surface, woutput->width, woutput->height);
1067 weston_surface_attach_solid(surface, buffer_ref,
1068 woutput->width, woutput->height);
1070 weston_surface_set_label_func(surface, curtain_get_label);
1071 weston_view_set_position(view, woutput->x, woutput->y);
1073 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
1074 if (!output->fullscreen_view.fs)
1077 output->fullscreen_view.fs->view = view;
1078 output->fullscreen_view.buffer_ref = buffer_ref;
1080 output->fullscreen_view.fs_destroy.notify =
1081 destroy_black_curtain_view;
1082 wl_signal_add(&woutput->destroy_signal,
1083 &output->fullscreen_view.fs_destroy);
1088 weston_view_destroy(view);
1090 weston_surface_unref(surface);
1094 output_has_black_curtain(struct ivi_output *output)
1096 return (output->fullscreen_view.fs &&
1097 output->fullscreen_view.fs->view &&
1098 output->fullscreen_view.fs->view->is_mapped &&
1099 output->fullscreen_view.fs->view->surface->is_mapped);
1103 remove_black_curtain(struct ivi_output *output)
1105 struct weston_view *view;
1108 !output->fullscreen_view.fs &&
1109 !output->fullscreen_view.fs->view) ||
1110 !output->fullscreen_view.fs) {
1111 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1115 view = output->fullscreen_view.fs->view;
1116 assert(view->is_mapped == true ||
1117 view->surface->is_mapped == true);
1119 view->is_mapped = false;
1120 view->surface->is_mapped = false;
1122 weston_layer_entry_remove(&view->layer_link);
1123 weston_view_update_transform(view);
1125 weston_view_damage_below(view);
1127 weston_log("Removed black curtain from output %s\n", output->output->name);
1131 insert_black_curtain(struct ivi_output *output)
1133 struct weston_view *view;
1136 !output->fullscreen_view.fs &&
1137 !output->fullscreen_view.fs->view) ||
1138 !output->output || !output->fullscreen_view.fs) {
1139 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1143 view = output->fullscreen_view.fs->view;
1144 if (view->is_mapped || view->surface->is_mapped)
1147 weston_layer_entry_remove(&view->layer_link);
1148 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1151 view->is_mapped = true;
1152 view->surface->is_mapped = true;
1154 weston_view_update_transform(view);
1155 weston_view_damage_below(view);
1157 weston_log("Added black curtain to output %s\n", output->output->name);
1161 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
1162 enum agl_shell_app_state state)
1164 if (app_id && wl_resource_get_version(ivi->shell_client.resource) >=
1165 AGL_SHELL_APP_STATE_SINCE_VERSION) {
1167 agl_shell_send_app_state(ivi->shell_client.resource,
1170 if (ivi->shell_client.resource_ext)
1171 agl_shell_send_app_state(ivi->shell_client.resource_ext,
1177 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
1178 const char *output_name)
1180 if (app_id && ivi->shell_client.resource &&
1181 wl_resource_get_version(ivi->shell_client.resource) >=
1182 AGL_SHELL_APP_ON_OUTPUT_SINCE_VERSION) {
1184 agl_shell_send_app_on_output(ivi->shell_client.resource,
1185 app_id, output_name);
1187 if (ivi->shell_client.resource_ext)
1188 agl_shell_send_app_on_output(ivi->shell_client.resource_ext,
1189 app_id, output_name);
1194 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1196 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1197 struct ivi_output *output;
1198 struct ivi_surface *surface, *tmp;
1200 if (wl_resource_get_version(shell_res) >=
1201 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1202 ivi->shell_client.status == BOUND_FAILED) {
1203 wl_resource_post_error(shell_res,
1204 WL_DISPLAY_ERROR_INVALID_OBJECT,
1205 "agl_shell (ready quest) has already "
1206 "been bound. Check out bound_fail event");
1210 /* Init already finished. Do nothing */
1211 if (ivi->shell_client.ready)
1215 ivi->shell_client.ready = true;
1217 wl_list_for_each(output, &ivi->outputs, link) {
1218 if (output->background &&
1219 output->background->role == IVI_SURFACE_ROLE_BACKGROUND) {
1220 /* track the background surface role as a "regular"
1221 * surface so we can activate it */
1222 ivi_set_background_surface(output->background);
1223 remove_black_curtain(output);
1226 ivi_layout_init(ivi, output);
1229 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1232 wl_list_remove(&surface->link);
1233 wl_list_init(&surface->link);
1234 ivi_check_pending_desktop_surface(surface);
1235 surface->checked_pending = true;
1236 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1238 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_STARTED);
1243 shell_set_background(struct wl_client *client,
1244 struct wl_resource *shell_res,
1245 struct wl_resource *surface_res,
1246 struct wl_resource *output_res)
1248 struct weston_head *head = weston_head_from_resource(output_res);
1249 struct weston_output *woutput = weston_head_get_output(head);
1250 struct ivi_output *output = to_ivi_output(woutput);
1251 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1252 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1253 struct weston_desktop_surface *dsurface;
1254 struct ivi_surface *surface;
1256 if ((wl_resource_get_version(shell_res) >=
1257 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1258 ivi->shell_client.status == BOUND_FAILED) ||
1259 ivi->shell_client.resource_ext == shell_res) {
1260 wl_resource_post_error(shell_res,
1261 WL_DISPLAY_ERROR_INVALID_OBJECT,
1262 "agl_shell (set_background) has already "
1263 "been bound. Check out bound_fail event");
1267 dsurface = weston_surface_get_desktop_surface(wsurface);
1269 wl_resource_post_error(shell_res,
1270 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1271 "surface must be a desktop surface");
1275 surface = weston_desktop_surface_get_user_data(dsurface);
1276 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1277 wl_resource_post_error(shell_res,
1278 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1279 "surface already has another ivi role");
1283 if (output->background) {
1284 wl_resource_post_error(shell_res,
1285 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1286 "output already has background");
1290 surface->checked_pending = true;
1291 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1292 surface->bg.output = output;
1293 wl_list_remove(&surface->link);
1294 wl_list_init(&surface->link);
1296 output->background = surface;
1298 weston_desktop_surface_set_maximized(dsurface, true);
1299 weston_desktop_surface_set_size(dsurface,
1300 output->output->width,
1301 output->output->height);
1305 shell_set_panel(struct wl_client *client,
1306 struct wl_resource *shell_res,
1307 struct wl_resource *surface_res,
1308 struct wl_resource *output_res,
1311 struct weston_head *head = weston_head_from_resource(output_res);
1312 struct weston_output *woutput = weston_head_get_output(head);
1313 struct ivi_output *output = to_ivi_output(woutput);
1314 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1315 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1316 struct weston_desktop_surface *dsurface;
1317 struct ivi_surface *surface;
1318 struct ivi_surface **member;
1319 int32_t width = 0, height = 0;
1321 if ((wl_resource_get_version(shell_res) >=
1322 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1323 ivi->shell_client.status == BOUND_FAILED) ||
1324 ivi->shell_client.resource_ext == shell_res) {
1325 wl_resource_post_error(shell_res,
1326 WL_DISPLAY_ERROR_INVALID_OBJECT,
1327 "agl_shell (set_panel) has already been bound. "
1328 "Check out bound_fail event");
1332 dsurface = weston_surface_get_desktop_surface(wsurface);
1334 wl_resource_post_error(shell_res,
1335 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1336 "surface must be a desktop surface");
1340 surface = weston_desktop_surface_get_user_data(dsurface);
1341 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1342 wl_resource_post_error(shell_res,
1343 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1344 "surface already has another ivi role");
1349 case AGL_SHELL_EDGE_TOP:
1350 member = &output->top;
1352 case AGL_SHELL_EDGE_BOTTOM:
1353 member = &output->bottom;
1355 case AGL_SHELL_EDGE_LEFT:
1356 member = &output->left;
1358 case AGL_SHELL_EDGE_RIGHT:
1359 member = &output->right;
1362 wl_resource_post_error(shell_res,
1363 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1364 "invalid edge for panel");
1369 wl_resource_post_error(shell_res,
1370 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1371 "output already has panel on this edge");
1375 surface->checked_pending = true;
1376 surface->role = IVI_SURFACE_ROLE_PANEL;
1377 surface->panel.output = output;
1378 surface->panel.edge = edge;
1379 wl_list_remove(&surface->link);
1380 wl_list_init(&surface->link);
1384 switch (surface->panel.edge) {
1385 case AGL_SHELL_EDGE_TOP:
1386 case AGL_SHELL_EDGE_BOTTOM:
1387 width = woutput->width;
1389 case AGL_SHELL_EDGE_LEFT:
1390 case AGL_SHELL_EDGE_RIGHT:
1391 height = woutput->height;
1395 weston_desktop_surface_set_size(dsurface, width, height);
1399 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1400 const char *data, uint32_t app_state)
1402 struct desktop_client *dclient;
1404 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1405 struct ivi_policy *policy = ivi->policy;
1407 /* FIXME: should queue it here and see when binding agl-shell-desktop
1408 * if there are any to be sent */
1415 if (policy && policy->api.surface_advertise_state_change &&
1416 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1420 app_role = surf->role;
1421 if (app_role == IVI_SURFACE_ROLE_POPUP)
1422 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1424 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1425 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1426 data, app_state, app_role);
1430 shell_activate_app(struct wl_client *client,
1431 struct wl_resource *shell_res,
1433 struct wl_resource *output_res)
1435 struct weston_head *head;
1436 struct weston_output *woutput;
1437 struct ivi_compositor *ivi;
1438 struct ivi_output *output;
1440 head = weston_head_from_resource(output_res);
1442 weston_log("Invalid output to activate '%s' on\n", app_id);
1446 woutput = weston_head_get_output(head);
1447 ivi = wl_resource_get_user_data(shell_res);
1448 output = to_ivi_output(woutput);
1450 if (wl_resource_get_version(shell_res) >=
1451 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1452 ivi->shell_client.status == BOUND_FAILED) {
1453 wl_resource_post_error(shell_res,
1454 WL_DISPLAY_ERROR_INVALID_OBJECT,
1455 "agl_shell has already been bound. "
1456 "Check out bound_fail event");
1460 ivi_layout_activate(output, app_id);
1464 shell_new_deactivate_app(struct wl_client *client, struct wl_resource *shell_res,
1467 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1469 ivi_layout_deactivate(ivi, app_id);
1473 shell_set_app_float(struct wl_client *client, struct wl_resource *shell_res,
1474 const char *app_id, int32_t x_pos, int32_t y_pos)
1476 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1477 struct weston_output *output = get_focused_output(ivi->compositor);
1478 struct ivi_output *ivi_output;
1479 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1482 output = get_default_output(ivi->compositor);
1484 ivi_output = to_ivi_output(output);
1486 /* verify if already mapped as desktop role, regular, unmap it, so we
1487 * can make it float */
1488 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1489 struct weston_view *ev = surf->view;
1490 struct weston_desktop_surface *dsurf = surf->dsurface;
1491 struct ivi_bounding_box bb = {};
1492 const char *prev_activate_app_id = NULL;
1494 /* XXX: if this is useful we could bring it as active then make
1495 * it float, but avoid doing it for the moment */
1496 if (surf != ivi_output->active)
1499 if (ivi_output->previous_active)
1500 prev_activate_app_id =
1501 weston_desktop_surface_get_app_id(ivi_output->previous_active->dsurface);
1503 /* only deactivate if previous_active is different, otherwise
1504 * this will blow up, because we're trying to activate the same
1505 * app_id as the this one! */
1506 if (prev_activate_app_id && strcmp(app_id, prev_activate_app_id)) {
1507 ivi_layout_deactivate(ivi, app_id);
1508 } else if (prev_activate_app_id) {
1509 weston_layer_entry_remove(&ev->layer_link);
1510 weston_view_geometry_dirty(ev);
1511 weston_surface_damage(ev->surface);
1514 surf->hidden_layer_output = ivi_output;
1516 /* set attributes */
1517 surf->popup.output = ivi_output;
1519 surf->popup.x = x_pos;
1520 surf->popup.y = y_pos;
1521 surf->popup.bb = bb;
1524 /* change the role */
1525 surf->role = IVI_SURFACE_ROLE_NONE;
1527 wl_list_remove(&surf->link);
1528 wl_list_init(&surf->link);
1530 ivi_set_desktop_surface_popup(surf);
1532 weston_desktop_surface_set_maximized(dsurf, false);
1533 weston_desktop_surface_set_size(dsurf, 0, 0);
1535 /* add to hidden layer */
1536 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1537 weston_compositor_schedule_repaint(ivi->compositor);
1539 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_POPUP)) {
1540 ivi_set_pending_desktop_surface_popup(ivi_output, x_pos, y_pos,
1541 0, 0, 0, 0, app_id);
1546 shell_set_app_fullscreen(struct wl_client *client,
1547 struct wl_resource *shell_res, const char *app_id)
1549 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1550 struct weston_output *output = get_focused_output(ivi->compositor);
1551 struct ivi_output *ivi_output;
1552 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1555 output = get_default_output(ivi->compositor);
1557 ivi_output = to_ivi_output(output);
1559 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1560 struct weston_view *ev = surf->view;
1561 struct weston_desktop_surface *dsurf = surf->dsurface;
1563 if (surf != ivi_output->active)
1566 weston_layer_entry_remove(&surf->view->layer_link);
1567 weston_view_geometry_dirty(surf->view);
1568 weston_surface_damage(surf->view->surface);
1570 surf->hidden_layer_output = ivi_output;
1572 /* set attributes */
1573 surf->fullscreen.output = ivi_output;
1575 /* change the role */
1576 surf->role = IVI_SURFACE_ROLE_NONE;
1578 wl_list_remove(&surf->link);
1579 wl_list_init(&surf->link);
1581 ivi_set_desktop_surface_fullscreen(surf);
1583 weston_desktop_surface_set_maximized(dsurf, false);
1584 weston_desktop_surface_set_fullscreen(dsurf, true);
1585 weston_desktop_surface_set_size(dsurf,
1586 ivi_output->output->width,
1587 ivi_output->output->height);
1589 /* add to hidden layer */
1590 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1591 weston_compositor_schedule_repaint(ivi->compositor);
1592 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_FULLSCREEN)) {
1593 ivi_set_pending_desktop_surface_fullscreen(ivi_output, app_id);
1599 shell_set_app_normal(struct wl_client *client, struct wl_resource *shell_res,
1602 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1603 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1604 struct weston_output *output = get_focused_output(ivi->compositor);
1605 struct ivi_output *ivi_output;
1606 struct weston_desktop_surface *dsurf;
1607 struct weston_geometry area = {};
1610 if (!surf || (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP))
1614 output = get_default_output(ivi->compositor);
1616 dsurf = surf->dsurface;
1617 ivi_output = to_ivi_output(output);
1619 weston_layer_entry_remove(&surf->view->layer_link);
1620 weston_view_geometry_dirty(surf->view);
1621 weston_surface_damage(surf->view->surface);
1623 /* change the role */
1624 surf->role = IVI_SURFACE_ROLE_NONE;
1625 surf->state = NORMAL;
1626 surf->desktop.pending_output = ivi_output;
1628 wl_list_remove(&surf->link);
1629 wl_list_init(&surf->link);
1631 ivi_set_desktop_surface(surf);
1633 if (ivi_output->area_activation.width ||
1634 ivi_output->area_activation.height)
1635 area = ivi_output->area_activation;
1637 area = ivi_output->area;
1639 if (weston_desktop_surface_get_fullscreen(dsurf))
1640 weston_desktop_surface_set_fullscreen(dsurf, false);
1642 weston_desktop_surface_set_maximized(dsurf, true);
1643 weston_desktop_surface_set_size(dsurf, area.width, area.height);
1645 /* add to hidden layer */
1646 weston_layer_entry_insert(&ivi->hidden.view_list,
1647 &surf->view->layer_link);
1648 weston_compositor_schedule_repaint(ivi->compositor);
1653 shell_desktop_activate_app(struct wl_client *client,
1654 struct wl_resource *shell_res,
1655 const char *app_id, const char *data,
1656 struct wl_resource *output_res)
1658 struct weston_head *head = weston_head_from_resource(output_res);
1659 struct weston_output *woutput = weston_head_get_output(head);
1660 struct ivi_output *output = to_ivi_output(woutput);
1662 ivi_layout_activate(output, app_id);
1663 shell_advertise_app_state(output->ivi, app_id,
1664 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1668 shell_deactivate_app(struct wl_client *client,
1669 struct wl_resource *shell_res,
1672 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1673 struct ivi_compositor *ivi = dclient->ivi;
1675 ivi_layout_deactivate(ivi, app_id);
1676 shell_advertise_app_state(ivi, app_id,
1677 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1681 shell_destroy(struct wl_client *client, struct wl_resource *res)
1683 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1685 /* reset status in case bind_fail was sent */
1686 if (wl_resource_get_version(res) >= AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1687 ivi->shell_client.status == BOUND_FAILED)
1688 ivi->shell_client.status = BOUND_OK;
1692 shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
1693 struct wl_resource *output, int x, int y,
1694 int width, int height)
1696 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1697 struct weston_head *head = weston_head_from_resource(output);
1698 struct weston_output *woutput = weston_head_get_output(head);
1699 struct ivi_output *ioutput = to_ivi_output(woutput);
1701 struct weston_geometry area = { .x = x, .y = y,
1704 if (ivi->shell_client.ready)
1707 ioutput->area_activation = area;
1711 shell_set_app_output(struct wl_client *client, struct wl_resource *res,
1712 const char *app_id, struct wl_resource *output)
1714 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1715 struct weston_head *head = weston_head_from_resource(output);
1716 struct weston_output *woutput = weston_head_get_output(head);
1717 struct ivi_output *ioutput = to_ivi_output(woutput);
1718 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1719 struct ivi_output *desktop_last_output;
1720 struct ivi_output *current_completed_output;
1722 if (!app_id || !ioutput)
1725 /* handle the case we're not mapped at all */
1727 ivi_set_pending_desktop_surface_remote(ioutput, app_id);
1728 shell_send_app_on_output(ivi, app_id, woutput->name);
1732 desktop_last_output = surf->desktop.last_output;
1733 current_completed_output = surf->current_completed_output;
1735 if (surf->remote.output)
1736 surf->hidden_layer_output = surf->remote.output;
1738 surf->hidden_layer_output = desktop_last_output;
1739 assert(surf->hidden_layer_output);
1741 if (ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_REMOTE) ||
1742 ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_DESKTOP)) {
1743 if (!current_completed_output->background)
1744 insert_black_curtain(current_completed_output);
1746 ivi_layout_deactivate(ivi, app_id);
1749 /* update the remote output */
1750 surf->remote.output = ioutput;
1752 if (surf->role != IVI_SURFACE_ROLE_REMOTE) {
1753 wl_list_remove(&surf->link);
1754 wl_list_init(&surf->link);
1756 surf->role = IVI_SURFACE_ROLE_NONE;
1757 ivi_set_desktop_surface_remote(surf);
1760 shell_send_app_on_output(ivi, app_id, woutput->name);
1764 shell_set_app_position(struct wl_client *client, struct wl_resource *res,
1765 const char *app_id, int32_t x, int32_t y)
1767 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1768 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1770 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1773 weston_view_set_position(surf->view, x, y);
1774 weston_compositor_schedule_repaint(ivi->compositor);
1778 shell_set_app_scale(struct wl_client *client, struct wl_resource *res,
1779 const char *app_id, int32_t width, int32_t height)
1782 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1783 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1785 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1788 weston_desktop_surface_set_size(surf->dsurface, width, height);
1789 weston_compositor_schedule_repaint(ivi->compositor);
1793 _ivi_set_pending_desktop_surface_split(struct wl_resource *output,
1794 const char *app_id, uint32_t orientation)
1796 weston_log("%s() added split surface for app_id '%s' with "
1797 "orientation %d to pending\n", __func__, app_id, orientation);
1799 struct weston_head *head = weston_head_from_resource(output);
1800 struct weston_output *woutput = weston_head_get_output(head);
1801 struct ivi_output *ivi_output = to_ivi_output(woutput);
1803 struct pending_app_tile *app_tile = zalloc(sizeof(*app_tile));
1805 app_tile->base.app_id = strdup(app_id);
1806 app_tile->base.ioutput = ivi_output;
1807 app_tile->base.role = IVI_SURFACE_ROLE_TILE;
1809 app_tile->orientation = orientation;
1810 wl_list_insert(&ivi_output->ivi->pending_apps, &app_tile->base.link);
1815 split_orientation_to_string(uint32_t orientation)
1817 switch (orientation) {
1818 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1821 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1822 return "tile_right";
1824 case AGL_SHELL_TILE_ORIENTATION_TOP:
1827 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1828 return "tile_bottom";
1836 reverse_orientation(uint32_t orientation)
1839 switch (orientation) {
1840 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1841 return AGL_SHELL_TILE_ORIENTATION_RIGHT;
1843 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1844 return AGL_SHELL_TILE_ORIENTATION_LEFT;
1846 case AGL_SHELL_TILE_ORIENTATION_TOP:
1847 return AGL_SHELL_TILE_ORIENTATION_BOTTOM;
1849 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1850 return AGL_SHELL_TILE_ORIENTATION_TOP;
1853 return AGL_SHELL_TILE_ORIENTATION_NONE;
1858 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *ioutput,
1859 uint32_t orientation, uint32_t width, int32_t sticky,
1862 struct ivi_compositor *ivi = surface->ivi;
1863 struct weston_view *ev = surface->view;
1864 struct weston_geometry geom = {};
1865 struct ivi_output *output = NULL;
1867 int new_width, new_height;
1870 geom = weston_desktop_surface_get_geometry(surface->dsurface);
1871 output = ivi_layout_get_output_from_surface(surface);
1876 // if we don't supply a width we automatically default to doing a half
1877 // split, each window taking half of the current output
1878 switch (orientation) {
1879 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1880 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1882 new_width = output->area.width / 2;
1883 new_height = output->area.height;
1886 new_height = output->area.height;
1889 case AGL_SHELL_TILE_ORIENTATION_TOP:
1890 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1892 new_width = output->area.width;
1893 new_height = output->area.height / 2;
1895 new_width = output->area.width;
1899 case AGL_SHELL_TILE_ORIENTATION_NONE:
1900 /* use the current_completed_output because the sticky window
1901 * might have changed the output area */
1902 new_width = surface->current_completed_output->area_activation.width;
1903 new_height = surface->current_completed_output->area_activation.height;
1905 if (new_width != output->area.width)
1906 output->area.width = new_width;
1908 if (new_height != output->area.height)
1909 output->area.height = new_height;
1911 weston_log("Adjusting activation area "
1912 "to %dX%d\n", output->area.width, output->area.height);
1914 if (surface->sticky) {
1915 surface->sticky = 0;
1916 weston_log("Resetting sticky window\n");
1919 surface->role = surface->prev_role;
1920 weston_log("Resetting tile role to previous role\n");
1924 assert(!"Invalid orientation passed");
1928 x = output->area.x - geom.x;
1929 y = output->area.y - geom.y;
1931 if (orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1932 x += output->area.width - new_width;
1933 else if (orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1934 y += output->area.height - new_height;
1938 struct ivi_shell_seat *ivi_seat = NULL;
1939 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
1942 ivi_seat = get_ivi_shell_seat(wseat);
1944 if (!weston_view_is_mapped(ev))
1945 weston_view_update_transform(ev);
1947 weston_layer_entry_remove(&ev->layer_link);
1950 // mark view as mapped
1951 ev->is_mapped = true;
1952 ev->surface->is_mapped = true;
1953 surface->mapped = true;
1955 // update older/new active surface
1956 output->previous_active = output->active;
1957 output->active = surface;
1959 // add to the layer and inflict damage
1960 weston_view_set_output(ev, output->output);
1961 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1962 weston_view_geometry_dirty(ev);
1963 weston_surface_damage(ev->surface);
1965 // handle input / keyboard
1967 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
1970 weston_view_set_position(surface->view, x, y);
1971 weston_desktop_surface_set_size(surface->dsurface, new_width, new_height);
1972 weston_desktop_surface_set_orientation(surface->dsurface, orientation);
1973 surface->orientation = orientation;
1975 weston_compositor_schedule_repaint(ivi->compositor);
1978 surface->sticky = sticky;
1980 if (orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
1981 surface->prev_role = surface->role;
1982 surface->role = IVI_SURFACE_ROLE_TILE;
1983 weston_log("Found split orientation different that none, "
1984 "setting surface role to orientation tile\n");
1987 if (surface->sticky) {
1988 if (orientation == AGL_SHELL_TILE_ORIENTATION_LEFT ||
1989 orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1990 output->area.width -= new_width;
1992 if (orientation == AGL_SHELL_TILE_ORIENTATION_TOP ||
1993 orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1994 output->area.height -= new_height;
1996 weston_log("Found sticky window, adjusting activation area "
1997 "to %dX%d\n", output->area.width, output->area.height);
2002 shell_ivi_surf_count_split_surfaces(struct ivi_compositor *ivi)
2005 struct ivi_surface *surf;
2007 wl_list_for_each(surf, &ivi->surfaces, link) {
2008 if (surf->orientation > AGL_SHELL_TILE_ORIENTATION_NONE)
2017 void shell_set_app_split(struct wl_client *client, struct wl_resource *res,
2018 const char *app_id, uint32_t orientation, int32_t width,
2019 int32_t sticky, struct wl_resource *output_res)
2021 struct ivi_surface *surf;
2022 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2024 struct weston_head *head = weston_head_from_resource(output_res);
2025 struct weston_output *woutput = weston_head_get_output(head);
2026 struct ivi_output *output = to_ivi_output(woutput);
2031 if (shell_ivi_surf_count_split_surfaces(ivi) > 2) {
2032 weston_log("Found more than two split surfaces in tile orientation.\n");
2036 /* add it as pending until */
2037 surf = ivi_find_app(ivi, app_id);
2039 _ivi_set_pending_desktop_surface_split(output_res, app_id, orientation);
2043 if (output->previous_active && output->background != output->previous_active) {
2044 int width_prev_app = 0;
2045 struct weston_view *ev = output->previous_active->view;
2046 const char *prev_app_id =
2047 weston_desktop_surface_get_app_id(output->previous_active->dsurface);
2049 if (orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
2050 if (!weston_view_is_mapped(ev))
2051 weston_view_update_transform(ev);
2053 weston_layer_entry_remove(&ev->layer_link);
2055 ev->is_mapped = true;
2056 ev->surface->is_mapped = true;
2057 output->previous_active->mapped = true;
2059 weston_view_set_output(ev, woutput);
2060 weston_layer_entry_insert(&ivi->normal.view_list,
2063 ev->is_mapped = false;
2064 ev->surface->is_mapped = false;
2066 weston_layer_entry_remove(&ev->layer_link);
2068 weston_view_geometry_dirty(ev);
2069 weston_surface_damage(ev->surface);
2072 /* a 0 width means we have no explicit width set-up */
2074 if (orientation == AGL_SHELL_TILE_ORIENTATION_TOP ||
2075 orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
2076 width_prev_app = output->area.height - width;
2078 width_prev_app = output->area.width - width;
2081 weston_log("Setting previous application '%s' to orientation '%s' width %d, not sticky\n",
2082 prev_app_id, split_orientation_to_string(reverse_orientation(orientation)),
2085 _ivi_set_shell_surface_split(output->previous_active, NULL,
2086 reverse_orientation(orientation),
2087 width_prev_app, false, false);
2089 if (orientation == AGL_SHELL_TILE_ORIENTATION_NONE &&
2090 output->active == surf) {
2091 output->active = output->previous_active;
2095 weston_log("Setting application '%s' to orientation '%s' width %d, %s\n",
2096 app_id, split_orientation_to_string(orientation),
2097 width, sticky == 1 ? "sticky" : "not sticky");
2098 _ivi_set_shell_surface_split(surf, NULL, orientation, width, sticky, false);
2102 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
2104 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2106 ivi->shell_client_ext.doas_requested = false;
2107 wl_resource_destroy(res);
2111 shell_ext_doas(struct wl_client *client, struct wl_resource *res)
2113 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2115 ivi->shell_client_ext.doas_requested = true;
2117 if (ivi->shell_client_ext.resource && ivi->shell_client.resource) {
2118 ivi->shell_client_ext.doas_requested_pending_bind = true;
2120 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
2121 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS);
2123 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
2124 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_FAILED);
2129 static const struct agl_shell_interface agl_shell_implementation = {
2130 .ready = shell_ready,
2131 .set_background = shell_set_background,
2132 .set_panel = shell_set_panel,
2133 .activate_app = shell_activate_app,
2134 .destroy = shell_destroy,
2135 .set_activate_region = shell_set_activate_region,
2136 .deactivate_app = shell_new_deactivate_app,
2137 .set_app_float = shell_set_app_float,
2138 .set_app_normal = shell_set_app_normal,
2139 .set_app_fullscreen = shell_set_app_fullscreen,
2140 .set_app_output = shell_set_app_output,
2141 .set_app_position = shell_set_app_position,
2142 .set_app_scale = shell_set_app_scale,
2143 .set_app_split = shell_set_app_split,
2146 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
2147 .destroy = shell_ext_destroy,
2148 .doas_shell_client = shell_ext_doas,
2152 shell_desktop_set_app_property(struct wl_client *client,
2153 struct wl_resource *shell_res,
2154 const char *app_id, uint32_t role,
2155 int x, int y, int bx, int by,
2156 int width, int height,
2157 struct wl_resource *output_res)
2159 struct weston_head *head = weston_head_from_resource(output_res);
2160 struct weston_output *woutput = weston_head_get_output(head);
2161 struct ivi_output *output = to_ivi_output(woutput);
2164 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
2165 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
2166 width, height, app_id);
2168 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
2169 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
2171 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
2172 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
2173 ivi_set_pending_desktop_surface_split(output, app_id, role);
2175 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
2176 ivi_set_pending_desktop_surface_remote(output, app_id);
2184 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
2186 struct pending_popup *p_popup, *next_p_popup;
2187 struct pending_split *split_surf, *next_split_surf;
2188 struct pending_fullscreen *fs_surf, *next_fs_surf;
2189 struct pending_remote *remote_surf, *next_remote_surf;
2191 wl_list_for_each_safe(p_popup, next_p_popup,
2192 &ivi->popup_pending_apps, link)
2193 ivi_remove_pending_desktop_surface_popup(p_popup);
2195 wl_list_for_each_safe(split_surf, next_split_surf,
2196 &ivi->split_pending_apps, link)
2197 ivi_remove_pending_desktop_surface_split(split_surf);
2199 wl_list_for_each_safe(fs_surf, next_fs_surf,
2200 &ivi->fullscreen_pending_apps, link)
2201 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
2203 wl_list_for_each_safe(remote_surf, next_remote_surf,
2204 &ivi->remote_pending_apps, link)
2205 ivi_remove_pending_desktop_surface_remote(remote_surf);
2209 shell_desktop_set_app_property_mode(struct wl_client *client,
2210 struct wl_resource *shell_res, uint32_t perm)
2212 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
2214 dclient->ivi->keep_pending_surfaces = true;
2216 dclient->ivi->keep_pending_surfaces = false;
2217 /* remove any previous pending surfaces */
2218 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
2222 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
2223 .activate_app = shell_desktop_activate_app,
2224 .set_app_property = shell_desktop_set_app_property,
2225 .deactivate_app = shell_deactivate_app,
2226 .set_app_property_mode = shell_desktop_set_app_property_mode,
2230 unbind_agl_shell(struct wl_resource *resource)
2232 struct ivi_compositor *ivi;
2233 struct ivi_output *output;
2234 struct ivi_surface *surf, *surf_tmp;
2236 ivi = wl_resource_get_user_data(resource);
2238 /* reset status to allow other clients issue legit requests */
2239 if (wl_resource_get_version(resource) >=
2240 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
2241 ivi->shell_client.status == BOUND_FAILED) {
2242 ivi->shell_client.status = BOUND_OK;
2246 wl_list_for_each(output, &ivi->outputs, link) {
2248 /* reset the active surf if there's one present */
2249 if (output->active) {
2250 struct weston_geometry area = {};
2252 output->active->view->is_mapped = false;
2253 output->active->view->surface->is_mapped = false;
2255 weston_layer_entry_remove(&output->active->view->layer_link);
2256 output->active = NULL;
2258 output->area_activation = area;
2261 insert_black_curtain(output);
2264 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
2265 wl_list_remove(&surf->link);
2266 wl_list_init(&surf->link);
2269 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
2270 wl_list_remove(&surf->link);
2271 wl_list_init(&surf->link);
2274 wl_list_init(&ivi->surfaces);
2275 wl_list_init(&ivi->pending_surfaces);
2277 ivi->shell_client.ready = false;
2278 ivi->shell_client.resource = NULL;
2279 ivi->shell_client.resource_ext = NULL;
2280 ivi->shell_client.client = NULL;
2284 unbind_agl_shell_ext(struct wl_resource *resource)
2286 struct ivi_compositor *ivi = wl_resource_get_user_data(resource);
2288 ivi->shell_client_ext.resource = NULL;
2289 ivi->shell_client.resource_ext = NULL;
2290 ivi->shell_client_ext.doas_requested = false;
2294 bind_agl_shell(struct wl_client *client,
2295 void *data, uint32_t version, uint32_t id)
2297 struct ivi_compositor *ivi = data;
2298 struct wl_resource *resource;
2299 struct ivi_policy *policy;
2302 policy = ivi->policy;
2303 interface = (void *) &agl_shell_interface;
2304 if (policy && policy->api.shell_bind_interface &&
2305 !policy->api.shell_bind_interface(client, interface)) {
2306 wl_client_post_implementation_error(client,
2307 "client not authorized to use agl_shell");
2311 resource = wl_resource_create(client, &agl_shell_interface, version, id);
2313 wl_client_post_no_memory(client);
2317 if (ivi->shell_client.resource && wl_resource_get_version(resource) == 1) {
2318 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2319 "agl_shell has already been bound (version 1)");
2320 wl_resource_destroy(resource);
2324 // for agl_shell client proxy
2325 if (ivi->shell_client.resource &&
2326 ivi->shell_client_ext.doas_requested_pending_bind) {
2328 ivi->shell_client_ext.doas_requested_pending_bind = false;
2330 // if there's one connected
2331 if (ivi->shell_client.resource_ext) {
2332 ivi->shell_client_ext.status = BOUND_FAILED;
2333 agl_shell_send_bound_fail(ivi->shell_client.resource_ext);
2334 wl_resource_destroy(resource);
2338 wl_resource_set_implementation(resource, &agl_shell_implementation,
2340 ivi->shell_client.resource_ext = resource;
2341 ivi->shell_client_ext.status = BOUND_OK;
2342 agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
2347 // if we already have an agl_shell client
2348 if (ivi->shell_client.resource) {
2349 agl_shell_send_bound_fail(resource);
2350 ivi->shell_client.status = BOUND_FAILED;
2351 wl_resource_destroy(resource);
2355 // default agl_shell client
2356 wl_resource_set_implementation(resource, &agl_shell_implementation,
2357 ivi, unbind_agl_shell);
2358 ivi->shell_client.resource = resource;
2360 if (wl_resource_get_version(resource) >=
2361 AGL_SHELL_BOUND_OK_SINCE_VERSION) {
2362 /* if we land here we'll have BOUND_OK by default,
2363 but still do the assignment */
2364 ivi->shell_client.status = BOUND_OK;
2365 agl_shell_send_bound_ok(ivi->shell_client.resource);
2370 bind_agl_shell_ext(struct wl_client *client,
2371 void *data, uint32_t version, uint32_t id)
2373 struct ivi_compositor *ivi = data;
2374 struct wl_resource *resource;
2376 resource = wl_resource_create(client, &agl_shell_ext_interface, version, id);
2378 wl_client_post_no_memory(client);
2382 if (ivi->shell_client_ext.resource) {
2383 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2384 "agl_shell_ext has already been bound");
2388 wl_resource_set_implementation(resource, &agl_shell_ext_implementation,
2389 ivi, unbind_agl_shell_ext);
2390 ivi->shell_client_ext.resource = resource;
2394 unbind_agl_shell_desktop(struct wl_resource *resource)
2396 struct desktop_client *dclient = wl_resource_get_user_data(resource);
2398 wl_list_remove(&dclient->link);
2403 bind_agl_shell_desktop(struct wl_client *client,
2404 void *data, uint32_t version, uint32_t id)
2406 struct ivi_compositor *ivi = data;
2407 struct wl_resource *resource;
2408 struct ivi_policy *policy;
2409 struct desktop_client *dclient;
2412 policy = ivi->policy;
2413 interface = (void *) &agl_shell_desktop_interface;
2414 if (policy && policy->api.shell_bind_interface &&
2415 !policy->api.shell_bind_interface(client, interface)) {
2416 wl_client_post_implementation_error(client,
2417 "client not authorized to use agl_shell_desktop");
2421 dclient = zalloc(sizeof(*dclient));
2423 wl_client_post_no_memory(client);
2427 resource = wl_resource_create(client, &agl_shell_desktop_interface,
2431 wl_client_post_no_memory(client);
2435 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
2436 dclient, unbind_agl_shell_desktop);
2438 dclient->resource = resource;
2439 wl_list_insert(&ivi->desktop_clients, &dclient->link);
2441 /* advertise xdg surfaces */
2442 ivi_shell_advertise_xdg_surfaces(ivi, resource);
2446 ivi_shell_create_global(struct ivi_compositor *ivi)
2448 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
2449 &agl_shell_interface, 11,
2450 ivi, bind_agl_shell);
2451 if (!ivi->agl_shell) {
2452 weston_log("Failed to create wayland global.\n");
2456 ivi->agl_shell_ext = wl_global_create(ivi->compositor->wl_display,
2457 &agl_shell_ext_interface, 1,
2458 ivi, bind_agl_shell_ext);
2459 if (!ivi->agl_shell_ext) {
2460 weston_log("Failed to create agl_shell_ext global.\n");
2464 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
2465 &agl_shell_desktop_interface, 2,
2466 ivi, bind_agl_shell_desktop);
2467 if (!ivi->agl_shell_desktop) {
2468 weston_log("Failed to create wayland global (agl_shell_desktop).\n");