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;
58 if (surface->advertised_on_launch)
61 /* advertise to all desktop clients the new surface */
62 wl_list_for_each(dclient, &ivi->desktop_clients, link) {
64 weston_desktop_surface_get_app_id(surface->dsurface);
66 weston_log("WARNING app_is is null, unable to advertise\n");
69 agl_shell_desktop_send_application(dclient->resource, app_id);
70 surface->advertised_on_launch = true;
75 ivi_set_desktop_surface(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_DESKTOP;
81 wl_list_insert(&surface->ivi->surfaces, &surface->link);
83 agl_shell_desktop_advertise_application_id(ivi, surface);
87 ivi_set_desktop_surface_popup(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_POPUP;
93 wl_list_insert(&ivi->surfaces, &surface->link);
95 agl_shell_desktop_advertise_application_id(ivi, surface);
99 ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
101 struct ivi_compositor *ivi = surface->ivi;
102 assert(surface->role == IVI_SURFACE_ROLE_NONE);
104 surface->role = IVI_SURFACE_ROLE_FULLSCREEN;
105 wl_list_insert(&ivi->surfaces, &surface->link);
107 agl_shell_desktop_advertise_application_id(ivi, surface);
111 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
113 struct ivi_compositor *ivi = surface->ivi;
114 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
115 struct weston_transmitter *transmitter;
116 struct weston_transmitter_remote *trans_remote;
117 struct weston_surface *weston_surface;
118 struct weston_output *woutput = surface->remote.output->output;
124 transmitter = api->transmitter_get(ivi->compositor);
128 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
130 weston_log("Could not find a valie weston_transmitter_remote "
131 "that matches the output %s\n", woutput->name);
135 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
137 weston_desktop_surface_get_surface(surface->dsurface);
139 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
141 /* this will have the effect of informing the remote side to create a
142 * surface with the name app_id. W/ xdg-shell the following happens:
144 * compositor (server):
145 * surface_push_to_remote():
146 * waltham-transmitter plug-in
147 * -> wthp_ivi_app_id_surface_create()
149 * client -- on the receiver side:
150 * -> wthp_ivi_app_id_surface_create()
151 * -> wth_receiver_weston_main()
152 * -> wl_compositor_create_surface()
153 * -> xdg_wm_base_get_xdg_surface
154 * -> xdg_toplevel_set_app_id()
156 * -> gst_parse_launch()
158 * wth_receiver_weston_main() will be invoked from the handler of
159 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
160 * the gstreamer pipeline as well.
162 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
166 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
168 struct ivi_compositor *ivi = surface->ivi;
169 struct weston_view *view;
170 struct ivi_output *output = surface->remote.output;
172 assert(surface->role == IVI_SURFACE_ROLE_NONE);
174 /* remote type are the same as desktop just that client can tell
175 * the compositor to start on another output */
176 surface->role = IVI_SURFACE_ROLE_REMOTE;
178 /* if thew black surface view is mapped on the mean we need
179 * to remove it in order to start showing the 'remote' surface
180 * just being added */
181 view = output->fullscreen_view.fs->view;
182 if (view->is_mapped || view->surface->is_mapped)
183 remove_black_surface(output);
185 if (output->type == OUTPUT_WALTHAM)
186 ivi_output_notify_waltham_plugin(surface);
188 wl_list_insert(&ivi->surfaces, &surface->link);
193 ivi_set_desktop_surface_split(struct ivi_surface *surface)
195 struct ivi_compositor *ivi = surface->ivi;
196 assert(surface->role == IVI_SURFACE_ROLE_NONE);
198 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
199 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
201 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
203 wl_list_insert(&ivi->surfaces, &surface->link);
205 agl_shell_desktop_advertise_application_id(ivi, surface);
209 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
210 int x, int y, int bx, int by, int width, int height,
213 struct ivi_compositor *ivi = ioutput->ivi;
214 size_t len_app_id = strlen(app_id);
216 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
218 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
219 memcpy(p_popup->app_id, app_id, len_app_id);
220 p_popup->ioutput = ioutput;
226 p_popup->bb.width = width;
227 p_popup->bb.height = height;
229 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
233 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
236 struct ivi_compositor *ivi = ioutput->ivi;
237 size_t len_app_id = strlen(app_id);
239 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
241 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
242 memcpy(fs->app_id, app_id, len_app_id);
244 fs->ioutput = ioutput;
246 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
250 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
251 const char *app_id, uint32_t orientation)
253 struct ivi_compositor *ivi = ioutput->ivi;
254 struct ivi_surface *surf;
255 size_t len_app_id = strlen(app_id);
256 struct pending_split *split;
258 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
259 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
262 /* more than one is un-supported, do note we need to do
263 * conversion for surface roles instead of using the protocol ones */
264 wl_list_for_each(surf, &ivi->surfaces, link)
265 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
266 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
269 split = zalloc(sizeof(*split));
270 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
271 memcpy(split->app_id, app_id, len_app_id);
273 split->ioutput = ioutput;
274 split->orientation = orientation;
276 wl_list_insert(&ivi->split_pending_apps, &split->link);
280 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
283 struct ivi_compositor *ivi = ioutput->ivi;
284 size_t len_app_id = strlen(app_id);
286 struct pending_remote *remote = zalloc(sizeof(*remote));
288 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
289 memcpy(remote->app_id, app_id, len_app_id);
291 remote->ioutput = ioutput;
293 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
298 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
301 wl_list_remove(&split->link);
306 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
309 wl_list_remove(&fs->link);
314 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
316 free(p_popup->app_id);
317 wl_list_remove(&p_popup->link);
322 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
324 free(remote->app_id);
325 wl_list_remove(&remote->link);
330 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
332 struct ivi_compositor *ivi = surface->ivi;
333 struct pending_popup *p_popup, *next_p_popup;
334 const char *_app_id =
335 weston_desktop_surface_get_app_id(surface->dsurface);
337 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
340 wl_list_for_each_safe(p_popup, next_p_popup,
341 &ivi->popup_pending_apps, link) {
342 if (!strcmp(_app_id, p_popup->app_id)) {
343 surface->popup.output = p_popup->ioutput;
344 surface->popup.x = p_popup->x;
345 surface->popup.y = p_popup->y;
347 surface->popup.bb.x = p_popup->bb.x;
348 surface->popup.bb.y = p_popup->bb.y;
349 surface->popup.bb.width = p_popup->bb.width;
350 surface->popup.bb.height = p_popup->bb.height;
352 ivi_remove_pending_desktop_surface_popup(p_popup);
361 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
363 struct pending_split *split_surf, *next_split_surf;
364 struct ivi_compositor *ivi = surface->ivi;
365 const char *_app_id =
366 weston_desktop_surface_get_app_id(surface->dsurface);
368 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
371 wl_list_for_each_safe(split_surf, next_split_surf,
372 &ivi->split_pending_apps, link) {
373 if (!strcmp(_app_id, split_surf->app_id)) {
374 surface->split.output = split_surf->ioutput;
375 surface->split.orientation = split_surf->orientation;
376 ivi_remove_pending_desktop_surface_split(split_surf);
385 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
387 struct pending_fullscreen *fs_surf, *next_fs_surf;
388 struct ivi_compositor *ivi = surface->ivi;
389 const char *_app_id =
390 weston_desktop_surface_get_app_id(surface->dsurface);
392 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
395 wl_list_for_each_safe(fs_surf, next_fs_surf,
396 &ivi->fullscreen_pending_apps, link) {
397 if (!strcmp(_app_id, fs_surf->app_id)) {
398 surface->fullscreen.output = fs_surf->ioutput;
399 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
408 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
410 struct pending_remote *remote_surf, *next_remote_surf;
411 struct ivi_compositor *ivi = surface->ivi;
412 const char *_app_id =
413 weston_desktop_surface_get_app_id(surface->dsurface);
415 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
418 wl_list_for_each_safe(remote_surf, next_remote_surf,
419 &ivi->remote_pending_apps, link) {
420 if (!strcmp(_app_id, remote_surf->app_id)) {
421 surface->remote.output = remote_surf->ioutput;
422 ivi_remove_pending_desktop_surface_remote(remote_surf);
432 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
436 ret = ivi_check_pending_desktop_surface_popup(surface);
438 ivi_set_desktop_surface_popup(surface);
439 ivi_layout_popup_committed(surface);
443 ret = ivi_check_pending_desktop_surface_split(surface);
445 ivi_set_desktop_surface_split(surface);
446 ivi_layout_split_committed(surface);
450 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
452 ivi_set_desktop_surface_fullscreen(surface);
453 ivi_layout_fullscreen_committed(surface);
457 ret = ivi_check_pending_desktop_surface_remote(surface);
459 ivi_set_desktop_surface_remote(surface);
460 ivi_layout_desktop_committed(surface);
464 /* if we end up here means we have a regular desktop app and
465 * try to activate it */
466 ivi_set_desktop_surface(surface);
467 ivi_layout_desktop_committed(surface);
471 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
473 struct ivi_output *out;
475 wl_list_for_each(out, &ivi->outputs, link) {
476 create_black_surface_view(out);
477 insert_black_surface(out);
482 ivi_shell_init(struct ivi_compositor *ivi)
484 weston_layer_init(&ivi->hidden, ivi->compositor);
485 weston_layer_init(&ivi->background, ivi->compositor);
486 weston_layer_init(&ivi->normal, ivi->compositor);
487 weston_layer_init(&ivi->panel, ivi->compositor);
488 weston_layer_init(&ivi->popup, ivi->compositor);
489 weston_layer_init(&ivi->fullscreen, ivi->compositor);
491 weston_layer_set_position(&ivi->hidden,
492 WESTON_LAYER_POSITION_HIDDEN);
493 weston_layer_set_position(&ivi->background,
494 WESTON_LAYER_POSITION_BACKGROUND);
495 weston_layer_set_position(&ivi->normal,
496 WESTON_LAYER_POSITION_NORMAL);
497 weston_layer_set_position(&ivi->panel,
498 WESTON_LAYER_POSITION_UI);
499 weston_layer_set_position(&ivi->popup,
500 WESTON_LAYER_POSITION_TOP_UI);
501 weston_layer_set_position(&ivi->fullscreen,
502 WESTON_LAYER_POSITION_FULLSCREEN);
508 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
510 struct ivi_surface *surface;
512 wl_list_for_each(surface, &ivi->surfaces, link) {
514 weston_desktop_surface_get_app_id(surface->dsurface);
515 if (app_id == NULL) {
516 weston_log("WARNING app_is is null, unable to advertise\n");
519 agl_shell_desktop_send_application(resource, app_id);
524 client_exec(const char *command, int fd)
529 /* Don't give the child our signal mask */
531 sigprocmask(SIG_UNBLOCK, &sig, NULL);
533 /* Launch clients as the user; don't give them the wrong euid */
534 if (seteuid(getuid()) == -1) {
535 weston_log("seteuid failed: %s\n", strerror(errno));
539 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
540 * clobbering fd, as we'll exit/exec either way.
544 weston_log("dup failed: %s\n", strerror(errno));
548 snprintf(s, sizeof s, "%d", fd);
549 setenv("WAYLAND_SOCKET", s, 1);
551 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
552 weston_log("executing '%s' failed: %s", command, strerror(errno));
555 static struct wl_client *
556 launch_shell_client(struct ivi_compositor *ivi, const char *command)
558 struct wl_client *client;
562 weston_log("launching' %s'\n", command);
564 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
565 weston_log("socketpair failed while launching '%s': %s\n",
566 command, strerror(errno));
574 weston_log("fork failed while launching '%s': %s\n",
575 command, strerror(errno));
580 client_exec(command, sock[1]);
585 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
588 weston_log("Failed to create wayland client for '%s'",
597 ivi_launch_shell_client(struct ivi_compositor *ivi)
599 struct weston_config_section *section;
600 char *command = NULL;
602 section = weston_config_get_section(ivi->config, "shell-client",
605 weston_config_section_get_string(section, "command",
611 ivi->shell_client.client = launch_shell_client(ivi, command);
612 if (!ivi->shell_client.client)
619 destroy_black_view(struct wl_listener *listener, void *data)
621 struct fullscreen_view *fs =
622 wl_container_of(listener, fs, fs_destroy);
626 wl_list_remove(&fs->fs_destroy.link);
633 create_black_surface_view(struct ivi_output *output)
635 struct weston_surface *surface = NULL;
636 struct weston_view *view;
637 struct ivi_compositor *ivi = output->ivi;
638 struct weston_compositor *wc= ivi->compositor;
639 struct weston_output *woutput = output->output;
644 surface = weston_surface_create(wc);
645 view = weston_view_create(surface);
647 assert(view || surface);
649 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
650 weston_surface_set_size(surface, woutput->width, woutput->height);
651 weston_view_set_position(view, woutput->x, woutput->y);
653 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
654 output->fullscreen_view.fs->view = view;
656 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
657 wl_signal_add(&woutput->destroy_signal,
658 &output->fullscreen_view.fs_destroy);
662 remove_black_surface(struct ivi_output *output)
664 struct weston_view *view;
667 !output->fullscreen_view.fs &&
668 !output->fullscreen_view.fs->view) {
669 weston_log("Output %s doesn't have a surface installed!\n", output->name);
673 view = output->fullscreen_view.fs->view;
674 assert(view->is_mapped == true ||
675 view->surface->is_mapped == true);
677 view->is_mapped = false;
678 view->surface->is_mapped = false;
680 weston_layer_entry_remove(&view->layer_link);
681 weston_view_update_transform(view);
683 weston_output_damage(output->output);
687 insert_black_surface(struct ivi_output *output)
689 struct weston_view *view;
692 !output->fullscreen_view.fs &&
693 !output->fullscreen_view.fs->view) || !output->output) {
694 weston_log("Output %s doesn't have a surface installed!\n", output->name);
698 view = output->fullscreen_view.fs->view;
699 if (view->is_mapped || view->surface->is_mapped)
702 weston_layer_entry_remove(&view->layer_link);
703 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
706 view->is_mapped = true;
707 view->surface->is_mapped = true;
709 weston_view_update_transform(view);
710 weston_output_damage(output->output);
714 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
716 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
717 struct ivi_output *output;
718 struct ivi_surface *surface, *tmp;
720 /* Init already finished. Do nothing */
721 if (ivi->shell_client.ready)
724 ivi->shell_client.ready = true;
726 wl_list_for_each(output, &ivi->outputs, link) {
727 if (output->background)
728 remove_black_surface(output);
729 ivi_layout_init(ivi, output);
732 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
733 wl_list_remove(&surface->link);
734 ivi_check_pending_desktop_surface(surface);
739 shell_set_background(struct wl_client *client,
740 struct wl_resource *shell_res,
741 struct wl_resource *surface_res,
742 struct wl_resource *output_res)
744 struct weston_head *head = weston_head_from_resource(output_res);
745 struct weston_output *woutput = weston_head_get_output(head);
746 struct ivi_output *output = to_ivi_output(woutput);
747 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
748 struct weston_desktop_surface *dsurface;
749 struct ivi_surface *surface;
751 dsurface = weston_surface_get_desktop_surface(wsurface);
753 wl_resource_post_error(shell_res,
754 AGL_SHELL_ERROR_INVALID_ARGUMENT,
755 "surface must be a desktop surface");
759 surface = weston_desktop_surface_get_user_data(dsurface);
760 if (surface->role != IVI_SURFACE_ROLE_NONE) {
761 wl_resource_post_error(shell_res,
762 AGL_SHELL_ERROR_INVALID_ARGUMENT,
763 "surface already has another ivi role");
767 if (output->background) {
768 wl_resource_post_error(shell_res,
769 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
770 "output already has background");
774 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
775 surface->bg.output = output;
776 wl_list_remove(&surface->link);
777 wl_list_init(&surface->link);
779 output->background = surface;
781 weston_desktop_surface_set_maximized(dsurface, true);
782 weston_desktop_surface_set_size(dsurface,
783 output->output->width,
784 output->output->height);
788 shell_set_panel(struct wl_client *client,
789 struct wl_resource *shell_res,
790 struct wl_resource *surface_res,
791 struct wl_resource *output_res,
794 struct weston_head *head = weston_head_from_resource(output_res);
795 struct weston_output *woutput = weston_head_get_output(head);
796 struct ivi_output *output = to_ivi_output(woutput);
797 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
798 struct weston_desktop_surface *dsurface;
799 struct ivi_surface *surface;
800 struct ivi_surface **member;
801 int32_t width = 0, height = 0;
803 dsurface = weston_surface_get_desktop_surface(wsurface);
805 wl_resource_post_error(shell_res,
806 AGL_SHELL_ERROR_INVALID_ARGUMENT,
807 "surface must be a desktop surface");
811 surface = weston_desktop_surface_get_user_data(dsurface);
812 if (surface->role != IVI_SURFACE_ROLE_NONE) {
813 wl_resource_post_error(shell_res,
814 AGL_SHELL_ERROR_INVALID_ARGUMENT,
815 "surface already has another ivi role");
820 case AGL_SHELL_EDGE_TOP:
821 member = &output->top;
823 case AGL_SHELL_EDGE_BOTTOM:
824 member = &output->bottom;
826 case AGL_SHELL_EDGE_LEFT:
827 member = &output->left;
829 case AGL_SHELL_EDGE_RIGHT:
830 member = &output->right;
833 wl_resource_post_error(shell_res,
834 AGL_SHELL_ERROR_INVALID_ARGUMENT,
835 "invalid edge for panel");
840 wl_resource_post_error(shell_res,
841 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
842 "output already has panel on this edge");
846 surface->role = IVI_SURFACE_ROLE_PANEL;
847 surface->panel.output = output;
848 surface->panel.edge = edge;
849 wl_list_remove(&surface->link);
850 wl_list_init(&surface->link);
854 switch (surface->panel.edge) {
855 case AGL_SHELL_EDGE_TOP:
856 case AGL_SHELL_EDGE_BOTTOM:
857 width = woutput->width;
859 case AGL_SHELL_EDGE_LEFT:
860 case AGL_SHELL_EDGE_RIGHT:
861 height = woutput->height;
865 weston_desktop_surface_set_size(dsurface, width, height);
869 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
870 const char *data, uint32_t app_state)
872 struct desktop_client *dclient;
874 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
875 struct ivi_policy *policy = ivi->policy;
877 /* FIXME: should queue it here and see when binding agl-shell-desktop
878 * if there are any to be sent */
885 if (policy && policy->api.surface_advertise_state_change &&
886 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
890 app_role = surf->role;
891 if (app_role == IVI_SURFACE_ROLE_POPUP)
892 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
894 wl_list_for_each(dclient, &ivi->desktop_clients, link)
895 agl_shell_desktop_send_state_app(dclient->resource, app_id,
896 data, app_state, app_role);
900 shell_activate_app(struct wl_client *client,
901 struct wl_resource *shell_res,
903 struct wl_resource *output_res)
905 struct weston_head *head = weston_head_from_resource(output_res);
906 struct weston_output *woutput = weston_head_get_output(head);
907 struct ivi_output *output = to_ivi_output(woutput);
909 ivi_layout_activate(output, app_id);
913 shell_desktop_activate_app(struct wl_client *client,
914 struct wl_resource *shell_res,
915 const char *app_id, const char *data,
916 struct wl_resource *output_res)
918 struct weston_head *head = weston_head_from_resource(output_res);
919 struct weston_output *woutput = weston_head_get_output(head);
920 struct ivi_output *output = to_ivi_output(woutput);
922 ivi_layout_activate(output, app_id);
923 shell_advertise_app_state(output->ivi, app_id,
924 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
928 shell_deactivate_app(struct wl_client *client,
929 struct wl_resource *shell_res,
932 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
933 struct ivi_compositor *ivi = dclient->ivi;
935 ivi_layout_deactivate(ivi, app_id);
936 shell_advertise_app_state(ivi, app_id,
937 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
940 static const struct agl_shell_interface agl_shell_implementation = {
941 .ready = shell_ready,
942 .set_background = shell_set_background,
943 .set_panel = shell_set_panel,
944 .activate_app = shell_activate_app,
948 shell_desktop_set_app_property(struct wl_client *client,
949 struct wl_resource *shell_res,
950 const char *app_id, uint32_t role,
951 int x, int y, int bx, int by,
952 int width, int height,
953 struct wl_resource *output_res)
955 struct weston_head *head = weston_head_from_resource(output_res);
956 struct weston_output *woutput = weston_head_get_output(head);
957 struct ivi_output *output = to_ivi_output(woutput);
960 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
961 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
962 width, height, app_id);
964 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
965 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
967 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
968 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
969 ivi_set_pending_desktop_surface_split(output, app_id, role);
971 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
972 ivi_set_pending_desktop_surface_remote(output, app_id);
979 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
980 .activate_app = shell_desktop_activate_app,
981 .set_app_property = shell_desktop_set_app_property,
982 .deactivate_app = shell_deactivate_app,
986 unbind_agl_shell(struct wl_resource *resource)
988 struct ivi_compositor *ivi;
989 struct ivi_output *output;
990 struct ivi_surface *surf, *surf_tmp;
992 ivi = wl_resource_get_user_data(resource);
993 wl_list_for_each(output, &ivi->outputs, link) {
994 /* reset the active surf if there's one present */
995 if (output->active) {
996 output->active->view->is_mapped = false;
997 output->active->view->surface->is_mapped = false;
999 weston_layer_entry_remove(&output->active->view->layer_link);
1000 output->active = NULL;
1003 insert_black_surface(output);
1006 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1007 wl_list_remove(&surf->link);
1008 wl_list_init(&surf->link);
1011 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1012 wl_list_remove(&surf->link);
1013 wl_list_init(&surf->link);
1016 wl_list_init(&ivi->surfaces);
1017 wl_list_init(&ivi->pending_surfaces);
1019 ivi->shell_client.ready = false;
1020 ivi->shell_client.resource = NULL;
1021 ivi->shell_client.client = NULL;
1025 bind_agl_shell(struct wl_client *client,
1026 void *data, uint32_t version, uint32_t id)
1028 struct ivi_compositor *ivi = data;
1029 struct wl_resource *resource;
1030 struct ivi_policy *policy;
1033 policy = ivi->policy;
1034 interface = (void *) &agl_shell_interface;
1035 if (policy && policy->api.shell_bind_interface &&
1036 !policy->api.shell_bind_interface(client, interface)) {
1037 wl_client_post_implementation_error(client,
1038 "client not authorized to use agl_shell");
1042 resource = wl_resource_create(client, &agl_shell_interface,
1045 wl_client_post_no_memory(client);
1050 if (ivi->shell_client.client != client) {
1051 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1052 "client not authorized to use agl_shell");
1057 if (ivi->shell_client.resource) {
1058 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1059 "agl_shell has already been bound");
1063 wl_resource_set_implementation(resource, &agl_shell_implementation,
1064 ivi, unbind_agl_shell);
1065 ivi->shell_client.resource = resource;
1069 unbind_agl_shell_desktop(struct wl_resource *resource)
1071 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1073 wl_list_remove(&dclient->link);
1078 bind_agl_shell_desktop(struct wl_client *client,
1079 void *data, uint32_t version, uint32_t id)
1081 struct ivi_compositor *ivi = data;
1082 struct wl_resource *resource;
1083 struct ivi_policy *policy;
1084 struct desktop_client *dclient;
1087 policy = ivi->policy;
1088 interface = (void *) &agl_shell_desktop_interface;
1089 if (policy && policy->api.shell_bind_interface &&
1090 !policy->api.shell_bind_interface(client, interface)) {
1091 wl_client_post_implementation_error(client,
1092 "client not authorized to use agl_shell_desktop");
1096 dclient = zalloc(sizeof(*dclient));
1098 wl_client_post_no_memory(client);
1102 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1106 wl_client_post_no_memory(client);
1110 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1111 dclient, unbind_agl_shell_desktop);
1113 dclient->resource = resource;
1114 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1116 /* advertise xdg surfaces */
1117 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1121 ivi_shell_create_global(struct ivi_compositor *ivi)
1123 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1124 &agl_shell_interface, 1,
1125 ivi, bind_agl_shell);
1126 if (!ivi->agl_shell) {
1127 weston_log("Failed to create wayland global.\n");
1131 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1132 &agl_shell_desktop_interface, 1,
1133 ivi, bind_agl_shell_desktop);
1134 if (!ivi->agl_shell_desktop) {
1135 weston_log("Failed to create wayland global (agl_shell_desktop).\n");