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"
28 #include "shared/helpers.h"
33 #include <libweston/libweston.h>
34 #include <libweston-desktop/libweston-desktop.h>
36 #include "agl-shell-desktop-server-protocol.h"
38 #define AGL_COMP_DEBUG
40 static const char *ivi_roles_as_string[] = {
41 [IVI_SURFACE_ROLE_NONE] = "NONE",
42 [IVI_SURFACE_ROLE_BACKGROUND] = "BACKGROUND",
43 [IVI_SURFACE_ROLE_PANEL] = "PANEL",
44 [IVI_SURFACE_ROLE_DESKTOP] = "DESKTOP",
45 [IVI_SURFACE_ROLE_POPUP] = "POPUP",
46 [IVI_SURFACE_ROLE_SPLIT_H] = "SPLIT_H",
47 [IVI_SURFACE_ROLE_SPLIT_V] = "SPLIT_V",
48 [IVI_SURFACE_ROLE_FULLSCREEN] = "FULLSCREEN",
49 [IVI_SURFACE_ROLE_REMOTE] = "REMOTE",
53 ivi_layout_get_surface_role_name(struct ivi_surface *surf)
55 if (surf->role < 0 || surf->role >= ARRAY_LENGTH(ivi_roles_as_string))
56 return " unknown surface role";
58 return ivi_roles_as_string[surf->role];
62 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
64 struct weston_output *woutput = output->output;
65 struct ivi_surface *bg = output->background;
66 struct weston_view *view;
69 weston_log("WARNING: Output does not have a background\n");
73 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
77 weston_view_set_output(view, woutput);
78 weston_view_set_position(view, woutput->x, woutput->y);
80 weston_log("(background) position view %p, x %d, y %d, on output %s\n", view,
81 woutput->x, woutput->y, output->name);
83 view->is_mapped = true;
84 view->surface->is_mapped = true;
86 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
90 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
91 struct ivi_surface *panel)
93 struct weston_output *woutput = output->output;
94 struct weston_desktop_surface *dsurface;
95 struct weston_view *view;
96 struct weston_geometry geom;
103 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
104 dsurface = panel->dsurface;
106 geom = weston_desktop_surface_get_geometry(dsurface);
108 weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
109 geom.width, geom.height, geom.x, geom.y);
111 switch (panel->panel.edge) {
112 case AGL_SHELL_EDGE_TOP:
113 output->area.y += geom.height;
114 output->area.height -= geom.height;
116 case AGL_SHELL_EDGE_BOTTOM:
117 y += woutput->height - geom.height;
118 output->area.height -= geom.height;
120 case AGL_SHELL_EDGE_LEFT:
121 output->area.x += geom.width;
122 output->area.width -= geom.width;
124 case AGL_SHELL_EDGE_RIGHT:
125 x += woutput->width - geom.width;
126 output->area.width -= geom.width;
133 weston_view_set_output(view, woutput);
134 weston_view_set_position(view, x, y);
136 weston_log("(panel) edge %d position view %p, x %d, y %d\n",
137 panel->panel.edge, view, x, y);
139 view->is_mapped = true;
140 view->surface->is_mapped = true;
142 weston_log("panel type %d inited on output %s\n", panel->panel.edge,
145 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
149 * Initializes all static parts of the layout, i.e. the background and panels.
152 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
154 bool use_default_area = true;
156 ivi_background_init(ivi, output);
158 if (output->area_activation.width ||
159 output->area_activation.height ||
160 output->area_activation.x ||
161 output->area_activation.y) {
162 /* Sanity check target area is within output bounds */
163 if ((output->area_activation.x + output->area_activation.width) < output->output->width ||
164 (output->area_activation.y + output->area_activation.height) < output->output->height) {
165 weston_log("Using specified area for output %s, ignoring panels\n",
167 output->area.x = output->area_activation.x;
168 output->area.y = output->area_activation.y;
169 output->area.width = output->area_activation.width;
170 output->area.height = output->area_activation.height;
171 use_default_area = false;
173 weston_log("Invalid activation-area position for output %s, ignoring\n",
177 if (use_default_area) {
180 output->area.width = output->output->width;
181 output->area.height = output->output->height;
183 ivi_panel_init(ivi, output, output->top);
184 ivi_panel_init(ivi, output, output->bottom);
185 ivi_panel_init(ivi, output, output->left);
186 ivi_panel_init(ivi, output, output->right);
189 weston_compositor_schedule_repaint(ivi->compositor);
191 weston_log("Usable area: %dx%d+%d,%d\n",
192 output->area.width, output->area.height,
193 output->area.x, output->area.y);
197 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
199 struct ivi_surface *surf;
202 wl_list_for_each(surf, &ivi->surfaces, link) {
203 id = weston_desktop_surface_get_app_id(surf->dsurface);
204 if (id && strcmp(app_id, id) == 0)
212 ivi_layout_activate_complete(struct ivi_output *output,
213 struct ivi_surface *surf)
215 struct ivi_compositor *ivi = output->ivi;
216 struct weston_output *woutput = output->output;
217 struct weston_view *view = surf->view;
218 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
219 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
220 const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
222 if (weston_view_is_mapped(view)) {
223 weston_layer_entry_remove(&view->layer_link);
225 weston_view_update_transform(view);
228 if (output_has_black_curtain(output)) {
229 if (!output->background) {
230 weston_log("Found that we have no background surface "
231 "for output %s. Using black curtain as background\n",
232 output->output->name);
234 struct weston_view *ev =
235 output->fullscreen_view.fs->view;
237 /* use the black curtain as background when we have
238 * none added by the shell client. */
239 weston_layer_entry_remove(&ev->layer_link);
240 weston_layer_entry_insert(&ivi->normal.view_list,
242 weston_view_geometry_dirty(ev);
243 weston_surface_damage(ev->surface);
245 remove_black_curtain(output);
250 weston_view_set_output(view, woutput);
252 if (surf->role != IVI_SURFACE_ROLE_BACKGROUND)
253 weston_view_set_position(view,
254 woutput->x + output->area.x,
255 woutput->y + output->area.y);
257 view->is_mapped = true;
259 view->surface->is_mapped = true;
261 /* handle a movement from one output to another */
262 if (surf->current_completed_output &&
263 surf->current_completed_output != output) {
265 /* we're migrating the same surface but to another output */
266 if (surf->current_completed_output->active == surf) {
267 struct weston_view *ev =
268 surf->current_completed_output->active->view;
270 weston_layer_entry_remove(&ev->layer_link);
271 surf->current_completed_output->previous_active =
272 surf->current_completed_output->active;
273 surf->current_completed_output->active = NULL;
275 /* damage all possible outputs to avoid stale views */
276 weston_compositor_damage_all(ivi->compositor);
280 if (output->active) {
281 /* keep the background surface mapped at all times */
282 if (output->active->role != IVI_SURFACE_ROLE_BACKGROUND) {
283 output->active->view->is_mapped = false;
284 output->active->view->surface->is_mapped = false;
286 weston_layer_entry_remove(&output->active->view->layer_link);
289 output->previous_active = output->active;
290 output->active = surf;
291 surf->current_completed_output = output;
293 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
294 weston_view_geometry_dirty(view);
295 weston_surface_damage(view->surface);
298 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
301 * the 'remote' role now makes use of this part so make sure we don't
302 * trip the enum such that we might end up with a modified output for
305 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
306 if (surf->desktop.pending_output)
307 surf->desktop.last_output = surf->desktop.pending_output;
308 surf->desktop.pending_output = NULL;
311 weston_log("Activation completed for app_id %s, role %s, output %s\n",
313 ivi_layout_get_surface_role_name(surf), output->name);
315 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_ACTIVATED);
319 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
321 struct ivi_output *out;
326 wl_list_for_each(out, &ivi->outputs, link) {
330 if (!strcmp(app_id, out->app_id))
338 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
340 struct ivi_output *out;
342 wl_list_for_each(out, &ivi->outputs, link) {
343 if (out->background &&
344 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
353 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
354 struct ivi_output *ivi_output)
356 struct weston_desktop_surface *dsurf = surf->dsurface;
357 struct weston_view *ev = surf->view;
358 struct ivi_compositor *ivi = surf->ivi;
359 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
362 * If the view isn't mapped, we put it onto the hidden layer so it will
363 * start receiving frame events, and will be able to act on our
366 if (!weston_view_is_mapped(ev)) {
367 ev->is_mapped = true;
368 ev->surface->is_mapped = true;
370 weston_desktop_surface_set_maximized(dsurf, true);
371 weston_desktop_surface_set_size(dsurf,
372 ivi_output->area.width,
373 ivi_output->area.height);
375 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
376 app_id, ivi_layout_get_surface_role_name(surf),
377 ivi_output->area.width, ivi_output->area.height);
379 surf->hidden_layer_output = ivi_output;
380 weston_view_set_output(ev, ivi_output->output);
381 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
382 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
383 app_id, ivi_layout_get_surface_role_name(surf),
384 ivi_output->output->name);
386 weston_compositor_schedule_repaint(ivi->compositor);
390 /* we might have another output to activate */
391 if (surf->hidden_layer_output &&
392 surf->hidden_layer_output != ivi_output) {
393 weston_layer_entry_remove(&ev->layer_link);
395 if (ivi_output->area.width != surf->hidden_layer_output->area.width &&
396 ivi_output->area.height != surf->hidden_layer_output->area.height) {
397 weston_desktop_surface_set_maximized(dsurf, true);
398 weston_desktop_surface_set_size(dsurf,
399 ivi_output->area.width,
400 ivi_output->area.height);
403 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
404 app_id, ivi_layout_get_surface_role_name(surf),
405 ivi_output->area.width, ivi_output->area.height);
407 surf->hidden_layer_output = ivi_output;
408 weston_view_set_output(ev, ivi_output->output);
409 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
410 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
411 app_id, ivi_layout_get_surface_role_name(surf),
412 ivi_output->output->name);
415 weston_compositor_schedule_repaint(ivi->compositor);
419 ivi_layout_desktop_committed(struct ivi_surface *surf)
421 struct weston_desktop_surface *dsurf = surf->dsurface;
422 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
423 struct ivi_policy *policy = surf->ivi->policy;
424 struct ivi_output *output;
425 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
427 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP ||
428 surf->role == IVI_SURFACE_ROLE_REMOTE);
431 * we can't make use here of the ivi_layout_get_output_from_surface()
432 * due to the fact that we'll always land here when a surface performs
433 * a commit and pending_output will not bet set. This works in tandem
434 * with 'mapped' at this point to avoid tripping over
435 * to a surface that continuously updates its content
437 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
438 output = surf->desktop.pending_output;
440 output = surf->remote.output;
442 if (surf->role == IVI_SURFACE_ROLE_DESKTOP && !output) {
443 struct ivi_output *r_output;
445 if (policy && policy->api.surface_activate_by_default &&
446 !policy->api.surface_activate_by_default(surf, surf->ivi))
449 /* we can only activate it again by using the protocol */
453 /* check first if there aren't any outputs being set */
454 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
457 struct weston_view *view = r_output->fullscreen_view.fs->view;
458 if (view->is_mapped || view->surface->is_mapped)
459 remove_black_curtain(r_output);
463 /* try finding an output with a background and use that */
465 r_output = ivi_layout_find_bg_output(surf->ivi);
467 /* if we couldn't still find an output by this point, there's
468 * something wrong so we abort with a protocol error */
470 wl_resource_post_error(surf->ivi->shell_client.resource,
471 AGL_SHELL_ERROR_INVALID_ARGUMENT,
472 "No valid output found to activate surface by default");
476 if (!surf->ivi->activate_by_default) {
477 weston_log("Refusing to activate surface role %d, app_id %s\n",
480 if (!weston_desktop_surface_get_maximized(dsurf) ||
481 geom.width != r_output->area.width ||
482 geom.height != r_output->area.height)
483 ivi_layout_add_to_hidden_layer(surf, r_output);
488 /* use the output of the bg to activate the app on start-up by
490 if (surf->view && r_output) {
491 if (app_id && r_output) {
492 weston_log("Surface with app_id %s, role %s activating by default\n",
493 weston_desktop_surface_get_app_id(surf->dsurface),
494 ivi_layout_get_surface_role_name(surf));
495 ivi_layout_activate(r_output, app_id);
496 } else if (!app_id) {
498 * applications not setting an app_id, or
499 * setting an app_id but at a later point in
500 * time, might fall-back here so give them a
501 * chance to receive the configure event and
504 weston_log("Surface no app_id, role %s activating by default\n",
505 ivi_layout_get_surface_role_name(surf));
506 ivi_layout_activate_by_surf(r_output, surf);
513 if (surf->role == IVI_SURFACE_ROLE_REMOTE && output) {
514 if (policy && policy->api.surface_activate_by_default &&
515 !policy->api.surface_activate_by_default(surf, surf->ivi))
518 /* we can only activate it again by using the protocol, but
519 * additionally the output is not reset when
520 * ivi_layout_activate_complete() terminates so we use the
521 * current active surface to avoid hitting this again and again
523 if (surf->mapped && output->active == surf)
527 weston_log("Surface with app_id %s, role %s activating "
528 "by default on output %s\n",
529 weston_desktop_surface_get_app_id(surf->dsurface),
530 ivi_layout_get_surface_role_name(surf),
531 output->output->name);
532 ivi_layout_activate(output, app_id);
537 if (!weston_desktop_surface_get_maximized(dsurf) ||
538 geom.width != output->area.width ||
539 geom.height != output->area.height)
542 ivi_layout_activate_complete(output, surf);
546 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
548 struct ivi_compositor *ivi = surface->ivi;
549 struct ivi_policy *policy = ivi->policy;
551 struct weston_desktop_surface *dsurface = surface->dsurface;
552 struct weston_surface *wsurface =
553 weston_desktop_surface_get_surface(dsurface);
554 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
556 struct ivi_output *output = surface->split.output;
557 struct weston_output *woutput = output->output;
558 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
560 struct weston_view *view = surface->view;
561 struct weston_geometry geom =
562 weston_desktop_surface_get_geometry(dsurface);
564 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
565 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
567 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
569 geom.width == bg_output->output->width &&
570 geom.height == bg_output->output->height;
572 if (policy && policy->api.surface_activate_by_default &&
573 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
577 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
579 if (weston_view_is_mapped(view))
582 /* if we still get here but we haven't resized so far, send configure
584 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
585 struct ivi_output *bg_output =
586 ivi_layout_find_bg_output(surface->ivi);
588 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
589 app_id, ivi_layout_get_surface_role_name(surface));
590 weston_desktop_surface_set_fullscreen(dsurface, true);
591 weston_desktop_surface_set_size(dsurface,
592 bg_output->output->width,
593 bg_output->output->height);
595 surface->state = RESIZING;
596 weston_view_set_output(view, output->output);
597 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
601 /* eventually, we would set the surface fullscreen, but the client
602 * hasn't resized correctly by this point, so terminate connection */
603 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
604 struct weston_desktop_client *desktop_client =
605 weston_desktop_surface_get_client(dsurface);
606 struct wl_client *client =
607 weston_desktop_client_get_client(desktop_client);
608 wl_client_post_implementation_error(client,
609 "can not display surface due to invalid geometry."
610 " Client should perform a geometry resize!");
614 /* this implies we resized correctly */
615 if (!weston_view_is_mapped(view)) {
616 weston_layer_entry_remove(&view->layer_link);
618 weston_view_set_output(view, woutput);
619 weston_view_set_position(view, woutput->x, woutput->y);
620 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
622 wsurface->is_mapped = true;
623 surface->view->is_mapped = true;
624 surface->state = FULLSCREEN;
626 weston_view_geometry_dirty(view);
627 weston_surface_damage(view->surface);
630 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
632 shell_advertise_app_state(ivi, app_id,
633 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
635 weston_log("Activation completed for app_id %s, role %s, "
636 "output %s\n", app_id,
637 ivi_layout_get_surface_role_name(surface),
644 ivi_layout_desktop_resize(struct ivi_surface *surface,
645 struct weston_geometry area)
647 struct weston_desktop_surface *dsurf = surface->dsurface;
648 struct weston_view *view = surface->view;
652 int width = area.width;
653 int height = area.height;
655 weston_desktop_surface_set_size(dsurf,
658 weston_view_set_position(view, x, y);
660 weston_view_geometry_dirty(view);
661 weston_surface_damage(view->surface);
665 ivi_layout_split_committed(struct ivi_surface *surface)
667 struct ivi_compositor *ivi = surface->ivi;
668 struct ivi_policy *policy = ivi->policy;
670 struct weston_desktop_surface *dsurface = surface->dsurface;
671 struct weston_surface *wsurface =
672 weston_desktop_surface_get_surface(dsurface);
673 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
675 struct ivi_output *output = surface->split.output;
676 struct weston_output *woutput = output->output;
678 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
679 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
681 struct weston_view *view = surface->view;
682 struct weston_geometry geom;
690 if (policy && policy->api.surface_activate_by_default &&
691 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
695 if (surface->view->is_mapped)
698 geom = weston_desktop_surface_get_geometry(dsurface);
700 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
701 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
703 /* save the previous area in order to recover it back when if this kind
704 * of surface is being destroyed/removed */
705 output->area_saved = output->area;
707 switch (surface->role) {
708 case IVI_SURFACE_ROLE_SPLIT_V:
709 geom.width = (output->area.width / 2);
711 x += woutput->width - geom.width;
712 output->area.width -= geom.width;
714 width = woutput->width - x;
715 height = output->area.height;
719 case IVI_SURFACE_ROLE_SPLIT_H:
720 geom.height = (output->area.height / 2);
723 output->area.y += geom.height;
724 output->area.height -= geom.height;
726 width = output->area.width;
727 height = output->area.height;
733 assert(!"Invalid split orientation\n");
736 weston_desktop_surface_set_size(dsurface,
739 /* resize the active surface first, output->area already contains
740 * correct area to resize to */
742 ivi_layout_desktop_resize(output->active, output->area);
744 weston_view_set_output(view, woutput);
745 weston_view_set_position(view, x, y);
746 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
748 weston_view_geometry_dirty(view);
749 weston_surface_damage(view->surface);
752 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
754 wsurface->is_mapped = true;
755 surface->view->is_mapped = true;
757 shell_advertise_app_state(ivi, app_id,
758 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
760 weston_log("Activation completed for app_id %s, role %s, output %s\n",
761 app_id, ivi_layout_get_surface_role_name(surface), output->name);
765 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
766 int initial_x, int initial_y, int *new_x, int *new_y)
768 *new_x = output->x + initial_x;
769 *new_y = output->y + initial_y;
774 ivi_layout_popup_committed(struct ivi_surface *surface)
776 struct ivi_compositor *ivi = surface->ivi;
777 struct ivi_policy *policy = ivi->policy;
779 struct weston_desktop_surface *dsurface = surface->dsurface;
780 struct weston_surface *wsurface =
781 weston_desktop_surface_get_surface(dsurface);
782 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
786 struct ivi_output *output = surface->popup.output;
787 struct weston_output *woutput = output->output;
789 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
790 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
792 struct weston_view *view = surface->view;
794 if (policy && policy->api.surface_activate_by_default &&
795 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
799 if (surface->view->is_mapped || surface->state == HIDDEN)
802 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
804 weston_view_set_output(view, woutput);
806 ivi_compute_popup_position(woutput, view,
807 surface->popup.x, surface->popup.y, &new_x, &new_y);
808 weston_view_set_position(view, new_x, new_y);
809 weston_view_update_transform(view);
811 /* only clip the pop-up dialog window if we have a valid
812 * width and height being passed on. Users might not want to have one
813 * set-up so only enfore it is really passed on. */
814 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
815 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
816 surface->popup.bb.width, surface->popup.bb.height);
818 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
820 weston_view_geometry_dirty(view);
821 weston_surface_damage(view->surface);
824 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
826 wsurface->is_mapped = true;
827 surface->view->is_mapped = true;
829 shell_advertise_app_state(ivi, app_id,
830 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
832 weston_log("Activation completed for app_id %s, role %s, output %s\n",
833 app_id, ivi_layout_get_surface_role_name(surface), output->name);
837 ivi_layout_popup_re_add(struct ivi_surface *surface)
839 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
840 struct weston_view *view = surface->view;
842 if (weston_view_is_mapped(view)) {
843 struct weston_desktop_surface *dsurface = surface->dsurface;
844 struct weston_surface *wsurface =
845 weston_desktop_surface_get_surface(dsurface);
847 weston_layer_entry_remove(&view->layer_link);
849 wsurface->is_mapped = false;
850 view->is_mapped = false;
853 /* reset the activate by default in order to (still) allow the surface
854 * to be activaved using the request */
855 if (!surface->mapped)
856 surface->mapped = true;
858 surface->state = NORMAL;
859 ivi_layout_popup_committed(surface);
863 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
865 struct ivi_compositor *ivi = surf->ivi;
866 struct ivi_surface *is;
868 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
869 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
870 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
873 /* reset the activate by default in order to (still) allow the surface
874 * to be activaved using the request */
878 wl_list_for_each(is, &ivi->surfaces, link)
886 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
888 struct ivi_compositor *ivi = output->ivi;
889 struct weston_desktop_surface *dsurf;
890 struct weston_geometry geom;
891 struct ivi_policy *policy = output->ivi->policy;
893 dsurf = surf->dsurface;
895 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
900 if (policy && policy->api.surface_activate &&
901 !policy->api.surface_activate(surf, surf->ivi)) {
905 #ifdef AGL_COMP_DEBUG
906 weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
907 ivi_layout_get_surface_role_name(surf), output->output->name);
910 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
911 ivi_layout_popup_re_add(surf);
915 /* do not 're'-activate surfaces that are split or active */
916 if (surf == output->active ||
917 ivi_layout_surface_is_split_or_fullscreen(surf)) {
918 weston_log("Application %s is already active on output %s\n",
919 app_id, output->output->name);
923 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
924 struct ivi_output *remote_output =
925 ivi_layout_find_with_app_id(app_id, ivi);
927 /* if already active on a remote output do not
928 * attempt to activate it again */
929 if (remote_output && remote_output->active == surf)
934 geom = weston_desktop_surface_get_geometry(dsurf);
936 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
937 surf->desktop.pending_output = output;
938 if (weston_desktop_surface_get_maximized(dsurf) &&
939 geom.width == output->area.width &&
940 geom.height == output->area.height) {
941 ivi_layout_activate_complete(output, surf);
945 /* the background surface is already "maximized" so we don't need to
946 * add to the hidden layer */
947 if (surf->role == IVI_SURFACE_ROLE_BACKGROUND) {
948 ivi_layout_activate_complete(output, surf);
952 ivi_layout_add_to_hidden_layer(surf, output);
956 ivi_layout_activate(struct ivi_output *output, const char *app_id)
958 struct ivi_surface *surf;
959 struct ivi_compositor *ivi = output->ivi;
964 surf = ivi_find_app(ivi, app_id);
968 ivi_layout_activate_by_surf(output, surf);
972 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
974 struct ivi_output *ivi_output = NULL;
976 switch (surf->role) {
977 case IVI_SURFACE_ROLE_DESKTOP:
978 if (surf->desktop.pending_output)
979 ivi_output = surf->desktop.pending_output;
981 ivi_output = surf->desktop.last_output;
983 case IVI_SURFACE_ROLE_POPUP:
984 ivi_output = surf->popup.output;
986 case IVI_SURFACE_ROLE_BACKGROUND:
987 ivi_output = surf->bg.output;
989 case IVI_SURFACE_ROLE_PANEL:
990 ivi_output = surf->panel.output;
992 case IVI_SURFACE_ROLE_FULLSCREEN:
993 ivi_output = surf->fullscreen.output;
995 case IVI_SURFACE_ROLE_SPLIT_H:
996 case IVI_SURFACE_ROLE_SPLIT_V:
997 ivi_output = surf->split.output;
999 case IVI_SURFACE_ROLE_REMOTE:
1000 ivi_output = surf->remote.output;
1002 case IVI_SURFACE_ROLE_NONE:
1011 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
1013 struct ivi_surface *surf;
1014 struct ivi_output *ivi_output;
1015 struct ivi_policy *policy = ivi->policy;
1020 surf = ivi_find_app(ivi, app_id);
1024 if (policy && policy->api.surface_deactivate &&
1025 !policy->api.surface_deactivate(surf, surf->ivi)) {
1029 ivi_output = ivi_layout_get_output_from_surface(surf);
1030 weston_log("Deactiving %s, role %s\n", app_id,
1031 ivi_layout_get_surface_role_name(surf));
1033 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
1034 struct ivi_surface *previous_active;
1036 previous_active = ivi_output->previous_active;
1037 if (!previous_active) {
1038 /* we don't have a previous active it means we should
1040 if (ivi_output->active) {
1041 struct weston_view *view;
1043 view = ivi_output->active->view;
1044 view->is_mapped = false;
1045 view->surface->is_mapped = false;
1047 weston_layer_entry_remove(&view->layer_link);
1048 weston_view_geometry_dirty(view);
1049 weston_surface_damage(view->surface);
1050 ivi_output->active = NULL;
1053 struct weston_desktop_surface *dsurface;
1054 const char *previous_active_app_id;
1056 dsurface = previous_active->dsurface;
1057 previous_active_app_id =
1058 weston_desktop_surface_get_app_id(dsurface);
1059 ivi_layout_activate(ivi_output, previous_active_app_id);
1061 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1062 struct weston_view *view = surf->view;
1064 weston_view_unmap(view);
1065 surf->state = HIDDEN;
1067 weston_layer_entry_remove(&view->layer_link);
1068 weston_view_geometry_dirty(view);
1069 weston_surface_damage(view->surface);
1072 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);