2 * Copyright © 2019, 2022, 2024 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 wet_process *proc,
808 wet_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 wet_process proc;
918 sigchld_handler(int signal_number, void *data)
920 struct wet_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, NULL);
941 if (pid < 0 && errno != ECHILD)
942 weston_log("waitpid error %s\n", strerror(errno));
949 process_handle_sigchld(struct wet_process *process, int status, void *data)
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, struct weston_coord_surface new_origin)
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->pos);
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;
1106 struct weston_surface *wsurface;
1109 !output->fullscreen_view.fs &&
1110 !output->fullscreen_view.fs->view) ||
1111 !output->fullscreen_view.fs) {
1112 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1116 view = output->fullscreen_view.fs->view;
1117 wsurface = view->surface;
1118 assert(view->is_mapped == true ||
1119 view->surface->is_mapped == true);
1121 weston_surface_unmap(wsurface);
1123 weston_view_move_to_layer(view, NULL);
1124 weston_log("Removed black curtain from output %s\n", output->output->name);
1128 insert_black_curtain(struct ivi_output *output)
1130 struct weston_view *view;
1131 struct weston_surface *wsurface;
1134 !output->fullscreen_view.fs &&
1135 !output->fullscreen_view.fs->view) ||
1136 !output->output || !output->fullscreen_view.fs) {
1137 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1141 view = output->fullscreen_view.fs->view;
1142 wsurface = view->surface;
1143 if (view->is_mapped || view->surface->is_mapped)
1146 weston_surface_map(wsurface);
1147 weston_view_move_to_layer(view, &output->ivi->fullscreen.view_list);
1148 weston_log("Added black curtain to output %s\n", output->output->name);
1152 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
1153 enum agl_shell_app_state state)
1155 if (app_id && wl_resource_get_version(ivi->shell_client.resource) >=
1156 AGL_SHELL_APP_STATE_SINCE_VERSION) {
1158 agl_shell_send_app_state(ivi->shell_client.resource,
1161 if (ivi->shell_client.resource_ext)
1162 agl_shell_send_app_state(ivi->shell_client.resource_ext,
1168 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
1169 const char *output_name)
1171 if (app_id && ivi->shell_client.resource &&
1172 wl_resource_get_version(ivi->shell_client.resource) >=
1173 AGL_SHELL_APP_ON_OUTPUT_SINCE_VERSION) {
1175 agl_shell_send_app_on_output(ivi->shell_client.resource,
1176 app_id, output_name);
1178 if (ivi->shell_client.resource_ext)
1179 agl_shell_send_app_on_output(ivi->shell_client.resource_ext,
1180 app_id, output_name);
1185 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1187 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1188 struct ivi_output *output;
1189 struct ivi_surface *surface, *tmp;
1191 if (wl_resource_get_version(shell_res) >=
1192 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1193 ivi->shell_client.status == BOUND_FAILED) {
1194 wl_resource_post_error(shell_res,
1195 WL_DISPLAY_ERROR_INVALID_OBJECT,
1196 "agl_shell (ready quest) has already "
1197 "been bound. Check out bound_fail event");
1201 /* Init already finished. Do nothing */
1202 if (ivi->shell_client.ready)
1206 ivi->shell_client.ready = true;
1208 wl_list_for_each(output, &ivi->outputs, link) {
1209 if (output->background &&
1210 output->background->role == IVI_SURFACE_ROLE_BACKGROUND) {
1211 /* track the background surface role as a "regular"
1212 * surface so we can activate it */
1213 ivi_set_background_surface(output->background);
1214 remove_black_curtain(output);
1217 ivi_layout_init(ivi, output);
1220 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1223 wl_list_remove(&surface->link);
1224 wl_list_init(&surface->link);
1225 ivi_check_pending_desktop_surface(surface);
1226 surface->checked_pending = true;
1227 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1229 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_STARTED);
1234 shell_set_background(struct wl_client *client,
1235 struct wl_resource *shell_res,
1236 struct wl_resource *surface_res,
1237 struct wl_resource *output_res)
1239 struct weston_head *head = weston_head_from_resource(output_res);
1240 struct weston_output *woutput = weston_head_get_output(head);
1241 struct ivi_output *output = to_ivi_output(woutput);
1242 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1243 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1244 struct weston_desktop_surface *dsurface;
1245 struct ivi_surface *surface;
1247 if ((wl_resource_get_version(shell_res) >=
1248 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1249 ivi->shell_client.status == BOUND_FAILED) ||
1250 ivi->shell_client.resource_ext == shell_res) {
1251 wl_resource_post_error(shell_res,
1252 WL_DISPLAY_ERROR_INVALID_OBJECT,
1253 "agl_shell (set_background) has already "
1254 "been bound. Check out bound_fail event");
1258 dsurface = weston_surface_get_desktop_surface(wsurface);
1260 wl_resource_post_error(shell_res,
1261 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1262 "surface must be a desktop surface");
1266 surface = weston_desktop_surface_get_user_data(dsurface);
1267 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1268 wl_resource_post_error(shell_res,
1269 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1270 "surface already has another ivi role");
1274 if (output->background) {
1275 wl_resource_post_error(shell_res,
1276 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1277 "output already has background");
1281 surface->checked_pending = true;
1282 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1283 surface->bg.output = output;
1284 wl_list_remove(&surface->link);
1285 wl_list_init(&surface->link);
1287 output->background = surface;
1289 weston_desktop_surface_set_maximized(dsurface, true);
1290 weston_desktop_surface_set_size(dsurface,
1291 output->output->width,
1292 output->output->height);
1296 shell_set_panel(struct wl_client *client,
1297 struct wl_resource *shell_res,
1298 struct wl_resource *surface_res,
1299 struct wl_resource *output_res,
1302 struct weston_head *head = weston_head_from_resource(output_res);
1303 struct weston_output *woutput = weston_head_get_output(head);
1304 struct ivi_output *output = to_ivi_output(woutput);
1305 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1306 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1307 struct weston_desktop_surface *dsurface;
1308 struct ivi_surface *surface;
1309 struct ivi_surface **member;
1310 int32_t width = 0, height = 0;
1312 if ((wl_resource_get_version(shell_res) >=
1313 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1314 ivi->shell_client.status == BOUND_FAILED) ||
1315 ivi->shell_client.resource_ext == shell_res) {
1316 wl_resource_post_error(shell_res,
1317 WL_DISPLAY_ERROR_INVALID_OBJECT,
1318 "agl_shell (set_panel) has already been bound. "
1319 "Check out bound_fail event");
1323 dsurface = weston_surface_get_desktop_surface(wsurface);
1325 wl_resource_post_error(shell_res,
1326 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1327 "surface must be a desktop surface");
1331 surface = weston_desktop_surface_get_user_data(dsurface);
1332 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1333 wl_resource_post_error(shell_res,
1334 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1335 "surface already has another ivi role");
1340 case AGL_SHELL_EDGE_TOP:
1341 member = &output->top;
1343 case AGL_SHELL_EDGE_BOTTOM:
1344 member = &output->bottom;
1346 case AGL_SHELL_EDGE_LEFT:
1347 member = &output->left;
1349 case AGL_SHELL_EDGE_RIGHT:
1350 member = &output->right;
1353 wl_resource_post_error(shell_res,
1354 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1355 "invalid edge for panel");
1360 wl_resource_post_error(shell_res,
1361 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1362 "output already has panel on this edge");
1366 surface->checked_pending = true;
1367 surface->role = IVI_SURFACE_ROLE_PANEL;
1368 surface->panel.output = output;
1369 surface->panel.edge = edge;
1370 wl_list_remove(&surface->link);
1371 wl_list_init(&surface->link);
1375 switch (surface->panel.edge) {
1376 case AGL_SHELL_EDGE_TOP:
1377 case AGL_SHELL_EDGE_BOTTOM:
1378 width = woutput->width;
1380 case AGL_SHELL_EDGE_LEFT:
1381 case AGL_SHELL_EDGE_RIGHT:
1382 height = woutput->height;
1386 weston_desktop_surface_set_size(dsurface, width, height);
1390 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1391 const char *data, uint32_t app_state)
1393 struct desktop_client *dclient;
1395 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1396 struct ivi_policy *policy = ivi->policy;
1398 /* FIXME: should queue it here and see when binding agl-shell-desktop
1399 * if there are any to be sent */
1406 if (policy && policy->api.surface_advertise_state_change &&
1407 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1411 app_role = surf->role;
1412 if (app_role == IVI_SURFACE_ROLE_POPUP)
1413 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1415 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1416 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1417 data, app_state, app_role);
1421 shell_activate_app(struct wl_client *client,
1422 struct wl_resource *shell_res,
1424 struct wl_resource *output_res)
1426 struct weston_head *head;
1427 struct weston_output *woutput;
1428 struct ivi_compositor *ivi;
1429 struct ivi_output *output;
1431 head = weston_head_from_resource(output_res);
1433 weston_log("Invalid output to activate '%s' on\n", app_id);
1437 woutput = weston_head_get_output(head);
1438 ivi = wl_resource_get_user_data(shell_res);
1439 output = to_ivi_output(woutput);
1441 if (wl_resource_get_version(shell_res) >=
1442 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1443 ivi->shell_client.status == BOUND_FAILED) {
1444 wl_resource_post_error(shell_res,
1445 WL_DISPLAY_ERROR_INVALID_OBJECT,
1446 "agl_shell has already been bound. "
1447 "Check out bound_fail event");
1451 ivi_layout_activate(output, app_id);
1455 shell_new_deactivate_app(struct wl_client *client, struct wl_resource *shell_res,
1458 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1460 ivi_layout_deactivate(ivi, app_id);
1464 shell_set_app_float(struct wl_client *client, struct wl_resource *shell_res,
1465 const char *app_id, int32_t x_pos, int32_t y_pos)
1467 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1468 struct weston_output *output = get_focused_output(ivi->compositor);
1469 struct ivi_output *ivi_output;
1470 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1473 output = get_default_output(ivi->compositor);
1475 ivi_output = to_ivi_output(output);
1477 /* verify if already mapped as desktop role, regular, unmap it, so we
1478 * can make it float */
1479 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1480 struct weston_view *ev = surf->view;
1481 struct weston_desktop_surface *dsurf = surf->dsurface;
1482 struct ivi_bounding_box bb = {};
1483 const char *prev_activate_app_id = NULL;
1485 /* XXX: if this is useful we could bring it as active then make
1486 * it float, but avoid doing it for the moment */
1487 if (surf != ivi_output->active)
1490 if (ivi_output->previous_active)
1491 prev_activate_app_id =
1492 weston_desktop_surface_get_app_id(ivi_output->previous_active->dsurface);
1494 /* only deactivate if previous_active is different, otherwise
1495 * this will blow up, because we're trying to activate the same
1496 * app_id as the this one! */
1497 if (prev_activate_app_id && strcmp(app_id, prev_activate_app_id)) {
1498 ivi_layout_deactivate(ivi, app_id);
1499 } else if (prev_activate_app_id) {
1500 weston_layer_entry_remove(&ev->layer_link);
1501 weston_view_geometry_dirty(ev);
1502 weston_surface_damage(ev->surface);
1505 surf->hidden_layer_output = ivi_output;
1507 /* set attributes */
1508 surf->popup.output = ivi_output;
1510 surf->popup.x = x_pos;
1511 surf->popup.y = y_pos;
1512 surf->popup.bb = bb;
1515 /* change the role */
1516 surf->role = IVI_SURFACE_ROLE_NONE;
1518 wl_list_remove(&surf->link);
1519 wl_list_init(&surf->link);
1521 ivi_set_desktop_surface_popup(surf);
1523 weston_desktop_surface_set_maximized(dsurf, false);
1524 weston_desktop_surface_set_size(dsurf, 0, 0);
1526 /* add to hidden layer */
1527 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1528 weston_compositor_schedule_repaint(ivi->compositor);
1530 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_POPUP)) {
1531 ivi_set_pending_desktop_surface_popup(ivi_output, x_pos, y_pos,
1532 0, 0, 0, 0, app_id);
1537 shell_set_app_fullscreen(struct wl_client *client,
1538 struct wl_resource *shell_res, const char *app_id)
1540 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1541 struct weston_output *output = get_focused_output(ivi->compositor);
1542 struct ivi_output *ivi_output;
1543 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1546 output = get_default_output(ivi->compositor);
1548 ivi_output = to_ivi_output(output);
1550 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1551 struct weston_view *ev = surf->view;
1552 struct weston_desktop_surface *dsurf = surf->dsurface;
1554 if (surf != ivi_output->active)
1557 weston_layer_entry_remove(&surf->view->layer_link);
1558 weston_view_geometry_dirty(surf->view);
1559 weston_surface_damage(surf->view->surface);
1561 surf->hidden_layer_output = ivi_output;
1563 /* set attributes */
1564 surf->fullscreen.output = ivi_output;
1566 /* change the role */
1567 surf->role = IVI_SURFACE_ROLE_NONE;
1569 wl_list_remove(&surf->link);
1570 wl_list_init(&surf->link);
1572 ivi_set_desktop_surface_fullscreen(surf);
1574 weston_desktop_surface_set_maximized(dsurf, false);
1575 weston_desktop_surface_set_fullscreen(dsurf, true);
1576 weston_desktop_surface_set_size(dsurf,
1577 ivi_output->output->width,
1578 ivi_output->output->height);
1580 /* add to hidden layer */
1581 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1582 weston_compositor_schedule_repaint(ivi->compositor);
1583 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_FULLSCREEN)) {
1584 ivi_set_pending_desktop_surface_fullscreen(ivi_output, app_id);
1590 shell_set_app_normal(struct wl_client *client, struct wl_resource *shell_res,
1593 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1594 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1595 struct weston_output *output = get_focused_output(ivi->compositor);
1596 struct ivi_output *ivi_output;
1597 struct weston_desktop_surface *dsurf;
1598 struct weston_geometry area = {};
1601 if (!surf || (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP))
1605 output = get_default_output(ivi->compositor);
1607 dsurf = surf->dsurface;
1608 ivi_output = to_ivi_output(output);
1610 weston_layer_entry_remove(&surf->view->layer_link);
1611 weston_view_geometry_dirty(surf->view);
1612 weston_surface_damage(surf->view->surface);
1614 /* change the role */
1615 surf->role = IVI_SURFACE_ROLE_NONE;
1616 surf->state = NORMAL;
1617 surf->desktop.pending_output = ivi_output;
1619 wl_list_remove(&surf->link);
1620 wl_list_init(&surf->link);
1622 ivi_set_desktop_surface(surf);
1624 if (ivi_output->area_activation.width ||
1625 ivi_output->area_activation.height)
1626 area = ivi_output->area_activation;
1628 area = ivi_output->area;
1630 if (weston_desktop_surface_get_fullscreen(dsurf))
1631 weston_desktop_surface_set_fullscreen(dsurf, false);
1633 weston_desktop_surface_set_maximized(dsurf, true);
1634 weston_desktop_surface_set_size(dsurf, area.width, area.height);
1636 /* add to hidden layer */
1637 weston_layer_entry_insert(&ivi->hidden.view_list,
1638 &surf->view->layer_link);
1639 weston_compositor_schedule_repaint(ivi->compositor);
1644 shell_desktop_activate_app(struct wl_client *client,
1645 struct wl_resource *shell_res,
1646 const char *app_id, const char *data,
1647 struct wl_resource *output_res)
1649 struct weston_head *head = weston_head_from_resource(output_res);
1650 struct weston_output *woutput = weston_head_get_output(head);
1651 struct ivi_output *output = to_ivi_output(woutput);
1653 ivi_layout_activate(output, app_id);
1654 shell_advertise_app_state(output->ivi, app_id,
1655 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1659 shell_deactivate_app(struct wl_client *client,
1660 struct wl_resource *shell_res,
1663 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1664 struct ivi_compositor *ivi = dclient->ivi;
1666 ivi_layout_deactivate(ivi, app_id);
1667 shell_advertise_app_state(ivi, app_id,
1668 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1672 shell_destroy(struct wl_client *client, struct wl_resource *res)
1674 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1676 /* reset status in case bind_fail was sent */
1677 if (wl_resource_get_version(res) >= AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1678 ivi->shell_client.status == BOUND_FAILED)
1679 ivi->shell_client.status = BOUND_OK;
1683 shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
1684 struct wl_resource *output, int x, int y,
1685 int width, int height)
1687 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1688 struct weston_head *head = weston_head_from_resource(output);
1689 struct weston_output *woutput = weston_head_get_output(head);
1690 struct ivi_output *ioutput = to_ivi_output(woutput);
1692 struct weston_geometry area = { .x = x, .y = y,
1695 if (ivi->shell_client.ready)
1698 ioutput->area_activation = area;
1702 shell_set_app_output(struct wl_client *client, struct wl_resource *res,
1703 const char *app_id, struct wl_resource *output)
1705 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1706 struct weston_head *head = weston_head_from_resource(output);
1707 struct weston_output *woutput = weston_head_get_output(head);
1708 struct ivi_output *ioutput = to_ivi_output(woutput);
1709 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1710 struct ivi_output *desktop_last_output;
1711 struct ivi_output *current_completed_output;
1713 if (!app_id || !ioutput)
1716 /* handle the case we're not mapped at all */
1718 ivi_set_pending_desktop_surface_remote(ioutput, app_id);
1719 shell_send_app_on_output(ivi, app_id, woutput->name);
1723 desktop_last_output = surf->desktop.last_output;
1724 current_completed_output = surf->current_completed_output;
1726 if (surf->remote.output)
1727 surf->hidden_layer_output = surf->remote.output;
1729 surf->hidden_layer_output = desktop_last_output;
1730 assert(surf->hidden_layer_output);
1732 if (ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_REMOTE) ||
1733 ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_DESKTOP)) {
1734 if (!current_completed_output->background)
1735 insert_black_curtain(current_completed_output);
1737 ivi_layout_deactivate(ivi, app_id);
1740 /* update the remote output */
1741 surf->remote.output = ioutput;
1743 if (surf->role != IVI_SURFACE_ROLE_REMOTE) {
1744 wl_list_remove(&surf->link);
1745 wl_list_init(&surf->link);
1747 surf->role = IVI_SURFACE_ROLE_NONE;
1748 ivi_set_desktop_surface_remote(surf);
1751 shell_send_app_on_output(ivi, app_id, woutput->name);
1755 shell_set_app_position(struct wl_client *client, struct wl_resource *res,
1756 const char *app_id, int32_t x, int32_t y)
1758 struct weston_coord_global pos;
1759 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1760 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1762 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1767 weston_view_set_position(surf->view, pos);
1768 weston_compositor_schedule_repaint(ivi->compositor);
1772 shell_set_app_scale(struct wl_client *client, struct wl_resource *res,
1773 const char *app_id, int32_t width, int32_t height)
1776 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1777 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1779 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1782 weston_desktop_surface_set_size(surf->dsurface, width, height);
1783 weston_compositor_schedule_repaint(ivi->compositor);
1787 _ivi_set_pending_desktop_surface_split(struct wl_resource *output,
1788 const char *app_id, uint32_t orientation)
1790 weston_log("%s() added split surface for app_id '%s' with "
1791 "orientation %d to pending\n", __func__, app_id, orientation);
1793 struct weston_head *head = weston_head_from_resource(output);
1794 struct weston_output *woutput = weston_head_get_output(head);
1795 struct ivi_output *ivi_output = to_ivi_output(woutput);
1797 struct pending_app_tile *app_tile = zalloc(sizeof(*app_tile));
1799 app_tile->base.app_id = strdup(app_id);
1800 app_tile->base.ioutput = ivi_output;
1801 app_tile->base.role = IVI_SURFACE_ROLE_TILE;
1803 app_tile->orientation = orientation;
1804 wl_list_insert(&ivi_output->ivi->pending_apps, &app_tile->base.link);
1809 split_orientation_to_string(uint32_t orientation)
1811 switch (orientation) {
1812 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1815 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1816 return "tile_right";
1818 case AGL_SHELL_TILE_ORIENTATION_TOP:
1821 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1822 return "tile_bottom";
1830 reverse_orientation(uint32_t orientation)
1833 switch (orientation) {
1834 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1835 return AGL_SHELL_TILE_ORIENTATION_RIGHT;
1837 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1838 return AGL_SHELL_TILE_ORIENTATION_LEFT;
1840 case AGL_SHELL_TILE_ORIENTATION_TOP:
1841 return AGL_SHELL_TILE_ORIENTATION_BOTTOM;
1843 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1844 return AGL_SHELL_TILE_ORIENTATION_TOP;
1847 return AGL_SHELL_TILE_ORIENTATION_NONE;
1852 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *ioutput,
1853 uint32_t orientation, uint32_t width, int32_t sticky,
1856 struct ivi_compositor *ivi = surface->ivi;
1857 struct weston_view *ev = surface->view;
1858 struct weston_geometry geom = {};
1859 struct ivi_output *output = NULL;
1860 struct weston_coord_global pos;
1862 int new_width, new_height;
1865 geom = weston_desktop_surface_get_geometry(surface->dsurface);
1866 output = ivi_layout_get_output_from_surface(surface);
1871 // if we don't supply a width we automatically default to doing a half
1872 // split, each window taking half of the current output
1873 switch (orientation) {
1874 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1875 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1877 new_width = output->area.width / 2;
1878 new_height = output->area.height;
1881 new_height = output->area.height;
1884 case AGL_SHELL_TILE_ORIENTATION_TOP:
1885 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1887 new_width = output->area.width;
1888 new_height = output->area.height / 2;
1890 new_width = output->area.width;
1894 case AGL_SHELL_TILE_ORIENTATION_NONE:
1895 /* use the current_completed_output because the sticky window
1896 * might have changed the output area */
1897 new_width = surface->current_completed_output->area_activation.width;
1898 new_height = surface->current_completed_output->area_activation.height;
1900 if (new_width != output->area.width)
1901 output->area.width = new_width;
1903 if (new_height != output->area.height)
1904 output->area.height = new_height;
1906 weston_log("Adjusting activation area "
1907 "to %dX%d\n", output->area.width, output->area.height);
1909 if (surface->sticky) {
1910 surface->sticky = 0;
1911 weston_log("Resetting sticky window\n");
1914 surface->role = surface->prev_role;
1915 weston_log("Resetting tile role to previous role\n");
1919 assert(!"Invalid orientation passed");
1923 x = output->area.x - geom.x;
1924 y = output->area.y - geom.y;
1926 if (orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1927 x += output->area.width - new_width;
1928 else if (orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1929 y += output->area.height - new_height;
1933 struct ivi_shell_seat *ivi_seat = NULL;
1934 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
1937 ivi_seat = get_ivi_shell_seat(wseat);
1939 if (!weston_view_is_mapped(ev))
1940 weston_view_update_transform(ev);
1942 weston_layer_entry_remove(&ev->layer_link);
1945 // mark view as mapped
1946 ev->is_mapped = true;
1947 ev->surface->is_mapped = true;
1948 surface->mapped = true;
1950 // update older/new active surface
1951 output->previous_active = output->active;
1952 output->active = surface;
1954 // add to the layer and inflict damage
1955 weston_view_set_output(ev, output->output);
1956 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1957 weston_view_geometry_dirty(ev);
1958 weston_surface_damage(ev->surface);
1960 // handle input / keyboard
1962 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
1968 weston_view_set_position(surface->view, pos);
1969 weston_desktop_surface_set_size(surface->dsurface, new_width, new_height);
1970 weston_desktop_surface_set_orientation(surface->dsurface, orientation);
1971 surface->orientation = orientation;
1973 weston_compositor_schedule_repaint(ivi->compositor);
1976 surface->sticky = sticky;
1978 if (orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
1979 surface->prev_role = surface->role;
1980 surface->role = IVI_SURFACE_ROLE_TILE;
1981 weston_log("Found split orientation different that none, "
1982 "setting surface role to orientation tile\n");
1985 if (surface->sticky) {
1986 if (orientation == AGL_SHELL_TILE_ORIENTATION_LEFT ||
1987 orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1988 output->area.width -= new_width;
1990 if (orientation == AGL_SHELL_TILE_ORIENTATION_TOP ||
1991 orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1992 output->area.height -= new_height;
1994 weston_log("Found sticky window, adjusting activation area "
1995 "to %dX%d\n", output->area.width, output->area.height);
2000 shell_ivi_surf_count_split_surfaces(struct ivi_compositor *ivi)
2003 struct ivi_surface *surf;
2005 wl_list_for_each(surf, &ivi->surfaces, link) {
2006 if (surf->orientation > AGL_SHELL_TILE_ORIENTATION_NONE)
2015 void shell_set_app_split(struct wl_client *client, struct wl_resource *res,
2016 const char *app_id, uint32_t orientation, int32_t width,
2017 int32_t sticky, struct wl_resource *output_res)
2019 struct ivi_surface *surf;
2020 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2022 struct weston_head *head = weston_head_from_resource(output_res);
2023 struct weston_output *woutput = weston_head_get_output(head);
2024 struct ivi_output *output = to_ivi_output(woutput);
2029 if (shell_ivi_surf_count_split_surfaces(ivi) > 2) {
2030 weston_log("Found more than two split surfaces in tile orientation.\n");
2034 /* add it as pending until */
2035 surf = ivi_find_app(ivi, app_id);
2037 _ivi_set_pending_desktop_surface_split(output_res, app_id, orientation);
2041 if (output->previous_active && output->background != output->previous_active) {
2042 int width_prev_app = 0;
2043 struct weston_view *ev = output->previous_active->view;
2044 const char *prev_app_id =
2045 weston_desktop_surface_get_app_id(output->previous_active->dsurface);
2047 if (orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
2048 if (!weston_view_is_mapped(ev))
2049 weston_view_update_transform(ev);
2051 weston_layer_entry_remove(&ev->layer_link);
2053 ev->is_mapped = true;
2054 ev->surface->is_mapped = true;
2055 output->previous_active->mapped = true;
2057 weston_view_set_output(ev, woutput);
2058 weston_layer_entry_insert(&ivi->normal.view_list,
2061 ev->is_mapped = false;
2062 ev->surface->is_mapped = false;
2064 weston_layer_entry_remove(&ev->layer_link);
2066 weston_view_geometry_dirty(ev);
2067 weston_surface_damage(ev->surface);
2070 /* a 0 width means we have no explicit width set-up */
2072 if (orientation == AGL_SHELL_TILE_ORIENTATION_TOP ||
2073 orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
2074 width_prev_app = output->area.height - width;
2076 width_prev_app = output->area.width - width;
2079 weston_log("Setting previous application '%s' to orientation '%s' width %d, not sticky\n",
2080 prev_app_id, split_orientation_to_string(reverse_orientation(orientation)),
2083 _ivi_set_shell_surface_split(output->previous_active, NULL,
2084 reverse_orientation(orientation),
2085 width_prev_app, false, false);
2087 if (orientation == AGL_SHELL_TILE_ORIENTATION_NONE &&
2088 output->active == surf) {
2089 output->active = output->previous_active;
2093 weston_log("Setting application '%s' to orientation '%s' width %d, %s\n",
2094 app_id, split_orientation_to_string(orientation),
2095 width, sticky == 1 ? "sticky" : "not sticky");
2096 _ivi_set_shell_surface_split(surf, NULL, orientation, width, sticky, false);
2100 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
2102 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2104 ivi->shell_client_ext.doas_requested = false;
2105 wl_resource_destroy(res);
2109 shell_ext_doas(struct wl_client *client, struct wl_resource *res)
2111 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
2113 ivi->shell_client_ext.doas_requested = true;
2115 if (ivi->shell_client_ext.resource && ivi->shell_client.resource) {
2116 ivi->shell_client_ext.doas_requested_pending_bind = true;
2118 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
2119 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS);
2121 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
2122 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_FAILED);
2127 static const struct agl_shell_interface agl_shell_implementation = {
2128 .ready = shell_ready,
2129 .set_background = shell_set_background,
2130 .set_panel = shell_set_panel,
2131 .activate_app = shell_activate_app,
2132 .destroy = shell_destroy,
2133 .set_activate_region = shell_set_activate_region,
2134 .deactivate_app = shell_new_deactivate_app,
2135 .set_app_float = shell_set_app_float,
2136 .set_app_normal = shell_set_app_normal,
2137 .set_app_fullscreen = shell_set_app_fullscreen,
2138 .set_app_output = shell_set_app_output,
2139 .set_app_position = shell_set_app_position,
2140 .set_app_scale = shell_set_app_scale,
2141 .set_app_split = shell_set_app_split,
2144 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
2145 .destroy = shell_ext_destroy,
2146 .doas_shell_client = shell_ext_doas,
2150 shell_desktop_set_app_property(struct wl_client *client,
2151 struct wl_resource *shell_res,
2152 const char *app_id, uint32_t role,
2153 int x, int y, int bx, int by,
2154 int width, int height,
2155 struct wl_resource *output_res)
2157 struct weston_head *head = weston_head_from_resource(output_res);
2158 struct weston_output *woutput = weston_head_get_output(head);
2159 struct ivi_output *output = to_ivi_output(woutput);
2162 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
2163 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
2164 width, height, app_id);
2166 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
2167 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
2169 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
2170 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
2171 ivi_set_pending_desktop_surface_split(output, app_id, role);
2173 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
2174 ivi_set_pending_desktop_surface_remote(output, app_id);
2182 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
2184 struct pending_popup *p_popup, *next_p_popup;
2185 struct pending_split *split_surf, *next_split_surf;
2186 struct pending_fullscreen *fs_surf, *next_fs_surf;
2187 struct pending_remote *remote_surf, *next_remote_surf;
2189 wl_list_for_each_safe(p_popup, next_p_popup,
2190 &ivi->popup_pending_apps, link)
2191 ivi_remove_pending_desktop_surface_popup(p_popup);
2193 wl_list_for_each_safe(split_surf, next_split_surf,
2194 &ivi->split_pending_apps, link)
2195 ivi_remove_pending_desktop_surface_split(split_surf);
2197 wl_list_for_each_safe(fs_surf, next_fs_surf,
2198 &ivi->fullscreen_pending_apps, link)
2199 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
2201 wl_list_for_each_safe(remote_surf, next_remote_surf,
2202 &ivi->remote_pending_apps, link)
2203 ivi_remove_pending_desktop_surface_remote(remote_surf);
2207 shell_desktop_set_app_property_mode(struct wl_client *client,
2208 struct wl_resource *shell_res, uint32_t perm)
2210 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
2212 dclient->ivi->keep_pending_surfaces = true;
2214 dclient->ivi->keep_pending_surfaces = false;
2215 /* remove any previous pending surfaces */
2216 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
2220 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
2221 .activate_app = shell_desktop_activate_app,
2222 .set_app_property = shell_desktop_set_app_property,
2223 .deactivate_app = shell_deactivate_app,
2224 .set_app_property_mode = shell_desktop_set_app_property_mode,
2228 unbind_agl_shell(struct wl_resource *resource)
2230 struct ivi_compositor *ivi;
2231 struct ivi_output *output;
2232 struct ivi_surface *surf, *surf_tmp;
2234 ivi = wl_resource_get_user_data(resource);
2236 /* reset status to allow other clients issue legit requests */
2237 if (wl_resource_get_version(resource) >=
2238 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
2239 ivi->shell_client.status == BOUND_FAILED) {
2240 ivi->shell_client.status = BOUND_OK;
2244 wl_list_for_each(output, &ivi->outputs, link) {
2246 /* reset the active surf if there's one present */
2247 if (output->active) {
2248 struct weston_geometry area = {};
2250 output->active->view->is_mapped = false;
2251 output->active->view->surface->is_mapped = false;
2253 weston_layer_entry_remove(&output->active->view->layer_link);
2254 output->active = NULL;
2256 output->area_activation = area;
2259 insert_black_curtain(output);
2262 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
2263 wl_list_remove(&surf->link);
2264 wl_list_init(&surf->link);
2267 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
2268 wl_list_remove(&surf->link);
2269 wl_list_init(&surf->link);
2272 wl_list_init(&ivi->surfaces);
2273 wl_list_init(&ivi->pending_surfaces);
2275 ivi->shell_client.ready = false;
2276 ivi->shell_client.resource = NULL;
2277 ivi->shell_client.resource_ext = NULL;
2278 ivi->shell_client.client = NULL;
2282 unbind_agl_shell_ext(struct wl_resource *resource)
2284 struct ivi_compositor *ivi = wl_resource_get_user_data(resource);
2286 ivi->shell_client_ext.resource = NULL;
2287 ivi->shell_client.resource_ext = NULL;
2288 ivi->shell_client_ext.doas_requested = false;
2292 bind_agl_shell(struct wl_client *client,
2293 void *data, uint32_t version, uint32_t id)
2295 struct ivi_compositor *ivi = data;
2296 struct wl_resource *resource;
2297 struct ivi_policy *policy;
2300 policy = ivi->policy;
2301 interface = (void *) &agl_shell_interface;
2302 if (policy && policy->api.shell_bind_interface &&
2303 !policy->api.shell_bind_interface(client, interface)) {
2304 wl_client_post_implementation_error(client,
2305 "client not authorized to use agl_shell");
2309 resource = wl_resource_create(client, &agl_shell_interface, version, id);
2311 wl_client_post_no_memory(client);
2315 if (ivi->shell_client.resource && wl_resource_get_version(resource) == 1) {
2316 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2317 "agl_shell has already been bound (version 1)");
2318 wl_resource_destroy(resource);
2322 // for agl_shell client proxy
2323 if (ivi->shell_client.resource &&
2324 ivi->shell_client_ext.doas_requested_pending_bind) {
2326 ivi->shell_client_ext.doas_requested_pending_bind = false;
2328 // if there's one connected
2329 if (ivi->shell_client.resource_ext) {
2330 ivi->shell_client_ext.status = BOUND_FAILED;
2331 agl_shell_send_bound_fail(ivi->shell_client.resource_ext);
2332 wl_resource_destroy(resource);
2336 wl_resource_set_implementation(resource, &agl_shell_implementation,
2338 ivi->shell_client.resource_ext = resource;
2339 ivi->shell_client_ext.status = BOUND_OK;
2340 agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
2345 // if we already have an agl_shell client
2346 if (ivi->shell_client.resource) {
2347 agl_shell_send_bound_fail(resource);
2348 ivi->shell_client.status = BOUND_FAILED;
2349 wl_resource_destroy(resource);
2353 // default agl_shell client
2354 wl_resource_set_implementation(resource, &agl_shell_implementation,
2355 ivi, unbind_agl_shell);
2356 ivi->shell_client.resource = resource;
2358 if (wl_resource_get_version(resource) >=
2359 AGL_SHELL_BOUND_OK_SINCE_VERSION) {
2360 /* if we land here we'll have BOUND_OK by default,
2361 but still do the assignment */
2362 ivi->shell_client.status = BOUND_OK;
2363 agl_shell_send_bound_ok(ivi->shell_client.resource);
2368 bind_agl_shell_ext(struct wl_client *client,
2369 void *data, uint32_t version, uint32_t id)
2371 struct ivi_compositor *ivi = data;
2372 struct wl_resource *resource;
2374 resource = wl_resource_create(client, &agl_shell_ext_interface, version, id);
2376 wl_client_post_no_memory(client);
2380 if (ivi->shell_client_ext.resource) {
2381 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2382 "agl_shell_ext has already been bound");
2386 wl_resource_set_implementation(resource, &agl_shell_ext_implementation,
2387 ivi, unbind_agl_shell_ext);
2388 ivi->shell_client_ext.resource = resource;
2392 unbind_agl_shell_desktop(struct wl_resource *resource)
2394 struct desktop_client *dclient = wl_resource_get_user_data(resource);
2396 wl_list_remove(&dclient->link);
2401 bind_agl_shell_desktop(struct wl_client *client,
2402 void *data, uint32_t version, uint32_t id)
2404 struct ivi_compositor *ivi = data;
2405 struct wl_resource *resource;
2406 struct ivi_policy *policy;
2407 struct desktop_client *dclient;
2410 policy = ivi->policy;
2411 interface = (void *) &agl_shell_desktop_interface;
2412 if (policy && policy->api.shell_bind_interface &&
2413 !policy->api.shell_bind_interface(client, interface)) {
2414 wl_client_post_implementation_error(client,
2415 "client not authorized to use agl_shell_desktop");
2419 dclient = zalloc(sizeof(*dclient));
2421 wl_client_post_no_memory(client);
2425 resource = wl_resource_create(client, &agl_shell_desktop_interface,
2429 wl_client_post_no_memory(client);
2433 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
2434 dclient, unbind_agl_shell_desktop);
2436 dclient->resource = resource;
2437 wl_list_insert(&ivi->desktop_clients, &dclient->link);
2439 /* advertise xdg surfaces */
2440 ivi_shell_advertise_xdg_surfaces(ivi, resource);
2444 ivi_shell_create_global(struct ivi_compositor *ivi)
2446 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
2447 &agl_shell_interface, 11,
2448 ivi, bind_agl_shell);
2449 if (!ivi->agl_shell) {
2450 weston_log("Failed to create wayland global.\n");
2454 ivi->agl_shell_ext = wl_global_create(ivi->compositor->wl_display,
2455 &agl_shell_ext_interface, 1,
2456 ivi, bind_agl_shell_ext);
2457 if (!ivi->agl_shell_ext) {
2458 weston_log("Failed to create agl_shell_ext global.\n");
2462 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
2463 &agl_shell_desktop_interface, 2,
2464 ivi, bind_agl_shell_desktop);
2465 if (!ivi->agl_shell_desktop) {
2466 weston_log("Failed to create wayland global (agl_shell_desktop).\n");