2 * Copyright © 2019, 2024 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.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_save(struct ivi_compositor *ivi, struct ivi_output *output)
60 struct ivi_output *new_output;
61 ivi->need_ivi_output_relayout = true;
63 new_output = zalloc(sizeof(*new_output));
65 new_output->ivi = ivi;
66 new_output->background = output->background;
68 new_output->top = output->top;
69 new_output->bottom = output->bottom;
70 new_output->left = output->left;
71 new_output->right = output->right;
73 new_output->active = output->active;
74 new_output->previous_active = output->previous_active;
75 new_output->name = strdup(output->name);
77 new_output->app_ids = strdup(output->app_ids);
79 new_output->area = output->area;
80 new_output->area_saved = output->area_saved;
81 new_output->area_activation = output->area_activation;
83 weston_log("saving output layout for output %s\n", new_output->name);
85 wl_list_insert(&ivi->saved_outputs, &new_output->link);
89 ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output)
91 struct ivi_output *output = NULL;
92 struct ivi_output *iter_output;
94 if (!ivi->need_ivi_output_relayout)
97 ivi->need_ivi_output_relayout = false;
99 wl_list_for_each(iter_output, &ivi->saved_outputs, link) {
100 if (strcmp(n_output->name, iter_output->name) == 0) {
101 output = iter_output;
109 weston_log("restoring output layout for output %s\n", output->name);
110 n_output->background = output->background;
112 n_output->top = output->top;
113 n_output->bottom = output->bottom;
114 n_output->left = output->left;
115 n_output->right = output->right;
117 n_output->active = output->active;
118 n_output->previous_active = output->previous_active;
120 n_output->app_ids = strdup(output->app_ids);
122 n_output->area = output->area;
123 n_output->area_saved = output->area_saved;
124 n_output->area_activation = output->area_activation;
126 free(output->app_ids);
128 wl_list_remove(&output->link);
133 ivi_layout_get_surface_role_name(struct ivi_surface *surf)
135 if (surf->role < 0 || surf->role >= ARRAY_LENGTH(ivi_roles_as_string))
136 return " unknown surface role";
138 return ivi_roles_as_string[surf->role];
142 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
144 struct weston_output *woutput = output->output;
145 struct ivi_surface *bg = output->background;
146 struct weston_view *view;
147 struct weston_surface *wsurface =
148 weston_desktop_surface_get_surface(bg->dsurface);
151 weston_log("WARNING: Output does not have a background\n");
155 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
158 weston_surface_map(wsurface);
160 weston_view_set_output(view, woutput);
161 weston_view_set_position(view, woutput->pos);
163 weston_view_move_to_layer(view, &ivi->background.view_list);
164 weston_log("(background) position view %p, x %f, y %f, on output %s\n", view,
165 woutput->pos.c.x, woutput->pos.c.y, output->name);
170 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
171 struct ivi_surface *panel)
173 struct weston_output *woutput = output->output;
174 struct weston_desktop_surface *dsurface;
175 struct weston_view *view;
176 struct weston_geometry geom;
177 struct weston_coord_global pos = woutput->pos;
178 struct weston_surface *wsurface;
183 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
184 dsurface = panel->dsurface;
186 geom = weston_desktop_surface_get_geometry(dsurface);
187 wsurface = weston_desktop_surface_get_surface(panel->dsurface);
189 weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
190 geom.width, geom.height, geom.x, geom.y);
192 switch (panel->panel.edge) {
193 case AGL_SHELL_EDGE_TOP:
194 output->area.y += geom.height;
195 output->area.height -= geom.height;
197 case AGL_SHELL_EDGE_BOTTOM:
198 pos.c.y += woutput->height - geom.height;
199 output->area.height -= geom.height;
201 case AGL_SHELL_EDGE_LEFT:
202 output->area.x += geom.width;
203 output->area.width -= geom.width;
205 case AGL_SHELL_EDGE_RIGHT:
206 pos.c.x += woutput->width - geom.width;
207 output->area.width -= geom.width;
214 weston_view_set_output(view, woutput);
215 weston_view_set_position(view, pos);
217 weston_surface_map(wsurface);
218 weston_view_move_to_layer(view, &ivi->panel.view_list);
220 weston_log("(panel) edge %d position view %p, x %f, y %f\n",
221 panel->panel.edge, view, pos.c.x, pos.c.y);
223 weston_log("panel type %d inited on output %s\n", panel->panel.edge,
228 * Initializes all static parts of the layout, i.e. the background and panels.
231 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
233 bool use_default_area = true;
234 struct weston_config_section *section = output->config;
237 weston_config_section_get_string(section, "activation-area", &t, NULL);
239 if (output->area_activation.width == 0 &&
240 output->area_activation.height == 0 &&
241 output->area_activation.x == 0 &&
242 output->area_activation.y == 0) {
243 weston_log("WARNING: activation-area set in "
244 "configuration file, but yet applied!\n");
245 if (parse_activation_area(t, output) < 0)
246 weston_log("Invalid activation-area \"%s\" for output %s\n",
249 weston_log("WARNING: activation-area detected in ini file, "
250 "but agl_shell override detected!\n");
251 if (parse_activation_area(t, output) < 0)
252 weston_log("Invalid activation-area \"%s\" for output %s\n",
258 ivi_background_init(ivi, output);
260 if (output->area_activation.width ||
261 output->area_activation.height ||
262 output->area_activation.x ||
263 output->area_activation.y) {
264 /* Sanity check target area is within output bounds */
265 if ((output->area_activation.x + output->area_activation.width) < output->output->width ||
266 (output->area_activation.y + output->area_activation.height) < output->output->height) {
267 weston_log("Using specified area for output %s, ignoring panels\n",
269 output->area.x = output->area_activation.x;
270 output->area.y = output->area_activation.y;
271 output->area.width = output->area_activation.width;
272 output->area.height = output->area_activation.height;
273 use_default_area = false;
275 weston_log("Invalid activation-area position for output %s, ignoring\n",
279 if (use_default_area) {
282 output->area.width = output->output->width;
283 output->area.height = output->output->height;
285 ivi_panel_init(ivi, output, output->top);
286 ivi_panel_init(ivi, output, output->bottom);
287 ivi_panel_init(ivi, output, output->left);
288 ivi_panel_init(ivi, output, output->right);
291 weston_compositor_schedule_repaint(ivi->compositor);
293 weston_log("Usable area: %dx%d+%d,%d\n",
294 output->area.width, output->area.height,
295 output->area.x, output->area.y);
299 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
301 struct ivi_surface *surf;
304 wl_list_for_each(surf, &ivi->surfaces, link) {
305 id = weston_desktop_surface_get_app_id(surf->dsurface);
306 if (id && strcmp(app_id, id) == 0)
314 ivi_layout_activate_complete(struct ivi_output *output,
315 struct ivi_surface *surf)
317 struct ivi_compositor *ivi = output->ivi;
318 struct weston_output *woutput = output->output;
319 struct weston_view *view = surf->view;
320 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
321 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
322 const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
323 bool update_previous = true;
324 struct weston_coord_global pos;
326 if (weston_view_is_mapped(view)) {
327 weston_layer_entry_remove(&view->layer_link);
329 weston_view_update_transform(view);
332 if (output_has_black_curtain(output)) {
333 if (!output->background) {
334 weston_log("Found that we have no background surface "
335 "for output %s. Using black curtain as background\n",
336 output->output->name);
338 struct weston_view *ev =
339 output->fullscreen_view.fs->view;
341 /* use the black curtain as background when we have
342 * none added by the shell client. */
343 weston_layer_entry_remove(&ev->layer_link);
344 weston_layer_entry_insert(&ivi->normal.view_list,
346 weston_view_geometry_dirty(ev);
347 weston_surface_damage(ev->surface);
349 remove_black_curtain(output);
354 weston_view_set_output(view, woutput);
355 /* drop any previous masks set on this view */
356 weston_view_set_mask_infinite(view);
358 if (surf->role != IVI_SURFACE_ROLE_BACKGROUND) {
359 pos.c.x = woutput->pos.c.x + output->area.x;
360 pos.c.y = woutput->pos.c.y + output->area.y;
361 weston_view_set_position(view, pos);
364 /* reset any previous orientation */
365 if (surf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE &&
367 weston_log("%s() resetting itself to none orientation\n", __func__);
368 surf->orientation = AGL_SHELL_TILE_ORIENTATION_NONE;
369 weston_desktop_surface_set_orientation(surf->dsurface,
372 view->is_mapped = true;
374 view->surface->is_mapped = true;
376 /* handle a movement from one output to another */
377 if (surf->current_completed_output &&
378 surf->current_completed_output != output) {
380 /* we're migrating the same surface but to another output */
381 if (surf->current_completed_output->active == surf) {
382 struct weston_view *ev =
383 surf->current_completed_output->active->view;
385 weston_layer_entry_remove(&ev->layer_link);
386 surf->current_completed_output->previous_active =
387 surf->current_completed_output->active;
388 surf->current_completed_output->active = NULL;
390 /* damage all possible outputs to avoid stale views */
391 weston_compositor_damage_all(ivi->compositor);
395 if (output->active) {
396 /* keep the background surface mapped at all times */
397 if (output->active->role != IVI_SURFACE_ROLE_BACKGROUND &&
398 !output->active->sticky) {
400 output->active->view->is_mapped = false;
401 output->active->view->surface->is_mapped = false;
403 weston_layer_entry_remove(&output->active->view->layer_link);
407 if (output->previous_active && output->active) {
408 const char *c_app_id =
409 weston_desktop_surface_get_app_id(output->active->dsurface);
411 /* if the currently activated app_id is the same as the one
412 * we're trying to complete activation with means we're
413 * operating on the same app_id so do update previous_active as
414 * it will overwrite it with the same value */
415 if (app_id && !strcmp(c_app_id, app_id)) {
416 update_previous = false;
421 output->previous_active = output->active;
422 output->active = surf;
423 surf->current_completed_output = output;
425 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
426 weston_view_geometry_dirty(view);
427 weston_surface_damage(view->surface);
430 ivi_shell_activate_surface(surf, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
433 * the 'remote' role now makes use of this part so make sure we don't
434 * trip the enum such that we might end up with a modified output for
437 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
438 if (surf->desktop.pending_output)
439 surf->desktop.last_output = surf->desktop.pending_output;
440 surf->desktop.pending_output = NULL;
443 weston_log("Activation completed for app_id %s, role %s, output %s\n",
445 ivi_layout_get_surface_role_name(surf), output->name);
447 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_ACTIVATED);
451 ivi_layout_find_output_with_app_id(const char *app_id, struct ivi_output *output)
456 cur = output->app_ids;
457 app_id_len = strlen(app_id);
459 while ((cur = strstr(cur, app_id))) {
460 if ((cur[app_id_len] == ',' || cur[app_id_len] == '\0') &&
461 (cur == output->app_ids || cur[-1] == ','))
470 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
472 struct ivi_output *out;
477 wl_list_for_each(out, &ivi->outputs, link) {
481 if (ivi_layout_find_output_with_app_id(app_id, out))
488 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
490 struct ivi_output *out;
492 wl_list_for_each(out, &ivi->outputs, link) {
493 if (out->background &&
494 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
503 ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
504 struct ivi_output *ivi_output)
506 struct weston_desktop_surface *dsurf = surf->dsurface;
507 struct weston_view *ev = surf->view;
508 struct ivi_compositor *ivi = surf->ivi;
509 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
512 * If the view isn't mapped, we put it onto the hidden layer so it will
513 * start receiving frame events, and will be able to act on our
516 if (!weston_view_is_mapped(ev)) {
517 ev->is_mapped = true;
518 ev->surface->is_mapped = true;
520 weston_desktop_surface_set_maximized(dsurf, true);
521 weston_desktop_surface_set_size(dsurf,
522 ivi_output->area.width,
523 ivi_output->area.height);
525 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
526 app_id, ivi_layout_get_surface_role_name(surf),
527 ivi_output->area.width, ivi_output->area.height);
529 surf->hidden_layer_output = ivi_output;
530 weston_view_set_output(ev, ivi_output->output);
531 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
532 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
533 app_id, ivi_layout_get_surface_role_name(surf),
534 ivi_output->output->name);
536 weston_compositor_schedule_repaint(ivi->compositor);
540 /* we might have another output to activate */
541 if (surf->hidden_layer_output &&
542 surf->hidden_layer_output != ivi_output) {
543 weston_layer_entry_remove(&ev->layer_link);
544 weston_view_geometry_dirty(ev);
545 weston_surface_damage(ev->surface);
547 if (ivi_output->area.width != surf->hidden_layer_output->area.width ||
548 ivi_output->area.height != surf->hidden_layer_output->area.height) {
549 weston_desktop_surface_set_maximized(dsurf, true);
550 weston_desktop_surface_set_size(dsurf,
551 ivi_output->area.width,
552 ivi_output->area.height);
555 weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
556 app_id, ivi_layout_get_surface_role_name(surf),
557 ivi_output->area.width, ivi_output->area.height);
559 surf->hidden_layer_output = ivi_output;
560 weston_view_set_output(ev, ivi_output->output);
561 weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
562 weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
563 app_id, ivi_layout_get_surface_role_name(surf),
564 ivi_output->output->name);
567 weston_compositor_schedule_repaint(ivi->compositor);
571 ivi_layout_remote_committed(struct ivi_surface *surf)
573 struct weston_desktop_surface *dsurf = surf->dsurface;
574 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
575 struct ivi_policy *policy = surf->ivi->policy;
576 struct ivi_output *output;
577 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
579 assert(surf->role == IVI_SURFACE_ROLE_REMOTE);
581 output = surf->remote.output;
583 if (policy && policy->api.surface_activate_by_default &&
584 !policy->api.surface_activate_by_default(surf, surf->ivi))
587 /* we can only activate it again by using the protocol, but
588 * additionally the output is not reset when
589 * ivi_layout_activate_complete() terminates so we use the
590 * current active surface to avoid hitting this again and again
592 if (surf->mapped && output->active == surf)
595 if (!surf->ivi->activate_by_default &&
596 !ivi_surf_in_hidden_layer(surf->ivi, surf)) {
597 weston_log("Refusing to activate surface role %d, "
598 "app_id %s\n", surf->role, app_id);
600 if (!weston_desktop_surface_get_maximized(dsurf) ||
601 geom.width != output->area.width ||
602 geom.height != output->area.height) {
603 ivi_layout_add_to_hidden_layer(surf, output);
609 if (!weston_desktop_surface_get_maximized(dsurf) ||
610 geom.width != output->area.width ||
611 geom.height != output->area.height)
614 ivi_layout_activate_complete(output, surf);
618 ivi_layout_desktop_committed(struct ivi_surface *surf)
620 struct weston_desktop_surface *dsurf = surf->dsurface;
621 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
622 struct ivi_policy *policy = surf->ivi->policy;
623 struct ivi_output *output;
624 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
626 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP);
629 * we can't make use here of the ivi_layout_get_output_from_surface()
630 * due to the fact that we'll always land here when a surface performs
631 * a commit and pending_output will not bet set. This works in tandem
632 * with 'mapped' at this point to avoid tripping over
633 * to a surface that continuously updates its content
635 output = surf->desktop.pending_output;
638 struct ivi_output *r_output;
640 if (policy && policy->api.surface_activate_by_default &&
641 !policy->api.surface_activate_by_default(surf, surf->ivi))
644 /* we can only activate it again by using the protocol */
648 /* check first if there aren't any outputs being set */
649 r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
652 struct weston_view *view = r_output->fullscreen_view.fs->view;
653 if (view->is_mapped || view->surface->is_mapped)
654 remove_black_curtain(r_output);
658 /* try finding an output with a background and use that */
660 r_output = ivi_layout_find_bg_output(surf->ivi);
662 /* if we couldn't still find an output by this point, there's
663 * something wrong so we abort with a protocol error */
665 wl_resource_post_error(surf->ivi->shell_client.resource,
666 AGL_SHELL_ERROR_INVALID_ARGUMENT,
667 "No valid output found to activate surface by default");
671 if (!surf->ivi->activate_by_default &&
672 (!surf->xwayland.is_set && !is_shell_surface_xwayland(surf))) {
673 weston_log("Refusing to activate surface role %d, app_id %s, type %s\n",
675 is_shell_surface_xwayland(surf) ?
676 "xwayland" : "regular");
678 if (!weston_desktop_surface_get_maximized(dsurf) ||
679 geom.width != r_output->area.width ||
680 geom.height != r_output->area.height)
681 ivi_layout_add_to_hidden_layer(surf, r_output);
686 /* use the output of the bg to activate the app on start-up by
688 if (surf->view && r_output) {
689 if (app_id && r_output) {
690 weston_log("Surface with app_id %s, role %s activating by default\n",
691 weston_desktop_surface_get_app_id(surf->dsurface),
692 ivi_layout_get_surface_role_name(surf));
693 ivi_layout_activate(r_output, app_id);
694 } else if (!app_id) {
696 * applications not setting an app_id, or
697 * setting an app_id but at a later point in
698 * time, might fall-back here so give them a
699 * chance to receive the configure event and
702 weston_log("Surface no app_id, role %s activating by default\n",
703 ivi_layout_get_surface_role_name(surf));
704 if (surf->xwayland.is_set || is_shell_surface_xwayland(surf)) {
705 ivi_layout_activate_by_surf(r_output, surf);
706 ivi_layout_activate_complete(r_output, surf);
708 ivi_layout_activate_by_surf(r_output, surf);
716 if (!weston_desktop_surface_get_maximized(dsurf) ||
717 geom.width != output->area.width ||
718 geom.height != output->area.height)
721 ivi_layout_activate_complete(output, surf);
725 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
727 struct ivi_compositor *ivi = surface->ivi;
728 struct ivi_policy *policy = ivi->policy;
730 struct weston_desktop_surface *dsurface = surface->dsurface;
731 struct weston_surface *wsurface =
732 weston_desktop_surface_get_surface(dsurface);
733 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
735 struct ivi_output *output = surface->split.output;
736 struct weston_output *woutput = output->output;
737 struct ivi_output *bg_output = ivi_layout_find_bg_output(ivi);
739 struct weston_view *view = surface->view;
740 struct weston_geometry geom =
741 weston_desktop_surface_get_geometry(dsurface);
743 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
744 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
746 bool is_fullscreen = weston_desktop_surface_get_fullscreen(dsurface);
748 geom.width == bg_output->output->width &&
749 geom.height == bg_output->output->height;
751 if (policy && policy->api.surface_activate_by_default &&
752 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
756 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
759 if (surface->state == FULLSCREEN && weston_view_is_mapped(view))
762 /* if we still get here but we haven't resized so far, send configure
764 if (surface->state != RESIZING && (!is_fullscreen || !is_dim_same)) {
765 struct ivi_output *bg_output =
766 ivi_layout_find_bg_output(surface->ivi);
768 weston_log("Placing fullscreen app_id %s, type %s in hidden layer\n",
769 app_id, ivi_layout_get_surface_role_name(surface));
770 weston_desktop_surface_set_fullscreen(dsurface, true);
771 weston_desktop_surface_set_size(dsurface,
772 bg_output->output->width,
773 bg_output->output->height);
775 surface->state = RESIZING;
776 weston_view_set_output(view, output->output);
777 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
781 /* eventually, we would set the surface fullscreen, but the client
782 * hasn't resized correctly by this point, so terminate connection */
783 if (surface->state == RESIZING && is_fullscreen && !is_dim_same) {
784 struct weston_desktop_client *desktop_client =
785 weston_desktop_surface_get_client(dsurface);
786 struct wl_client *client =
787 weston_desktop_client_get_client(desktop_client);
788 wl_client_post_implementation_error(client,
789 "can not display surface due to invalid geometry."
790 " Client should perform a geometry resize!");
794 /* this implies we resized correctly */
795 if (!weston_view_is_mapped(view) || surface->state != FULLSCREEN) {
796 weston_layer_entry_remove(&view->layer_link);
798 weston_view_set_output(view, woutput);
799 weston_view_set_position(view, woutput->pos);
800 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
802 wsurface->is_mapped = true;
803 surface->view->is_mapped = true;
804 surface->state = FULLSCREEN;
806 weston_view_geometry_dirty(view);
807 weston_surface_damage(view->surface);
810 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
812 shell_advertise_app_state(ivi, app_id,
813 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
815 weston_log("Activation completed for app_id %s, role %s, "
816 "output %s\n", app_id,
817 ivi_layout_get_surface_role_name(surface),
820 weston_compositor_schedule_repaint(ivi->compositor);
825 ivi_layout_desktop_resize(struct ivi_surface *surface,
826 struct weston_geometry area)
828 struct weston_desktop_surface *dsurf = surface->dsurface;
829 struct weston_view *view = surface->view;
831 struct weston_coord_global pos;
832 int width = area.width;
833 int height = area.height;
838 weston_desktop_surface_set_size(dsurf,
841 weston_view_set_position(view, pos);
843 weston_view_geometry_dirty(view);
844 weston_surface_damage(view->surface);
848 ivi_layout_split_committed(struct ivi_surface *surface)
850 struct ivi_compositor *ivi = surface->ivi;
851 struct ivi_policy *policy = ivi->policy;
853 struct weston_desktop_surface *dsurface = surface->dsurface;
854 struct weston_surface *wsurface =
855 weston_desktop_surface_get_surface(dsurface);
856 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
858 struct ivi_output *output = surface->split.output;
859 struct weston_output *woutput = output->output;
861 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
862 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
864 struct weston_view *view = surface->view;
865 struct weston_geometry geom;
867 struct weston_coord_global pos = woutput->pos;
870 if (policy && policy->api.surface_activate_by_default &&
871 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
875 if (surface->view->is_mapped)
878 geom = weston_desktop_surface_get_geometry(dsurface);
880 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
881 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
883 /* save the previous area in order to recover it back when if this kind
884 * of surface is being destroyed/removed */
885 output->area_saved = output->area;
887 switch (surface->role) {
888 case IVI_SURFACE_ROLE_SPLIT_V:
889 geom.width = (output->area.width / 2);
891 pos.c.x += woutput->width - geom.width;
892 output->area.width -= geom.width;
894 width = woutput->width - pos.c.x;
895 height = output->area.height;
896 pos.c.y = output->area.y;
899 case IVI_SURFACE_ROLE_SPLIT_H:
900 geom.height = (output->area.height / 2);
902 pos.c.y = output->area.y;
903 output->area.y += geom.height;
904 output->area.height -= geom.height;
906 width = output->area.width;
907 height = output->area.height;
909 pos.c.x = output->area.x;
913 assert(!"Invalid split orientation\n");
916 weston_desktop_surface_set_size(dsurface,
919 /* resize the active surface first, output->area already contains
920 * correct area to resize to */
922 ivi_layout_desktop_resize(output->active, output->area);
924 weston_view_set_output(view, woutput);
925 weston_view_set_position(view, pos);
926 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
928 weston_view_geometry_dirty(view);
929 weston_surface_damage(view->surface);
932 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
934 wsurface->is_mapped = true;
935 surface->view->is_mapped = true;
937 shell_advertise_app_state(ivi, app_id,
938 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
940 weston_log("Activation completed for app_id %s, role %s, output %s\n",
941 app_id, ivi_layout_get_surface_role_name(surface), output->name);
945 ivi_compute_popup_position(const struct weston_output *output, struct weston_view *view,
946 int initial_x, int initial_y, double *new_x, double *new_y)
948 *new_x = output->pos.c.x + initial_x;
949 *new_y = output->pos.c.y + initial_y;
954 ivi_surf_in_hidden_layer(struct ivi_compositor *ivi, struct ivi_surface *surface)
956 struct weston_view *ev;
958 wl_list_for_each(ev, &ivi->hidden.view_list.link, layer_link.link) {
959 if (ev == surface->view)
963 wl_list_for_each(ev, &ivi->fullscreen.view_list.link, layer_link.link) {
964 if (ev == surface->view)
972 ivi_layout_popup_committed(struct ivi_surface *surface)
974 struct ivi_compositor *ivi = surface->ivi;
975 struct ivi_policy *policy = ivi->policy;
977 struct weston_desktop_surface *dsurface = surface->dsurface;
978 struct weston_surface *wsurface =
979 weston_desktop_surface_get_surface(dsurface);
980 const char *app_id = weston_desktop_surface_get_app_id(dsurface);
982 struct weston_coord_global pos;
984 struct ivi_output *output = surface->popup.output;
985 struct weston_output *woutput = output->output;
987 struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
988 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
990 struct weston_view *view = surface->view;
992 if (policy && policy->api.surface_activate_by_default &&
993 !policy->api.surface_activate_by_default(surface, surface->ivi) &&
997 if (surface->view->is_mapped || surface->state == HIDDEN)
1000 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
1002 /* remove it from hidden layer if present */
1003 if (ivi_surf_in_hidden_layer(ivi, surface))
1004 weston_layer_entry_remove(&view->layer_link);
1006 weston_view_set_output(view, woutput);
1008 ivi_compute_popup_position(woutput, view,
1009 surface->popup.x, surface->popup.y, &pos.c.x, &pos.c.y);
1010 weston_view_set_position(view, pos);
1011 weston_view_update_transform(view);
1013 /* only clip the pop-up dialog window if we have a valid
1014 * width and height being passed on. Users might not want to have one
1015 * set-up so only enfore it is really passed on. */
1016 if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
1017 weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
1018 surface->popup.bb.width, surface->popup.bb.height);
1020 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
1022 weston_view_geometry_dirty(view);
1023 weston_surface_damage(view->surface);
1026 ivi_shell_activate_surface(surface, ivi_seat, WESTON_ACTIVATE_FLAG_NONE);
1028 wsurface->is_mapped = true;
1029 surface->view->is_mapped = true;
1031 shell_advertise_app_state(ivi, app_id,
1032 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
1034 weston_log("Activation completed for app_id %s, role %s, output %s\n",
1035 app_id, ivi_layout_get_surface_role_name(surface), output->name);
1039 ivi_layout_popup_re_add(struct ivi_surface *surface)
1041 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
1042 struct weston_view *view = surface->view;
1044 if (weston_view_is_mapped(view)) {
1045 struct weston_desktop_surface *dsurface = surface->dsurface;
1046 struct weston_surface *wsurface =
1047 weston_desktop_surface_get_surface(dsurface);
1049 weston_layer_entry_remove(&view->layer_link);
1051 wsurface->is_mapped = false;
1052 view->is_mapped = false;
1055 /* reset the activate by default in order to (still) allow the surface
1056 * to be activaved using the request */
1057 if (!surface->mapped)
1058 surface->mapped = true;
1060 surface->state = NORMAL;
1061 ivi_layout_popup_committed(surface);
1065 ivi_layout_fullscreen_re_add(struct ivi_surface *surface)
1067 assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
1068 struct weston_view *view = surface->view;
1070 if (weston_view_is_mapped(view)) {
1071 struct weston_desktop_surface *dsurface = surface->dsurface;
1072 struct weston_surface *wsurface =
1073 weston_desktop_surface_get_surface(dsurface);
1075 weston_layer_entry_remove(&view->layer_link);
1077 wsurface->is_mapped = false;
1078 view->is_mapped = false;
1081 /* reset the activate by default in order to (still) allow the surface
1082 * to be activaved using the request */
1083 if (!surface->mapped)
1084 surface->mapped = true;
1086 surface->state = NORMAL;
1087 ivi_layout_fullscreen_committed(surface);
1091 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
1093 struct ivi_compositor *ivi = surf->ivi;
1094 struct ivi_surface *is;
1096 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
1097 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
1098 surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
1101 /* reset the activate by default in order to (still) allow the surface
1102 * to be activaved using the request */
1104 surf->mapped = true;
1106 wl_list_for_each(is, &ivi->surfaces, link)
1114 ivi_layout_reset_split_surfaces(struct ivi_compositor *ivi)
1116 struct ivi_surface *ivisurf;
1117 struct ivi_surface *found_ivi_surf = NULL;
1118 bool found_split_surface = false;
1119 struct ivi_output *output = NULL;
1121 wl_list_for_each(ivisurf, &ivi->surfaces, link) {
1122 if (ivisurf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
1123 found_ivi_surf = ivisurf;
1124 found_split_surface = true;
1129 if (!found_split_surface)
1132 output = found_ivi_surf->current_completed_output;
1134 if (found_ivi_surf->sticky)
1137 if (output->previous_active && output->background != output->previous_active) {
1138 struct weston_view *ev = output->previous_active->view;
1139 struct weston_output *woutput = output->output;
1141 if (!weston_view_is_mapped(ev))
1142 weston_view_update_transform(ev);
1144 weston_layer_entry_remove(&ev->layer_link);
1146 ev->is_mapped = true;
1147 ev->surface->is_mapped = true;
1148 output->previous_active->mapped = true;
1150 weston_view_set_output(ev, woutput);
1152 weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
1154 _ivi_set_shell_surface_split(output->previous_active, NULL, 0,
1155 AGL_SHELL_TILE_ORIENTATION_NONE, false, false);
1157 if (output->active == ivisurf) {
1158 output->active = output->previous_active;
1162 _ivi_set_shell_surface_split(ivisurf, NULL, 0,
1163 AGL_SHELL_TILE_ORIENTATION_NONE, false, false);
1167 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
1169 struct ivi_compositor *ivi = output->ivi;
1170 struct weston_desktop_surface *dsurf;
1171 struct weston_geometry geom;
1172 struct ivi_policy *policy = output->ivi->policy;
1174 dsurf = surf->dsurface;
1176 const char *app_id = weston_desktop_surface_get_app_id(dsurf);
1181 if (policy && policy->api.surface_activate &&
1182 !policy->api.surface_activate(surf, surf->ivi)) {
1186 #ifdef AGL_COMP_DEBUG
1187 weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
1188 ivi_layout_get_surface_role_name(surf), output->output->name);
1191 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
1192 ivi_layout_popup_re_add(surf);
1196 if (surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
1197 ivi_layout_fullscreen_re_add(surf);
1201 /* reset tile to desktop to allow to resize correctly */
1202 if (surf->role == IVI_SURFACE_ROLE_TILE && output->active == surf) {
1203 weston_log("%s() resetting tile role!\n", __func__);
1204 surf->role = IVI_SURFACE_ROLE_DESKTOP;
1208 /* do not 're'-activate surfaces that are split or active */
1209 if (surf == output->active) {
1210 weston_log("Application %s is already active on output %s\n",
1211 app_id, output->output->name);
1215 if (surf->sticky && surf->role == IVI_SURFACE_ROLE_TILE && output->active == surf) {
1216 weston_log("Application %s is already active on output %s (split role)\n",
1217 app_id, output->output->name);
1221 if (ivi_layout_surface_is_split_or_fullscreen(surf)) {
1222 weston_log("Application %s is fullscreen or split on output %s\n",
1223 app_id, output->output->name);
1227 // destroy any split types to allow correct re-activation
1228 ivi_layout_reset_split_surfaces(surf->ivi);
1230 if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
1231 struct ivi_output *remote_output =
1232 ivi_layout_find_with_app_id(app_id, ivi);
1234 weston_log("Changed activation for app_id %s, type %s, on output %s\n", app_id,
1235 ivi_layout_get_surface_role_name(surf), output->output->name);
1237 /* if already active on a remote output do not
1238 * attempt to activate it again */
1239 if (remote_output && remote_output->active == surf)
1244 geom = weston_desktop_surface_get_geometry(dsurf);
1246 if (surf->role == IVI_SURFACE_ROLE_DESKTOP)
1247 surf->desktop.pending_output = output;
1248 if (weston_desktop_surface_get_maximized(dsurf) &&
1249 geom.width == output->area.width &&
1250 geom.height == output->area.height) {
1251 ivi_layout_activate_complete(output, surf);
1255 /* the background surface is already "maximized" so we don't need to
1256 * add to the hidden layer */
1257 if (surf->role == IVI_SURFACE_ROLE_BACKGROUND &&
1258 output->active->role != IVI_SURFACE_ROLE_TILE) {
1259 ivi_layout_activate_complete(output, surf);
1263 ivi_layout_add_to_hidden_layer(surf, output);
1267 ivi_layout_activate(struct ivi_output *output, const char *app_id)
1269 struct ivi_surface *surf;
1270 struct ivi_compositor *ivi = output->ivi;
1275 surf = ivi_find_app(ivi, app_id);
1279 ivi_layout_activate_by_surf(output, surf);
1283 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
1285 struct ivi_output *ivi_output = NULL;
1287 switch (surf->role) {
1288 case IVI_SURFACE_ROLE_DESKTOP:
1289 if (surf->desktop.pending_output)
1290 ivi_output = surf->desktop.pending_output;
1292 ivi_output = surf->desktop.last_output;
1294 case IVI_SURFACE_ROLE_POPUP:
1295 ivi_output = surf->popup.output;
1297 case IVI_SURFACE_ROLE_BACKGROUND:
1298 ivi_output = surf->bg.output;
1300 case IVI_SURFACE_ROLE_PANEL:
1301 ivi_output = surf->panel.output;
1303 case IVI_SURFACE_ROLE_FULLSCREEN:
1304 ivi_output = surf->fullscreen.output;
1306 case IVI_SURFACE_ROLE_SPLIT_H:
1307 case IVI_SURFACE_ROLE_SPLIT_V:
1308 ivi_output = surf->split.output;
1310 case IVI_SURFACE_ROLE_REMOTE:
1311 ivi_output = surf->remote.output;
1313 case IVI_SURFACE_ROLE_TILE:
1314 ivi_output = surf->current_completed_output;
1316 case IVI_SURFACE_ROLE_NONE:
1318 if (surf->view->output)
1319 return to_ivi_output(surf->view->output);
1327 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
1329 struct ivi_surface *surf;
1330 struct ivi_output *ivi_output;
1331 struct ivi_policy *policy = ivi->policy;
1336 surf = ivi_find_app(ivi, app_id);
1340 if (policy && policy->api.surface_deactivate &&
1341 !policy->api.surface_deactivate(surf, surf->ivi)) {
1345 ivi_output = ivi_layout_get_output_from_surface(surf);
1346 weston_log("Deactiving %s, role %s\n", app_id,
1347 ivi_layout_get_surface_role_name(surf));
1349 if (surf->role == IVI_SURFACE_ROLE_DESKTOP ||
1350 surf->role == IVI_SURFACE_ROLE_REMOTE) {
1351 struct ivi_surface *previous_active;
1353 previous_active = ivi_output->previous_active;
1354 if (!previous_active) {
1355 /* we don't have a previous active it means we should
1357 if (ivi_output->active) {
1358 struct weston_view *view;
1360 view = ivi_output->active->view;
1361 view->is_mapped = false;
1362 view->surface->is_mapped = false;
1364 weston_layer_entry_remove(&view->layer_link);
1365 weston_view_geometry_dirty(view);
1366 weston_surface_damage(view->surface);
1367 ivi_output->active = NULL;
1370 struct weston_desktop_surface *dsurface;
1371 const char *previous_active_app_id;
1373 dsurface = previous_active->dsurface;
1374 previous_active_app_id =
1375 weston_desktop_surface_get_app_id(dsurface);
1376 ivi_layout_activate(ivi_output, previous_active_app_id);
1378 } else if (surf->role == IVI_SURFACE_ROLE_POPUP ||
1379 surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
1380 struct weston_view *view = surf->view;
1382 weston_view_unmap(view);
1383 surf->state = HIDDEN;
1385 weston_layer_entry_remove(&view->layer_link);
1386 weston_view_geometry_dirty(view);
1387 weston_surface_damage(view->surface);
1390 shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);