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, int bx, int by, int width, int height,
143 struct ivi_compositor *ivi = ioutput->ivi;
144 size_t len_app_id = strlen(app_id);
146 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
148 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
149 memcpy(p_popup->app_id, app_id, len_app_id);
150 p_popup->ioutput = ioutput;
156 p_popup->bb.width = width;
157 p_popup->bb.height = height;
159 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
163 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
166 struct ivi_compositor *ivi = ioutput->ivi;
167 size_t len_app_id = strlen(app_id);
169 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
171 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
172 memcpy(fs->app_id, app_id, len_app_id);
174 fs->ioutput = ioutput;
176 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
180 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
181 const char *app_id, uint32_t orientation)
183 struct ivi_compositor *ivi = ioutput->ivi;
184 struct ivi_surface *surf;
185 size_t len_app_id = strlen(app_id);
186 struct pending_split *split;
188 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
189 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
192 /* more than one is un-supported, do note we need to do
193 * conversion for surface roles instead of using the protocol ones */
194 wl_list_for_each(surf, &ivi->surfaces, link)
195 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
196 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
199 split = zalloc(sizeof(*split));
200 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
201 memcpy(split->app_id, app_id, len_app_id);
203 split->ioutput = ioutput;
204 split->orientation = orientation;
206 wl_list_insert(&ivi->split_pending_apps, &split->link);
210 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
213 struct ivi_compositor *ivi = ioutput->ivi;
214 size_t len_app_id = strlen(app_id);
216 struct pending_remote *remote = zalloc(sizeof(*remote));
218 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
219 memcpy(remote->app_id, app_id, len_app_id);
221 remote->ioutput = ioutput;
223 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
228 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
231 wl_list_remove(&split->link);
236 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
239 wl_list_remove(&fs->link);
244 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
246 free(p_popup->app_id);
247 wl_list_remove(&p_popup->link);
252 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
254 free(remote->app_id);
255 wl_list_remove(&remote->link);
260 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
262 struct ivi_compositor *ivi = surface->ivi;
263 struct pending_popup *p_popup, *next_p_popup;
264 const char *_app_id =
265 weston_desktop_surface_get_app_id(surface->dsurface);
267 if (wl_list_empty(&ivi->popup_pending_apps))
270 wl_list_for_each_safe(p_popup, next_p_popup,
271 &ivi->popup_pending_apps, link) {
272 if (!strcmp(_app_id, p_popup->app_id)) {
273 surface->popup.output = p_popup->ioutput;
274 surface->popup.x = p_popup->x;
275 surface->popup.y = p_popup->y;
277 surface->popup.bb.x = p_popup->bb.x;
278 surface->popup.bb.y = p_popup->bb.y;
279 surface->popup.bb.width = p_popup->bb.width;
280 surface->popup.bb.height = p_popup->bb.height;
282 ivi_remove_pending_desktop_surface_popup(p_popup);
291 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
293 struct pending_split *split_surf, *next_split_surf;
294 struct ivi_compositor *ivi = surface->ivi;
295 const char *_app_id =
296 weston_desktop_surface_get_app_id(surface->dsurface);
298 if (wl_list_empty(&ivi->split_pending_apps))
301 wl_list_for_each_safe(split_surf, next_split_surf,
302 &ivi->split_pending_apps, link) {
303 if (!strcmp(_app_id, split_surf->app_id)) {
304 surface->split.output = split_surf->ioutput;
305 surface->split.orientation = split_surf->orientation;
306 ivi_remove_pending_desktop_surface_split(split_surf);
315 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
317 struct pending_fullscreen *fs_surf, *next_fs_surf;
318 struct ivi_compositor *ivi = surface->ivi;
319 const char *_app_id =
320 weston_desktop_surface_get_app_id(surface->dsurface);
322 if (wl_list_empty(&ivi->fullscreen_pending_apps))
325 wl_list_for_each_safe(fs_surf, next_fs_surf,
326 &ivi->fullscreen_pending_apps, link) {
327 if (!strcmp(_app_id, fs_surf->app_id)) {
328 surface->fullscreen.output = fs_surf->ioutput;
329 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
338 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
340 struct pending_remote *remote_surf, *next_remote_surf;
341 struct ivi_compositor *ivi = surface->ivi;
342 const char *_app_id =
343 weston_desktop_surface_get_app_id(surface->dsurface);
345 if (wl_list_empty(&ivi->remote_pending_apps))
348 wl_list_for_each_safe(remote_surf, next_remote_surf,
349 &ivi->remote_pending_apps, link) {
350 if (!strcmp(_app_id, remote_surf->app_id)) {
351 surface->remote.output = remote_surf->ioutput;
352 ivi_remove_pending_desktop_surface_remote(remote_surf);
362 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
366 ret = ivi_check_pending_desktop_surface_popup(surface);
368 ivi_set_desktop_surface_popup(surface);
372 ret = ivi_check_pending_desktop_surface_split(surface);
374 ivi_set_desktop_surface_split(surface);
378 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
380 ivi_set_desktop_surface_fullscreen(surface);
384 ret = ivi_check_pending_desktop_surface_remote(surface);
386 ivi_set_desktop_surface_remote(surface);
390 /* if we end up here means we have a regular desktop app and
391 * try to activate it */
392 ivi_set_desktop_surface(surface);
393 ivi_layout_desktop_committed(surface);
397 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
399 struct ivi_output *out;
401 wl_list_for_each(out, &ivi->outputs, link) {
402 create_black_surface_view(out);
403 insert_black_surface(out);
408 ivi_shell_init(struct ivi_compositor *ivi)
410 weston_layer_init(&ivi->hidden, ivi->compositor);
411 weston_layer_init(&ivi->background, ivi->compositor);
412 weston_layer_init(&ivi->normal, ivi->compositor);
413 weston_layer_init(&ivi->panel, ivi->compositor);
414 weston_layer_init(&ivi->popup, ivi->compositor);
415 weston_layer_init(&ivi->fullscreen, ivi->compositor);
417 weston_layer_set_position(&ivi->hidden,
418 WESTON_LAYER_POSITION_HIDDEN);
419 weston_layer_set_position(&ivi->background,
420 WESTON_LAYER_POSITION_BACKGROUND);
421 weston_layer_set_position(&ivi->normal,
422 WESTON_LAYER_POSITION_NORMAL);
423 weston_layer_set_position(&ivi->panel,
424 WESTON_LAYER_POSITION_UI);
425 weston_layer_set_position(&ivi->popup,
426 WESTON_LAYER_POSITION_TOP_UI);
427 weston_layer_set_position(&ivi->fullscreen,
428 WESTON_LAYER_POSITION_FULLSCREEN);
434 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
436 struct ivi_surface *surface;
438 wl_list_for_each(surface, &ivi->surfaces, link) {
440 weston_desktop_surface_get_app_id(surface->dsurface);
441 agl_shell_desktop_send_application(resource, app_id);
446 client_exec(const char *command, int fd)
451 /* Don't give the child our signal mask */
453 sigprocmask(SIG_UNBLOCK, &sig, NULL);
455 /* Launch clients as the user; don't give them the wrong euid */
456 if (seteuid(getuid()) == -1) {
457 weston_log("seteuid failed: %s\n", strerror(errno));
461 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
462 * clobbering fd, as we'll exit/exec either way.
466 weston_log("dup failed: %s\n", strerror(errno));
470 snprintf(s, sizeof s, "%d", fd);
471 setenv("WAYLAND_SOCKET", s, 1);
473 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
474 weston_log("executing '%s' failed: %s", command, strerror(errno));
477 static struct wl_client *
478 launch_shell_client(struct ivi_compositor *ivi, const char *command)
480 struct wl_client *client;
484 weston_log("launching' %s'\n", command);
486 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
487 weston_log("socketpair failed while launching '%s': %s\n",
488 command, strerror(errno));
496 weston_log("fork failed while launching '%s': %s\n",
497 command, strerror(errno));
502 client_exec(command, sock[1]);
507 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
510 weston_log("Failed to create wayland client for '%s'",
519 ivi_launch_shell_client(struct ivi_compositor *ivi)
521 struct weston_config_section *section;
522 char *command = NULL;
524 section = weston_config_get_section(ivi->config, "shell-client",
527 weston_config_section_get_string(section, "command",
533 ivi->shell_client.client = launch_shell_client(ivi, command);
534 if (!ivi->shell_client.client)
541 destroy_black_view(struct wl_listener *listener, void *data)
543 struct fullscreen_view *fs =
544 wl_container_of(listener, fs, fs_destroy);
548 if (fs->fs->view && fs->fs->view->surface) {
549 weston_surface_destroy(fs->fs->view->surface);
554 wl_list_remove(&fs->fs_destroy.link);
560 create_black_surface_view(struct ivi_output *output)
562 struct weston_surface *surface = NULL;
563 struct weston_view *view;
564 struct ivi_compositor *ivi = output->ivi;
565 struct weston_compositor *wc= ivi->compositor;
566 struct weston_output *woutput = output->output;
568 surface = weston_surface_create(wc);
569 view = weston_view_create(surface);
571 assert(view || surface);
573 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
574 weston_surface_set_size(surface, woutput->width, woutput->height);
575 weston_view_set_position(view, woutput->x, woutput->y);
577 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
578 output->fullscreen_view.fs->view = view;
580 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
581 wl_signal_add(&woutput->destroy_signal,
582 &output->fullscreen_view.fs_destroy);
586 remove_black_surface(struct ivi_output *output)
588 struct weston_view *view;
591 !output->fullscreen_view.fs &&
592 !output->fullscreen_view.fs->view) {
593 weston_log("Output %s doesn't have a surface installed!\n", output->name);
597 view = output->fullscreen_view.fs->view;
598 assert(view->is_mapped == true ||
599 view->surface->is_mapped == true);
601 view->is_mapped = false;
602 view->surface->is_mapped = false;
604 weston_layer_entry_remove(&view->layer_link);
605 weston_view_update_transform(view);
607 weston_output_damage(output->output);
611 insert_black_surface(struct ivi_output *output)
613 struct weston_view *view;
616 !output->fullscreen_view.fs &&
617 !output->fullscreen_view.fs->view) {
618 weston_log("Output %s doesn't have a surface installed!\n", output->name);
622 view = output->fullscreen_view.fs->view;
623 if (view->is_mapped || view->surface->is_mapped)
626 weston_layer_entry_remove(&view->layer_link);
627 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
630 view->is_mapped = true;
631 view->surface->is_mapped = true;
633 weston_view_update_transform(view);
634 weston_output_damage(output->output);
638 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
640 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
641 struct ivi_output *output;
642 struct ivi_surface *surface, *tmp;
644 /* Init already finished. Do nothing */
645 if (ivi->shell_client.ready)
648 ivi->shell_client.ready = true;
650 wl_list_for_each(output, &ivi->outputs, link) {
651 if (output->background)
652 remove_black_surface(output);
653 ivi_layout_init(ivi, output);
656 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
657 wl_list_remove(&surface->link);
658 ivi_check_pending_desktop_surface(surface);
663 shell_set_background(struct wl_client *client,
664 struct wl_resource *shell_res,
665 struct wl_resource *surface_res,
666 struct wl_resource *output_res)
668 struct weston_head *head = weston_head_from_resource(output_res);
669 struct weston_output *woutput = weston_head_get_output(head);
670 struct ivi_output *output = to_ivi_output(woutput);
671 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
672 struct weston_desktop_surface *dsurface;
673 struct ivi_surface *surface;
675 dsurface = weston_surface_get_desktop_surface(wsurface);
677 wl_resource_post_error(shell_res,
678 AGL_SHELL_ERROR_INVALID_ARGUMENT,
679 "surface must be a desktop surface");
683 surface = weston_desktop_surface_get_user_data(dsurface);
684 if (surface->role != IVI_SURFACE_ROLE_NONE) {
685 wl_resource_post_error(shell_res,
686 AGL_SHELL_ERROR_INVALID_ARGUMENT,
687 "surface already has another ivi role");
691 if (output->background) {
692 wl_resource_post_error(shell_res,
693 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
694 "output already has background");
698 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
699 surface->bg.output = output;
700 wl_list_remove(&surface->link);
701 wl_list_init(&surface->link);
703 output->background = surface;
705 weston_desktop_surface_set_maximized(dsurface, true);
706 weston_desktop_surface_set_size(dsurface,
707 output->output->width,
708 output->output->height);
712 shell_set_panel(struct wl_client *client,
713 struct wl_resource *shell_res,
714 struct wl_resource *surface_res,
715 struct wl_resource *output_res,
718 struct weston_head *head = weston_head_from_resource(output_res);
719 struct weston_output *woutput = weston_head_get_output(head);
720 struct ivi_output *output = to_ivi_output(woutput);
721 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
722 struct weston_desktop_surface *dsurface;
723 struct ivi_surface *surface;
724 struct ivi_surface **member;
725 int32_t width = 0, height = 0;
727 dsurface = weston_surface_get_desktop_surface(wsurface);
729 wl_resource_post_error(shell_res,
730 AGL_SHELL_ERROR_INVALID_ARGUMENT,
731 "surface must be a desktop surface");
735 surface = weston_desktop_surface_get_user_data(dsurface);
736 if (surface->role != IVI_SURFACE_ROLE_NONE) {
737 wl_resource_post_error(shell_res,
738 AGL_SHELL_ERROR_INVALID_ARGUMENT,
739 "surface already has another ivi role");
744 case AGL_SHELL_EDGE_TOP:
745 member = &output->top;
747 case AGL_SHELL_EDGE_BOTTOM:
748 member = &output->bottom;
750 case AGL_SHELL_EDGE_LEFT:
751 member = &output->left;
753 case AGL_SHELL_EDGE_RIGHT:
754 member = &output->right;
757 wl_resource_post_error(shell_res,
758 AGL_SHELL_ERROR_INVALID_ARGUMENT,
759 "invalid edge for panel");
764 wl_resource_post_error(shell_res,
765 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
766 "output already has panel on this edge");
770 surface->role = IVI_SURFACE_ROLE_PANEL;
771 surface->panel.output = output;
772 surface->panel.edge = edge;
773 wl_list_remove(&surface->link);
774 wl_list_init(&surface->link);
778 switch (surface->panel.edge) {
779 case AGL_SHELL_EDGE_TOP:
780 case AGL_SHELL_EDGE_BOTTOM:
781 width = woutput->width;
783 case AGL_SHELL_EDGE_LEFT:
784 case AGL_SHELL_EDGE_RIGHT:
785 height = woutput->height;
789 weston_desktop_surface_set_size(dsurface, width, height);
794 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
795 const char *data, uint32_t app_state)
797 struct desktop_client *dclient;
799 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
800 struct ivi_policy *policy = ivi->policy;
802 /* FIXME: should queue it here and see when binding agl-shell-desktop
803 * if there are any to be sent */
807 if (policy && policy->api.surface_advertise_state_change &&
808 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
812 app_role = surf->role;
813 if (app_role == IVI_SURFACE_ROLE_POPUP)
814 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
816 wl_list_for_each(dclient, &ivi->desktop_clients, link)
817 agl_shell_desktop_send_state_app(dclient->resource, app_id,
818 data, app_state, app_role);
822 shell_activate_app(struct wl_client *client,
823 struct wl_resource *shell_res,
825 struct wl_resource *output_res)
827 struct weston_head *head = weston_head_from_resource(output_res);
828 struct weston_output *woutput = weston_head_get_output(head);
829 struct ivi_output *output = to_ivi_output(woutput);
831 ivi_layout_activate(output, app_id);
835 shell_desktop_activate_app(struct wl_client *client,
836 struct wl_resource *shell_res,
837 const char *app_id, const char *data,
838 struct wl_resource *output_res)
840 struct weston_head *head = weston_head_from_resource(output_res);
841 struct weston_output *woutput = weston_head_get_output(head);
842 struct ivi_output *output = to_ivi_output(woutput);
844 ivi_layout_activate(output, app_id);
845 shell_advertise_app_state(output->ivi, app_id,
846 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
850 shell_deactivate_app(struct wl_client *client,
851 struct wl_resource *shell_res,
854 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
855 struct ivi_compositor *ivi = dclient->ivi;
857 ivi_layout_deactivate(ivi, app_id);
858 shell_advertise_app_state(ivi, app_id,
859 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
862 static const struct agl_shell_interface agl_shell_implementation = {
863 .ready = shell_ready,
864 .set_background = shell_set_background,
865 .set_panel = shell_set_panel,
866 .activate_app = shell_activate_app,
870 shell_desktop_set_app_property(struct wl_client *client,
871 struct wl_resource *shell_res,
872 const char *app_id, uint32_t role,
873 int x, int y, int bx, int by,
874 int width, int height,
875 struct wl_resource *output_res)
877 struct weston_head *head = weston_head_from_resource(output_res);
878 struct weston_output *woutput = weston_head_get_output(head);
879 struct ivi_output *output = to_ivi_output(woutput);
882 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
883 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
884 width, height, app_id);
886 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
887 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
889 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
890 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
891 ivi_set_pending_desktop_surface_split(output, app_id, role);
893 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
894 ivi_set_pending_desktop_surface_remote(output, app_id);
901 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
902 .activate_app = shell_desktop_activate_app,
903 .set_app_property = shell_desktop_set_app_property,
904 .deactivate_app = shell_deactivate_app,
908 unbind_agl_shell(struct wl_resource *resource)
910 struct ivi_compositor *ivi;
911 struct ivi_output *output;
912 struct ivi_surface *surf, *surf_tmp;
914 ivi = wl_resource_get_user_data(resource);
915 wl_list_for_each(output, &ivi->outputs, link) {
916 /* reset the active surf if there's one present */
917 if (output->active) {
918 output->active->view->is_mapped = false;
919 output->active->view->surface->is_mapped = false;
921 weston_layer_entry_remove(&output->active->view->layer_link);
922 output->active = NULL;
925 insert_black_surface(output);
928 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
929 wl_list_remove(&surf->link);
930 wl_list_init(&surf->link);
933 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
934 wl_list_remove(&surf->link);
935 wl_list_init(&surf->link);
938 wl_list_init(&ivi->surfaces);
939 wl_list_init(&ivi->pending_surfaces);
941 ivi->shell_client.ready = false;
942 ivi->shell_client.resource = NULL;
943 ivi->shell_client.client = NULL;
947 bind_agl_shell(struct wl_client *client,
948 void *data, uint32_t version, uint32_t id)
950 struct ivi_compositor *ivi = data;
951 struct wl_resource *resource;
953 resource = wl_resource_create(client, &agl_shell_interface,
956 wl_client_post_no_memory(client);
961 if (ivi->shell_client.client != client) {
962 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
963 "client not authorized to use agl_shell");
968 if (ivi->shell_client.resource) {
969 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
970 "agl_shell has already been bound");
974 wl_resource_set_implementation(resource, &agl_shell_implementation,
975 ivi, unbind_agl_shell);
976 ivi->shell_client.resource = resource;
980 unbind_agl_shell_desktop(struct wl_resource *resource)
982 struct desktop_client *dclient = wl_resource_get_user_data(resource);
984 wl_list_remove(&dclient->link);
989 bind_agl_shell_desktop(struct wl_client *client,
990 void *data, uint32_t version, uint32_t id)
992 struct ivi_compositor *ivi = data;
993 struct wl_resource *resource;
994 struct desktop_client *dclient = zalloc(sizeof(*dclient));
997 wl_client_post_no_memory(client);
1001 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1005 wl_client_post_no_memory(client);
1009 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1010 dclient, unbind_agl_shell_desktop);
1012 dclient->resource = resource;
1013 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1015 /* advertise xdg surfaces */
1016 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1020 ivi_shell_create_global(struct ivi_compositor *ivi)
1022 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1023 &agl_shell_interface, 1,
1024 ivi, bind_agl_shell);
1025 if (!ivi->agl_shell) {
1026 weston_log("Failed to create wayland global.\n");
1030 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1031 &agl_shell_desktop_interface, 1,
1032 ivi, bind_agl_shell_desktop);
1033 if (!ivi->agl_shell_desktop) {
1034 weston_log("Failed to create wayland global (agl_shell_desktop).\n");