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/config-parser.h>
34 #include <libweston/libweston.h>
35 #include <libweston-desktop/libweston-desktop.h>
37 #include "agl-shell-desktop-server-protocol.h"
39 #define AGL_COMP_DEBUG
41 static const char *ivi_roles_as_string[] = {
42 [IVI_SURFACE_ROLE_NONE] = "NONE",
43 [IVI_SURFACE_ROLE_BACKGROUND] = "BACKGROUND",
44 [IVI_SURFACE_ROLE_PANEL] = "PANEL",
45 [IVI_SURFACE_ROLE_DESKTOP] = "DESKTOP",
46 [IVI_SURFACE_ROLE_POPUP] = "POPUP",
47 [IVI_SURFACE_ROLE_SPLIT_H] = "SPLIT_H",
48 [IVI_SURFACE_ROLE_SPLIT_V] = "SPLIT_V",
49 [IVI_SURFACE_ROLE_FULLSCREEN] = "FULLSCREEN",
50 [IVI_SURFACE_ROLE_REMOTE] = "REMOTE",
54 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface);
57 ivi_layout_get_surface_role_name(struct ivi_surface *surf)
59 if (surf->role < 0 || surf->role >= ARRAY_LENGTH(ivi_roles_as_string))
60 return " unknown surface role";
62 return ivi_roles_as_string[surf->role];
66 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
68 struct weston_output *woutput = output->output;
69 struct ivi_surface *bg = output->background;
70 struct weston_view *view;
73 weston_log("WARNING: Output does not have a background\n");
77 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
81 weston_view_set_output(view, woutput);
82 weston_view_set_position(view, woutput->x, woutput->y);
84 weston_log("(background) position view %p, x %d, y %d, on output %s\n", view,
85 woutput->x, woutput->y, output->name);
87 view->is_mapped = true;
88 view->surface->is_mapped = true;
90 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
94 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
95 struct ivi_surface *panel)
97 struct weston_output *woutput = output->output;
98 struct weston_desktop_surface *dsurface;
99 struct weston_view *view;
100 struct weston_geometry geom;
107 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
108 dsurface = panel->dsurface;
110 geom = weston_desktop_surface_get_geometry(dsurface);
112 weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
113 geom.width, geom.height, geom.x, geom.y);
115 switch (panel->panel.edge) {
116 case AGL_SHELL_EDGE_TOP:
117 output->area.y += geom.height;
118 output->area.height -= geom.height;
120 case AGL_SHELL_EDGE_BOTTOM:
121 y += woutput->height - geom.height;
122 output->area.height -= geom.height;
124 case AGL_SHELL_EDGE_LEFT:
125 output->area.x += geom.width;
126 output->area.width -= geom.width;
128 case AGL_SHELL_EDGE_RIGHT:
129 x += woutput->width - geom.width;
130 output->area.width -= geom.width;
137 weston_view_set_output(view, woutput);
138 weston_view_set_position(view, x, y);
140 weston_log("(panel) edge %d position view %p, x %d, y %d\n",
141 panel->panel.edge, view, x, y);
143 view->is_mapped = true;
144 view->surface->is_mapped = true;
146 weston_log("panel type %d inited on output %s\n", panel->panel.edge,
149 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
153 * Initializes all static parts of the layout, i.e. the background and panels.
156 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
158 bool use_default_area = true;
159 struct weston_config_section *section = output->config;
162 weston_config_section_get_string(section, "activation-area", &t, NULL);
164 if (output->area_activation.width == 0 &&
165 output->area_activation.height == 0 &&
166 output->area_activation.x == 0 &&
167 output->area_activation.y == 0) {
168 weston_log("WARNING: activation-area set in "
169 "configuration file, but yet applied!\n");
170 if (parse_activation_area(t, output) < 0)
171 weston_log("Invalid activation-area \"%s\" for output %s\n",
177 ivi_background_init(ivi, output);
179 if (output->area_activation.width ||
180 output->area_activation.height ||
181 output->area_activation.x ||
182 output->area_activation.y) {
183 /* Sanity check target area is within output bounds */
184 if ((output->area_activation.x + output->area_activation.width) < output->output->width ||
185 (output->area_activation.y + output->area_activation.height) < output->output->height) {
186 weston_log("Using specified area for output %s, ignoring panels\n",
188 output->area.x = output->area_activation.x;
189 output->area.y = output->area_activation.y;
190 output->area.width = output->area_activation.width;
191 output->area.height = output->area_activation.height;
192 use_default_area = false;
194 weston_log("Invalid activation-area position for output %s, ignoring\n",
198 if (use_default_area) {
201 output->area.width = output->output->width;
202 output->area.height = output->output->height;
204 ivi_panel_init(ivi, output, output->top);
205 ivi_panel_init(ivi, output, output->bottom);
206 ivi_panel_init(ivi, output, output->left);
207 ivi_panel_init(ivi, output, output->right);
210 weston_compositor_schedule_repaint(ivi->compositor);
212 weston_log("Usable area: %dx%d+%d,%d\n",
213 output->area.width, output->area.height,
214 output->area.x, output->area.y);
218 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
220 struct ivi_surface *surf;
223 wl_list_for_each(surf, &ivi->surfaces, link) {
224 id = weston_desktop_surface_get_app_id(surf->dsurface);
225 if (id && strcmp(app_id, id) == 0)
233 ivi_layout_activate_complete(struct ivi_output *output,
234 struct ivi_surface *surf)
236 struct ivi_compositor *ivi = output->ivi;
237 struct weston_output *woutput = output->output;
238 struct weston_view *view = surf->view;
239 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
240 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
241 const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
242 bool update_previous = true;
244 if (weston_view_is_mapped(view)) {
245 weston_layer_entry_remove(&view->layer_link);
247 weston_view_update_transform(view);
250 if (output_has_black_curtain(output)) {
251 if (!output->background) {
252 weston_log("Found that we have no background surface "
253 "for output %s. Using black curtain as background\n",
254 output->output->name);
256 struct weston_view *ev =
257 output->fullscreen_view.fs->view;
259 /* use the black curtain as background when we have
260 * none added by the shell client. */
261 weston_layer_entry_remove(&ev->layer_link);
262 weston_layer_entry_insert(&ivi->normal.view_list,
264 weston_view_geometry_dirty(ev);
265 weston_surface_damage(ev->surface);
267 remove_black_curtain(output);
272 weston_view_set_output(view, woutput);
273 /* drop any previous masks set on this view */
274 weston_view_set_mask_infinite(view);
276 if (surf->role != IVI_SURFACE_ROLE_BACKGROUND)
277 weston_view_set_position(view,
278 woutput->x + output->area.x,
279 woutput->y + output->area.y);
281 view->is_mapped = true;
283 view->surface->is_mapped = true;
285 /* handle a movement from one output to another */
286 if (surf->current_completed_output &&
287 surf->current_completed_output != output) {
289 /* we're migrating the same surface but to another output */
290 if (surf->current_completed_output->active == surf) {
291 struct weston_view *ev =
292 surf->current_completed_output->active->view;
294 weston_layer_entry_remove(&ev->layer_link);
295 surf->current_completed_output->previous_active =
296 surf->current_completed_output->active;
297 surf->current_completed_output->active = NULL;
299 /* damage all possible outputs to avoid stale views */
300 weston_compositor_damage_all(ivi->compositor);
304 if (output->active) {
305 /* keep the background surface mapped at all times */
306 if (output->active->role != IVI_SURFACE_ROLE_BACKGROUND) {
307 output->active->view->is_mapped = false;
308 output->active->view->surface->is_mapped = false;
310 weston_layer_entry_remove(&output->active->view->layer_link);
314 if (output->previous_active && output->active) {
315 const char *c_app_id =
316 weston_desktop_surface_get_app_id(output->active->dsurface);
318 /* if the currently activated app_id is the same as the one
319 * we're trying to complete activation with means we're
320 * operating on the same app_id so do update previous_active as
321 * it will overwrite it with the same value */
322 if (!strcmp(c_app_id, app_id)) {
323 update_previous = false;
328 output->previous_active = output->active;
329 output->active = surf;
330 surf->current_completed_output = output;
332 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
333 weston_view_geometry_dirty(view);
334 weston_surface_damage(view->surface);
337 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
340 * the 'remote' role now makes use of this part so make sure we don't
341 * trip the enum such that we might end up with a modified output for
344 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
345 if (surf->desktop.pending_output)
346 surf->desktop.last_output = surf->desktop.pending_output;
347 surf->desktop.pending_output = NULL;
350 weston_log("Activation completed for app_id %s, role %s, output %s\n",
352 ivi_layout_get_surface_role_name(surf), output->name);
354 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_ACTIVATED);
358 ivi_layout_find_output_with_app_id(const char *app_id, struct ivi_output *output)
363 cur = output->app_ids;
364 app_id_len = strlen(app_id);
366 while ((cur = strstr(cur, app_id))) {
367 if ((cur[app_id_len] == ',' || cur[app_id_len] == '\0') &&
368 (cur == output->app_ids || cur[-1] == ','))
377 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
379 struct ivi_output *out;
384 wl_list_for_each(out, &ivi->outputs, link) {
388 if (ivi_layout_find_output_with_app_id(app_id, out))
395 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
397 struct ivi_output *out;
399 wl_list_for_each(out, &ivi->outputs, link) {
400 if (out->background &&
401 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
410 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
411 struct ivi_output *ivi_output)
413 struct weston_desktop_surface *dsurf = surf->dsurface;
414 struct weston_view *ev = surf->view;
415 struct ivi_compositor *ivi = surf->ivi;
416 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
419 * If the view isn't mapped, we put it onto the hidden layer so it will
420 * start receiving frame events, and will be able to act on our
423 if (!weston_view_is_mapped(ev)) {
424 ev->is_mapped = true;
425 ev->surface->is_mapped = true;
427 weston_desktop_surface_set_maximized(dsurf, true);
428 weston_desktop_surface_set_size(dsurf,
429 ivi_output->area.width,
430 ivi_output->area.height);
432 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
433 app_id, ivi_layout_get_surface_role_name(surf),
434 ivi_output->area.width, ivi_output->area.height);
436 surf->hidden_layer_output = ivi_output;
437 weston_view_set_output(ev, ivi_output->output);
438 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
439 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
440 app_id, ivi_layout_get_surface_role_name(surf),
441 ivi_output->output->name);
443 weston_compositor_schedule_repaint(ivi->compositor);
447 /* we might have another output to activate */
448 if (surf->hidden_layer_output &&
449 surf->hidden_layer_output != ivi_output) {
450 weston_layer_entry_remove(&ev->layer_link);
451 weston_view_geometry_dirty(ev);
452 weston_surface_damage(ev->surface);
454 if (ivi_output->area.width != surf->hidden_layer_output->area.width ||
455 ivi_output->area.height != surf->hidden_layer_output->area.height) {
456 weston_desktop_surface_set_maximized(dsurf, true);
457 weston_desktop_surface_set_size(dsurf,
458 ivi_output->area.width,
459 ivi_output->area.height);
462 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
463 app_id, ivi_layout_get_surface_role_name(surf),
464 ivi_output->area.width, ivi_output->area.height);
466 surf->hidden_layer_output = ivi_output;
467 weston_view_set_output(ev, ivi_output->output);
468 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
469 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
470 app_id, ivi_layout_get_surface_role_name(surf),
471 ivi_output->output->name);
474 weston_compositor_schedule_repaint(ivi->compositor);
478 ivi_layout_remote_committed(struct ivi_surface *surf)
480 struct weston_desktop_surface *dsurf = surf->dsurface;
481 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
482 struct ivi_policy *policy = surf->ivi->policy;
483 struct ivi_output *output;
484 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
486 assert(surf->role == IVI_SURFACE_ROLE_REMOTE);
488 output = surf->remote.output;
490 if (policy && policy->api.surface_activate_by_default &&
491 !policy->api.surface_activate_by_default(surf, surf->ivi))
494 /* we can only activate it again by using the protocol, but
495 * additionally the output is not reset when
496 * ivi_layout_activate_complete() terminates so we use the
497 * current active surface to avoid hitting this again and again
499 if (surf->mapped && output->active == surf)
502 if (!surf->ivi->activate_by_default &&
503 !ivi_surf_in_hidden_layer(surf->ivi, surf)) {
504 weston_log("Refusing to activate surface role %d, "
505 "app_id %s\n", surf->role, app_id);
507 if (!weston_desktop_surface_get_maximized(dsurf) ||
508 geom.width != output->area.width ||
509 geom.height != output->area.height) {
510 ivi_layout_add_to_hidden_layer(surf, output);
516 if (!weston_desktop_surface_get_maximized(dsurf) ||
517 geom.width != output->area.width ||
518 geom.height != output->area.height)
521 ivi_layout_activate_complete(output, surf);
525 ivi_layout_desktop_committed(struct ivi_surface *surf)
527 struct weston_desktop_surface *dsurf = surf->dsurface;
528 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
529 struct ivi_policy *policy = surf->ivi->policy;
530 struct ivi_output *output;
531 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
533 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP);
536 * we can't make use here of the ivi_layout_get_output_from_surface()
537 * due to the fact that we'll always land here when a surface performs
538 * a commit and pending_output will not bet set. This works in tandem
539 * with 'mapped' at this point to avoid tripping over
540 * to a surface that continuously updates its content
542 output = surf->desktop.pending_output;
545 struct ivi_output *r_output;
547 if (policy && policy->api.surface_activate_by_default &&
548 !policy->api.surface_activate_by_default(surf, surf->ivi))
551 /* we can only activate it again by using the protocol */
555 /* check first if there aren't any outputs being set */
556 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
559 struct weston_view *view = r_output->fullscreen_view.fs->view;
560 if (view->is_mapped || view->surface->is_mapped)
561 remove_black_curtain(r_output);
565 /* try finding an output with a background and use that */
567 r_output = ivi_layout_find_bg_output(surf->ivi);
569 /* if we couldn't still find an output by this point, there's
570 * something wrong so we abort with a protocol error */
572 wl_resource_post_error(surf->ivi->shell_client.resource,
573 AGL_SHELL_ERROR_INVALID_ARGUMENT,
574 "No valid output found to activate surface by default");
578 if (!surf->ivi->activate_by_default) {
579 weston_log("Refusing to activate surface role %d, app_id %s\n",
582 if (!weston_desktop_surface_get_maximized(dsurf) ||
583 geom.width != r_output->area.width ||
584 geom.height != r_output->area.height)
585 ivi_layout_add_to_hidden_layer(surf, r_output);
590 /* use the output of the bg to activate the app on start-up by
592 if (surf->view && r_output) {
593 if (app_id && r_output) {
594 weston_log("Surface with app_id %s, role %s activating by default\n",
595 weston_desktop_surface_get_app_id(surf->dsurface),
596 ivi_layout_get_surface_role_name(surf));
597 ivi_layout_activate(r_output, app_id);
598 } else if (!app_id) {
600 * applications not setting an app_id, or
601 * setting an app_id but at a later point in
602 * time, might fall-back here so give them a
603 * chance to receive the configure event and
606 weston_log("Surface no app_id, role %s activating by default\n",
607 ivi_layout_get_surface_role_name(surf));
608 ivi_layout_activate_by_surf(r_output, surf);
615 if (!weston_desktop_surface_get_maximized(dsurf) ||
616 geom.width != output->area.width ||
617 geom.height != output->area.height)
620 ivi_layout_activate_complete(output, surf);
624 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
626 struct ivi_compositor *ivi = surface->ivi;
627 struct ivi_policy *policy = ivi->policy;
629 struct weston_desktop_surface *dsurface = surface->dsurface;
630 struct weston_surface *wsurface =
631 weston_desktop_surface_get_surface(dsurface);
632 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
634 struct ivi_output *output = surface->split.output;
635 struct weston_output *woutput = output->output;
636 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
638 struct weston_view *view = surface->view;
639 struct weston_geometry geom =
640 weston_desktop_surface_get_geometry(dsurface);
642 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
643 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
645 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
647 geom.width == bg_output->output->width &&
648 geom.height == bg_output->output->height;
650 if (policy && policy->api.surface_activate_by_default &&
651 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
655 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
658 if (surface->state == FULLSCREEN && weston_view_is_mapped(view))
661 /* if we still get here but we haven't resized so far, send configure
663 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
664 struct ivi_output *bg_output =
665 ivi_layout_find_bg_output(surface->ivi);
667 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
668 app_id, ivi_layout_get_surface_role_name(surface));
669 weston_desktop_surface_set_fullscreen(dsurface, true);
670 weston_desktop_surface_set_size(dsurface,
671 bg_output->output->width,
672 bg_output->output->height);
674 surface->state = RESIZING;
675 weston_view_set_output(view, output->output);
676 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
680 /* eventually, we would set the surface fullscreen, but the client
681 * hasn't resized correctly by this point, so terminate connection */
682 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
683 struct weston_desktop_client *desktop_client =
684 weston_desktop_surface_get_client(dsurface);
685 struct wl_client *client =
686 weston_desktop_client_get_client(desktop_client);
687 wl_client_post_implementation_error(client,
688 "can not display surface due to invalid geometry."
689 " Client should perform a geometry resize!");
693 /* this implies we resized correctly */
694 if (!weston_view_is_mapped(view) || surface->state != FULLSCREEN) {
695 weston_layer_entry_remove(&view->layer_link);
697 weston_view_set_output(view, woutput);
698 weston_view_set_position(view, woutput->x, woutput->y);
699 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
701 wsurface->is_mapped = true;
702 surface->view->is_mapped = true;
703 surface->state = FULLSCREEN;
705 weston_view_geometry_dirty(view);
706 weston_surface_damage(view->surface);
709 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
711 shell_advertise_app_state(ivi, app_id,
712 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
714 weston_log("Activation completed for app_id %s, role %s, "
715 "output %s\n", app_id,
716 ivi_layout_get_surface_role_name(surface),
723 ivi_layout_desktop_resize(struct ivi_surface *surface,
724 struct weston_geometry area)
726 struct weston_desktop_surface *dsurf = surface->dsurface;
727 struct weston_view *view = surface->view;
731 int width = area.width;
732 int height = area.height;
734 weston_desktop_surface_set_size(dsurf,
737 weston_view_set_position(view, x, y);
739 weston_view_geometry_dirty(view);
740 weston_surface_damage(view->surface);
744 ivi_layout_split_committed(struct ivi_surface *surface)
746 struct ivi_compositor *ivi = surface->ivi;
747 struct ivi_policy *policy = ivi->policy;
749 struct weston_desktop_surface *dsurface = surface->dsurface;
750 struct weston_surface *wsurface =
751 weston_desktop_surface_get_surface(dsurface);
752 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
754 struct ivi_output *output = surface->split.output;
755 struct weston_output *woutput = output->output;
757 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
758 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
760 struct weston_view *view = surface->view;
761 struct weston_geometry geom;
769 if (policy && policy->api.surface_activate_by_default &&
770 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
774 if (surface->view->is_mapped)
777 geom = weston_desktop_surface_get_geometry(dsurface);
779 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
780 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
782 /* save the previous area in order to recover it back when if this kind
783 * of surface is being destroyed/removed */
784 output->area_saved = output->area;
786 switch (surface->role) {
787 case IVI_SURFACE_ROLE_SPLIT_V:
788 geom.width = (output->area.width / 2);
790 x += woutput->width - geom.width;
791 output->area.width -= geom.width;
793 width = woutput->width - x;
794 height = output->area.height;
798 case IVI_SURFACE_ROLE_SPLIT_H:
799 geom.height = (output->area.height / 2);
802 output->area.y += geom.height;
803 output->area.height -= geom.height;
805 width = output->area.width;
806 height = output->area.height;
812 assert(!"Invalid split orientation\n");
815 weston_desktop_surface_set_size(dsurface,
818 /* resize the active surface first, output->area already contains
819 * correct area to resize to */
821 ivi_layout_desktop_resize(output->active, output->area);
823 weston_view_set_output(view, woutput);
824 weston_view_set_position(view, x, y);
825 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
827 weston_view_geometry_dirty(view);
828 weston_surface_damage(view->surface);
831 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
833 wsurface->is_mapped = true;
834 surface->view->is_mapped = true;
836 shell_advertise_app_state(ivi, app_id,
837 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
839 weston_log("Activation completed for app_id %s, role %s, output %s\n",
840 app_id, ivi_layout_get_surface_role_name(surface), output->name);
844 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
845 int initial_x, int initial_y, int *new_x, int *new_y)
847 *new_x = output->x + initial_x;
848 *new_y = output->y + initial_y;
853 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface)
855 struct weston_view *ev;
857 wl_list_for_each(ev, &ivi->hidden.view_list.link, layer_link.link) {
858 if (ev == surface->view)
862 wl_list_for_each(ev, &ivi->fullscreen.view_list.link, layer_link.link) {
863 if (ev == surface->view)
871 ivi_layout_popup_committed(struct ivi_surface *surface)
873 struct ivi_compositor *ivi = surface->ivi;
874 struct ivi_policy *policy = ivi->policy;
876 struct weston_desktop_surface *dsurface = surface->dsurface;
877 struct weston_surface *wsurface =
878 weston_desktop_surface_get_surface(dsurface);
879 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
883 struct ivi_output *output = surface->popup.output;
884 struct weston_output *woutput = output->output;
886 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
887 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
889 struct weston_view *view = surface->view;
891 if (policy && policy->api.surface_activate_by_default &&
892 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
896 if (surface->view->is_mapped || surface->state == HIDDEN)
899 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
901 /* remove it from hidden layer if present */
902 if (ivi_surf_in_hidden_layer(ivi, surface))
903 weston_layer_entry_remove(&view->layer_link);
905 weston_view_set_output(view, woutput);
907 ivi_compute_popup_position(woutput, view,
908 surface->popup.x, surface->popup.y, &new_x, &new_y);
909 weston_view_set_position(view, new_x, new_y);
910 weston_view_update_transform(view);
912 /* only clip the pop-up dialog window if we have a valid
913 * width and height being passed on. Users might not want to have one
914 * set-up so only enfore it is really passed on. */
915 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
916 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
917 surface->popup.bb.width, surface->popup.bb.height);
919 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
921 weston_view_geometry_dirty(view);
922 weston_surface_damage(view->surface);
925 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
927 wsurface->is_mapped = true;
928 surface->view->is_mapped = true;
930 shell_advertise_app_state(ivi, app_id,
931 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
933 weston_log("Activation completed for app_id %s, role %s, output %s\n",
934 app_id, ivi_layout_get_surface_role_name(surface), output->name);
938 ivi_layout_popup_re_add(struct ivi_surface *surface)
940 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
941 struct weston_view *view = surface->view;
943 if (weston_view_is_mapped(view)) {
944 struct weston_desktop_surface *dsurface = surface->dsurface;
945 struct weston_surface *wsurface =
946 weston_desktop_surface_get_surface(dsurface);
948 weston_layer_entry_remove(&view->layer_link);
950 wsurface->is_mapped = false;
951 view->is_mapped = false;
954 /* reset the activate by default in order to (still) allow the surface
955 * to be activaved using the request */
956 if (!surface->mapped)
957 surface->mapped = true;
959 surface->state = NORMAL;
960 ivi_layout_popup_committed(surface);
964 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
966 struct ivi_compositor *ivi = surf->ivi;
967 struct ivi_surface *is;
969 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
970 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
971 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
974 /* reset the activate by default in order to (still) allow the surface
975 * to be activaved using the request */
979 wl_list_for_each(is, &ivi->surfaces, link)
987 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
989 struct ivi_compositor *ivi = output->ivi;
990 struct weston_desktop_surface *dsurf;
991 struct weston_geometry geom;
992 struct ivi_policy *policy = output->ivi->policy;
994 dsurf = surf->dsurface;
996 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
1001 if (policy && policy->api.surface_activate &&
1002 !policy->api.surface_activate(surf, surf->ivi)) {
1006 #ifdef AGL_COMP_DEBUG
1007 weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
1008 ivi_layout_get_surface_role_name(surf), output->output->name);
1011 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1012 ivi_layout_popup_re_add(surf);
1016 /* do not 're'-activate surfaces that are split or active */
1017 if (surf == output->active ||
1018 ivi_layout_surface_is_split_or_fullscreen(surf)) {
1019 weston_log("Application %s is already active on output %s\n",
1020 app_id, output->output->name);
1024 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
1025 struct ivi_output *remote_output =
1026 ivi_layout_find_with_app_id(app_id, ivi);
1028 weston_log("Changed activation for app_id %s, type %s, on output %s\n", app_id,
1029 ivi_layout_get_surface_role_name(surf), output->output->name);
1031 /* if already active on a remote output do not
1032 * attempt to activate it again */
1033 if (remote_output && remote_output->active == surf)
1038 geom = weston_desktop_surface_get_geometry(dsurf);
1040 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
1041 surf->desktop.pending_output = output;
1042 if (weston_desktop_surface_get_maximized(dsurf) &&
1043 geom.width == output->area.width &&
1044 geom.height == output->area.height) {
1045 ivi_layout_activate_complete(output, surf);
1049 /* the background surface is already "maximized" so we don't need to
1050 * add to the hidden layer */
1051 if (surf->role == IVI_SURFACE_ROLE_BACKGROUND) {
1052 ivi_layout_activate_complete(output, surf);
1056 ivi_layout_add_to_hidden_layer(surf, output);
1060 ivi_layout_activate(struct ivi_output *output, const char *app_id)
1062 struct ivi_surface *surf;
1063 struct ivi_compositor *ivi = output->ivi;
1068 surf = ivi_find_app(ivi, app_id);
1072 ivi_layout_activate_by_surf(output, surf);
1076 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
1078 struct ivi_output *ivi_output = NULL;
1080 switch (surf->role) {
1081 case IVI_SURFACE_ROLE_DESKTOP:
1082 if (surf->desktop.pending_output)
1083 ivi_output = surf->desktop.pending_output;
1085 ivi_output = surf->desktop.last_output;
1087 case IVI_SURFACE_ROLE_POPUP:
1088 ivi_output = surf->popup.output;
1090 case IVI_SURFACE_ROLE_BACKGROUND:
1091 ivi_output = surf->bg.output;
1093 case IVI_SURFACE_ROLE_PANEL:
1094 ivi_output = surf->panel.output;
1096 case IVI_SURFACE_ROLE_FULLSCREEN:
1097 ivi_output = surf->fullscreen.output;
1099 case IVI_SURFACE_ROLE_SPLIT_H:
1100 case IVI_SURFACE_ROLE_SPLIT_V:
1101 ivi_output = surf->split.output;
1103 case IVI_SURFACE_ROLE_REMOTE:
1104 ivi_output = surf->remote.output;
1106 case IVI_SURFACE_ROLE_NONE:
1115 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
1117 struct ivi_surface *surf;
1118 struct ivi_output *ivi_output;
1119 struct ivi_policy *policy = ivi->policy;
1124 surf = ivi_find_app(ivi, app_id);
1128 if (policy && policy->api.surface_deactivate &&
1129 !policy->api.surface_deactivate(surf, surf->ivi)) {
1133 ivi_output = ivi_layout_get_output_from_surface(surf);
1134 weston_log("Deactiving %s, role %s\n", app_id,
1135 ivi_layout_get_surface_role_name(surf));
1137 if (surf->role == IVI_SURFACE_ROLE_DESKTOP ||
1138 surf->role == IVI_SURFACE_ROLE_REMOTE) {
1139 struct ivi_surface *previous_active;
1141 previous_active = ivi_output->previous_active;
1142 if (!previous_active) {
1143 /* we don't have a previous active it means we should
1145 if (ivi_output->active) {
1146 struct weston_view *view;
1148 view = ivi_output->active->view;
1149 view->is_mapped = false;
1150 view->surface->is_mapped = false;
1152 weston_layer_entry_remove(&view->layer_link);
1153 weston_view_geometry_dirty(view);
1154 weston_surface_damage(view->surface);
1155 ivi_output->active = NULL;
1158 struct weston_desktop_surface *dsurface;
1159 const char *previous_active_app_id;
1161 dsurface = previous_active->dsurface;
1162 previous_active_app_id =
1163 weston_desktop_surface_get_app_id(dsurface);
1164 ivi_layout_activate(ivi_output, previous_active_app_id);
1166 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1167 struct weston_view *view = surf->view;
1169 weston_view_unmap(view);
1170 surf->state = HIDDEN;
1172 weston_layer_entry_remove(&view->layer_link);
1173 weston_view_geometry_dirty(view);
1174 weston_surface_damage(view->surface);
1177 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);