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",
174 weston_log("WARNING: activation-area detected in ini file, "
175 "but agl_shell override detected!\n");
176 if (parse_activation_area(t, output) < 0)
177 weston_log("Invalid activation-area \"%s\" for output %s\n",
183 ivi_background_init(ivi, output);
185 if (output->area_activation.width ||
186 output->area_activation.height ||
187 output->area_activation.x ||
188 output->area_activation.y) {
189 /* Sanity check target area is within output bounds */
190 if ((output->area_activation.x + output->area_activation.width) < output->output->width ||
191 (output->area_activation.y + output->area_activation.height) < output->output->height) {
192 weston_log("Using specified area for output %s, ignoring panels\n",
194 output->area.x = output->area_activation.x;
195 output->area.y = output->area_activation.y;
196 output->area.width = output->area_activation.width;
197 output->area.height = output->area_activation.height;
198 use_default_area = false;
200 weston_log("Invalid activation-area position for output %s, ignoring\n",
204 if (use_default_area) {
207 output->area.width = output->output->width;
208 output->area.height = output->output->height;
210 ivi_panel_init(ivi, output, output->top);
211 ivi_panel_init(ivi, output, output->bottom);
212 ivi_panel_init(ivi, output, output->left);
213 ivi_panel_init(ivi, output, output->right);
216 weston_compositor_schedule_repaint(ivi->compositor);
218 weston_log("Usable area: %dx%d+%d,%d\n",
219 output->area.width, output->area.height,
220 output->area.x, output->area.y);
224 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
226 struct ivi_surface *surf;
229 wl_list_for_each(surf, &ivi->surfaces, link) {
230 id = weston_desktop_surface_get_app_id(surf->dsurface);
231 if (id && strcmp(app_id, id) == 0)
239 ivi_layout_activate_complete(struct ivi_output *output,
240 struct ivi_surface *surf)
242 struct ivi_compositor *ivi = output->ivi;
243 struct weston_output *woutput = output->output;
244 struct weston_view *view = surf->view;
245 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
246 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
247 const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
248 bool update_previous = true;
250 if (weston_view_is_mapped(view)) {
251 weston_layer_entry_remove(&view->layer_link);
253 weston_view_update_transform(view);
256 if (output_has_black_curtain(output)) {
257 if (!output->background) {
258 weston_log("Found that we have no background surface "
259 "for output %s. Using black curtain as background\n",
260 output->output->name);
262 struct weston_view *ev =
263 output->fullscreen_view.fs->view;
265 /* use the black curtain as background when we have
266 * none added by the shell client. */
267 weston_layer_entry_remove(&ev->layer_link);
268 weston_layer_entry_insert(&ivi->normal.view_list,
270 weston_view_geometry_dirty(ev);
271 weston_surface_damage(ev->surface);
273 remove_black_curtain(output);
278 weston_view_set_output(view, woutput);
279 /* drop any previous masks set on this view */
280 weston_view_set_mask_infinite(view);
282 if (surf->role != IVI_SURFACE_ROLE_BACKGROUND)
283 weston_view_set_position(view,
284 woutput->x + output->area.x,
285 woutput->y + output->area.y);
287 view->is_mapped = true;
289 view->surface->is_mapped = true;
291 /* handle a movement from one output to another */
292 if (surf->current_completed_output &&
293 surf->current_completed_output != output) {
295 /* we're migrating the same surface but to another output */
296 if (surf->current_completed_output->active == surf) {
297 struct weston_view *ev =
298 surf->current_completed_output->active->view;
300 weston_layer_entry_remove(&ev->layer_link);
301 surf->current_completed_output->previous_active =
302 surf->current_completed_output->active;
303 surf->current_completed_output->active = NULL;
305 /* damage all possible outputs to avoid stale views */
306 weston_compositor_damage_all(ivi->compositor);
310 if (output->active) {
311 /* keep the background surface mapped at all times */
312 if (output->active->role != IVI_SURFACE_ROLE_BACKGROUND) {
313 output->active->view->is_mapped = false;
314 output->active->view->surface->is_mapped = false;
316 weston_layer_entry_remove(&output->active->view->layer_link);
320 if (output->previous_active && output->active) {
321 const char *c_app_id =
322 weston_desktop_surface_get_app_id(output->active->dsurface);
324 /* if the currently activated app_id is the same as the one
325 * we're trying to complete activation with means we're
326 * operating on the same app_id so do update previous_active as
327 * it will overwrite it with the same value */
328 if (app_id && !strcmp(c_app_id, app_id)) {
329 update_previous = false;
334 output->previous_active = output->active;
335 output->active = surf;
336 surf->current_completed_output = output;
338 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
339 weston_view_geometry_dirty(view);
340 weston_surface_damage(view->surface);
343 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
346 * the 'remote' role now makes use of this part so make sure we don't
347 * trip the enum such that we might end up with a modified output for
350 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
351 if (surf->desktop.pending_output)
352 surf->desktop.last_output = surf->desktop.pending_output;
353 surf->desktop.pending_output = NULL;
356 weston_log("Activation completed for app_id %s, role %s, output %s\n",
358 ivi_layout_get_surface_role_name(surf), output->name);
360 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_ACTIVATED);
364 ivi_layout_find_output_with_app_id(const char *app_id, struct ivi_output *output)
369 cur = output->app_ids;
370 app_id_len = strlen(app_id);
372 while ((cur = strstr(cur, app_id))) {
373 if ((cur[app_id_len] == ',' || cur[app_id_len] == '\0') &&
374 (cur == output->app_ids || cur[-1] == ','))
383 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
385 struct ivi_output *out;
390 wl_list_for_each(out, &ivi->outputs, link) {
394 if (ivi_layout_find_output_with_app_id(app_id, out))
401 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
403 struct ivi_output *out;
405 wl_list_for_each(out, &ivi->outputs, link) {
406 if (out->background &&
407 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
416 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
417 struct ivi_output *ivi_output)
419 struct weston_desktop_surface *dsurf = surf->dsurface;
420 struct weston_view *ev = surf->view;
421 struct ivi_compositor *ivi = surf->ivi;
422 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
425 * If the view isn't mapped, we put it onto the hidden layer so it will
426 * start receiving frame events, and will be able to act on our
429 if (!weston_view_is_mapped(ev)) {
430 ev->is_mapped = true;
431 ev->surface->is_mapped = true;
433 weston_desktop_surface_set_maximized(dsurf, true);
434 weston_desktop_surface_set_size(dsurf,
435 ivi_output->area.width,
436 ivi_output->area.height);
438 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
439 app_id, ivi_layout_get_surface_role_name(surf),
440 ivi_output->area.width, ivi_output->area.height);
442 surf->hidden_layer_output = ivi_output;
443 weston_view_set_output(ev, ivi_output->output);
444 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
445 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
446 app_id, ivi_layout_get_surface_role_name(surf),
447 ivi_output->output->name);
449 weston_compositor_schedule_repaint(ivi->compositor);
453 /* we might have another output to activate */
454 if (surf->hidden_layer_output &&
455 surf->hidden_layer_output != ivi_output) {
456 weston_layer_entry_remove(&ev->layer_link);
457 weston_view_geometry_dirty(ev);
458 weston_surface_damage(ev->surface);
460 if (ivi_output->area.width != surf->hidden_layer_output->area.width ||
461 ivi_output->area.height != surf->hidden_layer_output->area.height) {
462 weston_desktop_surface_set_maximized(dsurf, true);
463 weston_desktop_surface_set_size(dsurf,
464 ivi_output->area.width,
465 ivi_output->area.height);
468 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
469 app_id, ivi_layout_get_surface_role_name(surf),
470 ivi_output->area.width, ivi_output->area.height);
472 surf->hidden_layer_output = ivi_output;
473 weston_view_set_output(ev, ivi_output->output);
474 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
475 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
476 app_id, ivi_layout_get_surface_role_name(surf),
477 ivi_output->output->name);
480 weston_compositor_schedule_repaint(ivi->compositor);
484 ivi_layout_remote_committed(struct ivi_surface *surf)
486 struct weston_desktop_surface *dsurf = surf->dsurface;
487 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
488 struct ivi_policy *policy = surf->ivi->policy;
489 struct ivi_output *output;
490 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
492 assert(surf->role == IVI_SURFACE_ROLE_REMOTE);
494 output = surf->remote.output;
496 if (policy && policy->api.surface_activate_by_default &&
497 !policy->api.surface_activate_by_default(surf, surf->ivi))
500 /* we can only activate it again by using the protocol, but
501 * additionally the output is not reset when
502 * ivi_layout_activate_complete() terminates so we use the
503 * current active surface to avoid hitting this again and again
505 if (surf->mapped && output->active == surf)
508 if (!surf->ivi->activate_by_default &&
509 !ivi_surf_in_hidden_layer(surf->ivi, surf)) {
510 weston_log("Refusing to activate surface role %d, "
511 "app_id %s\n", surf->role, app_id);
513 if (!weston_desktop_surface_get_maximized(dsurf) ||
514 geom.width != output->area.width ||
515 geom.height != output->area.height) {
516 ivi_layout_add_to_hidden_layer(surf, output);
522 if (!weston_desktop_surface_get_maximized(dsurf) ||
523 geom.width != output->area.width ||
524 geom.height != output->area.height)
527 ivi_layout_activate_complete(output, surf);
531 ivi_layout_desktop_committed(struct ivi_surface *surf)
533 struct weston_desktop_surface *dsurf = surf->dsurface;
534 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
535 struct ivi_policy *policy = surf->ivi->policy;
536 struct ivi_output *output;
537 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
539 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP);
542 * we can't make use here of the ivi_layout_get_output_from_surface()
543 * due to the fact that we'll always land here when a surface performs
544 * a commit and pending_output will not bet set. This works in tandem
545 * with 'mapped' at this point to avoid tripping over
546 * to a surface that continuously updates its content
548 output = surf->desktop.pending_output;
551 struct ivi_output *r_output;
553 if (policy && policy->api.surface_activate_by_default &&
554 !policy->api.surface_activate_by_default(surf, surf->ivi))
557 /* we can only activate it again by using the protocol */
561 /* check first if there aren't any outputs being set */
562 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
565 struct weston_view *view = r_output->fullscreen_view.fs->view;
566 if (view->is_mapped || view->surface->is_mapped)
567 remove_black_curtain(r_output);
571 /* try finding an output with a background and use that */
573 r_output = ivi_layout_find_bg_output(surf->ivi);
575 /* if we couldn't still find an output by this point, there's
576 * something wrong so we abort with a protocol error */
578 wl_resource_post_error(surf->ivi->shell_client.resource,
579 AGL_SHELL_ERROR_INVALID_ARGUMENT,
580 "No valid output found to activate surface by default");
584 if (!surf->ivi->activate_by_default &&
585 (!surf->xwayland.is_set && !is_shell_surface_xwayland(surf))) {
586 weston_log("Refusing to activate surface role %d, app_id %s, type %s\n",
588 is_shell_surface_xwayland(surf) ?
589 "xwayland" : "regular");
591 if (!weston_desktop_surface_get_maximized(dsurf) ||
592 geom.width != r_output->area.width ||
593 geom.height != r_output->area.height)
594 ivi_layout_add_to_hidden_layer(surf, r_output);
599 /* use the output of the bg to activate the app on start-up by
601 if (surf->view && r_output) {
602 if (app_id && r_output) {
603 weston_log("Surface with app_id %s, role %s activating by default\n",
604 weston_desktop_surface_get_app_id(surf->dsurface),
605 ivi_layout_get_surface_role_name(surf));
606 ivi_layout_activate(r_output, app_id);
607 } else if (!app_id) {
609 * applications not setting an app_id, or
610 * setting an app_id but at a later point in
611 * time, might fall-back here so give them a
612 * chance to receive the configure event and
615 weston_log("Surface no app_id, role %s activating by default\n",
616 ivi_layout_get_surface_role_name(surf));
617 if (surf->xwayland.is_set || is_shell_surface_xwayland(surf)) {
618 ivi_layout_activate_by_surf(r_output, surf);
619 ivi_layout_activate_complete(r_output, surf);
621 ivi_layout_activate_by_surf(r_output, surf);
629 if (!weston_desktop_surface_get_maximized(dsurf) ||
630 geom.width != output->area.width ||
631 geom.height != output->area.height)
634 ivi_layout_activate_complete(output, surf);
638 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
640 struct ivi_compositor *ivi = surface->ivi;
641 struct ivi_policy *policy = ivi->policy;
643 struct weston_desktop_surface *dsurface = surface->dsurface;
644 struct weston_surface *wsurface =
645 weston_desktop_surface_get_surface(dsurface);
646 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
648 struct ivi_output *output = surface->split.output;
649 struct weston_output *woutput = output->output;
650 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
652 struct weston_view *view = surface->view;
653 struct weston_geometry geom =
654 weston_desktop_surface_get_geometry(dsurface);
656 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
657 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
659 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
661 geom.width == bg_output->output->width &&
662 geom.height == bg_output->output->height;
664 if (policy && policy->api.surface_activate_by_default &&
665 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
669 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
672 if (surface->state == FULLSCREEN && weston_view_is_mapped(view))
675 /* if we still get here but we haven't resized so far, send configure
677 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
678 struct ivi_output *bg_output =
679 ivi_layout_find_bg_output(surface->ivi);
681 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
682 app_id, ivi_layout_get_surface_role_name(surface));
683 weston_desktop_surface_set_fullscreen(dsurface, true);
684 weston_desktop_surface_set_size(dsurface,
685 bg_output->output->width,
686 bg_output->output->height);
688 surface->state = RESIZING;
689 weston_view_set_output(view, output->output);
690 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
694 /* eventually, we would set the surface fullscreen, but the client
695 * hasn't resized correctly by this point, so terminate connection */
696 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
697 struct weston_desktop_client *desktop_client =
698 weston_desktop_surface_get_client(dsurface);
699 struct wl_client *client =
700 weston_desktop_client_get_client(desktop_client);
701 wl_client_post_implementation_error(client,
702 "can not display surface due to invalid geometry."
703 " Client should perform a geometry resize!");
707 /* this implies we resized correctly */
708 if (!weston_view_is_mapped(view) || surface->state != FULLSCREEN) {
709 weston_layer_entry_remove(&view->layer_link);
711 weston_view_set_output(view, woutput);
712 weston_view_set_position(view, woutput->x, woutput->y);
713 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
715 wsurface->is_mapped = true;
716 surface->view->is_mapped = true;
717 surface->state = FULLSCREEN;
719 weston_view_geometry_dirty(view);
720 weston_surface_damage(view->surface);
723 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
725 shell_advertise_app_state(ivi, app_id,
726 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
728 weston_log("Activation completed for app_id %s, role %s, "
729 "output %s\n", app_id,
730 ivi_layout_get_surface_role_name(surface),
737 ivi_layout_desktop_resize(struct ivi_surface *surface,
738 struct weston_geometry area)
740 struct weston_desktop_surface *dsurf = surface->dsurface;
741 struct weston_view *view = surface->view;
745 int width = area.width;
746 int height = area.height;
748 weston_desktop_surface_set_size(dsurf,
751 weston_view_set_position(view, x, y);
753 weston_view_geometry_dirty(view);
754 weston_surface_damage(view->surface);
758 ivi_layout_split_committed(struct ivi_surface *surface)
760 struct ivi_compositor *ivi = surface->ivi;
761 struct ivi_policy *policy = ivi->policy;
763 struct weston_desktop_surface *dsurface = surface->dsurface;
764 struct weston_surface *wsurface =
765 weston_desktop_surface_get_surface(dsurface);
766 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
768 struct ivi_output *output = surface->split.output;
769 struct weston_output *woutput = output->output;
771 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
772 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
774 struct weston_view *view = surface->view;
775 struct weston_geometry geom;
783 if (policy && policy->api.surface_activate_by_default &&
784 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
788 if (surface->view->is_mapped)
791 geom = weston_desktop_surface_get_geometry(dsurface);
793 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
794 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
796 /* save the previous area in order to recover it back when if this kind
797 * of surface is being destroyed/removed */
798 output->area_saved = output->area;
800 switch (surface->role) {
801 case IVI_SURFACE_ROLE_SPLIT_V:
802 geom.width = (output->area.width / 2);
804 x += woutput->width - geom.width;
805 output->area.width -= geom.width;
807 width = woutput->width - x;
808 height = output->area.height;
812 case IVI_SURFACE_ROLE_SPLIT_H:
813 geom.height = (output->area.height / 2);
816 output->area.y += geom.height;
817 output->area.height -= geom.height;
819 width = output->area.width;
820 height = output->area.height;
826 assert(!"Invalid split orientation\n");
829 weston_desktop_surface_set_size(dsurface,
832 /* resize the active surface first, output->area already contains
833 * correct area to resize to */
835 ivi_layout_desktop_resize(output->active, output->area);
837 weston_view_set_output(view, woutput);
838 weston_view_set_position(view, x, y);
839 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
841 weston_view_geometry_dirty(view);
842 weston_surface_damage(view->surface);
845 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
847 wsurface->is_mapped = true;
848 surface->view->is_mapped = true;
850 shell_advertise_app_state(ivi, app_id,
851 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
853 weston_log("Activation completed for app_id %s, role %s, output %s\n",
854 app_id, ivi_layout_get_surface_role_name(surface), output->name);
858 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
859 int initial_x, int initial_y, int *new_x, int *new_y)
861 *new_x = output->x + initial_x;
862 *new_y = output->y + initial_y;
867 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface)
869 struct weston_view *ev;
871 wl_list_for_each(ev, &ivi->hidden.view_list.link, layer_link.link) {
872 if (ev == surface->view)
876 wl_list_for_each(ev, &ivi->fullscreen.view_list.link, layer_link.link) {
877 if (ev == surface->view)
885 ivi_layout_popup_committed(struct ivi_surface *surface)
887 struct ivi_compositor *ivi = surface->ivi;
888 struct ivi_policy *policy = ivi->policy;
890 struct weston_desktop_surface *dsurface = surface->dsurface;
891 struct weston_surface *wsurface =
892 weston_desktop_surface_get_surface(dsurface);
893 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
897 struct ivi_output *output = surface->popup.output;
898 struct weston_output *woutput = output->output;
900 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
901 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
903 struct weston_view *view = surface->view;
905 if (policy && policy->api.surface_activate_by_default &&
906 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
910 if (surface->view->is_mapped || surface->state == HIDDEN)
913 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
915 /* remove it from hidden layer if present */
916 if (ivi_surf_in_hidden_layer(ivi, surface))
917 weston_layer_entry_remove(&view->layer_link);
919 weston_view_set_output(view, woutput);
921 ivi_compute_popup_position(woutput, view,
922 surface->popup.x, surface->popup.y, &new_x, &new_y);
923 weston_view_set_position(view, new_x, new_y);
924 weston_view_update_transform(view);
926 /* only clip the pop-up dialog window if we have a valid
927 * width and height being passed on. Users might not want to have one
928 * set-up so only enfore it is really passed on. */
929 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
930 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
931 surface->popup.bb.width, surface->popup.bb.height);
933 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
935 weston_view_geometry_dirty(view);
936 weston_surface_damage(view->surface);
939 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
941 wsurface->is_mapped = true;
942 surface->view->is_mapped = true;
944 shell_advertise_app_state(ivi, app_id,
945 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
947 weston_log("Activation completed for app_id %s, role %s, output %s\n",
948 app_id, ivi_layout_get_surface_role_name(surface), output->name);
952 ivi_layout_popup_re_add(struct ivi_surface *surface)
954 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
955 struct weston_view *view = surface->view;
957 if (weston_view_is_mapped(view)) {
958 struct weston_desktop_surface *dsurface = surface->dsurface;
959 struct weston_surface *wsurface =
960 weston_desktop_surface_get_surface(dsurface);
962 weston_layer_entry_remove(&view->layer_link);
964 wsurface->is_mapped = false;
965 view->is_mapped = false;
968 /* reset the activate by default in order to (still) allow the surface
969 * to be activaved using the request */
970 if (!surface->mapped)
971 surface->mapped = true;
973 surface->state = NORMAL;
974 ivi_layout_popup_committed(surface);
978 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
980 struct ivi_compositor *ivi = surf->ivi;
981 struct ivi_surface *is;
983 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
984 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
985 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
988 /* reset the activate by default in order to (still) allow the surface
989 * to be activaved using the request */
993 wl_list_for_each(is, &ivi->surfaces, link)
1001 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
1003 struct ivi_compositor *ivi = output->ivi;
1004 struct weston_desktop_surface *dsurf;
1005 struct weston_geometry geom;
1006 struct ivi_policy *policy = output->ivi->policy;
1008 dsurf = surf->dsurface;
1010 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
1015 if (policy && policy->api.surface_activate &&
1016 !policy->api.surface_activate(surf, surf->ivi)) {
1020 #ifdef AGL_COMP_DEBUG
1021 weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
1022 ivi_layout_get_surface_role_name(surf), output->output->name);
1025 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1026 ivi_layout_popup_re_add(surf);
1030 /* do not 're'-activate surfaces that are split or active */
1031 if (surf == output->active ||
1032 ivi_layout_surface_is_split_or_fullscreen(surf)) {
1033 weston_log("Application %s is already active on output %s\n",
1034 app_id, output->output->name);
1038 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
1039 struct ivi_output *remote_output =
1040 ivi_layout_find_with_app_id(app_id, ivi);
1042 weston_log("Changed activation for app_id %s, type %s, on output %s\n", app_id,
1043 ivi_layout_get_surface_role_name(surf), output->output->name);
1045 /* if already active on a remote output do not
1046 * attempt to activate it again */
1047 if (remote_output && remote_output->active == surf)
1052 geom = weston_desktop_surface_get_geometry(dsurf);
1054 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
1055 surf->desktop.pending_output = output;
1056 if (weston_desktop_surface_get_maximized(dsurf) &&
1057 geom.width == output->area.width &&
1058 geom.height == output->area.height) {
1059 ivi_layout_activate_complete(output, surf);
1063 /* the background surface is already "maximized" so we don't need to
1064 * add to the hidden layer */
1065 if (surf->role == IVI_SURFACE_ROLE_BACKGROUND) {
1066 ivi_layout_activate_complete(output, surf);
1070 ivi_layout_add_to_hidden_layer(surf, output);
1074 ivi_layout_activate(struct ivi_output *output, const char *app_id)
1076 struct ivi_surface *surf;
1077 struct ivi_compositor *ivi = output->ivi;
1082 surf = ivi_find_app(ivi, app_id);
1086 ivi_layout_activate_by_surf(output, surf);
1090 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
1092 struct ivi_output *ivi_output = NULL;
1094 switch (surf->role) {
1095 case IVI_SURFACE_ROLE_DESKTOP:
1096 if (surf->desktop.pending_output)
1097 ivi_output = surf->desktop.pending_output;
1099 ivi_output = surf->desktop.last_output;
1101 case IVI_SURFACE_ROLE_POPUP:
1102 ivi_output = surf->popup.output;
1104 case IVI_SURFACE_ROLE_BACKGROUND:
1105 ivi_output = surf->bg.output;
1107 case IVI_SURFACE_ROLE_PANEL:
1108 ivi_output = surf->panel.output;
1110 case IVI_SURFACE_ROLE_FULLSCREEN:
1111 ivi_output = surf->fullscreen.output;
1113 case IVI_SURFACE_ROLE_SPLIT_H:
1114 case IVI_SURFACE_ROLE_SPLIT_V:
1115 ivi_output = surf->split.output;
1117 case IVI_SURFACE_ROLE_REMOTE:
1118 ivi_output = surf->remote.output;
1120 case IVI_SURFACE_ROLE_NONE:
1129 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
1131 struct ivi_surface *surf;
1132 struct ivi_output *ivi_output;
1133 struct ivi_policy *policy = ivi->policy;
1138 surf = ivi_find_app(ivi, app_id);
1142 if (policy && policy->api.surface_deactivate &&
1143 !policy->api.surface_deactivate(surf, surf->ivi)) {
1147 ivi_output = ivi_layout_get_output_from_surface(surf);
1148 weston_log("Deactiving %s, role %s\n", app_id,
1149 ivi_layout_get_surface_role_name(surf));
1151 if (surf->role == IVI_SURFACE_ROLE_DESKTOP ||
1152 surf->role == IVI_SURFACE_ROLE_REMOTE) {
1153 struct ivi_surface *previous_active;
1155 previous_active = ivi_output->previous_active;
1156 if (!previous_active) {
1157 /* we don't have a previous active it means we should
1159 if (ivi_output->active) {
1160 struct weston_view *view;
1162 view = ivi_output->active->view;
1163 view->is_mapped = false;
1164 view->surface->is_mapped = false;
1166 weston_layer_entry_remove(&view->layer_link);
1167 weston_view_geometry_dirty(view);
1168 weston_surface_damage(view->surface);
1169 ivi_output->active = NULL;
1172 struct weston_desktop_surface *dsurface;
1173 const char *previous_active_app_id;
1175 dsurface = previous_active->dsurface;
1176 previous_active_app_id =
1177 weston_desktop_surface_get_app_id(dsurface);
1178 ivi_layout_activate(ivi_output, previous_active_app_id);
1180 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1181 struct weston_view *view = surf->view;
1183 weston_view_unmap(view);
1184 surf->state = HIDDEN;
1186 weston_layer_entry_remove(&view->layer_link);
1187 weston_view_geometry_dirty(view);
1188 weston_surface_damage(view->surface);
1191 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);