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 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
54 struct ivi_surface *surface)
56 struct desktop_client *dclient;
57 static bool display_adv = false;
59 if (surface->advertised_on_launch)
62 /* advertise to all desktop clients the new surface */
63 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
65 weston_desktop_surface_get_app_id(surface->dsurface);
68 weston_log("WARNING app_is is null, unable to advertise\n");
73 agl_shell_desktop_send_application(dclient->resource, app_id);
74 surface->advertised_on_launch = true;
79 ivi_set_desktop_surface(struct ivi_surface *surface)
81 struct ivi_compositor *ivi = surface->ivi;
82 assert(surface->role == IVI_SURFACE_ROLE_NONE);
84 surface->role = IVI_SURFACE_ROLE_DESKTOP;
85 wl_list_insert(&surface->ivi->surfaces, &surface->link);
87 agl_shell_desktop_advertise_application_id(ivi, surface);
91 ivi_set_background_surface(struct ivi_surface *surface)
93 struct ivi_compositor *ivi = surface->ivi;
94 assert(surface->role == IVI_SURFACE_ROLE_BACKGROUND);
96 wl_list_insert(&surface->ivi->surfaces, &surface->link);
97 agl_shell_desktop_advertise_application_id(ivi, surface);
101 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
103 struct ivi_compositor *ivi = surface->ivi;
104 assert(surface->role == IVI_SURFACE_ROLE_NONE);
106 surface->role = IVI_SURFACE_ROLE_POPUP;
107 wl_list_insert(&ivi->surfaces, &surface->link);
109 agl_shell_desktop_advertise_application_id(ivi, surface);
113 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
115 struct ivi_compositor *ivi = surface->ivi;
116 assert(surface->role == IVI_SURFACE_ROLE_NONE);
118 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
119 wl_list_insert(&ivi->surfaces, &surface->link);
121 agl_shell_desktop_advertise_application_id(ivi, surface);
125 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
127 struct ivi_compositor *ivi = surface->ivi;
128 struct weston_view *view;
129 struct ivi_output *output = surface->remote.output;
131 assert(surface->role == IVI_SURFACE_ROLE_NONE);
133 /* remote type are the same as desktop just that client can tell
134 * the compositor to start on another output */
135 surface->role = IVI_SURFACE_ROLE_REMOTE;
137 /* if thew black surface view is mapped on the mean we need
138 * to remove it in order to start showing the 'remote' surface
139 * just being added */
140 view = output->fullscreen_view.fs->view;
141 if (view->is_mapped || view->surface->is_mapped)
142 remove_black_curtain(output);
144 wl_list_insert(&ivi->surfaces, &surface->link);
149 ivi_set_desktop_surface_split(struct ivi_surface *surface)
151 struct ivi_compositor *ivi = surface->ivi;
152 assert(surface->role == IVI_SURFACE_ROLE_NONE);
154 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
155 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
157 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
159 wl_list_insert(&ivi->surfaces, &surface->link);
161 agl_shell_desktop_advertise_application_id(ivi, surface);
164 static struct pending_popup *
165 ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
166 int width, int height, const char *app_id)
168 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
169 size_t len_app_id = strlen(app_id);
173 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
174 if (!p_popup->app_id) {
178 memcpy(p_popup->app_id, app_id, len_app_id);
179 p_popup->ioutput = ioutput;
185 p_popup->bb.width = width;
186 p_popup->bb.height = height;
192 ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
193 int width, int height, const char *app_id, struct pending_popup *p_popup)
195 size_t len_app_id = strlen(app_id);
197 wl_list_remove(&p_popup->link);
198 wl_list_init(&p_popup->link);
200 memset(p_popup->app_id, 0, strlen(app_id) + 1);
201 free(p_popup->app_id);
203 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
204 if (!p_popup->app_id)
206 memcpy(p_popup->app_id, app_id, len_app_id);
208 p_popup->ioutput = ioutput;
214 p_popup->bb.width = width;
215 p_popup->bb.height = height;
218 static struct pending_fullscreen *
219 ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
221 struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
222 size_t len_app_id = strlen(app_id);
226 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
227 if (!p_fullscreen->app_id) {
231 memcpy(p_fullscreen->app_id, app_id, len_app_id);
233 p_fullscreen->ioutput = ioutput;
238 ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
239 struct pending_fullscreen *p_fullscreen)
241 size_t len_app_id = strlen(app_id);
243 wl_list_remove(&p_fullscreen->link);
244 wl_list_init(&p_fullscreen->link);
246 memset(p_fullscreen->app_id, 0, strlen(app_id) + 1);
247 free(p_fullscreen->app_id);
249 p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
250 if (!p_fullscreen->app_id)
252 memcpy(p_fullscreen->app_id, app_id, len_app_id);
254 p_fullscreen->ioutput = ioutput;
257 static struct pending_remote *
258 ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
260 struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
261 size_t len_app_id = strlen(app_id);
265 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
266 if (!p_remote->app_id) {
270 memcpy(p_remote->app_id, app_id, len_app_id);
272 p_remote->ioutput = ioutput;
277 ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
278 struct pending_remote *p_remote)
280 size_t len_app_id = strlen(app_id);
282 wl_list_remove(&p_remote->link);
283 wl_list_init(&p_remote->link);
285 memset(p_remote->app_id, 0, strlen(app_id) + 1);
286 free(p_remote->app_id);
288 p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
289 if (!p_remote->app_id)
291 memcpy(p_remote->app_id, app_id, len_app_id);
293 p_remote->ioutput = ioutput;
297 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y, int bx,
298 int by, int width, int height, const char *app_id)
300 struct ivi_compositor *ivi = ioutput->ivi;
301 struct pending_popup *p_popup = NULL;
302 struct pending_popup *popup;
304 wl_list_for_each(popup, &ivi->popup_pending_apps, link)
305 if (!strcmp(app_id, popup->app_id))
309 p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
311 ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
315 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
319 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
322 struct ivi_compositor *ivi = ioutput->ivi;
323 struct pending_fullscreen *p_fullscreen = NULL;
324 struct pending_fullscreen *fullscreen;
326 wl_list_for_each(fullscreen, &ivi->fullscreen_pending_apps, link)
327 if (!strcmp(app_id, fullscreen->app_id))
328 p_fullscreen = fullscreen;
331 p_fullscreen = ivi_ensure_fullscreen(ioutput, app_id);
333 ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
337 wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
341 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
342 const char *app_id, uint32_t orientation)
344 struct ivi_compositor *ivi = ioutput->ivi;
345 struct ivi_surface *surf;
346 size_t len_app_id = strlen(app_id);
347 struct pending_split *split;
349 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
350 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
353 /* more than one is un-supported, do note we need to do
354 * conversion for surface roles instead of using the protocol ones */
355 wl_list_for_each(surf, &ivi->surfaces, link)
356 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
357 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
360 split = zalloc(sizeof(*split));
363 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
364 if (!split->app_id) {
368 memcpy(split->app_id, app_id, len_app_id);
370 split->ioutput = ioutput;
371 split->orientation = orientation;
373 wl_list_insert(&ivi->split_pending_apps, &split->link);
377 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
380 struct ivi_compositor *ivi = ioutput->ivi;
381 struct pending_remote *remote;
382 struct pending_remote *p_remote = NULL;
384 wl_list_for_each(remote, &ivi->remote_pending_apps, link)
385 if (!strcmp(app_id, remote->app_id))
389 p_remote = ivi_ensure_remote(ioutput, app_id);
391 ivi_update_remote(ioutput, app_id, p_remote);
395 wl_list_insert(&ivi->remote_pending_apps, &p_remote->link);
400 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
403 wl_list_remove(&split->link);
408 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
411 wl_list_remove(&fs->link);
416 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
418 free(p_popup->app_id);
419 wl_list_remove(&p_popup->link);
424 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
426 free(remote->app_id);
427 wl_list_remove(&remote->link);
432 ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
434 return surface->ivi->keep_pending_surfaces;
438 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
440 struct ivi_compositor *ivi = surface->ivi;
441 struct pending_popup *p_popup, *next_p_popup;
442 const char *_app_id =
443 weston_desktop_surface_get_app_id(surface->dsurface);
445 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
448 wl_list_for_each_safe(p_popup, next_p_popup,
449 &ivi->popup_pending_apps, link) {
450 if (!strcmp(_app_id, p_popup->app_id)) {
451 surface->popup.output = p_popup->ioutput;
452 surface->popup.x = p_popup->x;
453 surface->popup.y = p_popup->y;
455 surface->popup.bb.x = p_popup->bb.x;
456 surface->popup.bb.y = p_popup->bb.y;
457 surface->popup.bb.width = p_popup->bb.width;
458 surface->popup.bb.height = p_popup->bb.height;
460 if (!ivi_compositor_keep_pending_surfaces(surface))
461 ivi_remove_pending_desktop_surface_popup(p_popup);
470 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
472 struct pending_split *split_surf, *next_split_surf;
473 struct ivi_compositor *ivi = surface->ivi;
474 const char *_app_id =
475 weston_desktop_surface_get_app_id(surface->dsurface);
477 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
480 wl_list_for_each_safe(split_surf, next_split_surf,
481 &ivi->split_pending_apps, link) {
482 if (!strcmp(_app_id, split_surf->app_id)) {
483 surface->split.output = split_surf->ioutput;
484 surface->split.orientation = split_surf->orientation;
485 if (!ivi_compositor_keep_pending_surfaces(surface))
486 ivi_remove_pending_desktop_surface_split(split_surf);
495 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
497 struct pending_fullscreen *fs_surf, *next_fs_surf;
498 struct ivi_compositor *ivi = surface->ivi;
499 const char *_app_id =
500 weston_desktop_surface_get_app_id(surface->dsurface);
502 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
505 wl_list_for_each_safe(fs_surf, next_fs_surf,
506 &ivi->fullscreen_pending_apps, link) {
507 if (!strcmp(_app_id, fs_surf->app_id)) {
508 surface->fullscreen.output = fs_surf->ioutput;
509 if (!ivi_compositor_keep_pending_surfaces(surface))
510 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
519 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
521 struct pending_remote *remote_surf, *next_remote_surf;
522 struct ivi_compositor *ivi = surface->ivi;
523 const char *_app_id =
524 weston_desktop_surface_get_app_id(surface->dsurface);
526 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
529 wl_list_for_each_safe(remote_surf, next_remote_surf,
530 &ivi->remote_pending_apps, link) {
531 if (!strcmp(_app_id, remote_surf->app_id)) {
532 surface->remote.output = remote_surf->ioutput;
533 if (!ivi_compositor_keep_pending_surfaces(surface))
534 ivi_remove_pending_desktop_surface_remote(remote_surf);
542 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
543 enum ivi_surface_role *role)
545 struct ivi_compositor *ivi = surface->ivi;
546 struct wl_list *role_pending_list;
547 struct pending_popup *p_popup;
548 struct pending_split *p_split;
549 struct pending_fullscreen *p_fullscreen;
550 struct pending_remote *p_remote;
552 weston_desktop_surface_get_app_id(surface->dsurface);
554 role_pending_list = &ivi->popup_pending_apps;
555 wl_list_for_each(p_popup, role_pending_list, link) {
556 if (app_id && !strcmp(app_id, p_popup->app_id)) {
557 *role = IVI_SURFACE_ROLE_POPUP;
562 role_pending_list = &ivi->split_pending_apps;
563 wl_list_for_each(p_split, role_pending_list, link) {
564 if (app_id && !strcmp(app_id, p_split->app_id)) {
565 *role = IVI_SURFACE_ROLE_SPLIT_V;
570 role_pending_list = &ivi->fullscreen_pending_apps;
571 wl_list_for_each(p_fullscreen, role_pending_list, link) {
572 if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
573 *role = IVI_SURFACE_ROLE_FULLSCREEN;
578 role_pending_list = &ivi->remote_pending_apps;
579 wl_list_for_each(p_remote, role_pending_list, link) {
580 if (app_id && !strcmp(app_id, p_remote->app_id)) {
581 *role = IVI_SURFACE_ROLE_REMOTE;
586 /* else, we are a regular desktop surface */
587 *role = IVI_SURFACE_ROLE_DESKTOP;
592 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
596 ret = ivi_check_pending_desktop_surface_popup(surface);
598 ivi_set_desktop_surface_popup(surface);
599 ivi_layout_popup_committed(surface);
603 ret = ivi_check_pending_desktop_surface_split(surface);
605 ivi_set_desktop_surface_split(surface);
606 ivi_layout_split_committed(surface);
610 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
612 ivi_set_desktop_surface_fullscreen(surface);
613 ivi_layout_fullscreen_committed(surface);
617 ret = ivi_check_pending_desktop_surface_remote(surface);
619 ivi_set_desktop_surface_remote(surface);
620 ivi_layout_remote_committed(surface);
624 /* if we end up here means we have a regular desktop app and
625 * try to activate it */
626 ivi_set_desktop_surface(surface);
627 ivi_layout_desktop_committed(surface);
631 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
633 struct ivi_output *out;
635 wl_list_for_each(out, &ivi->outputs, link) {
636 create_black_curtain_view(out);
637 insert_black_curtain(out);
642 ivi_shell_init(struct ivi_compositor *ivi)
644 weston_layer_init(&ivi->hidden, ivi->compositor);
645 weston_layer_init(&ivi->background, ivi->compositor);
646 weston_layer_init(&ivi->normal, ivi->compositor);
647 weston_layer_init(&ivi->panel, ivi->compositor);
648 weston_layer_init(&ivi->popup, ivi->compositor);
649 weston_layer_init(&ivi->fullscreen, ivi->compositor);
651 weston_layer_set_position(&ivi->hidden,
652 WESTON_LAYER_POSITION_HIDDEN);
653 weston_layer_set_position(&ivi->background,
654 WESTON_LAYER_POSITION_BACKGROUND);
655 weston_layer_set_position(&ivi->normal,
656 WESTON_LAYER_POSITION_NORMAL);
657 weston_layer_set_position(&ivi->panel,
658 WESTON_LAYER_POSITION_UI);
659 weston_layer_set_position(&ivi->popup,
660 WESTON_LAYER_POSITION_TOP_UI);
661 weston_layer_set_position(&ivi->fullscreen,
662 WESTON_LAYER_POSITION_FULLSCREEN);
669 ivi_surf_destroy(struct ivi_surface *surf)
671 struct weston_surface *wsurface = surf->view->surface;
673 if (weston_surface_is_mapped(wsurface)) {
674 weston_desktop_surface_unlink_view(surf->view);
675 weston_view_destroy(surf->view);
678 wl_list_remove(&surf->link);
683 ivi_shell_destroy_views_on_layer(struct weston_layer *layer)
685 struct weston_view *view, *view_next;
687 wl_list_for_each_safe(view, view_next, &layer->view_list.link, layer_link.link) {
688 struct ivi_surface *ivi_surf =
689 get_ivi_shell_surface(view->surface);
691 ivi_surf_destroy(ivi_surf);
696 ivi_shell_finalize(struct ivi_compositor *ivi)
698 struct ivi_output *output;
700 ivi_shell_destroy_views_on_layer(&ivi->hidden);
701 weston_layer_fini(&ivi->hidden);
703 ivi_shell_destroy_views_on_layer(&ivi->background);
704 weston_layer_fini(&ivi->background);
706 ivi_shell_destroy_views_on_layer(&ivi->normal);
707 weston_layer_fini(&ivi->normal);
709 ivi_shell_destroy_views_on_layer(&ivi->panel);
710 weston_layer_fini(&ivi->panel);
712 ivi_shell_destroy_views_on_layer(&ivi->popup);
713 weston_layer_fini(&ivi->popup);
715 wl_list_for_each(output, &ivi->outputs, link) {
716 if (output->fullscreen_view.fs &&
717 output->fullscreen_view.fs->view) {
718 weston_surface_destroy(output->fullscreen_view.fs->view->surface);
719 output->fullscreen_view.fs->view = NULL;
722 weston_layer_fini(&ivi->fullscreen);
726 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
728 struct ivi_surface *surface;
730 wl_list_for_each(surface, &ivi->surfaces, link) {
732 weston_desktop_surface_get_app_id(surface->dsurface);
733 if (app_id == NULL) {
734 weston_log("WARNING app_is is null, unable to advertise\n");
737 agl_shell_desktop_send_application(resource, app_id);
741 static struct wl_client *
742 client_launch(struct weston_compositor *compositor,
743 struct weston_process *proc,
745 weston_process_cleanup_func_t cleanup)
747 struct wl_client *client = NULL;
748 struct custom_env child_env;
749 struct fdstr wayland_socket;
750 const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket";
751 const char *fail_seteuid = "Couldn't call seteuid";
758 struct ivi_compositor *ivi;
759 size_t written __attribute__((unused));
761 weston_log("launching '%s'\n", path);
762 str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
764 custom_env_init_from_environ(&child_env);
765 custom_env_add_from_exec_string(&child_env, path);
767 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
768 wayland_socket.fds) < 0) {
769 weston_log("client_launch: "
770 "socketpair failed while launching '%s': %s\n",
771 path, strerror(errno));
772 custom_env_fini(&child_env);
775 fdstr_update_str1(&wayland_socket);
776 custom_env_set_env_var(&child_env, "WAYLAND_SOCKET",
777 wayland_socket.str1);
779 argp = custom_env_get_argp(&child_env);
780 envp = custom_env_get_envp(&child_env);
785 /* Put the client in a new session so it won't catch signals
786 * intended for the parent. Sharing a session can be
787 * confusing when launching weston under gdb, as the ctrl-c
788 * intended for gdb will pass to the child, and weston
789 * will cleanly shut down when the child exits.
793 /* do not give our signal mask to the new process */
794 sigfillset(&allsigs);
795 sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
797 /* Launch clients as the user. Do not launch clients with wrong euid. */
798 if (seteuid(getuid()) == -1) {
799 written = write(STDERR_FILENO, fail_seteuid, strlen(fail_seteuid));
803 ret = fdstr_clear_cloexec_fd1(&wayland_socket);
805 written = write(STDERR_FILENO, fail_cloexec, strlen(fail_cloexec));
809 execve(argp[0], argp, envp);
812 written = write(STDERR_FILENO, fail_exec, strlen(fail_exec));
816 close(wayland_socket.fds[1]);
817 ivi = weston_compositor_get_user_data(compositor);
818 client = wl_client_create(compositor->wl_display,
819 wayland_socket.fds[0]);
821 custom_env_fini(&child_env);
822 close(wayland_socket.fds[0]);
824 weston_log("client_launch: "
825 "wl_client_create failed while launching '%s'.\n",
831 proc->cleanup = cleanup;
832 wl_list_insert(&ivi->child_process_list, &proc->link);
836 fdstr_close_all(&wayland_socket);
837 weston_log("client_launch: "
838 "fork failed while launching '%s': %s\n", path,
843 custom_env_fini(&child_env);
849 struct process_info {
850 struct weston_process proc;
855 sigchld_handler(int signal_number, void *data)
857 struct weston_process *p;
858 struct ivi_compositor *ivi = data;
862 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
863 wl_list_for_each(p, &ivi->child_process_list, link) {
868 if (&p->link == &ivi->child_process_list) {
869 weston_log("unknown child process exited\n");
873 wl_list_remove(&p->link);
874 wl_list_init(&p->link);
875 p->cleanup(p, status);
878 if (pid < 0 && errno != ECHILD)
879 weston_log("waitpid error %s\n", strerror(errno));
886 process_handle_sigchld(struct weston_process *process, int status)
888 struct process_info *pinfo =
889 container_of(process, struct process_info, proc);
892 * There are no guarantees whether this runs before or after
893 * the wl_client destructor.
896 if (WIFEXITED(status)) {
897 weston_log("%s exited with status %d\n", pinfo->path,
898 WEXITSTATUS(status));
899 } else if (WIFSIGNALED(status)) {
900 weston_log("%s died on signal %d\n", pinfo->path,
903 weston_log("%s disappeared\n", pinfo->path);
911 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section,
912 struct wl_client **client)
914 struct process_info *pinfo;
915 struct weston_config_section *section;
916 char *command = NULL;
918 section = weston_config_get_section(ivi->config, cmd_section, NULL, NULL);
920 weston_config_section_get_string(section, "command", &command, NULL);
925 pinfo = zalloc(sizeof *pinfo);
929 pinfo->path = strdup(command);
933 *client = client_launch(ivi->compositor, &pinfo->proc, command, process_handle_sigchld);
949 destroy_black_curtain_view(struct wl_listener *listener, void *data)
951 struct fullscreen_view *fs =
952 wl_container_of(listener, fs, fs_destroy);
956 wl_list_remove(&fs->fs_destroy.link);
963 create_black_curtain_view(struct ivi_output *output)
965 struct weston_surface *surface = NULL;
966 struct weston_view *view;
967 struct ivi_compositor *ivi = output->ivi;
968 struct weston_compositor *wc= ivi->compositor;
969 struct weston_output *woutput = output->output;
974 surface = weston_surface_create(wc);
977 view = weston_view_create(surface);
979 weston_surface_destroy(surface);
983 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
984 weston_surface_set_size(surface, woutput->width, woutput->height);
985 weston_view_set_position(view, woutput->x, woutput->y);
987 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
988 if (!output->fullscreen_view.fs) {
989 weston_surface_destroy(surface);
992 output->fullscreen_view.fs->view = view;
994 output->fullscreen_view.fs_destroy.notify = destroy_black_curtain_view;
995 wl_signal_add(&woutput->destroy_signal,
996 &output->fullscreen_view.fs_destroy);
1000 output_has_black_curtain(struct ivi_output *output)
1002 return (output->fullscreen_view.fs &&
1003 output->fullscreen_view.fs->view &&
1004 output->fullscreen_view.fs->view->is_mapped &&
1005 output->fullscreen_view.fs->view->surface->is_mapped);
1009 remove_black_curtain(struct ivi_output *output)
1011 struct weston_view *view;
1014 !output->fullscreen_view.fs &&
1015 !output->fullscreen_view.fs->view) ||
1016 !output->fullscreen_view.fs) {
1017 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1021 view = output->fullscreen_view.fs->view;
1022 assert(view->is_mapped == true ||
1023 view->surface->is_mapped == true);
1025 view->is_mapped = false;
1026 view->surface->is_mapped = false;
1028 weston_layer_entry_remove(&view->layer_link);
1029 weston_view_update_transform(view);
1031 weston_view_damage_below(view);
1033 weston_log("Removed black curtain from output %s\n", output->output->name);
1037 insert_black_curtain(struct ivi_output *output)
1039 struct weston_view *view;
1042 !output->fullscreen_view.fs &&
1043 !output->fullscreen_view.fs->view) || !output->output ||
1044 !output->fullscreen_view.fs) {
1045 weston_log("Output %s doesn't have a surface installed!\n", output->name);
1049 view = output->fullscreen_view.fs->view;
1050 if (view->is_mapped || view->surface->is_mapped)
1053 weston_layer_entry_remove(&view->layer_link);
1054 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
1057 view->is_mapped = true;
1058 view->surface->is_mapped = true;
1060 weston_view_update_transform(view);
1061 weston_view_damage_below(view);
1063 weston_log("Added black curtain to output %s\n", output->output->name);
1067 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
1068 enum agl_shell_app_state state)
1070 if (app_id && wl_resource_get_version(ivi->shell_client.resource) >=
1071 AGL_SHELL_APP_STATE_SINCE_VERSION) {
1073 agl_shell_send_app_state(ivi->shell_client.resource,
1076 if (ivi->shell_client.resource_ext)
1077 agl_shell_send_app_state(ivi->shell_client.resource_ext,
1083 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
1084 const char *output_name)
1086 if (app_id && ivi->shell_client.resource &&
1087 wl_resource_get_version(ivi->shell_client.resource) >=
1088 AGL_SHELL_APP_ON_OUTPUT_SINCE_VERSION) {
1090 agl_shell_send_app_on_output(ivi->shell_client.resource,
1091 app_id, output_name);
1093 if (ivi->shell_client.resource_ext)
1094 agl_shell_send_app_on_output(ivi->shell_client.resource_ext,
1095 app_id, output_name);
1100 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
1102 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1103 struct ivi_output *output;
1104 struct ivi_surface *surface, *tmp;
1106 if (wl_resource_get_version(shell_res) >=
1107 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1108 ivi->shell_client.status == BOUND_FAILED) {
1109 wl_resource_post_error(shell_res,
1110 WL_DISPLAY_ERROR_INVALID_OBJECT,
1111 "agl_shell has already been bound. "
1112 "Check out bound_fail event");
1116 /* Init already finished. Do nothing */
1117 if (ivi->shell_client.ready)
1121 ivi->shell_client.ready = true;
1123 wl_list_for_each(output, &ivi->outputs, link) {
1124 if (output->background &&
1125 output->background->role == IVI_SURFACE_ROLE_BACKGROUND) {
1126 /* track the background surface role as a "regular"
1127 * surface so we can activate it */
1128 ivi_set_background_surface(output->background);
1129 remove_black_curtain(output);
1132 ivi_layout_init(ivi, output);
1135 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
1138 wl_list_remove(&surface->link);
1139 wl_list_init(&surface->link);
1140 ivi_check_pending_desktop_surface(surface);
1141 surface->checked_pending = true;
1142 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
1144 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_STARTED);
1149 shell_set_background(struct wl_client *client,
1150 struct wl_resource *shell_res,
1151 struct wl_resource *surface_res,
1152 struct wl_resource *output_res)
1154 struct weston_head *head = weston_head_from_resource(output_res);
1155 struct weston_output *woutput = weston_head_get_output(head);
1156 struct ivi_output *output = to_ivi_output(woutput);
1157 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1158 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1159 struct weston_desktop_surface *dsurface;
1160 struct ivi_surface *surface;
1162 if ((wl_resource_get_version(shell_res) >=
1163 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1164 ivi->shell_client.status == BOUND_FAILED) ||
1165 ivi->shell_client.resource_ext == shell_res) {
1166 wl_resource_post_error(shell_res,
1167 WL_DISPLAY_ERROR_INVALID_OBJECT,
1168 "agl_shell has already been bound. "
1169 "Check out bound_fail event");
1173 dsurface = weston_surface_get_desktop_surface(wsurface);
1175 wl_resource_post_error(shell_res,
1176 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1177 "surface must be a desktop surface");
1181 surface = weston_desktop_surface_get_user_data(dsurface);
1182 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1183 wl_resource_post_error(shell_res,
1184 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1185 "surface already has another ivi role");
1189 if (output->background) {
1190 wl_resource_post_error(shell_res,
1191 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1192 "output already has background");
1196 surface->checked_pending = true;
1197 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
1198 surface->bg.output = output;
1199 wl_list_remove(&surface->link);
1200 wl_list_init(&surface->link);
1202 output->background = surface;
1204 weston_desktop_surface_set_maximized(dsurface, true);
1205 weston_desktop_surface_set_size(dsurface,
1206 output->output->width,
1207 output->output->height);
1211 shell_set_panel(struct wl_client *client,
1212 struct wl_resource *shell_res,
1213 struct wl_resource *surface_res,
1214 struct wl_resource *output_res,
1217 struct weston_head *head = weston_head_from_resource(output_res);
1218 struct weston_output *woutput = weston_head_get_output(head);
1219 struct ivi_output *output = to_ivi_output(woutput);
1220 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
1221 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1222 struct weston_desktop_surface *dsurface;
1223 struct ivi_surface *surface;
1224 struct ivi_surface **member;
1225 int32_t width = 0, height = 0;
1227 if ((wl_resource_get_version(shell_res) >=
1228 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1229 ivi->shell_client.status == BOUND_FAILED) ||
1230 ivi->shell_client.resource_ext == shell_res) {
1231 wl_resource_post_error(shell_res,
1232 WL_DISPLAY_ERROR_INVALID_OBJECT,
1233 "agl_shell has already been bound. "
1234 "Check out bound_fail event");
1238 dsurface = weston_surface_get_desktop_surface(wsurface);
1240 wl_resource_post_error(shell_res,
1241 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1242 "surface must be a desktop surface");
1246 surface = weston_desktop_surface_get_user_data(dsurface);
1247 if (surface->role != IVI_SURFACE_ROLE_NONE) {
1248 wl_resource_post_error(shell_res,
1249 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1250 "surface already has another ivi role");
1255 case AGL_SHELL_EDGE_TOP:
1256 member = &output->top;
1258 case AGL_SHELL_EDGE_BOTTOM:
1259 member = &output->bottom;
1261 case AGL_SHELL_EDGE_LEFT:
1262 member = &output->left;
1264 case AGL_SHELL_EDGE_RIGHT:
1265 member = &output->right;
1268 wl_resource_post_error(shell_res,
1269 AGL_SHELL_ERROR_INVALID_ARGUMENT,
1270 "invalid edge for panel");
1275 wl_resource_post_error(shell_res,
1276 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
1277 "output already has panel on this edge");
1281 surface->checked_pending = true;
1282 surface->role = IVI_SURFACE_ROLE_PANEL;
1283 surface->panel.output = output;
1284 surface->panel.edge = edge;
1285 wl_list_remove(&surface->link);
1286 wl_list_init(&surface->link);
1290 switch (surface->panel.edge) {
1291 case AGL_SHELL_EDGE_TOP:
1292 case AGL_SHELL_EDGE_BOTTOM:
1293 width = woutput->width;
1295 case AGL_SHELL_EDGE_LEFT:
1296 case AGL_SHELL_EDGE_RIGHT:
1297 height = woutput->height;
1301 weston_desktop_surface_set_size(dsurface, width, height);
1305 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
1306 const char *data, uint32_t app_state)
1308 struct desktop_client *dclient;
1310 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1311 struct ivi_policy *policy = ivi->policy;
1313 /* FIXME: should queue it here and see when binding agl-shell-desktop
1314 * if there are any to be sent */
1321 if (policy && policy->api.surface_advertise_state_change &&
1322 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
1326 app_role = surf->role;
1327 if (app_role == IVI_SURFACE_ROLE_POPUP)
1328 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
1330 wl_list_for_each(dclient, &ivi->desktop_clients, link)
1331 agl_shell_desktop_send_state_app(dclient->resource, app_id,
1332 data, app_state, app_role);
1336 shell_activate_app(struct wl_client *client,
1337 struct wl_resource *shell_res,
1339 struct wl_resource *output_res)
1341 struct weston_head *head;
1342 struct weston_output *woutput;
1343 struct ivi_compositor *ivi;
1344 struct ivi_output *output;
1346 head = weston_head_from_resource(output_res);
1348 weston_log("Invalid output to activate '%s' on\n", app_id);
1352 woutput = weston_head_get_output(head);
1353 ivi = wl_resource_get_user_data(shell_res);
1354 output = to_ivi_output(woutput);
1356 if (wl_resource_get_version(shell_res) >=
1357 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1358 ivi->shell_client.status == BOUND_FAILED) {
1359 wl_resource_post_error(shell_res,
1360 WL_DISPLAY_ERROR_INVALID_OBJECT,
1361 "agl_shell has already been bound. "
1362 "Check out bound_fail event");
1366 ivi_layout_activate(output, app_id);
1370 shell_new_deactivate_app(struct wl_client *client, struct wl_resource *shell_res,
1373 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1375 ivi_layout_deactivate(ivi, app_id);
1379 shell_set_app_float(struct wl_client *client, struct wl_resource *shell_res,
1380 const char *app_id, int32_t x_pos, int32_t y_pos)
1382 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1383 struct weston_output *output = get_focused_output(ivi->compositor);
1384 struct ivi_output *ivi_output;
1385 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1388 output = get_default_output(ivi->compositor);
1390 ivi_output = to_ivi_output(output);
1392 /* verify if already mapped as desktop role, regular, unmap it, so we
1393 * can make it float */
1394 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1395 struct weston_view *ev = surf->view;
1396 struct weston_desktop_surface *dsurf = surf->dsurface;
1397 struct ivi_bounding_box bb = {};
1398 const char *prev_activate_app_id = NULL;
1400 /* XXX: if this is useful we could bring it as active then make
1401 * it float, but avoid doing it for the moment */
1402 if (surf != ivi_output->active)
1405 if (ivi_output->previous_active)
1406 prev_activate_app_id =
1407 weston_desktop_surface_get_app_id(ivi_output->previous_active->dsurface);
1409 /* only deactivate if previous_active is different, otherwise
1410 * this will blow up, because we're trying to activate the same
1411 * app_id as the this one! */
1412 if (prev_activate_app_id && strcmp(app_id, prev_activate_app_id)) {
1413 ivi_layout_deactivate(ivi, app_id);
1414 } else if (prev_activate_app_id) {
1415 weston_layer_entry_remove(&ev->layer_link);
1416 weston_view_geometry_dirty(ev);
1417 weston_surface_damage(ev->surface);
1420 surf->hidden_layer_output = ivi_output;
1422 /* set attributes */
1423 surf->popup.output = ivi_output;
1425 surf->popup.x = x_pos;
1426 surf->popup.y = y_pos;
1427 surf->popup.bb = bb;
1430 /* change the role */
1431 surf->role = IVI_SURFACE_ROLE_NONE;
1433 wl_list_remove(&surf->link);
1434 wl_list_init(&surf->link);
1436 ivi_set_desktop_surface_popup(surf);
1438 weston_desktop_surface_set_maximized(dsurf, false);
1439 weston_desktop_surface_set_size(dsurf, 0, 0);
1441 /* add to hidden layer */
1442 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1443 weston_compositor_schedule_repaint(ivi->compositor);
1445 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_POPUP)) {
1446 ivi_set_pending_desktop_surface_popup(ivi_output, x_pos, y_pos,
1447 0, 0, 0, 0, app_id);
1452 shell_set_app_fullscreen(struct wl_client *client,
1453 struct wl_resource *shell_res, const char *app_id)
1455 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1456 struct weston_output *output = get_focused_output(ivi->compositor);
1457 struct ivi_output *ivi_output;
1458 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1461 output = get_default_output(ivi->compositor);
1463 ivi_output = to_ivi_output(output);
1465 if (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1466 struct weston_view *ev = surf->view;
1467 struct weston_desktop_surface *dsurf = surf->dsurface;
1469 if (surf != ivi_output->active)
1472 weston_layer_entry_remove(&surf->view->layer_link);
1473 weston_view_geometry_dirty(surf->view);
1474 weston_surface_damage(surf->view->surface);
1476 surf->hidden_layer_output = ivi_output;
1478 /* set attributes */
1479 surf->fullscreen.output = ivi_output;
1481 /* change the role */
1482 surf->role = IVI_SURFACE_ROLE_NONE;
1484 wl_list_remove(&surf->link);
1485 wl_list_init(&surf->link);
1487 ivi_set_desktop_surface_fullscreen(surf);
1489 weston_desktop_surface_set_maximized(dsurf, false);
1490 weston_desktop_surface_set_fullscreen(dsurf, true);
1491 weston_desktop_surface_set_size(dsurf,
1492 ivi_output->output->width,
1493 ivi_output->output->height);
1495 /* add to hidden layer */
1496 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
1497 weston_compositor_schedule_repaint(ivi->compositor);
1498 } else if (!surf || (surf && surf->role != IVI_SURFACE_ROLE_FULLSCREEN)) {
1499 ivi_set_pending_desktop_surface_fullscreen(ivi_output, app_id);
1505 shell_set_app_normal(struct wl_client *client, struct wl_resource *shell_res,
1508 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
1509 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1510 struct weston_output *output = get_focused_output(ivi->compositor);
1511 struct ivi_output *ivi_output;
1512 struct weston_desktop_surface *dsurf;
1513 struct weston_geometry area = {};
1516 if (!surf || (surf && surf->role == IVI_SURFACE_ROLE_DESKTOP))
1520 output = get_default_output(ivi->compositor);
1522 dsurf = surf->dsurface;
1523 ivi_output = to_ivi_output(output);
1525 weston_layer_entry_remove(&surf->view->layer_link);
1526 weston_view_geometry_dirty(surf->view);
1527 weston_surface_damage(surf->view->surface);
1529 /* change the role */
1530 surf->role = IVI_SURFACE_ROLE_NONE;
1531 surf->state = NORMAL;
1532 surf->desktop.pending_output = ivi_output;
1534 wl_list_remove(&surf->link);
1535 wl_list_init(&surf->link);
1537 ivi_set_desktop_surface(surf);
1539 if (ivi_output->area_activation.width ||
1540 ivi_output->area_activation.height)
1541 area = ivi_output->area_activation;
1543 area = ivi_output->area;
1545 if (weston_desktop_surface_get_fullscreen(dsurf))
1546 weston_desktop_surface_set_fullscreen(dsurf, false);
1548 weston_desktop_surface_set_maximized(dsurf, true);
1549 weston_desktop_surface_set_size(dsurf, area.width, area.height);
1551 /* add to hidden layer */
1552 weston_layer_entry_insert(&ivi->hidden.view_list,
1553 &surf->view->layer_link);
1554 weston_compositor_schedule_repaint(ivi->compositor);
1559 shell_desktop_activate_app(struct wl_client *client,
1560 struct wl_resource *shell_res,
1561 const char *app_id, const char *data,
1562 struct wl_resource *output_res)
1564 struct weston_head *head = weston_head_from_resource(output_res);
1565 struct weston_output *woutput = weston_head_get_output(head);
1566 struct ivi_output *output = to_ivi_output(woutput);
1568 ivi_layout_activate(output, app_id);
1569 shell_advertise_app_state(output->ivi, app_id,
1570 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1574 shell_deactivate_app(struct wl_client *client,
1575 struct wl_resource *shell_res,
1578 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1579 struct ivi_compositor *ivi = dclient->ivi;
1581 ivi_layout_deactivate(ivi, app_id);
1582 shell_advertise_app_state(ivi, app_id,
1583 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1587 shell_destroy(struct wl_client *client, struct wl_resource *res)
1589 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1591 /* reset status in case bind_fail was sent */
1592 if (wl_resource_get_version(res) >= AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1593 ivi->shell_client.status == BOUND_FAILED)
1594 ivi->shell_client.status = BOUND_OK;
1598 shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
1599 struct wl_resource *output, int x, int y,
1600 int width, int height)
1602 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1603 struct weston_head *head = weston_head_from_resource(output);
1604 struct weston_output *woutput = weston_head_get_output(head);
1605 struct ivi_output *ioutput = to_ivi_output(woutput);
1607 struct weston_geometry area = { .x = x, .y = y,
1610 if (ivi->shell_client.ready)
1613 ioutput->area_activation = area;
1617 shell_set_app_output(struct wl_client *client, struct wl_resource *res,
1618 const char *app_id, struct wl_resource *output)
1620 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1621 struct weston_head *head = weston_head_from_resource(output);
1622 struct weston_output *woutput = weston_head_get_output(head);
1623 struct ivi_output *ioutput = to_ivi_output(woutput);
1624 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1625 struct ivi_output *desktop_last_output = surf->desktop.last_output;
1626 struct ivi_output *current_completed_output =
1627 surf->current_completed_output;
1629 if (!app_id || !ioutput)
1632 /* handle the case we're not mapped at all */
1634 ivi_set_pending_desktop_surface_remote(ioutput, app_id);
1635 shell_send_app_on_output(ivi, app_id, woutput->name);
1639 if (surf->remote.output)
1640 surf->hidden_layer_output = surf->remote.output;
1642 surf->hidden_layer_output = desktop_last_output;
1643 assert(surf->hidden_layer_output);
1645 if (ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_REMOTE) ||
1646 ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_DESKTOP)) {
1647 if (!current_completed_output->background)
1648 insert_black_curtain(current_completed_output);
1650 ivi_layout_deactivate(ivi, app_id);
1653 /* update the remote output */
1654 surf->remote.output = ioutput;
1656 if (surf->role != IVI_SURFACE_ROLE_REMOTE) {
1657 wl_list_remove(&surf->link);
1658 wl_list_init(&surf->link);
1660 surf->role = IVI_SURFACE_ROLE_NONE;
1661 ivi_set_desktop_surface_remote(surf);
1664 shell_send_app_on_output(ivi, app_id, woutput->name);
1668 shell_set_app_position(struct wl_client *client, struct wl_resource *res,
1669 const char *app_id, int32_t x, int32_t y)
1671 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1672 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1674 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1677 weston_view_set_position(surf->view, x, y);
1678 weston_compositor_schedule_repaint(ivi->compositor);
1682 shell_set_app_scale(struct wl_client *client, struct wl_resource *res,
1683 const char *app_id, int32_t width, int32_t height)
1686 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1687 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
1689 if (!surf || !app_id || surf->role != IVI_SURFACE_ROLE_POPUP)
1692 weston_desktop_surface_set_size(surf->dsurface, width, height);
1693 weston_compositor_schedule_repaint(ivi->compositor);
1697 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
1699 wl_resource_destroy(res);
1703 shell_ext_doas(struct wl_client *client, struct wl_resource *res)
1705 struct ivi_compositor *ivi = wl_resource_get_user_data(res);
1707 ivi->shell_client_ext.doas_requested = true;
1708 agl_shell_ext_send_doas_done(ivi->shell_client_ext.resource,
1709 AGL_SHELL_EXT_DOAS_SHELL_CLIENT_STATUS_SUCCESS);
1712 static const struct agl_shell_interface agl_shell_implementation = {
1713 .ready = shell_ready,
1714 .set_background = shell_set_background,
1715 .set_panel = shell_set_panel,
1716 .activate_app = shell_activate_app,
1717 .destroy = shell_destroy,
1718 .set_activate_region = shell_set_activate_region,
1719 .deactivate_app = shell_new_deactivate_app,
1720 .set_app_float = shell_set_app_float,
1721 .set_app_normal = shell_set_app_normal,
1722 .set_app_fullscreen = shell_set_app_fullscreen,
1723 .set_app_output = shell_set_app_output,
1724 .set_app_position = shell_set_app_position,
1725 .set_app_scale = shell_set_app_scale,
1728 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
1729 .destroy = shell_ext_destroy,
1730 .doas_shell_client = shell_ext_doas,
1734 shell_desktop_set_app_property(struct wl_client *client,
1735 struct wl_resource *shell_res,
1736 const char *app_id, uint32_t role,
1737 int x, int y, int bx, int by,
1738 int width, int height,
1739 struct wl_resource *output_res)
1741 struct weston_head *head = weston_head_from_resource(output_res);
1742 struct weston_output *woutput = weston_head_get_output(head);
1743 struct ivi_output *output = to_ivi_output(woutput);
1746 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1747 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1748 width, height, app_id);
1750 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1751 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1753 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1754 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1755 ivi_set_pending_desktop_surface_split(output, app_id, role);
1757 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1758 ivi_set_pending_desktop_surface_remote(output, app_id);
1766 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1768 struct pending_popup *p_popup, *next_p_popup;
1769 struct pending_split *split_surf, *next_split_surf;
1770 struct pending_fullscreen *fs_surf, *next_fs_surf;
1771 struct pending_remote *remote_surf, *next_remote_surf;
1773 wl_list_for_each_safe(p_popup, next_p_popup,
1774 &ivi->popup_pending_apps, link)
1775 ivi_remove_pending_desktop_surface_popup(p_popup);
1777 wl_list_for_each_safe(split_surf, next_split_surf,
1778 &ivi->split_pending_apps, link)
1779 ivi_remove_pending_desktop_surface_split(split_surf);
1781 wl_list_for_each_safe(fs_surf, next_fs_surf,
1782 &ivi->fullscreen_pending_apps, link)
1783 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1785 wl_list_for_each_safe(remote_surf, next_remote_surf,
1786 &ivi->remote_pending_apps, link)
1787 ivi_remove_pending_desktop_surface_remote(remote_surf);
1791 shell_desktop_set_app_property_mode(struct wl_client *client,
1792 struct wl_resource *shell_res, uint32_t perm)
1794 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1796 dclient->ivi->keep_pending_surfaces = true;
1798 dclient->ivi->keep_pending_surfaces = false;
1799 /* remove any previous pending surfaces */
1800 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1804 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1805 .activate_app = shell_desktop_activate_app,
1806 .set_app_property = shell_desktop_set_app_property,
1807 .deactivate_app = shell_deactivate_app,
1808 .set_app_property_mode = shell_desktop_set_app_property_mode,
1812 unbind_agl_shell(struct wl_resource *resource)
1814 struct ivi_compositor *ivi;
1815 struct ivi_output *output;
1816 struct ivi_surface *surf, *surf_tmp;
1818 ivi = wl_resource_get_user_data(resource);
1820 /* reset status to allow other clients issue legit requests */
1821 if (wl_resource_get_version(resource) >=
1822 AGL_SHELL_BOUND_OK_SINCE_VERSION &&
1823 ivi->shell_client.status == BOUND_FAILED) {
1824 ivi->shell_client.status = BOUND_OK;
1828 wl_list_for_each(output, &ivi->outputs, link) {
1830 /* reset the active surf if there's one present */
1831 if (output->active) {
1832 struct weston_geometry area = {};
1834 output->active->view->is_mapped = false;
1835 output->active->view->surface->is_mapped = false;
1837 weston_layer_entry_remove(&output->active->view->layer_link);
1838 output->active = NULL;
1840 output->area_activation = area;
1843 insert_black_curtain(output);
1846 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1847 wl_list_remove(&surf->link);
1848 wl_list_init(&surf->link);
1851 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1852 wl_list_remove(&surf->link);
1853 wl_list_init(&surf->link);
1856 wl_list_init(&ivi->surfaces);
1857 wl_list_init(&ivi->pending_surfaces);
1859 ivi->shell_client.ready = false;
1860 ivi->shell_client.resource = NULL;
1861 ivi->shell_client.client = NULL;
1865 unbind_agl_shell_ext(struct wl_resource *resource)
1867 struct ivi_compositor *ivi = wl_resource_get_user_data(resource);
1869 ivi->shell_client_ext.resource = NULL;
1873 bind_agl_shell(struct wl_client *client,
1874 void *data, uint32_t version, uint32_t id)
1876 struct ivi_compositor *ivi = data;
1877 struct wl_resource *resource;
1878 struct ivi_policy *policy;
1881 policy = ivi->policy;
1882 interface = (void *) &agl_shell_interface;
1883 if (policy && policy->api.shell_bind_interface &&
1884 !policy->api.shell_bind_interface(client, interface)) {
1885 wl_client_post_implementation_error(client,
1886 "client not authorized to use agl_shell");
1890 resource = wl_resource_create(client, &agl_shell_interface, version, id);
1892 wl_client_post_no_memory(client);
1896 if (ivi->shell_client.resource) {
1897 if (wl_resource_get_version(resource) == 1) {
1898 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1899 "agl_shell has already been bound");
1903 if (ivi->shell_client_ext.resource &&
1904 ivi->shell_client_ext.doas_requested) {
1906 /* reset status in case client-ext doesn't send an
1907 * explicit agl_shell_destroy request, see
1908 * shell_destroy() */
1909 if (ivi->shell_client.status == BOUND_FAILED)
1910 ivi->shell_client.status = BOUND_OK;
1912 wl_resource_set_implementation(resource, &agl_shell_implementation,
1914 ivi->shell_client.resource_ext = resource;
1916 ivi->shell_client_ext.status = BOUND_OK;
1917 agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
1921 wl_resource_set_implementation(resource, &agl_shell_implementation,
1923 agl_shell_send_bound_fail(resource);
1924 ivi->shell_client.status = BOUND_FAILED;
1930 if (wl_resource_get_version(resource) >=
1931 AGL_SHELL_BOUND_OK_SINCE_VERSION) {
1932 wl_resource_set_implementation(resource, &agl_shell_implementation,
1933 ivi, unbind_agl_shell);
1934 ivi->shell_client.resource = resource;
1935 /* if we land here we'll have BOUND_OK by default,
1936 but still do the assignment */
1937 ivi->shell_client.status = BOUND_OK;
1938 agl_shell_send_bound_ok(ivi->shell_client.resource);
1940 /* fallback for just version 1 of the protocol */
1941 wl_resource_set_implementation(resource, &agl_shell_implementation,
1942 ivi, unbind_agl_shell);
1943 ivi->shell_client.resource = resource;
1948 bind_agl_shell_ext(struct wl_client *client,
1949 void *data, uint32_t version, uint32_t id)
1951 struct ivi_compositor *ivi = data;
1952 struct wl_resource *resource;
1954 resource = wl_resource_create(client, &agl_shell_ext_interface, version, id);
1956 wl_client_post_no_memory(client);
1960 if (ivi->shell_client_ext.resource) {
1961 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1962 "agl_shell_ext has already been bound");
1966 wl_resource_set_implementation(resource, &agl_shell_ext_implementation,
1967 ivi, unbind_agl_shell_ext);
1968 ivi->shell_client_ext.resource = resource;
1972 unbind_agl_shell_desktop(struct wl_resource *resource)
1974 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1976 wl_list_remove(&dclient->link);
1981 bind_agl_shell_desktop(struct wl_client *client,
1982 void *data, uint32_t version, uint32_t id)
1984 struct ivi_compositor *ivi = data;
1985 struct wl_resource *resource;
1986 struct ivi_policy *policy;
1987 struct desktop_client *dclient;
1990 policy = ivi->policy;
1991 interface = (void *) &agl_shell_desktop_interface;
1992 if (policy && policy->api.shell_bind_interface &&
1993 !policy->api.shell_bind_interface(client, interface)) {
1994 wl_client_post_implementation_error(client,
1995 "client not authorized to use agl_shell_desktop");
1999 dclient = zalloc(sizeof(*dclient));
2001 wl_client_post_no_memory(client);
2005 resource = wl_resource_create(client, &agl_shell_desktop_interface,
2009 wl_client_post_no_memory(client);
2013 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
2014 dclient, unbind_agl_shell_desktop);
2016 dclient->resource = resource;
2017 wl_list_insert(&ivi->desktop_clients, &dclient->link);
2019 /* advertise xdg surfaces */
2020 ivi_shell_advertise_xdg_surfaces(ivi, resource);
2024 ivi_shell_create_global(struct ivi_compositor *ivi)
2026 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
2027 &agl_shell_interface, 10,
2028 ivi, bind_agl_shell);
2029 if (!ivi->agl_shell) {
2030 weston_log("Failed to create wayland global.\n");
2034 ivi->agl_shell_ext = wl_global_create(ivi->compositor->wl_display,
2035 &agl_shell_ext_interface, 1,
2036 ivi, bind_agl_shell_ext);
2037 if (!ivi->agl_shell_ext) {
2038 weston_log("Failed to create agl_shell_ext global.\n");
2042 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
2043 &agl_shell_desktop_interface, 2,
2044 ivi, bind_agl_shell_desktop);
2045 if (!ivi->agl_shell_desktop) {
2046 weston_log("Failed to create wayland global (agl_shell_desktop).\n");