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"
42 #include "agl-shell-server-protocol.h"
43 #include "agl-shell-desktop-server-protocol.h"
46 #include <waltham-transmitter/transmitter_api.h>
50 create_black_curtain_view(struct ivi_output *output);
53 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
54 struct ivi_surface *surface)
56 struct desktop_client *dclient;
57 static bool display_adv = false;
59 if (surface->advertised_on_launch)
62 /* advertise to all desktop clients the new surface */
63 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
65 weston_desktop_surface_get_app_id(surface->dsurface);
68 weston_log("WARNING app_is is null, unable to advertise\n");
73 agl_shell_desktop_send_application(dclient->resource, app_id);
74 surface->advertised_on_launch = true;
79 ivi_set_desktop_surface(struct ivi_surface *surface)
81 struct ivi_compositor *ivi = surface->ivi;
82 assert(surface->role == IVI_SURFACE_ROLE_NONE);
84 surface->role = IVI_SURFACE_ROLE_DESKTOP;
85 wl_list_insert(&surface->ivi->surfaces, &surface->link);
87 agl_shell_desktop_advertise_application_id(ivi, surface);
91 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
93 struct ivi_compositor *ivi = surface->ivi;
94 assert(surface->role == IVI_SURFACE_ROLE_NONE);
96 surface->role = IVI_SURFACE_ROLE_POPUP;
97 wl_list_insert(&ivi->surfaces, &surface->link);
99 agl_shell_desktop_advertise_application_id(ivi, surface);
103 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
105 struct ivi_compositor *ivi = surface->ivi;
106 assert(surface->role == IVI_SURFACE_ROLE_NONE);
108 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
109 wl_list_insert(&ivi->surfaces, &surface->link);
111 agl_shell_desktop_advertise_application_id(ivi, surface);
116 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
118 struct ivi_compositor *ivi = surface->ivi;
119 const struct weston_transmitter_api *api =
120 ivi->waltham_transmitter_api;
125 if (surface->waltham_surface.transmitter_surface)
126 api->surface_destroy(surface->waltham_surface.transmitter_surface);
130 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
132 struct ivi_compositor *ivi = surface->ivi;
133 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
134 struct weston_transmitter *transmitter;
135 struct weston_transmitter_remote *trans_remote;
136 struct weston_surface *weston_surface;
137 struct weston_output *woutput = surface->remote.output->output;
143 transmitter = api->transmitter_get(ivi->compositor);
147 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
149 weston_log("Could not find a valie weston_transmitter_remote "
150 "that matches the output %s\n", woutput->name);
154 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
156 weston_desktop_surface_get_surface(surface->dsurface);
158 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
160 /* this will have the effect of informing the remote side to create a
161 * surface with the name app_id. W/ xdg-shell the following happens:
163 * compositor (server):
164 * surface_push_to_remote():
165 * waltham-transmitter plug-in
166 * -> wthp_ivi_app_id_surface_create()
168 * client -- on the receiver side:
169 * -> wthp_ivi_app_id_surface_create()
170 * -> wth_receiver_weston_main()
171 * -> wl_compositor_create_surface()
172 * -> xdg_wm_base_get_xdg_surface
173 * -> xdg_toplevel_set_app_id()
175 * -> gst_parse_launch()
177 * wth_receiver_weston_main() will be invoked from the handler of
178 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
179 * the gstreamer pipeline as well.
181 surface->waltham_surface.transmitter_surface =
182 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
187 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
191 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
197 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
199 struct ivi_compositor *ivi = surface->ivi;
200 struct weston_view *view;
201 struct ivi_output *output = surface->remote.output;
203 assert(surface->role == IVI_SURFACE_ROLE_NONE);
205 /* remote type are the same as desktop just that client can tell
206 * the compositor to start on another output */
207 surface->role = IVI_SURFACE_ROLE_REMOTE;
209 /* if thew black surface view is mapped on the mean we need
210 * to remove it in order to start showing the 'remote' surface
211 * just being added */
212 view = output->fullscreen_view.fs->view;
213 if (view->is_mapped || view->surface->is_mapped)
214 remove_black_curtain(output);
216 if (output->type == OUTPUT_WALTHAM)
217 ivi_output_notify_waltham_plugin(surface);
219 wl_list_insert(&ivi->surfaces, &surface->link);
224 ivi_set_desktop_surface_split(struct ivi_surface *surface)
226 struct ivi_compositor *ivi = surface->ivi;
227 assert(surface->role == IVI_SURFACE_ROLE_NONE);
229 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
230 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
232 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
234 wl_list_insert(&ivi->surfaces, &surface->link);
236 agl_shell_desktop_advertise_application_id(ivi, surface);
239 static struct pending_popup *
240 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
241 int width, int height, const char *app_id)
243 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
244 size_t len_app_id = strlen(app_id);
248 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
249 if (!p_popup->app_id) {
253 memcpy(p_popup->app_id, app_id, len_app_id);
254 p_popup->ioutput = ioutput;
260 p_popup->bb.width = width;
261 p_popup->bb.height = height;
267 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
268 int width, int height, const char *app_id, struct pending_popup *p_popup)
270 size_t len_app_id = strlen(app_id);
272 wl_list_remove(&p_popup->link);
273 wl_list_init(&p_popup->link);
275 memset(p_popup->app_id, 0, strlen(app_id) + 1);
276 free(p_popup->app_id);
278 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
279 if (!p_popup->app_id)
281 memcpy(p_popup->app_id, app_id, len_app_id);
283 p_popup->ioutput = ioutput;
289 p_popup->bb.width = width;
290 p_popup->bb.height = height;
293 static struct pending_fullscreen *
294 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
296 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
297 size_t len_app_id = strlen(app_id);
301 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
302 if (!p_fullscreen->app_id) {
306 memcpy(p_fullscreen->app_id, app_id, len_app_id);
308 p_fullscreen->ioutput = ioutput;
313 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
314 struct pending_fullscreen *p_fullscreen)
316 size_t len_app_id = strlen(app_id);
318 wl_list_remove(&p_fullscreen->link);
319 wl_list_init(&p_fullscreen->link);
321 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
322 free(p_fullscreen->app_id);
324 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
325 if (!p_fullscreen->app_id)
327 memcpy(p_fullscreen->app_id, app_id, len_app_id);
329 p_fullscreen->ioutput = ioutput;
332 static struct pending_remote *
333 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
335 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
336 size_t len_app_id = strlen(app_id);
340 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
341 if (!p_remote->app_id) {
345 memcpy(p_remote->app_id, app_id, len_app_id);
347 p_remote->ioutput = ioutput;
352 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
353 struct pending_remote *p_remote)
355 size_t len_app_id = strlen(app_id);
357 wl_list_remove(&p_remote->link);
358 wl_list_init(&p_remote->link);
360 memset(p_remote->app_id, 0, strlen(app_id) + 1);
361 free(p_remote->app_id);
363 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
364 if (!p_remote->app_id)
366 memcpy(p_remote->app_id, app_id, len_app_id);
368 p_remote->ioutput = ioutput;
372 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
373 int by, int width, int height, const char *app_id)
375 struct ivi_compositor *ivi = ioutput->ivi;
376 struct pending_popup *p_popup = NULL;
377 struct pending_popup *popup;
379 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
380 if (!strcmp(app_id, popup->app_id))
384 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
386 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
390 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
394 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
397 struct ivi_compositor *ivi = ioutput->ivi;
398 struct pending_fullscreen *p_fullscreen = NULL;
399 struct pending_fullscreen *fullscreen;
401 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
402 if (!strcmp(app_id, fullscreen->app_id))
403 p_fullscreen = fullscreen;
406 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
408 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
412 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
416 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
417 const char *app_id, uint32_t orientation)
419 struct ivi_compositor *ivi = ioutput->ivi;
420 struct ivi_surface *surf;
421 size_t len_app_id = strlen(app_id);
422 struct pending_split *split;
424 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
425 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
428 /* more than one is un-supported, do note we need to do
429 * conversion for surface roles instead of using the protocol ones */
430 wl_list_for_each(surf, &ivi->surfaces, link)
431 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
432 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
435 split = zalloc(sizeof(*split));
438 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
439 if (!split->app_id) {
443 memcpy(split->app_id, app_id, len_app_id);
445 split->ioutput = ioutput;
446 split->orientation = orientation;
448 wl_list_insert(&ivi->split_pending_apps, &split->link);
452 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
455 struct ivi_compositor *ivi = ioutput->ivi;
456 struct pending_remote *remote;
457 struct pending_remote *p_remote = NULL;
459 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
460 if (!strcmp(app_id, remote->app_id))
464 p_remote = ivi_ensure_remote(ioutput, app_id);
466 ivi_update_remote(ioutput, app_id, p_remote);
470 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
475 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
478 wl_list_remove(&split->link);
483 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
486 wl_list_remove(&fs->link);
491 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
493 free(p_popup->app_id);
494 wl_list_remove(&p_popup->link);
499 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
501 free(remote->app_id);
502 wl_list_remove(&remote->link);
507 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
509 return surface->ivi->keep_pending_surfaces;
513 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
515 struct ivi_compositor *ivi = surface->ivi;
516 struct pending_popup *p_popup, *next_p_popup;
517 const char *_app_id =
518 weston_desktop_surface_get_app_id(surface->dsurface);
520 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
523 wl_list_for_each_safe(p_popup, next_p_popup,
524 &ivi->popup_pending_apps, link) {
525 if (!strcmp(_app_id, p_popup->app_id)) {
526 surface->popup.output = p_popup->ioutput;
527 surface->popup.x = p_popup->x;
528 surface->popup.y = p_popup->y;
530 surface->popup.bb.x = p_popup->bb.x;
531 surface->popup.bb.y = p_popup->bb.y;
532 surface->popup.bb.width = p_popup->bb.width;
533 surface->popup.bb.height = p_popup->bb.height;
535 if (!ivi_compositor_keep_pending_surfaces(surface))
536 ivi_remove_pending_desktop_surface_popup(p_popup);
545 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
547 struct pending_split *split_surf, *next_split_surf;
548 struct ivi_compositor *ivi = surface->ivi;
549 const char *_app_id =
550 weston_desktop_surface_get_app_id(surface->dsurface);
552 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
555 wl_list_for_each_safe(split_surf, next_split_surf,
556 &ivi->split_pending_apps, link) {
557 if (!strcmp(_app_id, split_surf->app_id)) {
558 surface->split.output = split_surf->ioutput;
559 surface->split.orientation = split_surf->orientation;
560 if (!ivi_compositor_keep_pending_surfaces(surface))
561 ivi_remove_pending_desktop_surface_split(split_surf);
570 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
572 struct pending_fullscreen *fs_surf, *next_fs_surf;
573 struct ivi_compositor *ivi = surface->ivi;
574 const char *_app_id =
575 weston_desktop_surface_get_app_id(surface->dsurface);
577 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
580 wl_list_for_each_safe(fs_surf, next_fs_surf,
581 &ivi->fullscreen_pending_apps, link) {
582 if (!strcmp(_app_id, fs_surf->app_id)) {
583 surface->fullscreen.output = fs_surf->ioutput;
584 if (!ivi_compositor_keep_pending_surfaces(surface))
585 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
594 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
596 struct pending_remote *remote_surf, *next_remote_surf;
597 struct ivi_compositor *ivi = surface->ivi;
598 const char *_app_id =
599 weston_desktop_surface_get_app_id(surface->dsurface);
601 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
604 wl_list_for_each_safe(remote_surf, next_remote_surf,
605 &ivi->remote_pending_apps, link) {
606 if (!strcmp(_app_id, remote_surf->app_id)) {
607 surface->remote.output = remote_surf->ioutput;
608 if (!ivi_compositor_keep_pending_surfaces(surface))
609 ivi_remove_pending_desktop_surface_remote(remote_surf);
617 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
618 enum ivi_surface_role *role)
620 struct ivi_compositor *ivi = surface->ivi;
621 struct wl_list *role_pending_list;
622 struct pending_popup *p_popup;
623 struct pending_split *p_split;
624 struct pending_fullscreen *p_fullscreen;
625 struct pending_remote *p_remote;
627 weston_desktop_surface_get_app_id(surface->dsurface);
629 role_pending_list = &ivi->popup_pending_apps;
630 wl_list_for_each(p_popup, role_pending_list, link) {
631 if (app_id && !strcmp(app_id, p_popup->app_id)) {
632 *role = IVI_SURFACE_ROLE_POPUP;
637 role_pending_list = &ivi->split_pending_apps;
638 wl_list_for_each(p_split, role_pending_list, link) {
639 if (app_id && !strcmp(app_id, p_split->app_id)) {
640 *role = IVI_SURFACE_ROLE_SPLIT_V;
645 role_pending_list = &ivi->fullscreen_pending_apps;
646 wl_list_for_each(p_fullscreen, role_pending_list, link) {
647 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
648 *role = IVI_SURFACE_ROLE_FULLSCREEN;
653 role_pending_list = &ivi->remote_pending_apps;
654 wl_list_for_each(p_remote, role_pending_list, link) {
655 if (app_id && !strcmp(app_id, p_remote->app_id)) {
656 *role = IVI_SURFACE_ROLE_REMOTE;
661 /* else, we are a regular desktop surface */
662 *role = IVI_SURFACE_ROLE_DESKTOP;
667 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
671 ret = ivi_check_pending_desktop_surface_popup(surface);
673 ivi_set_desktop_surface_popup(surface);
674 ivi_layout_popup_committed(surface);
678 ret = ivi_check_pending_desktop_surface_split(surface);
680 ivi_set_desktop_surface_split(surface);
681 ivi_layout_split_committed(surface);
685 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
687 ivi_set_desktop_surface_fullscreen(surface);
688 ivi_layout_fullscreen_committed(surface);
692 ret = ivi_check_pending_desktop_surface_remote(surface);
694 ivi_set_desktop_surface_remote(surface);
695 ivi_layout_desktop_committed(surface);
699 /* if we end up here means we have a regular desktop app and
700 * try to activate it */
701 ivi_set_desktop_surface(surface);
702 ivi_layout_desktop_committed(surface);
706 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
708 struct ivi_output *out;
710 wl_list_for_each(out, &ivi->outputs, link) {
711 create_black_curtain_view(out);
712 insert_black_curtain(out);
717 ivi_shell_init(struct ivi_compositor *ivi)
719 weston_layer_init(&ivi->hidden, ivi->compositor);
720 weston_layer_init(&ivi->background, ivi->compositor);
721 weston_layer_init(&ivi->normal, ivi->compositor);
722 weston_layer_init(&ivi->panel, ivi->compositor);
723 weston_layer_init(&ivi->popup, ivi->compositor);
724 weston_layer_init(&ivi->fullscreen, ivi->compositor);
726 weston_layer_set_position(&ivi->hidden,
727 WESTON_LAYER_POSITION_HIDDEN);
728 weston_layer_set_position(&ivi->background,
729 WESTON_LAYER_POSITION_BACKGROUND);
730 weston_layer_set_position(&ivi->normal,
731 WESTON_LAYER_POSITION_NORMAL);
732 weston_layer_set_position(&ivi->panel,
733 WESTON_LAYER_POSITION_UI);
734 weston_layer_set_position(&ivi->popup,
735 WESTON_LAYER_POSITION_TOP_UI);
736 weston_layer_set_position(&ivi->fullscreen,
737 WESTON_LAYER_POSITION_FULLSCREEN);
744 ivi_surf_destroy(struct ivi_surface *surf)
746 struct weston_surface *wsurface = surf->view->surface;
748 if (weston_surface_is_mapped(wsurface)) {
749 weston_desktop_surface_unlink_view(surf->view);
750 weston_view_destroy(surf->view);
753 wl_list_remove(&surf->link);
758 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
760 struct weston_view *view, *view_next;
762 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
763 struct ivi_surface *ivi_surf =
764 get_ivi_shell_surface(view->surface);
766 ivi_surf_destroy(ivi_surf);
771 ivi_shell_finalize(struct ivi_compositor *ivi)
773 struct ivi_output *output;
775 ivi_shell_destroy_views_on_layer(&ivi->hidden);
776 weston_layer_fini(&ivi->hidden);
778 ivi_shell_destroy_views_on_layer(&ivi->background);
779 weston_layer_fini(&ivi->background);
781 ivi_shell_destroy_views_on_layer(&ivi->normal);
782 weston_layer_fini(&ivi->normal);
784 ivi_shell_destroy_views_on_layer(&ivi->panel);
785 weston_layer_fini(&ivi->panel);
787 ivi_shell_destroy_views_on_layer(&ivi->popup);
788 weston_layer_fini(&ivi->popup);
790 wl_list_for_each(output, &ivi->outputs, link) {
791 if (output->fullscreen_view.fs->view) {
792 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
793 output->fullscreen_view.fs->view = NULL;
796 weston_layer_fini(&ivi->fullscreen);
800 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
802 struct ivi_surface *surface;
804 wl_list_for_each(surface, &ivi->surfaces, link) {
806 weston_desktop_surface_get_app_id(surface->dsurface);
807 if (app_id == NULL) {
808 weston_log("WARNING app_is is null, unable to advertise\n");
811 agl_shell_desktop_send_application(resource, app_id);
816 client_exec(const char *command, int fd)
821 /* Don't give the child our signal mask */
823 sigprocmask(SIG_UNBLOCK, &sig, NULL);
825 /* Launch clients as the user; don't give them the wrong euid */
826 if (seteuid(getuid()) == -1) {
827 weston_log("seteuid failed: %s\n", strerror(errno));
831 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
832 * clobbering fd, as we'll exit/exec either way.
836 weston_log("dup failed: %s\n", strerror(errno));
840 snprintf(s, sizeof s, "%d", fd);
841 setenv("WAYLAND_SOCKET", s, 1);
843 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
844 weston_log("executing '%s' failed: %s", command, strerror(errno));
847 static struct wl_client *
848 launch_shell_client(struct ivi_compositor *ivi, const char *command)
850 struct wl_client *client;
854 weston_log("launching' %s'\n", command);
856 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
857 weston_log("socketpair failed while launching '%s': %s\n",
858 command, strerror(errno));
866 weston_log("fork failed while launching '%s': %s\n",
867 command, strerror(errno));
872 client_exec(command, sock[1]);
877 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
880 weston_log("Failed to create wayland client for '%s'",
889 ivi_launch_shell_client(struct ivi_compositor *ivi)
891 struct weston_config_section *section;
892 char *command = NULL;
894 section = weston_config_get_section(ivi->config, "shell-client",
897 weston_config_section_get_string(section, "command",
903 ivi->shell_client.client = launch_shell_client(ivi, command);
904 if (!ivi->shell_client.client)
911 destroy_black_curtain_view(struct wl_listener *listener, void *data)
913 struct fullscreen_view *fs =
914 wl_container_of(listener, fs, fs_destroy);
918 wl_list_remove(&fs->fs_destroy.link);
925 create_black_curtain_view(struct ivi_output *output)
927 struct weston_surface *surface = NULL;
928 struct weston_view *view;
929 struct ivi_compositor *ivi = output->ivi;
930 struct weston_compositor *wc= ivi->compositor;
931 struct weston_output *woutput = output->output;
936 surface = weston_surface_create(wc);
939 view = weston_view_create(surface);
941 weston_surface_destroy(surface);
945 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
946 weston_surface_set_size(surface, woutput->width, woutput->height);
947 weston_view_set_position(view, woutput->x, woutput->y);
949 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
950 if (!output->fullscreen_view.fs) {
951 weston_surface_destroy(surface);
954 output->fullscreen_view.fs->view = view;
956 output->fullscreen_view.fs_destroy.notify = destroy_black_curtain_view;
957 wl_signal_add(&woutput->destroy_signal,
958 &output->fullscreen_view.fs_destroy);
962 output_has_black_curtain(struct ivi_output *output)
964 return (output->fullscreen_view.fs->view &&
965 output->fullscreen_view.fs->view->is_mapped &&
966 output->fullscreen_view.fs->view->surface->is_mapped);
970 remove_black_curtain(struct ivi_output *output)
972 struct weston_view *view;
975 !output->fullscreen_view.fs &&
976 !output->fullscreen_view.fs->view) {
977 weston_log("Output %s doesn't have a surface installed!\n", output->name);
981 view = output->fullscreen_view.fs->view;
982 assert(view->is_mapped == true ||
983 view->surface->is_mapped == true);
985 view->is_mapped = false;
986 view->surface->is_mapped = false;
988 weston_layer_entry_remove(&view->layer_link);
989 weston_view_update_transform(view);
991 weston_view_damage_below(view);
993 weston_log("Removed black curtain from output %s\n", output->output->name);
997 insert_black_curtain(struct ivi_output *output)
999 struct weston_view *view;
1002 !output->fullscreen_view.fs &&
1003 !output->fullscreen_view.fs->view) || !output->output) {
1004 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1008 view = output->fullscreen_view.fs->view;
1009 if (view->is_mapped || view->surface->is_mapped)
1012 weston_layer_entry_remove(&view->layer_link);
1013 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1016 view->is_mapped = true;
1017 view->surface->is_mapped = true;
1019 weston_view_update_transform(view);
1020 weston_view_damage_below(view);
1022 weston_log("Added black curtain to output %s\n", output->output->name);
1026 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1028 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1029 struct ivi_output *output;
1030 struct ivi_surface *surface, *tmp;
1032 if (ivi->shell_client.resource &&
1033 ivi->shell_client.status == BOUND_FAILED) {
1034 wl_resource_post_error(shell_res,
1035 WL_DISPLAY_ERROR_INVALID_OBJECT,
1036 "agl_shell has already been bound. "
1037 "Check out bound_fail event");
1041 /* Init already finished. Do nothing */
1042 if (ivi->shell_client.ready)
1046 ivi->shell_client.ready = true;
1048 wl_list_for_each(output, &ivi->outputs, link) {
1049 if (output->background)
1050 remove_black_curtain(output);
1051 ivi_layout_init(ivi, output);
1054 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1055 wl_list_remove(&surface->link);
1056 wl_list_init(&surface->link);
1057 ivi_check_pending_desktop_surface(surface);
1058 surface->checked_pending = true;
1063 shell_set_background(struct wl_client *client,
1064 struct wl_resource *shell_res,
1065 struct wl_resource *surface_res,
1066 struct wl_resource *output_res)
1068 struct weston_head *head = weston_head_from_resource(output_res);
1069 struct weston_output *woutput = weston_head_get_output(head);
1070 struct ivi_output *output = to_ivi_output(woutput);
1071 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1072 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1073 struct weston_desktop_surface *dsurface;
1074 struct ivi_surface *surface;
1076 if (ivi->shell_client.resource &&
1077 ivi->shell_client.status == BOUND_FAILED) {
1078 wl_resource_post_error(shell_res,
1079 WL_DISPLAY_ERROR_INVALID_OBJECT,
1080 "agl_shell has already been bound. "
1081 "Check out bound_fail event");
1085 dsurface = weston_surface_get_desktop_surface(wsurface);
1087 wl_resource_post_error(shell_res,
1088 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1089 "surface must be a desktop surface");
1093 surface = weston_desktop_surface_get_user_data(dsurface);
1094 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1095 wl_resource_post_error(shell_res,
1096 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1097 "surface already has another ivi role");
1101 if (output->background) {
1102 wl_resource_post_error(shell_res,
1103 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1104 "output already has background");
1108 surface->checked_pending = true;
1109 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1110 surface->bg.output = output;
1111 wl_list_remove(&surface->link);
1112 wl_list_init(&surface->link);
1114 output->background = surface;
1116 weston_desktop_surface_set_maximized(dsurface, true);
1117 weston_desktop_surface_set_size(dsurface,
1118 output->output->width,
1119 output->output->height);
1123 shell_set_panel(struct wl_client *client,
1124 struct wl_resource *shell_res,
1125 struct wl_resource *surface_res,
1126 struct wl_resource *output_res,
1129 struct weston_head *head = weston_head_from_resource(output_res);
1130 struct weston_output *woutput = weston_head_get_output(head);
1131 struct ivi_output *output = to_ivi_output(woutput);
1132 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1133 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1134 struct weston_desktop_surface *dsurface;
1135 struct ivi_surface *surface;
1136 struct ivi_surface **member;
1137 int32_t width = 0, height = 0;
1139 if (ivi->shell_client.resource &&
1140 ivi->shell_client.status == BOUND_FAILED) {
1141 wl_resource_post_error(shell_res,
1142 WL_DISPLAY_ERROR_INVALID_OBJECT,
1143 "agl_shell has already been bound. "
1144 "Check out bound_fail event");
1148 dsurface = weston_surface_get_desktop_surface(wsurface);
1150 wl_resource_post_error(shell_res,
1151 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1152 "surface must be a desktop surface");
1156 surface = weston_desktop_surface_get_user_data(dsurface);
1157 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1158 wl_resource_post_error(shell_res,
1159 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1160 "surface already has another ivi role");
1165 case AGL_SHELL_EDGE_TOP:
1166 member = &output->top;
1168 case AGL_SHELL_EDGE_BOTTOM:
1169 member = &output->bottom;
1171 case AGL_SHELL_EDGE_LEFT:
1172 member = &output->left;
1174 case AGL_SHELL_EDGE_RIGHT:
1175 member = &output->right;
1178 wl_resource_post_error(shell_res,
1179 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1180 "invalid edge for panel");
1185 wl_resource_post_error(shell_res,
1186 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1187 "output already has panel on this edge");
1191 surface->checked_pending = true;
1192 surface->role = IVI_SURFACE_ROLE_PANEL;
1193 surface->panel.output = output;
1194 surface->panel.edge = edge;
1195 wl_list_remove(&surface->link);
1196 wl_list_init(&surface->link);
1200 switch (surface->panel.edge) {
1201 case AGL_SHELL_EDGE_TOP:
1202 case AGL_SHELL_EDGE_BOTTOM:
1203 width = woutput->width;
1205 case AGL_SHELL_EDGE_LEFT:
1206 case AGL_SHELL_EDGE_RIGHT:
1207 height = woutput->height;
1211 weston_desktop_surface_set_size(dsurface, width, height);
1215 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1216 const char *data, uint32_t app_state)
1218 struct desktop_client *dclient;
1220 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1221 struct ivi_policy *policy = ivi->policy;
1223 /* FIXME: should queue it here and see when binding agl-shell-desktop
1224 * if there are any to be sent */
1231 if (policy && policy->api.surface_advertise_state_change &&
1232 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1236 app_role = surf->role;
1237 if (app_role == IVI_SURFACE_ROLE_POPUP)
1238 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1240 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1241 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1242 data, app_state, app_role);
1246 shell_activate_app(struct wl_client *client,
1247 struct wl_resource *shell_res,
1249 struct wl_resource *output_res)
1251 struct weston_head *head = weston_head_from_resource(output_res);
1252 struct weston_output *woutput = weston_head_get_output(head);
1253 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1254 struct ivi_output *output = to_ivi_output(woutput);
1256 if (ivi->shell_client.resource &&
1257 ivi->shell_client.status == BOUND_FAILED) {
1258 wl_resource_post_error(shell_res,
1259 WL_DISPLAY_ERROR_INVALID_OBJECT,
1260 "agl_shell has already been bound. "
1261 "Check out bound_fail event");
1265 ivi_layout_activate(output, app_id);
1269 shell_desktop_activate_app(struct wl_client *client,
1270 struct wl_resource *shell_res,
1271 const char *app_id, const char *data,
1272 struct wl_resource *output_res)
1274 struct weston_head *head = weston_head_from_resource(output_res);
1275 struct weston_output *woutput = weston_head_get_output(head);
1276 struct ivi_output *output = to_ivi_output(woutput);
1278 ivi_layout_activate(output, app_id);
1279 shell_advertise_app_state(output->ivi, app_id,
1280 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1284 shell_deactivate_app(struct wl_client *client,
1285 struct wl_resource *shell_res,
1288 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1289 struct ivi_compositor *ivi = dclient->ivi;
1291 ivi_layout_deactivate(ivi, app_id);
1292 shell_advertise_app_state(ivi, app_id,
1293 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1296 /* stub, no usage for the time being */
1298 shell_destroy(struct wl_client *client, struct wl_resource *res)
1302 static const struct agl_shell_interface agl_shell_implementation = {
1303 .destroy = shell_destroy,
1304 .ready = shell_ready,
1305 .set_background = shell_set_background,
1306 .set_panel = shell_set_panel,
1307 .activate_app = shell_activate_app,
1311 shell_desktop_set_app_property(struct wl_client *client,
1312 struct wl_resource *shell_res,
1313 const char *app_id, uint32_t role,
1314 int x, int y, int bx, int by,
1315 int width, int height,
1316 struct wl_resource *output_res)
1318 struct weston_head *head = weston_head_from_resource(output_res);
1319 struct weston_output *woutput = weston_head_get_output(head);
1320 struct ivi_output *output = to_ivi_output(woutput);
1323 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1324 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1325 width, height, app_id);
1327 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1328 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1330 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1331 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1332 ivi_set_pending_desktop_surface_split(output, app_id, role);
1334 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1335 ivi_set_pending_desktop_surface_remote(output, app_id);
1343 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1345 struct pending_popup *p_popup, *next_p_popup;
1346 struct pending_split *split_surf, *next_split_surf;
1347 struct pending_fullscreen *fs_surf, *next_fs_surf;
1348 struct pending_remote *remote_surf, *next_remote_surf;
1350 wl_list_for_each_safe(p_popup, next_p_popup,
1351 &ivi->popup_pending_apps, link)
1352 ivi_remove_pending_desktop_surface_popup(p_popup);
1354 wl_list_for_each_safe(split_surf, next_split_surf,
1355 &ivi->split_pending_apps, link)
1356 ivi_remove_pending_desktop_surface_split(split_surf);
1358 wl_list_for_each_safe(fs_surf, next_fs_surf,
1359 &ivi->fullscreen_pending_apps, link)
1360 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1362 wl_list_for_each_safe(remote_surf, next_remote_surf,
1363 &ivi->remote_pending_apps, link)
1364 ivi_remove_pending_desktop_surface_remote(remote_surf);
1368 shell_desktop_set_app_property_mode(struct wl_client *client,
1369 struct wl_resource *shell_res, uint32_t perm)
1371 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1373 dclient->ivi->keep_pending_surfaces = true;
1375 dclient->ivi->keep_pending_surfaces = false;
1376 /* remove any previous pending surfaces */
1377 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1381 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1382 .activate_app = shell_desktop_activate_app,
1383 .set_app_property = shell_desktop_set_app_property,
1384 .deactivate_app = shell_deactivate_app,
1385 .set_app_property_mode = shell_desktop_set_app_property_mode,
1389 unbind_agl_shell(struct wl_resource *resource)
1391 struct ivi_compositor *ivi;
1392 struct ivi_output *output;
1393 struct ivi_surface *surf, *surf_tmp;
1395 ivi = wl_resource_get_user_data(resource);
1397 /* reset status to allow other clients issue legit requests */
1398 if (ivi->shell_client.resource &&
1399 ivi->shell_client.status == BOUND_FAILED) {
1400 ivi->shell_client.status = BOUND_OK;
1404 wl_list_for_each(output, &ivi->outputs, link) {
1405 /* reset the active surf if there's one present */
1406 if (output->active) {
1407 output->active->view->is_mapped = false;
1408 output->active->view->surface->is_mapped = false;
1410 weston_layer_entry_remove(&output->active->view->layer_link);
1411 output->active = NULL;
1414 insert_black_curtain(output);
1417 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1418 wl_list_remove(&surf->link);
1419 wl_list_init(&surf->link);
1422 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1423 wl_list_remove(&surf->link);
1424 wl_list_init(&surf->link);
1427 wl_list_init(&ivi->surfaces);
1428 wl_list_init(&ivi->pending_surfaces);
1430 ivi->shell_client.ready = false;
1431 ivi->shell_client.resource = NULL;
1432 ivi->shell_client.client = NULL;
1436 bind_agl_shell(struct wl_client *client,
1437 void *data, uint32_t version, uint32_t id)
1439 struct ivi_compositor *ivi = data;
1440 struct wl_resource *resource;
1441 struct ivi_policy *policy;
1444 policy = ivi->policy;
1445 interface = (void *) &agl_shell_interface;
1446 if (policy && policy->api.shell_bind_interface &&
1447 !policy->api.shell_bind_interface(client, interface)) {
1448 wl_client_post_implementation_error(client,
1449 "client not authorized to use agl_shell");
1453 resource = wl_resource_create(client, &agl_shell_interface, version, id);
1455 wl_client_post_no_memory(client);
1459 if (ivi->shell_client.resource) {
1460 if (wl_resource_get_version(resource) == 1) {
1461 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1462 "agl_shell has already been bound");
1466 agl_shell_send_bound_fail(resource);
1467 ivi->shell_client.status = BOUND_FAILED;
1470 wl_resource_set_implementation(resource, &agl_shell_implementation,
1471 ivi, unbind_agl_shell);
1472 ivi->shell_client.resource = resource;
1474 if (ivi->shell_client.status == BOUND_OK &&
1475 wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION)
1476 agl_shell_send_bound_ok(ivi->shell_client.resource);
1480 unbind_agl_shell_desktop(struct wl_resource *resource)
1482 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1484 wl_list_remove(&dclient->link);
1489 bind_agl_shell_desktop(struct wl_client *client,
1490 void *data, uint32_t version, uint32_t id)
1492 struct ivi_compositor *ivi = data;
1493 struct wl_resource *resource;
1494 struct ivi_policy *policy;
1495 struct desktop_client *dclient;
1498 policy = ivi->policy;
1499 interface = (void *) &agl_shell_desktop_interface;
1500 if (policy && policy->api.shell_bind_interface &&
1501 !policy->api.shell_bind_interface(client, interface)) {
1502 wl_client_post_implementation_error(client,
1503 "client not authorized to use agl_shell_desktop");
1507 dclient = zalloc(sizeof(*dclient));
1509 wl_client_post_no_memory(client);
1513 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1517 wl_client_post_no_memory(client);
1521 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1522 dclient, unbind_agl_shell_desktop);
1524 dclient->resource = resource;
1525 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1527 /* advertise xdg surfaces */
1528 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1532 ivi_shell_create_global(struct ivi_compositor *ivi)
1534 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1535 &agl_shell_interface, 2,
1536 ivi, bind_agl_shell);
1537 if (!ivi->agl_shell) {
1538 weston_log("Failed to create wayland global.\n");
1542 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1543 &agl_shell_desktop_interface, 2,
1544 ivi, bind_agl_shell_desktop);
1545 if (!ivi->agl_shell_desktop) {
1546 weston_log("Failed to create wayland global (agl_shell_desktop).\n");