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 #include <waltham-transmitter/transmitter_api.h>
50 create_black_surface_view(struct ivi_output *output);
53 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
54 struct ivi_surface *surface)
56 struct desktop_client *dclient;
57 static bool display_adv = false;
59 if (surface->advertised_on_launch)
62 /* advertise to all desktop clients the new surface */
63 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
65 weston_desktop_surface_get_app_id(surface->dsurface);
68 weston_log("WARNING app_is is null, unable to advertise\n");
73 agl_shell_desktop_send_application(dclient->resource, app_id);
74 surface->advertised_on_launch = true;
79 ivi_set_desktop_surface(struct ivi_surface *surface)
81 struct ivi_compositor *ivi = surface->ivi;
82 assert(surface->role == IVI_SURFACE_ROLE_NONE);
84 surface->role = IVI_SURFACE_ROLE_DESKTOP;
85 wl_list_insert(&surface->ivi->surfaces, &surface->link);
87 agl_shell_desktop_advertise_application_id(ivi, surface);
91 ivi_set_desktop_surface_popup(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_POPUP;
97 wl_list_insert(&ivi->surfaces, &surface->link);
99 agl_shell_desktop_advertise_application_id(ivi, surface);
103 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
105 struct ivi_compositor *ivi = surface->ivi;
106 assert(surface->role == IVI_SURFACE_ROLE_NONE);
108 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
109 wl_list_insert(&ivi->surfaces, &surface->link);
111 agl_shell_desktop_advertise_application_id(ivi, surface);
116 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
118 struct ivi_compositor *ivi = surface->ivi;
119 const struct weston_transmitter_api *api =
120 ivi->waltham_transmitter_api;
125 if (surface->waltham_surface.transmitter_surface)
126 api->surface_destroy(surface->waltham_surface.transmitter_surface);
130 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
132 struct ivi_compositor *ivi = surface->ivi;
133 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
134 struct weston_transmitter *transmitter;
135 struct weston_transmitter_remote *trans_remote;
136 struct weston_surface *weston_surface;
137 struct weston_output *woutput = surface->remote.output->output;
143 transmitter = api->transmitter_get(ivi->compositor);
147 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
149 weston_log("Could not find a valie weston_transmitter_remote "
150 "that matches the output %s\n", woutput->name);
154 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
156 weston_desktop_surface_get_surface(surface->dsurface);
158 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
160 /* this will have the effect of informing the remote side to create a
161 * surface with the name app_id. W/ xdg-shell the following happens:
163 * compositor (server):
164 * surface_push_to_remote():
165 * waltham-transmitter plug-in
166 * -> wthp_ivi_app_id_surface_create()
168 * client -- on the receiver side:
169 * -> wthp_ivi_app_id_surface_create()
170 * -> wth_receiver_weston_main()
171 * -> wl_compositor_create_surface()
172 * -> xdg_wm_base_get_xdg_surface
173 * -> xdg_toplevel_set_app_id()
175 * -> gst_parse_launch()
177 * wth_receiver_weston_main() will be invoked from the handler of
178 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
179 * the gstreamer pipeline as well.
181 surface->waltham_surface.transmitter_surface =
182 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
187 ivi_destroy_waltham_destroy(struct ivi_surface *surface)
191 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
197 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
199 struct ivi_compositor *ivi = surface->ivi;
200 struct weston_view *view;
201 struct ivi_output *output = surface->remote.output;
203 assert(surface->role == IVI_SURFACE_ROLE_NONE);
205 /* remote type are the same as desktop just that client can tell
206 * the compositor to start on another output */
207 surface->role = IVI_SURFACE_ROLE_REMOTE;
209 /* if thew black surface view is mapped on the mean we need
210 * to remove it in order to start showing the 'remote' surface
211 * just being added */
212 view = output->fullscreen_view.fs->view;
213 if (view->is_mapped || view->surface->is_mapped)
214 remove_black_surface(output);
216 if (output->type == OUTPUT_WALTHAM)
217 ivi_output_notify_waltham_plugin(surface);
219 wl_list_insert(&ivi->surfaces, &surface->link);
224 ivi_set_desktop_surface_split(struct ivi_surface *surface)
226 struct ivi_compositor *ivi = surface->ivi;
227 assert(surface->role == IVI_SURFACE_ROLE_NONE);
229 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
230 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
232 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
234 wl_list_insert(&ivi->surfaces, &surface->link);
236 agl_shell_desktop_advertise_application_id(ivi, surface);
240 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
241 int x, int y, int bx, int by, int width, int height,
244 struct ivi_compositor *ivi = ioutput->ivi;
245 size_t len_app_id = strlen(app_id);
247 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
249 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
250 memcpy(p_popup->app_id, app_id, len_app_id);
251 p_popup->ioutput = ioutput;
257 p_popup->bb.width = width;
258 p_popup->bb.height = height;
260 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
264 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
267 struct ivi_compositor *ivi = ioutput->ivi;
268 size_t len_app_id = strlen(app_id);
270 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
272 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
273 memcpy(fs->app_id, app_id, len_app_id);
275 fs->ioutput = ioutput;
277 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
281 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
282 const char *app_id, uint32_t orientation)
284 struct ivi_compositor *ivi = ioutput->ivi;
285 struct ivi_surface *surf;
286 size_t len_app_id = strlen(app_id);
287 struct pending_split *split;
289 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
290 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
293 /* more than one is un-supported, do note we need to do
294 * conversion for surface roles instead of using the protocol ones */
295 wl_list_for_each(surf, &ivi->surfaces, link)
296 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
297 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
300 split = zalloc(sizeof(*split));
301 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
302 memcpy(split->app_id, app_id, len_app_id);
304 split->ioutput = ioutput;
305 split->orientation = orientation;
307 wl_list_insert(&ivi->split_pending_apps, &split->link);
311 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
314 struct ivi_compositor *ivi = ioutput->ivi;
315 size_t len_app_id = strlen(app_id);
317 struct pending_remote *remote = zalloc(sizeof(*remote));
319 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
320 memcpy(remote->app_id, app_id, len_app_id);
322 remote->ioutput = ioutput;
324 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
329 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
332 wl_list_remove(&split->link);
337 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
340 wl_list_remove(&fs->link);
345 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
347 free(p_popup->app_id);
348 wl_list_remove(&p_popup->link);
353 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
355 free(remote->app_id);
356 wl_list_remove(&remote->link);
361 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
363 struct ivi_compositor *ivi = surface->ivi;
364 struct pending_popup *p_popup, *next_p_popup;
365 const char *_app_id =
366 weston_desktop_surface_get_app_id(surface->dsurface);
368 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
371 wl_list_for_each_safe(p_popup, next_p_popup,
372 &ivi->popup_pending_apps, link) {
373 if (!strcmp(_app_id, p_popup->app_id)) {
374 surface->popup.output = p_popup->ioutput;
375 surface->popup.x = p_popup->x;
376 surface->popup.y = p_popup->y;
378 surface->popup.bb.x = p_popup->bb.x;
379 surface->popup.bb.y = p_popup->bb.y;
380 surface->popup.bb.width = p_popup->bb.width;
381 surface->popup.bb.height = p_popup->bb.height;
383 ivi_remove_pending_desktop_surface_popup(p_popup);
392 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
394 struct pending_split *split_surf, *next_split_surf;
395 struct ivi_compositor *ivi = surface->ivi;
396 const char *_app_id =
397 weston_desktop_surface_get_app_id(surface->dsurface);
399 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
402 wl_list_for_each_safe(split_surf, next_split_surf,
403 &ivi->split_pending_apps, link) {
404 if (!strcmp(_app_id, split_surf->app_id)) {
405 surface->split.output = split_surf->ioutput;
406 surface->split.orientation = split_surf->orientation;
407 ivi_remove_pending_desktop_surface_split(split_surf);
416 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
418 struct pending_fullscreen *fs_surf, *next_fs_surf;
419 struct ivi_compositor *ivi = surface->ivi;
420 const char *_app_id =
421 weston_desktop_surface_get_app_id(surface->dsurface);
423 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
426 wl_list_for_each_safe(fs_surf, next_fs_surf,
427 &ivi->fullscreen_pending_apps, link) {
428 if (!strcmp(_app_id, fs_surf->app_id)) {
429 surface->fullscreen.output = fs_surf->ioutput;
430 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
439 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
441 struct pending_remote *remote_surf, *next_remote_surf;
442 struct ivi_compositor *ivi = surface->ivi;
443 const char *_app_id =
444 weston_desktop_surface_get_app_id(surface->dsurface);
446 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
449 wl_list_for_each_safe(remote_surf, next_remote_surf,
450 &ivi->remote_pending_apps, link) {
451 if (!strcmp(_app_id, remote_surf->app_id)) {
452 surface->remote.output = remote_surf->ioutput;
453 ivi_remove_pending_desktop_surface_remote(remote_surf);
462 ivi_check_pending_surface(struct ivi_surface *surface)
464 struct ivi_compositor *ivi = surface->ivi;
465 struct wl_list *role_pending_list;
466 struct pending_popup *p_popup;
467 struct pending_split *p_split;
468 struct pending_fullscreen *p_fullscreen;
469 struct pending_remote *p_remote;
471 weston_desktop_surface_get_app_id(surface->dsurface);
476 role_pending_list = &ivi->popup_pending_apps;
477 wl_list_for_each(p_popup, role_pending_list, link) {
478 if (!strcmp(app_id, p_popup->app_id)) {
483 role_pending_list = &ivi->split_pending_apps;
484 wl_list_for_each(p_split, role_pending_list, link) {
485 if (!strcmp(app_id, p_split->app_id)) {
490 role_pending_list = &ivi->fullscreen_pending_apps;
491 wl_list_for_each(p_fullscreen, role_pending_list, link) {
492 if (!strcmp(app_id, p_fullscreen->app_id)) {
497 role_pending_list = &ivi->remote_pending_apps;
498 wl_list_for_each(p_remote, role_pending_list, link) {
499 if (!strcmp(app_id, p_remote->app_id)) {
504 /* else, we are a regular desktop surface */
510 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
514 ret = ivi_check_pending_desktop_surface_popup(surface);
516 ivi_set_desktop_surface_popup(surface);
517 ivi_layout_popup_committed(surface);
521 ret = ivi_check_pending_desktop_surface_split(surface);
523 ivi_set_desktop_surface_split(surface);
524 ivi_layout_split_committed(surface);
528 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
530 ivi_set_desktop_surface_fullscreen(surface);
531 ivi_layout_fullscreen_committed(surface);
535 ret = ivi_check_pending_desktop_surface_remote(surface);
537 ivi_set_desktop_surface_remote(surface);
538 ivi_layout_desktop_committed(surface);
542 /* if we end up here means we have a regular desktop app and
543 * try to activate it */
544 ivi_set_desktop_surface(surface);
545 ivi_layout_desktop_committed(surface);
549 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
551 struct ivi_output *out;
553 wl_list_for_each(out, &ivi->outputs, link) {
554 create_black_surface_view(out);
555 insert_black_surface(out);
560 ivi_shell_init(struct ivi_compositor *ivi)
562 weston_layer_init(&ivi->hidden, ivi->compositor);
563 weston_layer_init(&ivi->background, ivi->compositor);
564 weston_layer_init(&ivi->normal, ivi->compositor);
565 weston_layer_init(&ivi->panel, ivi->compositor);
566 weston_layer_init(&ivi->popup, ivi->compositor);
567 weston_layer_init(&ivi->fullscreen, ivi->compositor);
569 weston_layer_set_position(&ivi->hidden,
570 WESTON_LAYER_POSITION_HIDDEN);
571 weston_layer_set_position(&ivi->background,
572 WESTON_LAYER_POSITION_BACKGROUND);
573 weston_layer_set_position(&ivi->normal,
574 WESTON_LAYER_POSITION_NORMAL);
575 weston_layer_set_position(&ivi->panel,
576 WESTON_LAYER_POSITION_UI);
577 weston_layer_set_position(&ivi->popup,
578 WESTON_LAYER_POSITION_TOP_UI);
579 weston_layer_set_position(&ivi->fullscreen,
580 WESTON_LAYER_POSITION_FULLSCREEN);
586 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
588 struct ivi_surface *surface;
590 wl_list_for_each(surface, &ivi->surfaces, link) {
592 weston_desktop_surface_get_app_id(surface->dsurface);
593 if (app_id == NULL) {
594 weston_log("WARNING app_is is null, unable to advertise\n");
597 agl_shell_desktop_send_application(resource, app_id);
602 client_exec(const char *command, int fd)
607 /* Don't give the child our signal mask */
609 sigprocmask(SIG_UNBLOCK, &sig, NULL);
611 /* Launch clients as the user; don't give them the wrong euid */
612 if (seteuid(getuid()) == -1) {
613 weston_log("seteuid failed: %s\n", strerror(errno));
617 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
618 * clobbering fd, as we'll exit/exec either way.
622 weston_log("dup failed: %s\n", strerror(errno));
626 snprintf(s, sizeof s, "%d", fd);
627 setenv("WAYLAND_SOCKET", s, 1);
629 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
630 weston_log("executing '%s' failed: %s", command, strerror(errno));
633 static struct wl_client *
634 launch_shell_client(struct ivi_compositor *ivi, const char *command)
636 struct wl_client *client;
640 weston_log("launching' %s'\n", command);
642 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
643 weston_log("socketpair failed while launching '%s': %s\n",
644 command, strerror(errno));
652 weston_log("fork failed while launching '%s': %s\n",
653 command, strerror(errno));
658 client_exec(command, sock[1]);
663 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
666 weston_log("Failed to create wayland client for '%s'",
675 ivi_launch_shell_client(struct ivi_compositor *ivi)
677 struct weston_config_section *section;
678 char *command = NULL;
680 section = weston_config_get_section(ivi->config, "shell-client",
683 weston_config_section_get_string(section, "command",
689 ivi->shell_client.client = launch_shell_client(ivi, command);
690 if (!ivi->shell_client.client)
697 destroy_black_view(struct wl_listener *listener, void *data)
699 struct fullscreen_view *fs =
700 wl_container_of(listener, fs, fs_destroy);
704 wl_list_remove(&fs->fs_destroy.link);
711 create_black_surface_view(struct ivi_output *output)
713 struct weston_surface *surface = NULL;
714 struct weston_view *view;
715 struct ivi_compositor *ivi = output->ivi;
716 struct weston_compositor *wc= ivi->compositor;
717 struct weston_output *woutput = output->output;
722 surface = weston_surface_create(wc);
723 view = weston_view_create(surface);
725 assert(view || surface);
727 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
728 weston_surface_set_size(surface, woutput->width, woutput->height);
729 weston_view_set_position(view, woutput->x, woutput->y);
731 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
732 output->fullscreen_view.fs->view = view;
734 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
735 wl_signal_add(&woutput->destroy_signal,
736 &output->fullscreen_view.fs_destroy);
740 remove_black_surface(struct ivi_output *output)
742 struct weston_view *view;
745 !output->fullscreen_view.fs &&
746 !output->fullscreen_view.fs->view) {
747 weston_log("Output %s doesn't have a surface installed!\n", output->name);
751 view = output->fullscreen_view.fs->view;
752 assert(view->is_mapped == true ||
753 view->surface->is_mapped == true);
755 view->is_mapped = false;
756 view->surface->is_mapped = false;
758 weston_layer_entry_remove(&view->layer_link);
759 weston_view_update_transform(view);
761 weston_view_damage_below(view);
765 insert_black_surface(struct ivi_output *output)
767 struct weston_view *view;
770 !output->fullscreen_view.fs &&
771 !output->fullscreen_view.fs->view) || !output->output) {
772 weston_log("Output %s doesn't have a surface installed!\n", output->name);
776 view = output->fullscreen_view.fs->view;
777 if (view->is_mapped || view->surface->is_mapped)
780 weston_layer_entry_remove(&view->layer_link);
781 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
784 view->is_mapped = true;
785 view->surface->is_mapped = true;
787 weston_view_update_transform(view);
788 weston_view_damage_below(view);
792 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
794 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
795 struct ivi_output *output;
796 struct ivi_surface *surface, *tmp;
798 /* Init already finished. Do nothing */
799 if (ivi->shell_client.ready)
802 ivi->shell_client.ready = true;
804 wl_list_for_each(output, &ivi->outputs, link) {
805 if (output->background)
806 remove_black_surface(output);
807 ivi_layout_init(ivi, output);
810 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
811 wl_list_remove(&surface->link);
812 wl_list_init(&surface->link);
813 ivi_check_pending_desktop_surface(surface);
814 surface->checked_pending = true;
819 shell_set_background(struct wl_client *client,
820 struct wl_resource *shell_res,
821 struct wl_resource *surface_res,
822 struct wl_resource *output_res)
824 struct weston_head *head = weston_head_from_resource(output_res);
825 struct weston_output *woutput = weston_head_get_output(head);
826 struct ivi_output *output = to_ivi_output(woutput);
827 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
828 struct weston_desktop_surface *dsurface;
829 struct ivi_surface *surface;
831 dsurface = weston_surface_get_desktop_surface(wsurface);
833 wl_resource_post_error(shell_res,
834 AGL_SHELL_ERROR_INVALID_ARGUMENT,
835 "surface must be a desktop surface");
839 surface = weston_desktop_surface_get_user_data(dsurface);
840 if (surface->role != IVI_SURFACE_ROLE_NONE) {
841 wl_resource_post_error(shell_res,
842 AGL_SHELL_ERROR_INVALID_ARGUMENT,
843 "surface already has another ivi role");
847 if (output->background) {
848 wl_resource_post_error(shell_res,
849 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
850 "output already has background");
854 surface->checked_pending = true;
855 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
856 surface->bg.output = output;
857 wl_list_remove(&surface->link);
858 wl_list_init(&surface->link);
860 output->background = surface;
862 weston_desktop_surface_set_maximized(dsurface, true);
863 weston_desktop_surface_set_size(dsurface,
864 output->output->width,
865 output->output->height);
869 shell_set_panel(struct wl_client *client,
870 struct wl_resource *shell_res,
871 struct wl_resource *surface_res,
872 struct wl_resource *output_res,
875 struct weston_head *head = weston_head_from_resource(output_res);
876 struct weston_output *woutput = weston_head_get_output(head);
877 struct ivi_output *output = to_ivi_output(woutput);
878 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
879 struct weston_desktop_surface *dsurface;
880 struct ivi_surface *surface;
881 struct ivi_surface **member;
882 int32_t width = 0, height = 0;
884 dsurface = weston_surface_get_desktop_surface(wsurface);
886 wl_resource_post_error(shell_res,
887 AGL_SHELL_ERROR_INVALID_ARGUMENT,
888 "surface must be a desktop surface");
892 surface = weston_desktop_surface_get_user_data(dsurface);
893 if (surface->role != IVI_SURFACE_ROLE_NONE) {
894 wl_resource_post_error(shell_res,
895 AGL_SHELL_ERROR_INVALID_ARGUMENT,
896 "surface already has another ivi role");
901 case AGL_SHELL_EDGE_TOP:
902 member = &output->top;
904 case AGL_SHELL_EDGE_BOTTOM:
905 member = &output->bottom;
907 case AGL_SHELL_EDGE_LEFT:
908 member = &output->left;
910 case AGL_SHELL_EDGE_RIGHT:
911 member = &output->right;
914 wl_resource_post_error(shell_res,
915 AGL_SHELL_ERROR_INVALID_ARGUMENT,
916 "invalid edge for panel");
921 wl_resource_post_error(shell_res,
922 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
923 "output already has panel on this edge");
927 surface->checked_pending = true;
928 surface->role = IVI_SURFACE_ROLE_PANEL;
929 surface->panel.output = output;
930 surface->panel.edge = edge;
931 wl_list_remove(&surface->link);
932 wl_list_init(&surface->link);
936 switch (surface->panel.edge) {
937 case AGL_SHELL_EDGE_TOP:
938 case AGL_SHELL_EDGE_BOTTOM:
939 width = woutput->width;
941 case AGL_SHELL_EDGE_LEFT:
942 case AGL_SHELL_EDGE_RIGHT:
943 height = woutput->height;
947 weston_desktop_surface_set_size(dsurface, width, height);
951 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
952 const char *data, uint32_t app_state)
954 struct desktop_client *dclient;
956 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
957 struct ivi_policy *policy = ivi->policy;
959 /* FIXME: should queue it here and see when binding agl-shell-desktop
960 * if there are any to be sent */
967 if (policy && policy->api.surface_advertise_state_change &&
968 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
972 app_role = surf->role;
973 if (app_role == IVI_SURFACE_ROLE_POPUP)
974 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
976 wl_list_for_each(dclient, &ivi->desktop_clients, link)
977 agl_shell_desktop_send_state_app(dclient->resource, app_id,
978 data, app_state, app_role);
982 shell_activate_app(struct wl_client *client,
983 struct wl_resource *shell_res,
985 struct wl_resource *output_res)
987 struct weston_head *head = weston_head_from_resource(output_res);
988 struct weston_output *woutput = weston_head_get_output(head);
989 struct ivi_output *output = to_ivi_output(woutput);
991 ivi_layout_activate(output, app_id);
995 shell_desktop_activate_app(struct wl_client *client,
996 struct wl_resource *shell_res,
997 const char *app_id, const char *data,
998 struct wl_resource *output_res)
1000 struct weston_head *head = weston_head_from_resource(output_res);
1001 struct weston_output *woutput = weston_head_get_output(head);
1002 struct ivi_output *output = to_ivi_output(woutput);
1004 ivi_layout_activate(output, app_id);
1005 shell_advertise_app_state(output->ivi, app_id,
1006 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1010 shell_deactivate_app(struct wl_client *client,
1011 struct wl_resource *shell_res,
1014 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1015 struct ivi_compositor *ivi = dclient->ivi;
1017 ivi_layout_deactivate(ivi, app_id);
1018 shell_advertise_app_state(ivi, app_id,
1019 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1022 static const struct agl_shell_interface agl_shell_implementation = {
1023 .ready = shell_ready,
1024 .set_background = shell_set_background,
1025 .set_panel = shell_set_panel,
1026 .activate_app = shell_activate_app,
1030 shell_desktop_set_app_property(struct wl_client *client,
1031 struct wl_resource *shell_res,
1032 const char *app_id, uint32_t role,
1033 int x, int y, int bx, int by,
1034 int width, int height,
1035 struct wl_resource *output_res)
1037 struct weston_head *head = weston_head_from_resource(output_res);
1038 struct weston_output *woutput = weston_head_get_output(head);
1039 struct ivi_output *output = to_ivi_output(woutput);
1042 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1043 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1044 width, height, app_id);
1046 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1047 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1049 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1050 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1051 ivi_set_pending_desktop_surface_split(output, app_id, role);
1053 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1054 ivi_set_pending_desktop_surface_remote(output, app_id);
1061 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1062 .activate_app = shell_desktop_activate_app,
1063 .set_app_property = shell_desktop_set_app_property,
1064 .deactivate_app = shell_deactivate_app,
1068 unbind_agl_shell(struct wl_resource *resource)
1070 struct ivi_compositor *ivi;
1071 struct ivi_output *output;
1072 struct ivi_surface *surf, *surf_tmp;
1074 ivi = wl_resource_get_user_data(resource);
1075 wl_list_for_each(output, &ivi->outputs, link) {
1076 /* reset the active surf if there's one present */
1077 if (output->active) {
1078 output->active->view->is_mapped = false;
1079 output->active->view->surface->is_mapped = false;
1081 weston_layer_entry_remove(&output->active->view->layer_link);
1082 output->active = NULL;
1085 insert_black_surface(output);
1088 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1089 wl_list_remove(&surf->link);
1090 wl_list_init(&surf->link);
1093 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1094 wl_list_remove(&surf->link);
1095 wl_list_init(&surf->link);
1098 wl_list_init(&ivi->surfaces);
1099 wl_list_init(&ivi->pending_surfaces);
1101 ivi->shell_client.ready = false;
1102 ivi->shell_client.resource = NULL;
1103 ivi->shell_client.client = NULL;
1107 bind_agl_shell(struct wl_client *client,
1108 void *data, uint32_t version, uint32_t id)
1110 struct ivi_compositor *ivi = data;
1111 struct wl_resource *resource;
1112 struct ivi_policy *policy;
1115 policy = ivi->policy;
1116 interface = (void *) &agl_shell_interface;
1117 if (policy && policy->api.shell_bind_interface &&
1118 !policy->api.shell_bind_interface(client, interface)) {
1119 wl_client_post_implementation_error(client,
1120 "client not authorized to use agl_shell");
1124 resource = wl_resource_create(client, &agl_shell_interface,
1127 wl_client_post_no_memory(client);
1132 if (ivi->shell_client.client != client) {
1133 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1134 "client not authorized to use agl_shell");
1139 if (ivi->shell_client.resource) {
1140 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1141 "agl_shell has already been bound");
1145 wl_resource_set_implementation(resource, &agl_shell_implementation,
1146 ivi, unbind_agl_shell);
1147 ivi->shell_client.resource = resource;
1151 unbind_agl_shell_desktop(struct wl_resource *resource)
1153 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1155 wl_list_remove(&dclient->link);
1160 bind_agl_shell_desktop(struct wl_client *client,
1161 void *data, uint32_t version, uint32_t id)
1163 struct ivi_compositor *ivi = data;
1164 struct wl_resource *resource;
1165 struct ivi_policy *policy;
1166 struct desktop_client *dclient;
1169 policy = ivi->policy;
1170 interface = (void *) &agl_shell_desktop_interface;
1171 if (policy && policy->api.shell_bind_interface &&
1172 !policy->api.shell_bind_interface(client, interface)) {
1173 wl_client_post_implementation_error(client,
1174 "client not authorized to use agl_shell_desktop");
1178 dclient = zalloc(sizeof(*dclient));
1180 wl_client_post_no_memory(client);
1184 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1188 wl_client_post_no_memory(client);
1192 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1193 dclient, unbind_agl_shell_desktop);
1195 dclient->resource = resource;
1196 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1198 /* advertise xdg surfaces */
1199 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1203 ivi_shell_create_global(struct ivi_compositor *ivi)
1205 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1206 &agl_shell_interface, 1,
1207 ivi, bind_agl_shell);
1208 if (!ivi->agl_shell) {
1209 weston_log("Failed to create wayland global.\n");
1213 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1214 &agl_shell_desktop_interface, 1,
1215 ivi, bind_agl_shell_desktop);
1216 if (!ivi->agl_shell_desktop) {
1217 weston_log("Failed to create wayland global (agl_shell_desktop).\n");