2 * Copyright © 2019 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>
37 #include <libweston/libweston.h>
38 #include <libweston/config-parser.h>
40 #include "shared/os-compatibility.h"
41 #include "shared/helpers.h"
43 #include "agl-shell-server-protocol.h"
44 #include "agl-shell-desktop-server-protocol.h"
47 #include <waltham-transmitter/transmitter_api.h>
51 create_black_surface_view(struct ivi_output *output);
54 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *output,
55 uint32_t orientation, bool to_activate);
58 reverse_orientation(uint32_t orientation);
61 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
62 struct ivi_surface *surface)
64 struct desktop_client *dclient;
65 static bool display_adv = false;
67 if (surface->advertised_on_launch)
70 /* advertise to all desktop clients the new surface */
71 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
73 weston_desktop_surface_get_app_id(surface->dsurface);
76 weston_log("WARNING app_is is null, unable to advertise\n");
81 agl_shell_desktop_send_application(dclient->resource, app_id);
82 surface->advertised_on_launch = true;
87 ivi_set_desktop_surface(struct ivi_surface *surface)
89 struct ivi_compositor *ivi = surface->ivi;
90 assert(surface->role == IVI_SURFACE_ROLE_NONE);
92 surface->role = IVI_SURFACE_ROLE_DESKTOP;
93 wl_list_insert(&surface->ivi->surfaces, &surface->link);
95 agl_shell_desktop_advertise_application_id(ivi, surface);
99 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
101 struct ivi_compositor *ivi = surface->ivi;
102 assert(surface->role == IVI_SURFACE_ROLE_NONE);
104 surface->role = IVI_SURFACE_ROLE_POPUP;
105 wl_list_insert(&ivi->surfaces, &surface->link);
107 agl_shell_desktop_advertise_application_id(ivi, surface);
111 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
113 struct ivi_compositor *ivi = surface->ivi;
114 assert(surface->role == IVI_SURFACE_ROLE_NONE);
116 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
117 wl_list_insert(&ivi->surfaces, &surface->link);
119 agl_shell_desktop_advertise_application_id(ivi, surface);
124 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
126 struct ivi_compositor *ivi = surface->ivi;
127 const struct weston_transmitter_api *api =
128 ivi->waltham_transmitter_api;
133 if (surface->waltham_surface.transmitter_surface)
134 api->surface_destroy(surface->waltham_surface.transmitter_surface);
138 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
140 struct ivi_compositor *ivi = surface->ivi;
141 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
142 struct weston_transmitter *transmitter;
143 struct weston_transmitter_remote *trans_remote;
144 struct weston_surface *weston_surface;
145 struct weston_output *woutput = surface->remote.output->output;
151 transmitter = api->transmitter_get(ivi->compositor);
155 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
157 weston_log("Could not find a valie weston_transmitter_remote "
158 "that matches the output %s\n", woutput->name);
162 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
164 weston_desktop_surface_get_surface(surface->dsurface);
166 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
168 /* this will have the effect of informing the remote side to create a
169 * surface with the name app_id. W/ xdg-shell the following happens:
171 * compositor (server):
172 * surface_push_to_remote():
173 * waltham-transmitter plug-in
174 * -> wthp_ivi_app_id_surface_create()
176 * client -- on the receiver side:
177 * -> wthp_ivi_app_id_surface_create()
178 * -> wth_receiver_weston_main()
179 * -> wl_compositor_create_surface()
180 * -> xdg_wm_base_get_xdg_surface
181 * -> xdg_toplevel_set_app_id()
183 * -> gst_parse_launch()
185 * wth_receiver_weston_main() will be invoked from the handler of
186 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
187 * the gstreamer pipeline as well.
189 surface->waltham_surface.transmitter_surface =
190 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
195 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
199 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
205 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
207 struct ivi_compositor *ivi = surface->ivi;
208 struct weston_view *view;
209 struct ivi_output *output = surface->remote.output;
211 assert(surface->role == IVI_SURFACE_ROLE_NONE);
213 /* remote type are the same as desktop just that client can tell
214 * the compositor to start on another output */
215 surface->role = IVI_SURFACE_ROLE_REMOTE;
217 /* if thew black surface view is mapped on the mean we need
218 * to remove it in order to start showing the 'remote' surface
219 * just being added */
220 view = output->fullscreen_view.fs->view;
221 if (view->is_mapped || view->surface->is_mapped)
222 remove_black_surface(output);
224 if (output->type == OUTPUT_WALTHAM)
225 ivi_output_notify_waltham_plugin(surface);
227 wl_list_insert(&ivi->surfaces, &surface->link);
232 ivi_set_desktop_surface_split(struct ivi_surface *surface)
234 struct ivi_compositor *ivi = surface->ivi;
235 assert(surface->role == IVI_SURFACE_ROLE_NONE);
237 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
238 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
240 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
242 wl_list_insert(&ivi->surfaces, &surface->link);
244 agl_shell_desktop_advertise_application_id(ivi, surface);
247 static struct pending_popup *
248 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
249 int width, int height, const char *app_id)
251 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
252 size_t len_app_id = strlen(app_id);
256 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
257 if (!p_popup->app_id) {
261 memcpy(p_popup->app_id, app_id, len_app_id);
262 p_popup->ioutput = ioutput;
268 p_popup->bb.width = width;
269 p_popup->bb.height = height;
275 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
276 int width, int height, const char *app_id, struct pending_popup *p_popup)
278 size_t len_app_id = strlen(app_id);
280 wl_list_remove(&p_popup->link);
281 wl_list_init(&p_popup->link);
283 memset(p_popup->app_id, 0, strlen(app_id) + 1);
284 free(p_popup->app_id);
286 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
287 if (!p_popup->app_id)
289 memcpy(p_popup->app_id, app_id, len_app_id);
291 p_popup->ioutput = ioutput;
297 p_popup->bb.width = width;
298 p_popup->bb.height = height;
301 static struct pending_fullscreen *
302 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
304 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
305 size_t len_app_id = strlen(app_id);
309 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
310 if (!p_fullscreen->app_id) {
314 memcpy(p_fullscreen->app_id, app_id, len_app_id);
316 p_fullscreen->ioutput = ioutput;
321 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
322 struct pending_fullscreen *p_fullscreen)
324 size_t len_app_id = strlen(app_id);
326 wl_list_remove(&p_fullscreen->link);
327 wl_list_init(&p_fullscreen->link);
329 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
330 free(p_fullscreen->app_id);
332 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
333 if (!p_fullscreen->app_id)
335 memcpy(p_fullscreen->app_id, app_id, len_app_id);
337 p_fullscreen->ioutput = ioutput;
340 static struct pending_remote *
341 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
343 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
344 size_t len_app_id = strlen(app_id);
348 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
349 if (!p_remote->app_id) {
353 memcpy(p_remote->app_id, app_id, len_app_id);
355 p_remote->ioutput = ioutput;
360 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
361 struct pending_remote *p_remote)
363 size_t len_app_id = strlen(app_id);
365 wl_list_remove(&p_remote->link);
366 wl_list_init(&p_remote->link);
368 memset(p_remote->app_id, 0, strlen(app_id) + 1);
369 free(p_remote->app_id);
371 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
372 if (!p_remote->app_id)
374 memcpy(p_remote->app_id, app_id, len_app_id);
376 p_remote->ioutput = ioutput;
380 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
381 int by, int width, int height, const char *app_id)
383 struct ivi_compositor *ivi = ioutput->ivi;
384 struct pending_popup *p_popup = NULL;
385 struct pending_popup *popup;
387 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
388 if (!strcmp(app_id, popup->app_id))
392 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
394 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
398 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
402 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
405 struct ivi_compositor *ivi = ioutput->ivi;
406 struct pending_fullscreen *p_fullscreen = NULL;
407 struct pending_fullscreen *fullscreen;
409 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
410 if (!strcmp(app_id, fullscreen->app_id))
411 p_fullscreen = fullscreen;
414 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
416 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
420 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
424 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
425 const char *app_id, uint32_t orientation)
427 struct ivi_compositor *ivi = ioutput->ivi;
428 struct ivi_surface *surf;
429 size_t len_app_id = strlen(app_id);
430 struct pending_split *split;
432 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
433 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
436 /* more than one is un-supported, do note we need to do
437 * conversion for surface roles instead of using the protocol ones */
438 wl_list_for_each(surf, &ivi->surfaces, link)
439 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
440 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
443 split = zalloc(sizeof(*split));
446 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
447 if (!split->app_id) {
451 memcpy(split->app_id, app_id, len_app_id);
453 split->ioutput = ioutput;
454 split->orientation = orientation;
456 wl_list_insert(&ivi->split_pending_apps, &split->link);
460 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
463 struct ivi_compositor *ivi = ioutput->ivi;
464 struct pending_remote *remote;
465 struct pending_remote *p_remote = NULL;
467 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
468 if (!strcmp(app_id, remote->app_id))
472 p_remote = ivi_ensure_remote(ioutput, app_id);
474 ivi_update_remote(ioutput, app_id, p_remote);
478 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
483 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
486 wl_list_remove(&split->link);
491 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
494 wl_list_remove(&fs->link);
499 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
501 free(p_popup->app_id);
502 wl_list_remove(&p_popup->link);
507 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
509 free(remote->app_id);
510 wl_list_remove(&remote->link);
515 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
517 return surface->ivi->keep_pending_surfaces;
521 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
523 struct ivi_compositor *ivi = surface->ivi;
524 struct pending_popup *p_popup, *next_p_popup;
525 const char *_app_id =
526 weston_desktop_surface_get_app_id(surface->dsurface);
528 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
531 wl_list_for_each_safe(p_popup, next_p_popup,
532 &ivi->popup_pending_apps, link) {
533 if (!strcmp(_app_id, p_popup->app_id)) {
534 surface->popup.output = p_popup->ioutput;
535 surface->popup.x = p_popup->x;
536 surface->popup.y = p_popup->y;
538 surface->popup.bb.x = p_popup->bb.x;
539 surface->popup.bb.y = p_popup->bb.y;
540 surface->popup.bb.width = p_popup->bb.width;
541 surface->popup.bb.height = p_popup->bb.height;
543 if (!ivi_compositor_keep_pending_surfaces(surface))
544 ivi_remove_pending_desktop_surface_popup(p_popup);
553 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
555 struct pending_split *split_surf, *next_split_surf;
556 struct ivi_compositor *ivi = surface->ivi;
557 const char *_app_id =
558 weston_desktop_surface_get_app_id(surface->dsurface);
560 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
563 wl_list_for_each_safe(split_surf, next_split_surf,
564 &ivi->split_pending_apps, link) {
565 if (!strcmp(_app_id, split_surf->app_id)) {
566 surface->split.output = split_surf->ioutput;
567 surface->split.orientation = split_surf->orientation;
568 if (!ivi_compositor_keep_pending_surfaces(surface))
569 ivi_remove_pending_desktop_surface_split(split_surf);
578 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
580 struct pending_fullscreen *fs_surf, *next_fs_surf;
581 struct ivi_compositor *ivi = surface->ivi;
582 const char *_app_id =
583 weston_desktop_surface_get_app_id(surface->dsurface);
585 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
588 wl_list_for_each_safe(fs_surf, next_fs_surf,
589 &ivi->fullscreen_pending_apps, link) {
590 if (!strcmp(_app_id, fs_surf->app_id)) {
591 surface->fullscreen.output = fs_surf->ioutput;
592 if (!ivi_compositor_keep_pending_surfaces(surface))
593 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
602 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
604 struct pending_remote *remote_surf, *next_remote_surf;
605 struct ivi_compositor *ivi = surface->ivi;
606 const char *_app_id =
607 weston_desktop_surface_get_app_id(surface->dsurface);
609 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
612 wl_list_for_each_safe(remote_surf, next_remote_surf,
613 &ivi->remote_pending_apps, link) {
614 if (!strcmp(_app_id, remote_surf->app_id)) {
615 surface->remote.output = remote_surf->ioutput;
616 if (!ivi_compositor_keep_pending_surfaces(surface))
617 ivi_remove_pending_desktop_surface_remote(remote_surf);
625 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
626 enum ivi_surface_role *role)
628 struct ivi_compositor *ivi = surface->ivi;
629 struct wl_list *role_pending_list;
630 struct pending_popup *p_popup;
631 struct pending_split *p_split;
632 struct pending_fullscreen *p_fullscreen;
633 struct pending_remote *p_remote;
635 weston_desktop_surface_get_app_id(surface->dsurface);
637 role_pending_list = &ivi->popup_pending_apps;
638 wl_list_for_each(p_popup, role_pending_list, link) {
639 if (app_id && !strcmp(app_id, p_popup->app_id)) {
640 *role = IVI_SURFACE_ROLE_POPUP;
645 role_pending_list = &ivi->split_pending_apps;
646 wl_list_for_each(p_split, role_pending_list, link) {
647 if (app_id && !strcmp(app_id, p_split->app_id)) {
648 *role = IVI_SURFACE_ROLE_SPLIT_V;
653 role_pending_list = &ivi->fullscreen_pending_apps;
654 wl_list_for_each(p_fullscreen, role_pending_list, link) {
655 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
656 *role = IVI_SURFACE_ROLE_FULLSCREEN;
661 role_pending_list = &ivi->remote_pending_apps;
662 wl_list_for_each(p_remote, role_pending_list, link) {
663 if (app_id && !strcmp(app_id, p_remote->app_id)) {
664 *role = IVI_SURFACE_ROLE_REMOTE;
669 /* else, we are a regular desktop surface */
670 *role = IVI_SURFACE_ROLE_DESKTOP;
674 ivi_check_pending_app_type(struct ivi_surface *surface, enum ivi_surface_role role)
676 struct pending_app *papp;
677 const char *app_id = NULL;
680 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
685 wl_list_for_each(papp, &surface->ivi->pending_apps, link) {
686 if (strcmp(app_id, papp->app_id) == 0 && papp->role == role)
694 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
698 ret = ivi_check_pending_desktop_surface_popup(surface);
700 ivi_set_desktop_surface_popup(surface);
701 ivi_layout_popup_committed(surface);
705 ret = ivi_check_pending_desktop_surface_split(surface);
707 ivi_set_desktop_surface_split(surface);
708 ivi_layout_split_committed(surface);
712 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
714 ivi_set_desktop_surface_fullscreen(surface);
715 ivi_layout_fullscreen_committed(surface);
719 ret = ivi_check_pending_desktop_surface_remote(surface);
721 ivi_set_desktop_surface_remote(surface);
722 ivi_layout_desktop_committed(surface);
726 /* new way of doing it */
727 struct pending_app *papp =
728 ivi_check_pending_app_type(surface, IVI_SURFACE_ROLE_TILE);
730 struct pending_app_tile *papp_tile =
731 container_of(papp, struct pending_app_tile, base);
733 // handle the currently active surface
734 if (papp->ioutput->active) {
735 _ivi_set_shell_surface_split(papp->ioutput->active, NULL,
736 reverse_orientation(papp_tile->orientation), false);
739 surface->role = IVI_SURFACE_ROLE_TILE;
740 wl_list_insert(&surface->ivi->surfaces, &surface->link);
742 _ivi_set_shell_surface_split(surface, papp->ioutput,
743 papp_tile->orientation, true);
745 /* remove it from pending */
746 wl_list_remove(&papp->link);
754 /* if we end up here means we have a regular desktop app and
755 * try to activate it */
756 ivi_set_desktop_surface(surface);
757 ivi_layout_desktop_committed(surface);
761 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
763 struct ivi_output *out;
765 wl_list_for_each(out, &ivi->outputs, link) {
766 create_black_surface_view(out);
767 insert_black_surface(out);
772 ivi_shell_init(struct ivi_compositor *ivi)
774 weston_layer_init(&ivi->hidden, ivi->compositor);
775 weston_layer_init(&ivi->background, ivi->compositor);
776 weston_layer_init(&ivi->normal, ivi->compositor);
777 weston_layer_init(&ivi->panel, ivi->compositor);
778 weston_layer_init(&ivi->popup, ivi->compositor);
779 weston_layer_init(&ivi->fullscreen, ivi->compositor);
781 weston_layer_set_position(&ivi->hidden,
782 WESTON_LAYER_POSITION_HIDDEN);
783 weston_layer_set_position(&ivi->background,
784 WESTON_LAYER_POSITION_BACKGROUND);
785 weston_layer_set_position(&ivi->normal,
786 WESTON_LAYER_POSITION_NORMAL);
787 weston_layer_set_position(&ivi->panel,
788 WESTON_LAYER_POSITION_UI);
789 weston_layer_set_position(&ivi->popup,
790 WESTON_LAYER_POSITION_TOP_UI);
791 weston_layer_set_position(&ivi->fullscreen,
792 WESTON_LAYER_POSITION_FULLSCREEN);
799 ivi_surf_destroy(struct ivi_surface *surf)
801 struct weston_surface *wsurface = surf->view->surface;
803 if (weston_surface_is_mapped(wsurface)) {
804 weston_desktop_surface_unlink_view(surf->view);
805 weston_view_destroy(surf->view);
808 wl_list_remove(&surf->link);
813 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
815 struct weston_view *view, *view_next;
817 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
818 struct ivi_surface *ivi_surf =
819 get_ivi_shell_surface(view->surface);
821 ivi_surf_destroy(ivi_surf);
826 ivi_shell_finalize(struct ivi_compositor *ivi)
828 struct ivi_output *output;
830 ivi_shell_destroy_views_on_layer(&ivi->hidden);
831 weston_layer_fini(&ivi->hidden);
833 ivi_shell_destroy_views_on_layer(&ivi->background);
834 weston_layer_fini(&ivi->background);
836 ivi_shell_destroy_views_on_layer(&ivi->normal);
837 weston_layer_fini(&ivi->normal);
839 ivi_shell_destroy_views_on_layer(&ivi->panel);
840 weston_layer_fini(&ivi->panel);
842 ivi_shell_destroy_views_on_layer(&ivi->popup);
843 weston_layer_fini(&ivi->popup);
845 wl_list_for_each(output, &ivi->outputs, link) {
846 if (output->fullscreen_view.fs->view) {
847 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
848 output->fullscreen_view.fs->view = NULL;
851 weston_layer_fini(&ivi->fullscreen);
855 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
857 struct ivi_surface *surface;
859 wl_list_for_each(surface, &ivi->surfaces, link) {
861 weston_desktop_surface_get_app_id(surface->dsurface);
862 if (app_id == NULL) {
863 weston_log("WARNING app_is is null, unable to advertise\n");
866 agl_shell_desktop_send_application(resource, app_id);
871 client_exec(const char *command, int fd)
876 /* Don't give the child our signal mask */
878 sigprocmask(SIG_UNBLOCK, &sig, NULL);
880 /* Launch clients as the user; don't give them the wrong euid */
881 if (seteuid(getuid()) == -1) {
882 weston_log("seteuid failed: %s\n", strerror(errno));
886 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
887 * clobbering fd, as we'll exit/exec either way.
891 weston_log("dup failed: %s\n", strerror(errno));
895 snprintf(s, sizeof s, "%d", fd);
896 setenv("WAYLAND_SOCKET", s, 1);
898 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
899 weston_log("executing '%s' failed: %s", command, strerror(errno));
902 static struct wl_client *
903 launch_shell_client(struct ivi_compositor *ivi, const char *command)
905 struct wl_client *client;
909 weston_log("launching' %s'\n", command);
911 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
912 weston_log("socketpair failed while launching '%s': %s\n",
913 command, strerror(errno));
921 weston_log("fork failed while launching '%s': %s\n",
922 command, strerror(errno));
927 client_exec(command, sock[1]);
932 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
935 weston_log("Failed to create wayland client for '%s'",
944 ivi_launch_shell_client(struct ivi_compositor *ivi)
946 struct weston_config_section *section;
947 char *command = NULL;
949 section = weston_config_get_section(ivi->config, "shell-client",
952 weston_config_section_get_string(section, "command",
958 ivi->shell_client.client = launch_shell_client(ivi, command);
959 if (!ivi->shell_client.client)
966 destroy_black_view(struct wl_listener *listener, void *data)
968 struct fullscreen_view *fs =
969 wl_container_of(listener, fs, fs_destroy);
973 wl_list_remove(&fs->fs_destroy.link);
980 create_black_surface_view(struct ivi_output *output)
982 struct weston_surface *surface = NULL;
983 struct weston_view *view;
984 struct ivi_compositor *ivi = output->ivi;
985 struct weston_compositor *wc= ivi->compositor;
986 struct weston_output *woutput = output->output;
991 surface = weston_surface_create(wc);
994 view = weston_view_create(surface);
996 weston_surface_destroy(surface);
1000 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1001 weston_surface_set_size(surface, woutput->width, woutput->height);
1002 weston_view_set_position(view, woutput->x, woutput->y);
1004 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
1005 if (!output->fullscreen_view.fs) {
1006 weston_surface_destroy(surface);
1009 output->fullscreen_view.fs->view = view;
1011 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
1012 wl_signal_add(&woutput->destroy_signal,
1013 &output->fullscreen_view.fs_destroy);
1017 remove_black_surface(struct ivi_output *output)
1019 struct weston_view *view;
1022 !output->fullscreen_view.fs &&
1023 !output->fullscreen_view.fs->view) {
1024 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1028 view = output->fullscreen_view.fs->view;
1029 assert(view->is_mapped == true ||
1030 view->surface->is_mapped == true);
1032 view->is_mapped = false;
1033 view->surface->is_mapped = false;
1035 weston_layer_entry_remove(&view->layer_link);
1036 weston_view_update_transform(view);
1038 weston_view_damage_below(view);
1042 insert_black_surface(struct ivi_output *output)
1044 struct weston_view *view;
1047 !output->fullscreen_view.fs &&
1048 !output->fullscreen_view.fs->view) || !output->output) {
1049 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1053 view = output->fullscreen_view.fs->view;
1054 if (view->is_mapped || view->surface->is_mapped)
1057 weston_layer_entry_remove(&view->layer_link);
1058 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1061 view->is_mapped = true;
1062 view->surface->is_mapped = true;
1064 weston_view_update_transform(view);
1065 weston_view_damage_below(view);
1069 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1071 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1072 struct ivi_output *output;
1073 struct ivi_surface *surface, *tmp;
1075 if (ivi->shell_client.resource &&
1076 ivi->shell_client.status == BOUND_FAILED) {
1077 wl_resource_post_error(shell_res,
1078 WL_DISPLAY_ERROR_INVALID_OBJECT,
1079 "agl_shell has already been bound. "
1080 "Check out bound_fail event");
1084 /* Init already finished. Do nothing */
1085 if (ivi->shell_client.ready)
1089 ivi->shell_client.ready = true;
1091 wl_list_for_each(output, &ivi->outputs, link) {
1092 if (output->background)
1093 remove_black_surface(output);
1094 ivi_layout_init(ivi, output);
1097 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1098 wl_list_remove(&surface->link);
1099 wl_list_init(&surface->link);
1100 ivi_check_pending_desktop_surface(surface);
1101 surface->checked_pending = true;
1106 shell_set_background(struct wl_client *client,
1107 struct wl_resource *shell_res,
1108 struct wl_resource *surface_res,
1109 struct wl_resource *output_res)
1111 struct weston_head *head = weston_head_from_resource(output_res);
1112 struct weston_output *woutput = weston_head_get_output(head);
1113 struct ivi_output *output = to_ivi_output(woutput);
1114 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1115 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1116 struct weston_desktop_surface *dsurface;
1117 struct ivi_surface *surface;
1119 if (ivi->shell_client.resource &&
1120 ivi->shell_client.status == BOUND_FAILED) {
1121 wl_resource_post_error(shell_res,
1122 WL_DISPLAY_ERROR_INVALID_OBJECT,
1123 "agl_shell has already been bound. "
1124 "Check out bound_fail event");
1128 dsurface = weston_surface_get_desktop_surface(wsurface);
1130 wl_resource_post_error(shell_res,
1131 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1132 "surface must be a desktop surface");
1136 surface = weston_desktop_surface_get_user_data(dsurface);
1137 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1138 wl_resource_post_error(shell_res,
1139 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1140 "surface already has another ivi role");
1144 if (output->background) {
1145 wl_resource_post_error(shell_res,
1146 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1147 "output already has background");
1151 surface->checked_pending = true;
1152 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1153 surface->bg.output = output;
1154 wl_list_remove(&surface->link);
1155 wl_list_init(&surface->link);
1157 output->background = surface;
1159 weston_desktop_surface_set_maximized(dsurface, true);
1160 weston_desktop_surface_set_size(dsurface,
1161 output->output->width,
1162 output->output->height);
1166 shell_set_panel(struct wl_client *client,
1167 struct wl_resource *shell_res,
1168 struct wl_resource *surface_res,
1169 struct wl_resource *output_res,
1172 struct weston_head *head = weston_head_from_resource(output_res);
1173 struct weston_output *woutput = weston_head_get_output(head);
1174 struct ivi_output *output = to_ivi_output(woutput);
1175 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1176 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1177 struct weston_desktop_surface *dsurface;
1178 struct ivi_surface *surface;
1179 struct ivi_surface **member;
1180 int32_t width = 0, height = 0;
1182 if (ivi->shell_client.resource &&
1183 ivi->shell_client.status == BOUND_FAILED) {
1184 wl_resource_post_error(shell_res,
1185 WL_DISPLAY_ERROR_INVALID_OBJECT,
1186 "agl_shell has already been bound. "
1187 "Check out bound_fail event");
1191 dsurface = weston_surface_get_desktop_surface(wsurface);
1193 wl_resource_post_error(shell_res,
1194 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1195 "surface must be a desktop surface");
1199 surface = weston_desktop_surface_get_user_data(dsurface);
1200 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1201 wl_resource_post_error(shell_res,
1202 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1203 "surface already has another ivi role");
1208 case AGL_SHELL_EDGE_TOP:
1209 member = &output->top;
1211 case AGL_SHELL_EDGE_BOTTOM:
1212 member = &output->bottom;
1214 case AGL_SHELL_EDGE_LEFT:
1215 member = &output->left;
1217 case AGL_SHELL_EDGE_RIGHT:
1218 member = &output->right;
1221 wl_resource_post_error(shell_res,
1222 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1223 "invalid edge for panel");
1228 wl_resource_post_error(shell_res,
1229 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1230 "output already has panel on this edge");
1234 surface->checked_pending = true;
1235 surface->role = IVI_SURFACE_ROLE_PANEL;
1236 surface->panel.output = output;
1237 surface->panel.edge = edge;
1238 wl_list_remove(&surface->link);
1239 wl_list_init(&surface->link);
1243 switch (surface->panel.edge) {
1244 case AGL_SHELL_EDGE_TOP:
1245 case AGL_SHELL_EDGE_BOTTOM:
1246 width = woutput->width;
1248 case AGL_SHELL_EDGE_LEFT:
1249 case AGL_SHELL_EDGE_RIGHT:
1250 height = woutput->height;
1254 weston_desktop_surface_set_size(dsurface, width, height);
1258 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1259 const char *data, uint32_t app_state)
1261 struct desktop_client *dclient;
1263 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1264 struct ivi_policy *policy = ivi->policy;
1266 /* FIXME: should queue it here and see when binding agl-shell-desktop
1267 * if there are any to be sent */
1274 if (policy && policy->api.surface_advertise_state_change &&
1275 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1279 app_role = surf->role;
1280 if (app_role == IVI_SURFACE_ROLE_POPUP)
1281 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1283 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1284 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1285 data, app_state, app_role);
1289 shell_activate_app(struct wl_client *client,
1290 struct wl_resource *shell_res,
1292 struct wl_resource *output_res)
1294 struct weston_head *head = weston_head_from_resource(output_res);
1295 struct weston_output *woutput = weston_head_get_output(head);
1296 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1297 struct ivi_output *output = to_ivi_output(woutput);
1299 if (ivi->shell_client.resource &&
1300 ivi->shell_client.status == BOUND_FAILED) {
1301 wl_resource_post_error(shell_res,
1302 WL_DISPLAY_ERROR_INVALID_OBJECT,
1303 "agl_shell has already been bound. "
1304 "Check out bound_fail event");
1308 ivi_layout_activate(output, app_id);
1312 shell_desktop_activate_app(struct wl_client *client,
1313 struct wl_resource *shell_res,
1314 const char *app_id, const char *data,
1315 struct wl_resource *output_res)
1317 struct weston_head *head = weston_head_from_resource(output_res);
1318 struct weston_output *woutput = weston_head_get_output(head);
1319 struct ivi_output *output = to_ivi_output(woutput);
1321 ivi_layout_activate(output, app_id);
1322 shell_advertise_app_state(output->ivi, app_id,
1323 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1327 shell_deactivate_app(struct wl_client *client,
1328 struct wl_resource *shell_res,
1331 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1332 struct ivi_compositor *ivi = dclient->ivi;
1334 ivi_layout_deactivate(ivi, app_id);
1335 shell_advertise_app_state(ivi, app_id,
1336 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1339 /* stub, no usage for the time being */
1341 shell_destroy(struct wl_client *client, struct wl_resource *res)
1346 _ivi_set_pending_desktop_surface_split(struct wl_resource *output,
1347 const char *app_id, uint32_t orientation)
1349 weston_log("%s() added split surface for app_id '%s' with "
1350 "orientation %d to pending\n", __func__, app_id, orientation);
1352 struct weston_head *head = weston_head_from_resource(output);
1353 struct weston_output *woutput = weston_head_get_output(head);
1354 struct ivi_output *ivi_output = to_ivi_output(woutput);
1356 struct pending_app_tile *app_tile = zalloc(sizeof(*app_tile));
1358 app_tile->base.app_id = strdup(app_id);
1359 app_tile->base.ioutput = ivi_output;
1360 app_tile->base.role = IVI_SURFACE_ROLE_TILE;
1362 app_tile->orientation = orientation;
1363 wl_list_insert(&ivi_output->ivi->pending_apps, &app_tile->base.link);
1367 reverse_orientation(uint32_t orientation)
1370 switch (orientation) {
1371 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1372 return AGL_SHELL_TILE_ORIENTATION_RIGHT;
1374 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1375 return AGL_SHELL_TILE_ORIENTATION_LEFT;
1377 case AGL_SHELL_TILE_ORIENTATION_TOP:
1378 return AGL_SHELL_TILE_ORIENTATION_BOTTOM;
1380 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1381 return AGL_SHELL_TILE_ORIENTATION_TOP;
1384 return AGL_SHELL_TILE_ORIENTATION_NONE;
1389 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *ioutput,
1390 uint32_t orientation, bool to_activate)
1392 struct ivi_compositor *ivi = surface->ivi;
1393 struct weston_geometry geom = {};
1394 struct ivi_output *output = NULL;
1399 geom = weston_desktop_surface_get_geometry(surface->dsurface);
1400 output = ivi_layout_get_output_from_surface(surface);
1405 width = output->area.width;
1406 height = output->area.height;
1408 switch (orientation) {
1409 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1410 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1413 case AGL_SHELL_TILE_ORIENTATION_TOP:
1414 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1417 case AGL_SHELL_TILE_ORIENTATION_NONE:
1421 assert(!"Invalid orientation passed");
1425 x = output->area.x - geom.x;
1426 y = output->area.y - geom.y;
1428 if (orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1430 else if (orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1434 struct weston_view *ev = surface->view;
1435 struct ivi_shell_seat *ivi_seat = NULL;
1436 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
1439 ivi_seat = get_ivi_shell_seat(wseat);
1441 if (!weston_view_is_mapped(ev))
1442 weston_view_update_transform(ev);
1444 weston_layer_entry_remove(&ev->layer_link);
1447 // mark view as mapped
1448 ev->is_mapped = true;
1449 ev->surface->is_mapped = true;
1450 surface->mapped = true;
1452 // update older/new active surface
1453 output->previous_active = output->active;
1454 output->active = surface;
1456 // add to the layer and inflict damage
1457 weston_view_set_output(ev, output->output);
1458 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1459 weston_view_geometry_dirty(ev);
1460 weston_surface_damage(ev->surface);
1462 // handle input / keyboard
1464 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
1467 weston_view_set_position(surface->view, x, y);
1468 weston_desktop_surface_set_size(surface->dsurface, width, height);
1469 weston_desktop_surface_set_orientation(surface->dsurface, orientation);
1470 surface->orientation = orientation;
1472 weston_compositor_schedule_repaint(ivi->compositor);
1474 weston_log("%s() Setting to x=%d, y=%d, width=%d, height=%d, orientation=%d\n",
1475 __func__, x, y, width, height, orientation);
1480 shell_ivi_surf_count_split_surfaces(struct ivi_compositor *ivi)
1483 struct ivi_surface *surf;
1485 wl_list_for_each(surf, &ivi->surfaces, link) {
1486 if (surf->orientation > AGL_SHELL_TILE_ORIENTATION_NONE)
1495 void shell_set_app_split(struct wl_client *client, struct wl_resource *res,
1496 const char *app_id, uint32_t orientation,
1497 struct wl_resource *output_res)
1499 struct ivi_surface *surf;
1500 struct ivi_compositor *ivi = wl_resource_get_user_data(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);
1509 if (shell_ivi_surf_count_split_surfaces(ivi) > 2) {
1510 weston_log("Found more than two split surfaces in tile orientation.\n");
1514 /* add it as pending until */
1515 surf = ivi_find_app(ivi, app_id);
1517 _ivi_set_pending_desktop_surface_split(output_res, app_id, orientation);
1521 /* otherwise, take actions now */
1522 weston_log("%s() added split surface for app_id '%s' with orientation %d\n",
1523 __func__, app_id, orientation);
1525 if (output->previous_active) {
1526 struct weston_view *ev = output->previous_active->view;
1528 ev->is_mapped = true;
1529 ev->surface->is_mapped = true;
1530 output->previous_active->mapped = true;
1532 weston_view_update_transform(ev);
1533 weston_view_set_output(ev, woutput);
1534 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1536 _ivi_set_shell_surface_split(output->previous_active, NULL,
1537 reverse_orientation(orientation), false);
1539 _ivi_set_shell_surface_split(surf, NULL, orientation, false);
1542 static const struct agl_shell_interface agl_shell_implementation = {
1543 .destroy = shell_destroy,
1544 .ready = shell_ready,
1545 .set_background = shell_set_background,
1546 .set_panel = shell_set_panel,
1547 .activate_app = shell_activate_app,
1548 .set_app_split = shell_set_app_split,
1552 shell_desktop_set_app_property(struct wl_client *client,
1553 struct wl_resource *shell_res,
1554 const char *app_id, uint32_t role,
1555 int x, int y, int bx, int by,
1556 int width, int height,
1557 struct wl_resource *output_res)
1559 struct weston_head *head = weston_head_from_resource(output_res);
1560 struct weston_output *woutput = weston_head_get_output(head);
1561 struct ivi_output *output = to_ivi_output(woutput);
1564 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1565 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1566 width, height, app_id);
1568 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1569 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1571 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1572 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1573 ivi_set_pending_desktop_surface_split(output, app_id, role);
1575 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1576 ivi_set_pending_desktop_surface_remote(output, app_id);
1584 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1586 struct pending_popup *p_popup, *next_p_popup;
1587 struct pending_split *split_surf, *next_split_surf;
1588 struct pending_fullscreen *fs_surf, *next_fs_surf;
1589 struct pending_remote *remote_surf, *next_remote_surf;
1591 wl_list_for_each_safe(p_popup, next_p_popup,
1592 &ivi->popup_pending_apps, link)
1593 ivi_remove_pending_desktop_surface_popup(p_popup);
1595 wl_list_for_each_safe(split_surf, next_split_surf,
1596 &ivi->split_pending_apps, link)
1597 ivi_remove_pending_desktop_surface_split(split_surf);
1599 wl_list_for_each_safe(fs_surf, next_fs_surf,
1600 &ivi->fullscreen_pending_apps, link)
1601 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1603 wl_list_for_each_safe(remote_surf, next_remote_surf,
1604 &ivi->remote_pending_apps, link)
1605 ivi_remove_pending_desktop_surface_remote(remote_surf);
1609 shell_desktop_set_app_property_mode(struct wl_client *client,
1610 struct wl_resource *shell_res, uint32_t perm)
1612 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1614 dclient->ivi->keep_pending_surfaces = true;
1616 dclient->ivi->keep_pending_surfaces = false;
1617 /* remove any previous pending surfaces */
1618 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1622 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1623 .activate_app = shell_desktop_activate_app,
1624 .set_app_property = shell_desktop_set_app_property,
1625 .deactivate_app = shell_deactivate_app,
1626 .set_app_property_mode = shell_desktop_set_app_property_mode,
1630 unbind_agl_shell(struct wl_resource *resource)
1632 struct ivi_compositor *ivi;
1633 struct ivi_output *output;
1634 struct ivi_surface *surf, *surf_tmp;
1636 ivi = wl_resource_get_user_data(resource);
1638 /* reset status to allow other clients issue legit requests */
1639 if (ivi->shell_client.resource &&
1640 ivi->shell_client.status == BOUND_FAILED) {
1641 ivi->shell_client.status = BOUND_OK;
1645 wl_list_for_each(output, &ivi->outputs, link) {
1646 /* reset the active surf if there's one present */
1647 if (output->active) {
1648 output->active->view->is_mapped = false;
1649 output->active->view->surface->is_mapped = false;
1651 weston_layer_entry_remove(&output->active->view->layer_link);
1652 output->active = NULL;
1655 insert_black_surface(output);
1658 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1659 wl_list_remove(&surf->link);
1660 wl_list_init(&surf->link);
1663 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1664 wl_list_remove(&surf->link);
1665 wl_list_init(&surf->link);
1668 wl_list_init(&ivi->surfaces);
1669 wl_list_init(&ivi->pending_surfaces);
1671 ivi->shell_client.ready = false;
1672 ivi->shell_client.resource = NULL;
1673 ivi->shell_client.client = NULL;
1677 bind_agl_shell(struct wl_client *client,
1678 void *data, uint32_t version, uint32_t id)
1680 struct ivi_compositor *ivi = data;
1681 struct wl_resource *resource;
1682 struct ivi_policy *policy;
1685 policy = ivi->policy;
1686 interface = (void *) &agl_shell_interface;
1687 if (policy && policy->api.shell_bind_interface &&
1688 !policy->api.shell_bind_interface(client, interface)) {
1689 wl_client_post_implementation_error(client,
1690 "client not authorized to use agl_shell");
1694 resource = wl_resource_create(client, &agl_shell_interface, version, id);
1696 wl_client_post_no_memory(client);
1700 if (ivi->shell_client.resource) {
1701 if (wl_resource_get_version(resource) == 1) {
1702 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1703 "agl_shell has already been bound");
1707 agl_shell_send_bound_fail(resource);
1708 ivi->shell_client.status = BOUND_FAILED;
1711 wl_resource_set_implementation(resource, &agl_shell_implementation,
1712 ivi, unbind_agl_shell);
1713 ivi->shell_client.resource = resource;
1715 if (ivi->shell_client.status == BOUND_OK &&
1716 wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION)
1717 agl_shell_send_bound_ok(ivi->shell_client.resource);
1721 unbind_agl_shell_desktop(struct wl_resource *resource)
1723 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1725 wl_list_remove(&dclient->link);
1730 bind_agl_shell_desktop(struct wl_client *client,
1731 void *data, uint32_t version, uint32_t id)
1733 struct ivi_compositor *ivi = data;
1734 struct wl_resource *resource;
1735 struct ivi_policy *policy;
1736 struct desktop_client *dclient;
1739 policy = ivi->policy;
1740 interface = (void *) &agl_shell_desktop_interface;
1741 if (policy && policy->api.shell_bind_interface &&
1742 !policy->api.shell_bind_interface(client, interface)) {
1743 wl_client_post_implementation_error(client,
1744 "client not authorized to use agl_shell_desktop");
1748 dclient = zalloc(sizeof(*dclient));
1750 wl_client_post_no_memory(client);
1754 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1758 wl_client_post_no_memory(client);
1762 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1763 dclient, unbind_agl_shell_desktop);
1765 dclient->resource = resource;
1766 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1768 /* advertise xdg surfaces */
1769 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1773 ivi_shell_create_global(struct ivi_compositor *ivi)
1775 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1776 &agl_shell_interface, 3,
1777 ivi, bind_agl_shell);
1778 if (!ivi->agl_shell) {
1779 weston_log("Failed to create wayland 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");