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);
59 weston_log("WARNING app_is is null, unable to advertise\n");
62 agl_shell_desktop_send_application(dclient->resource, app_id);
67 ivi_set_desktop_surface(struct ivi_surface *surface)
69 struct ivi_compositor *ivi = surface->ivi;
70 assert(surface->role == IVI_SURFACE_ROLE_NONE);
72 surface->role = IVI_SURFACE_ROLE_DESKTOP;
73 wl_list_insert(&surface->ivi->surfaces, &surface->link);
75 agl_shell_desktop_advertise_application_id(ivi, surface);
79 ivi_set_desktop_surface_popup(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_POPUP;
85 wl_list_insert(&ivi->surfaces, &surface->link);
87 agl_shell_desktop_advertise_application_id(ivi, surface);
91 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
93 struct ivi_compositor *ivi = surface->ivi;
94 assert(surface->role == IVI_SURFACE_ROLE_NONE);
96 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
97 wl_list_insert(&ivi->surfaces, &surface->link);
99 agl_shell_desktop_advertise_application_id(ivi, surface);
103 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
105 struct ivi_compositor *ivi = surface->ivi;
106 struct weston_view *view;
107 struct ivi_output *output = surface->remote.output;
109 assert(surface->role == IVI_SURFACE_ROLE_NONE);
111 /* remote type are the same as desktop just that client can tell
112 * the compositor to start on another output */
113 surface->role = IVI_SURFACE_ROLE_REMOTE;
115 /* if thew black surface view is mapped on the mean we need
116 * to remove it in order to start showing the 'remote' surface
117 * just being added */
118 view = output->fullscreen_view.fs->view;
119 if (view->is_mapped || view->surface->is_mapped)
120 remove_black_surface(output);
122 wl_list_insert(&ivi->surfaces, &surface->link);
127 ivi_set_desktop_surface_split(struct ivi_surface *surface)
129 struct ivi_compositor *ivi = surface->ivi;
130 assert(surface->role == IVI_SURFACE_ROLE_NONE);
132 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
133 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
135 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
137 wl_list_insert(&ivi->surfaces, &surface->link);
139 agl_shell_desktop_advertise_application_id(ivi, surface);
143 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
144 int x, int y, int bx, int by, int width, int height,
147 struct ivi_compositor *ivi = ioutput->ivi;
148 size_t len_app_id = strlen(app_id);
150 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
152 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
153 memcpy(p_popup->app_id, app_id, len_app_id);
154 p_popup->ioutput = ioutput;
160 p_popup->bb.width = width;
161 p_popup->bb.height = height;
163 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
167 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
170 struct ivi_compositor *ivi = ioutput->ivi;
171 size_t len_app_id = strlen(app_id);
173 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
175 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
176 memcpy(fs->app_id, app_id, len_app_id);
178 fs->ioutput = ioutput;
180 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
184 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
185 const char *app_id, uint32_t orientation)
187 struct ivi_compositor *ivi = ioutput->ivi;
188 struct ivi_surface *surf;
189 size_t len_app_id = strlen(app_id);
190 struct pending_split *split;
192 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
193 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
196 /* more than one is un-supported, do note we need to do
197 * conversion for surface roles instead of using the protocol ones */
198 wl_list_for_each(surf, &ivi->surfaces, link)
199 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
200 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
203 split = zalloc(sizeof(*split));
204 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
205 memcpy(split->app_id, app_id, len_app_id);
207 split->ioutput = ioutput;
208 split->orientation = orientation;
210 wl_list_insert(&ivi->split_pending_apps, &split->link);
214 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
217 struct ivi_compositor *ivi = ioutput->ivi;
218 size_t len_app_id = strlen(app_id);
220 struct pending_remote *remote = zalloc(sizeof(*remote));
222 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
223 memcpy(remote->app_id, app_id, len_app_id);
225 remote->ioutput = ioutput;
227 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
232 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
235 wl_list_remove(&split->link);
240 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
243 wl_list_remove(&fs->link);
248 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
250 free(p_popup->app_id);
251 wl_list_remove(&p_popup->link);
256 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
258 free(remote->app_id);
259 wl_list_remove(&remote->link);
264 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
266 struct ivi_compositor *ivi = surface->ivi;
267 struct pending_popup *p_popup, *next_p_popup;
268 const char *_app_id =
269 weston_desktop_surface_get_app_id(surface->dsurface);
271 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
274 wl_list_for_each_safe(p_popup, next_p_popup,
275 &ivi->popup_pending_apps, link) {
276 if (!strcmp(_app_id, p_popup->app_id)) {
277 surface->popup.output = p_popup->ioutput;
278 surface->popup.x = p_popup->x;
279 surface->popup.y = p_popup->y;
281 surface->popup.bb.x = p_popup->bb.x;
282 surface->popup.bb.y = p_popup->bb.y;
283 surface->popup.bb.width = p_popup->bb.width;
284 surface->popup.bb.height = p_popup->bb.height;
286 ivi_remove_pending_desktop_surface_popup(p_popup);
295 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
297 struct pending_split *split_surf, *next_split_surf;
298 struct ivi_compositor *ivi = surface->ivi;
299 const char *_app_id =
300 weston_desktop_surface_get_app_id(surface->dsurface);
302 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
305 wl_list_for_each_safe(split_surf, next_split_surf,
306 &ivi->split_pending_apps, link) {
307 if (!strcmp(_app_id, split_surf->app_id)) {
308 surface->split.output = split_surf->ioutput;
309 surface->split.orientation = split_surf->orientation;
310 ivi_remove_pending_desktop_surface_split(split_surf);
319 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
321 struct pending_fullscreen *fs_surf, *next_fs_surf;
322 struct ivi_compositor *ivi = surface->ivi;
323 const char *_app_id =
324 weston_desktop_surface_get_app_id(surface->dsurface);
326 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
329 wl_list_for_each_safe(fs_surf, next_fs_surf,
330 &ivi->fullscreen_pending_apps, link) {
331 if (!strcmp(_app_id, fs_surf->app_id)) {
332 surface->fullscreen.output = fs_surf->ioutput;
333 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
342 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
344 struct pending_remote *remote_surf, *next_remote_surf;
345 struct ivi_compositor *ivi = surface->ivi;
346 const char *_app_id =
347 weston_desktop_surface_get_app_id(surface->dsurface);
349 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
352 wl_list_for_each_safe(remote_surf, next_remote_surf,
353 &ivi->remote_pending_apps, link) {
354 if (!strcmp(_app_id, remote_surf->app_id)) {
355 surface->remote.output = remote_surf->ioutput;
356 ivi_remove_pending_desktop_surface_remote(remote_surf);
366 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
370 ret = ivi_check_pending_desktop_surface_popup(surface);
372 ivi_set_desktop_surface_popup(surface);
373 ivi_layout_popup_committed(surface);
377 ret = ivi_check_pending_desktop_surface_split(surface);
379 ivi_set_desktop_surface_split(surface);
380 ivi_layout_split_committed(surface);
384 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
386 ivi_set_desktop_surface_fullscreen(surface);
387 ivi_layout_fullscreen_committed(surface);
391 ret = ivi_check_pending_desktop_surface_remote(surface);
393 ivi_set_desktop_surface_remote(surface);
394 ivi_layout_desktop_committed(surface);
398 /* if we end up here means we have a regular desktop app and
399 * try to activate it */
400 ivi_set_desktop_surface(surface);
401 ivi_layout_desktop_committed(surface);
405 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
407 struct ivi_output *out;
409 wl_list_for_each(out, &ivi->outputs, link) {
410 create_black_surface_view(out);
411 insert_black_surface(out);
416 ivi_shell_init(struct ivi_compositor *ivi)
418 weston_layer_init(&ivi->hidden, ivi->compositor);
419 weston_layer_init(&ivi->background, ivi->compositor);
420 weston_layer_init(&ivi->normal, ivi->compositor);
421 weston_layer_init(&ivi->panel, ivi->compositor);
422 weston_layer_init(&ivi->popup, ivi->compositor);
423 weston_layer_init(&ivi->fullscreen, ivi->compositor);
425 weston_layer_set_position(&ivi->hidden,
426 WESTON_LAYER_POSITION_HIDDEN);
427 weston_layer_set_position(&ivi->background,
428 WESTON_LAYER_POSITION_BACKGROUND);
429 weston_layer_set_position(&ivi->normal,
430 WESTON_LAYER_POSITION_NORMAL);
431 weston_layer_set_position(&ivi->panel,
432 WESTON_LAYER_POSITION_UI);
433 weston_layer_set_position(&ivi->popup,
434 WESTON_LAYER_POSITION_TOP_UI);
435 weston_layer_set_position(&ivi->fullscreen,
436 WESTON_LAYER_POSITION_FULLSCREEN);
442 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
444 struct ivi_surface *surface;
446 wl_list_for_each(surface, &ivi->surfaces, link) {
448 weston_desktop_surface_get_app_id(surface->dsurface);
449 if (app_id == NULL) {
450 weston_log("WARNING app_is is null, unable to advertise\n");
453 agl_shell_desktop_send_application(resource, app_id);
458 client_exec(const char *command, int fd)
463 /* Don't give the child our signal mask */
465 sigprocmask(SIG_UNBLOCK, &sig, NULL);
467 /* Launch clients as the user; don't give them the wrong euid */
468 if (seteuid(getuid()) == -1) {
469 weston_log("seteuid failed: %s\n", strerror(errno));
473 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
474 * clobbering fd, as we'll exit/exec either way.
478 weston_log("dup failed: %s\n", strerror(errno));
482 snprintf(s, sizeof s, "%d", fd);
483 setenv("WAYLAND_SOCKET", s, 1);
485 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
486 weston_log("executing '%s' failed: %s", command, strerror(errno));
489 static struct wl_client *
490 launch_shell_client(struct ivi_compositor *ivi, const char *command)
492 struct wl_client *client;
496 weston_log("launching' %s'\n", command);
498 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
499 weston_log("socketpair failed while launching '%s': %s\n",
500 command, strerror(errno));
508 weston_log("fork failed while launching '%s': %s\n",
509 command, strerror(errno));
514 client_exec(command, sock[1]);
519 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
522 weston_log("Failed to create wayland client for '%s'",
531 ivi_launch_shell_client(struct ivi_compositor *ivi)
533 struct weston_config_section *section;
534 char *command = NULL;
536 section = weston_config_get_section(ivi->config, "shell-client",
539 weston_config_section_get_string(section, "command",
545 ivi->shell_client.client = launch_shell_client(ivi, command);
546 if (!ivi->shell_client.client)
553 destroy_black_view(struct wl_listener *listener, void *data)
555 struct fullscreen_view *fs =
556 wl_container_of(listener, fs, fs_destroy);
560 if (fs->fs->view && fs->fs->view->surface) {
561 weston_surface_destroy(fs->fs->view->surface);
566 wl_list_remove(&fs->fs_destroy.link);
572 create_black_surface_view(struct ivi_output *output)
574 struct weston_surface *surface = NULL;
575 struct weston_view *view;
576 struct ivi_compositor *ivi = output->ivi;
577 struct weston_compositor *wc= ivi->compositor;
578 struct weston_output *woutput = output->output;
580 surface = weston_surface_create(wc);
581 view = weston_view_create(surface);
583 assert(view || surface);
585 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
586 weston_surface_set_size(surface, woutput->width, woutput->height);
587 weston_view_set_position(view, woutput->x, woutput->y);
589 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
590 output->fullscreen_view.fs->view = view;
592 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
593 wl_signal_add(&woutput->destroy_signal,
594 &output->fullscreen_view.fs_destroy);
598 remove_black_surface(struct ivi_output *output)
600 struct weston_view *view;
603 !output->fullscreen_view.fs &&
604 !output->fullscreen_view.fs->view) {
605 weston_log("Output %s doesn't have a surface installed!\n", output->name);
609 view = output->fullscreen_view.fs->view;
610 assert(view->is_mapped == true ||
611 view->surface->is_mapped == true);
613 view->is_mapped = false;
614 view->surface->is_mapped = false;
616 weston_layer_entry_remove(&view->layer_link);
617 weston_view_update_transform(view);
619 weston_output_damage(output->output);
623 insert_black_surface(struct ivi_output *output)
625 struct weston_view *view;
628 !output->fullscreen_view.fs &&
629 !output->fullscreen_view.fs->view) {
630 weston_log("Output %s doesn't have a surface installed!\n", output->name);
634 view = output->fullscreen_view.fs->view;
635 if (view->is_mapped || view->surface->is_mapped)
638 weston_layer_entry_remove(&view->layer_link);
639 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
642 view->is_mapped = true;
643 view->surface->is_mapped = true;
645 weston_view_update_transform(view);
646 weston_output_damage(output->output);
650 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
652 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
653 struct ivi_output *output;
654 struct ivi_surface *surface, *tmp;
656 /* Init already finished. Do nothing */
657 if (ivi->shell_client.ready)
660 ivi->shell_client.ready = true;
662 wl_list_for_each(output, &ivi->outputs, link) {
663 if (output->background)
664 remove_black_surface(output);
665 ivi_layout_init(ivi, output);
668 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
669 wl_list_remove(&surface->link);
670 ivi_check_pending_desktop_surface(surface);
675 shell_set_background(struct wl_client *client,
676 struct wl_resource *shell_res,
677 struct wl_resource *surface_res,
678 struct wl_resource *output_res)
680 struct weston_head *head = weston_head_from_resource(output_res);
681 struct weston_output *woutput = weston_head_get_output(head);
682 struct ivi_output *output = to_ivi_output(woutput);
683 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
684 struct weston_desktop_surface *dsurface;
685 struct ivi_surface *surface;
687 dsurface = weston_surface_get_desktop_surface(wsurface);
689 wl_resource_post_error(shell_res,
690 AGL_SHELL_ERROR_INVALID_ARGUMENT,
691 "surface must be a desktop surface");
695 surface = weston_desktop_surface_get_user_data(dsurface);
696 if (surface->role != IVI_SURFACE_ROLE_NONE) {
697 wl_resource_post_error(shell_res,
698 AGL_SHELL_ERROR_INVALID_ARGUMENT,
699 "surface already has another ivi role");
703 if (output->background) {
704 wl_resource_post_error(shell_res,
705 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
706 "output already has background");
710 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
711 surface->bg.output = output;
712 wl_list_remove(&surface->link);
713 wl_list_init(&surface->link);
715 output->background = surface;
717 weston_desktop_surface_set_maximized(dsurface, true);
718 weston_desktop_surface_set_size(dsurface,
719 output->output->width,
720 output->output->height);
724 shell_set_panel(struct wl_client *client,
725 struct wl_resource *shell_res,
726 struct wl_resource *surface_res,
727 struct wl_resource *output_res,
730 struct weston_head *head = weston_head_from_resource(output_res);
731 struct weston_output *woutput = weston_head_get_output(head);
732 struct ivi_output *output = to_ivi_output(woutput);
733 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
734 struct weston_desktop_surface *dsurface;
735 struct ivi_surface *surface;
736 struct ivi_surface **member;
737 int32_t width = 0, height = 0;
739 dsurface = weston_surface_get_desktop_surface(wsurface);
741 wl_resource_post_error(shell_res,
742 AGL_SHELL_ERROR_INVALID_ARGUMENT,
743 "surface must be a desktop surface");
747 surface = weston_desktop_surface_get_user_data(dsurface);
748 if (surface->role != IVI_SURFACE_ROLE_NONE) {
749 wl_resource_post_error(shell_res,
750 AGL_SHELL_ERROR_INVALID_ARGUMENT,
751 "surface already has another ivi role");
756 case AGL_SHELL_EDGE_TOP:
757 member = &output->top;
759 case AGL_SHELL_EDGE_BOTTOM:
760 member = &output->bottom;
762 case AGL_SHELL_EDGE_LEFT:
763 member = &output->left;
765 case AGL_SHELL_EDGE_RIGHT:
766 member = &output->right;
769 wl_resource_post_error(shell_res,
770 AGL_SHELL_ERROR_INVALID_ARGUMENT,
771 "invalid edge for panel");
776 wl_resource_post_error(shell_res,
777 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
778 "output already has panel on this edge");
782 surface->role = IVI_SURFACE_ROLE_PANEL;
783 surface->panel.output = output;
784 surface->panel.edge = edge;
785 wl_list_remove(&surface->link);
786 wl_list_init(&surface->link);
790 switch (surface->panel.edge) {
791 case AGL_SHELL_EDGE_TOP:
792 case AGL_SHELL_EDGE_BOTTOM:
793 width = woutput->width;
795 case AGL_SHELL_EDGE_LEFT:
796 case AGL_SHELL_EDGE_RIGHT:
797 height = woutput->height;
801 weston_desktop_surface_set_size(dsurface, width, height);
805 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
806 const char *data, uint32_t app_state)
808 struct desktop_client *dclient;
810 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
811 struct ivi_policy *policy = ivi->policy;
813 /* FIXME: should queue it here and see when binding agl-shell-desktop
814 * if there are any to be sent */
821 if (policy && policy->api.surface_advertise_state_change &&
822 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
826 app_role = surf->role;
827 if (app_role == IVI_SURFACE_ROLE_POPUP)
828 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
830 wl_list_for_each(dclient, &ivi->desktop_clients, link)
831 agl_shell_desktop_send_state_app(dclient->resource, app_id,
832 data, app_state, app_role);
836 shell_activate_app(struct wl_client *client,
837 struct wl_resource *shell_res,
839 struct wl_resource *output_res)
841 struct weston_head *head = weston_head_from_resource(output_res);
842 struct weston_output *woutput = weston_head_get_output(head);
843 struct ivi_output *output = to_ivi_output(woutput);
845 ivi_layout_activate(output, app_id);
849 shell_desktop_activate_app(struct wl_client *client,
850 struct wl_resource *shell_res,
851 const char *app_id, const char *data,
852 struct wl_resource *output_res)
854 struct weston_head *head = weston_head_from_resource(output_res);
855 struct weston_output *woutput = weston_head_get_output(head);
856 struct ivi_output *output = to_ivi_output(woutput);
858 ivi_layout_activate(output, app_id);
859 shell_advertise_app_state(output->ivi, app_id,
860 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
864 shell_deactivate_app(struct wl_client *client,
865 struct wl_resource *shell_res,
868 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
869 struct ivi_compositor *ivi = dclient->ivi;
871 ivi_layout_deactivate(ivi, app_id);
872 shell_advertise_app_state(ivi, app_id,
873 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
876 static const struct agl_shell_interface agl_shell_implementation = {
877 .ready = shell_ready,
878 .set_background = shell_set_background,
879 .set_panel = shell_set_panel,
880 .activate_app = shell_activate_app,
884 shell_desktop_set_app_property(struct wl_client *client,
885 struct wl_resource *shell_res,
886 const char *app_id, uint32_t role,
887 int x, int y, int bx, int by,
888 int width, int height,
889 struct wl_resource *output_res)
891 struct weston_head *head = weston_head_from_resource(output_res);
892 struct weston_output *woutput = weston_head_get_output(head);
893 struct ivi_output *output = to_ivi_output(woutput);
896 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
897 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
898 width, height, app_id);
900 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
901 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
903 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
904 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
905 ivi_set_pending_desktop_surface_split(output, app_id, role);
907 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
908 ivi_set_pending_desktop_surface_remote(output, app_id);
915 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
916 .activate_app = shell_desktop_activate_app,
917 .set_app_property = shell_desktop_set_app_property,
918 .deactivate_app = shell_deactivate_app,
922 unbind_agl_shell(struct wl_resource *resource)
924 struct ivi_compositor *ivi;
925 struct ivi_output *output;
926 struct ivi_surface *surf, *surf_tmp;
928 ivi = wl_resource_get_user_data(resource);
929 wl_list_for_each(output, &ivi->outputs, link) {
930 /* reset the active surf if there's one present */
931 if (output->active) {
932 output->active->view->is_mapped = false;
933 output->active->view->surface->is_mapped = false;
935 weston_layer_entry_remove(&output->active->view->layer_link);
936 output->active = NULL;
939 insert_black_surface(output);
942 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
943 wl_list_remove(&surf->link);
944 wl_list_init(&surf->link);
947 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
948 wl_list_remove(&surf->link);
949 wl_list_init(&surf->link);
952 wl_list_init(&ivi->surfaces);
953 wl_list_init(&ivi->pending_surfaces);
955 ivi->shell_client.ready = false;
956 ivi->shell_client.resource = NULL;
957 ivi->shell_client.client = NULL;
961 bind_agl_shell(struct wl_client *client,
962 void *data, uint32_t version, uint32_t id)
964 struct ivi_compositor *ivi = data;
965 struct wl_resource *resource;
966 struct ivi_policy *policy;
969 policy = ivi->policy;
970 interface = (void *) &agl_shell_interface;
971 if (policy && policy->api.shell_bind_interface &&
972 !policy->api.shell_bind_interface(client, interface)) {
973 wl_client_post_implementation_error(client,
974 "client not authorized to use agl_shell");
978 resource = wl_resource_create(client, &agl_shell_interface,
981 wl_client_post_no_memory(client);
986 if (ivi->shell_client.client != client) {
987 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
988 "client not authorized to use agl_shell");
993 if (ivi->shell_client.resource) {
994 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
995 "agl_shell has already been bound");
999 wl_resource_set_implementation(resource, &agl_shell_implementation,
1000 ivi, unbind_agl_shell);
1001 ivi->shell_client.resource = resource;
1005 unbind_agl_shell_desktop(struct wl_resource *resource)
1007 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1009 wl_list_remove(&dclient->link);
1014 bind_agl_shell_desktop(struct wl_client *client,
1015 void *data, uint32_t version, uint32_t id)
1017 struct ivi_compositor *ivi = data;
1018 struct wl_resource *resource;
1019 struct ivi_policy *policy;
1020 struct desktop_client *dclient;
1023 policy = ivi->policy;
1024 interface = (void *) &agl_shell_desktop_interface;
1025 if (policy && policy->api.shell_bind_interface &&
1026 !policy->api.shell_bind_interface(client, interface)) {
1027 wl_client_post_implementation_error(client,
1028 "client not authorized to use agl_shell_desktop");
1032 dclient = zalloc(sizeof(*dclient));
1034 wl_client_post_no_memory(client);
1038 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1042 wl_client_post_no_memory(client);
1046 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1047 dclient, unbind_agl_shell_desktop);
1049 dclient->resource = resource;
1050 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1052 /* advertise xdg surfaces */
1053 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1057 ivi_shell_create_global(struct ivi_compositor *ivi)
1059 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1060 &agl_shell_interface, 1,
1061 ivi, bind_agl_shell);
1062 if (!ivi->agl_shell) {
1063 weston_log("Failed to create wayland global.\n");
1067 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1068 &agl_shell_desktop_interface, 1,
1069 ivi, bind_agl_shell_desktop);
1070 if (!ivi->agl_shell_desktop) {
1071 weston_log("Failed to create wayland global (agl_shell_desktop).\n");