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>
41 #include <weston/weston.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 #include <waltham-transmitter/transmitter_api.h>
54 create_black_curtain_view(struct ivi_output *output);
57 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
58 struct ivi_surface *surface)
60 struct desktop_client *dclient;
61 static bool display_adv = false;
63 if (surface->advertised_on_launch)
66 /* advertise to all desktop clients the new surface */
67 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
69 weston_desktop_surface_get_app_id(surface->dsurface);
72 weston_log("WARNING app_is is null, unable to advertise\n");
77 agl_shell_desktop_send_application(dclient->resource, app_id);
78 surface->advertised_on_launch = true;
83 ivi_set_desktop_surface(struct ivi_surface *surface)
85 struct ivi_compositor *ivi = surface->ivi;
86 assert(surface->role == IVI_SURFACE_ROLE_NONE);
88 surface->role = IVI_SURFACE_ROLE_DESKTOP;
89 wl_list_insert(&surface->ivi->surfaces, &surface->link);
91 agl_shell_desktop_advertise_application_id(ivi, surface);
95 ivi_set_background_surface(struct ivi_surface *surface)
97 struct ivi_compositor *ivi = surface->ivi;
98 assert(surface->role == IVI_SURFACE_ROLE_BACKGROUND);
100 wl_list_insert(&surface->ivi->surfaces, &surface->link);
101 agl_shell_desktop_advertise_application_id(ivi, surface);
105 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
107 struct ivi_compositor *ivi = surface->ivi;
108 assert(surface->role == IVI_SURFACE_ROLE_NONE);
110 surface->role = IVI_SURFACE_ROLE_POPUP;
111 wl_list_insert(&ivi->surfaces, &surface->link);
113 agl_shell_desktop_advertise_application_id(ivi, surface);
117 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
119 struct ivi_compositor *ivi = surface->ivi;
120 assert(surface->role == IVI_SURFACE_ROLE_NONE);
122 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
123 wl_list_insert(&ivi->surfaces, &surface->link);
125 agl_shell_desktop_advertise_application_id(ivi, surface);
130 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
132 struct ivi_compositor *ivi = surface->ivi;
133 const struct weston_transmitter_api *api =
134 ivi->waltham_transmitter_api;
139 if (surface->waltham_surface.transmitter_surface)
140 api->surface_destroy(surface->waltham_surface.transmitter_surface);
144 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
146 struct ivi_compositor *ivi = surface->ivi;
147 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
148 struct weston_transmitter *transmitter;
149 struct weston_transmitter_remote *trans_remote;
150 struct weston_surface *weston_surface;
151 struct weston_output *woutput = surface->remote.output->output;
157 transmitter = api->transmitter_get(ivi->compositor);
161 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
163 weston_log("Could not find a valie weston_transmitter_remote "
164 "that matches the output %s\n", woutput->name);
168 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
170 weston_desktop_surface_get_surface(surface->dsurface);
172 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
174 /* this will have the effect of informing the remote side to create a
175 * surface with the name app_id. W/ xdg-shell the following happens:
177 * compositor (server):
178 * surface_push_to_remote():
179 * waltham-transmitter plug-in
180 * -> wthp_ivi_app_id_surface_create()
182 * client -- on the receiver side:
183 * -> wthp_ivi_app_id_surface_create()
184 * -> wth_receiver_weston_main()
185 * -> wl_compositor_create_surface()
186 * -> xdg_wm_base_get_xdg_surface
187 * -> xdg_toplevel_set_app_id()
189 * -> gst_parse_launch()
191 * wth_receiver_weston_main() will be invoked from the handler of
192 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
193 * the gstreamer pipeline as well.
195 surface->waltham_surface.transmitter_surface =
196 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
201 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
205 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
211 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
213 struct ivi_compositor *ivi = surface->ivi;
214 struct weston_view *view;
215 struct ivi_output *output = surface->remote.output;
217 assert(surface->role == IVI_SURFACE_ROLE_NONE);
219 /* remote type are the same as desktop just that client can tell
220 * the compositor to start on another output */
221 surface->role = IVI_SURFACE_ROLE_REMOTE;
223 /* if thew black surface view is mapped on the mean we need
224 * to remove it in order to start showing the 'remote' surface
225 * just being added */
226 view = output->fullscreen_view.fs->view;
227 if (view->is_mapped || view->surface->is_mapped)
228 remove_black_curtain(output);
230 if (output->type == OUTPUT_WALTHAM)
231 ivi_output_notify_waltham_plugin(surface);
233 wl_list_insert(&ivi->surfaces, &surface->link);
238 ivi_set_desktop_surface_split(struct ivi_surface *surface)
240 struct ivi_compositor *ivi = surface->ivi;
241 assert(surface->role == IVI_SURFACE_ROLE_NONE);
243 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
244 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
246 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
248 wl_list_insert(&ivi->surfaces, &surface->link);
250 agl_shell_desktop_advertise_application_id(ivi, surface);
253 static struct pending_popup *
254 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
255 int width, int height, const char *app_id)
257 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
258 size_t len_app_id = strlen(app_id);
262 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
263 if (!p_popup->app_id) {
267 memcpy(p_popup->app_id, app_id, len_app_id);
268 p_popup->ioutput = ioutput;
274 p_popup->bb.width = width;
275 p_popup->bb.height = height;
281 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
282 int width, int height, const char *app_id, struct pending_popup *p_popup)
284 size_t len_app_id = strlen(app_id);
286 wl_list_remove(&p_popup->link);
287 wl_list_init(&p_popup->link);
289 memset(p_popup->app_id, 0, strlen(app_id) + 1);
290 free(p_popup->app_id);
292 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
293 if (!p_popup->app_id)
295 memcpy(p_popup->app_id, app_id, len_app_id);
297 p_popup->ioutput = ioutput;
303 p_popup->bb.width = width;
304 p_popup->bb.height = height;
307 static struct pending_fullscreen *
308 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
310 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
311 size_t len_app_id = strlen(app_id);
315 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
316 if (!p_fullscreen->app_id) {
320 memcpy(p_fullscreen->app_id, app_id, len_app_id);
322 p_fullscreen->ioutput = ioutput;
327 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
328 struct pending_fullscreen *p_fullscreen)
330 size_t len_app_id = strlen(app_id);
332 wl_list_remove(&p_fullscreen->link);
333 wl_list_init(&p_fullscreen->link);
335 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
336 free(p_fullscreen->app_id);
338 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
339 if (!p_fullscreen->app_id)
341 memcpy(p_fullscreen->app_id, app_id, len_app_id);
343 p_fullscreen->ioutput = ioutput;
346 static struct pending_remote *
347 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
349 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
350 size_t len_app_id = strlen(app_id);
354 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
355 if (!p_remote->app_id) {
359 memcpy(p_remote->app_id, app_id, len_app_id);
361 p_remote->ioutput = ioutput;
366 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
367 struct pending_remote *p_remote)
369 size_t len_app_id = strlen(app_id);
371 wl_list_remove(&p_remote->link);
372 wl_list_init(&p_remote->link);
374 memset(p_remote->app_id, 0, strlen(app_id) + 1);
375 free(p_remote->app_id);
377 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
378 if (!p_remote->app_id)
380 memcpy(p_remote->app_id, app_id, len_app_id);
382 p_remote->ioutput = ioutput;
386 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
387 int by, int width, int height, const char *app_id)
389 struct ivi_compositor *ivi = ioutput->ivi;
390 struct pending_popup *p_popup = NULL;
391 struct pending_popup *popup;
393 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
394 if (!strcmp(app_id, popup->app_id))
398 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
400 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
404 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
408 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
411 struct ivi_compositor *ivi = ioutput->ivi;
412 struct pending_fullscreen *p_fullscreen = NULL;
413 struct pending_fullscreen *fullscreen;
415 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
416 if (!strcmp(app_id, fullscreen->app_id))
417 p_fullscreen = fullscreen;
420 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
422 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
426 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
430 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
431 const char *app_id, uint32_t orientation)
433 struct ivi_compositor *ivi = ioutput->ivi;
434 struct ivi_surface *surf;
435 size_t len_app_id = strlen(app_id);
436 struct pending_split *split;
438 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
439 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
442 /* more than one is un-supported, do note we need to do
443 * conversion for surface roles instead of using the protocol ones */
444 wl_list_for_each(surf, &ivi->surfaces, link)
445 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
446 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
449 split = zalloc(sizeof(*split));
452 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
453 if (!split->app_id) {
457 memcpy(split->app_id, app_id, len_app_id);
459 split->ioutput = ioutput;
460 split->orientation = orientation;
462 wl_list_insert(&ivi->split_pending_apps, &split->link);
466 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
469 struct ivi_compositor *ivi = ioutput->ivi;
470 struct pending_remote *remote;
471 struct pending_remote *p_remote = NULL;
473 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
474 if (!strcmp(app_id, remote->app_id))
478 p_remote = ivi_ensure_remote(ioutput, app_id);
480 ivi_update_remote(ioutput, app_id, p_remote);
484 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
489 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
492 wl_list_remove(&split->link);
497 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
500 wl_list_remove(&fs->link);
505 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
507 free(p_popup->app_id);
508 wl_list_remove(&p_popup->link);
513 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
515 free(remote->app_id);
516 wl_list_remove(&remote->link);
521 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
523 return surface->ivi->keep_pending_surfaces;
527 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
529 struct ivi_compositor *ivi = surface->ivi;
530 struct pending_popup *p_popup, *next_p_popup;
531 const char *_app_id =
532 weston_desktop_surface_get_app_id(surface->dsurface);
534 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
537 wl_list_for_each_safe(p_popup, next_p_popup,
538 &ivi->popup_pending_apps, link) {
539 if (!strcmp(_app_id, p_popup->app_id)) {
540 surface->popup.output = p_popup->ioutput;
541 surface->popup.x = p_popup->x;
542 surface->popup.y = p_popup->y;
544 surface->popup.bb.x = p_popup->bb.x;
545 surface->popup.bb.y = p_popup->bb.y;
546 surface->popup.bb.width = p_popup->bb.width;
547 surface->popup.bb.height = p_popup->bb.height;
549 if (!ivi_compositor_keep_pending_surfaces(surface))
550 ivi_remove_pending_desktop_surface_popup(p_popup);
559 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
561 struct pending_split *split_surf, *next_split_surf;
562 struct ivi_compositor *ivi = surface->ivi;
563 const char *_app_id =
564 weston_desktop_surface_get_app_id(surface->dsurface);
566 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
569 wl_list_for_each_safe(split_surf, next_split_surf,
570 &ivi->split_pending_apps, link) {
571 if (!strcmp(_app_id, split_surf->app_id)) {
572 surface->split.output = split_surf->ioutput;
573 surface->split.orientation = split_surf->orientation;
574 if (!ivi_compositor_keep_pending_surfaces(surface))
575 ivi_remove_pending_desktop_surface_split(split_surf);
584 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
586 struct pending_fullscreen *fs_surf, *next_fs_surf;
587 struct ivi_compositor *ivi = surface->ivi;
588 const char *_app_id =
589 weston_desktop_surface_get_app_id(surface->dsurface);
591 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
594 wl_list_for_each_safe(fs_surf, next_fs_surf,
595 &ivi->fullscreen_pending_apps, link) {
596 if (!strcmp(_app_id, fs_surf->app_id)) {
597 surface->fullscreen.output = fs_surf->ioutput;
598 if (!ivi_compositor_keep_pending_surfaces(surface))
599 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
608 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
610 struct pending_remote *remote_surf, *next_remote_surf;
611 struct ivi_compositor *ivi = surface->ivi;
612 const char *_app_id =
613 weston_desktop_surface_get_app_id(surface->dsurface);
615 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
618 wl_list_for_each_safe(remote_surf, next_remote_surf,
619 &ivi->remote_pending_apps, link) {
620 if (!strcmp(_app_id, remote_surf->app_id)) {
621 surface->remote.output = remote_surf->ioutput;
622 if (!ivi_compositor_keep_pending_surfaces(surface))
623 ivi_remove_pending_desktop_surface_remote(remote_surf);
631 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
632 enum ivi_surface_role *role)
634 struct ivi_compositor *ivi = surface->ivi;
635 struct wl_list *role_pending_list;
636 struct pending_popup *p_popup;
637 struct pending_split *p_split;
638 struct pending_fullscreen *p_fullscreen;
639 struct pending_remote *p_remote;
641 weston_desktop_surface_get_app_id(surface->dsurface);
643 role_pending_list = &ivi->popup_pending_apps;
644 wl_list_for_each(p_popup, role_pending_list, link) {
645 if (app_id && !strcmp(app_id, p_popup->app_id)) {
646 *role = IVI_SURFACE_ROLE_POPUP;
651 role_pending_list = &ivi->split_pending_apps;
652 wl_list_for_each(p_split, role_pending_list, link) {
653 if (app_id && !strcmp(app_id, p_split->app_id)) {
654 *role = IVI_SURFACE_ROLE_SPLIT_V;
659 role_pending_list = &ivi->fullscreen_pending_apps;
660 wl_list_for_each(p_fullscreen, role_pending_list, link) {
661 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
662 *role = IVI_SURFACE_ROLE_FULLSCREEN;
667 role_pending_list = &ivi->remote_pending_apps;
668 wl_list_for_each(p_remote, role_pending_list, link) {
669 if (app_id && !strcmp(app_id, p_remote->app_id)) {
670 *role = IVI_SURFACE_ROLE_REMOTE;
675 /* else, we are a regular desktop surface */
676 *role = IVI_SURFACE_ROLE_DESKTOP;
681 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
685 ret = ivi_check_pending_desktop_surface_popup(surface);
687 ivi_set_desktop_surface_popup(surface);
688 ivi_layout_popup_committed(surface);
692 ret = ivi_check_pending_desktop_surface_split(surface);
694 ivi_set_desktop_surface_split(surface);
695 ivi_layout_split_committed(surface);
699 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
701 ivi_set_desktop_surface_fullscreen(surface);
702 ivi_layout_fullscreen_committed(surface);
706 ret = ivi_check_pending_desktop_surface_remote(surface);
708 ivi_set_desktop_surface_remote(surface);
709 ivi_layout_desktop_committed(surface);
713 /* if we end up here means we have a regular desktop app and
714 * try to activate it */
715 ivi_set_desktop_surface(surface);
716 ivi_layout_desktop_committed(surface);
720 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
722 struct ivi_output *out;
724 wl_list_for_each(out, &ivi->outputs, link) {
725 create_black_curtain_view(out);
726 insert_black_curtain(out);
731 ivi_shell_init(struct ivi_compositor *ivi)
733 weston_layer_init(&ivi->hidden, ivi->compositor);
734 weston_layer_init(&ivi->background, ivi->compositor);
735 weston_layer_init(&ivi->normal, ivi->compositor);
736 weston_layer_init(&ivi->panel, ivi->compositor);
737 weston_layer_init(&ivi->popup, ivi->compositor);
738 weston_layer_init(&ivi->fullscreen, ivi->compositor);
740 weston_layer_set_position(&ivi->hidden,
741 WESTON_LAYER_POSITION_HIDDEN);
742 weston_layer_set_position(&ivi->background,
743 WESTON_LAYER_POSITION_BACKGROUND);
744 weston_layer_set_position(&ivi->normal,
745 WESTON_LAYER_POSITION_NORMAL);
746 weston_layer_set_position(&ivi->panel,
747 WESTON_LAYER_POSITION_UI);
748 weston_layer_set_position(&ivi->popup,
749 WESTON_LAYER_POSITION_TOP_UI);
750 weston_layer_set_position(&ivi->fullscreen,
751 WESTON_LAYER_POSITION_FULLSCREEN);
758 ivi_surf_destroy(struct ivi_surface *surf)
760 struct weston_surface *wsurface = surf->view->surface;
762 if (weston_surface_is_mapped(wsurface)) {
763 weston_desktop_surface_unlink_view(surf->view);
764 weston_view_destroy(surf->view);
767 wl_list_remove(&surf->link);
772 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
774 struct weston_view *view, *view_next;
776 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
777 struct ivi_surface *ivi_surf =
778 get_ivi_shell_surface(view->surface);
780 ivi_surf_destroy(ivi_surf);
785 ivi_shell_finalize(struct ivi_compositor *ivi)
787 struct ivi_output *output;
789 ivi_shell_destroy_views_on_layer(&ivi->hidden);
790 weston_layer_fini(&ivi->hidden);
792 ivi_shell_destroy_views_on_layer(&ivi->background);
793 weston_layer_fini(&ivi->background);
795 ivi_shell_destroy_views_on_layer(&ivi->normal);
796 weston_layer_fini(&ivi->normal);
798 ivi_shell_destroy_views_on_layer(&ivi->panel);
799 weston_layer_fini(&ivi->panel);
801 ivi_shell_destroy_views_on_layer(&ivi->popup);
802 weston_layer_fini(&ivi->popup);
804 wl_list_for_each(output, &ivi->outputs, link) {
805 if (output->fullscreen_view.fs->view) {
806 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
807 output->fullscreen_view.fs->view = NULL;
810 weston_layer_fini(&ivi->fullscreen);
814 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
816 struct ivi_surface *surface;
818 wl_list_for_each(surface, &ivi->surfaces, link) {
820 weston_desktop_surface_get_app_id(surface->dsurface);
821 if (app_id == NULL) {
822 weston_log("WARNING app_is is null, unable to advertise\n");
825 agl_shell_desktop_send_application(resource, app_id);
829 static struct wl_client *
830 client_launch(struct weston_compositor *compositor,
831 struct weston_process *proc,
833 weston_process_cleanup_func_t cleanup)
835 struct wl_client *client = NULL;
836 struct custom_env child_env;
837 struct fdstr wayland_socket;
838 const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket";
839 const char *fail_seteuid = "Couldn't call seteuid";
846 struct ivi_compositor *ivi;
847 size_t written __attribute__((unused));
849 weston_log("launching '%s'\n", path);
850 str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
852 custom_env_init_from_environ(&child_env);
853 custom_env_add_from_exec_string(&child_env, path);
855 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
856 wayland_socket.fds) < 0) {
857 weston_log("client_launch: "
858 "socketpair failed while launching '%s': %s\n",
859 path, strerror(errno));
860 custom_env_fini(&child_env);
863 fdstr_update_str1(&wayland_socket);
864 custom_env_set_env_var(&child_env, "WAYLAND_SOCKET",
865 wayland_socket.str1);
867 argp = custom_env_get_argp(&child_env);
868 envp = custom_env_get_envp(&child_env);
873 /* Put the client in a new session so it won't catch signals
874 * intended for the parent. Sharing a session can be
875 * confusing when launching weston under gdb, as the ctrl-c
876 * intended for gdb will pass to the child, and weston
877 * will cleanly shut down when the child exits.
881 /* do not give our signal mask to the new process */
882 sigfillset(&allsigs);
883 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
885 /* Launch clients as the user. Do not launch clients with wrong euid. */
886 if (seteuid(getuid()) == -1) {
887 written = write(STDERR_FILENO, fail_seteuid, strlen(fail_seteuid));
891 ret = fdstr_clear_cloexec_fd1(&wayland_socket);
893 written = write(STDERR_FILENO, fail_cloexec, strlen(fail_cloexec));
897 execve(argp[0], argp, envp);
900 written = write(STDERR_FILENO, fail_exec, strlen(fail_exec));
904 close(wayland_socket.fds[1]);
905 ivi = weston_compositor_get_user_data(compositor);
906 client = wl_client_create(compositor->wl_display,
907 wayland_socket.fds[0]);
909 custom_env_fini(&child_env);
910 close(wayland_socket.fds[0]);
912 weston_log("client_launch: "
913 "wl_client_create failed while launching '%s'.\n",
919 proc->cleanup = cleanup;
920 wl_list_insert(&ivi->child_process_list, &proc->link);
924 fdstr_close_all(&wayland_socket);
925 weston_log("client_launch: "
926 "fork failed while launching '%s': %s\n", path,
931 custom_env_fini(&child_env);
937 struct process_info {
938 struct weston_process proc;
943 sigchld_handler(int signal_number, void *data)
945 struct weston_process *p;
946 struct ivi_compositor *ivi = data;
950 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
951 wl_list_for_each(p, &ivi->child_process_list, link) {
956 if (&p->link == &ivi->child_process_list) {
957 weston_log("unknown child process exited\n");
961 wl_list_remove(&p->link);
962 wl_list_init(&p->link);
963 p->cleanup(p, status);
966 if (pid < 0 && errno != ECHILD)
967 weston_log("waitpid error %s\n", strerror(errno));
974 process_handle_sigchld(struct weston_process *process, int status)
976 struct process_info *pinfo =
977 container_of(process, struct process_info, proc);
980 * There are no guarantees whether this runs before or after
981 * the wl_client destructor.
984 if (WIFEXITED(status)) {
985 weston_log("%s exited with status %d\n", pinfo->path,
986 WEXITSTATUS(status));
987 } else if (WIFSIGNALED(status)) {
988 weston_log("%s died on signal %d\n", pinfo->path,
991 weston_log("%s disappeared\n", pinfo->path);
999 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section,
1000 struct wl_client **client)
1002 struct process_info *pinfo;
1003 struct weston_config_section *section;
1004 char *command = NULL;
1006 section = weston_config_get_section(ivi->config, cmd_section, NULL, NULL);
1008 weston_config_section_get_string(section, "command", &command, NULL);
1013 pinfo = zalloc(sizeof *pinfo);
1017 pinfo->path = strdup(command);
1021 *client = client_launch(ivi->compositor, &pinfo->proc, command, process_handle_sigchld);
1037 destroy_black_curtain_view(struct wl_listener *listener, void *data)
1039 struct fullscreen_view *fs =
1040 wl_container_of(listener, fs, fs_destroy);
1044 wl_list_remove(&fs->fs_destroy.link);
1051 create_black_curtain_view(struct ivi_output *output)
1053 struct weston_surface *surface = NULL;
1054 struct weston_view *view;
1055 struct ivi_compositor *ivi = output->ivi;
1056 struct weston_compositor *wc= ivi->compositor;
1057 struct weston_output *woutput = output->output;
1062 surface = weston_surface_create(wc);
1065 view = weston_view_create(surface);
1067 weston_surface_destroy(surface);
1071 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1072 weston_surface_set_size(surface, woutput->width, woutput->height);
1073 weston_view_set_position(view, woutput->x, woutput->y);
1075 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
1076 if (!output->fullscreen_view.fs) {
1077 weston_surface_destroy(surface);
1080 output->fullscreen_view.fs->view = view;
1082 output->fullscreen_view.fs_destroy.notify = destroy_black_curtain_view;
1083 wl_signal_add(&woutput->destroy_signal,
1084 &output->fullscreen_view.fs_destroy);
1088 output_has_black_curtain(struct ivi_output *output)
1090 return (output->fullscreen_view.fs->view &&
1091 output->fullscreen_view.fs->view->is_mapped &&
1092 output->fullscreen_view.fs->view->surface->is_mapped);
1096 remove_black_curtain(struct ivi_output *output)
1098 struct weston_view *view;
1101 !output->fullscreen_view.fs &&
1102 !output->fullscreen_view.fs->view) {
1103 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1107 view = output->fullscreen_view.fs->view;
1108 assert(view->is_mapped == true ||
1109 view->surface->is_mapped == true);
1111 view->is_mapped = false;
1112 view->surface->is_mapped = false;
1114 weston_layer_entry_remove(&view->layer_link);
1115 weston_view_update_transform(view);
1117 weston_view_damage_below(view);
1119 weston_log("Removed black curtain from output %s\n", output->output->name);
1123 insert_black_curtain(struct ivi_output *output)
1125 struct weston_view *view;
1128 !output->fullscreen_view.fs &&
1129 !output->fullscreen_view.fs->view) || !output->output) {
1130 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1134 view = output->fullscreen_view.fs->view;
1135 if (view->is_mapped || view->surface->is_mapped)
1138 weston_layer_entry_remove(&view->layer_link);
1139 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1142 view->is_mapped = true;
1143 view->surface->is_mapped = true;
1145 weston_view_update_transform(view);
1146 weston_view_damage_below(view);
1148 weston_log("Added black curtain to output %s\n", output->output->name);
1152 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1154 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1155 struct ivi_output *output;
1156 struct ivi_surface *surface, *tmp;
1158 if (ivi->shell_client.resource &&
1159 ivi->shell_client.status == BOUND_FAILED) {
1160 wl_resource_post_error(shell_res,
1161 WL_DISPLAY_ERROR_INVALID_OBJECT,
1162 "agl_shell has already been bound. "
1163 "Check out bound_fail event");
1167 /* Init already finished. Do nothing */
1168 if (ivi->shell_client.ready)
1172 ivi->shell_client.ready = true;
1174 wl_list_for_each(output, &ivi->outputs, link) {
1175 if (output->background &&
1176 output->background->role == IVI_SURFACE_ROLE_BACKGROUND) {
1177 /* track the background surface role as a "regular"
1178 * surface so we can activate it */
1179 ivi_set_background_surface(output->background);
1180 remove_black_curtain(output);
1183 ivi_layout_init(ivi, output);
1186 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1189 wl_list_remove(&surface->link);
1190 wl_list_init(&surface->link);
1191 ivi_check_pending_desktop_surface(surface);
1192 surface->checked_pending = true;
1193 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1196 wl_resource_get_version(ivi->shell_client.resource) >=
1197 AGL_SHELL_APP_STATE_SINCE_VERSION)
1198 agl_shell_send_app_state(ivi->shell_client.resource,
1199 app_id, AGL_SHELL_APP_STATE_STARTED);
1204 shell_set_background(struct wl_client *client,
1205 struct wl_resource *shell_res,
1206 struct wl_resource *surface_res,
1207 struct wl_resource *output_res)
1209 struct weston_head *head = weston_head_from_resource(output_res);
1210 struct weston_output *woutput = weston_head_get_output(head);
1211 struct ivi_output *output = to_ivi_output(woutput);
1212 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1213 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1214 struct weston_desktop_surface *dsurface;
1215 struct ivi_surface *surface;
1217 if ((ivi->shell_client.resource &&
1218 ivi->shell_client.status == BOUND_FAILED) ||
1219 ivi->shell_client.resource_ext == shell_res) {
1220 wl_resource_post_error(shell_res,
1221 WL_DISPLAY_ERROR_INVALID_OBJECT,
1222 "agl_shell has already been bound. "
1223 "Check out bound_fail event");
1227 dsurface = weston_surface_get_desktop_surface(wsurface);
1229 wl_resource_post_error(shell_res,
1230 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1231 "surface must be a desktop surface");
1235 surface = weston_desktop_surface_get_user_data(dsurface);
1236 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1237 wl_resource_post_error(shell_res,
1238 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1239 "surface already has another ivi role");
1243 if (output->background) {
1244 wl_resource_post_error(shell_res,
1245 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1246 "output already has background");
1250 surface->checked_pending = true;
1251 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1252 surface->bg.output = output;
1253 wl_list_remove(&surface->link);
1254 wl_list_init(&surface->link);
1256 output->background = surface;
1258 weston_desktop_surface_set_maximized(dsurface, true);
1259 weston_desktop_surface_set_size(dsurface,
1260 output->output->width,
1261 output->output->height);
1265 shell_set_panel(struct wl_client *client,
1266 struct wl_resource *shell_res,
1267 struct wl_resource *surface_res,
1268 struct wl_resource *output_res,
1271 struct weston_head *head = weston_head_from_resource(output_res);
1272 struct weston_output *woutput = weston_head_get_output(head);
1273 struct ivi_output *output = to_ivi_output(woutput);
1274 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1275 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1276 struct weston_desktop_surface *dsurface;
1277 struct ivi_surface *surface;
1278 struct ivi_surface **member;
1279 int32_t width = 0, height = 0;
1281 if ((ivi->shell_client.resource &&
1282 ivi->shell_client.status == BOUND_FAILED) ||
1283 ivi->shell_client.resource_ext == shell_res) {
1284 wl_resource_post_error(shell_res,
1285 WL_DISPLAY_ERROR_INVALID_OBJECT,
1286 "agl_shell has already been bound. "
1287 "Check out bound_fail event");
1291 dsurface = weston_surface_get_desktop_surface(wsurface);
1293 wl_resource_post_error(shell_res,
1294 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1295 "surface must be a desktop surface");
1299 surface = weston_desktop_surface_get_user_data(dsurface);
1300 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1301 wl_resource_post_error(shell_res,
1302 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1303 "surface already has another ivi role");
1308 case AGL_SHELL_EDGE_TOP:
1309 member = &output->top;
1311 case AGL_SHELL_EDGE_BOTTOM:
1312 member = &output->bottom;
1314 case AGL_SHELL_EDGE_LEFT:
1315 member = &output->left;
1317 case AGL_SHELL_EDGE_RIGHT:
1318 member = &output->right;
1321 wl_resource_post_error(shell_res,
1322 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1323 "invalid edge for panel");
1328 wl_resource_post_error(shell_res,
1329 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1330 "output already has panel on this edge");
1334 surface->checked_pending = true;
1335 surface->role = IVI_SURFACE_ROLE_PANEL;
1336 surface->panel.output = output;
1337 surface->panel.edge = edge;
1338 wl_list_remove(&surface->link);
1339 wl_list_init(&surface->link);
1343 switch (surface->panel.edge) {
1344 case AGL_SHELL_EDGE_TOP:
1345 case AGL_SHELL_EDGE_BOTTOM:
1346 width = woutput->width;
1348 case AGL_SHELL_EDGE_LEFT:
1349 case AGL_SHELL_EDGE_RIGHT:
1350 height = woutput->height;
1354 weston_desktop_surface_set_size(dsurface, width, height);
1358 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1359 const char *data, uint32_t app_state)
1361 struct desktop_client *dclient;
1363 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1364 struct ivi_policy *policy = ivi->policy;
1366 /* FIXME: should queue it here and see when binding agl-shell-desktop
1367 * if there are any to be sent */
1374 if (policy && policy->api.surface_advertise_state_change &&
1375 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1379 app_role = surf->role;
1380 if (app_role == IVI_SURFACE_ROLE_POPUP)
1381 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1383 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1384 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1385 data, app_state, app_role);
1389 shell_activate_app(struct wl_client *client,
1390 struct wl_resource *shell_res,
1392 struct wl_resource *output_res)
1394 struct weston_head *head = weston_head_from_resource(output_res);
1395 struct weston_output *woutput = weston_head_get_output(head);
1396 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1397 struct ivi_output *output = to_ivi_output(woutput);
1399 if (ivi->shell_client.resource &&
1400 ivi->shell_client.status == BOUND_FAILED) {
1401 wl_resource_post_error(shell_res,
1402 WL_DISPLAY_ERROR_INVALID_OBJECT,
1403 "agl_shell has already been bound. "
1404 "Check out bound_fail event");
1408 ivi_layout_activate(output, app_id);
1412 shell_desktop_activate_app(struct wl_client *client,
1413 struct wl_resource *shell_res,
1414 const char *app_id, const char *data,
1415 struct wl_resource *output_res)
1417 struct weston_head *head = weston_head_from_resource(output_res);
1418 struct weston_output *woutput = weston_head_get_output(head);
1419 struct ivi_output *output = to_ivi_output(woutput);
1421 ivi_layout_activate(output, app_id);
1422 shell_advertise_app_state(output->ivi, app_id,
1423 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1427 shell_deactivate_app(struct wl_client *client,
1428 struct wl_resource *shell_res,
1431 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1432 struct ivi_compositor *ivi = dclient->ivi;
1434 ivi_layout_deactivate(ivi, app_id);
1435 shell_advertise_app_state(ivi, app_id,
1436 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1439 /* stub, no usage for the time being */
1441 shell_destroy(struct wl_client *client, struct wl_resource *res)
1446 shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
1447 struct wl_resource *output, int x, int y,
1448 int width, int height)
1450 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1451 struct weston_head *head = weston_head_from_resource(output);
1452 struct weston_output *woutput = weston_head_get_output(head);
1453 struct ivi_output *ioutput = to_ivi_output(woutput);
1455 struct weston_geometry area = { .x = x, .y = y,
1458 if (ivi->shell_client.ready)
1461 ioutput->area_activation = area;
1465 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
1467 wl_resource_destroy(res);
1471 shell_ext_doas(struct wl_client *client, struct wl_resource *res)
1473 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1475 ivi->shell_client_ext.doas_requested = true;
1476 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
1477 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS);
1480 static const struct agl_shell_interface agl_shell_implementation = {
1481 .ready = shell_ready,
1482 .set_background = shell_set_background,
1483 .set_panel = shell_set_panel,
1484 .activate_app = shell_activate_app,
1485 .destroy = shell_destroy,
1486 .set_activate_region = shell_set_activate_region
1489 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
1490 .destroy = shell_ext_destroy,
1491 .doas_shell_client = shell_ext_doas,
1495 shell_desktop_set_app_property(struct wl_client *client,
1496 struct wl_resource *shell_res,
1497 const char *app_id, uint32_t role,
1498 int x, int y, int bx, int by,
1499 int width, int height,
1500 struct wl_resource *output_res)
1502 struct weston_head *head = weston_head_from_resource(output_res);
1503 struct weston_output *woutput = weston_head_get_output(head);
1504 struct ivi_output *output = to_ivi_output(woutput);
1507 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1508 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1509 width, height, app_id);
1511 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1512 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1514 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1515 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1516 ivi_set_pending_desktop_surface_split(output, app_id, role);
1518 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1519 ivi_set_pending_desktop_surface_remote(output, app_id);
1527 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1529 struct pending_popup *p_popup, *next_p_popup;
1530 struct pending_split *split_surf, *next_split_surf;
1531 struct pending_fullscreen *fs_surf, *next_fs_surf;
1532 struct pending_remote *remote_surf, *next_remote_surf;
1534 wl_list_for_each_safe(p_popup, next_p_popup,
1535 &ivi->popup_pending_apps, link)
1536 ivi_remove_pending_desktop_surface_popup(p_popup);
1538 wl_list_for_each_safe(split_surf, next_split_surf,
1539 &ivi->split_pending_apps, link)
1540 ivi_remove_pending_desktop_surface_split(split_surf);
1542 wl_list_for_each_safe(fs_surf, next_fs_surf,
1543 &ivi->fullscreen_pending_apps, link)
1544 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1546 wl_list_for_each_safe(remote_surf, next_remote_surf,
1547 &ivi->remote_pending_apps, link)
1548 ivi_remove_pending_desktop_surface_remote(remote_surf);
1552 shell_desktop_set_app_property_mode(struct wl_client *client,
1553 struct wl_resource *shell_res, uint32_t perm)
1555 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1557 dclient->ivi->keep_pending_surfaces = true;
1559 dclient->ivi->keep_pending_surfaces = false;
1560 /* remove any previous pending surfaces */
1561 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1565 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1566 .activate_app = shell_desktop_activate_app,
1567 .set_app_property = shell_desktop_set_app_property,
1568 .deactivate_app = shell_deactivate_app,
1569 .set_app_property_mode = shell_desktop_set_app_property_mode,
1573 unbind_agl_shell(struct wl_resource *resource)
1575 struct ivi_compositor *ivi;
1576 struct ivi_output *output;
1577 struct ivi_surface *surf, *surf_tmp;
1579 ivi = wl_resource_get_user_data(resource);
1581 /* reset status to allow other clients issue legit requests */
1582 if (ivi->shell_client.resource &&
1583 ivi->shell_client.status == BOUND_FAILED) {
1584 ivi->shell_client.status = BOUND_OK;
1588 wl_list_for_each(output, &ivi->outputs, link) {
1589 /* reset the active surf if there's one present */
1590 if (output->active) {
1591 output->active->view->is_mapped = false;
1592 output->active->view->surface->is_mapped = false;
1594 weston_layer_entry_remove(&output->active->view->layer_link);
1595 output->active = NULL;
1598 insert_black_curtain(output);
1601 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1602 wl_list_remove(&surf->link);
1603 wl_list_init(&surf->link);
1606 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1607 wl_list_remove(&surf->link);
1608 wl_list_init(&surf->link);
1611 wl_list_init(&ivi->surfaces);
1612 wl_list_init(&ivi->pending_surfaces);
1614 ivi->shell_client.ready = false;
1615 ivi->shell_client.resource = NULL;
1616 ivi->shell_client.client = NULL;
1620 unbind_agl_shell_ext(struct wl_resource *resource)
1622 struct ivi_compositor *ivi = wl_resource_get_user_data(resource);
1624 ivi->shell_client_ext.resource = NULL;
1628 bind_agl_shell(struct wl_client *client,
1629 void *data, uint32_t version, uint32_t id)
1631 struct ivi_compositor *ivi = data;
1632 struct wl_resource *resource;
1633 struct ivi_policy *policy;
1636 policy = ivi->policy;
1637 interface = (void *) &agl_shell_interface;
1638 if (policy && policy->api.shell_bind_interface &&
1639 !policy->api.shell_bind_interface(client, interface)) {
1640 wl_client_post_implementation_error(client,
1641 "client not authorized to use agl_shell");
1645 resource = wl_resource_create(client, &agl_shell_interface, version, id);
1647 wl_client_post_no_memory(client);
1651 if (ivi->shell_client.resource) {
1652 if (wl_resource_get_version(resource) == 1) {
1653 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1654 "agl_shell has already been bound");
1658 if (ivi->shell_client_ext.resource &&
1659 ivi->shell_client_ext.doas_requested) {
1661 wl_resource_set_implementation(resource, &agl_shell_implementation,
1663 ivi->shell_client_ext.resource = resource;
1665 if (ivi->shell_client.status == BOUND_OK &&
1666 wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION) {
1667 weston_log("Sent agl_shell_send_bound_ok to client ext\n");
1668 ivi->shell_client_ext.status = BOUND_OK;
1669 agl_shell_send_bound_ok(ivi->shell_client_ext.resource);
1674 agl_shell_send_bound_fail(resource);
1675 ivi->shell_client.status = BOUND_FAILED;
1679 wl_resource_set_implementation(resource, &agl_shell_implementation,
1680 ivi, unbind_agl_shell);
1681 ivi->shell_client.resource = resource;
1683 if (ivi->shell_client.status == BOUND_OK &&
1684 wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION)
1685 agl_shell_send_bound_ok(ivi->shell_client.resource);
1689 bind_agl_shell_ext(struct wl_client *client,
1690 void *data, uint32_t version, uint32_t id)
1692 struct ivi_compositor *ivi = data;
1693 struct wl_resource *resource;
1695 resource = wl_resource_create(client, &agl_shell_ext_interface, version, id);
1697 wl_client_post_no_memory(client);
1701 if (ivi->shell_client_ext.resource) {
1702 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1703 "agl_shell_ext has already been bound");
1707 wl_resource_set_implementation(resource, &agl_shell_ext_implementation,
1708 ivi, unbind_agl_shell_ext);
1709 ivi->shell_client_ext.resource = resource;
1713 unbind_agl_shell_desktop(struct wl_resource *resource)
1715 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1717 wl_list_remove(&dclient->link);
1722 bind_agl_shell_desktop(struct wl_client *client,
1723 void *data, uint32_t version, uint32_t id)
1725 struct ivi_compositor *ivi = data;
1726 struct wl_resource *resource;
1727 struct ivi_policy *policy;
1728 struct desktop_client *dclient;
1731 policy = ivi->policy;
1732 interface = (void *) &agl_shell_desktop_interface;
1733 if (policy && policy->api.shell_bind_interface &&
1734 !policy->api.shell_bind_interface(client, interface)) {
1735 wl_client_post_implementation_error(client,
1736 "client not authorized to use agl_shell_desktop");
1740 dclient = zalloc(sizeof(*dclient));
1742 wl_client_post_no_memory(client);
1746 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1750 wl_client_post_no_memory(client);
1754 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1755 dclient, unbind_agl_shell_desktop);
1757 dclient->resource = resource;
1758 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1760 /* advertise xdg surfaces */
1761 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1765 ivi_shell_create_global(struct ivi_compositor *ivi)
1767 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1768 &agl_shell_interface, 4,
1769 ivi, bind_agl_shell);
1770 if (!ivi->agl_shell) {
1771 weston_log("Failed to create wayland global.\n");
1775 ivi->agl_shell_ext = wl_global_create(ivi->compositor->wl_display,
1776 &agl_shell_ext_interface, 1,
1777 ivi, bind_agl_shell_ext);
1778 if (!ivi->agl_shell_ext) {
1779 weston_log("Failed to create agl_shell_ext global.\n");
1783 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1784 &agl_shell_desktop_interface, 2,
1785 ivi, bind_agl_shell_desktop);
1786 if (!ivi->agl_shell_desktop) {
1787 weston_log("Failed to create wayland global (agl_shell_desktop).\n");