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"
32 #include <libweston/libweston.h>
33 #include <libweston-desktop/libweston-desktop.h>
35 #include "agl-shell-desktop-server-protocol.h"
37 #define AGL_COMP_DEBUG
40 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
42 struct weston_output *woutput = output->output;
43 struct ivi_surface *bg = output->background;
44 struct weston_view *view;
47 weston_log("WARNING: Output does not have a background\n");
51 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
55 weston_view_set_output(view, woutput);
56 weston_view_set_position(view, woutput->x, woutput->y);
59 weston_log("(background) position view %p, x %d, y %d\n", view,
60 woutput->x, woutput->y);
63 view->is_mapped = true;
64 view->surface->is_mapped = true;
66 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
70 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
71 struct ivi_surface *panel)
73 struct weston_output *woutput = output->output;
74 struct weston_desktop_surface *dsurface;
75 struct weston_view *view;
76 struct weston_geometry geom;
83 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
84 dsurface = panel->dsurface;
86 geom = weston_desktop_surface_get_geometry(dsurface);
88 weston_log("geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
89 geom.width, geom.height, geom.x, geom.y);
91 switch (panel->panel.edge) {
92 case AGL_SHELL_EDGE_TOP:
93 output->area.y += geom.height;
94 output->area.height -= geom.height;
96 case AGL_SHELL_EDGE_BOTTOM:
97 y += woutput->height - geom.height;
98 output->area.height -= geom.height;
100 case AGL_SHELL_EDGE_LEFT:
101 output->area.x += geom.width;
102 output->area.width -= geom.width;
104 case AGL_SHELL_EDGE_RIGHT:
105 x += woutput->width - geom.width;
106 output->area.width -= geom.width;
113 weston_view_set_output(view, woutput);
114 weston_view_set_position(view, x, y);
115 #ifdef AGL_COMP_DEBUG
116 weston_log("(panel) edge %d position view %p, x %d, y %d\n",
117 panel->panel.edge, view, x, y);
120 /* this is necessary for cases we already mapped it desktop_committed()
121 * but we not running the older qtwayland, so we still have a chance
122 * for this to run at the next test */
123 if (view->surface->is_mapped) {
124 weston_layer_entry_remove(&view->layer_link);
126 view->is_mapped = false;
127 view->surface->is_mapped = false;
130 /* give ivi_layout_panel_committed() a chance to map the view/surface
132 if ((geom.width == geom.height && geom.width == 0) &&
133 (geom.x == geom.y && geom.x == 0) &&
134 panel->panel.edge != AGL_SHELL_EDGE_TOP)
137 view->is_mapped = true;
138 view->surface->is_mapped = true;
139 #ifdef AGL_COMP_DEBUG
140 weston_log("panel type %d inited\n", panel->panel.edge);
142 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
146 * Initializes all static parts of the layout, i.e. the background and panels.
149 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
151 ivi_background_init(ivi, output);
155 output->area.width = output->output->width;
156 output->area.height = output->output->height;
158 ivi_panel_init(ivi, output, output->top);
159 ivi_panel_init(ivi, output, output->bottom);
160 ivi_panel_init(ivi, output, output->left);
161 ivi_panel_init(ivi, output, output->right);
163 weston_compositor_schedule_repaint(ivi->compositor);
165 weston_log("Usable area: %dx%d+%d,%d\n",
166 output->area.width, output->area.height,
167 output->area.x, output->area.y);
171 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
173 struct ivi_surface *surf;
176 wl_list_for_each(surf, &ivi->surfaces, link) {
177 id = weston_desktop_surface_get_app_id(surf->dsurface);
178 if (id && strcmp(app_id, id) == 0)
186 ivi_layout_activate_complete(struct ivi_output *output,
187 struct ivi_surface *surf)
189 struct ivi_compositor *ivi = output->ivi;
190 struct weston_output *woutput = output->output;
191 struct weston_view *view = surf->view;
193 if (weston_view_is_mapped(view)) {
194 weston_layer_entry_remove(&view->layer_link);
197 weston_view_set_output(view, woutput);
198 weston_view_set_position(view,
199 woutput->x + output->area.x,
200 woutput->y + output->area.y);
202 view->is_mapped = true;
203 view->surface->is_mapped = true;
205 if (output->active) {
206 output->active->view->is_mapped = false;
207 output->active->view->surface->is_mapped = false;
209 weston_layer_entry_remove(&output->active->view->layer_link);
211 output->previous_active = output->active;
212 output->active = surf;
214 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
215 weston_view_update_transform(view);
217 /* force repaint of the entire output */
218 weston_output_damage(output->output);
220 surf->desktop.last_output = surf->desktop.pending_output;
221 surf->desktop.pending_output = NULL;
224 static struct ivi_output *
225 ivi_layout_find_bg_output(struct ivi_compositor *ivi)
227 struct ivi_output *out;
229 wl_list_for_each(out, &ivi->outputs, link) {
230 if (out->background &&
231 out->background->role == IVI_SURFACE_ROLE_BACKGROUND)
238 static struct ivi_output *
239 ivi_layout_get_output_from_surface(struct ivi_surface *surf)
241 struct ivi_output *ivi_output = NULL;
243 switch (surf->role) {
244 case IVI_SURFACE_ROLE_DESKTOP:
245 if (surf->desktop.pending_output)
246 ivi_output = surf->desktop.pending_output;
248 ivi_output = surf->desktop.last_output;
250 case IVI_SURFACE_ROLE_POPUP:
251 ivi_output = surf->popup.output;
253 case IVI_SURFACE_ROLE_REMOTE:
254 ivi_output = surf->remote.output;
257 case IVI_SURFACE_ROLE_BACKGROUND:
258 case IVI_SURFACE_ROLE_PANEL:
259 case IVI_SURFACE_ROLE_NONE:
267 ivi_layout_desktop_committed(struct ivi_surface *surf)
269 struct weston_desktop_surface *dsurf = surf->dsurface;
270 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
271 struct ivi_output *output;
272 struct ivi_policy *policy = surf->ivi->policy;
274 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP ||
275 surf->role == IVI_SURFACE_ROLE_REMOTE);
277 output = ivi_layout_get_output_from_surface(surf);
279 struct ivi_output *ivi_bg_output;
281 if (policy && policy->api.surface_activate_by_default)
282 if (policy->api.surface_activate_by_default(surf, surf->ivi))
283 goto skip_config_check;
285 if (!surf->ivi->quirks.activate_apps_by_default)
289 /* we can only activate it again by using the protocol */
290 if (surf->activated_by_default)
293 ivi_bg_output = ivi_layout_find_bg_output(surf->ivi);
295 /* use the output of the bg to activate the app on start-up by
297 if (surf->view && ivi_bg_output) {
299 weston_desktop_surface_get_app_id(dsurf);
300 if (app_id && ivi_bg_output) {
301 ivi_layout_activate(ivi_bg_output, app_id);
302 surf->activated_by_default = true;
309 if (surf->role == IVI_SURFACE_ROLE_REMOTE && output) {
312 if (policy && policy->api.surface_activate_by_default &&
313 !policy->api.surface_activate_by_default(surf, surf->ivi))
316 app_id = weston_desktop_surface_get_app_id(dsurf);
318 ivi_layout_activate(output, app_id);
320 /* we transition to the desktop role from remote one,
321 * as they're basically one and the same, but in order
322 * to keep the same functionality (that is to display
323 * it by default when starting), we need to know the
324 * output before hand, fact that that is not true for,
325 * regular desktop ones.
327 surf->role = IVI_SURFACE_ROLE_DESKTOP;
328 surf->activated_by_default = true;
333 if (!weston_desktop_surface_get_maximized(dsurf) ||
334 geom.width != output->area.width ||
335 geom.height != output->area.height)
338 ivi_layout_activate_complete(output, surf);
342 ivi_layout_fs_committed(struct ivi_surface *surface)
344 struct ivi_compositor *ivi = surface->ivi;
346 struct weston_desktop_surface *dsurface = surface->dsurface;
347 struct weston_surface *wsurface =
348 weston_desktop_surface_get_surface(dsurface);
350 struct ivi_output *output = surface->split.output;
351 struct weston_output *woutput = output->output;
353 struct weston_view *view = surface->view;
354 struct weston_geometry geom;
356 if (surface->view->is_mapped)
359 geom = weston_desktop_surface_get_geometry(dsurface);
360 weston_log("(fs) geom x %d, y %d, width %d, height %d\n", geom.x, geom.y,
361 geom.width, geom.height);
363 assert(surface->role == IVI_SURFACE_ROLE_FS);
365 weston_desktop_surface_set_fullscreen(dsurface, true);
367 weston_view_set_output(view, woutput);
368 weston_view_set_position(view, woutput->x, woutput->y);
369 weston_layer_entry_insert(&ivi->fullscreen.view_list, &view->layer_link);
371 weston_view_update_transform(view);
372 weston_view_damage_below(view);
374 wsurface->is_mapped = true;
375 surface->view->is_mapped = true;
380 ivi_layout_desktop_resize(struct ivi_surface *surface,
381 struct weston_geometry area)
383 struct weston_desktop_surface *dsurf = surface->dsurface;
384 struct weston_view *view = surface->view;
388 int width = area.width;
389 int height = area.height;
391 weston_desktop_surface_set_size(dsurf,
394 weston_view_set_position(view, x, y);
395 weston_view_update_transform(view);
396 weston_view_damage_below(view);
400 ivi_layout_split_committed(struct ivi_surface *surface)
402 struct ivi_compositor *ivi = surface->ivi;
404 struct weston_desktop_surface *dsurface = surface->dsurface;
405 struct weston_surface *wsurface =
406 weston_desktop_surface_get_surface(dsurface);
408 struct ivi_output *output = surface->split.output;
409 struct weston_output *woutput = output->output;
411 struct weston_view *view = surface->view;
412 struct weston_geometry geom;
420 if (surface->view->is_mapped)
423 geom = weston_desktop_surface_get_geometry(dsurface);
425 assert(surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
426 surface->role == IVI_SURFACE_ROLE_SPLIT_V);
428 /* save the previous area in order to recover it back when if this kind
429 * of surface is being destroyed/removed */
430 output->area_saved = output->area;
432 switch (surface->role) {
433 case IVI_SURFACE_ROLE_SPLIT_V:
434 if (geom.width == woutput->width &&
435 geom.height == woutput->height)
436 geom.width = (output->area.width / 2);
438 x += woutput->width - geom.width;
439 output->area.width -= geom.width;
441 width = woutput->width - x;
442 height = output->area.height;
446 case IVI_SURFACE_ROLE_SPLIT_H:
447 if (geom.width == woutput->width &&
448 geom.height == woutput->height)
449 geom.height = (output->area.height / 2);
452 output->area.y += geom.height;
453 output->area.height -= geom.height;
455 width = output->area.width;
456 height = output->area.height;
462 assert(!"Invalid split orientation\n");
465 weston_desktop_surface_set_size(dsurface,
468 /* resize the active surface first, output->area already contains
469 * correct area to resize to */
471 ivi_layout_desktop_resize(output->active, output->area);
473 weston_view_set_output(view, woutput);
474 weston_view_set_position(view, x, y);
475 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
477 weston_view_update_transform(view);
478 weston_view_damage_below(view);
480 wsurface->is_mapped = true;
481 surface->view->is_mapped = true;
485 ivi_layout_popup_committed(struct ivi_surface *surface)
487 struct ivi_compositor *ivi = surface->ivi;
489 struct weston_desktop_surface *dsurface = surface->dsurface;
490 struct weston_surface *wsurface =
491 weston_desktop_surface_get_surface(dsurface);
493 struct ivi_output *output = surface->popup.output;
494 struct weston_output *woutput = output->output;
496 struct weston_view *view = surface->view;
497 struct weston_geometry geom;
499 if (surface->view->is_mapped)
502 geom = weston_desktop_surface_get_geometry(dsurface);
503 weston_log("geom x %d, y %d, width %d, height %d\n", geom.x, geom.y,
504 geom.width, geom.height);
506 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
508 weston_view_set_output(view, woutput);
509 if (surface->popup.x || surface->popup.y)
510 weston_view_set_position(view, surface->popup.x, surface->popup.y);
512 weston_view_set_position(view, geom.x, geom.y);
513 weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
515 weston_view_update_transform(view);
516 weston_view_damage_below(view);
518 wsurface->is_mapped = true;
519 surface->view->is_mapped = true;
523 ivi_layout_popup_re_add(struct ivi_surface *surface)
525 assert(surface->role == IVI_SURFACE_ROLE_POPUP);
526 struct weston_view *view = surface->view;
528 if (weston_view_is_mapped(view)) {
529 struct weston_desktop_surface *dsurface = surface->dsurface;
530 struct weston_surface *wsurface =
531 weston_desktop_surface_get_surface(dsurface);
533 weston_layer_entry_remove(&view->layer_link);
535 wsurface->is_mapped = false;
536 view->is_mapped = false;
539 ivi_layout_popup_committed(surface);
543 ivi_layout_panel_committed(struct ivi_surface *surface)
545 struct ivi_compositor *ivi = surface->ivi;
546 struct ivi_output *output = surface->bg.output;
547 struct weston_output *woutput = output->output;
548 struct weston_desktop_surface *dsurface = surface->dsurface;
549 struct weston_surface *wsurface =
550 weston_desktop_surface_get_surface(dsurface);
551 struct weston_geometry geom;
555 assert(surface->role == IVI_SURFACE_ROLE_PANEL);
558 * If the desktop_surface geometry is not set and the panel is not a
559 * top one, we'll give this a chance to run, as some qtwayland version
560 * seem to have a 'problem', where the panel initilization part will
561 * have a desktop surface with 0 as geometry for *all* its members
562 * (width/height). Doing that will result in the panel not being
565 * Later versions of qtwayland do have the correct window geometry for
566 * the desktop surface so the weston_surface is already mapped in
569 if (wsurface->is_mapped)
572 geom = weston_desktop_surface_get_geometry(dsurface);
574 #ifdef AGL_COMP_DEBUG
575 weston_log("geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
576 geom.width, geom.height, geom.x, geom.y);
579 switch (surface->panel.edge) {
580 case AGL_SHELL_EDGE_TOP:
583 case AGL_SHELL_EDGE_BOTTOM:
584 y += woutput->height - geom.height;
586 case AGL_SHELL_EDGE_LEFT:
589 case AGL_SHELL_EDGE_RIGHT:
590 x += woutput->width - geom.width;
593 #ifndef AGL_COMP_DEBUG
594 weston_log("panel type %d commited\n", surface->panel.edge);
597 weston_view_set_output(surface->view, woutput);
598 weston_view_set_position(surface->view, x, y);
599 weston_layer_entry_insert(&ivi->panel.view_list,
600 &surface->view->layer_link);
602 weston_view_update_transform(surface->view);
603 weston_view_schedule_repaint(surface->view);
605 wsurface->is_mapped = true;
606 surface->view->is_mapped = true;
610 ivi_layout_surface_is_split_or_fs(struct ivi_surface *surf)
612 struct ivi_compositor *ivi = surf->ivi;
613 struct ivi_surface *is;
615 if (surf->role != IVI_SURFACE_ROLE_SPLIT_H &&
616 surf->role != IVI_SURFACE_ROLE_SPLIT_V &&
617 surf->role != IVI_SURFACE_ROLE_FS)
620 wl_list_for_each(is, &ivi->surfaces, link)
628 ivi_layout_activate(struct ivi_output *output, const char *app_id)
630 struct ivi_compositor *ivi = output->ivi;
631 struct ivi_surface *surf;
632 struct weston_desktop_surface *dsurf;
633 struct weston_view *view;
634 struct weston_geometry geom;
635 struct ivi_policy *policy = output->ivi->policy;
637 surf = ivi_find_app(ivi, app_id);
641 if (policy && policy->api.surface_activate &&
642 !policy->api.surface_activate(surf, surf->ivi)) {
646 #ifdef AGL_COMP_DEBUG
647 weston_log("Found app_id %s\n", app_id);
650 if (surf->role == IVI_SURFACE_ROLE_POPUP) {
651 ivi_layout_popup_re_add(surf);
655 /* do not 're'-activate surfaces that are split or active */
656 if (surf == output->active ||
657 ivi_layout_surface_is_split_or_fs(surf))
661 dsurf = surf->dsurface;
663 geom = weston_desktop_surface_get_geometry(dsurf);
665 surf->desktop.pending_output = output;
666 if (weston_desktop_surface_get_maximized(dsurf) &&
667 geom.width == output->area.width &&
668 geom.height == output->area.height) {
669 ivi_layout_activate_complete(output, surf);
673 weston_desktop_surface_set_maximized(dsurf, true);
674 weston_desktop_surface_set_size(dsurf,
676 output->area.height);
679 * If the view isn't mapped, we put it onto the hidden layer so it will
680 * start receiving frame events, and will be able to act on our
683 if (!weston_view_is_mapped(view)) {
684 view->is_mapped = true;
685 view->surface->is_mapped = true;
687 weston_view_set_output(view, output->output);
688 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
689 /* force repaint of the entire output */
690 weston_output_damage(output->output);
695 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
697 struct ivi_surface *surf;
698 struct ivi_output *ivi_output;
699 struct ivi_policy *policy = ivi->policy;
701 surf = ivi_find_app(ivi, app_id);
705 if (policy && policy->api.surface_deactivate &&
706 !policy->api.surface_deactivate(surf, surf->ivi)) {
710 ivi_output = ivi_layout_get_output_from_surface(surf);
711 weston_log("deactiving %s\n", app_id);
713 if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
714 struct ivi_surface *previous_active;
716 previous_active = ivi_output->previous_active;
717 if (!previous_active) {
718 /* we don't have a previous active it means we should
720 if (ivi_output->active) {
721 struct weston_view *view;
723 view = ivi_output->active->view;
724 view->is_mapped = false;
725 view->surface->is_mapped = false;
727 weston_layer_entry_remove(&view->layer_link);
728 weston_output_damage(ivi_output->output);
731 struct weston_desktop_surface *dsurface;
732 const char *previous_active_app_id;
734 dsurface = previous_active->dsurface;
735 previous_active_app_id =
736 weston_desktop_surface_get_app_id(dsurface);
737 ivi_layout_activate(ivi_output, previous_active_app_id);
739 } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
740 struct weston_view *view = surf->view;
742 weston_layer_entry_remove(&view->layer_link);
743 weston_view_damage_below(view);