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",
50 [IVI_SURFACE_ROLE_TILE] = "TILE",
54 ivi_layout_get_surface_role_name(struct ivi_surface *surf)
56 if (surf->role < 0 || surf->role >= ARRAY_LENGTH(ivi_roles_as_string))
57 return " unknown surface role";
59 return ivi_roles_as_string[surf->role];
63 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
65 struct weston_output *woutput = output->output;
66 struct ivi_surface *bg = output->background;
67 struct weston_view *view;
70 weston_log("WARNING: Output does not have a background\n");
74 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
78 weston_view_set_output(view, woutput);
79 weston_view_set_position(view, woutput->x, woutput->y);
81 weston_log("(background) position view %p, x %d, y %d, on output %s\n", view,
82 woutput->x, woutput->y, output->name);
84 view->is_mapped = true;
85 view->surface->is_mapped = true;
87 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
91 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
92 struct ivi_surface *panel)
94 struct weston_output *woutput = output->output;
95 struct weston_desktop_surface *dsurface;
96 struct weston_view *view;
97 struct weston_geometry geom;
104 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
105 dsurface = panel->dsurface;
107 geom = weston_desktop_surface_get_geometry(dsurface);
109 weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
110 geom.width, geom.height, geom.x, geom.y);
112 switch (panel->panel.edge) {
113 case AGL_SHELL_EDGE_TOP:
114 output->area.y += geom.height;
115 output->area.height -= geom.height;
117 case AGL_SHELL_EDGE_BOTTOM:
118 y += woutput->height - geom.height;
119 output->area.height -= geom.height;
121 case AGL_SHELL_EDGE_LEFT:
122 output->area.x += geom.width;
123 output->area.width -= geom.width;
125 case AGL_SHELL_EDGE_RIGHT:
126 x += woutput->width - geom.width;
127 output->area.width -= geom.width;
134 weston_view_set_output(view, woutput);
135 weston_view_set_position(view, x, y);
137 weston_log("(panel) edge %d position view %p, x %d, y %d\n",
138 panel->panel.edge, view, x, y);
140 view->is_mapped = true;
141 view->surface->is_mapped = true;
143 weston_log("panel type %d inited on output %s\n", panel->panel.edge,
146 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
150 * Initializes all static parts of the layout, i.e. the background and panels.
153 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
155 ivi_background_init(ivi, output);
159 output->area.width = output->output->width;
160 output->area.height = output->output->height;
162 ivi_panel_init(ivi, output, output->top);
163 ivi_panel_init(ivi, output, output->bottom);
164 ivi_panel_init(ivi, output, output->left);
165 ivi_panel_init(ivi, output, output->right);
167 weston_compositor_schedule_repaint(ivi->compositor);
169 weston_log("Usable area: %dx%d+%d,%d\n",
170 output->area.width, output->area.height,
171 output->area.x, output->area.y);
175 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
177 struct ivi_surface *surf;
180 wl_list_for_each(surf, &ivi->surfaces, link) {
181 id = weston_desktop_surface_get_app_id(surf->dsurface);
182 if (id && strcmp(app_id, id) == 0)
190 ivi_layout_activate_complete(struct ivi_output *output,
191 struct ivi_surface *surf)
193 struct ivi_compositor *ivi = output->ivi;
194 struct weston_output *woutput = output->output;
195 struct weston_view *view = surf->view;
196 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
197 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
199 if (weston_view_is_mapped(view)) {
200 weston_layer_entry_remove(&view->layer_link);
202 weston_view_update_transform(view);
205 weston_view_set_output(view, woutput);
206 weston_view_set_position(view,
207 woutput->x + output->area.x,
208 woutput->y + output->area.y);
210 surf->orientation = AGL_SHELL_TILE_ORIENTATION_NONE;
211 weston_desktop_surface_set_orientation(surf->dsurface,
214 view->is_mapped = true;
216 view->surface->is_mapped = true;
218 if (output->active) {
219 output->active->view->is_mapped = false;
220 output->active->view->surface->is_mapped = false;
222 weston_layer_entry_remove(&output->active->view->layer_link);
224 output->previous_active = output->active;
225 output->active = surf;
227 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
228 weston_view_geometry_dirty(view);
229 weston_surface_damage(view->surface);
232 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
235 * the 'remote' role now makes use of this part so make sure we don't
236 * trip the enum such that we might end up with a modified output for
239 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
240 if (surf->desktop.pending_output)
241 surf->desktop.last_output = surf->desktop.pending_output;
242 surf->desktop.pending_output = NULL;
245 weston_log("Activation completed for app_id %s, role %s, output %s\n",
246 weston_desktop_surface_get_app_id(surf->dsurface),
247 ivi_layout_get_surface_role_name(surf), output->name);
251 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
253 struct ivi_output *out;
258 wl_list_for_each(out, &ivi->outputs, link) {
262 if (!strcmp(app_id, out->app_id))
270 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
272 struct ivi_output *out;
274 wl_list_for_each(out, &ivi->outputs, link) {
275 if (out->background &&
276 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
285 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
286 struct ivi_output *ivi_output)
288 struct weston_desktop_surface *dsurf = surf->dsurface;
289 struct weston_view *ev = surf->view;
290 struct ivi_compositor *ivi = surf->ivi;
291 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
293 weston_desktop_surface_set_maximized(dsurf, true);
294 weston_desktop_surface_set_size(dsurf,
295 ivi_output->area.width,
296 ivi_output->area.height);
298 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
299 app_id, ivi_layout_get_surface_role_name(surf),
300 ivi_output->area.width, ivi_output->area.height);
302 * If the view isn't mapped, we put it onto the hidden layer so it will
303 * start receiving frame events, and will be able to act on our
306 if (!weston_view_is_mapped(ev)) {
307 ev->is_mapped = true;
308 ev->surface->is_mapped = true;
310 weston_view_set_output(ev, ivi_output->output);
311 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
312 weston_log("Placed app_id %s, type %s in hidden layer\n",
313 app_id, ivi_layout_get_surface_role_name(surf));
318 ivi_layout_desktop_committed(struct ivi_surface *surf)
320 struct weston_desktop_surface *dsurf = surf->dsurface;
321 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
322 struct ivi_policy *policy = surf->ivi->policy;
323 struct ivi_output *output;
324 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
326 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP ||
327 surf->role == IVI_SURFACE_ROLE_REMOTE);
330 * we can't make use here of the ivi_layout_get_output_from_surface()
331 * due to the fact that we'll always land here when a surface performs
332 * a commit and pending_output will not bet set. This works in tandem
333 * with 'mapped' at this point to avoid tripping over
334 * to a surface that continuously updates its content
336 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
337 output = surf->desktop.pending_output;
339 output = surf->remote.output;
341 if (surf->role == IVI_SURFACE_ROLE_DESKTOP && !output) {
342 struct ivi_output *r_output;
344 if (policy && policy->api.surface_activate_by_default &&
345 !policy->api.surface_activate_by_default(surf, surf->ivi))
348 /* we can only activate it again by using the protocol */
352 /* check first if there aren't any outputs being set */
353 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
356 struct weston_view *view = r_output->fullscreen_view.fs->view;
357 if (view->is_mapped || view->surface->is_mapped)
358 remove_black_surface(r_output);
362 /* try finding an output with a background and use that */
364 r_output = ivi_layout_find_bg_output(surf->ivi);
366 /* if we couldn't still find an output by this point, there's
367 * something wrong so we abort with a protocol error */
369 wl_resource_post_error(surf->ivi->shell_client.resource,
370 AGL_SHELL_ERROR_INVALID_ARGUMENT,
371 "No valid output found to activate surface by default");
375 if (!surf->ivi->activate_by_default) {
376 weston_log("Refusing to activate surface role %d, app_id %s\n",
379 if (!weston_desktop_surface_get_maximized(dsurf) ||
380 geom.width != r_output->area.width ||
381 geom.height != r_output->area.height)
382 ivi_layout_add_to_hidden_layer(surf, r_output);
387 /* use the output of the bg to activate the app on start-up by
389 if (surf->view && r_output) {
390 if (app_id && r_output) {
391 weston_log("Surface with app_id %s, role %s activating by default\n",
392 weston_desktop_surface_get_app_id(surf->dsurface),
393 ivi_layout_get_surface_role_name(surf));
394 ivi_layout_activate(r_output, app_id);
395 } else if (!app_id) {
397 * applications not setting an app_id, or
398 * setting an app_id but at a later point in
399 * time, might fall-back here so give them a
400 * chance to receive the configure event and
403 weston_log("Surface no app_id, role %s activating by default\n",
404 ivi_layout_get_surface_role_name(surf));
405 ivi_layout_activate_by_surf(r_output, surf);
412 if (surf->role == IVI_SURFACE_ROLE_REMOTE && output) {
413 if (policy && policy->api.surface_activate_by_default &&
414 !policy->api.surface_activate_by_default(surf, surf->ivi))
417 /* we can only activate it again by using the protocol, but
418 * additionally the output is not reset when
419 * ivi_layout_activate_complete() terminates so we use the
420 * current active surface to avoid hitting this again and again
422 if (surf->mapped && output->active == surf)
426 weston_log("Surface with app_id %s, role %s activating by default\n",
427 weston_desktop_surface_get_app_id(surf->dsurface),
428 ivi_layout_get_surface_role_name(surf));
429 ivi_layout_activate(output, app_id);
434 if (!weston_desktop_surface_get_maximized(dsurf) ||
435 geom.width != output->area.width ||
436 geom.height != output->area.height)
439 ivi_layout_activate_complete(output, surf);
443 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
445 struct ivi_compositor *ivi = surface->ivi;
446 struct ivi_policy *policy = ivi->policy;
448 struct weston_desktop_surface *dsurface = surface->dsurface;
449 struct weston_surface *wsurface =
450 weston_desktop_surface_get_surface(dsurface);
451 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
453 struct ivi_output *output = surface->split.output;
454 struct weston_output *woutput = output->output;
455 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
457 struct weston_view *view = surface->view;
458 struct weston_geometry geom =
459 weston_desktop_surface_get_geometry(dsurface);
461 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
462 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
464 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
466 geom.width == bg_output->output->width &&
467 geom.height == bg_output->output->height;
469 if (policy && policy->api.surface_activate_by_default &&
470 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
474 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
476 if (weston_view_is_mapped(view))
479 /* if we still get here but we haven't resized so far, send configure
481 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
482 struct ivi_output *bg_output =
483 ivi_layout_find_bg_output(surface->ivi);
485 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
486 app_id, ivi_layout_get_surface_role_name(surface));
487 weston_desktop_surface_set_fullscreen(dsurface, true);
488 weston_desktop_surface_set_size(dsurface,
489 bg_output->output->width,
490 bg_output->output->height);
492 surface->state = RESIZING;
493 weston_view_set_output(view, output->output);
494 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
498 /* eventually, we would set the surface fullscreen, but the client
499 * hasn't resized correctly by this point, so terminate connection */
500 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
501 struct weston_desktop_client *desktop_client =
502 weston_desktop_surface_get_client(dsurface);
503 struct wl_client *client =
504 weston_desktop_client_get_client(desktop_client);
505 wl_client_post_implementation_error(client,
506 "can not display surface due to invalid geometry."
507 " Client should perform a geometry resize!");
511 /* this implies we resized correctly */
512 if (!weston_view_is_mapped(view)) {
513 weston_layer_entry_remove(&view->layer_link);
515 weston_view_set_output(view, woutput);
516 weston_view_set_position(view, woutput->x, woutput->y);
517 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
519 wsurface->is_mapped = true;
520 surface->view->is_mapped = true;
521 surface->state = FULLSCREEN;
523 weston_view_geometry_dirty(view);
524 weston_surface_damage(view->surface);
527 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
529 shell_advertise_app_state(ivi, app_id,
530 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
532 weston_log("Activation completed for app_id %s, role %s, "
533 "output %s\n", app_id,
534 ivi_layout_get_surface_role_name(surface),
541 ivi_layout_desktop_resize(struct ivi_surface *surface,
542 struct weston_geometry area)
544 struct weston_desktop_surface *dsurf = surface->dsurface;
545 struct weston_view *view = surface->view;
549 int width = area.width;
550 int height = area.height;
552 weston_desktop_surface_set_size(dsurf,
555 weston_view_set_position(view, x, y);
557 weston_view_geometry_dirty(view);
558 weston_surface_damage(view->surface);
562 ivi_layout_split_committed(struct ivi_surface *surface)
564 struct ivi_compositor *ivi = surface->ivi;
565 struct ivi_policy *policy = ivi->policy;
567 struct weston_desktop_surface *dsurface = surface->dsurface;
568 struct weston_surface *wsurface =
569 weston_desktop_surface_get_surface(dsurface);
570 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
572 struct ivi_output *output = surface->split.output;
573 struct weston_output *woutput = output->output;
575 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
576 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
578 struct weston_view *view = surface->view;
579 struct weston_geometry geom;
587 if (policy && policy->api.surface_activate_by_default &&
588 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
592 if (surface->view->is_mapped)
595 geom = weston_desktop_surface_get_geometry(dsurface);
597 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
598 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
600 /* save the previous area in order to recover it back when if this kind
601 * of surface is being destroyed/removed */
602 output->area_saved = output->area;
604 switch (surface->role) {
605 case IVI_SURFACE_ROLE_SPLIT_V:
606 geom.width = (output->area.width / 2);
608 x += woutput->width - geom.width;
609 output->area.width -= geom.width;
611 width = woutput->width - x;
612 height = output->area.height;
616 case IVI_SURFACE_ROLE_SPLIT_H:
617 geom.height = (output->area.height / 2);
620 output->area.y += geom.height;
621 output->area.height -= geom.height;
623 width = output->area.width;
624 height = output->area.height;
630 assert(!"Invalid split orientation\n");
633 weston_desktop_surface_set_size(dsurface,
636 /* resize the active surface first, output->area already contains
637 * correct area to resize to */
639 ivi_layout_desktop_resize(output->active, output->area);
641 weston_view_set_output(view, woutput);
642 weston_view_set_position(view, x, y);
643 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
645 weston_view_geometry_dirty(view);
646 weston_surface_damage(view->surface);
649 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
651 wsurface->is_mapped = true;
652 surface->view->is_mapped = true;
654 shell_advertise_app_state(ivi, app_id,
655 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
657 weston_log("Activation completed for app_id %s, role %s, output %s\n",
658 app_id, ivi_layout_get_surface_role_name(surface), output->name);
662 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
663 int initial_x, int initial_y, int *new_x, int *new_y)
665 *new_x = output->x + initial_x;
666 *new_y = output->y + initial_y;
671 ivi_layout_popup_committed(struct ivi_surface *surface)
673 struct ivi_compositor *ivi = surface->ivi;
674 struct ivi_policy *policy = ivi->policy;
676 struct weston_desktop_surface *dsurface = surface->dsurface;
677 struct weston_surface *wsurface =
678 weston_desktop_surface_get_surface(dsurface);
679 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
683 struct ivi_output *output = surface->popup.output;
684 struct weston_output *woutput = output->output;
686 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
687 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
689 struct weston_view *view = surface->view;
691 if (policy && policy->api.surface_activate_by_default &&
692 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
696 if (surface->view->is_mapped || surface->state == HIDDEN)
699 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
701 weston_view_set_output(view, woutput);
703 ivi_compute_popup_position(woutput, view,
704 surface->popup.x, surface->popup.y, &new_x, &new_y);
705 weston_view_set_position(view, new_x, new_y);
706 weston_view_update_transform(view);
708 /* only clip the pop-up dialog window if we have a valid
709 * width and height being passed on. Users might not want to have one
710 * set-up so only enfore it is really passed on. */
711 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
712 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
713 surface->popup.bb.width, surface->popup.bb.height);
715 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
717 weston_view_geometry_dirty(view);
718 weston_surface_damage(view->surface);
721 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
723 wsurface->is_mapped = true;
724 surface->view->is_mapped = true;
726 shell_advertise_app_state(ivi, app_id,
727 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
729 weston_log("Activation completed for app_id %s, role %s, output %s\n",
730 app_id, ivi_layout_get_surface_role_name(surface), output->name);
734 ivi_layout_popup_re_add(struct ivi_surface *surface)
736 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
737 struct weston_view *view = surface->view;
739 if (weston_view_is_mapped(view)) {
740 struct weston_desktop_surface *dsurface = surface->dsurface;
741 struct weston_surface *wsurface =
742 weston_desktop_surface_get_surface(dsurface);
744 weston_layer_entry_remove(&view->layer_link);
746 wsurface->is_mapped = false;
747 view->is_mapped = false;
750 /* reset the activate by default in order to (still) allow the surface
751 * to be activaved using the request */
752 if (!surface->mapped)
753 surface->mapped = true;
755 surface->state = NORMAL;
756 ivi_layout_popup_committed(surface);
760 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
762 struct ivi_compositor *ivi = surf->ivi;
763 struct ivi_surface *is;
765 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
766 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
767 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
770 /* reset the activate by default in order to (still) allow the surface
771 * to be activaved using the request */
775 wl_list_for_each(is, &ivi->surfaces, link)
783 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
785 struct ivi_compositor *ivi = output->ivi;
786 struct weston_desktop_surface *dsurf;
787 struct weston_geometry geom;
788 struct ivi_policy *policy = output->ivi->policy;
790 dsurf = surf->dsurface;
792 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
797 if (policy && policy->api.surface_activate &&
798 !policy->api.surface_activate(surf, surf->ivi)) {
802 #ifdef AGL_COMP_DEBUG
803 weston_log("Activating app_id %s, type %s\n", app_id,
804 ivi_layout_get_surface_role_name(surf));
807 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
808 ivi_layout_popup_re_add(surf);
812 /* reset tile to desktop to allow to resize correctly */
813 if (surf->role == IVI_SURFACE_ROLE_TILE && output->active == surf)
814 surf->role = IVI_SURFACE_ROLE_DESKTOP;
816 /* do not 're'-activate surfaces that are split or active */
817 if ((surf == output->active && surf->role != IVI_SURFACE_ROLE_DESKTOP) ||
818 ivi_layout_surface_is_split_or_fullscreen(surf)) {
819 weston_log("Found split || fullscreen surface. Refusing to activate!\n");
823 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
824 struct ivi_output *remote_output =
825 ivi_layout_find_with_app_id(app_id, ivi);
827 /* if already active on a remote output do not
828 * attempt to activate it again */
829 if (remote_output && remote_output->active == surf)
834 geom = weston_desktop_surface_get_geometry(dsurf);
836 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
837 surf->desktop.pending_output = output;
838 if (weston_desktop_surface_get_maximized(dsurf) &&
839 geom.width == output->area.width &&
840 geom.height == output->area.height) {
841 ivi_layout_activate_complete(output, surf);
845 ivi_layout_add_to_hidden_layer(surf, output);
849 ivi_layout_activate(struct ivi_output *output, const char *app_id)
851 struct ivi_surface *surf;
852 struct ivi_compositor *ivi = output->ivi;
857 surf = ivi_find_app(ivi, app_id);
861 ivi_layout_activate_by_surf(output, surf);
865 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
867 struct ivi_output *ivi_output = NULL;
869 switch (surf->role) {
870 case IVI_SURFACE_ROLE_DESKTOP:
871 if (surf->desktop.pending_output)
872 ivi_output = surf->desktop.pending_output;
874 ivi_output = surf->desktop.last_output;
876 case IVI_SURFACE_ROLE_POPUP:
877 ivi_output = surf->popup.output;
879 case IVI_SURFACE_ROLE_BACKGROUND:
880 ivi_output = surf->bg.output;
882 case IVI_SURFACE_ROLE_PANEL:
883 ivi_output = surf->panel.output;
885 case IVI_SURFACE_ROLE_FULLSCREEN:
886 ivi_output = surf->fullscreen.output;
888 case IVI_SURFACE_ROLE_SPLIT_H:
889 case IVI_SURFACE_ROLE_SPLIT_V:
890 ivi_output = surf->split.output;
892 case IVI_SURFACE_ROLE_REMOTE:
893 ivi_output = surf->remote.output;
895 case IVI_SURFACE_ROLE_NONE:
897 if (surf->view->output)
898 return to_ivi_output(surf->view->output);
906 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
908 struct ivi_surface *surf;
909 struct ivi_output *ivi_output;
910 struct ivi_policy *policy = ivi->policy;
915 surf = ivi_find_app(ivi, app_id);
919 if (policy && policy->api.surface_deactivate &&
920 !policy->api.surface_deactivate(surf, surf->ivi)) {
924 ivi_output = ivi_layout_get_output_from_surface(surf);
925 weston_log("Deactiving %s, role %s\n", app_id,
926 ivi_layout_get_surface_role_name(surf));
928 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
929 struct ivi_surface *previous_active;
931 previous_active = ivi_output->previous_active;
932 if (!previous_active) {
933 /* we don't have a previous active it means we should
935 if (ivi_output->active) {
936 struct weston_view *view;
938 view = ivi_output->active->view;
939 view->is_mapped = false;
940 view->surface->is_mapped = false;
942 weston_layer_entry_remove(&view->layer_link);
943 weston_view_geometry_dirty(view);
944 weston_surface_damage(view->surface);
945 ivi_output->active = NULL;
948 struct weston_desktop_surface *dsurface;
949 const char *previous_active_app_id;
951 dsurface = previous_active->dsurface;
952 previous_active_app_id =
953 weston_desktop_surface_get_app_id(dsurface);
954 ivi_layout_activate(ivi_output, previous_active_app_id);
956 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
957 struct weston_view *view = surf->view;
959 weston_view_unmap(view);
960 surf->state = HIDDEN;
962 weston_layer_entry_remove(&view->layer_link);
963 weston_view_geometry_dirty(view);
964 weston_surface_damage(view->surface);