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",
51 [IVI_SURFACE_ROLE_TILE] = "SPLIT",
55 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface);
58 ivi_layout_get_surface_role_name(struct ivi_surface *surf)
60 if (surf->role < 0 || surf->role >= ARRAY_LENGTH(ivi_roles_as_string))
61 return " unknown surface role";
63 return ivi_roles_as_string[surf->role];
67 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
69 struct weston_output *woutput = output->output;
70 struct ivi_surface *bg = output->background;
71 struct weston_view *view;
74 weston_log("WARNING: Output does not have a background\n");
78 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
82 weston_view_set_output(view, woutput);
83 weston_view_set_position(view, woutput->x, woutput->y);
85 weston_log("(background) position view %p, x %d, y %d, on output %s\n", view,
86 woutput->x, woutput->y, output->name);
88 view->is_mapped = true;
89 view->surface->is_mapped = true;
91 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
95 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
96 struct ivi_surface *panel)
98 struct weston_output *woutput = output->output;
99 struct weston_desktop_surface *dsurface;
100 struct weston_view *view;
101 struct weston_geometry geom;
108 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
109 dsurface = panel->dsurface;
111 geom = weston_desktop_surface_get_geometry(dsurface);
113 weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
114 geom.width, geom.height, geom.x, geom.y);
116 switch (panel->panel.edge) {
117 case AGL_SHELL_EDGE_TOP:
118 output->area.y += geom.height;
119 output->area.height -= geom.height;
121 case AGL_SHELL_EDGE_BOTTOM:
122 y += woutput->height - geom.height;
123 output->area.height -= geom.height;
125 case AGL_SHELL_EDGE_LEFT:
126 output->area.x += geom.width;
127 output->area.width -= geom.width;
129 case AGL_SHELL_EDGE_RIGHT:
130 x += woutput->width - geom.width;
131 output->area.width -= geom.width;
138 weston_view_set_output(view, woutput);
139 weston_view_set_position(view, x, y);
141 weston_log("(panel) edge %d position view %p, x %d, y %d\n",
142 panel->panel.edge, view, x, y);
144 view->is_mapped = true;
145 view->surface->is_mapped = true;
147 weston_log("panel type %d inited on output %s\n", panel->panel.edge,
150 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
154 * Initializes all static parts of the layout, i.e. the background and panels.
157 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
159 bool use_default_area = true;
160 struct weston_config_section *section = output->config;
163 weston_config_section_get_string(section, "activation-area", &t, NULL);
165 if (output->area_activation.width == 0 &&
166 output->area_activation.height == 0 &&
167 output->area_activation.x == 0 &&
168 output->area_activation.y == 0) {
169 weston_log("WARNING: activation-area set in "
170 "configuration file, but yet applied!\n");
171 if (parse_activation_area(t, output) < 0)
172 weston_log("Invalid activation-area \"%s\" for output %s\n",
175 weston_log("WARNING: activation-area detected in ini file, "
176 "but agl_shell override detected!\n");
177 if (parse_activation_area(t, output) < 0)
178 weston_log("Invalid activation-area \"%s\" for output %s\n",
184 ivi_background_init(ivi, output);
186 if (output->area_activation.width ||
187 output->area_activation.height ||
188 output->area_activation.x ||
189 output->area_activation.y) {
190 /* Sanity check target area is within output bounds */
191 if ((output->area_activation.x + output->area_activation.width) < output->output->width ||
192 (output->area_activation.y + output->area_activation.height) < output->output->height) {
193 weston_log("Using specified area for output %s, ignoring panels\n",
195 output->area.x = output->area_activation.x;
196 output->area.y = output->area_activation.y;
197 output->area.width = output->area_activation.width;
198 output->area.height = output->area_activation.height;
199 use_default_area = false;
201 weston_log("Invalid activation-area position for output %s, ignoring\n",
205 if (use_default_area) {
208 output->area.width = output->output->width;
209 output->area.height = output->output->height;
211 ivi_panel_init(ivi, output, output->top);
212 ivi_panel_init(ivi, output, output->bottom);
213 ivi_panel_init(ivi, output, output->left);
214 ivi_panel_init(ivi, output, output->right);
217 weston_compositor_schedule_repaint(ivi->compositor);
219 weston_log("Usable area: %dx%d+%d,%d\n",
220 output->area.width, output->area.height,
221 output->area.x, output->area.y);
225 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
227 struct ivi_surface *surf;
230 wl_list_for_each(surf, &ivi->surfaces, link) {
231 id = weston_desktop_surface_get_app_id(surf->dsurface);
232 if (id && strcmp(app_id, id) == 0)
240 ivi_layout_activate_complete(struct ivi_output *output,
241 struct ivi_surface *surf)
243 struct ivi_compositor *ivi = output->ivi;
244 struct weston_output *woutput = output->output;
245 struct weston_view *view = surf->view;
246 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
247 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
248 const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
249 bool update_previous = true;
251 if (weston_view_is_mapped(view)) {
252 weston_layer_entry_remove(&view->layer_link);
254 weston_view_update_transform(view);
257 if (output_has_black_curtain(output)) {
258 if (!output->background) {
259 weston_log("Found that we have no background surface "
260 "for output %s. Using black curtain as background\n",
261 output->output->name);
263 struct weston_view *ev =
264 output->fullscreen_view.fs->view;
266 /* use the black curtain as background when we have
267 * none added by the shell client. */
268 weston_layer_entry_remove(&ev->layer_link);
269 weston_layer_entry_insert(&ivi->normal.view_list,
271 weston_view_geometry_dirty(ev);
272 weston_surface_damage(ev->surface);
274 remove_black_curtain(output);
279 weston_view_set_output(view, woutput);
280 /* drop any previous masks set on this view */
281 weston_view_set_mask_infinite(view);
283 if (surf->role != IVI_SURFACE_ROLE_BACKGROUND)
284 weston_view_set_position(view,
285 woutput->x + output->area.x,
286 woutput->y + output->area.y);
288 /* reset any previous orientation */
289 if (surf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
290 weston_log("%s() resetting itself to none orientation\n", __func__);
291 surf->orientation = AGL_SHELL_TILE_ORIENTATION_NONE;
292 weston_desktop_surface_set_orientation(surf->dsurface,
295 view->is_mapped = true;
297 view->surface->is_mapped = true;
299 /* handle a movement from one output to another */
300 if (surf->current_completed_output &&
301 surf->current_completed_output != output) {
303 /* we're migrating the same surface but to another output */
304 if (surf->current_completed_output->active == surf) {
305 struct weston_view *ev =
306 surf->current_completed_output->active->view;
308 weston_layer_entry_remove(&ev->layer_link);
309 surf->current_completed_output->previous_active =
310 surf->current_completed_output->active;
311 surf->current_completed_output->active = NULL;
313 /* damage all possible outputs to avoid stale views */
314 weston_compositor_damage_all(ivi->compositor);
318 if (output->active) {
319 /* keep the background surface mapped at all times */
320 if (output->active->role != IVI_SURFACE_ROLE_BACKGROUND) {
321 output->active->view->is_mapped = false;
322 output->active->view->surface->is_mapped = false;
324 weston_layer_entry_remove(&output->active->view->layer_link);
328 if (output->previous_active && output->active) {
329 const char *c_app_id =
330 weston_desktop_surface_get_app_id(output->active->dsurface);
332 /* if the currently activated app_id is the same as the one
333 * we're trying to complete activation with means we're
334 * operating on the same app_id so do update previous_active as
335 * it will overwrite it with the same value */
336 if (app_id && !strcmp(c_app_id, app_id)) {
337 update_previous = false;
342 output->previous_active = output->active;
343 output->active = surf;
344 surf->current_completed_output = output;
346 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
347 weston_view_geometry_dirty(view);
348 weston_surface_damage(view->surface);
351 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
354 * the 'remote' role now makes use of this part so make sure we don't
355 * trip the enum such that we might end up with a modified output for
358 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
359 if (surf->desktop.pending_output)
360 surf->desktop.last_output = surf->desktop.pending_output;
361 surf->desktop.pending_output = NULL;
364 weston_log("Activation completed for app_id %s, role %s, output %s\n",
366 ivi_layout_get_surface_role_name(surf), output->name);
368 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_ACTIVATED);
372 ivi_layout_find_output_with_app_id(const char *app_id, struct ivi_output *output)
377 cur = output->app_ids;
378 app_id_len = strlen(app_id);
380 while ((cur = strstr(cur, app_id))) {
381 if ((cur[app_id_len] == ',' || cur[app_id_len] == '\0') &&
382 (cur == output->app_ids || cur[-1] == ','))
391 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
393 struct ivi_output *out;
398 wl_list_for_each(out, &ivi->outputs, link) {
402 if (ivi_layout_find_output_with_app_id(app_id, out))
409 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
411 struct ivi_output *out;
413 wl_list_for_each(out, &ivi->outputs, link) {
414 if (out->background &&
415 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
424 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
425 struct ivi_output *ivi_output)
427 struct weston_desktop_surface *dsurf = surf->dsurface;
428 struct weston_view *ev = surf->view;
429 struct ivi_compositor *ivi = surf->ivi;
430 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
433 * If the view isn't mapped, we put it onto the hidden layer so it will
434 * start receiving frame events, and will be able to act on our
437 if (!weston_view_is_mapped(ev)) {
438 ev->is_mapped = true;
439 ev->surface->is_mapped = true;
441 weston_desktop_surface_set_maximized(dsurf, true);
442 weston_desktop_surface_set_size(dsurf,
443 ivi_output->area.width,
444 ivi_output->area.height);
446 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
447 app_id, ivi_layout_get_surface_role_name(surf),
448 ivi_output->area.width, ivi_output->area.height);
450 surf->hidden_layer_output = ivi_output;
451 weston_view_set_output(ev, ivi_output->output);
452 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
453 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
454 app_id, ivi_layout_get_surface_role_name(surf),
455 ivi_output->output->name);
457 weston_compositor_schedule_repaint(ivi->compositor);
461 /* we might have another output to activate */
462 if (surf->hidden_layer_output &&
463 surf->hidden_layer_output != ivi_output) {
464 weston_layer_entry_remove(&ev->layer_link);
465 weston_view_geometry_dirty(ev);
466 weston_surface_damage(ev->surface);
468 if (ivi_output->area.width != surf->hidden_layer_output->area.width ||
469 ivi_output->area.height != surf->hidden_layer_output->area.height) {
470 weston_desktop_surface_set_maximized(dsurf, true);
471 weston_desktop_surface_set_size(dsurf,
472 ivi_output->area.width,
473 ivi_output->area.height);
476 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
477 app_id, ivi_layout_get_surface_role_name(surf),
478 ivi_output->area.width, ivi_output->area.height);
480 surf->hidden_layer_output = ivi_output;
481 weston_view_set_output(ev, ivi_output->output);
482 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
483 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
484 app_id, ivi_layout_get_surface_role_name(surf),
485 ivi_output->output->name);
488 weston_compositor_schedule_repaint(ivi->compositor);
492 ivi_layout_remote_committed(struct ivi_surface *surf)
494 struct weston_desktop_surface *dsurf = surf->dsurface;
495 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
496 struct ivi_policy *policy = surf->ivi->policy;
497 struct ivi_output *output;
498 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
500 assert(surf->role == IVI_SURFACE_ROLE_REMOTE);
502 output = surf->remote.output;
504 if (policy && policy->api.surface_activate_by_default &&
505 !policy->api.surface_activate_by_default(surf, surf->ivi))
508 /* we can only activate it again by using the protocol, but
509 * additionally the output is not reset when
510 * ivi_layout_activate_complete() terminates so we use the
511 * current active surface to avoid hitting this again and again
513 if (surf->mapped && output->active == surf)
516 if (!surf->ivi->activate_by_default &&
517 !ivi_surf_in_hidden_layer(surf->ivi, surf)) {
518 weston_log("Refusing to activate surface role %d, "
519 "app_id %s\n", surf->role, app_id);
521 if (!weston_desktop_surface_get_maximized(dsurf) ||
522 geom.width != output->area.width ||
523 geom.height != output->area.height) {
524 ivi_layout_add_to_hidden_layer(surf, output);
530 if (!weston_desktop_surface_get_maximized(dsurf) ||
531 geom.width != output->area.width ||
532 geom.height != output->area.height)
535 ivi_layout_activate_complete(output, surf);
539 ivi_layout_desktop_committed(struct ivi_surface *surf)
541 struct weston_desktop_surface *dsurf = surf->dsurface;
542 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
543 struct ivi_policy *policy = surf->ivi->policy;
544 struct ivi_output *output;
545 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
547 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP);
550 * we can't make use here of the ivi_layout_get_output_from_surface()
551 * due to the fact that we'll always land here when a surface performs
552 * a commit and pending_output will not bet set. This works in tandem
553 * with 'mapped' at this point to avoid tripping over
554 * to a surface that continuously updates its content
556 output = surf->desktop.pending_output;
559 struct ivi_output *r_output;
561 if (policy && policy->api.surface_activate_by_default &&
562 !policy->api.surface_activate_by_default(surf, surf->ivi))
565 /* we can only activate it again by using the protocol */
569 /* check first if there aren't any outputs being set */
570 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
573 struct weston_view *view = r_output->fullscreen_view.fs->view;
574 if (view->is_mapped || view->surface->is_mapped)
575 remove_black_curtain(r_output);
579 /* try finding an output with a background and use that */
581 r_output = ivi_layout_find_bg_output(surf->ivi);
583 /* if we couldn't still find an output by this point, there's
584 * something wrong so we abort with a protocol error */
586 wl_resource_post_error(surf->ivi->shell_client.resource,
587 AGL_SHELL_ERROR_INVALID_ARGUMENT,
588 "No valid output found to activate surface by default");
592 if (!surf->ivi->activate_by_default &&
593 (!surf->xwayland.is_set && !is_shell_surface_xwayland(surf))) {
594 weston_log("Refusing to activate surface role %d, app_id %s, type %s\n",
596 is_shell_surface_xwayland(surf) ?
597 "xwayland" : "regular");
599 if (!weston_desktop_surface_get_maximized(dsurf) ||
600 geom.width != r_output->area.width ||
601 geom.height != r_output->area.height)
602 ivi_layout_add_to_hidden_layer(surf, r_output);
607 /* use the output of the bg to activate the app on start-up by
609 if (surf->view && r_output) {
610 if (app_id && r_output) {
611 weston_log("Surface with app_id %s, role %s activating by default\n",
612 weston_desktop_surface_get_app_id(surf->dsurface),
613 ivi_layout_get_surface_role_name(surf));
614 ivi_layout_activate(r_output, app_id);
615 } else if (!app_id) {
617 * applications not setting an app_id, or
618 * setting an app_id but at a later point in
619 * time, might fall-back here so give them a
620 * chance to receive the configure event and
623 weston_log("Surface no app_id, role %s activating by default\n",
624 ivi_layout_get_surface_role_name(surf));
625 if (surf->xwayland.is_set || is_shell_surface_xwayland(surf)) {
626 ivi_layout_activate_by_surf(r_output, surf);
627 ivi_layout_activate_complete(r_output, surf);
629 ivi_layout_activate_by_surf(r_output, surf);
637 if (!weston_desktop_surface_get_maximized(dsurf) ||
638 geom.width != output->area.width ||
639 geom.height != output->area.height)
642 ivi_layout_activate_complete(output, surf);
646 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
648 struct ivi_compositor *ivi = surface->ivi;
649 struct ivi_policy *policy = ivi->policy;
651 struct weston_desktop_surface *dsurface = surface->dsurface;
652 struct weston_surface *wsurface =
653 weston_desktop_surface_get_surface(dsurface);
654 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
656 struct ivi_output *output = surface->split.output;
657 struct weston_output *woutput = output->output;
658 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
660 struct weston_view *view = surface->view;
661 struct weston_geometry geom =
662 weston_desktop_surface_get_geometry(dsurface);
664 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
665 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
667 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
669 geom.width == bg_output->output->width &&
670 geom.height == bg_output->output->height;
672 if (policy && policy->api.surface_activate_by_default &&
673 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
677 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
680 if (surface->state == FULLSCREEN && weston_view_is_mapped(view))
683 /* if we still get here but we haven't resized so far, send configure
685 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
686 struct ivi_output *bg_output =
687 ivi_layout_find_bg_output(surface->ivi);
689 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
690 app_id, ivi_layout_get_surface_role_name(surface));
691 weston_desktop_surface_set_fullscreen(dsurface, true);
692 weston_desktop_surface_set_size(dsurface,
693 bg_output->output->width,
694 bg_output->output->height);
696 surface->state = RESIZING;
697 weston_view_set_output(view, output->output);
698 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
702 /* eventually, we would set the surface fullscreen, but the client
703 * hasn't resized correctly by this point, so terminate connection */
704 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
705 struct weston_desktop_client *desktop_client =
706 weston_desktop_surface_get_client(dsurface);
707 struct wl_client *client =
708 weston_desktop_client_get_client(desktop_client);
709 wl_client_post_implementation_error(client,
710 "can not display surface due to invalid geometry."
711 " Client should perform a geometry resize!");
715 /* this implies we resized correctly */
716 if (!weston_view_is_mapped(view) || surface->state != FULLSCREEN) {
717 weston_layer_entry_remove(&view->layer_link);
719 weston_view_set_output(view, woutput);
720 weston_view_set_position(view, woutput->x, woutput->y);
721 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
723 wsurface->is_mapped = true;
724 surface->view->is_mapped = true;
725 surface->state = FULLSCREEN;
727 weston_view_geometry_dirty(view);
728 weston_surface_damage(view->surface);
731 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
733 shell_advertise_app_state(ivi, app_id,
734 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
736 weston_log("Activation completed for app_id %s, role %s, "
737 "output %s\n", app_id,
738 ivi_layout_get_surface_role_name(surface),
741 weston_compositor_schedule_repaint(ivi->compositor);
746 ivi_layout_desktop_resize(struct ivi_surface *surface,
747 struct weston_geometry area)
749 struct weston_desktop_surface *dsurf = surface->dsurface;
750 struct weston_view *view = surface->view;
754 int width = area.width;
755 int height = area.height;
757 weston_desktop_surface_set_size(dsurf,
760 weston_view_set_position(view, x, y);
762 weston_view_geometry_dirty(view);
763 weston_surface_damage(view->surface);
767 ivi_layout_split_committed(struct ivi_surface *surface)
769 struct ivi_compositor *ivi = surface->ivi;
770 struct ivi_policy *policy = ivi->policy;
772 struct weston_desktop_surface *dsurface = surface->dsurface;
773 struct weston_surface *wsurface =
774 weston_desktop_surface_get_surface(dsurface);
775 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
777 struct ivi_output *output = surface->split.output;
778 struct weston_output *woutput = output->output;
780 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
781 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
783 struct weston_view *view = surface->view;
784 struct weston_geometry geom;
792 if (policy && policy->api.surface_activate_by_default &&
793 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
797 if (surface->view->is_mapped)
800 geom = weston_desktop_surface_get_geometry(dsurface);
802 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
803 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
805 /* save the previous area in order to recover it back when if this kind
806 * of surface is being destroyed/removed */
807 output->area_saved = output->area;
809 switch (surface->role) {
810 case IVI_SURFACE_ROLE_SPLIT_V:
811 geom.width = (output->area.width / 2);
813 x += woutput->width - geom.width;
814 output->area.width -= geom.width;
816 width = woutput->width - x;
817 height = output->area.height;
821 case IVI_SURFACE_ROLE_SPLIT_H:
822 geom.height = (output->area.height / 2);
825 output->area.y += geom.height;
826 output->area.height -= geom.height;
828 width = output->area.width;
829 height = output->area.height;
835 assert(!"Invalid split orientation\n");
838 weston_desktop_surface_set_size(dsurface,
841 /* resize the active surface first, output->area already contains
842 * correct area to resize to */
844 ivi_layout_desktop_resize(output->active, output->area);
846 weston_view_set_output(view, woutput);
847 weston_view_set_position(view, x, y);
848 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
850 weston_view_geometry_dirty(view);
851 weston_surface_damage(view->surface);
854 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
856 wsurface->is_mapped = true;
857 surface->view->is_mapped = true;
859 shell_advertise_app_state(ivi, app_id,
860 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
862 weston_log("Activation completed for app_id %s, role %s, output %s\n",
863 app_id, ivi_layout_get_surface_role_name(surface), output->name);
867 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
868 int initial_x, int initial_y, int *new_x, int *new_y)
870 *new_x = output->x + initial_x;
871 *new_y = output->y + initial_y;
876 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface)
878 struct weston_view *ev;
880 wl_list_for_each(ev, &ivi->hidden.view_list.link, layer_link.link) {
881 if (ev == surface->view)
885 wl_list_for_each(ev, &ivi->fullscreen.view_list.link, layer_link.link) {
886 if (ev == surface->view)
894 ivi_layout_popup_committed(struct ivi_surface *surface)
896 struct ivi_compositor *ivi = surface->ivi;
897 struct ivi_policy *policy = ivi->policy;
899 struct weston_desktop_surface *dsurface = surface->dsurface;
900 struct weston_surface *wsurface =
901 weston_desktop_surface_get_surface(dsurface);
902 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
906 struct ivi_output *output = surface->popup.output;
907 struct weston_output *woutput = output->output;
909 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
910 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
912 struct weston_view *view = surface->view;
914 if (policy && policy->api.surface_activate_by_default &&
915 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
919 if (surface->view->is_mapped || surface->state == HIDDEN)
922 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
924 /* remove it from hidden layer if present */
925 if (ivi_surf_in_hidden_layer(ivi, surface))
926 weston_layer_entry_remove(&view->layer_link);
928 weston_view_set_output(view, woutput);
930 ivi_compute_popup_position(woutput, view,
931 surface->popup.x, surface->popup.y, &new_x, &new_y);
932 weston_view_set_position(view, new_x, new_y);
933 weston_view_update_transform(view);
935 /* only clip the pop-up dialog window if we have a valid
936 * width and height being passed on. Users might not want to have one
937 * set-up so only enfore it is really passed on. */
938 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
939 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
940 surface->popup.bb.width, surface->popup.bb.height);
942 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
944 weston_view_geometry_dirty(view);
945 weston_surface_damage(view->surface);
948 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
950 wsurface->is_mapped = true;
951 surface->view->is_mapped = true;
953 shell_advertise_app_state(ivi, app_id,
954 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
956 weston_log("Activation completed for app_id %s, role %s, output %s\n",
957 app_id, ivi_layout_get_surface_role_name(surface), output->name);
961 ivi_layout_popup_re_add(struct ivi_surface *surface)
963 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
964 struct weston_view *view = surface->view;
966 if (weston_view_is_mapped(view)) {
967 struct weston_desktop_surface *dsurface = surface->dsurface;
968 struct weston_surface *wsurface =
969 weston_desktop_surface_get_surface(dsurface);
971 weston_layer_entry_remove(&view->layer_link);
973 wsurface->is_mapped = false;
974 view->is_mapped = false;
977 /* reset the activate by default in order to (still) allow the surface
978 * to be activaved using the request */
979 if (!surface->mapped)
980 surface->mapped = true;
982 surface->state = NORMAL;
983 ivi_layout_popup_committed(surface);
987 ivi_layout_fullscreen_re_add(struct ivi_surface *surface)
989 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
990 struct weston_view *view = surface->view;
992 if (weston_view_is_mapped(view)) {
993 struct weston_desktop_surface *dsurface = surface->dsurface;
994 struct weston_surface *wsurface =
995 weston_desktop_surface_get_surface(dsurface);
997 weston_layer_entry_remove(&view->layer_link);
999 wsurface->is_mapped = false;
1000 view->is_mapped = false;
1003 /* reset the activate by default in order to (still) allow the surface
1004 * to be activaved using the request */
1005 if (!surface->mapped)
1006 surface->mapped = true;
1008 surface->state = NORMAL;
1009 ivi_layout_fullscreen_committed(surface);
1013 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
1015 struct ivi_compositor *ivi = surf->ivi;
1016 struct ivi_surface *is;
1018 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
1019 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
1020 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
1023 /* reset the activate by default in order to (still) allow the surface
1024 * to be activaved using the request */
1026 surf->mapped = true;
1028 wl_list_for_each(is, &ivi->surfaces, link)
1036 ivi_layout_reset_split_surfaces(struct ivi_compositor *ivi)
1038 struct ivi_surface *ivisurf;
1040 wl_list_for_each(ivisurf, &ivi->surfaces, link) {
1041 struct weston_desktop_surface *dsurf = ivisurf->dsurface;
1043 if (ivisurf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
1044 weston_log("%s() resetting apps to none orientation\n", __func__);
1045 ivisurf->orientation = AGL_SHELL_TILE_ORIENTATION_NONE;
1046 weston_desktop_surface_set_orientation(dsurf, ivisurf->orientation);
1052 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
1054 struct ivi_compositor *ivi = output->ivi;
1055 struct weston_desktop_surface *dsurf;
1056 struct weston_geometry geom;
1057 struct ivi_policy *policy = output->ivi->policy;
1059 dsurf = surf->dsurface;
1061 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
1066 if (policy && policy->api.surface_activate &&
1067 !policy->api.surface_activate(surf, surf->ivi)) {
1071 #ifdef AGL_COMP_DEBUG
1072 weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
1073 ivi_layout_get_surface_role_name(surf), output->output->name);
1076 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1077 ivi_layout_popup_re_add(surf);
1081 if (surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
1082 ivi_layout_fullscreen_re_add(surf);
1086 /* reset tile to desktop to allow to resize correctly */
1087 if (surf->role == IVI_SURFACE_ROLE_TILE && output->active == surf) {
1088 weston_log("%s() resetting tile role!\n", __func__);
1089 surf->role = IVI_SURFACE_ROLE_DESKTOP;
1093 /* do not 're'-activate surfaces that are split or active */
1094 if (surf == output->active ||
1095 ivi_layout_surface_is_split_or_fullscreen(surf) ||
1096 surf->role != IVI_SURFACE_ROLE_DESKTOP) {
1097 weston_log("Application %s is already active on output %s\n",
1098 app_id, output->output->name);
1102 // destroy any split types to allow correct re-activation
1103 ivi_layout_reset_split_surfaces(surf->ivi);
1105 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
1106 struct ivi_output *remote_output =
1107 ivi_layout_find_with_app_id(app_id, ivi);
1109 weston_log("Changed activation for app_id %s, type %s, on output %s\n", app_id,
1110 ivi_layout_get_surface_role_name(surf), output->output->name);
1112 /* if already active on a remote output do not
1113 * attempt to activate it again */
1114 if (remote_output && remote_output->active == surf)
1119 geom = weston_desktop_surface_get_geometry(dsurf);
1121 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
1122 surf->desktop.pending_output = output;
1123 if (weston_desktop_surface_get_maximized(dsurf) &&
1124 geom.width == output->area.width &&
1125 geom.height == output->area.height) {
1126 ivi_layout_activate_complete(output, surf);
1130 /* the background surface is already "maximized" so we don't need to
1131 * add to the hidden layer */
1132 if (surf->role == IVI_SURFACE_ROLE_BACKGROUND) {
1133 ivi_layout_activate_complete(output, surf);
1137 ivi_layout_add_to_hidden_layer(surf, output);
1141 ivi_layout_activate(struct ivi_output *output, const char *app_id)
1143 struct ivi_surface *surf;
1144 struct ivi_compositor *ivi = output->ivi;
1149 surf = ivi_find_app(ivi, app_id);
1153 ivi_layout_activate_by_surf(output, surf);
1157 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
1159 struct ivi_output *ivi_output = NULL;
1161 switch (surf->role) {
1162 case IVI_SURFACE_ROLE_DESKTOP:
1163 if (surf->desktop.pending_output)
1164 ivi_output = surf->desktop.pending_output;
1166 ivi_output = surf->desktop.last_output;
1168 case IVI_SURFACE_ROLE_POPUP:
1169 ivi_output = surf->popup.output;
1171 case IVI_SURFACE_ROLE_BACKGROUND:
1172 ivi_output = surf->bg.output;
1174 case IVI_SURFACE_ROLE_PANEL:
1175 ivi_output = surf->panel.output;
1177 case IVI_SURFACE_ROLE_FULLSCREEN:
1178 ivi_output = surf->fullscreen.output;
1180 case IVI_SURFACE_ROLE_SPLIT_H:
1181 case IVI_SURFACE_ROLE_SPLIT_V:
1182 ivi_output = surf->split.output;
1184 case IVI_SURFACE_ROLE_REMOTE:
1185 ivi_output = surf->remote.output;
1187 case IVI_SURFACE_ROLE_TILE:
1188 ivi_output = surf->current_completed_output;
1190 case IVI_SURFACE_ROLE_NONE:
1192 if (surf->view->output)
1193 return to_ivi_output(surf->view->output);
1201 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
1203 struct ivi_surface *surf;
1204 struct ivi_output *ivi_output;
1205 struct ivi_policy *policy = ivi->policy;
1210 surf = ivi_find_app(ivi, app_id);
1214 if (policy && policy->api.surface_deactivate &&
1215 !policy->api.surface_deactivate(surf, surf->ivi)) {
1219 ivi_output = ivi_layout_get_output_from_surface(surf);
1220 weston_log("Deactiving %s, role %s\n", app_id,
1221 ivi_layout_get_surface_role_name(surf));
1223 if (surf->role == IVI_SURFACE_ROLE_DESKTOP ||
1224 surf->role == IVI_SURFACE_ROLE_REMOTE) {
1225 struct ivi_surface *previous_active;
1227 previous_active = ivi_output->previous_active;
1228 if (!previous_active) {
1229 /* we don't have a previous active it means we should
1231 if (ivi_output->active) {
1232 struct weston_view *view;
1234 view = ivi_output->active->view;
1235 view->is_mapped = false;
1236 view->surface->is_mapped = false;
1238 weston_layer_entry_remove(&view->layer_link);
1239 weston_view_geometry_dirty(view);
1240 weston_surface_damage(view->surface);
1241 ivi_output->active = NULL;
1244 struct weston_desktop_surface *dsurface;
1245 const char *previous_active_app_id;
1247 dsurface = previous_active->dsurface;
1248 previous_active_app_id =
1249 weston_desktop_surface_get_app_id(dsurface);
1250 ivi_layout_activate(ivi_output, previous_active_app_id);
1252 } else if (surf->role == IVI_SURFACE_ROLE_POPUP ||
1253 surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
1254 struct weston_view *view = surf->view;
1256 weston_view_unmap(view);
1257 surf->state = HIDDEN;
1259 weston_layer_entry_remove(&view->layer_link);
1260 weston_view_geometry_dirty(view);
1261 weston_surface_damage(view->surface);
1264 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);