2 * Copyright © 2019, 2022 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
34 #include <sys/socket.h>
35 #include <sys/types.h>
38 #include <libweston/libweston.h>
39 #include <libweston/config-parser.h>
42 #include "shared/os-compatibility.h"
43 #include "shared/helpers.h"
44 #include "shared/process-util.h"
46 #include "agl-shell-server-protocol.h"
47 #include "agl-shell-desktop-server-protocol.h"
50 create_black_curtain_view(struct ivi_output *output);
53 reverse_orientation(uint32_t orientation);
56 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
57 struct ivi_surface *surface)
59 struct desktop_client *dclient;
60 static bool display_adv = false;
62 if (surface->advertised_on_launch)
65 /* advertise to all desktop clients the new surface */
66 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
68 weston_desktop_surface_get_app_id(surface->dsurface);
71 weston_log("WARNING app_is is null, unable to advertise\n");
76 agl_shell_desktop_send_application(dclient->resource, app_id);
77 surface->advertised_on_launch = true;
82 ivi_set_desktop_surface(struct ivi_surface *surface)
84 struct ivi_compositor *ivi = surface->ivi;
85 assert(surface->role == IVI_SURFACE_ROLE_NONE);
87 surface->role = IVI_SURFACE_ROLE_DESKTOP;
88 wl_list_insert(&surface->ivi->surfaces, &surface->link);
90 agl_shell_desktop_advertise_application_id(ivi, surface);
94 ivi_set_background_surface(struct ivi_surface *surface)
96 struct ivi_compositor *ivi = surface->ivi;
97 assert(surface->role == IVI_SURFACE_ROLE_BACKGROUND);
99 wl_list_insert(&surface->ivi->surfaces, &surface->link);
100 agl_shell_desktop_advertise_application_id(ivi, surface);
104 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
106 struct ivi_compositor *ivi = surface->ivi;
107 assert(surface->role == IVI_SURFACE_ROLE_NONE);
109 surface->role = IVI_SURFACE_ROLE_POPUP;
110 wl_list_insert(&ivi->surfaces, &surface->link);
112 agl_shell_desktop_advertise_application_id(ivi, surface);
116 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
118 struct ivi_compositor *ivi = surface->ivi;
119 assert(surface->role == IVI_SURFACE_ROLE_NONE);
121 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
122 wl_list_insert(&ivi->surfaces, &surface->link);
124 agl_shell_desktop_advertise_application_id(ivi, surface);
128 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
130 struct ivi_compositor *ivi = surface->ivi;
131 struct weston_view *view;
132 struct ivi_output *output = surface->remote.output;
134 assert(surface->role == IVI_SURFACE_ROLE_NONE);
136 /* remote type are the same as desktop just that client can tell
137 * the compositor to start on another output */
138 surface->role = IVI_SURFACE_ROLE_REMOTE;
140 /* if thew black surface view is mapped on the mean we need
141 * to remove it in order to start showing the 'remote' surface
142 * just being added */
143 view = output->fullscreen_view.fs->view;
144 if (view->is_mapped || view->surface->is_mapped)
145 remove_black_curtain(output);
147 wl_list_insert(&ivi->surfaces, &surface->link);
152 ivi_set_desktop_surface_split(struct ivi_surface *surface)
154 struct ivi_compositor *ivi = surface->ivi;
155 assert(surface->role == IVI_SURFACE_ROLE_NONE);
157 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
158 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
160 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
162 wl_list_insert(&ivi->surfaces, &surface->link);
164 agl_shell_desktop_advertise_application_id(ivi, surface);
167 static struct pending_popup *
168 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
169 int width, int height, const char *app_id)
171 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
172 size_t len_app_id = strlen(app_id);
176 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
177 if (!p_popup->app_id) {
181 memcpy(p_popup->app_id, app_id, len_app_id);
182 p_popup->ioutput = ioutput;
188 p_popup->bb.width = width;
189 p_popup->bb.height = height;
195 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
196 int width, int height, const char *app_id, struct pending_popup *p_popup)
198 size_t len_app_id = strlen(app_id);
200 wl_list_remove(&p_popup->link);
201 wl_list_init(&p_popup->link);
203 memset(p_popup->app_id, 0, strlen(app_id) + 1);
204 free(p_popup->app_id);
206 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
207 if (!p_popup->app_id)
209 memcpy(p_popup->app_id, app_id, len_app_id);
211 p_popup->ioutput = ioutput;
217 p_popup->bb.width = width;
218 p_popup->bb.height = height;
221 static struct pending_fullscreen *
222 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
224 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
225 size_t len_app_id = strlen(app_id);
229 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
230 if (!p_fullscreen->app_id) {
234 memcpy(p_fullscreen->app_id, app_id, len_app_id);
236 p_fullscreen->ioutput = ioutput;
241 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
242 struct pending_fullscreen *p_fullscreen)
244 size_t len_app_id = strlen(app_id);
246 wl_list_remove(&p_fullscreen->link);
247 wl_list_init(&p_fullscreen->link);
249 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
250 free(p_fullscreen->app_id);
252 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
253 if (!p_fullscreen->app_id)
255 memcpy(p_fullscreen->app_id, app_id, len_app_id);
257 p_fullscreen->ioutput = ioutput;
260 static struct pending_remote *
261 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
263 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
264 size_t len_app_id = strlen(app_id);
268 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
269 if (!p_remote->app_id) {
273 memcpy(p_remote->app_id, app_id, len_app_id);
275 p_remote->ioutput = ioutput;
280 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
281 struct pending_remote *p_remote)
283 size_t len_app_id = strlen(app_id);
285 wl_list_remove(&p_remote->link);
286 wl_list_init(&p_remote->link);
288 memset(p_remote->app_id, 0, strlen(app_id) + 1);
289 free(p_remote->app_id);
291 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
292 if (!p_remote->app_id)
294 memcpy(p_remote->app_id, app_id, len_app_id);
296 p_remote->ioutput = ioutput;
300 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
301 int by, int width, int height, const char *app_id)
303 struct ivi_compositor *ivi = ioutput->ivi;
304 struct pending_popup *p_popup = NULL;
305 struct pending_popup *popup;
307 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
308 if (!strcmp(app_id, popup->app_id))
312 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
314 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
318 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
322 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
325 struct ivi_compositor *ivi = ioutput->ivi;
326 struct pending_fullscreen *p_fullscreen = NULL;
327 struct pending_fullscreen *fullscreen;
329 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
330 if (!strcmp(app_id, fullscreen->app_id))
331 p_fullscreen = fullscreen;
334 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
336 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
340 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
344 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
345 const char *app_id, uint32_t orientation)
347 struct ivi_compositor *ivi = ioutput->ivi;
348 struct ivi_surface *surf;
349 size_t len_app_id = strlen(app_id);
350 struct pending_split *split;
352 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
353 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
356 /* more than one is un-supported, do note we need to do
357 * conversion for surface roles instead of using the protocol ones */
358 wl_list_for_each(surf, &ivi->surfaces, link)
359 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
360 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
363 split = zalloc(sizeof(*split));
366 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
367 if (!split->app_id) {
371 memcpy(split->app_id, app_id, len_app_id);
373 split->ioutput = ioutput;
374 split->orientation = orientation;
376 wl_list_insert(&ivi->split_pending_apps, &split->link);
380 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
383 struct ivi_compositor *ivi = ioutput->ivi;
384 struct pending_remote *remote;
385 struct pending_remote *p_remote = NULL;
387 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
388 if (!strcmp(app_id, remote->app_id))
392 p_remote = ivi_ensure_remote(ioutput, app_id);
394 ivi_update_remote(ioutput, app_id, p_remote);
398 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
403 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
406 wl_list_remove(&split->link);
411 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
414 wl_list_remove(&fs->link);
419 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
421 free(p_popup->app_id);
422 wl_list_remove(&p_popup->link);
427 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
429 free(remote->app_id);
430 wl_list_remove(&remote->link);
435 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
437 return surface->ivi->keep_pending_surfaces;
441 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
443 struct ivi_compositor *ivi = surface->ivi;
444 struct pending_popup *p_popup, *next_p_popup;
445 const char *_app_id =
446 weston_desktop_surface_get_app_id(surface->dsurface);
448 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
451 wl_list_for_each_safe(p_popup, next_p_popup,
452 &ivi->popup_pending_apps, link) {
453 if (!strcmp(_app_id, p_popup->app_id)) {
454 surface->popup.output = p_popup->ioutput;
455 surface->popup.x = p_popup->x;
456 surface->popup.y = p_popup->y;
458 surface->popup.bb.x = p_popup->bb.x;
459 surface->popup.bb.y = p_popup->bb.y;
460 surface->popup.bb.width = p_popup->bb.width;
461 surface->popup.bb.height = p_popup->bb.height;
463 if (!ivi_compositor_keep_pending_surfaces(surface))
464 ivi_remove_pending_desktop_surface_popup(p_popup);
473 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
475 struct pending_split *split_surf, *next_split_surf;
476 struct ivi_compositor *ivi = surface->ivi;
477 const char *_app_id =
478 weston_desktop_surface_get_app_id(surface->dsurface);
480 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
483 wl_list_for_each_safe(split_surf, next_split_surf,
484 &ivi->split_pending_apps, link) {
485 if (!strcmp(_app_id, split_surf->app_id)) {
486 surface->split.output = split_surf->ioutput;
487 surface->split.orientation = split_surf->orientation;
488 if (!ivi_compositor_keep_pending_surfaces(surface))
489 ivi_remove_pending_desktop_surface_split(split_surf);
498 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
500 struct pending_fullscreen *fs_surf, *next_fs_surf;
501 struct ivi_compositor *ivi = surface->ivi;
502 const char *_app_id =
503 weston_desktop_surface_get_app_id(surface->dsurface);
505 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
508 wl_list_for_each_safe(fs_surf, next_fs_surf,
509 &ivi->fullscreen_pending_apps, link) {
510 if (!strcmp(_app_id, fs_surf->app_id)) {
511 surface->fullscreen.output = fs_surf->ioutput;
512 if (!ivi_compositor_keep_pending_surfaces(surface))
513 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
522 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
524 struct pending_remote *remote_surf, *next_remote_surf;
525 struct ivi_compositor *ivi = surface->ivi;
526 const char *_app_id =
527 weston_desktop_surface_get_app_id(surface->dsurface);
529 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
532 wl_list_for_each_safe(remote_surf, next_remote_surf,
533 &ivi->remote_pending_apps, link) {
534 if (!strcmp(_app_id, remote_surf->app_id)) {
535 surface->remote.output = remote_surf->ioutput;
536 if (!ivi_compositor_keep_pending_surfaces(surface))
537 ivi_remove_pending_desktop_surface_remote(remote_surf);
545 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
546 enum ivi_surface_role *role)
548 struct ivi_compositor *ivi = surface->ivi;
549 struct wl_list *role_pending_list;
550 struct pending_popup *p_popup;
551 struct pending_split *p_split;
552 struct pending_fullscreen *p_fullscreen;
553 struct pending_remote *p_remote;
555 weston_desktop_surface_get_app_id(surface->dsurface);
557 role_pending_list = &ivi->popup_pending_apps;
558 wl_list_for_each(p_popup, role_pending_list, link) {
559 if (app_id && !strcmp(app_id, p_popup->app_id)) {
560 *role = IVI_SURFACE_ROLE_POPUP;
565 role_pending_list = &ivi->split_pending_apps;
566 wl_list_for_each(p_split, role_pending_list, link) {
567 if (app_id && !strcmp(app_id, p_split->app_id)) {
568 *role = IVI_SURFACE_ROLE_SPLIT_V;
573 role_pending_list = &ivi->fullscreen_pending_apps;
574 wl_list_for_each(p_fullscreen, role_pending_list, link) {
575 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
576 *role = IVI_SURFACE_ROLE_FULLSCREEN;
581 role_pending_list = &ivi->remote_pending_apps;
582 wl_list_for_each(p_remote, role_pending_list, link) {
583 if (app_id && !strcmp(app_id, p_remote->app_id)) {
584 *role = IVI_SURFACE_ROLE_REMOTE;
589 /* else, we are a regular desktop surface */
590 *role = IVI_SURFACE_ROLE_DESKTOP;
594 ivi_check_pending_app_type(struct ivi_surface *surface, enum ivi_surface_role role)
596 struct pending_app *papp;
597 const char *app_id = NULL;
599 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
603 wl_list_for_each(papp, &surface->ivi->pending_apps, link) {
604 if (strcmp(app_id, papp->app_id) == 0 && papp->role == role)
613 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
617 ret = ivi_check_pending_desktop_surface_popup(surface);
619 ivi_set_desktop_surface_popup(surface);
620 ivi_layout_popup_committed(surface);
624 ret = ivi_check_pending_desktop_surface_split(surface);
626 ivi_set_desktop_surface_split(surface);
627 ivi_layout_split_committed(surface);
631 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
633 ivi_set_desktop_surface_fullscreen(surface);
634 ivi_layout_fullscreen_committed(surface);
638 ret = ivi_check_pending_desktop_surface_remote(surface);
640 ivi_set_desktop_surface_remote(surface);
641 ivi_layout_remote_committed(surface);
645 /* new way of doing it */
646 struct pending_app *papp =
647 ivi_check_pending_app_type(surface, IVI_SURFACE_ROLE_TILE);
649 struct pending_app_tile *papp_tile =
650 container_of(papp, struct pending_app_tile, base);
652 // handle the currently active surface
653 if (papp->ioutput->active) {
654 _ivi_set_shell_surface_split(papp->ioutput->active, NULL,
655 reverse_orientation(papp_tile->orientation), false);
658 surface->role = IVI_SURFACE_ROLE_TILE;
659 surface->current_completed_output = papp->ioutput;
660 wl_list_insert(&surface->ivi->surfaces, &surface->link);
662 _ivi_set_shell_surface_split(surface, papp->ioutput,
663 papp_tile->orientation, true);
665 /* remove it from pending */
666 wl_list_remove(&papp->link);
673 /* if we end up here means we have a regular desktop app and
674 * try to activate it */
675 ivi_set_desktop_surface(surface);
676 ivi_layout_desktop_committed(surface);
680 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
682 struct ivi_output *out;
684 wl_list_for_each(out, &ivi->outputs, link) {
685 create_black_curtain_view(out);
686 insert_black_curtain(out);
691 ivi_shell_init(struct ivi_compositor *ivi)
693 weston_layer_init(&ivi->hidden, ivi->compositor);
694 weston_layer_init(&ivi->background, ivi->compositor);
695 weston_layer_init(&ivi->normal, ivi->compositor);
696 weston_layer_init(&ivi->panel, ivi->compositor);
697 weston_layer_init(&ivi->popup, ivi->compositor);
698 weston_layer_init(&ivi->fullscreen, ivi->compositor);
700 weston_layer_set_position(&ivi->hidden,
701 WESTON_LAYER_POSITION_HIDDEN);
702 weston_layer_set_position(&ivi->background,
703 WESTON_LAYER_POSITION_BACKGROUND);
704 weston_layer_set_position(&ivi->normal,
705 WESTON_LAYER_POSITION_NORMAL);
706 weston_layer_set_position(&ivi->panel,
707 WESTON_LAYER_POSITION_UI);
708 weston_layer_set_position(&ivi->popup,
709 WESTON_LAYER_POSITION_TOP_UI);
710 weston_layer_set_position(&ivi->fullscreen,
711 WESTON_LAYER_POSITION_FULLSCREEN);
718 ivi_surf_destroy(struct ivi_surface *surf)
720 struct weston_surface *wsurface = surf->view->surface;
722 if (weston_surface_is_mapped(wsurface)) {
723 weston_desktop_surface_unlink_view(surf->view);
724 weston_view_destroy(surf->view);
727 wl_list_remove(&surf->link);
732 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
734 struct weston_view *view, *view_next;
736 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
737 struct ivi_surface *ivi_surf =
738 get_ivi_shell_surface(view->surface);
740 ivi_surf_destroy(ivi_surf);
745 ivi_shell_finalize(struct ivi_compositor *ivi)
747 struct ivi_output *output;
749 ivi_shell_destroy_views_on_layer(&ivi->hidden);
750 weston_layer_fini(&ivi->hidden);
752 ivi_shell_destroy_views_on_layer(&ivi->background);
753 weston_layer_fini(&ivi->background);
755 ivi_shell_destroy_views_on_layer(&ivi->normal);
756 weston_layer_fini(&ivi->normal);
758 ivi_shell_destroy_views_on_layer(&ivi->panel);
759 weston_layer_fini(&ivi->panel);
761 ivi_shell_destroy_views_on_layer(&ivi->popup);
762 weston_layer_fini(&ivi->popup);
764 wl_list_for_each(output, &ivi->outputs, link) {
765 if (output->fullscreen_view.fs &&
766 output->fullscreen_view.fs->view) {
767 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
768 output->fullscreen_view.fs->view = NULL;
771 weston_layer_fini(&ivi->fullscreen);
775 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
777 struct ivi_surface *surface;
779 wl_list_for_each(surface, &ivi->surfaces, link) {
781 weston_desktop_surface_get_app_id(surface->dsurface);
782 if (app_id == NULL) {
783 weston_log("WARNING app_is is null, unable to advertise\n");
786 agl_shell_desktop_send_application(resource, app_id);
790 static struct wl_client *
791 client_launch(struct weston_compositor *compositor,
792 struct weston_process *proc,
794 weston_process_cleanup_func_t cleanup)
796 struct wl_client *client = NULL;
797 struct custom_env child_env;
798 struct fdstr wayland_socket;
799 const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket";
800 const char *fail_seteuid = "Couldn't call seteuid";
807 struct ivi_compositor *ivi;
808 size_t written __attribute__((unused));
810 weston_log("launching '%s'\n", path);
811 str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
813 custom_env_init_from_environ(&child_env);
814 custom_env_add_from_exec_string(&child_env, path);
816 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
817 wayland_socket.fds) < 0) {
818 weston_log("client_launch: "
819 "socketpair failed while launching '%s': %s\n",
820 path, strerror(errno));
821 custom_env_fini(&child_env);
824 fdstr_update_str1(&wayland_socket);
825 custom_env_set_env_var(&child_env, "WAYLAND_SOCKET",
826 wayland_socket.str1);
828 argp = custom_env_get_argp(&child_env);
829 envp = custom_env_get_envp(&child_env);
834 /* Put the client in a new session so it won't catch signals
835 * intended for the parent. Sharing a session can be
836 * confusing when launching weston under gdb, as the ctrl-c
837 * intended for gdb will pass to the child, and weston
838 * will cleanly shut down when the child exits.
842 /* do not give our signal mask to the new process */
843 sigfillset(&allsigs);
844 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
846 /* Launch clients as the user. Do not launch clients with wrong euid. */
847 if (seteuid(getuid()) == -1) {
848 written = write(STDERR_FILENO, fail_seteuid, strlen(fail_seteuid));
852 ret = fdstr_clear_cloexec_fd1(&wayland_socket);
854 written = write(STDERR_FILENO, fail_cloexec, strlen(fail_cloexec));
858 execve(argp[0], argp, envp);
861 written = write(STDERR_FILENO, fail_exec, strlen(fail_exec));
865 close(wayland_socket.fds[1]);
866 ivi = weston_compositor_get_user_data(compositor);
867 client = wl_client_create(compositor->wl_display,
868 wayland_socket.fds[0]);
870 custom_env_fini(&child_env);
871 close(wayland_socket.fds[0]);
873 weston_log("client_launch: "
874 "wl_client_create failed while launching '%s'.\n",
880 proc->cleanup = cleanup;
881 wl_list_insert(&ivi->child_process_list, &proc->link);
885 fdstr_close_all(&wayland_socket);
886 weston_log("client_launch: "
887 "fork failed while launching '%s': %s\n", path,
892 custom_env_fini(&child_env);
898 struct process_info {
899 struct weston_process proc;
904 sigchld_handler(int signal_number, void *data)
906 struct weston_process *p;
907 struct ivi_compositor *ivi = data;
911 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
912 wl_list_for_each(p, &ivi->child_process_list, link) {
917 if (&p->link == &ivi->child_process_list) {
918 weston_log("unknown child process exited\n");
922 wl_list_remove(&p->link);
923 wl_list_init(&p->link);
924 p->cleanup(p, status);
927 if (pid < 0 && errno != ECHILD)
928 weston_log("waitpid error %s\n", strerror(errno));
935 process_handle_sigchld(struct weston_process *process, int status)
937 struct process_info *pinfo =
938 container_of(process, struct process_info, proc);
941 * There are no guarantees whether this runs before or after
942 * the wl_client destructor.
945 if (WIFEXITED(status)) {
946 weston_log("%s exited with status %d\n", pinfo->path,
947 WEXITSTATUS(status));
948 } else if (WIFSIGNALED(status)) {
949 weston_log("%s died on signal %d\n", pinfo->path,
952 weston_log("%s disappeared\n", pinfo->path);
960 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section,
961 struct wl_client **client)
963 struct process_info *pinfo;
964 struct weston_config_section *section;
965 char *command = NULL;
967 section = weston_config_get_section(ivi->config, cmd_section, NULL, NULL);
969 weston_config_section_get_string(section, "command", &command, NULL);
974 pinfo = zalloc(sizeof *pinfo);
978 pinfo->path = strdup(command);
982 *client = client_launch(ivi->compositor, &pinfo->proc, command, process_handle_sigchld);
998 destroy_black_curtain_view(struct wl_listener *listener, void *data)
1000 struct fullscreen_view *fs =
1001 wl_container_of(listener, fs, fs_destroy);
1005 wl_list_remove(&fs->fs_destroy.link);
1012 create_black_curtain_view(struct ivi_output *output)
1014 struct weston_surface *surface = NULL;
1015 struct weston_view *view;
1016 struct ivi_compositor *ivi = output->ivi;
1017 struct weston_compositor *wc= ivi->compositor;
1018 struct weston_output *woutput = output->output;
1023 surface = weston_surface_create(wc);
1026 view = weston_view_create(surface);
1028 weston_surface_destroy(surface);
1032 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1033 weston_surface_set_size(surface, woutput->width, woutput->height);
1034 weston_view_set_position(view, woutput->x, woutput->y);
1036 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
1037 if (!output->fullscreen_view.fs) {
1038 weston_surface_destroy(surface);
1041 output->fullscreen_view.fs->view = view;
1043 output->fullscreen_view.fs_destroy.notify = destroy_black_curtain_view;
1044 wl_signal_add(&woutput->destroy_signal,
1045 &output->fullscreen_view.fs_destroy);
1049 output_has_black_curtain(struct ivi_output *output)
1051 return (output->fullscreen_view.fs &&
1052 output->fullscreen_view.fs->view &&
1053 output->fullscreen_view.fs->view->is_mapped &&
1054 output->fullscreen_view.fs->view->surface->is_mapped);
1058 remove_black_curtain(struct ivi_output *output)
1060 struct weston_view *view;
1063 !output->fullscreen_view.fs &&
1064 !output->fullscreen_view.fs->view) ||
1065 !output->fullscreen_view.fs) {
1066 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1070 view = output->fullscreen_view.fs->view;
1071 assert(view->is_mapped == true ||
1072 view->surface->is_mapped == true);
1074 view->is_mapped = false;
1075 view->surface->is_mapped = false;
1077 weston_layer_entry_remove(&view->layer_link);
1078 weston_view_update_transform(view);
1080 weston_view_damage_below(view);
1082 weston_log("Removed black curtain from output %s\n", output->output->name);
1086 insert_black_curtain(struct ivi_output *output)
1088 struct weston_view *view;
1091 !output->fullscreen_view.fs &&
1092 !output->fullscreen_view.fs->view) || !output->output ||
1093 !output->fullscreen_view.fs) {
1094 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1098 view = output->fullscreen_view.fs->view;
1099 if (view->is_mapped || view->surface->is_mapped)
1102 weston_layer_entry_remove(&view->layer_link);
1103 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1106 view->is_mapped = true;
1107 view->surface->is_mapped = true;
1109 weston_view_update_transform(view);
1110 weston_view_damage_below(view);
1112 weston_log("Added black curtain to output %s\n", output->output->name);
1116 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
1117 enum agl_shell_app_state state)
1119 if (app_id && wl_resource_get_version(ivi->shell_client.resource) >=
1120 AGL_SHELL_APP_STATE_SINCE_VERSION) {
1122 agl_shell_send_app_state(ivi->shell_client.resource,
1125 if (ivi->shell_client.resource_ext)
1126 agl_shell_send_app_state(ivi->shell_client.resource_ext,
1132 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
1133 const char *output_name)
1135 if (app_id && ivi->shell_client.resource &&
1136 wl_resource_get_version(ivi->shell_client.resource) >=
1137 AGL_SHELL_APP_ON_OUTPUT_SINCE_VERSION) {
1139 agl_shell_send_app_on_output(ivi->shell_client.resource,
1140 app_id, output_name);
1142 if (ivi->shell_client.resource_ext)
1143 agl_shell_send_app_on_output(ivi->shell_client.resource_ext,
1144 app_id, output_name);
1149 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1151 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1152 struct ivi_output *output;
1153 struct ivi_surface *surface, *tmp;
1155 if (wl_resource_get_version(shell_res) >=
1156 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1157 ivi->shell_client.status == BOUND_FAILED) {
1158 wl_resource_post_error(shell_res,
1159 WL_DISPLAY_ERROR_INVALID_OBJECT,
1160 "agl_shell (ready quest) has already "
1161 "been bound. Check out bound_fail event");
1165 /* Init already finished. Do nothing */
1166 if (ivi->shell_client.ready)
1170 ivi->shell_client.ready = true;
1172 wl_list_for_each(output, &ivi->outputs, link) {
1173 if (output->background &&
1174 output->background->role == IVI_SURFACE_ROLE_BACKGROUND) {
1175 /* track the background surface role as a "regular"
1176 * surface so we can activate it */
1177 ivi_set_background_surface(output->background);
1178 remove_black_curtain(output);
1181 ivi_layout_init(ivi, output);
1184 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1187 wl_list_remove(&surface->link);
1188 wl_list_init(&surface->link);
1189 ivi_check_pending_desktop_surface(surface);
1190 surface->checked_pending = true;
1191 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1193 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_STARTED);
1198 shell_set_background(struct wl_client *client,
1199 struct wl_resource *shell_res,
1200 struct wl_resource *surface_res,
1201 struct wl_resource *output_res)
1203 struct weston_head *head = weston_head_from_resource(output_res);
1204 struct weston_output *woutput = weston_head_get_output(head);
1205 struct ivi_output *output = to_ivi_output(woutput);
1206 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1207 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1208 struct weston_desktop_surface *dsurface;
1209 struct ivi_surface *surface;
1211 if ((wl_resource_get_version(shell_res) >=
1212 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1213 ivi->shell_client.status == BOUND_FAILED) ||
1214 ivi->shell_client.resource_ext == shell_res) {
1215 wl_resource_post_error(shell_res,
1216 WL_DISPLAY_ERROR_INVALID_OBJECT,
1217 "agl_shell (set_background) has already "
1218 "been bound. Check out bound_fail event");
1222 dsurface = weston_surface_get_desktop_surface(wsurface);
1224 wl_resource_post_error(shell_res,
1225 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1226 "surface must be a desktop surface");
1230 surface = weston_desktop_surface_get_user_data(dsurface);
1231 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1232 wl_resource_post_error(shell_res,
1233 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1234 "surface already has another ivi role");
1238 if (output->background) {
1239 wl_resource_post_error(shell_res,
1240 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1241 "output already has background");
1245 surface->checked_pending = true;
1246 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1247 surface->bg.output = output;
1248 wl_list_remove(&surface->link);
1249 wl_list_init(&surface->link);
1251 output->background = surface;
1253 weston_desktop_surface_set_maximized(dsurface, true);
1254 weston_desktop_surface_set_size(dsurface,
1255 output->output->width,
1256 output->output->height);
1260 shell_set_panel(struct wl_client *client,
1261 struct wl_resource *shell_res,
1262 struct wl_resource *surface_res,
1263 struct wl_resource *output_res,
1266 struct weston_head *head = weston_head_from_resource(output_res);
1267 struct weston_output *woutput = weston_head_get_output(head);
1268 struct ivi_output *output = to_ivi_output(woutput);
1269 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1270 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1271 struct weston_desktop_surface *dsurface;
1272 struct ivi_surface *surface;
1273 struct ivi_surface **member;
1274 int32_t width = 0, height = 0;
1276 if ((wl_resource_get_version(shell_res) >=
1277 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1278 ivi->shell_client.status == BOUND_FAILED) ||
1279 ivi->shell_client.resource_ext == shell_res) {
1280 wl_resource_post_error(shell_res,
1281 WL_DISPLAY_ERROR_INVALID_OBJECT,
1282 "agl_shell (set_panel) has already been bound. "
1283 "Check out bound_fail event");
1287 dsurface = weston_surface_get_desktop_surface(wsurface);
1289 wl_resource_post_error(shell_res,
1290 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1291 "surface must be a desktop surface");
1295 surface = weston_desktop_surface_get_user_data(dsurface);
1296 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1297 wl_resource_post_error(shell_res,
1298 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1299 "surface already has another ivi role");
1304 case AGL_SHELL_EDGE_TOP:
1305 member = &output->top;
1307 case AGL_SHELL_EDGE_BOTTOM:
1308 member = &output->bottom;
1310 case AGL_SHELL_EDGE_LEFT:
1311 member = &output->left;
1313 case AGL_SHELL_EDGE_RIGHT:
1314 member = &output->right;
1317 wl_resource_post_error(shell_res,
1318 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1319 "invalid edge for panel");
1324 wl_resource_post_error(shell_res,
1325 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1326 "output already has panel on this edge");
1330 surface->checked_pending = true;
1331 surface->role = IVI_SURFACE_ROLE_PANEL;
1332 surface->panel.output = output;
1333 surface->panel.edge = edge;
1334 wl_list_remove(&surface->link);
1335 wl_list_init(&surface->link);
1339 switch (surface->panel.edge) {
1340 case AGL_SHELL_EDGE_TOP:
1341 case AGL_SHELL_EDGE_BOTTOM:
1342 width = woutput->width;
1344 case AGL_SHELL_EDGE_LEFT:
1345 case AGL_SHELL_EDGE_RIGHT:
1346 height = woutput->height;
1350 weston_desktop_surface_set_size(dsurface, width, height);
1354 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1355 const char *data, uint32_t app_state)
1357 struct desktop_client *dclient;
1359 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1360 struct ivi_policy *policy = ivi->policy;
1362 /* FIXME: should queue it here and see when binding agl-shell-desktop
1363 * if there are any to be sent */
1370 if (policy && policy->api.surface_advertise_state_change &&
1371 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1375 app_role = surf->role;
1376 if (app_role == IVI_SURFACE_ROLE_POPUP)
1377 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1379 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1380 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1381 data, app_state, app_role);
1385 shell_activate_app(struct wl_client *client,
1386 struct wl_resource *shell_res,
1388 struct wl_resource *output_res)
1390 struct weston_head *head;
1391 struct weston_output *woutput;
1392 struct ivi_compositor *ivi;
1393 struct ivi_output *output;
1395 head = weston_head_from_resource(output_res);
1397 weston_log("Invalid output to activate '%s' on\n", app_id);
1401 woutput = weston_head_get_output(head);
1402 ivi = wl_resource_get_user_data(shell_res);
1403 output = to_ivi_output(woutput);
1405 if (wl_resource_get_version(shell_res) >=
1406 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1407 ivi->shell_client.status == BOUND_FAILED) {
1408 wl_resource_post_error(shell_res,
1409 WL_DISPLAY_ERROR_INVALID_OBJECT,
1410 "agl_shell has already been bound. "
1411 "Check out bound_fail event");
1415 ivi_layout_activate(output, app_id);
1419 shell_new_deactivate_app(struct wl_client *client, struct wl_resource *shell_res,
1422 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1424 ivi_layout_deactivate(ivi, app_id);
1428 shell_set_app_float(struct wl_client *client, struct wl_resource *shell_res,
1429 const char *app_id, int32_t x_pos, int32_t y_pos)
1431 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1432 struct weston_output *output = get_focused_output(ivi->compositor);
1433 struct ivi_output *ivi_output;
1434 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1437 output = get_default_output(ivi->compositor);
1439 ivi_output = to_ivi_output(output);
1441 /* verify if already mapped as desktop role, regular, unmap it, so we
1442 * can make it float */
1443 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1444 struct weston_view *ev = surf->view;
1445 struct weston_desktop_surface *dsurf = surf->dsurface;
1446 struct ivi_bounding_box bb = {};
1447 const char *prev_activate_app_id = NULL;
1449 /* XXX: if this is useful we could bring it as active then make
1450 * it float, but avoid doing it for the moment */
1451 if (surf != ivi_output->active)
1454 if (ivi_output->previous_active)
1455 prev_activate_app_id =
1456 weston_desktop_surface_get_app_id(ivi_output->previous_active->dsurface);
1458 /* only deactivate if previous_active is different, otherwise
1459 * this will blow up, because we're trying to activate the same
1460 * app_id as the this one! */
1461 if (prev_activate_app_id && strcmp(app_id, prev_activate_app_id)) {
1462 ivi_layout_deactivate(ivi, app_id);
1463 } else if (prev_activate_app_id) {
1464 weston_layer_entry_remove(&ev->layer_link);
1465 weston_view_geometry_dirty(ev);
1466 weston_surface_damage(ev->surface);
1469 surf->hidden_layer_output = ivi_output;
1471 /* set attributes */
1472 surf->popup.output = ivi_output;
1474 surf->popup.x = x_pos;
1475 surf->popup.y = y_pos;
1476 surf->popup.bb = bb;
1479 /* change the role */
1480 surf->role = IVI_SURFACE_ROLE_NONE;
1482 wl_list_remove(&surf->link);
1483 wl_list_init(&surf->link);
1485 ivi_set_desktop_surface_popup(surf);
1487 weston_desktop_surface_set_maximized(dsurf, false);
1488 weston_desktop_surface_set_size(dsurf, 0, 0);
1490 /* add to hidden layer */
1491 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1492 weston_compositor_schedule_repaint(ivi->compositor);
1494 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_POPUP)) {
1495 ivi_set_pending_desktop_surface_popup(ivi_output, x_pos, y_pos,
1496 0, 0, 0, 0, app_id);
1501 shell_set_app_fullscreen(struct wl_client *client,
1502 struct wl_resource *shell_res, const char *app_id)
1504 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1505 struct weston_output *output = get_focused_output(ivi->compositor);
1506 struct ivi_output *ivi_output;
1507 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1510 output = get_default_output(ivi->compositor);
1512 ivi_output = to_ivi_output(output);
1514 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1515 struct weston_view *ev = surf->view;
1516 struct weston_desktop_surface *dsurf = surf->dsurface;
1518 if (surf != ivi_output->active)
1521 weston_layer_entry_remove(&surf->view->layer_link);
1522 weston_view_geometry_dirty(surf->view);
1523 weston_surface_damage(surf->view->surface);
1525 surf->hidden_layer_output = ivi_output;
1527 /* set attributes */
1528 surf->fullscreen.output = ivi_output;
1530 /* change the role */
1531 surf->role = IVI_SURFACE_ROLE_NONE;
1533 wl_list_remove(&surf->link);
1534 wl_list_init(&surf->link);
1536 ivi_set_desktop_surface_fullscreen(surf);
1538 weston_desktop_surface_set_maximized(dsurf, false);
1539 weston_desktop_surface_set_fullscreen(dsurf, true);
1540 weston_desktop_surface_set_size(dsurf,
1541 ivi_output->output->width,
1542 ivi_output->output->height);
1544 /* add to hidden layer */
1545 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1546 weston_compositor_schedule_repaint(ivi->compositor);
1547 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_FULLSCREEN)) {
1548 ivi_set_pending_desktop_surface_fullscreen(ivi_output, app_id);
1554 shell_set_app_normal(struct wl_client *client, struct wl_resource *shell_res,
1557 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1558 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1559 struct weston_output *output = get_focused_output(ivi->compositor);
1560 struct ivi_output *ivi_output;
1561 struct weston_desktop_surface *dsurf;
1562 struct weston_geometry area = {};
1565 if (!surf || (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP))
1569 output = get_default_output(ivi->compositor);
1571 dsurf = surf->dsurface;
1572 ivi_output = to_ivi_output(output);
1574 weston_layer_entry_remove(&surf->view->layer_link);
1575 weston_view_geometry_dirty(surf->view);
1576 weston_surface_damage(surf->view->surface);
1578 /* change the role */
1579 surf->role = IVI_SURFACE_ROLE_NONE;
1580 surf->state = NORMAL;
1581 surf->desktop.pending_output = ivi_output;
1583 wl_list_remove(&surf->link);
1584 wl_list_init(&surf->link);
1586 ivi_set_desktop_surface(surf);
1588 if (ivi_output->area_activation.width ||
1589 ivi_output->area_activation.height)
1590 area = ivi_output->area_activation;
1592 area = ivi_output->area;
1594 if (weston_desktop_surface_get_fullscreen(dsurf))
1595 weston_desktop_surface_set_fullscreen(dsurf, false);
1597 weston_desktop_surface_set_maximized(dsurf, true);
1598 weston_desktop_surface_set_size(dsurf, area.width, area.height);
1600 /* add to hidden layer */
1601 weston_layer_entry_insert(&ivi->hidden.view_list,
1602 &surf->view->layer_link);
1603 weston_compositor_schedule_repaint(ivi->compositor);
1608 shell_desktop_activate_app(struct wl_client *client,
1609 struct wl_resource *shell_res,
1610 const char *app_id, const char *data,
1611 struct wl_resource *output_res)
1613 struct weston_head *head = weston_head_from_resource(output_res);
1614 struct weston_output *woutput = weston_head_get_output(head);
1615 struct ivi_output *output = to_ivi_output(woutput);
1617 ivi_layout_activate(output, app_id);
1618 shell_advertise_app_state(output->ivi, app_id,
1619 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1623 shell_deactivate_app(struct wl_client *client,
1624 struct wl_resource *shell_res,
1627 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1628 struct ivi_compositor *ivi = dclient->ivi;
1630 ivi_layout_deactivate(ivi, app_id);
1631 shell_advertise_app_state(ivi, app_id,
1632 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1636 shell_destroy(struct wl_client *client, struct wl_resource *res)
1638 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1640 /* reset status in case bind_fail was sent */
1641 if (wl_resource_get_version(res) >= AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1642 ivi->shell_client.status == BOUND_FAILED)
1643 ivi->shell_client.status = BOUND_OK;
1647 shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
1648 struct wl_resource *output, int x, int y,
1649 int width, int height)
1651 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1652 struct weston_head *head = weston_head_from_resource(output);
1653 struct weston_output *woutput = weston_head_get_output(head);
1654 struct ivi_output *ioutput = to_ivi_output(woutput);
1656 struct weston_geometry area = { .x = x, .y = y,
1659 if (ivi->shell_client.ready)
1662 ioutput->area_activation = area;
1666 shell_set_app_output(struct wl_client *client, struct wl_resource *res,
1667 const char *app_id, struct wl_resource *output)
1669 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1670 struct weston_head *head = weston_head_from_resource(output);
1671 struct weston_output *woutput = weston_head_get_output(head);
1672 struct ivi_output *ioutput = to_ivi_output(woutput);
1673 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1674 struct ivi_output *desktop_last_output;
1675 struct ivi_output *current_completed_output;
1677 if (!app_id || !ioutput)
1680 /* handle the case we're not mapped at all */
1682 ivi_set_pending_desktop_surface_remote(ioutput, app_id);
1683 shell_send_app_on_output(ivi, app_id, woutput->name);
1687 desktop_last_output = surf->desktop.last_output;
1688 current_completed_output = surf->current_completed_output;
1690 if (surf->remote.output)
1691 surf->hidden_layer_output = surf->remote.output;
1693 surf->hidden_layer_output = desktop_last_output;
1694 assert(surf->hidden_layer_output);
1696 if (ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_REMOTE) ||
1697 ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_DESKTOP)) {
1698 if (!current_completed_output->background)
1699 insert_black_curtain(current_completed_output);
1701 ivi_layout_deactivate(ivi, app_id);
1704 /* update the remote output */
1705 surf->remote.output = ioutput;
1707 if (surf->role != IVI_SURFACE_ROLE_REMOTE) {
1708 wl_list_remove(&surf->link);
1709 wl_list_init(&surf->link);
1711 surf->role = IVI_SURFACE_ROLE_NONE;
1712 ivi_set_desktop_surface_remote(surf);
1715 shell_send_app_on_output(ivi, app_id, woutput->name);
1719 shell_set_app_position(struct wl_client *client, struct wl_resource *res,
1720 const char *app_id, int32_t x, int32_t y)
1722 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1723 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1725 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1728 weston_view_set_position(surf->view, x, y);
1729 weston_compositor_schedule_repaint(ivi->compositor);
1733 shell_set_app_scale(struct wl_client *client, struct wl_resource *res,
1734 const char *app_id, int32_t width, int32_t height)
1737 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1738 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1740 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1743 weston_desktop_surface_set_size(surf->dsurface, width, height);
1744 weston_compositor_schedule_repaint(ivi->compositor);
1748 _ivi_set_pending_desktop_surface_split(struct wl_resource *output,
1749 const char *app_id, uint32_t orientation)
1751 weston_log("%s() added split surface for app_id '%s' with "
1752 "orientation %d to pending\n", __func__, app_id, orientation);
1754 struct weston_head *head = weston_head_from_resource(output);
1755 struct weston_output *woutput = weston_head_get_output(head);
1756 struct ivi_output *ivi_output = to_ivi_output(woutput);
1758 struct pending_app_tile *app_tile = zalloc(sizeof(*app_tile));
1760 app_tile->base.app_id = strdup(app_id);
1761 app_tile->base.ioutput = ivi_output;
1762 app_tile->base.role = IVI_SURFACE_ROLE_TILE;
1764 app_tile->orientation = orientation;
1765 wl_list_insert(&ivi_output->ivi->pending_apps, &app_tile->base.link);
1770 reverse_orientation(uint32_t orientation)
1773 switch (orientation) {
1774 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1775 return AGL_SHELL_TILE_ORIENTATION_RIGHT;
1777 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1778 return AGL_SHELL_TILE_ORIENTATION_LEFT;
1780 case AGL_SHELL_TILE_ORIENTATION_TOP:
1781 return AGL_SHELL_TILE_ORIENTATION_BOTTOM;
1783 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1784 return AGL_SHELL_TILE_ORIENTATION_TOP;
1787 return AGL_SHELL_TILE_ORIENTATION_NONE;
1792 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *ioutput,
1793 uint32_t orientation, bool to_activate)
1795 struct ivi_compositor *ivi = surface->ivi;
1796 struct weston_geometry geom = {};
1797 struct ivi_output *output = NULL;
1802 geom = weston_desktop_surface_get_geometry(surface->dsurface);
1803 output = ivi_layout_get_output_from_surface(surface);
1808 width = output->area.width;
1809 height = output->area.height;
1811 switch (orientation) {
1812 case AGL_SHELL_TILE_ORIENTATION_LEFT:
1813 case AGL_SHELL_TILE_ORIENTATION_RIGHT:
1816 case AGL_SHELL_TILE_ORIENTATION_TOP:
1817 case AGL_SHELL_TILE_ORIENTATION_BOTTOM:
1820 case AGL_SHELL_TILE_ORIENTATION_NONE:
1824 assert(!"Invalid orientation passed");
1828 x = output->area.x - geom.x;
1829 y = output->area.y - geom.y;
1831 if (orientation == AGL_SHELL_TILE_ORIENTATION_RIGHT)
1833 else if (orientation == AGL_SHELL_TILE_ORIENTATION_BOTTOM)
1837 struct weston_view *ev = surface->view;
1838 struct ivi_shell_seat *ivi_seat = NULL;
1839 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
1842 ivi_seat = get_ivi_shell_seat(wseat);
1844 if (!weston_view_is_mapped(ev))
1845 weston_view_update_transform(ev);
1847 weston_layer_entry_remove(&ev->layer_link);
1850 // mark view as mapped
1851 ev->is_mapped = true;
1852 ev->surface->is_mapped = true;
1853 surface->mapped = true;
1855 // update older/new active surface
1856 output->previous_active = output->active;
1857 output->active = surface;
1859 // add to the layer and inflict damage
1860 weston_view_set_output(ev, output->output);
1861 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1862 weston_view_geometry_dirty(ev);
1863 weston_surface_damage(ev->surface);
1865 // handle input / keyboard
1867 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
1870 weston_view_set_position(surface->view, x, y);
1871 weston_desktop_surface_set_size(surface->dsurface, width, height);
1872 weston_desktop_surface_set_orientation(surface->dsurface, orientation);
1873 surface->orientation = orientation;
1875 weston_compositor_schedule_repaint(ivi->compositor);
1877 weston_log("%s() Setting to x=%d, y=%d, width=%d, height=%d, orientation=%d\n",
1878 __func__, x, y, width, height, orientation);
1883 shell_ivi_surf_count_split_surfaces(struct ivi_compositor *ivi)
1886 struct ivi_surface *surf;
1888 wl_list_for_each(surf, &ivi->surfaces, link) {
1889 if (surf->orientation > AGL_SHELL_TILE_ORIENTATION_NONE)
1898 void shell_set_app_split(struct wl_client *client, struct wl_resource *res,
1899 const char *app_id, uint32_t orientation,
1900 struct wl_resource *output_res)
1902 struct ivi_surface *surf;
1903 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1905 struct weston_head *head = weston_head_from_resource(output_res);
1906 struct weston_output *woutput = weston_head_get_output(head);
1907 struct ivi_output *output = to_ivi_output(woutput);
1912 if (shell_ivi_surf_count_split_surfaces(ivi) > 2) {
1913 weston_log("Found more than two split surfaces in tile orientation.\n");
1917 /* add it as pending until */
1918 surf = ivi_find_app(ivi, app_id);
1920 _ivi_set_pending_desktop_surface_split(output_res, app_id, orientation);
1924 /* otherwise, take actions now */
1925 weston_log("%s() added split surface for app_id '%s' with orientation %d\n",
1926 __func__, app_id, orientation);
1928 if (output->previous_active) {
1929 struct weston_view *ev = output->previous_active->view;
1931 if (!weston_view_is_mapped(ev))
1932 weston_view_update_transform(ev);
1934 weston_layer_entry_remove(&ev->layer_link);
1936 ev->is_mapped = true;
1937 ev->surface->is_mapped = true;
1938 output->previous_active->mapped = true;
1940 weston_view_set_output(ev, woutput);
1942 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1944 _ivi_set_shell_surface_split(output->previous_active, NULL,
1945 reverse_orientation(orientation), false);
1947 if (orientation == AGL_SHELL_TILE_ORIENTATION_NONE &&
1948 output->active == surf) {
1949 output->active = output->previous_active;
1953 _ivi_set_shell_surface_split(surf, NULL, orientation, false);
1957 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
1959 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1961 ivi->shell_client_ext.doas_requested = false;
1962 wl_resource_destroy(res);
1966 shell_ext_doas(struct wl_client *client, struct wl_resource *res)
1968 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1970 ivi->shell_client_ext.doas_requested = true;
1972 if (ivi->shell_client_ext.resource && ivi->shell_client.resource) {
1973 ivi->shell_client_ext.doas_requested_pending_bind = true;
1975 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
1976 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS);
1978 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
1979 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_FAILED);
1984 static const struct agl_shell_interface agl_shell_implementation = {
1985 .ready = shell_ready,
1986 .set_background = shell_set_background,
1987 .set_panel = shell_set_panel,
1988 .activate_app = shell_activate_app,
1989 .destroy = shell_destroy,
1990 .set_activate_region = shell_set_activate_region,
1991 .deactivate_app = shell_new_deactivate_app,
1992 .set_app_float = shell_set_app_float,
1993 .set_app_normal = shell_set_app_normal,
1994 .set_app_fullscreen = shell_set_app_fullscreen,
1995 .set_app_output = shell_set_app_output,
1996 .set_app_position = shell_set_app_position,
1997 .set_app_scale = shell_set_app_scale,
1998 .set_app_split = shell_set_app_split,
2001 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
2002 .destroy = shell_ext_destroy,
2003 .doas_shell_client = shell_ext_doas,
2007 shell_desktop_set_app_property(struct wl_client *client,
2008 struct wl_resource *shell_res,
2009 const char *app_id, uint32_t role,
2010 int x, int y, int bx, int by,
2011 int width, int height,
2012 struct wl_resource *output_res)
2014 struct weston_head *head = weston_head_from_resource(output_res);
2015 struct weston_output *woutput = weston_head_get_output(head);
2016 struct ivi_output *output = to_ivi_output(woutput);
2019 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
2020 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
2021 width, height, app_id);
2023 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
2024 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
2026 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
2027 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
2028 ivi_set_pending_desktop_surface_split(output, app_id, role);
2030 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
2031 ivi_set_pending_desktop_surface_remote(output, app_id);
2039 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
2041 struct pending_popup *p_popup, *next_p_popup;
2042 struct pending_split *split_surf, *next_split_surf;
2043 struct pending_fullscreen *fs_surf, *next_fs_surf;
2044 struct pending_remote *remote_surf, *next_remote_surf;
2046 wl_list_for_each_safe(p_popup, next_p_popup,
2047 &ivi->popup_pending_apps, link)
2048 ivi_remove_pending_desktop_surface_popup(p_popup);
2050 wl_list_for_each_safe(split_surf, next_split_surf,
2051 &ivi->split_pending_apps, link)
2052 ivi_remove_pending_desktop_surface_split(split_surf);
2054 wl_list_for_each_safe(fs_surf, next_fs_surf,
2055 &ivi->fullscreen_pending_apps, link)
2056 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
2058 wl_list_for_each_safe(remote_surf, next_remote_surf,
2059 &ivi->remote_pending_apps, link)
2060 ivi_remove_pending_desktop_surface_remote(remote_surf);
2064 shell_desktop_set_app_property_mode(struct wl_client *client,
2065 struct wl_resource *shell_res, uint32_t perm)
2067 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
2069 dclient->ivi->keep_pending_surfaces = true;
2071 dclient->ivi->keep_pending_surfaces = false;
2072 /* remove any previous pending surfaces */
2073 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
2077 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
2078 .activate_app = shell_desktop_activate_app,
2079 .set_app_property = shell_desktop_set_app_property,
2080 .deactivate_app = shell_deactivate_app,
2081 .set_app_property_mode = shell_desktop_set_app_property_mode,
2085 unbind_agl_shell(struct wl_resource *resource)
2087 struct ivi_compositor *ivi;
2088 struct ivi_output *output;
2089 struct ivi_surface *surf, *surf_tmp;
2091 ivi = wl_resource_get_user_data(resource);
2093 /* reset status to allow other clients issue legit requests */
2094 if (wl_resource_get_version(resource) >=
2095 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
2096 ivi->shell_client.status == BOUND_FAILED) {
2097 ivi->shell_client.status = BOUND_OK;
2101 wl_list_for_each(output, &ivi->outputs, link) {
2103 /* reset the active surf if there's one present */
2104 if (output->active) {
2105 struct weston_geometry area = {};
2107 output->active->view->is_mapped = false;
2108 output->active->view->surface->is_mapped = false;
2110 weston_layer_entry_remove(&output->active->view->layer_link);
2111 output->active = NULL;
2113 output->area_activation = area;
2116 insert_black_curtain(output);
2119 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
2120 wl_list_remove(&surf->link);
2121 wl_list_init(&surf->link);
2124 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
2125 wl_list_remove(&surf->link);
2126 wl_list_init(&surf->link);
2129 wl_list_init(&ivi->surfaces);
2130 wl_list_init(&ivi->pending_surfaces);
2132 ivi->shell_client.ready = false;
2133 ivi->shell_client.resource = NULL;
2134 ivi->shell_client.resource_ext = NULL;
2135 ivi->shell_client.client = NULL;
2139 unbind_agl_shell_ext(struct wl_resource *resource)
2141 struct ivi_compositor *ivi = wl_resource_get_user_data(resource);
2143 ivi->shell_client_ext.resource = NULL;
2144 ivi->shell_client.resource_ext = NULL;
2145 ivi->shell_client_ext.doas_requested = false;
2149 bind_agl_shell(struct wl_client *client,
2150 void *data, uint32_t version, uint32_t id)
2152 struct ivi_compositor *ivi = data;
2153 struct wl_resource *resource;
2154 struct ivi_policy *policy;
2157 policy = ivi->policy;
2158 interface = (void *) &agl_shell_interface;
2159 if (policy && policy->api.shell_bind_interface &&
2160 !policy->api.shell_bind_interface(client, interface)) {
2161 wl_client_post_implementation_error(client,
2162 "client not authorized to use agl_shell");
2166 resource = wl_resource_create(client, &agl_shell_interface, version, id);
2168 wl_client_post_no_memory(client);
2172 if (ivi->shell_client.resource && wl_resource_get_version(resource) == 1) {
2173 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2174 "agl_shell has already been bound (version 1)");
2175 wl_resource_destroy(resource);
2179 // for agl_shell client proxy
2180 if (ivi->shell_client.resource &&
2181 ivi->shell_client_ext.doas_requested_pending_bind) {
2183 ivi->shell_client_ext.doas_requested_pending_bind = false;
2185 // if there's one connected
2186 if (ivi->shell_client.resource_ext) {
2187 ivi->shell_client_ext.status = BOUND_FAILED;
2188 agl_shell_send_bound_fail(ivi->shell_client.resource_ext);
2189 wl_resource_destroy(resource);
2193 wl_resource_set_implementation(resource, &agl_shell_implementation,
2195 ivi->shell_client.resource_ext = resource;
2196 ivi->shell_client_ext.status = BOUND_OK;
2197 agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
2202 // if we already have an agl_shell client
2203 if (ivi->shell_client.resource) {
2204 agl_shell_send_bound_fail(resource);
2205 ivi->shell_client.status = BOUND_FAILED;
2206 wl_resource_destroy(resource);
2210 // default agl_shell client
2211 wl_resource_set_implementation(resource, &agl_shell_implementation,
2212 ivi, unbind_agl_shell);
2213 ivi->shell_client.resource = resource;
2215 if (wl_resource_get_version(resource) >=
2216 AGL_SHELL_BOUND_OK_SINCE_VERSION) {
2217 /* if we land here we'll have BOUND_OK by default,
2218 but still do the assignment */
2219 ivi->shell_client.status = BOUND_OK;
2220 agl_shell_send_bound_ok(ivi->shell_client.resource);
2225 bind_agl_shell_ext(struct wl_client *client,
2226 void *data, uint32_t version, uint32_t id)
2228 struct ivi_compositor *ivi = data;
2229 struct wl_resource *resource;
2231 resource = wl_resource_create(client, &agl_shell_ext_interface, version, id);
2233 wl_client_post_no_memory(client);
2237 if (ivi->shell_client_ext.resource) {
2238 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2239 "agl_shell_ext has already been bound");
2243 wl_resource_set_implementation(resource, &agl_shell_ext_implementation,
2244 ivi, unbind_agl_shell_ext);
2245 ivi->shell_client_ext.resource = resource;
2249 unbind_agl_shell_desktop(struct wl_resource *resource)
2251 struct desktop_client *dclient = wl_resource_get_user_data(resource);
2253 wl_list_remove(&dclient->link);
2258 bind_agl_shell_desktop(struct wl_client *client,
2259 void *data, uint32_t version, uint32_t id)
2261 struct ivi_compositor *ivi = data;
2262 struct wl_resource *resource;
2263 struct ivi_policy *policy;
2264 struct desktop_client *dclient;
2267 policy = ivi->policy;
2268 interface = (void *) &agl_shell_desktop_interface;
2269 if (policy && policy->api.shell_bind_interface &&
2270 !policy->api.shell_bind_interface(client, interface)) {
2271 wl_client_post_implementation_error(client,
2272 "client not authorized to use agl_shell_desktop");
2276 dclient = zalloc(sizeof(*dclient));
2278 wl_client_post_no_memory(client);
2282 resource = wl_resource_create(client, &agl_shell_desktop_interface,
2286 wl_client_post_no_memory(client);
2290 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
2291 dclient, unbind_agl_shell_desktop);
2293 dclient->resource = resource;
2294 wl_list_insert(&ivi->desktop_clients, &dclient->link);
2296 /* advertise xdg surfaces */
2297 ivi_shell_advertise_xdg_surfaces(ivi, resource);
2301 ivi_shell_create_global(struct ivi_compositor *ivi)
2303 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
2304 &agl_shell_interface, 11,
2305 ivi, bind_agl_shell);
2306 if (!ivi->agl_shell) {
2307 weston_log("Failed to create wayland global.\n");
2311 ivi->agl_shell_ext = wl_global_create(ivi->compositor->wl_display,
2312 &agl_shell_ext_interface, 1,
2313 ivi, bind_agl_shell_ext);
2314 if (!ivi->agl_shell_ext) {
2315 weston_log("Failed to create agl_shell_ext global.\n");
2319 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
2320 &agl_shell_desktop_interface, 2,
2321 ivi, bind_agl_shell_desktop);
2322 if (!ivi->agl_shell_desktop) {
2323 weston_log("Failed to create wayland global (agl_shell_desktop).\n");