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) || !_app_id)
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) || !_app_id)
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) || !_app_id)
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) || !_app_id)
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);
369 ivi_layout_popup_committed(surface);
373 ret = ivi_check_pending_desktop_surface_split(surface);
375 ivi_set_desktop_surface_split(surface);
376 ivi_layout_split_committed(surface);
380 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
382 ivi_set_desktop_surface_fullscreen(surface);
383 ivi_layout_fullscreen_committed(surface);
387 ret = ivi_check_pending_desktop_surface_remote(surface);
389 ivi_set_desktop_surface_remote(surface);
390 ivi_layout_desktop_committed(surface);
394 /* if we end up here means we have a regular desktop app and
395 * try to activate it */
396 ivi_set_desktop_surface(surface);
397 ivi_layout_desktop_committed(surface);
401 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
403 struct ivi_output *out;
405 wl_list_for_each(out, &ivi->outputs, link) {
406 create_black_surface_view(out);
407 insert_black_surface(out);
412 ivi_shell_init(struct ivi_compositor *ivi)
414 weston_layer_init(&ivi->hidden, ivi->compositor);
415 weston_layer_init(&ivi->background, ivi->compositor);
416 weston_layer_init(&ivi->normal, ivi->compositor);
417 weston_layer_init(&ivi->panel, ivi->compositor);
418 weston_layer_init(&ivi->popup, ivi->compositor);
419 weston_layer_init(&ivi->fullscreen, ivi->compositor);
421 weston_layer_set_position(&ivi->hidden,
422 WESTON_LAYER_POSITION_HIDDEN);
423 weston_layer_set_position(&ivi->background,
424 WESTON_LAYER_POSITION_BACKGROUND);
425 weston_layer_set_position(&ivi->normal,
426 WESTON_LAYER_POSITION_NORMAL);
427 weston_layer_set_position(&ivi->panel,
428 WESTON_LAYER_POSITION_UI);
429 weston_layer_set_position(&ivi->popup,
430 WESTON_LAYER_POSITION_TOP_UI);
431 weston_layer_set_position(&ivi->fullscreen,
432 WESTON_LAYER_POSITION_FULLSCREEN);
438 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
440 struct ivi_surface *surface;
442 wl_list_for_each(surface, &ivi->surfaces, link) {
444 weston_desktop_surface_get_app_id(surface->dsurface);
445 agl_shell_desktop_send_application(resource, app_id);
450 client_exec(const char *command, int fd)
455 /* Don't give the child our signal mask */
457 sigprocmask(SIG_UNBLOCK, &sig, NULL);
459 /* Launch clients as the user; don't give them the wrong euid */
460 if (seteuid(getuid()) == -1) {
461 weston_log("seteuid failed: %s\n", strerror(errno));
465 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
466 * clobbering fd, as we'll exit/exec either way.
470 weston_log("dup failed: %s\n", strerror(errno));
474 snprintf(s, sizeof s, "%d", fd);
475 setenv("WAYLAND_SOCKET", s, 1);
477 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
478 weston_log("executing '%s' failed: %s", command, strerror(errno));
481 static struct wl_client *
482 launch_shell_client(struct ivi_compositor *ivi, const char *command)
484 struct wl_client *client;
488 weston_log("launching' %s'\n", command);
490 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
491 weston_log("socketpair failed while launching '%s': %s\n",
492 command, strerror(errno));
500 weston_log("fork failed while launching '%s': %s\n",
501 command, strerror(errno));
506 client_exec(command, sock[1]);
511 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
514 weston_log("Failed to create wayland client for '%s'",
523 ivi_launch_shell_client(struct ivi_compositor *ivi)
525 struct weston_config_section *section;
526 char *command = NULL;
528 section = weston_config_get_section(ivi->config, "shell-client",
531 weston_config_section_get_string(section, "command",
537 ivi->shell_client.client = launch_shell_client(ivi, command);
538 if (!ivi->shell_client.client)
545 destroy_black_view(struct wl_listener *listener, void *data)
547 struct fullscreen_view *fs =
548 wl_container_of(listener, fs, fs_destroy);
552 if (fs->fs->view && fs->fs->view->surface) {
553 weston_surface_destroy(fs->fs->view->surface);
558 wl_list_remove(&fs->fs_destroy.link);
564 create_black_surface_view(struct ivi_output *output)
566 struct weston_surface *surface = NULL;
567 struct weston_view *view;
568 struct ivi_compositor *ivi = output->ivi;
569 struct weston_compositor *wc= ivi->compositor;
570 struct weston_output *woutput = output->output;
572 surface = weston_surface_create(wc);
573 view = weston_view_create(surface);
575 assert(view || surface);
577 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
578 weston_surface_set_size(surface, woutput->width, woutput->height);
579 weston_view_set_position(view, woutput->x, woutput->y);
581 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
582 output->fullscreen_view.fs->view = view;
584 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
585 wl_signal_add(&woutput->destroy_signal,
586 &output->fullscreen_view.fs_destroy);
590 remove_black_surface(struct ivi_output *output)
592 struct weston_view *view;
595 !output->fullscreen_view.fs &&
596 !output->fullscreen_view.fs->view) {
597 weston_log("Output %s doesn't have a surface installed!\n", output->name);
601 view = output->fullscreen_view.fs->view;
602 assert(view->is_mapped == true ||
603 view->surface->is_mapped == true);
605 view->is_mapped = false;
606 view->surface->is_mapped = false;
608 weston_layer_entry_remove(&view->layer_link);
609 weston_view_update_transform(view);
611 weston_output_damage(output->output);
615 insert_black_surface(struct ivi_output *output)
617 struct weston_view *view;
620 !output->fullscreen_view.fs &&
621 !output->fullscreen_view.fs->view) {
622 weston_log("Output %s doesn't have a surface installed!\n", output->name);
626 view = output->fullscreen_view.fs->view;
627 if (view->is_mapped || view->surface->is_mapped)
630 weston_layer_entry_remove(&view->layer_link);
631 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
634 view->is_mapped = true;
635 view->surface->is_mapped = true;
637 weston_view_update_transform(view);
638 weston_output_damage(output->output);
642 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
644 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
645 struct ivi_output *output;
646 struct ivi_surface *surface, *tmp;
648 /* Init already finished. Do nothing */
649 if (ivi->shell_client.ready)
652 ivi->shell_client.ready = true;
654 wl_list_for_each(output, &ivi->outputs, link) {
655 if (output->background)
656 remove_black_surface(output);
657 ivi_layout_init(ivi, output);
660 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
661 wl_list_remove(&surface->link);
662 ivi_check_pending_desktop_surface(surface);
667 shell_set_background(struct wl_client *client,
668 struct wl_resource *shell_res,
669 struct wl_resource *surface_res,
670 struct wl_resource *output_res)
672 struct weston_head *head = weston_head_from_resource(output_res);
673 struct weston_output *woutput = weston_head_get_output(head);
674 struct ivi_output *output = to_ivi_output(woutput);
675 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
676 struct weston_desktop_surface *dsurface;
677 struct ivi_surface *surface;
679 dsurface = weston_surface_get_desktop_surface(wsurface);
681 wl_resource_post_error(shell_res,
682 AGL_SHELL_ERROR_INVALID_ARGUMENT,
683 "surface must be a desktop surface");
687 surface = weston_desktop_surface_get_user_data(dsurface);
688 if (surface->role != IVI_SURFACE_ROLE_NONE) {
689 wl_resource_post_error(shell_res,
690 AGL_SHELL_ERROR_INVALID_ARGUMENT,
691 "surface already has another ivi role");
695 if (output->background) {
696 wl_resource_post_error(shell_res,
697 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
698 "output already has background");
702 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
703 surface->bg.output = output;
704 wl_list_remove(&surface->link);
705 wl_list_init(&surface->link);
707 output->background = surface;
709 weston_desktop_surface_set_maximized(dsurface, true);
710 weston_desktop_surface_set_size(dsurface,
711 output->output->width,
712 output->output->height);
716 shell_set_panel(struct wl_client *client,
717 struct wl_resource *shell_res,
718 struct wl_resource *surface_res,
719 struct wl_resource *output_res,
722 struct weston_head *head = weston_head_from_resource(output_res);
723 struct weston_output *woutput = weston_head_get_output(head);
724 struct ivi_output *output = to_ivi_output(woutput);
725 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
726 struct weston_desktop_surface *dsurface;
727 struct ivi_surface *surface;
728 struct ivi_surface **member;
729 int32_t width = 0, height = 0;
731 dsurface = weston_surface_get_desktop_surface(wsurface);
733 wl_resource_post_error(shell_res,
734 AGL_SHELL_ERROR_INVALID_ARGUMENT,
735 "surface must be a desktop surface");
739 surface = weston_desktop_surface_get_user_data(dsurface);
740 if (surface->role != IVI_SURFACE_ROLE_NONE) {
741 wl_resource_post_error(shell_res,
742 AGL_SHELL_ERROR_INVALID_ARGUMENT,
743 "surface already has another ivi role");
748 case AGL_SHELL_EDGE_TOP:
749 member = &output->top;
751 case AGL_SHELL_EDGE_BOTTOM:
752 member = &output->bottom;
754 case AGL_SHELL_EDGE_LEFT:
755 member = &output->left;
757 case AGL_SHELL_EDGE_RIGHT:
758 member = &output->right;
761 wl_resource_post_error(shell_res,
762 AGL_SHELL_ERROR_INVALID_ARGUMENT,
763 "invalid edge for panel");
768 wl_resource_post_error(shell_res,
769 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
770 "output already has panel on this edge");
774 surface->role = IVI_SURFACE_ROLE_PANEL;
775 surface->panel.output = output;
776 surface->panel.edge = edge;
777 wl_list_remove(&surface->link);
778 wl_list_init(&surface->link);
782 switch (surface->panel.edge) {
783 case AGL_SHELL_EDGE_TOP:
784 case AGL_SHELL_EDGE_BOTTOM:
785 width = woutput->width;
787 case AGL_SHELL_EDGE_LEFT:
788 case AGL_SHELL_EDGE_RIGHT:
789 height = woutput->height;
793 weston_desktop_surface_set_size(dsurface, width, height);
797 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
798 const char *data, uint32_t app_state)
800 struct desktop_client *dclient;
802 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
803 struct ivi_policy *policy = ivi->policy;
805 /* FIXME: should queue it here and see when binding agl-shell-desktop
806 * if there are any to be sent */
810 if (policy && policy->api.surface_advertise_state_change &&
811 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
815 app_role = surf->role;
816 if (app_role == IVI_SURFACE_ROLE_POPUP)
817 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
819 wl_list_for_each(dclient, &ivi->desktop_clients, link)
820 agl_shell_desktop_send_state_app(dclient->resource, app_id,
821 data, app_state, app_role);
825 shell_activate_app(struct wl_client *client,
826 struct wl_resource *shell_res,
828 struct wl_resource *output_res)
830 struct weston_head *head = weston_head_from_resource(output_res);
831 struct weston_output *woutput = weston_head_get_output(head);
832 struct ivi_output *output = to_ivi_output(woutput);
834 ivi_layout_activate(output, app_id);
838 shell_desktop_activate_app(struct wl_client *client,
839 struct wl_resource *shell_res,
840 const char *app_id, const char *data,
841 struct wl_resource *output_res)
843 struct weston_head *head = weston_head_from_resource(output_res);
844 struct weston_output *woutput = weston_head_get_output(head);
845 struct ivi_output *output = to_ivi_output(woutput);
847 ivi_layout_activate(output, app_id);
848 shell_advertise_app_state(output->ivi, app_id,
849 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
853 shell_deactivate_app(struct wl_client *client,
854 struct wl_resource *shell_res,
857 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
858 struct ivi_compositor *ivi = dclient->ivi;
860 ivi_layout_deactivate(ivi, app_id);
861 shell_advertise_app_state(ivi, app_id,
862 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
865 static const struct agl_shell_interface agl_shell_implementation = {
866 .ready = shell_ready,
867 .set_background = shell_set_background,
868 .set_panel = shell_set_panel,
869 .activate_app = shell_activate_app,
873 shell_desktop_set_app_property(struct wl_client *client,
874 struct wl_resource *shell_res,
875 const char *app_id, uint32_t role,
876 int x, int y, int bx, int by,
877 int width, int height,
878 struct wl_resource *output_res)
880 struct weston_head *head = weston_head_from_resource(output_res);
881 struct weston_output *woutput = weston_head_get_output(head);
882 struct ivi_output *output = to_ivi_output(woutput);
885 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
886 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
887 width, height, app_id);
889 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
890 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
892 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
893 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
894 ivi_set_pending_desktop_surface_split(output, app_id, role);
896 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
897 ivi_set_pending_desktop_surface_remote(output, app_id);
904 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
905 .activate_app = shell_desktop_activate_app,
906 .set_app_property = shell_desktop_set_app_property,
907 .deactivate_app = shell_deactivate_app,
911 unbind_agl_shell(struct wl_resource *resource)
913 struct ivi_compositor *ivi;
914 struct ivi_output *output;
915 struct ivi_surface *surf, *surf_tmp;
917 ivi = wl_resource_get_user_data(resource);
918 wl_list_for_each(output, &ivi->outputs, link) {
919 /* reset the active surf if there's one present */
920 if (output->active) {
921 output->active->view->is_mapped = false;
922 output->active->view->surface->is_mapped = false;
924 weston_layer_entry_remove(&output->active->view->layer_link);
925 output->active = NULL;
928 insert_black_surface(output);
931 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
932 wl_list_remove(&surf->link);
933 wl_list_init(&surf->link);
936 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
937 wl_list_remove(&surf->link);
938 wl_list_init(&surf->link);
941 wl_list_init(&ivi->surfaces);
942 wl_list_init(&ivi->pending_surfaces);
944 ivi->shell_client.ready = false;
945 ivi->shell_client.resource = NULL;
946 ivi->shell_client.client = NULL;
950 bind_agl_shell(struct wl_client *client,
951 void *data, uint32_t version, uint32_t id)
953 struct ivi_compositor *ivi = data;
954 struct wl_resource *resource;
955 struct ivi_policy *policy;
958 policy = ivi->policy;
959 interface = (void *) &agl_shell_interface;
960 if (policy && policy->api.shell_bind_interface &&
961 !policy->api.shell_bind_interface(client, interface)) {
962 wl_client_post_implementation_error(client,
963 "client not authorized to use agl_shell");
967 resource = wl_resource_create(client, &agl_shell_interface,
970 wl_client_post_no_memory(client);
975 if (ivi->shell_client.client != client) {
976 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
977 "client not authorized to use agl_shell");
982 if (ivi->shell_client.resource) {
983 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
984 "agl_shell has already been bound");
988 wl_resource_set_implementation(resource, &agl_shell_implementation,
989 ivi, unbind_agl_shell);
990 ivi->shell_client.resource = resource;
994 unbind_agl_shell_desktop(struct wl_resource *resource)
996 struct desktop_client *dclient = wl_resource_get_user_data(resource);
998 wl_list_remove(&dclient->link);
1003 bind_agl_shell_desktop(struct wl_client *client,
1004 void *data, uint32_t version, uint32_t id)
1006 struct ivi_compositor *ivi = data;
1007 struct wl_resource *resource;
1008 struct ivi_policy *policy;
1009 struct desktop_client *dclient;
1012 policy = ivi->policy;
1013 interface = (void *) &agl_shell_desktop_interface;
1014 if (policy && policy->api.shell_bind_interface &&
1015 !policy->api.shell_bind_interface(client, interface)) {
1016 wl_client_post_implementation_error(client,
1017 "client not authorized to use agl_shell_desktop");
1021 dclient = zalloc(sizeof(*dclient));
1023 wl_client_post_no_memory(client);
1027 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1031 wl_client_post_no_memory(client);
1035 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1036 dclient, unbind_agl_shell_desktop);
1038 dclient->resource = resource;
1039 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1041 /* advertise xdg surfaces */
1042 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1046 ivi_shell_create_global(struct ivi_compositor *ivi)
1048 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1049 &agl_shell_interface, 1,
1050 ivi, bind_agl_shell);
1051 if (!ivi->agl_shell) {
1052 weston_log("Failed to create wayland global.\n");
1056 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1057 &agl_shell_desktop_interface, 1,
1058 ivi, bind_agl_shell_desktop);
1059 if (!ivi->agl_shell_desktop) {
1060 weston_log("Failed to create wayland global (agl_shell_desktop).\n");