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);
221 if (weston_view_is_mapped(view)) {
222 weston_layer_entry_remove(&view->layer_link);
224 weston_view_update_transform(view);
227 weston_view_set_output(view, woutput);
228 weston_view_set_position(view,
229 woutput->x + output->area.x,
230 woutput->y + output->area.y);
232 view->is_mapped = true;
234 view->surface->is_mapped = true;
236 if (output->active) {
237 output->active->view->is_mapped = false;
238 output->active->view->surface->is_mapped = false;
240 weston_layer_entry_remove(&output->active->view->layer_link);
242 output->previous_active = output->active;
243 output->active = surf;
245 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
246 weston_view_geometry_dirty(view);
247 weston_surface_damage(view->surface);
250 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
253 * the 'remote' role now makes use of this part so make sure we don't
254 * trip the enum such that we might end up with a modified output for
257 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
258 if (surf->desktop.pending_output)
259 surf->desktop.last_output = surf->desktop.pending_output;
260 surf->desktop.pending_output = NULL;
263 weston_log("Activation completed for app_id %s, role %s, output %s\n",
264 weston_desktop_surface_get_app_id(surf->dsurface),
265 ivi_layout_get_surface_role_name(surf), output->name);
269 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
271 struct ivi_output *out;
276 wl_list_for_each(out, &ivi->outputs, link) {
280 if (!strcmp(app_id, out->app_id))
288 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
290 struct ivi_output *out;
292 wl_list_for_each(out, &ivi->outputs, link) {
293 if (out->background &&
294 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
303 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
304 struct ivi_output *ivi_output)
306 struct weston_desktop_surface *dsurf = surf->dsurface;
307 struct weston_view *ev = surf->view;
308 struct ivi_compositor *ivi = surf->ivi;
309 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
311 weston_desktop_surface_set_maximized(dsurf, true);
312 weston_desktop_surface_set_size(dsurf,
313 ivi_output->area.width,
314 ivi_output->area.height);
316 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
317 app_id, ivi_layout_get_surface_role_name(surf),
318 ivi_output->area.width, ivi_output->area.height);
320 * If the view isn't mapped, we put it onto the hidden layer so it will
321 * start receiving frame events, and will be able to act on our
324 if (!weston_view_is_mapped(ev)) {
325 ev->is_mapped = true;
326 ev->surface->is_mapped = true;
328 weston_view_set_output(ev, ivi_output->output);
329 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
330 weston_log("Placed app_id %s, type %s in hidden layer\n",
331 app_id, ivi_layout_get_surface_role_name(surf));
336 ivi_layout_desktop_committed(struct ivi_surface *surf)
338 struct weston_desktop_surface *dsurf = surf->dsurface;
339 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
340 struct ivi_policy *policy = surf->ivi->policy;
341 struct ivi_output *output;
342 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
344 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP ||
345 surf->role == IVI_SURFACE_ROLE_REMOTE);
348 * we can't make use here of the ivi_layout_get_output_from_surface()
349 * due to the fact that we'll always land here when a surface performs
350 * a commit and pending_output will not bet set. This works in tandem
351 * with 'mapped' at this point to avoid tripping over
352 * to a surface that continuously updates its content
354 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
355 output = surf->desktop.pending_output;
357 output = surf->remote.output;
359 if (surf->role == IVI_SURFACE_ROLE_DESKTOP && !output) {
360 struct ivi_output *r_output;
362 if (policy && policy->api.surface_activate_by_default &&
363 !policy->api.surface_activate_by_default(surf, surf->ivi))
366 /* we can only activate it again by using the protocol */
370 /* check first if there aren't any outputs being set */
371 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
374 struct weston_view *view = r_output->fullscreen_view.fs->view;
375 if (view->is_mapped || view->surface->is_mapped)
376 remove_black_surface(r_output);
380 /* try finding an output with a background and use that */
382 r_output = ivi_layout_find_bg_output(surf->ivi);
384 /* if we couldn't still find an output by this point, there's
385 * something wrong so we abort with a protocol error */
387 wl_resource_post_error(surf->ivi->shell_client.resource,
388 AGL_SHELL_ERROR_INVALID_ARGUMENT,
389 "No valid output found to activate surface by default");
393 if (!surf->ivi->activate_by_default) {
394 weston_log("Refusing to activate surface role %d, app_id %s\n",
397 if (!weston_desktop_surface_get_maximized(dsurf) ||
398 geom.width != r_output->area.width ||
399 geom.height != r_output->area.height)
400 ivi_layout_add_to_hidden_layer(surf, r_output);
405 /* use the output of the bg to activate the app on start-up by
407 if (surf->view && r_output) {
408 if (app_id && r_output) {
409 weston_log("Surface with app_id %s, role %s activating by default\n",
410 weston_desktop_surface_get_app_id(surf->dsurface),
411 ivi_layout_get_surface_role_name(surf));
412 ivi_layout_activate(r_output, app_id);
413 } else if (!app_id) {
415 * applications not setting an app_id, or
416 * setting an app_id but at a later point in
417 * time, might fall-back here so give them a
418 * chance to receive the configure event and
421 weston_log("Surface no app_id, role %s activating by default\n",
422 ivi_layout_get_surface_role_name(surf));
423 ivi_layout_activate_by_surf(r_output, surf);
430 if (surf->role == IVI_SURFACE_ROLE_REMOTE && output) {
431 if (policy && policy->api.surface_activate_by_default &&
432 !policy->api.surface_activate_by_default(surf, surf->ivi))
435 /* we can only activate it again by using the protocol, but
436 * additionally the output is not reset when
437 * ivi_layout_activate_complete() terminates so we use the
438 * current active surface to avoid hitting this again and again
440 if (surf->mapped && output->active == surf)
444 weston_log("Surface with app_id %s, role %s activating by default\n",
445 weston_desktop_surface_get_app_id(surf->dsurface),
446 ivi_layout_get_surface_role_name(surf));
447 ivi_layout_activate(output, app_id);
452 if (!weston_desktop_surface_get_maximized(dsurf) ||
453 geom.width != output->area.width ||
454 geom.height != output->area.height)
457 ivi_layout_activate_complete(output, surf);
461 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
463 struct ivi_compositor *ivi = surface->ivi;
464 struct ivi_policy *policy = ivi->policy;
466 struct weston_desktop_surface *dsurface = surface->dsurface;
467 struct weston_surface *wsurface =
468 weston_desktop_surface_get_surface(dsurface);
469 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
471 struct ivi_output *output = surface->split.output;
472 struct weston_output *woutput = output->output;
473 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
475 struct weston_view *view = surface->view;
476 struct weston_geometry geom =
477 weston_desktop_surface_get_geometry(dsurface);
479 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
480 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
482 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
484 geom.width == bg_output->output->width &&
485 geom.height == bg_output->output->height;
487 if (policy && policy->api.surface_activate_by_default &&
488 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
492 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
494 if (weston_view_is_mapped(view))
497 /* if we still get here but we haven't resized so far, send configure
499 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
500 struct ivi_output *bg_output =
501 ivi_layout_find_bg_output(surface->ivi);
503 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
504 app_id, ivi_layout_get_surface_role_name(surface));
505 weston_desktop_surface_set_fullscreen(dsurface, true);
506 weston_desktop_surface_set_size(dsurface,
507 bg_output->output->width,
508 bg_output->output->height);
510 surface->state = RESIZING;
511 weston_view_set_output(view, output->output);
512 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
516 /* eventually, we would set the surface fullscreen, but the client
517 * hasn't resized correctly by this point, so terminate connection */
518 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
519 struct weston_desktop_client *desktop_client =
520 weston_desktop_surface_get_client(dsurface);
521 struct wl_client *client =
522 weston_desktop_client_get_client(desktop_client);
523 wl_client_post_implementation_error(client,
524 "can not display surface due to invalid geometry."
525 " Client should perform a geometry resize!");
529 /* this implies we resized correctly */
530 if (!weston_view_is_mapped(view)) {
531 weston_layer_entry_remove(&view->layer_link);
533 weston_view_set_output(view, woutput);
534 weston_view_set_position(view, woutput->x, woutput->y);
535 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
537 wsurface->is_mapped = true;
538 surface->view->is_mapped = true;
539 surface->state = FULLSCREEN;
541 weston_view_geometry_dirty(view);
542 weston_surface_damage(view->surface);
545 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
547 shell_advertise_app_state(ivi, app_id,
548 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
550 weston_log("Activation completed for app_id %s, role %s, "
551 "output %s\n", app_id,
552 ivi_layout_get_surface_role_name(surface),
559 ivi_layout_desktop_resize(struct ivi_surface *surface,
560 struct weston_geometry area)
562 struct weston_desktop_surface *dsurf = surface->dsurface;
563 struct weston_view *view = surface->view;
567 int width = area.width;
568 int height = area.height;
570 weston_desktop_surface_set_size(dsurf,
573 weston_view_set_position(view, x, y);
575 weston_view_geometry_dirty(view);
576 weston_surface_damage(view->surface);
580 ivi_layout_split_committed(struct ivi_surface *surface)
582 struct ivi_compositor *ivi = surface->ivi;
583 struct ivi_policy *policy = ivi->policy;
585 struct weston_desktop_surface *dsurface = surface->dsurface;
586 struct weston_surface *wsurface =
587 weston_desktop_surface_get_surface(dsurface);
588 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
590 struct ivi_output *output = surface->split.output;
591 struct weston_output *woutput = output->output;
593 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
594 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
596 struct weston_view *view = surface->view;
597 struct weston_geometry geom;
605 if (policy && policy->api.surface_activate_by_default &&
606 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
610 if (surface->view->is_mapped)
613 geom = weston_desktop_surface_get_geometry(dsurface);
615 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
616 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
618 /* save the previous area in order to recover it back when if this kind
619 * of surface is being destroyed/removed */
620 output->area_saved = output->area;
622 switch (surface->role) {
623 case IVI_SURFACE_ROLE_SPLIT_V:
624 geom.width = (output->area.width / 2);
626 x += woutput->width - geom.width;
627 output->area.width -= geom.width;
629 width = woutput->width - x;
630 height = output->area.height;
634 case IVI_SURFACE_ROLE_SPLIT_H:
635 geom.height = (output->area.height / 2);
638 output->area.y += geom.height;
639 output->area.height -= geom.height;
641 width = output->area.width;
642 height = output->area.height;
648 assert(!"Invalid split orientation\n");
651 weston_desktop_surface_set_size(dsurface,
654 /* resize the active surface first, output->area already contains
655 * correct area to resize to */
657 ivi_layout_desktop_resize(output->active, output->area);
659 weston_view_set_output(view, woutput);
660 weston_view_set_position(view, x, y);
661 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
663 weston_view_geometry_dirty(view);
664 weston_surface_damage(view->surface);
667 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
669 wsurface->is_mapped = true;
670 surface->view->is_mapped = true;
672 shell_advertise_app_state(ivi, app_id,
673 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
675 weston_log("Activation completed for app_id %s, role %s, output %s\n",
676 app_id, ivi_layout_get_surface_role_name(surface), output->name);
680 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
681 int initial_x, int initial_y, int *new_x, int *new_y)
683 *new_x = output->x + initial_x;
684 *new_y = output->y + initial_y;
689 ivi_layout_popup_committed(struct ivi_surface *surface)
691 struct ivi_compositor *ivi = surface->ivi;
692 struct ivi_policy *policy = ivi->policy;
694 struct weston_desktop_surface *dsurface = surface->dsurface;
695 struct weston_surface *wsurface =
696 weston_desktop_surface_get_surface(dsurface);
697 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
701 struct ivi_output *output = surface->popup.output;
702 struct weston_output *woutput = output->output;
704 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
705 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
707 struct weston_view *view = surface->view;
709 if (policy && policy->api.surface_activate_by_default &&
710 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
714 if (surface->view->is_mapped || surface->state == HIDDEN)
717 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
719 weston_view_set_output(view, woutput);
721 ivi_compute_popup_position(woutput, view,
722 surface->popup.x, surface->popup.y, &new_x, &new_y);
723 weston_view_set_position(view, new_x, new_y);
724 weston_view_update_transform(view);
726 /* only clip the pop-up dialog window if we have a valid
727 * width and height being passed on. Users might not want to have one
728 * set-up so only enfore it is really passed on. */
729 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
730 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
731 surface->popup.bb.width, surface->popup.bb.height);
733 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
735 weston_view_geometry_dirty(view);
736 weston_surface_damage(view->surface);
739 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
741 wsurface->is_mapped = true;
742 surface->view->is_mapped = true;
744 shell_advertise_app_state(ivi, app_id,
745 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
747 weston_log("Activation completed for app_id %s, role %s, output %s\n",
748 app_id, ivi_layout_get_surface_role_name(surface), output->name);
752 ivi_layout_popup_re_add(struct ivi_surface *surface)
754 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
755 struct weston_view *view = surface->view;
757 if (weston_view_is_mapped(view)) {
758 struct weston_desktop_surface *dsurface = surface->dsurface;
759 struct weston_surface *wsurface =
760 weston_desktop_surface_get_surface(dsurface);
762 weston_layer_entry_remove(&view->layer_link);
764 wsurface->is_mapped = false;
765 view->is_mapped = false;
768 /* reset the activate by default in order to (still) allow the surface
769 * to be activaved using the request */
770 if (!surface->mapped)
771 surface->mapped = true;
773 surface->state = NORMAL;
774 ivi_layout_popup_committed(surface);
778 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
780 struct ivi_compositor *ivi = surf->ivi;
781 struct ivi_surface *is;
783 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
784 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
785 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
788 /* reset the activate by default in order to (still) allow the surface
789 * to be activaved using the request */
793 wl_list_for_each(is, &ivi->surfaces, link)
801 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
803 struct ivi_compositor *ivi = output->ivi;
804 struct weston_desktop_surface *dsurf;
805 struct weston_geometry geom;
806 struct ivi_policy *policy = output->ivi->policy;
808 dsurf = surf->dsurface;
810 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
815 if (policy && policy->api.surface_activate &&
816 !policy->api.surface_activate(surf, surf->ivi)) {
820 #ifdef AGL_COMP_DEBUG
821 weston_log("Activating app_id %s, type %s\n", app_id,
822 ivi_layout_get_surface_role_name(surf));
825 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
826 ivi_layout_popup_re_add(surf);
830 /* do not 're'-activate surfaces that are split or active */
831 if (surf == output->active ||
832 ivi_layout_surface_is_split_or_fullscreen(surf))
835 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
836 struct ivi_output *remote_output =
837 ivi_layout_find_with_app_id(app_id, ivi);
839 /* if already active on a remote output do not
840 * attempt to activate it again */
841 if (remote_output && remote_output->active == surf)
846 geom = weston_desktop_surface_get_geometry(dsurf);
848 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
849 surf->desktop.pending_output = output;
850 if (weston_desktop_surface_get_maximized(dsurf) &&
851 geom.width == output->area.width &&
852 geom.height == output->area.height) {
853 ivi_layout_activate_complete(output, surf);
857 ivi_layout_add_to_hidden_layer(surf, output);
861 ivi_layout_activate(struct ivi_output *output, const char *app_id)
863 struct ivi_surface *surf;
864 struct ivi_compositor *ivi = output->ivi;
869 surf = ivi_find_app(ivi, app_id);
873 ivi_layout_activate_by_surf(output, surf);
877 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
879 struct ivi_output *ivi_output = NULL;
881 switch (surf->role) {
882 case IVI_SURFACE_ROLE_DESKTOP:
883 if (surf->desktop.pending_output)
884 ivi_output = surf->desktop.pending_output;
886 ivi_output = surf->desktop.last_output;
888 case IVI_SURFACE_ROLE_POPUP:
889 ivi_output = surf->popup.output;
891 case IVI_SURFACE_ROLE_BACKGROUND:
892 ivi_output = surf->bg.output;
894 case IVI_SURFACE_ROLE_PANEL:
895 ivi_output = surf->panel.output;
897 case IVI_SURFACE_ROLE_FULLSCREEN:
898 ivi_output = surf->fullscreen.output;
900 case IVI_SURFACE_ROLE_SPLIT_H:
901 case IVI_SURFACE_ROLE_SPLIT_V:
902 ivi_output = surf->split.output;
904 case IVI_SURFACE_ROLE_REMOTE:
905 ivi_output = surf->remote.output;
907 case IVI_SURFACE_ROLE_NONE:
916 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
918 struct ivi_surface *surf;
919 struct ivi_output *ivi_output;
920 struct ivi_policy *policy = ivi->policy;
925 surf = ivi_find_app(ivi, app_id);
929 if (policy && policy->api.surface_deactivate &&
930 !policy->api.surface_deactivate(surf, surf->ivi)) {
934 ivi_output = ivi_layout_get_output_from_surface(surf);
935 weston_log("Deactiving %s, role %s\n", app_id,
936 ivi_layout_get_surface_role_name(surf));
938 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
939 struct ivi_surface *previous_active;
941 previous_active = ivi_output->previous_active;
942 if (!previous_active) {
943 /* we don't have a previous active it means we should
945 if (ivi_output->active) {
946 struct weston_view *view;
948 view = ivi_output->active->view;
949 view->is_mapped = false;
950 view->surface->is_mapped = false;
952 weston_layer_entry_remove(&view->layer_link);
953 weston_view_geometry_dirty(view);
954 weston_surface_damage(view->surface);
955 ivi_output->active = NULL;
958 struct weston_desktop_surface *dsurface;
959 const char *previous_active_app_id;
961 dsurface = previous_active->dsurface;
962 previous_active_app_id =
963 weston_desktop_surface_get_app_id(dsurface);
964 ivi_layout_activate(ivi_output, previous_active_app_id);
966 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
967 struct weston_view *view = surf->view;
969 weston_view_unmap(view);
970 surf->state = HIDDEN;
972 weston_layer_entry_remove(&view->layer_link);
973 weston_view_geometry_dirty(view);
974 weston_surface_damage(view->surface);