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_destroy_waltham_destroy(struct ivi_surface *surface)
113 struct ivi_compositor *ivi = surface->ivi;
114 const struct weston_transmitter_api *api =
115 ivi->waltham_transmitter_api;
120 if (surface->waltham_surface.transmitter_surface)
121 api->surface_destroy(surface->waltham_surface.transmitter_surface);
125 ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
127 struct ivi_compositor *ivi = surface->ivi;
128 const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
129 struct weston_transmitter *transmitter;
130 struct weston_transmitter_remote *trans_remote;
131 struct weston_surface *weston_surface;
132 struct weston_output *woutput = surface->remote.output->output;
138 transmitter = api->transmitter_get(ivi->compositor);
142 trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
144 weston_log("Could not find a valie weston_transmitter_remote "
145 "that matches the output %s\n", woutput->name);
149 app_id = weston_desktop_surface_get_app_id(surface->dsurface);
151 weston_desktop_surface_get_surface(surface->dsurface);
153 weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
155 /* this will have the effect of informing the remote side to create a
156 * surface with the name app_id. W/ xdg-shell the following happens:
158 * compositor (server):
159 * surface_push_to_remote():
160 * waltham-transmitter plug-in
161 * -> wthp_ivi_app_id_surface_create()
163 * client -- on the receiver side:
164 * -> wthp_ivi_app_id_surface_create()
165 * -> wth_receiver_weston_main()
166 * -> wl_compositor_create_surface()
167 * -> xdg_wm_base_get_xdg_surface
168 * -> xdg_toplevel_set_app_id()
170 * -> gst_parse_launch()
172 * wth_receiver_weston_main() will be invoked from the handler of
173 * wthp_ivi_app_id_surface_create() and is responsible for setting-up
174 * the gstreamer pipeline as well.
176 surface->waltham_surface.transmitter_surface =
177 api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
181 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
183 struct ivi_compositor *ivi = surface->ivi;
184 struct weston_view *view;
185 struct ivi_output *output = surface->remote.output;
187 assert(surface->role == IVI_SURFACE_ROLE_NONE);
189 /* remote type are the same as desktop just that client can tell
190 * the compositor to start on another output */
191 surface->role = IVI_SURFACE_ROLE_REMOTE;
193 /* if thew black surface view is mapped on the mean we need
194 * to remove it in order to start showing the 'remote' surface
195 * just being added */
196 view = output->fullscreen_view.fs->view;
197 if (view->is_mapped || view->surface->is_mapped)
198 remove_black_surface(output);
200 if (output->type == OUTPUT_WALTHAM)
201 ivi_output_notify_waltham_plugin(surface);
203 wl_list_insert(&ivi->surfaces, &surface->link);
208 ivi_set_desktop_surface_split(struct ivi_surface *surface)
210 struct ivi_compositor *ivi = surface->ivi;
211 assert(surface->role == IVI_SURFACE_ROLE_NONE);
213 if (surface->split.orientation == AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL)
214 surface->role = IVI_SURFACE_ROLE_SPLIT_V;
216 surface->role = IVI_SURFACE_ROLE_SPLIT_H;
218 wl_list_insert(&ivi->surfaces, &surface->link);
220 agl_shell_desktop_advertise_application_id(ivi, surface);
224 ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput,
225 int x, int y, int bx, int by, int width, int height,
228 struct ivi_compositor *ivi = ioutput->ivi;
229 size_t len_app_id = strlen(app_id);
231 struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
233 p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
234 memcpy(p_popup->app_id, app_id, len_app_id);
235 p_popup->ioutput = ioutput;
241 p_popup->bb.width = width;
242 p_popup->bb.height = height;
244 wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
248 ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
251 struct ivi_compositor *ivi = ioutput->ivi;
252 size_t len_app_id = strlen(app_id);
254 struct pending_fullscreen *fs = zalloc(sizeof(*fs));
256 fs->app_id = zalloc(sizeof(char) * (len_app_id + 1));
257 memcpy(fs->app_id, app_id, len_app_id);
259 fs->ioutput = ioutput;
261 wl_list_insert(&ivi->fullscreen_pending_apps, &fs->link);
265 ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
266 const char *app_id, uint32_t orientation)
268 struct ivi_compositor *ivi = ioutput->ivi;
269 struct ivi_surface *surf;
270 size_t len_app_id = strlen(app_id);
271 struct pending_split *split;
273 if (orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL &&
274 orientation != AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL)
277 /* more than one is un-supported, do note we need to do
278 * conversion for surface roles instead of using the protocol ones */
279 wl_list_for_each(surf, &ivi->surfaces, link)
280 if (surf->role == IVI_SURFACE_ROLE_SPLIT_V ||
281 surf->role == IVI_SURFACE_ROLE_SPLIT_H)
284 split = zalloc(sizeof(*split));
285 split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
286 memcpy(split->app_id, app_id, len_app_id);
288 split->ioutput = ioutput;
289 split->orientation = orientation;
291 wl_list_insert(&ivi->split_pending_apps, &split->link);
295 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
298 struct ivi_compositor *ivi = ioutput->ivi;
299 size_t len_app_id = strlen(app_id);
301 struct pending_remote *remote = zalloc(sizeof(*remote));
303 remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
304 memcpy(remote->app_id, app_id, len_app_id);
306 remote->ioutput = ioutput;
308 wl_list_insert(&ivi->remote_pending_apps, &remote->link);
313 ivi_remove_pending_desktop_surface_split(struct pending_split *split)
316 wl_list_remove(&split->link);
321 ivi_remove_pending_desktop_surface_fullscreen(struct pending_fullscreen *fs)
324 wl_list_remove(&fs->link);
329 ivi_remove_pending_desktop_surface_popup(struct pending_popup *p_popup)
331 free(p_popup->app_id);
332 wl_list_remove(&p_popup->link);
337 ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
339 free(remote->app_id);
340 wl_list_remove(&remote->link);
345 ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
347 struct ivi_compositor *ivi = surface->ivi;
348 struct pending_popup *p_popup, *next_p_popup;
349 const char *_app_id =
350 weston_desktop_surface_get_app_id(surface->dsurface);
352 if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
355 wl_list_for_each_safe(p_popup, next_p_popup,
356 &ivi->popup_pending_apps, link) {
357 if (!strcmp(_app_id, p_popup->app_id)) {
358 surface->popup.output = p_popup->ioutput;
359 surface->popup.x = p_popup->x;
360 surface->popup.y = p_popup->y;
362 surface->popup.bb.x = p_popup->bb.x;
363 surface->popup.bb.y = p_popup->bb.y;
364 surface->popup.bb.width = p_popup->bb.width;
365 surface->popup.bb.height = p_popup->bb.height;
367 ivi_remove_pending_desktop_surface_popup(p_popup);
376 ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
378 struct pending_split *split_surf, *next_split_surf;
379 struct ivi_compositor *ivi = surface->ivi;
380 const char *_app_id =
381 weston_desktop_surface_get_app_id(surface->dsurface);
383 if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
386 wl_list_for_each_safe(split_surf, next_split_surf,
387 &ivi->split_pending_apps, link) {
388 if (!strcmp(_app_id, split_surf->app_id)) {
389 surface->split.output = split_surf->ioutput;
390 surface->split.orientation = split_surf->orientation;
391 ivi_remove_pending_desktop_surface_split(split_surf);
400 ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
402 struct pending_fullscreen *fs_surf, *next_fs_surf;
403 struct ivi_compositor *ivi = surface->ivi;
404 const char *_app_id =
405 weston_desktop_surface_get_app_id(surface->dsurface);
407 if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
410 wl_list_for_each_safe(fs_surf, next_fs_surf,
411 &ivi->fullscreen_pending_apps, link) {
412 if (!strcmp(_app_id, fs_surf->app_id)) {
413 surface->fullscreen.output = fs_surf->ioutput;
414 ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
423 ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
425 struct pending_remote *remote_surf, *next_remote_surf;
426 struct ivi_compositor *ivi = surface->ivi;
427 const char *_app_id =
428 weston_desktop_surface_get_app_id(surface->dsurface);
430 if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
433 wl_list_for_each_safe(remote_surf, next_remote_surf,
434 &ivi->remote_pending_apps, link) {
435 if (!strcmp(_app_id, remote_surf->app_id)) {
436 surface->remote.output = remote_surf->ioutput;
437 ivi_remove_pending_desktop_surface_remote(remote_surf);
447 ivi_check_pending_desktop_surface(struct ivi_surface *surface)
451 ret = ivi_check_pending_desktop_surface_popup(surface);
453 ivi_set_desktop_surface_popup(surface);
454 ivi_layout_popup_committed(surface);
458 ret = ivi_check_pending_desktop_surface_split(surface);
460 ivi_set_desktop_surface_split(surface);
461 ivi_layout_split_committed(surface);
465 ret = ivi_check_pending_desktop_surface_fullscreen(surface);
467 ivi_set_desktop_surface_fullscreen(surface);
468 ivi_layout_fullscreen_committed(surface);
472 ret = ivi_check_pending_desktop_surface_remote(surface);
474 ivi_set_desktop_surface_remote(surface);
475 ivi_layout_desktop_committed(surface);
479 /* if we end up here means we have a regular desktop app and
480 * try to activate it */
481 ivi_set_desktop_surface(surface);
482 ivi_layout_desktop_committed(surface);
486 ivi_shell_init_black_fs(struct ivi_compositor *ivi)
488 struct ivi_output *out;
490 wl_list_for_each(out, &ivi->outputs, link) {
491 create_black_surface_view(out);
492 insert_black_surface(out);
497 ivi_shell_init(struct ivi_compositor *ivi)
499 weston_layer_init(&ivi->hidden, ivi->compositor);
500 weston_layer_init(&ivi->background, ivi->compositor);
501 weston_layer_init(&ivi->normal, ivi->compositor);
502 weston_layer_init(&ivi->panel, ivi->compositor);
503 weston_layer_init(&ivi->popup, ivi->compositor);
504 weston_layer_init(&ivi->fullscreen, ivi->compositor);
506 weston_layer_set_position(&ivi->hidden,
507 WESTON_LAYER_POSITION_HIDDEN);
508 weston_layer_set_position(&ivi->background,
509 WESTON_LAYER_POSITION_BACKGROUND);
510 weston_layer_set_position(&ivi->normal,
511 WESTON_LAYER_POSITION_NORMAL);
512 weston_layer_set_position(&ivi->panel,
513 WESTON_LAYER_POSITION_UI);
514 weston_layer_set_position(&ivi->popup,
515 WESTON_LAYER_POSITION_TOP_UI);
516 weston_layer_set_position(&ivi->fullscreen,
517 WESTON_LAYER_POSITION_FULLSCREEN);
523 ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
525 struct ivi_surface *surface;
527 wl_list_for_each(surface, &ivi->surfaces, link) {
529 weston_desktop_surface_get_app_id(surface->dsurface);
530 if (app_id == NULL) {
531 weston_log("WARNING app_is is null, unable to advertise\n");
534 agl_shell_desktop_send_application(resource, app_id);
539 client_exec(const char *command, int fd)
544 /* Don't give the child our signal mask */
546 sigprocmask(SIG_UNBLOCK, &sig, NULL);
548 /* Launch clients as the user; don't give them the wrong euid */
549 if (seteuid(getuid()) == -1) {
550 weston_log("seteuid failed: %s\n", strerror(errno));
554 /* Duplicate fd to unset the CLOEXEC flag. We don't need to worry about
555 * clobbering fd, as we'll exit/exec either way.
559 weston_log("dup failed: %s\n", strerror(errno));
563 snprintf(s, sizeof s, "%d", fd);
564 setenv("WAYLAND_SOCKET", s, 1);
566 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
567 weston_log("executing '%s' failed: %s", command, strerror(errno));
570 static struct wl_client *
571 launch_shell_client(struct ivi_compositor *ivi, const char *command)
573 struct wl_client *client;
577 weston_log("launching' %s'\n", command);
579 if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
580 weston_log("socketpair failed while launching '%s': %s\n",
581 command, strerror(errno));
589 weston_log("fork failed while launching '%s': %s\n",
590 command, strerror(errno));
595 client_exec(command, sock[1]);
600 client = wl_client_create(ivi->compositor->wl_display, sock[0]);
603 weston_log("Failed to create wayland client for '%s'",
612 ivi_launch_shell_client(struct ivi_compositor *ivi)
614 struct weston_config_section *section;
615 char *command = NULL;
617 section = weston_config_get_section(ivi->config, "shell-client",
620 weston_config_section_get_string(section, "command",
626 ivi->shell_client.client = launch_shell_client(ivi, command);
627 if (!ivi->shell_client.client)
634 destroy_black_view(struct wl_listener *listener, void *data)
636 struct fullscreen_view *fs =
637 wl_container_of(listener, fs, fs_destroy);
641 wl_list_remove(&fs->fs_destroy.link);
648 create_black_surface_view(struct ivi_output *output)
650 struct weston_surface *surface = NULL;
651 struct weston_view *view;
652 struct ivi_compositor *ivi = output->ivi;
653 struct weston_compositor *wc= ivi->compositor;
654 struct weston_output *woutput = output->output;
659 surface = weston_surface_create(wc);
660 view = weston_view_create(surface);
662 assert(view || surface);
664 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
665 weston_surface_set_size(surface, woutput->width, woutput->height);
666 weston_view_set_position(view, woutput->x, woutput->y);
668 output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
669 output->fullscreen_view.fs->view = view;
671 output->fullscreen_view.fs_destroy.notify = destroy_black_view;
672 wl_signal_add(&woutput->destroy_signal,
673 &output->fullscreen_view.fs_destroy);
677 remove_black_surface(struct ivi_output *output)
679 struct weston_view *view;
682 !output->fullscreen_view.fs &&
683 !output->fullscreen_view.fs->view) {
684 weston_log("Output %s doesn't have a surface installed!\n", output->name);
688 view = output->fullscreen_view.fs->view;
689 assert(view->is_mapped == true ||
690 view->surface->is_mapped == true);
692 view->is_mapped = false;
693 view->surface->is_mapped = false;
695 weston_layer_entry_remove(&view->layer_link);
696 weston_view_update_transform(view);
698 weston_output_damage(output->output);
702 insert_black_surface(struct ivi_output *output)
704 struct weston_view *view;
707 !output->fullscreen_view.fs &&
708 !output->fullscreen_view.fs->view) || !output->output) {
709 weston_log("Output %s doesn't have a surface installed!\n", output->name);
713 view = output->fullscreen_view.fs->view;
714 if (view->is_mapped || view->surface->is_mapped)
717 weston_layer_entry_remove(&view->layer_link);
718 weston_layer_entry_insert(&output->ivi->fullscreen.view_list,
721 view->is_mapped = true;
722 view->surface->is_mapped = true;
724 weston_view_update_transform(view);
725 weston_output_damage(output->output);
729 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
731 struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
732 struct ivi_output *output;
733 struct ivi_surface *surface, *tmp;
735 /* Init already finished. Do nothing */
736 if (ivi->shell_client.ready)
739 ivi->shell_client.ready = true;
741 wl_list_for_each(output, &ivi->outputs, link) {
742 if (output->background)
743 remove_black_surface(output);
744 ivi_layout_init(ivi, output);
747 wl_list_for_each_safe(surface, tmp, &ivi->pending_surfaces, link) {
748 wl_list_remove(&surface->link);
749 ivi_check_pending_desktop_surface(surface);
754 shell_set_background(struct wl_client *client,
755 struct wl_resource *shell_res,
756 struct wl_resource *surface_res,
757 struct wl_resource *output_res)
759 struct weston_head *head = weston_head_from_resource(output_res);
760 struct weston_output *woutput = weston_head_get_output(head);
761 struct ivi_output *output = to_ivi_output(woutput);
762 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
763 struct weston_desktop_surface *dsurface;
764 struct ivi_surface *surface;
766 dsurface = weston_surface_get_desktop_surface(wsurface);
768 wl_resource_post_error(shell_res,
769 AGL_SHELL_ERROR_INVALID_ARGUMENT,
770 "surface must be a desktop surface");
774 surface = weston_desktop_surface_get_user_data(dsurface);
775 if (surface->role != IVI_SURFACE_ROLE_NONE) {
776 wl_resource_post_error(shell_res,
777 AGL_SHELL_ERROR_INVALID_ARGUMENT,
778 "surface already has another ivi role");
782 if (output->background) {
783 wl_resource_post_error(shell_res,
784 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
785 "output already has background");
789 surface->role = IVI_SURFACE_ROLE_BACKGROUND;
790 surface->bg.output = output;
791 wl_list_remove(&surface->link);
792 wl_list_init(&surface->link);
794 output->background = surface;
796 weston_desktop_surface_set_maximized(dsurface, true);
797 weston_desktop_surface_set_size(dsurface,
798 output->output->width,
799 output->output->height);
803 shell_set_panel(struct wl_client *client,
804 struct wl_resource *shell_res,
805 struct wl_resource *surface_res,
806 struct wl_resource *output_res,
809 struct weston_head *head = weston_head_from_resource(output_res);
810 struct weston_output *woutput = weston_head_get_output(head);
811 struct ivi_output *output = to_ivi_output(woutput);
812 struct weston_surface *wsurface = wl_resource_get_user_data(surface_res);
813 struct weston_desktop_surface *dsurface;
814 struct ivi_surface *surface;
815 struct ivi_surface **member;
816 int32_t width = 0, height = 0;
818 dsurface = weston_surface_get_desktop_surface(wsurface);
820 wl_resource_post_error(shell_res,
821 AGL_SHELL_ERROR_INVALID_ARGUMENT,
822 "surface must be a desktop surface");
826 surface = weston_desktop_surface_get_user_data(dsurface);
827 if (surface->role != IVI_SURFACE_ROLE_NONE) {
828 wl_resource_post_error(shell_res,
829 AGL_SHELL_ERROR_INVALID_ARGUMENT,
830 "surface already has another ivi role");
835 case AGL_SHELL_EDGE_TOP:
836 member = &output->top;
838 case AGL_SHELL_EDGE_BOTTOM:
839 member = &output->bottom;
841 case AGL_SHELL_EDGE_LEFT:
842 member = &output->left;
844 case AGL_SHELL_EDGE_RIGHT:
845 member = &output->right;
848 wl_resource_post_error(shell_res,
849 AGL_SHELL_ERROR_INVALID_ARGUMENT,
850 "invalid edge for panel");
855 wl_resource_post_error(shell_res,
856 AGL_SHELL_ERROR_BACKGROUND_EXISTS,
857 "output already has panel on this edge");
861 surface->role = IVI_SURFACE_ROLE_PANEL;
862 surface->panel.output = output;
863 surface->panel.edge = edge;
864 wl_list_remove(&surface->link);
865 wl_list_init(&surface->link);
869 switch (surface->panel.edge) {
870 case AGL_SHELL_EDGE_TOP:
871 case AGL_SHELL_EDGE_BOTTOM:
872 width = woutput->width;
874 case AGL_SHELL_EDGE_LEFT:
875 case AGL_SHELL_EDGE_RIGHT:
876 height = woutput->height;
880 weston_desktop_surface_set_size(dsurface, width, height);
884 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
885 const char *data, uint32_t app_state)
887 struct desktop_client *dclient;
889 struct ivi_surface *surf = ivi_find_app(ivi, app_id);
890 struct ivi_policy *policy = ivi->policy;
892 /* FIXME: should queue it here and see when binding agl-shell-desktop
893 * if there are any to be sent */
900 if (policy && policy->api.surface_advertise_state_change &&
901 !policy->api.surface_advertise_state_change(surf, surf->ivi)) {
905 app_role = surf->role;
906 if (app_role == IVI_SURFACE_ROLE_POPUP)
907 app_role = AGL_SHELL_DESKTOP_APP_ROLE_POPUP;
909 wl_list_for_each(dclient, &ivi->desktop_clients, link)
910 agl_shell_desktop_send_state_app(dclient->resource, app_id,
911 data, app_state, app_role);
915 shell_activate_app(struct wl_client *client,
916 struct wl_resource *shell_res,
918 struct wl_resource *output_res)
920 struct weston_head *head = weston_head_from_resource(output_res);
921 struct weston_output *woutput = weston_head_get_output(head);
922 struct ivi_output *output = to_ivi_output(woutput);
924 ivi_layout_activate(output, app_id);
928 shell_desktop_activate_app(struct wl_client *client,
929 struct wl_resource *shell_res,
930 const char *app_id, const char *data,
931 struct wl_resource *output_res)
933 struct weston_head *head = weston_head_from_resource(output_res);
934 struct weston_output *woutput = weston_head_get_output(head);
935 struct ivi_output *output = to_ivi_output(woutput);
937 ivi_layout_activate(output, app_id);
938 shell_advertise_app_state(output->ivi, app_id,
939 data, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
943 shell_deactivate_app(struct wl_client *client,
944 struct wl_resource *shell_res,
947 struct desktop_client *dclient = wl_resource_get_user_data(shell_res);
948 struct ivi_compositor *ivi = dclient->ivi;
950 ivi_layout_deactivate(ivi, app_id);
951 shell_advertise_app_state(ivi, app_id,
952 NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
955 static const struct agl_shell_interface agl_shell_implementation = {
956 .ready = shell_ready,
957 .set_background = shell_set_background,
958 .set_panel = shell_set_panel,
959 .activate_app = shell_activate_app,
963 shell_desktop_set_app_property(struct wl_client *client,
964 struct wl_resource *shell_res,
965 const char *app_id, uint32_t role,
966 int x, int y, int bx, int by,
967 int width, int height,
968 struct wl_resource *output_res)
970 struct weston_head *head = weston_head_from_resource(output_res);
971 struct weston_output *woutput = weston_head_get_output(head);
972 struct ivi_output *output = to_ivi_output(woutput);
975 case AGL_SHELL_DESKTOP_APP_ROLE_POPUP:
976 ivi_set_pending_desktop_surface_popup(output, x, y, bx, by,
977 width, height, app_id);
979 case AGL_SHELL_DESKTOP_APP_ROLE_FULLSCREEN:
980 ivi_set_pending_desktop_surface_fullscreen(output, app_id);
982 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_VERTICAL:
983 case AGL_SHELL_DESKTOP_APP_ROLE_SPLIT_HORIZONTAL:
984 ivi_set_pending_desktop_surface_split(output, app_id, role);
986 case AGL_SHELL_DESKTOP_APP_ROLE_REMOTE:
987 ivi_set_pending_desktop_surface_remote(output, app_id);
994 static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
995 .activate_app = shell_desktop_activate_app,
996 .set_app_property = shell_desktop_set_app_property,
997 .deactivate_app = shell_deactivate_app,
1001 unbind_agl_shell(struct wl_resource *resource)
1003 struct ivi_compositor *ivi;
1004 struct ivi_output *output;
1005 struct ivi_surface *surf, *surf_tmp;
1007 ivi = wl_resource_get_user_data(resource);
1008 wl_list_for_each(output, &ivi->outputs, link) {
1009 /* reset the active surf if there's one present */
1010 if (output->active) {
1011 output->active->view->is_mapped = false;
1012 output->active->view->surface->is_mapped = false;
1014 weston_layer_entry_remove(&output->active->view->layer_link);
1015 output->active = NULL;
1018 insert_black_surface(output);
1021 wl_list_for_each_safe(surf, surf_tmp, &ivi->surfaces, link) {
1022 wl_list_remove(&surf->link);
1023 wl_list_init(&surf->link);
1026 wl_list_for_each_safe(surf, surf_tmp, &ivi->pending_surfaces, link) {
1027 wl_list_remove(&surf->link);
1028 wl_list_init(&surf->link);
1031 wl_list_init(&ivi->surfaces);
1032 wl_list_init(&ivi->pending_surfaces);
1034 ivi->shell_client.ready = false;
1035 ivi->shell_client.resource = NULL;
1036 ivi->shell_client.client = NULL;
1040 bind_agl_shell(struct wl_client *client,
1041 void *data, uint32_t version, uint32_t id)
1043 struct ivi_compositor *ivi = data;
1044 struct wl_resource *resource;
1045 struct ivi_policy *policy;
1048 policy = ivi->policy;
1049 interface = (void *) &agl_shell_interface;
1050 if (policy && policy->api.shell_bind_interface &&
1051 !policy->api.shell_bind_interface(client, interface)) {
1052 wl_client_post_implementation_error(client,
1053 "client not authorized to use agl_shell");
1057 resource = wl_resource_create(client, &agl_shell_interface,
1060 wl_client_post_no_memory(client);
1065 if (ivi->shell_client.client != client) {
1066 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1067 "client not authorized to use agl_shell");
1072 if (ivi->shell_client.resource) {
1073 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1074 "agl_shell has already been bound");
1078 wl_resource_set_implementation(resource, &agl_shell_implementation,
1079 ivi, unbind_agl_shell);
1080 ivi->shell_client.resource = resource;
1084 unbind_agl_shell_desktop(struct wl_resource *resource)
1086 struct desktop_client *dclient = wl_resource_get_user_data(resource);
1088 wl_list_remove(&dclient->link);
1093 bind_agl_shell_desktop(struct wl_client *client,
1094 void *data, uint32_t version, uint32_t id)
1096 struct ivi_compositor *ivi = data;
1097 struct wl_resource *resource;
1098 struct ivi_policy *policy;
1099 struct desktop_client *dclient;
1102 policy = ivi->policy;
1103 interface = (void *) &agl_shell_desktop_interface;
1104 if (policy && policy->api.shell_bind_interface &&
1105 !policy->api.shell_bind_interface(client, interface)) {
1106 wl_client_post_implementation_error(client,
1107 "client not authorized to use agl_shell_desktop");
1111 dclient = zalloc(sizeof(*dclient));
1113 wl_client_post_no_memory(client);
1117 resource = wl_resource_create(client, &agl_shell_desktop_interface,
1121 wl_client_post_no_memory(client);
1125 wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
1126 dclient, unbind_agl_shell_desktop);
1128 dclient->resource = resource;
1129 wl_list_insert(&ivi->desktop_clients, &dclient->link);
1131 /* advertise xdg surfaces */
1132 ivi_shell_advertise_xdg_surfaces(ivi, resource);
1136 ivi_shell_create_global(struct ivi_compositor *ivi)
1138 ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
1139 &agl_shell_interface, 1,
1140 ivi, bind_agl_shell);
1141 if (!ivi->agl_shell) {
1142 weston_log("Failed to create wayland global.\n");
1146 ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
1147 &agl_shell_desktop_interface, 1,
1148 ivi, bind_agl_shell_desktop);
1149 if (!ivi->agl_shell_desktop) {
1150 weston_log("Failed to create wayland global (agl_shell_desktop).\n");