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);
463 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
467 ret = ivi_check_pending_desktop_surface_popup(surface);
469 ivi_set_desktop_surface_popup(surface);
470 ivi_layout_popup_committed(surface);
474 ret = ivi_check_pending_desktop_surface_split(surface);
476 ivi_set_desktop_surface_split(surface);
477 ivi_layout_split_committed(surface);
481 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
483 ivi_set_desktop_surface_fullscreen(surface);
484 ivi_layout_fullscreen_committed(surface);
488 ret = ivi_check_pending_desktop_surface_remote(surface);
490 ivi_set_desktop_surface_remote(surface);
491 ivi_layout_desktop_committed(surface);
495 /* if we end up here means we have a regular desktop app and
496 * try to activate it */
497 ivi_set_desktop_surface(surface);
498 ivi_layout_desktop_committed(surface);
502 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
504 struct ivi_output *out;
506 wl_list_for_each(out, &ivi->outputs, link) {
507 create_black_surface_view(out);
508 insert_black_surface(out);
513 ivi_shell_init(struct ivi_compositor *ivi)
515 weston_layer_init(&ivi->hidden, ivi->compositor);
516 weston_layer_init(&ivi->background, ivi->compositor);
517 weston_layer_init(&ivi->normal, ivi->compositor);
518 weston_layer_init(&ivi->panel, ivi->compositor);
519 weston_layer_init(&ivi->popup, ivi->compositor);
520 weston_layer_init(&ivi->fullscreen, ivi->compositor);
522 weston_layer_set_position(&ivi->hidden,
523 WESTON_LAYER_POSITION_HIDDEN);
524 weston_layer_set_position(&ivi->background,
525 WESTON_LAYER_POSITION_BACKGROUND);
526 weston_layer_set_position(&ivi->normal,
527 WESTON_LAYER_POSITION_NORMAL);
528 weston_layer_set_position(&ivi->panel,
529 WESTON_LAYER_POSITION_UI);
530 weston_layer_set_position(&ivi->popup,
531 WESTON_LAYER_POSITION_TOP_UI);
532 weston_layer_set_position(&ivi->fullscreen,
533 WESTON_LAYER_POSITION_FULLSCREEN);
539 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
541 struct ivi_surface *surface;
543 wl_list_for_each(surface, &ivi->surfaces, link) {
545 weston_desktop_surface_get_app_id(surface->dsurface);
546 if (app_id == NULL) {
547 weston_log("WARNING app_is is null, unable to advertise\n");
550 agl_shell_desktop_send_application(resource, app_id);
555 client_exec(const char *command, int fd)
560 /* Don't give the child our signal mask */
562 sigprocmask(SIG_UNBLOCK, &sig, NULL);
564 /* Launch clients as the user; don't give them the wrong euid */
565 if (seteuid(getuid()) == -1) {
566 weston_log("seteuid failed: %s\n", strerror(errno));
570 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
571 * clobbering fd, as we'll exit/exec either way.
575 weston_log("dup failed: %s\n", strerror(errno));
579 snprintf(s, sizeof s, "%d", fd);
580 setenv("WAYLAND_SOCKET", s, 1);
582 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
583 weston_log("executing '%s' failed: %s", command, strerror(errno));
586 static struct wl_client *
587 launch_shell_client(struct ivi_compositor *ivi, const char *command)
589 struct wl_client *client;
593 weston_log("launching' %s'\n", command);
595 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
596 weston_log("socketpair failed while launching '%s': %s\n",
597 command, strerror(errno));
605 weston_log("fork failed while launching '%s': %s\n",
606 command, strerror(errno));
611 client_exec(command, sock[1]);
616 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
619 weston_log("Failed to create wayland client for '%s'",
628 ivi_launch_shell_client(struct ivi_compositor *ivi)
630 struct weston_config_section *section;
631 char *command = NULL;
633 section = weston_config_get_section(ivi->config, "shell-client",
636 weston_config_section_get_string(section, "command",
642 ivi->shell_client.client = launch_shell_client(ivi, command);
643 if (!ivi->shell_client.client)
650 destroy_black_view(struct wl_listener *listener, void *data)
652 struct fullscreen_view *fs =
653 wl_container_of(listener, fs, fs_destroy);
657 wl_list_remove(&fs->fs_destroy.link);
664 create_black_surface_view(struct ivi_output *output)
666 struct weston_surface *surface = NULL;
667 struct weston_view *view;
668 struct ivi_compositor *ivi = output->ivi;
669 struct weston_compositor *wc= ivi->compositor;
670 struct weston_output *woutput = output->output;
675 surface = weston_surface_create(wc);
676 view = weston_view_create(surface);
678 assert(view || surface);
680 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
681 weston_surface_set_size(surface, woutput->width, woutput->height);
682 weston_view_set_position(view, woutput->x, woutput->y);
684 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
685 output->fullscreen_view.fs->view = view;
687 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
688 wl_signal_add(&woutput->destroy_signal,
689 &output->fullscreen_view.fs_destroy);
693 remove_black_surface(struct ivi_output *output)
695 struct weston_view *view;
698 !output->fullscreen_view.fs &&
699 !output->fullscreen_view.fs->view) {
700 weston_log("Output %s doesn't have a surface installed!\n", output->name);
704 view = output->fullscreen_view.fs->view;
705 assert(view->is_mapped == true ||
706 view->surface->is_mapped == true);
708 view->is_mapped = false;
709 view->surface->is_mapped = false;
711 weston_layer_entry_remove(&view->layer_link);
712 weston_view_update_transform(view);
714 weston_view_damage_below(view);
718 insert_black_surface(struct ivi_output *output)
720 struct weston_view *view;
723 !output->fullscreen_view.fs &&
724 !output->fullscreen_view.fs->view) || !output->output) {
725 weston_log("Output %s doesn't have a surface installed!\n", output->name);
729 view = output->fullscreen_view.fs->view;
730 if (view->is_mapped || view->surface->is_mapped)
733 weston_layer_entry_remove(&view->layer_link);
734 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
737 view->is_mapped = true;
738 view->surface->is_mapped = true;
740 weston_view_update_transform(view);
741 weston_view_damage_below(view);
745 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
747 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
748 struct ivi_output *output;
749 struct ivi_surface *surface, *tmp;
751 /* Init already finished. Do nothing */
752 if (ivi->shell_client.ready)
755 ivi->shell_client.ready = true;
757 wl_list_for_each(output, &ivi->outputs, link) {
758 if (output->background)
759 remove_black_surface(output);
760 ivi_layout_init(ivi, output);
763 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
764 wl_list_remove(&surface->link);
765 wl_list_init(&surface->link);
766 ivi_check_pending_desktop_surface(surface);
767 surface->checked_pending = true;
772 shell_set_background(struct wl_client *client,
773 struct wl_resource *shell_res,
774 struct wl_resource *surface_res,
775 struct wl_resource *output_res)
777 struct weston_head *head = weston_head_from_resource(output_res);
778 struct weston_output *woutput = weston_head_get_output(head);
779 struct ivi_output *output = to_ivi_output(woutput);
780 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
781 struct weston_desktop_surface *dsurface;
782 struct ivi_surface *surface;
784 dsurface = weston_surface_get_desktop_surface(wsurface);
786 wl_resource_post_error(shell_res,
787 AGL_SHELL_ERROR_INVALID_ARGUMENT,
788 "surface must be a desktop surface");
792 surface = weston_desktop_surface_get_user_data(dsurface);
793 if (surface->role != IVI_SURFACE_ROLE_NONE) {
794 wl_resource_post_error(shell_res,
795 AGL_SHELL_ERROR_INVALID_ARGUMENT,
796 "surface already has another ivi role");
800 if (output->background) {
801 wl_resource_post_error(shell_res,
802 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
803 "output already has background");
807 surface->checked_pending = true;
808 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
809 surface->bg.output = output;
810 wl_list_remove(&surface->link);
811 wl_list_init(&surface->link);
813 output->background = surface;
815 weston_desktop_surface_set_maximized(dsurface, true);
816 weston_desktop_surface_set_size(dsurface,
817 output->output->width,
818 output->output->height);
822 shell_set_panel(struct wl_client *client,
823 struct wl_resource *shell_res,
824 struct wl_resource *surface_res,
825 struct wl_resource *output_res,
828 struct weston_head *head = weston_head_from_resource(output_res);
829 struct weston_output *woutput = weston_head_get_output(head);
830 struct ivi_output *output = to_ivi_output(woutput);
831 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
832 struct weston_desktop_surface *dsurface;
833 struct ivi_surface *surface;
834 struct ivi_surface **member;
835 int32_t width = 0, height = 0;
837 dsurface = weston_surface_get_desktop_surface(wsurface);
839 wl_resource_post_error(shell_res,
840 AGL_SHELL_ERROR_INVALID_ARGUMENT,
841 "surface must be a desktop surface");
845 surface = weston_desktop_surface_get_user_data(dsurface);
846 if (surface->role != IVI_SURFACE_ROLE_NONE) {
847 wl_resource_post_error(shell_res,
848 AGL_SHELL_ERROR_INVALID_ARGUMENT,
849 "surface already has another ivi role");
854 case AGL_SHELL_EDGE_TOP:
855 member = &output->top;
857 case AGL_SHELL_EDGE_BOTTOM:
858 member = &output->bottom;
860 case AGL_SHELL_EDGE_LEFT:
861 member = &output->left;
863 case AGL_SHELL_EDGE_RIGHT:
864 member = &output->right;
867 wl_resource_post_error(shell_res,
868 AGL_SHELL_ERROR_INVALID_ARGUMENT,
869 "invalid edge for panel");
874 wl_resource_post_error(shell_res,
875 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
876 "output already has panel on this edge");
880 surface->checked_pending = true;
881 surface->role = IVI_SURFACE_ROLE_PANEL;
882 surface->panel.output = output;
883 surface->panel.edge = edge;
884 wl_list_remove(&surface->link);
885 wl_list_init(&surface->link);
889 switch (surface->panel.edge) {
890 case AGL_SHELL_EDGE_TOP:
891 case AGL_SHELL_EDGE_BOTTOM:
892 width = woutput->width;
894 case AGL_SHELL_EDGE_LEFT:
895 case AGL_SHELL_EDGE_RIGHT:
896 height = woutput->height;
900 weston_desktop_surface_set_size(dsurface, width, height);
904 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
905 const char *data, uint32_t app_state)
907 struct desktop_client *dclient;
909 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
910 struct ivi_policy *policy = ivi->policy;
912 /* FIXME: should queue it here and see when binding agl-shell-desktop
913 * if there are any to be sent */
920 if (policy && policy->api.surface_advertise_state_change &&
921 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
925 app_role = surf->role;
926 if (app_role == IVI_SURFACE_ROLE_POPUP)
927 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
929 wl_list_for_each(dclient, &ivi->desktop_clients, link)
930 agl_shell_desktop_send_state_app(dclient->resource, app_id,
931 data, app_state, app_role);
935 shell_activate_app(struct wl_client *client,
936 struct wl_resource *shell_res,
938 struct wl_resource *output_res)
940 struct weston_head *head = weston_head_from_resource(output_res);
941 struct weston_output *woutput = weston_head_get_output(head);
942 struct ivi_output *output = to_ivi_output(woutput);
944 ivi_layout_activate(output, app_id);
948 shell_desktop_activate_app(struct wl_client *client,
949 struct wl_resource *shell_res,
950 const char *app_id, const char *data,
951 struct wl_resource *output_res)
953 struct weston_head *head = weston_head_from_resource(output_res);
954 struct weston_output *woutput = weston_head_get_output(head);
955 struct ivi_output *output = to_ivi_output(woutput);
957 ivi_layout_activate(output, app_id);
958 shell_advertise_app_state(output->ivi, app_id,
959 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
963 shell_deactivate_app(struct wl_client *client,
964 struct wl_resource *shell_res,
967 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
968 struct ivi_compositor *ivi = dclient->ivi;
970 ivi_layout_deactivate(ivi, app_id);
971 shell_advertise_app_state(ivi, app_id,
972 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
975 static const struct agl_shell_interface agl_shell_implementation = {
976 .ready = shell_ready,
977 .set_background = shell_set_background,
978 .set_panel = shell_set_panel,
979 .activate_app = shell_activate_app,
983 shell_desktop_set_app_property(struct wl_client *client,
984 struct wl_resource *shell_res,
985 const char *app_id, uint32_t role,
986 int x, int y, int bx, int by,
987 int width, int height,
988 struct wl_resource *output_res)
990 struct weston_head *head = weston_head_from_resource(output_res);
991 struct weston_output *woutput = weston_head_get_output(head);
992 struct ivi_output *output = to_ivi_output(woutput);
995 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
996 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
997 width, height, app_id);
999 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1000 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1002 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1003 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1004 ivi_set_pending_desktop_surface_split(output, app_id, role);
1006 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1007 ivi_set_pending_desktop_surface_remote(output, app_id);
1014 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1015 .activate_app = shell_desktop_activate_app,
1016 .set_app_property = shell_desktop_set_app_property,
1017 .deactivate_app = shell_deactivate_app,
1021 unbind_agl_shell(struct wl_resource *resource)
1023 struct ivi_compositor *ivi;
1024 struct ivi_output *output;
1025 struct ivi_surface *surf, *surf_tmp;
1027 ivi = wl_resource_get_user_data(resource);
1028 wl_list_for_each(output, &ivi->outputs, link) {
1029 /* reset the active surf if there's one present */
1030 if (output->active) {
1031 output->active->view->is_mapped = false;
1032 output->active->view->surface->is_mapped = false;
1034 weston_layer_entry_remove(&output->active->view->layer_link);
1035 output->active = NULL;
1038 insert_black_surface(output);
1041 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1042 wl_list_remove(&surf->link);
1043 wl_list_init(&surf->link);
1046 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1047 wl_list_remove(&surf->link);
1048 wl_list_init(&surf->link);
1051 wl_list_init(&ivi->surfaces);
1052 wl_list_init(&ivi->pending_surfaces);
1054 ivi->shell_client.ready = false;
1055 ivi->shell_client.resource = NULL;
1056 ivi->shell_client.client = NULL;
1060 bind_agl_shell(struct wl_client *client,
1061 void *data, uint32_t version, uint32_t id)
1063 struct ivi_compositor *ivi = data;
1064 struct wl_resource *resource;
1065 struct ivi_policy *policy;
1068 policy = ivi->policy;
1069 interface = (void *) &agl_shell_interface;
1070 if (policy && policy->api.shell_bind_interface &&
1071 !policy->api.shell_bind_interface(client, interface)) {
1072 wl_client_post_implementation_error(client,
1073 "client not authorized to use agl_shell");
1077 resource = wl_resource_create(client, &agl_shell_interface,
1080 wl_client_post_no_memory(client);
1085 if (ivi->shell_client.client != client) {
1086 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1087 "client not authorized to use agl_shell");
1092 if (ivi->shell_client.resource) {
1093 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1094 "agl_shell has already been bound");
1098 wl_resource_set_implementation(resource, &agl_shell_implementation,
1099 ivi, unbind_agl_shell);
1100 ivi->shell_client.resource = resource;
1104 unbind_agl_shell_desktop(struct wl_resource *resource)
1106 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1108 wl_list_remove(&dclient->link);
1113 bind_agl_shell_desktop(struct wl_client *client,
1114 void *data, uint32_t version, uint32_t id)
1116 struct ivi_compositor *ivi = data;
1117 struct wl_resource *resource;
1118 struct ivi_policy *policy;
1119 struct desktop_client *dclient;
1122 policy = ivi->policy;
1123 interface = (void *) &agl_shell_desktop_interface;
1124 if (policy && policy->api.shell_bind_interface &&
1125 !policy->api.shell_bind_interface(client, interface)) {
1126 wl_client_post_implementation_error(client,
1127 "client not authorized to use agl_shell_desktop");
1131 dclient = zalloc(sizeof(*dclient));
1133 wl_client_post_no_memory(client);
1137 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1141 wl_client_post_no_memory(client);
1145 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1146 dclient, unbind_agl_shell_desktop);
1148 dclient->resource = resource;
1149 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1151 /* advertise xdg surfaces */
1152 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1156 ivi_shell_create_global(struct ivi_compositor *ivi)
1158 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1159 &agl_shell_interface, 1,
1160 ivi, bind_agl_shell);
1161 if (!ivi->agl_shell) {
1162 weston_log("Failed to create wayland global.\n");
1166 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1167 &agl_shell_desktop_interface, 1,
1168 ivi, bind_agl_shell_desktop);
1169 if (!ivi->agl_shell_desktop) {
1170 weston_log("Failed to create wayland global (agl_shell_desktop).\n");