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_compositor_keep_pending_surfaces(struct ivi_surface *surface)
363 return surface->ivi->keep_pending_surfaces;
367 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
369 struct ivi_compositor *ivi = surface->ivi;
370 struct pending_popup *p_popup, *next_p_popup;
371 const char *_app_id =
372 weston_desktop_surface_get_app_id(surface->dsurface);
374 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
377 wl_list_for_each_safe(p_popup, next_p_popup,
378 &ivi->popup_pending_apps, link) {
379 if (!strcmp(_app_id, p_popup->app_id)) {
380 surface->popup.output = p_popup->ioutput;
381 surface->popup.x = p_popup->x;
382 surface->popup.y = p_popup->y;
384 surface->popup.bb.x = p_popup->bb.x;
385 surface->popup.bb.y = p_popup->bb.y;
386 surface->popup.bb.width = p_popup->bb.width;
387 surface->popup.bb.height = p_popup->bb.height;
389 if (!ivi_compositor_keep_pending_surfaces(surface))
390 ivi_remove_pending_desktop_surface_popup(p_popup);
399 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
401 struct pending_split *split_surf, *next_split_surf;
402 struct ivi_compositor *ivi = surface->ivi;
403 const char *_app_id =
404 weston_desktop_surface_get_app_id(surface->dsurface);
406 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
409 wl_list_for_each_safe(split_surf, next_split_surf,
410 &ivi->split_pending_apps, link) {
411 if (!strcmp(_app_id, split_surf->app_id)) {
412 surface->split.output = split_surf->ioutput;
413 surface->split.orientation = split_surf->orientation;
414 if (!ivi_compositor_keep_pending_surfaces(surface))
415 ivi_remove_pending_desktop_surface_split(split_surf);
424 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
426 struct pending_fullscreen *fs_surf, *next_fs_surf;
427 struct ivi_compositor *ivi = surface->ivi;
428 const char *_app_id =
429 weston_desktop_surface_get_app_id(surface->dsurface);
431 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
434 wl_list_for_each_safe(fs_surf, next_fs_surf,
435 &ivi->fullscreen_pending_apps, link) {
436 if (!strcmp(_app_id, fs_surf->app_id)) {
437 surface->fullscreen.output = fs_surf->ioutput;
438 if (!ivi_compositor_keep_pending_surfaces(surface))
439 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
448 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
450 struct pending_remote *remote_surf, *next_remote_surf;
451 struct ivi_compositor *ivi = surface->ivi;
452 const char *_app_id =
453 weston_desktop_surface_get_app_id(surface->dsurface);
455 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
458 wl_list_for_each_safe(remote_surf, next_remote_surf,
459 &ivi->remote_pending_apps, link) {
460 if (!strcmp(_app_id, remote_surf->app_id)) {
461 surface->remote.output = remote_surf->ioutput;
462 if (!ivi_compositor_keep_pending_surfaces(surface))
463 ivi_remove_pending_desktop_surface_remote(remote_surf);
472 ivi_check_pending_surface(struct ivi_surface *surface)
474 struct ivi_compositor *ivi = surface->ivi;
475 struct wl_list *role_pending_list;
476 struct pending_popup *p_popup;
477 struct pending_split *p_split;
478 struct pending_fullscreen *p_fullscreen;
479 struct pending_remote *p_remote;
481 weston_desktop_surface_get_app_id(surface->dsurface);
486 role_pending_list = &ivi->popup_pending_apps;
487 wl_list_for_each(p_popup, role_pending_list, link) {
488 if (!strcmp(app_id, p_popup->app_id)) {
493 role_pending_list = &ivi->split_pending_apps;
494 wl_list_for_each(p_split, role_pending_list, link) {
495 if (!strcmp(app_id, p_split->app_id)) {
500 role_pending_list = &ivi->fullscreen_pending_apps;
501 wl_list_for_each(p_fullscreen, role_pending_list, link) {
502 if (!strcmp(app_id, p_fullscreen->app_id)) {
507 role_pending_list = &ivi->remote_pending_apps;
508 wl_list_for_each(p_remote, role_pending_list, link) {
509 if (!strcmp(app_id, p_remote->app_id)) {
514 /* else, we are a regular desktop surface */
520 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
524 ret = ivi_check_pending_desktop_surface_popup(surface);
526 ivi_set_desktop_surface_popup(surface);
527 ivi_layout_popup_committed(surface);
531 ret = ivi_check_pending_desktop_surface_split(surface);
533 ivi_set_desktop_surface_split(surface);
534 ivi_layout_split_committed(surface);
538 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
540 ivi_set_desktop_surface_fullscreen(surface);
541 ivi_layout_fullscreen_committed(surface);
545 ret = ivi_check_pending_desktop_surface_remote(surface);
547 ivi_set_desktop_surface_remote(surface);
548 ivi_layout_desktop_committed(surface);
552 /* if we end up here means we have a regular desktop app and
553 * try to activate it */
554 ivi_set_desktop_surface(surface);
555 ivi_layout_desktop_committed(surface);
559 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
561 struct ivi_output *out;
563 wl_list_for_each(out, &ivi->outputs, link) {
564 create_black_surface_view(out);
565 insert_black_surface(out);
570 ivi_shell_init(struct ivi_compositor *ivi)
572 weston_layer_init(&ivi->hidden, ivi->compositor);
573 weston_layer_init(&ivi->background, ivi->compositor);
574 weston_layer_init(&ivi->normal, ivi->compositor);
575 weston_layer_init(&ivi->panel, ivi->compositor);
576 weston_layer_init(&ivi->popup, ivi->compositor);
577 weston_layer_init(&ivi->fullscreen, ivi->compositor);
579 weston_layer_set_position(&ivi->hidden,
580 WESTON_LAYER_POSITION_HIDDEN);
581 weston_layer_set_position(&ivi->background,
582 WESTON_LAYER_POSITION_BACKGROUND);
583 weston_layer_set_position(&ivi->normal,
584 WESTON_LAYER_POSITION_NORMAL);
585 weston_layer_set_position(&ivi->panel,
586 WESTON_LAYER_POSITION_UI);
587 weston_layer_set_position(&ivi->popup,
588 WESTON_LAYER_POSITION_TOP_UI);
589 weston_layer_set_position(&ivi->fullscreen,
590 WESTON_LAYER_POSITION_FULLSCREEN);
596 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
598 struct ivi_surface *surface;
600 wl_list_for_each(surface, &ivi->surfaces, link) {
602 weston_desktop_surface_get_app_id(surface->dsurface);
603 if (app_id == NULL) {
604 weston_log("WARNING app_is is null, unable to advertise\n");
607 agl_shell_desktop_send_application(resource, app_id);
612 client_exec(const char *command, int fd)
617 /* Don't give the child our signal mask */
619 sigprocmask(SIG_UNBLOCK, &sig, NULL);
621 /* Launch clients as the user; don't give them the wrong euid */
622 if (seteuid(getuid()) == -1) {
623 weston_log("seteuid failed: %s\n", strerror(errno));
627 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
628 * clobbering fd, as we'll exit/exec either way.
632 weston_log("dup failed: %s\n", strerror(errno));
636 snprintf(s, sizeof s, "%d", fd);
637 setenv("WAYLAND_SOCKET", s, 1);
639 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
640 weston_log("executing '%s' failed: %s", command, strerror(errno));
643 static struct wl_client *
644 launch_shell_client(struct ivi_compositor *ivi, const char *command)
646 struct wl_client *client;
650 weston_log("launching' %s'\n", command);
652 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
653 weston_log("socketpair failed while launching '%s': %s\n",
654 command, strerror(errno));
662 weston_log("fork failed while launching '%s': %s\n",
663 command, strerror(errno));
668 client_exec(command, sock[1]);
673 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
676 weston_log("Failed to create wayland client for '%s'",
685 ivi_launch_shell_client(struct ivi_compositor *ivi)
687 struct weston_config_section *section;
688 char *command = NULL;
690 section = weston_config_get_section(ivi->config, "shell-client",
693 weston_config_section_get_string(section, "command",
699 ivi->shell_client.client = launch_shell_client(ivi, command);
700 if (!ivi->shell_client.client)
707 destroy_black_view(struct wl_listener *listener, void *data)
709 struct fullscreen_view *fs =
710 wl_container_of(listener, fs, fs_destroy);
714 wl_list_remove(&fs->fs_destroy.link);
721 create_black_surface_view(struct ivi_output *output)
723 struct weston_surface *surface = NULL;
724 struct weston_view *view;
725 struct ivi_compositor *ivi = output->ivi;
726 struct weston_compositor *wc= ivi->compositor;
727 struct weston_output *woutput = output->output;
732 surface = weston_surface_create(wc);
733 view = weston_view_create(surface);
735 assert(view || surface);
737 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
738 weston_surface_set_size(surface, woutput->width, woutput->height);
739 weston_view_set_position(view, woutput->x, woutput->y);
741 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
742 output->fullscreen_view.fs->view = view;
744 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
745 wl_signal_add(&woutput->destroy_signal,
746 &output->fullscreen_view.fs_destroy);
750 remove_black_surface(struct ivi_output *output)
752 struct weston_view *view;
755 !output->fullscreen_view.fs &&
756 !output->fullscreen_view.fs->view) {
757 weston_log("Output %s doesn't have a surface installed!\n", output->name);
761 view = output->fullscreen_view.fs->view;
762 assert(view->is_mapped == true ||
763 view->surface->is_mapped == true);
765 view->is_mapped = false;
766 view->surface->is_mapped = false;
768 weston_layer_entry_remove(&view->layer_link);
769 weston_view_update_transform(view);
771 weston_view_damage_below(view);
775 insert_black_surface(struct ivi_output *output)
777 struct weston_view *view;
780 !output->fullscreen_view.fs &&
781 !output->fullscreen_view.fs->view) || !output->output) {
782 weston_log("Output %s doesn't have a surface installed!\n", output->name);
786 view = output->fullscreen_view.fs->view;
787 if (view->is_mapped || view->surface->is_mapped)
790 weston_layer_entry_remove(&view->layer_link);
791 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
794 view->is_mapped = true;
795 view->surface->is_mapped = true;
797 weston_view_update_transform(view);
798 weston_view_damage_below(view);
802 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
804 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
805 struct ivi_output *output;
806 struct ivi_surface *surface, *tmp;
808 /* Init already finished. Do nothing */
809 if (ivi->shell_client.ready)
812 ivi->shell_client.ready = true;
814 wl_list_for_each(output, &ivi->outputs, link) {
815 if (output->background)
816 remove_black_surface(output);
817 ivi_layout_init(ivi, output);
820 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
821 wl_list_remove(&surface->link);
822 wl_list_init(&surface->link);
823 ivi_check_pending_desktop_surface(surface);
824 surface->checked_pending = true;
829 shell_set_background(struct wl_client *client,
830 struct wl_resource *shell_res,
831 struct wl_resource *surface_res,
832 struct wl_resource *output_res)
834 struct weston_head *head = weston_head_from_resource(output_res);
835 struct weston_output *woutput = weston_head_get_output(head);
836 struct ivi_output *output = to_ivi_output(woutput);
837 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
838 struct weston_desktop_surface *dsurface;
839 struct ivi_surface *surface;
841 dsurface = weston_surface_get_desktop_surface(wsurface);
843 wl_resource_post_error(shell_res,
844 AGL_SHELL_ERROR_INVALID_ARGUMENT,
845 "surface must be a desktop surface");
849 surface = weston_desktop_surface_get_user_data(dsurface);
850 if (surface->role != IVI_SURFACE_ROLE_NONE) {
851 wl_resource_post_error(shell_res,
852 AGL_SHELL_ERROR_INVALID_ARGUMENT,
853 "surface already has another ivi role");
857 if (output->background) {
858 wl_resource_post_error(shell_res,
859 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
860 "output already has background");
864 surface->checked_pending = true;
865 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
866 surface->bg.output = output;
867 wl_list_remove(&surface->link);
868 wl_list_init(&surface->link);
870 output->background = surface;
872 weston_desktop_surface_set_maximized(dsurface, true);
873 weston_desktop_surface_set_size(dsurface,
874 output->output->width,
875 output->output->height);
879 shell_set_panel(struct wl_client *client,
880 struct wl_resource *shell_res,
881 struct wl_resource *surface_res,
882 struct wl_resource *output_res,
885 struct weston_head *head = weston_head_from_resource(output_res);
886 struct weston_output *woutput = weston_head_get_output(head);
887 struct ivi_output *output = to_ivi_output(woutput);
888 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
889 struct weston_desktop_surface *dsurface;
890 struct ivi_surface *surface;
891 struct ivi_surface **member;
892 int32_t width = 0, height = 0;
894 dsurface = weston_surface_get_desktop_surface(wsurface);
896 wl_resource_post_error(shell_res,
897 AGL_SHELL_ERROR_INVALID_ARGUMENT,
898 "surface must be a desktop surface");
902 surface = weston_desktop_surface_get_user_data(dsurface);
903 if (surface->role != IVI_SURFACE_ROLE_NONE) {
904 wl_resource_post_error(shell_res,
905 AGL_SHELL_ERROR_INVALID_ARGUMENT,
906 "surface already has another ivi role");
911 case AGL_SHELL_EDGE_TOP:
912 member = &output->top;
914 case AGL_SHELL_EDGE_BOTTOM:
915 member = &output->bottom;
917 case AGL_SHELL_EDGE_LEFT:
918 member = &output->left;
920 case AGL_SHELL_EDGE_RIGHT:
921 member = &output->right;
924 wl_resource_post_error(shell_res,
925 AGL_SHELL_ERROR_INVALID_ARGUMENT,
926 "invalid edge for panel");
931 wl_resource_post_error(shell_res,
932 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
933 "output already has panel on this edge");
937 surface->checked_pending = true;
938 surface->role = IVI_SURFACE_ROLE_PANEL;
939 surface->panel.output = output;
940 surface->panel.edge = edge;
941 wl_list_remove(&surface->link);
942 wl_list_init(&surface->link);
946 switch (surface->panel.edge) {
947 case AGL_SHELL_EDGE_TOP:
948 case AGL_SHELL_EDGE_BOTTOM:
949 width = woutput->width;
951 case AGL_SHELL_EDGE_LEFT:
952 case AGL_SHELL_EDGE_RIGHT:
953 height = woutput->height;
957 weston_desktop_surface_set_size(dsurface, width, height);
961 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
962 const char *data, uint32_t app_state)
964 struct desktop_client *dclient;
966 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
967 struct ivi_policy *policy = ivi->policy;
969 /* FIXME: should queue it here and see when binding agl-shell-desktop
970 * if there are any to be sent */
977 if (policy && policy->api.surface_advertise_state_change &&
978 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
982 app_role = surf->role;
983 if (app_role == IVI_SURFACE_ROLE_POPUP)
984 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
986 wl_list_for_each(dclient, &ivi->desktop_clients, link)
987 agl_shell_desktop_send_state_app(dclient->resource, app_id,
988 data, app_state, app_role);
992 shell_activate_app(struct wl_client *client,
993 struct wl_resource *shell_res,
995 struct wl_resource *output_res)
997 struct weston_head *head = weston_head_from_resource(output_res);
998 struct weston_output *woutput = weston_head_get_output(head);
999 struct ivi_output *output = to_ivi_output(woutput);
1001 ivi_layout_activate(output, app_id);
1005 shell_desktop_activate_app(struct wl_client *client,
1006 struct wl_resource *shell_res,
1007 const char *app_id, const char *data,
1008 struct wl_resource *output_res)
1010 struct weston_head *head = weston_head_from_resource(output_res);
1011 struct weston_output *woutput = weston_head_get_output(head);
1012 struct ivi_output *output = to_ivi_output(woutput);
1014 ivi_layout_activate(output, app_id);
1015 shell_advertise_app_state(output->ivi, app_id,
1016 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1020 shell_deactivate_app(struct wl_client *client,
1021 struct wl_resource *shell_res,
1024 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1025 struct ivi_compositor *ivi = dclient->ivi;
1027 ivi_layout_deactivate(ivi, app_id);
1028 shell_advertise_app_state(ivi, app_id,
1029 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
1032 static const struct agl_shell_interface agl_shell_implementation = {
1033 .ready = shell_ready,
1034 .set_background = shell_set_background,
1035 .set_panel = shell_set_panel,
1036 .activate_app = shell_activate_app,
1040 shell_desktop_set_app_property(struct wl_client *client,
1041 struct wl_resource *shell_res,
1042 const char *app_id, uint32_t role,
1043 int x, int y, int bx, int by,
1044 int width, int height,
1045 struct wl_resource *output_res)
1047 struct weston_head *head = weston_head_from_resource(output_res);
1048 struct weston_output *woutput = weston_head_get_output(head);
1049 struct ivi_output *output = to_ivi_output(woutput);
1052 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
1053 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
1054 width, height, app_id);
1056 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
1057 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
1059 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
1060 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
1061 ivi_set_pending_desktop_surface_split(output, app_id, role);
1063 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
1064 ivi_set_pending_desktop_surface_remote(output, app_id);
1072 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi)
1074 struct pending_popup *p_popup, *next_p_popup;
1075 struct pending_split *split_surf, *next_split_surf;
1076 struct pending_fullscreen *fs_surf, *next_fs_surf;
1077 struct pending_remote *remote_surf, *next_remote_surf;
1079 wl_list_for_each_safe(p_popup, next_p_popup,
1080 &ivi->popup_pending_apps, link)
1081 ivi_remove_pending_desktop_surface_popup(p_popup);
1083 wl_list_for_each_safe(split_surf, next_split_surf,
1084 &ivi->split_pending_apps, link)
1085 ivi_remove_pending_desktop_surface_split(split_surf);
1087 wl_list_for_each_safe(fs_surf, next_fs_surf,
1088 &ivi->fullscreen_pending_apps, link)
1089 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
1091 wl_list_for_each_safe(remote_surf, next_remote_surf,
1092 &ivi->remote_pending_apps, link)
1093 ivi_remove_pending_desktop_surface_remote(remote_surf);
1097 shell_desktop_set_app_property_mode(struct wl_client *client,
1098 struct wl_resource *shell_res, uint32_t perm)
1100 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
1102 dclient->ivi->keep_pending_surfaces = true;
1104 dclient->ivi->keep_pending_surfaces = false;
1105 /* remove any previous pending surfaces */
1106 ivi_compositor_destroy_pending_surfaces(dclient->ivi);
1110 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
1111 .activate_app = shell_desktop_activate_app,
1112 .set_app_property = shell_desktop_set_app_property,
1113 .deactivate_app = shell_deactivate_app,
1114 .set_app_property_mode = shell_desktop_set_app_property_mode,
1118 unbind_agl_shell(struct wl_resource *resource)
1120 struct ivi_compositor *ivi;
1121 struct ivi_output *output;
1122 struct ivi_surface *surf, *surf_tmp;
1124 ivi = wl_resource_get_user_data(resource);
1125 wl_list_for_each(output, &ivi->outputs, link) {
1126 /* reset the active surf if there's one present */
1127 if (output->active) {
1128 output->active->view->is_mapped = false;
1129 output->active->view->surface->is_mapped = false;
1131 weston_layer_entry_remove(&output->active->view->layer_link);
1132 output->active = NULL;
1135 insert_black_surface(output);
1138 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1139 wl_list_remove(&surf->link);
1140 wl_list_init(&surf->link);
1143 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1144 wl_list_remove(&surf->link);
1145 wl_list_init(&surf->link);
1148 wl_list_init(&ivi->surfaces);
1149 wl_list_init(&ivi->pending_surfaces);
1151 ivi->shell_client.ready = false;
1152 ivi->shell_client.resource = NULL;
1153 ivi->shell_client.client = NULL;
1157 bind_agl_shell(struct wl_client *client,
1158 void *data, uint32_t version, uint32_t id)
1160 struct ivi_compositor *ivi = data;
1161 struct wl_resource *resource;
1162 struct ivi_policy *policy;
1165 policy = ivi->policy;
1166 interface = (void *) &agl_shell_interface;
1167 if (policy && policy->api.shell_bind_interface &&
1168 !policy->api.shell_bind_interface(client, interface)) {
1169 wl_client_post_implementation_error(client,
1170 "client not authorized to use agl_shell");
1174 resource = wl_resource_create(client, &agl_shell_interface,
1177 wl_client_post_no_memory(client);
1182 if (ivi->shell_client.client != client) {
1183 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1184 "client not authorized to use agl_shell");
1189 if (ivi->shell_client.resource) {
1190 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1191 "agl_shell has already been bound");
1195 wl_resource_set_implementation(resource, &agl_shell_implementation,
1196 ivi, unbind_agl_shell);
1197 ivi->shell_client.resource = resource;
1201 unbind_agl_shell_desktop(struct wl_resource *resource)
1203 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1205 wl_list_remove(&dclient->link);
1210 bind_agl_shell_desktop(struct wl_client *client,
1211 void *data, uint32_t version, uint32_t id)
1213 struct ivi_compositor *ivi = data;
1214 struct wl_resource *resource;
1215 struct ivi_policy *policy;
1216 struct desktop_client *dclient;
1219 policy = ivi->policy;
1220 interface = (void *) &agl_shell_desktop_interface;
1221 if (policy && policy->api.shell_bind_interface &&
1222 !policy->api.shell_bind_interface(client, interface)) {
1223 wl_client_post_implementation_error(client,
1224 "client not authorized to use agl_shell_desktop");
1228 dclient = zalloc(sizeof(*dclient));
1230 wl_client_post_no_memory(client);
1234 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1238 wl_client_post_no_memory(client);
1242 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1243 dclient, unbind_agl_shell_desktop);
1245 dclient->resource = resource;
1246 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1248 /* advertise xdg surfaces */
1249 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1253 ivi_shell_create_global(struct ivi_compositor *ivi)
1255 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1256 &agl_shell_interface, 1,
1257 ivi, bind_agl_shell);
1258 if (!ivi->agl_shell) {
1259 weston_log("Failed to create wayland global.\n");
1263 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1264 &agl_shell_desktop_interface, 2,
1265 ivi, bind_agl_shell_desktop);
1266 if (!ivi->agl_shell_desktop) {
1267 weston_log("Failed to create wayland global (agl_shell_desktop).\n");