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>
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_desktop_surface_popup(struct ivi_surface *surface)
97 struct ivi_compositor *ivi = surface->ivi;
98 assert(surface->role == IVI_SURFACE_ROLE_NONE);
100 surface->role = IVI_SURFACE_ROLE_POPUP;
101 wl_list_insert(&ivi->surfaces, &surface->link);
103 agl_shell_desktop_advertise_application_id(ivi, surface);
107 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
109 struct ivi_compositor *ivi = surface->ivi;
110 assert(surface->role == IVI_SURFACE_ROLE_NONE);
112 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
113 wl_list_insert(&ivi->surfaces, &surface->link);
115 agl_shell_desktop_advertise_application_id(ivi, surface);
120 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
122 struct ivi_compositor *ivi = surface->ivi;
123 const struct weston_transmitter_api *api =
124 ivi->waltham_transmitter_api;
129 if (surface->waltham_surface.transmitter_surface)
130 api->surface_destroy(surface->waltham_surface.transmitter_surface);
134 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
136 struct ivi_compositor *ivi = surface->ivi;
137 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
138 struct weston_transmitter *transmitter;
139 struct weston_transmitter_remote *trans_remote;
140 struct weston_surface *weston_surface;
141 struct weston_output *woutput = surface->remote.output->output;
147 transmitter = api->transmitter_get(ivi->compositor);
151 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
153 weston_log("Could not find a valie weston_transmitter_remote "
154 "that matches the output %s\n", woutput->name);
158 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
160 weston_desktop_surface_get_surface(surface->dsurface);
162 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
164 /* this will have the effect of informing the remote side to create a
165 * surface with the name app_id. W/ xdg-shell the following happens:
167 * compositor (server):
168 * surface_push_to_remote():
169 * waltham-transmitter plug-in
170 * -> wthp_ivi_app_id_surface_create()
172 * client -- on the receiver side:
173 * -> wthp_ivi_app_id_surface_create()
174 * -> wth_receiver_weston_main()
175 * -> wl_compositor_create_surface()
176 * -> xdg_wm_base_get_xdg_surface
177 * -> xdg_toplevel_set_app_id()
179 * -> gst_parse_launch()
181 * wth_receiver_weston_main() will be invoked from the handler of
182 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
183 * the gstreamer pipeline as well.
185 surface->waltham_surface.transmitter_surface =
186 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
191 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
195 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
201 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
203 struct ivi_compositor *ivi = surface->ivi;
204 struct weston_view *view;
205 struct ivi_output *output = surface->remote.output;
207 assert(surface->role == IVI_SURFACE_ROLE_NONE);
209 /* remote type are the same as desktop just that client can tell
210 * the compositor to start on another output */
211 surface->role = IVI_SURFACE_ROLE_REMOTE;
213 /* if thew black surface view is mapped on the mean we need
214 * to remove it in order to start showing the 'remote' surface
215 * just being added */
216 view = output->fullscreen_view.fs->view;
217 if (view->is_mapped || view->surface->is_mapped)
218 remove_black_curtain(output);
220 if (output->type == OUTPUT_WALTHAM)
221 ivi_output_notify_waltham_plugin(surface);
223 wl_list_insert(&ivi->surfaces, &surface->link);
228 ivi_set_desktop_surface_split(struct ivi_surface *surface)
230 struct ivi_compositor *ivi = surface->ivi;
231 assert(surface->role == IVI_SURFACE_ROLE_NONE);
233 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
234 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
236 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
238 wl_list_insert(&ivi->surfaces, &surface->link);
240 agl_shell_desktop_advertise_application_id(ivi, surface);
243 static struct pending_popup *
244 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
245 int width, int height, const char *app_id)
247 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
248 size_t len_app_id = strlen(app_id);
252 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
253 if (!p_popup->app_id) {
257 memcpy(p_popup->app_id, app_id, len_app_id);
258 p_popup->ioutput = ioutput;
264 p_popup->bb.width = width;
265 p_popup->bb.height = height;
271 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
272 int width, int height, const char *app_id, struct pending_popup *p_popup)
274 size_t len_app_id = strlen(app_id);
276 wl_list_remove(&p_popup->link);
277 wl_list_init(&p_popup->link);
279 memset(p_popup->app_id, 0, strlen(app_id) + 1);
280 free(p_popup->app_id);
282 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
283 if (!p_popup->app_id)
285 memcpy(p_popup->app_id, app_id, len_app_id);
287 p_popup->ioutput = ioutput;
293 p_popup->bb.width = width;
294 p_popup->bb.height = height;
297 static struct pending_fullscreen *
298 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
300 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
301 size_t len_app_id = strlen(app_id);
305 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
306 if (!p_fullscreen->app_id) {
310 memcpy(p_fullscreen->app_id, app_id, len_app_id);
312 p_fullscreen->ioutput = ioutput;
317 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
318 struct pending_fullscreen *p_fullscreen)
320 size_t len_app_id = strlen(app_id);
322 wl_list_remove(&p_fullscreen->link);
323 wl_list_init(&p_fullscreen->link);
325 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
326 free(p_fullscreen->app_id);
328 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
329 if (!p_fullscreen->app_id)
331 memcpy(p_fullscreen->app_id, app_id, len_app_id);
333 p_fullscreen->ioutput = ioutput;
336 static struct pending_remote *
337 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
339 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
340 size_t len_app_id = strlen(app_id);
344 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
345 if (!p_remote->app_id) {
349 memcpy(p_remote->app_id, app_id, len_app_id);
351 p_remote->ioutput = ioutput;
356 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
357 struct pending_remote *p_remote)
359 size_t len_app_id = strlen(app_id);
361 wl_list_remove(&p_remote->link);
362 wl_list_init(&p_remote->link);
364 memset(p_remote->app_id, 0, strlen(app_id) + 1);
365 free(p_remote->app_id);
367 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
368 if (!p_remote->app_id)
370 memcpy(p_remote->app_id, app_id, len_app_id);
372 p_remote->ioutput = ioutput;
376 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
377 int by, int width, int height, const char *app_id)
379 struct ivi_compositor *ivi = ioutput->ivi;
380 struct pending_popup *p_popup = NULL;
381 struct pending_popup *popup;
383 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
384 if (!strcmp(app_id, popup->app_id))
388 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
390 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
394 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
398 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
401 struct ivi_compositor *ivi = ioutput->ivi;
402 struct pending_fullscreen *p_fullscreen = NULL;
403 struct pending_fullscreen *fullscreen;
405 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
406 if (!strcmp(app_id, fullscreen->app_id))
407 p_fullscreen = fullscreen;
410 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
412 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
416 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
420 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
421 const char *app_id, uint32_t orientation)
423 struct ivi_compositor *ivi = ioutput->ivi;
424 struct ivi_surface *surf;
425 size_t len_app_id = strlen(app_id);
426 struct pending_split *split;
428 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
429 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
432 /* more than one is un-supported, do note we need to do
433 * conversion for surface roles instead of using the protocol ones */
434 wl_list_for_each(surf, &ivi->surfaces, link)
435 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
436 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
439 split = zalloc(sizeof(*split));
442 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
443 if (!split->app_id) {
447 memcpy(split->app_id, app_id, len_app_id);
449 split->ioutput = ioutput;
450 split->orientation = orientation;
452 wl_list_insert(&ivi->split_pending_apps, &split->link);
456 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
459 struct ivi_compositor *ivi = ioutput->ivi;
460 struct pending_remote *remote;
461 struct pending_remote *p_remote = NULL;
463 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
464 if (!strcmp(app_id, remote->app_id))
468 p_remote = ivi_ensure_remote(ioutput, app_id);
470 ivi_update_remote(ioutput, app_id, p_remote);
474 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
479 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
482 wl_list_remove(&split->link);
487 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
490 wl_list_remove(&fs->link);
495 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
497 free(p_popup->app_id);
498 wl_list_remove(&p_popup->link);
503 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
505 free(remote->app_id);
506 wl_list_remove(&remote->link);
511 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
513 return surface->ivi->keep_pending_surfaces;
517 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
519 struct ivi_compositor *ivi = surface->ivi;
520 struct pending_popup *p_popup, *next_p_popup;
521 const char *_app_id =
522 weston_desktop_surface_get_app_id(surface->dsurface);
524 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
527 wl_list_for_each_safe(p_popup, next_p_popup,
528 &ivi->popup_pending_apps, link) {
529 if (!strcmp(_app_id, p_popup->app_id)) {
530 surface->popup.output = p_popup->ioutput;
531 surface->popup.x = p_popup->x;
532 surface->popup.y = p_popup->y;
534 surface->popup.bb.x = p_popup->bb.x;
535 surface->popup.bb.y = p_popup->bb.y;
536 surface->popup.bb.width = p_popup->bb.width;
537 surface->popup.bb.height = p_popup->bb.height;
539 if (!ivi_compositor_keep_pending_surfaces(surface))
540 ivi_remove_pending_desktop_surface_popup(p_popup);
549 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
551 struct pending_split *split_surf, *next_split_surf;
552 struct ivi_compositor *ivi = surface->ivi;
553 const char *_app_id =
554 weston_desktop_surface_get_app_id(surface->dsurface);
556 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
559 wl_list_for_each_safe(split_surf, next_split_surf,
560 &ivi->split_pending_apps, link) {
561 if (!strcmp(_app_id, split_surf->app_id)) {
562 surface->split.output = split_surf->ioutput;
563 surface->split.orientation = split_surf->orientation;
564 if (!ivi_compositor_keep_pending_surfaces(surface))
565 ivi_remove_pending_desktop_surface_split(split_surf);
574 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
576 struct pending_fullscreen *fs_surf, *next_fs_surf;
577 struct ivi_compositor *ivi = surface->ivi;
578 const char *_app_id =
579 weston_desktop_surface_get_app_id(surface->dsurface);
581 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
584 wl_list_for_each_safe(fs_surf, next_fs_surf,
585 &ivi->fullscreen_pending_apps, link) {
586 if (!strcmp(_app_id, fs_surf->app_id)) {
587 surface->fullscreen.output = fs_surf->ioutput;
588 if (!ivi_compositor_keep_pending_surfaces(surface))
589 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
598 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
600 struct pending_remote *remote_surf, *next_remote_surf;
601 struct ivi_compositor *ivi = surface->ivi;
602 const char *_app_id =
603 weston_desktop_surface_get_app_id(surface->dsurface);
605 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
608 wl_list_for_each_safe(remote_surf, next_remote_surf,
609 &ivi->remote_pending_apps, link) {
610 if (!strcmp(_app_id, remote_surf->app_id)) {
611 surface->remote.output = remote_surf->ioutput;
612 if (!ivi_compositor_keep_pending_surfaces(surface))
613 ivi_remove_pending_desktop_surface_remote(remote_surf);
621 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
622 enum ivi_surface_role *role)
624 struct ivi_compositor *ivi = surface->ivi;
625 struct wl_list *role_pending_list;
626 struct pending_popup *p_popup;
627 struct pending_split *p_split;
628 struct pending_fullscreen *p_fullscreen;
629 struct pending_remote *p_remote;
631 weston_desktop_surface_get_app_id(surface->dsurface);
633 role_pending_list = &ivi->popup_pending_apps;
634 wl_list_for_each(p_popup, role_pending_list, link) {
635 if (app_id && !strcmp(app_id, p_popup->app_id)) {
636 *role = IVI_SURFACE_ROLE_POPUP;
641 role_pending_list = &ivi->split_pending_apps;
642 wl_list_for_each(p_split, role_pending_list, link) {
643 if (app_id && !strcmp(app_id, p_split->app_id)) {
644 *role = IVI_SURFACE_ROLE_SPLIT_V;
649 role_pending_list = &ivi->fullscreen_pending_apps;
650 wl_list_for_each(p_fullscreen, role_pending_list, link) {
651 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
652 *role = IVI_SURFACE_ROLE_FULLSCREEN;
657 role_pending_list = &ivi->remote_pending_apps;
658 wl_list_for_each(p_remote, role_pending_list, link) {
659 if (app_id && !strcmp(app_id, p_remote->app_id)) {
660 *role = IVI_SURFACE_ROLE_REMOTE;
665 /* else, we are a regular desktop surface */
666 *role = IVI_SURFACE_ROLE_DESKTOP;
671 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
675 ret = ivi_check_pending_desktop_surface_popup(surface);
677 ivi_set_desktop_surface_popup(surface);
678 ivi_layout_popup_committed(surface);
682 ret = ivi_check_pending_desktop_surface_split(surface);
684 ivi_set_desktop_surface_split(surface);
685 ivi_layout_split_committed(surface);
689 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
691 ivi_set_desktop_surface_fullscreen(surface);
692 ivi_layout_fullscreen_committed(surface);
696 ret = ivi_check_pending_desktop_surface_remote(surface);
698 ivi_set_desktop_surface_remote(surface);
699 ivi_layout_desktop_committed(surface);
703 /* if we end up here means we have a regular desktop app and
704 * try to activate it */
705 ivi_set_desktop_surface(surface);
706 ivi_layout_desktop_committed(surface);
710 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
712 struct ivi_output *out;
714 wl_list_for_each(out, &ivi->outputs, link) {
715 create_black_curtain_view(out);
716 insert_black_curtain(out);
721 ivi_shell_init(struct ivi_compositor *ivi)
723 weston_layer_init(&ivi->hidden, ivi->compositor);
724 weston_layer_init(&ivi->background, ivi->compositor);
725 weston_layer_init(&ivi->normal, ivi->compositor);
726 weston_layer_init(&ivi->panel, ivi->compositor);
727 weston_layer_init(&ivi->popup, ivi->compositor);
728 weston_layer_init(&ivi->fullscreen, ivi->compositor);
730 weston_layer_set_position(&ivi->hidden,
731 WESTON_LAYER_POSITION_HIDDEN);
732 weston_layer_set_position(&ivi->background,
733 WESTON_LAYER_POSITION_BACKGROUND);
734 weston_layer_set_position(&ivi->normal,
735 WESTON_LAYER_POSITION_NORMAL);
736 weston_layer_set_position(&ivi->panel,
737 WESTON_LAYER_POSITION_UI);
738 weston_layer_set_position(&ivi->popup,
739 WESTON_LAYER_POSITION_TOP_UI);
740 weston_layer_set_position(&ivi->fullscreen,
741 WESTON_LAYER_POSITION_FULLSCREEN);
748 ivi_surf_destroy(struct ivi_surface *surf)
750 struct weston_surface *wsurface = surf->view->surface;
752 if (weston_surface_is_mapped(wsurface)) {
753 weston_desktop_surface_unlink_view(surf->view);
754 weston_view_destroy(surf->view);
757 wl_list_remove(&surf->link);
762 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
764 struct weston_view *view, *view_next;
766 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
767 struct ivi_surface *ivi_surf =
768 get_ivi_shell_surface(view->surface);
770 ivi_surf_destroy(ivi_surf);
775 ivi_shell_finalize(struct ivi_compositor *ivi)
777 struct ivi_output *output;
779 ivi_shell_destroy_views_on_layer(&ivi->hidden);
780 weston_layer_fini(&ivi->hidden);
782 ivi_shell_destroy_views_on_layer(&ivi->background);
783 weston_layer_fini(&ivi->background);
785 ivi_shell_destroy_views_on_layer(&ivi->normal);
786 weston_layer_fini(&ivi->normal);
788 ivi_shell_destroy_views_on_layer(&ivi->panel);
789 weston_layer_fini(&ivi->panel);
791 ivi_shell_destroy_views_on_layer(&ivi->popup);
792 weston_layer_fini(&ivi->popup);
794 wl_list_for_each(output, &ivi->outputs, link) {
795 if (output->fullscreen_view.fs->view) {
796 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
797 output->fullscreen_view.fs->view = NULL;
800 weston_layer_fini(&ivi->fullscreen);
804 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
806 struct ivi_surface *surface;
808 wl_list_for_each(surface, &ivi->surfaces, link) {
810 weston_desktop_surface_get_app_id(surface->dsurface);
811 if (app_id == NULL) {
812 weston_log("WARNING app_is is null, unable to advertise\n");
815 agl_shell_desktop_send_application(resource, app_id);
819 static struct wl_client *
820 client_launch(struct weston_compositor *compositor,
821 struct weston_process *proc,
823 weston_process_cleanup_func_t cleanup)
825 struct wl_client *client = NULL;
826 struct custom_env child_env;
827 struct fdstr wayland_socket;
828 const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket";
829 const char *fail_seteuid = "Couldn't call seteuid";
836 struct ivi_compositor *ivi;
837 size_t written __attribute__((unused));
839 weston_log("launching '%s'\n", path);
840 str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
842 custom_env_init_from_environ(&child_env);
843 custom_env_add_from_exec_string(&child_env, path);
845 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
846 wayland_socket.fds) < 0) {
847 weston_log("client_launch: "
848 "socketpair failed while launching '%s': %s\n",
849 path, strerror(errno));
850 custom_env_fini(&child_env);
853 fdstr_update_str1(&wayland_socket);
854 custom_env_set_env_var(&child_env, "WAYLAND_SOCKET",
855 wayland_socket.str1);
857 argp = custom_env_get_argp(&child_env);
858 envp = custom_env_get_envp(&child_env);
863 /* Put the client in a new session so it won't catch signals
864 * intended for the parent. Sharing a session can be
865 * confusing when launching weston under gdb, as the ctrl-c
866 * intended for gdb will pass to the child, and weston
867 * will cleanly shut down when the child exits.
871 /* do not give our signal mask to the new process */
872 sigfillset(&allsigs);
873 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
875 /* Launch clients as the user. Do not launch clients with wrong euid. */
876 if (seteuid(getuid()) == -1) {
877 written = write(STDERR_FILENO, fail_seteuid, strlen(fail_seteuid));
881 ret = fdstr_clear_cloexec_fd1(&wayland_socket);
883 written = write(STDERR_FILENO, fail_cloexec, strlen(fail_cloexec));
887 execve(argp[0], argp, envp);
890 written = write(STDERR_FILENO, fail_exec, strlen(fail_exec));
894 close(wayland_socket.fds[1]);
895 ivi = weston_compositor_get_user_data(compositor);
896 client = wl_client_create(compositor->wl_display,
897 wayland_socket.fds[0]);
899 custom_env_fini(&child_env);
900 close(wayland_socket.fds[0]);
902 weston_log("client_launch: "
903 "wl_client_create failed while launching '%s'.\n",
909 proc->cleanup = cleanup;
910 wl_list_insert(&ivi->child_process_list, &proc->link);
914 fdstr_close_all(&wayland_socket);
915 weston_log("client_launch: "
916 "fork failed while launching '%s': %s\n", path,
921 custom_env_fini(&child_env);
927 struct process_info {
928 struct weston_process proc;
933 sigchld_handler(int signal_number, void *data)
935 struct weston_process *p;
936 struct ivi_compositor *ivi = data;
940 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
941 wl_list_for_each(p, &ivi->child_process_list, link) {
946 if (&p->link == &ivi->child_process_list) {
947 weston_log("unknown child process exited\n");
951 wl_list_remove(&p->link);
952 wl_list_init(&p->link);
953 p->cleanup(p, status);
956 if (pid < 0 && errno != ECHILD)
957 weston_log("waitpid error %s\n", strerror(errno));
964 process_handle_sigchld(struct weston_process *process, int status)
966 struct process_info *pinfo =
967 container_of(process, struct process_info, proc);
970 * There are no guarantees whether this runs before or after
971 * the wl_client destructor.
974 if (WIFEXITED(status)) {
975 weston_log("%s exited with status %d\n", pinfo->path,
976 WEXITSTATUS(status));
977 } else if (WIFSIGNALED(status)) {
978 weston_log("%s died on signal %d\n", pinfo->path,
981 weston_log("%s disappeared\n", pinfo->path);
989 ivi_launch_shell_client(struct ivi_compositor *ivi)
991 struct process_info *pinfo;
992 struct weston_config_section *section;
993 char *command = NULL;
995 section = weston_config_get_section(ivi->config, "shell-client",
998 weston_config_section_get_string(section, "command",
1004 pinfo = zalloc(sizeof *pinfo);
1008 pinfo->path = strdup(command);
1012 ivi->shell_client.client = client_launch(ivi->compositor, &pinfo->proc,
1013 command, process_handle_sigchld);
1014 if (!ivi->shell_client.client)
1029 destroy_black_curtain_view(struct wl_listener *listener, void *data)
1031 struct fullscreen_view *fs =
1032 wl_container_of(listener, fs, fs_destroy);
1036 wl_list_remove(&fs->fs_destroy.link);
1043 create_black_curtain_view(struct ivi_output *output)
1045 struct weston_surface *surface = NULL;
1046 struct weston_view *view;
1047 struct ivi_compositor *ivi = output->ivi;
1048 struct weston_compositor *wc= ivi->compositor;
1049 struct weston_output *woutput = output->output;
1054 surface = weston_surface_create(wc);
1057 view = weston_view_create(surface);
1059 weston_surface_destroy(surface);
1063 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1064 weston_surface_set_size(surface, woutput->width, woutput->height);
1065 weston_view_set_position(view, woutput->x, woutput->y);
1067 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
1068 if (!output->fullscreen_view.fs) {
1069 weston_surface_destroy(surface);
1072 output->fullscreen_view.fs->view = view;
1074 output->fullscreen_view.fs_destroy.notify = destroy_black_curtain_view;
1075 wl_signal_add(&woutput->destroy_signal,
1076 &output->fullscreen_view.fs_destroy);
1080 output_has_black_curtain(struct ivi_output *output)
1082 return (output->fullscreen_view.fs->view &&
1083 output->fullscreen_view.fs->view->is_mapped &&
1084 output->fullscreen_view.fs->view->surface->is_mapped);
1088 remove_black_curtain(struct ivi_output *output)
1090 struct weston_view *view;
1093 !output->fullscreen_view.fs &&
1094 !output->fullscreen_view.fs->view) {
1095 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1099 view = output->fullscreen_view.fs->view;
1100 assert(view->is_mapped == true ||
1101 view->surface->is_mapped == true);
1103 view->is_mapped = false;
1104 view->surface->is_mapped = false;
1106 weston_layer_entry_remove(&view->layer_link);
1107 weston_view_update_transform(view);
1109 weston_view_damage_below(view);
1111 weston_log("Removed black curtain from output %s\n", output->output->name);
1115 insert_black_curtain(struct ivi_output *output)
1117 struct weston_view *view;
1120 !output->fullscreen_view.fs &&
1121 !output->fullscreen_view.fs->view) || !output->output) {
1122 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1126 view = output->fullscreen_view.fs->view;
1127 if (view->is_mapped || view->surface->is_mapped)
1130 weston_layer_entry_remove(&view->layer_link);
1131 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1134 view->is_mapped = true;
1135 view->surface->is_mapped = true;
1137 weston_view_update_transform(view);
1138 weston_view_damage_below(view);
1140 weston_log("Added black curtain to output %s\n", output->output->name);
1144 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1146 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1147 struct ivi_output *output;
1148 struct ivi_surface *surface, *tmp;
1150 if (ivi->shell_client.resource &&
1151 ivi->shell_client.status == BOUND_FAILED) {
1152 wl_resource_post_error(shell_res,
1153 WL_DISPLAY_ERROR_INVALID_OBJECT,
1154 "agl_shell has already been bound. "
1155 "Check out bound_fail event");
1159 /* Init already finished. Do nothing */
1160 if (ivi->shell_client.ready)
1164 ivi->shell_client.ready = true;
1166 wl_list_for_each(output, &ivi->outputs, link) {
1167 if (output->background)
1168 remove_black_curtain(output);
1169 ivi_layout_init(ivi, output);
1172 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1175 wl_list_remove(&surface->link);
1176 wl_list_init(&surface->link);
1177 ivi_check_pending_desktop_surface(surface);
1178 surface->checked_pending = true;
1179 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1182 wl_resource_get_version(ivi->shell_client.resource) >=
1183 AGL_SHELL_APP_STATE_SINCE_VERSION)
1184 agl_shell_send_app_state(ivi->shell_client.resource,
1185 app_id, AGL_SHELL_APP_STATE_STARTED);
1190 shell_set_background(struct wl_client *client,
1191 struct wl_resource *shell_res,
1192 struct wl_resource *surface_res,
1193 struct wl_resource *output_res)
1195 struct weston_head *head = weston_head_from_resource(output_res);
1196 struct weston_output *woutput = weston_head_get_output(head);
1197 struct ivi_output *output = to_ivi_output(woutput);
1198 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1199 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1200 struct weston_desktop_surface *dsurface;
1201 struct ivi_surface *surface;
1203 if (ivi->shell_client.resource &&
1204 ivi->shell_client.status == BOUND_FAILED) {
1205 wl_resource_post_error(shell_res,
1206 WL_DISPLAY_ERROR_INVALID_OBJECT,
1207 "agl_shell has already been bound. "
1208 "Check out bound_fail event");
1212 dsurface = weston_surface_get_desktop_surface(wsurface);
1214 wl_resource_post_error(shell_res,
1215 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1216 "surface must be a desktop surface");
1220 surface = weston_desktop_surface_get_user_data(dsurface);
1221 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1222 wl_resource_post_error(shell_res,
1223 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1224 "surface already has another ivi role");
1228 if (output->background) {
1229 wl_resource_post_error(shell_res,
1230 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1231 "output already has background");
1235 surface->checked_pending = true;
1236 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1237 surface->bg.output = output;
1238 wl_list_remove(&surface->link);
1239 wl_list_init(&surface->link);
1241 output->background = surface;
1243 weston_desktop_surface_set_maximized(dsurface, true);
1244 weston_desktop_surface_set_size(dsurface,
1245 output->output->width,
1246 output->output->height);
1250 shell_set_panel(struct wl_client *client,
1251 struct wl_resource *shell_res,
1252 struct wl_resource *surface_res,
1253 struct wl_resource *output_res,
1256 struct weston_head *head = weston_head_from_resource(output_res);
1257 struct weston_output *woutput = weston_head_get_output(head);
1258 struct ivi_output *output = to_ivi_output(woutput);
1259 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1260 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1261 struct weston_desktop_surface *dsurface;
1262 struct ivi_surface *surface;
1263 struct ivi_surface **member;
1264 int32_t width = 0, height = 0;
1266 if (ivi->shell_client.resource &&
1267 ivi->shell_client.status == BOUND_FAILED) {
1268 wl_resource_post_error(shell_res,
1269 WL_DISPLAY_ERROR_INVALID_OBJECT,
1270 "agl_shell has already been bound. "
1271 "Check out bound_fail event");
1275 dsurface = weston_surface_get_desktop_surface(wsurface);
1277 wl_resource_post_error(shell_res,
1278 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1279 "surface must be a desktop surface");
1283 surface = weston_desktop_surface_get_user_data(dsurface);
1284 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1285 wl_resource_post_error(shell_res,
1286 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1287 "surface already has another ivi role");
1292 case AGL_SHELL_EDGE_TOP:
1293 member = &output->top;
1295 case AGL_SHELL_EDGE_BOTTOM:
1296 member = &output->bottom;
1298 case AGL_SHELL_EDGE_LEFT:
1299 member = &output->left;
1301 case AGL_SHELL_EDGE_RIGHT:
1302 member = &output->right;
1305 wl_resource_post_error(shell_res,
1306 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1307 "invalid edge for panel");
1312 wl_resource_post_error(shell_res,
1313 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1314 "output already has panel on this edge");
1318 surface->checked_pending = true;
1319 surface->role = IVI_SURFACE_ROLE_PANEL;
1320 surface->panel.output = output;
1321 surface->panel.edge = edge;
1322 wl_list_remove(&surface->link);
1323 wl_list_init(&surface->link);
1327 switch (surface->panel.edge) {
1328 case AGL_SHELL_EDGE_TOP:
1329 case AGL_SHELL_EDGE_BOTTOM:
1330 width = woutput->width;
1332 case AGL_SHELL_EDGE_LEFT:
1333 case AGL_SHELL_EDGE_RIGHT:
1334 height = woutput->height;
1338 weston_desktop_surface_set_size(dsurface, width, height);
1342 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1343 const char *data, uint32_t app_state)
1345 struct desktop_client *dclient;
1347 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1348 struct ivi_policy *policy = ivi->policy;
1350 /* FIXME: should queue it here and see when binding agl-shell-desktop
1351 * if there are any to be sent */
1358 if (policy && policy->api.surface_advertise_state_change &&
1359 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1363 app_role = surf->role;
1364 if (app_role == IVI_SURFACE_ROLE_POPUP)
1365 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1367 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1368 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1369 data, app_state, app_role);
1373 shell_activate_app(struct wl_client *client,
1374 struct wl_resource *shell_res,
1376 struct wl_resource *output_res)
1378 struct weston_head *head = weston_head_from_resource(output_res);
1379 struct weston_output *woutput = weston_head_get_output(head);
1380 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1381 struct ivi_output *output = to_ivi_output(woutput);
1383 if (ivi->shell_client.resource &&
1384 ivi->shell_client.status == BOUND_FAILED) {
1385 wl_resource_post_error(shell_res,
1386 WL_DISPLAY_ERROR_INVALID_OBJECT,
1387 "agl_shell has already been bound. "
1388 "Check out bound_fail event");
1392 ivi_layout_activate(output, app_id);
1396 shell_desktop_activate_app(struct wl_client *client,
1397 struct wl_resource *shell_res,
1398 const char *app_id, const char *data,
1399 struct wl_resource *output_res)
1401 struct weston_head *head = weston_head_from_resource(output_res);
1402 struct weston_output *woutput = weston_head_get_output(head);
1403 struct ivi_output *output = to_ivi_output(woutput);
1405 ivi_layout_activate(output, app_id);
1406 shell_advertise_app_state(output->ivi, app_id,
1407 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1411 shell_deactivate_app(struct wl_client *client,
1412 struct wl_resource *shell_res,
1415 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1416 struct ivi_compositor *ivi = dclient->ivi;
1418 ivi_layout_deactivate(ivi, app_id);
1419 shell_advertise_app_state(ivi, app_id,
1420 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1423 /* stub, no usage for the time being */
1425 shell_destroy(struct wl_client *client, struct wl_resource *res)
1429 static const struct agl_shell_interface agl_shell_implementation = {
1430 .destroy = shell_destroy,
1431 .ready = shell_ready,
1432 .set_background = shell_set_background,
1433 .set_panel = shell_set_panel,
1434 .activate_app = shell_activate_app,
1438 shell_desktop_set_app_property(struct wl_client *client,
1439 struct wl_resource *shell_res,
1440 const char *app_id, uint32_t role,
1441 int x, int y, int bx, int by,
1442 int width, int height,
1443 struct wl_resource *output_res)
1445 struct weston_head *head = weston_head_from_resource(output_res);
1446 struct weston_output *woutput = weston_head_get_output(head);
1447 struct ivi_output *output = to_ivi_output(woutput);
1450 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1451 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1452 width, height, app_id);
1454 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1455 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1457 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1458 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1459 ivi_set_pending_desktop_surface_split(output, app_id, role);
1461 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1462 ivi_set_pending_desktop_surface_remote(output, app_id);
1470 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1472 struct pending_popup *p_popup, *next_p_popup;
1473 struct pending_split *split_surf, *next_split_surf;
1474 struct pending_fullscreen *fs_surf, *next_fs_surf;
1475 struct pending_remote *remote_surf, *next_remote_surf;
1477 wl_list_for_each_safe(p_popup, next_p_popup,
1478 &ivi->popup_pending_apps, link)
1479 ivi_remove_pending_desktop_surface_popup(p_popup);
1481 wl_list_for_each_safe(split_surf, next_split_surf,
1482 &ivi->split_pending_apps, link)
1483 ivi_remove_pending_desktop_surface_split(split_surf);
1485 wl_list_for_each_safe(fs_surf, next_fs_surf,
1486 &ivi->fullscreen_pending_apps, link)
1487 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1489 wl_list_for_each_safe(remote_surf, next_remote_surf,
1490 &ivi->remote_pending_apps, link)
1491 ivi_remove_pending_desktop_surface_remote(remote_surf);
1495 shell_desktop_set_app_property_mode(struct wl_client *client,
1496 struct wl_resource *shell_res, uint32_t perm)
1498 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1500 dclient->ivi->keep_pending_surfaces = true;
1502 dclient->ivi->keep_pending_surfaces = false;
1503 /* remove any previous pending surfaces */
1504 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1508 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1509 .activate_app = shell_desktop_activate_app,
1510 .set_app_property = shell_desktop_set_app_property,
1511 .deactivate_app = shell_deactivate_app,
1512 .set_app_property_mode = shell_desktop_set_app_property_mode,
1516 unbind_agl_shell(struct wl_resource *resource)
1518 struct ivi_compositor *ivi;
1519 struct ivi_output *output;
1520 struct ivi_surface *surf, *surf_tmp;
1522 ivi = wl_resource_get_user_data(resource);
1524 /* reset status to allow other clients issue legit requests */
1525 if (ivi->shell_client.resource &&
1526 ivi->shell_client.status == BOUND_FAILED) {
1527 ivi->shell_client.status = BOUND_OK;
1531 wl_list_for_each(output, &ivi->outputs, link) {
1532 /* reset the active surf if there's one present */
1533 if (output->active) {
1534 output->active->view->is_mapped = false;
1535 output->active->view->surface->is_mapped = false;
1537 weston_layer_entry_remove(&output->active->view->layer_link);
1538 output->active = NULL;
1541 insert_black_curtain(output);
1544 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1545 wl_list_remove(&surf->link);
1546 wl_list_init(&surf->link);
1549 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1550 wl_list_remove(&surf->link);
1551 wl_list_init(&surf->link);
1554 wl_list_init(&ivi->surfaces);
1555 wl_list_init(&ivi->pending_surfaces);
1557 ivi->shell_client.ready = false;
1558 ivi->shell_client.resource = NULL;
1559 ivi->shell_client.client = NULL;
1563 bind_agl_shell(struct wl_client *client,
1564 void *data, uint32_t version, uint32_t id)
1566 struct ivi_compositor *ivi = data;
1567 struct wl_resource *resource;
1568 struct ivi_policy *policy;
1571 policy = ivi->policy;
1572 interface = (void *) &agl_shell_interface;
1573 if (policy && policy->api.shell_bind_interface &&
1574 !policy->api.shell_bind_interface(client, interface)) {
1575 wl_client_post_implementation_error(client,
1576 "client not authorized to use agl_shell");
1580 resource = wl_resource_create(client, &agl_shell_interface, version, id);
1582 wl_client_post_no_memory(client);
1586 if (ivi->shell_client.resource) {
1587 if (wl_resource_get_version(resource) == 1) {
1588 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1589 "agl_shell has already been bound");
1593 agl_shell_send_bound_fail(resource);
1594 ivi->shell_client.status = BOUND_FAILED;
1597 wl_resource_set_implementation(resource, &agl_shell_implementation,
1598 ivi, unbind_agl_shell);
1599 ivi->shell_client.resource = resource;
1601 if (ivi->shell_client.status == BOUND_OK &&
1602 wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION)
1603 agl_shell_send_bound_ok(ivi->shell_client.resource);
1607 unbind_agl_shell_desktop(struct wl_resource *resource)
1609 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1611 wl_list_remove(&dclient->link);
1616 bind_agl_shell_desktop(struct wl_client *client,
1617 void *data, uint32_t version, uint32_t id)
1619 struct ivi_compositor *ivi = data;
1620 struct wl_resource *resource;
1621 struct ivi_policy *policy;
1622 struct desktop_client *dclient;
1625 policy = ivi->policy;
1626 interface = (void *) &agl_shell_desktop_interface;
1627 if (policy && policy->api.shell_bind_interface &&
1628 !policy->api.shell_bind_interface(client, interface)) {
1629 wl_client_post_implementation_error(client,
1630 "client not authorized to use agl_shell_desktop");
1634 dclient = zalloc(sizeof(*dclient));
1636 wl_client_post_no_memory(client);
1640 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1644 wl_client_post_no_memory(client);
1648 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1649 dclient, unbind_agl_shell_desktop);
1651 dclient->resource = resource;
1652 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1654 /* advertise xdg surfaces */
1655 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1659 ivi_shell_create_global(struct ivi_compositor *ivi)
1661 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1662 &agl_shell_interface, 3,
1663 ivi, bind_agl_shell);
1664 if (!ivi->agl_shell) {
1665 weston_log("Failed to create wayland global.\n");
1669 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1670 &agl_shell_desktop_interface, 2,
1671 ivi, bind_agl_shell_desktop);
1672 if (!ivi->agl_shell_desktop) {
1673 weston_log("Failed to create wayland global (agl_shell_desktop).\n");