2 * Copyright © 2019 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
34 #include <sys/socket.h>
35 #include <sys/types.h>
37 #include <libweston/libweston.h>
38 #include <libweston/config-parser.h>
40 #include "shared/os-compatibility.h"
42 #include "agl-shell-server-protocol.h"
43 #include "agl-shell-desktop-server-protocol.h"
46 create_black_surface_view(struct ivi_output *output);
49 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
50 struct ivi_surface *surface)
52 struct desktop_client *dclient;
54 /* advertise to all desktop clients the new surface */
55 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
57 weston_desktop_surface_get_app_id(surface->dsurface);
58 agl_shell_desktop_send_application(dclient->resource, app_id);
63 ivi_set_desktop_surface(struct ivi_surface *surface)
65 struct ivi_compositor *ivi = surface->ivi;
66 assert(surface->role == IVI_SURFACE_ROLE_NONE);
68 surface->role = IVI_SURFACE_ROLE_DESKTOP;
69 wl_list_insert(&surface->ivi->surfaces, &surface->link);
71 agl_shell_desktop_advertise_application_id(ivi, surface);
75 ivi_set_desktop_surface_popup(struct ivi_surface *surface)
77 struct ivi_compositor *ivi = surface->ivi;
78 assert(surface->role == IVI_SURFACE_ROLE_NONE);
80 surface->role = IVI_SURFACE_ROLE_POPUP;
81 wl_list_insert(&ivi->surfaces, &surface->link);
83 agl_shell_desktop_advertise_application_id(ivi, surface);
87 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
89 struct ivi_compositor *ivi = surface->ivi;
90 assert(surface->role == IVI_SURFACE_ROLE_NONE);
92 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
93 wl_list_insert(&ivi->surfaces, &surface->link);
95 agl_shell_desktop_advertise_application_id(ivi, surface);
99 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
101 struct ivi_compositor *ivi = surface->ivi;
102 struct weston_view *view;
103 struct ivi_output *output = surface->remote.output;
105 assert(surface->role == IVI_SURFACE_ROLE_NONE);
107 /* remote type are the same as desktop just that client can tell
108 * the compositor to start on another output */
109 surface->role = IVI_SURFACE_ROLE_REMOTE;
111 /* if thew black surface view is mapped on the mean we need
112 * to remove it in order to start showing the 'remote' surface
113 * just being added */
114 view = output->fullscreen_view.fs->view;
115 if (view->is_mapped || view->surface->is_mapped)
116 remove_black_surface(output);
118 wl_list_insert(&ivi->surfaces, &surface->link);
123 ivi_set_desktop_surface_split(struct ivi_surface *surface)
125 struct ivi_compositor *ivi = surface->ivi;
126 assert(surface->role == IVI_SURFACE_ROLE_NONE);
128 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
129 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
131 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
133 wl_list_insert(&ivi->surfaces, &surface->link);
135 agl_shell_desktop_advertise_application_id(ivi, surface);
139 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
140 int x, int y, const char *app_id)
142 struct ivi_compositor *ivi = ioutput->ivi;
143 size_t len_app_id = strlen(app_id);
145 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
147 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
148 memcpy(p_popup->app_id, app_id, len_app_id);
149 p_popup->ioutput = ioutput;
153 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
157 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
160 struct ivi_compositor *ivi = ioutput->ivi;
161 size_t len_app_id = strlen(app_id);
163 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
165 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
166 memcpy(fs->app_id, app_id, len_app_id);
168 fs->ioutput = ioutput;
170 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
174 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
175 const char *app_id, uint32_t orientation)
177 struct ivi_compositor *ivi = ioutput->ivi;
178 struct ivi_surface *surf;
179 size_t len_app_id = strlen(app_id);
180 struct pending_split *split;
182 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
183 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
186 /* more than one is un-supported, do note we need to do
187 * conversion for surface roles instead of using the protocol ones */
188 wl_list_for_each(surf, &ivi->surfaces, link)
189 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
190 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
193 split = zalloc(sizeof(*split));
194 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
195 memcpy(split->app_id, app_id, len_app_id);
197 split->ioutput = ioutput;
198 split->orientation = orientation;
200 wl_list_insert(&ivi->split_pending_apps, &split->link);
204 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
207 struct ivi_compositor *ivi = ioutput->ivi;
208 size_t len_app_id = strlen(app_id);
210 struct pending_remote *remote = zalloc(sizeof(*remote));
212 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
213 memcpy(remote->app_id, app_id, len_app_id);
215 remote->ioutput = ioutput;
217 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
222 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
225 wl_list_remove(&split->link);
230 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
233 wl_list_remove(&fs->link);
238 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
240 free(p_popup->app_id);
241 wl_list_remove(&p_popup->link);
246 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
248 free(remote->app_id);
249 wl_list_remove(&remote->link);
254 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
256 struct ivi_compositor *ivi = surface->ivi;
257 struct pending_popup *p_popup, *next_p_popup;
258 const char *_app_id =
259 weston_desktop_surface_get_app_id(surface->dsurface);
261 if (wl_list_empty(&ivi->popup_pending_apps))
264 wl_list_for_each_safe(p_popup, next_p_popup,
265 &ivi->popup_pending_apps, link) {
266 if (!strcmp(_app_id, p_popup->app_id)) {
267 surface->popup.output = p_popup->ioutput;
268 surface->popup.x = p_popup->x;
269 surface->popup.y = p_popup->y;
270 ivi_remove_pending_desktop_surface_popup(p_popup);
279 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
281 struct pending_split *split_surf, *next_split_surf;
282 struct ivi_compositor *ivi = surface->ivi;
283 const char *_app_id =
284 weston_desktop_surface_get_app_id(surface->dsurface);
286 if (wl_list_empty(&ivi->split_pending_apps))
289 wl_list_for_each_safe(split_surf, next_split_surf,
290 &ivi->split_pending_apps, link) {
291 if (!strcmp(_app_id, split_surf->app_id)) {
292 surface->split.output = split_surf->ioutput;
293 surface->split.orientation = split_surf->orientation;
294 ivi_remove_pending_desktop_surface_split(split_surf);
303 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
305 struct pending_fullscreen *fs_surf, *next_fs_surf;
306 struct ivi_compositor *ivi = surface->ivi;
307 const char *_app_id =
308 weston_desktop_surface_get_app_id(surface->dsurface);
310 if (wl_list_empty(&ivi->fullscreen_pending_apps))
313 wl_list_for_each_safe(fs_surf, next_fs_surf,
314 &ivi->fullscreen_pending_apps, link) {
315 if (!strcmp(_app_id, fs_surf->app_id)) {
316 surface->fullscreen.output = fs_surf->ioutput;
317 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
326 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
328 struct pending_remote *remote_surf, *next_remote_surf;
329 struct ivi_compositor *ivi = surface->ivi;
330 const char *_app_id =
331 weston_desktop_surface_get_app_id(surface->dsurface);
333 if (wl_list_empty(&ivi->remote_pending_apps))
336 wl_list_for_each_safe(remote_surf, next_remote_surf,
337 &ivi->remote_pending_apps, link) {
338 if (!strcmp(_app_id, remote_surf->app_id)) {
339 surface->remote.output = remote_surf->ioutput;
340 ivi_remove_pending_desktop_surface_remote(remote_surf);
350 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
354 ret = ivi_check_pending_desktop_surface_popup(surface);
356 ivi_set_desktop_surface_popup(surface);
360 ret = ivi_check_pending_desktop_surface_split(surface);
362 ivi_set_desktop_surface_split(surface);
366 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
368 ivi_set_desktop_surface_fullscreen(surface);
372 ret = ivi_check_pending_desktop_surface_remote(surface);
374 ivi_set_desktop_surface_remote(surface);
378 /* if we end up here means we have a regular desktop app and
379 * try to activate it */
380 ivi_set_desktop_surface(surface);
381 ivi_layout_desktop_committed(surface);
385 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
387 struct ivi_output *out;
389 wl_list_for_each(out, &ivi->outputs, link) {
390 create_black_surface_view(out);
391 insert_black_surface(out);
396 ivi_shell_init(struct ivi_compositor *ivi)
398 weston_layer_init(&ivi->hidden, ivi->compositor);
399 weston_layer_init(&ivi->background, ivi->compositor);
400 weston_layer_init(&ivi->normal, ivi->compositor);
401 weston_layer_init(&ivi->panel, ivi->compositor);
402 weston_layer_init(&ivi->popup, ivi->compositor);
403 weston_layer_init(&ivi->fullscreen, ivi->compositor);
405 weston_layer_set_position(&ivi->hidden,
406 WESTON_LAYER_POSITION_HIDDEN);
407 weston_layer_set_position(&ivi->background,
408 WESTON_LAYER_POSITION_BACKGROUND);
409 weston_layer_set_position(&ivi->normal,
410 WESTON_LAYER_POSITION_NORMAL);
411 weston_layer_set_position(&ivi->panel,
412 WESTON_LAYER_POSITION_UI);
413 weston_layer_set_position(&ivi->popup,
414 WESTON_LAYER_POSITION_TOP_UI);
415 weston_layer_set_position(&ivi->fullscreen,
416 WESTON_LAYER_POSITION_FULLSCREEN);
422 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
424 struct ivi_surface *surface;
426 wl_list_for_each(surface, &ivi->surfaces, link) {
428 weston_desktop_surface_get_app_id(surface->dsurface);
429 agl_shell_desktop_send_application(resource, app_id);
434 client_exec(const char *command, int fd)
439 /* Don't give the child our signal mask */
441 sigprocmask(SIG_UNBLOCK, &sig, NULL);
443 /* Launch clients as the user; don't give them the wrong euid */
444 if (seteuid(getuid()) == -1) {
445 weston_log("seteuid failed: %s\n", strerror(errno));
449 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
450 * clobbering fd, as we'll exit/exec either way.
454 weston_log("dup failed: %s\n", strerror(errno));
458 snprintf(s, sizeof s, "%d", fd);
459 setenv("WAYLAND_SOCKET", s, 1);
461 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
462 weston_log("executing '%s' failed: %s", command, strerror(errno));
465 static struct wl_client *
466 launch_shell_client(struct ivi_compositor *ivi, const char *command)
468 struct wl_client *client;
472 weston_log("launching' %s'\n", command);
474 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
475 weston_log("socketpair failed while launching '%s': %s\n",
476 command, strerror(errno));
484 weston_log("fork failed while launching '%s': %s\n",
485 command, strerror(errno));
490 client_exec(command, sock[1]);
495 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
498 weston_log("Failed to create wayland client for '%s'",
507 ivi_launch_shell_client(struct ivi_compositor *ivi)
509 struct weston_config_section *section;
510 char *command = NULL;
512 section = weston_config_get_section(ivi->config, "shell-client",
515 weston_config_section_get_string(section, "command",
521 ivi->shell_client.client = launch_shell_client(ivi, command);
522 if (!ivi->shell_client.client)
529 destroy_black_view(struct wl_listener *listener, void *data)
531 struct fullscreen_view *fs =
532 wl_container_of(listener, fs, fs_destroy);
536 if (fs->fs->view && fs->fs->view->surface) {
537 weston_surface_destroy(fs->fs->view->surface);
542 wl_list_remove(&fs->fs_destroy.link);
548 create_black_surface_view(struct ivi_output *output)
550 struct weston_surface *surface = NULL;
551 struct weston_view *view;
552 struct ivi_compositor *ivi = output->ivi;
553 struct weston_compositor *wc= ivi->compositor;
554 struct weston_output *woutput = output->output;
556 surface = weston_surface_create(wc);
557 view = weston_view_create(surface);
559 assert(view || surface);
561 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
562 weston_surface_set_size(surface, woutput->width, woutput->height);
563 weston_view_set_position(view, woutput->x, woutput->y);
565 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
566 output->fullscreen_view.fs->view = view;
568 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
569 wl_signal_add(&woutput->destroy_signal,
570 &output->fullscreen_view.fs_destroy);
574 remove_black_surface(struct ivi_output *output)
576 struct weston_view *view;
579 !output->fullscreen_view.fs &&
580 !output->fullscreen_view.fs->view) {
581 weston_log("Output %s doesn't have a surface installed!\n", output->name);
585 view = output->fullscreen_view.fs->view;
586 assert(view->is_mapped == true ||
587 view->surface->is_mapped == true);
589 view->is_mapped = false;
590 view->surface->is_mapped = false;
592 weston_layer_entry_remove(&view->layer_link);
593 weston_view_update_transform(view);
595 weston_output_damage(output->output);
599 insert_black_surface(struct ivi_output *output)
601 struct weston_view *view;
604 !output->fullscreen_view.fs &&
605 !output->fullscreen_view.fs->view) {
606 weston_log("Output %s doesn't have a surface installed!\n", output->name);
610 view = output->fullscreen_view.fs->view;
611 if (view->is_mapped || view->surface->is_mapped)
614 weston_layer_entry_remove(&view->layer_link);
615 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
618 view->is_mapped = true;
619 view->surface->is_mapped = true;
621 weston_view_update_transform(view);
622 weston_output_damage(output->output);
626 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
628 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
629 struct ivi_output *output;
630 struct ivi_surface *surface, *tmp;
632 /* Init already finished. Do nothing */
633 if (ivi->shell_client.ready)
636 ivi->shell_client.ready = true;
638 wl_list_for_each(output, &ivi->outputs, link) {
639 if (output->background)
640 remove_black_surface(output);
641 ivi_layout_init(ivi, output);
644 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
645 wl_list_remove(&surface->link);
646 ivi_check_pending_desktop_surface(surface);
651 shell_set_background(struct wl_client *client,
652 struct wl_resource *shell_res,
653 struct wl_resource *surface_res,
654 struct wl_resource *output_res)
656 struct weston_head *head = weston_head_from_resource(output_res);
657 struct weston_output *woutput = weston_head_get_output(head);
658 struct ivi_output *output = to_ivi_output(woutput);
659 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
660 struct weston_desktop_surface *dsurface;
661 struct ivi_surface *surface;
663 dsurface = weston_surface_get_desktop_surface(wsurface);
665 wl_resource_post_error(shell_res,
666 AGL_SHELL_ERROR_INVALID_ARGUMENT,
667 "surface must be a desktop surface");
671 surface = weston_desktop_surface_get_user_data(dsurface);
672 if (surface->role != IVI_SURFACE_ROLE_NONE) {
673 wl_resource_post_error(shell_res,
674 AGL_SHELL_ERROR_INVALID_ARGUMENT,
675 "surface already has another ivi role");
679 if (output->background) {
680 wl_resource_post_error(shell_res,
681 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
682 "output already has background");
686 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
687 surface->bg.output = output;
688 wl_list_remove(&surface->link);
689 wl_list_init(&surface->link);
691 output->background = surface;
693 weston_desktop_surface_set_maximized(dsurface, true);
694 weston_desktop_surface_set_size(dsurface,
695 output->output->width,
696 output->output->height);
700 shell_set_panel(struct wl_client *client,
701 struct wl_resource *shell_res,
702 struct wl_resource *surface_res,
703 struct wl_resource *output_res,
706 struct weston_head *head = weston_head_from_resource(output_res);
707 struct weston_output *woutput = weston_head_get_output(head);
708 struct ivi_output *output = to_ivi_output(woutput);
709 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
710 struct weston_desktop_surface *dsurface;
711 struct ivi_surface *surface;
712 struct ivi_surface **member;
713 int32_t width = 0, height = 0;
715 dsurface = weston_surface_get_desktop_surface(wsurface);
717 wl_resource_post_error(shell_res,
718 AGL_SHELL_ERROR_INVALID_ARGUMENT,
719 "surface must be a desktop surface");
723 surface = weston_desktop_surface_get_user_data(dsurface);
724 if (surface->role != IVI_SURFACE_ROLE_NONE) {
725 wl_resource_post_error(shell_res,
726 AGL_SHELL_ERROR_INVALID_ARGUMENT,
727 "surface already has another ivi role");
732 case AGL_SHELL_EDGE_TOP:
733 member = &output->top;
735 case AGL_SHELL_EDGE_BOTTOM:
736 member = &output->bottom;
738 case AGL_SHELL_EDGE_LEFT:
739 member = &output->left;
741 case AGL_SHELL_EDGE_RIGHT:
742 member = &output->right;
745 wl_resource_post_error(shell_res,
746 AGL_SHELL_ERROR_INVALID_ARGUMENT,
747 "invalid edge for panel");
752 wl_resource_post_error(shell_res,
753 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
754 "output already has panel on this edge");
758 surface->role = IVI_SURFACE_ROLE_PANEL;
759 surface->panel.output = output;
760 surface->panel.edge = edge;
761 wl_list_remove(&surface->link);
762 wl_list_init(&surface->link);
766 switch (surface->panel.edge) {
767 case AGL_SHELL_EDGE_TOP:
768 case AGL_SHELL_EDGE_BOTTOM:
769 width = woutput->width;
771 case AGL_SHELL_EDGE_LEFT:
772 case AGL_SHELL_EDGE_RIGHT:
773 height = woutput->height;
777 weston_desktop_surface_set_size(dsurface, width, height);
782 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
783 const char *data, uint32_t app_state)
785 struct desktop_client *dclient;
787 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
788 struct ivi_policy *policy = ivi->policy;
790 /* FIXME: should queue it here and see when binding agl-shell-desktop
791 * if there are any to be sent */
795 if (policy && policy->api.surface_advertise_state_change &&
796 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
800 app_role = surf->role;
801 if (app_role == IVI_SURFACE_ROLE_POPUP)
802 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
804 wl_list_for_each(dclient, &ivi->desktop_clients, link)
805 agl_shell_desktop_send_state_app(dclient->resource, app_id,
806 data, app_state, app_role);
810 shell_activate_app(struct wl_client *client,
811 struct wl_resource *shell_res,
813 struct wl_resource *output_res)
815 struct weston_head *head = weston_head_from_resource(output_res);
816 struct weston_output *woutput = weston_head_get_output(head);
817 struct ivi_output *output = to_ivi_output(woutput);
819 ivi_layout_activate(output, app_id);
823 shell_desktop_activate_app(struct wl_client *client,
824 struct wl_resource *shell_res,
825 const char *app_id, const char *data,
826 struct wl_resource *output_res)
828 struct weston_head *head = weston_head_from_resource(output_res);
829 struct weston_output *woutput = weston_head_get_output(head);
830 struct ivi_output *output = to_ivi_output(woutput);
832 ivi_layout_activate(output, app_id);
833 shell_advertise_app_state(output->ivi, app_id,
834 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
838 shell_deactivate_app(struct wl_client *client,
839 struct wl_resource *shell_res,
842 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
843 struct ivi_compositor *ivi = dclient->ivi;
845 ivi_layout_deactivate(ivi, app_id);
846 shell_advertise_app_state(ivi, app_id,
847 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
850 static const struct agl_shell_interface agl_shell_implementation = {
851 .ready = shell_ready,
852 .set_background = shell_set_background,
853 .set_panel = shell_set_panel,
854 .activate_app = shell_activate_app,
858 shell_desktop_set_app_property(struct wl_client *client,
859 struct wl_resource *shell_res,
860 const char *app_id, uint32_t role,
861 int x, int y, struct wl_resource *output_res)
863 struct weston_head *head = weston_head_from_resource(output_res);
864 struct weston_output *woutput = weston_head_get_output(head);
865 struct ivi_output *output = to_ivi_output(woutput);
868 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
869 ivi_set_pending_desktop_surface_popup(output, x, y, app_id);
871 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
872 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
874 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
875 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
876 ivi_set_pending_desktop_surface_split(output, app_id, role);
878 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
879 ivi_set_pending_desktop_surface_remote(output, app_id);
886 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
887 .activate_app = shell_desktop_activate_app,
888 .set_app_property = shell_desktop_set_app_property,
889 .deactivate_app = shell_deactivate_app,
893 unbind_agl_shell(struct wl_resource *resource)
895 struct ivi_compositor *ivi;
896 struct ivi_output *output;
897 struct ivi_surface *surf, *surf_tmp;
899 ivi = wl_resource_get_user_data(resource);
900 wl_list_for_each(output, &ivi->outputs, link) {
901 /* reset the active surf if there's one present */
902 if (output->active) {
903 output->active->view->is_mapped = false;
904 output->active->view->surface->is_mapped = false;
906 weston_layer_entry_remove(&output->active->view->layer_link);
907 output->active = NULL;
910 insert_black_surface(output);
913 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
914 wl_list_remove(&surf->link);
915 wl_list_init(&surf->link);
918 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
919 wl_list_remove(&surf->link);
920 wl_list_init(&surf->link);
923 wl_list_init(&ivi->surfaces);
924 wl_list_init(&ivi->pending_surfaces);
926 ivi->shell_client.ready = false;
927 ivi->shell_client.resource = NULL;
928 ivi->shell_client.client = NULL;
932 bind_agl_shell(struct wl_client *client,
933 void *data, uint32_t version, uint32_t id)
935 struct ivi_compositor *ivi = data;
936 struct wl_resource *resource;
938 resource = wl_resource_create(client, &agl_shell_interface,
941 wl_client_post_no_memory(client);
946 if (ivi->shell_client.client != client) {
947 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
948 "client not authorized to use agl_shell");
953 if (ivi->shell_client.resource) {
954 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
955 "agl_shell has already been bound");
959 wl_resource_set_implementation(resource, &agl_shell_implementation,
960 ivi, unbind_agl_shell);
961 ivi->shell_client.resource = resource;
965 unbind_agl_shell_desktop(struct wl_resource *resource)
967 struct desktop_client *dclient = wl_resource_get_user_data(resource);
969 wl_list_remove(&dclient->link);
974 bind_agl_shell_desktop(struct wl_client *client,
975 void *data, uint32_t version, uint32_t id)
977 struct ivi_compositor *ivi = data;
978 struct wl_resource *resource;
979 struct desktop_client *dclient = zalloc(sizeof(*dclient));
982 wl_client_post_no_memory(client);
986 resource = wl_resource_create(client, &agl_shell_desktop_interface,
990 wl_client_post_no_memory(client);
994 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
995 dclient, unbind_agl_shell_desktop);
997 dclient->resource = resource;
998 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1000 /* advertise xdg surfaces */
1001 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1005 ivi_shell_create_global(struct ivi_compositor *ivi)
1007 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1008 &agl_shell_interface, 1,
1009 ivi, bind_agl_shell);
1010 if (!ivi->agl_shell) {
1011 weston_log("Failed to create wayland global.\n");
1015 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1016 &agl_shell_desktop_interface, 1,
1017 ivi, bind_agl_shell_desktop);
1018 if (!ivi->agl_shell_desktop) {
1019 weston_log("Failed to create wayland global (agl_shell_desktop).\n");