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"
31 #include <libweston-6/compositor.h>
32 #include <libweston-6/libweston-desktop.h>
35 ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
37 struct weston_output *woutput = output->output;
38 struct ivi_surface *bg = output->background;
39 struct weston_view *view;
42 weston_log("WARNING: Output does not have a background\n");
46 assert(bg->role == IVI_SURFACE_ROLE_BACKGROUND);
50 weston_view_set_output(view, woutput);
51 weston_view_set_position(view, woutput->x, woutput->y);
53 view->is_mapped = true;
54 view->surface->is_mapped = true;
56 weston_layer_entry_insert(&ivi->background.view_list, &view->layer_link);
60 ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
61 struct ivi_surface *panel)
63 struct weston_output *woutput = output->output;
64 struct weston_desktop_surface *dsurface;
65 struct weston_view *view;
66 struct weston_geometry geom;
73 assert(panel->role == IVI_SURFACE_ROLE_PANEL);
74 dsurface = panel->dsurface;
76 geom = weston_desktop_surface_get_geometry(dsurface);
78 switch (panel->panel.edge) {
79 case AGL_SHELL_EDGE_TOP:
80 output->area.y += geom.height;
81 output->area.height -= geom.height;
83 case AGL_SHELL_EDGE_BOTTOM:
84 y += woutput->height - geom.height;
85 output->area.height -= geom.height;
87 case AGL_SHELL_EDGE_LEFT:
88 output->area.x += geom.width;
89 output->area.width -= geom.width;
91 case AGL_SHELL_EDGE_RIGHT:
92 x += woutput->width - geom.width;
93 output->area.width -= geom.width;
100 weston_view_set_output(view, woutput);
101 weston_view_set_position(view, x, y);
103 view->is_mapped = true;
104 view->surface->is_mapped = true;
106 weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
110 * Initializes all static parts of the layout, i.e. the background and panels.
113 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
115 ivi_background_init(ivi, output);
119 output->area.width = output->output->width;
120 output->area.height = output->output->height;
122 ivi_panel_init(ivi, output, output->top);
123 ivi_panel_init(ivi, output, output->bottom);
124 ivi_panel_init(ivi, output, output->left);
125 ivi_panel_init(ivi, output, output->right);
127 weston_compositor_schedule_repaint(ivi->compositor);
129 weston_log("Usable area: %dx%d+%d,%d\n",
130 output->area.width, output->area.height,
131 output->area.x, output->area.y);
134 static struct ivi_surface *
135 ivi_find_app(struct ivi_compositor *ivi, const char *app_id)
137 struct ivi_surface *surf;
140 wl_list_for_each(surf, &ivi->surfaces, link) {
141 id = weston_desktop_surface_get_app_id(surf->dsurface);
142 if (id && strcmp(app_id, id) == 0)
150 ivi_layout_activate_complete(struct ivi_output *output,
151 struct ivi_surface *surf)
153 struct ivi_compositor *ivi = output->ivi;
154 struct weston_output *woutput = output->output;
155 struct weston_view *view = surf->view;
157 if (weston_view_is_mapped(view)) {
158 weston_layer_entry_remove(&view->layer_link);
161 weston_view_set_output(view, woutput);
162 weston_view_set_position(view,
163 woutput->x + output->area.x,
164 woutput->y + output->area.y);
166 view->is_mapped = true;
167 view->surface->is_mapped = true;
169 if (output->active) {
170 output->active->view->is_mapped = false;
171 output->active->view->surface->is_mapped = false;
173 weston_layer_entry_remove(&output->active->view->layer_link);
175 output->active = surf;
177 weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
178 weston_view_update_transform(view);
180 weston_view_schedule_repaint(view);
181 surf->desktop.pending_output = NULL;
185 ivi_layout_desktop_committed(struct ivi_surface *surf)
187 struct weston_desktop_surface *dsurf = surf->dsurface;
188 struct weston_geometry geom = weston_desktop_surface_get_geometry(dsurf);
189 struct ivi_output *output;
191 assert(surf->role == IVI_SURFACE_ROLE_DESKTOP);
193 output = surf->desktop.pending_output;
197 if (!weston_desktop_surface_get_maximized(dsurf) ||
198 geom.width != output->area.width ||
199 geom.height != output->area.height)
202 ivi_layout_activate_complete(output, surf);
206 ivi_layout_activate(struct ivi_output *output, const char *app_id)
208 struct ivi_compositor *ivi = output->ivi;
209 struct ivi_surface *surf;
210 struct weston_desktop_surface *dsurf;
211 struct weston_view *view;
212 struct weston_geometry geom;
214 surf = ivi_find_app(ivi, app_id);
218 weston_log("Found app_id %s\n", app_id);
220 if (surf == output->active)
223 dsurf = surf->dsurface;
225 geom = weston_desktop_surface_get_geometry(dsurf);
227 if (weston_desktop_surface_get_maximized(dsurf) &&
228 geom.width == output->area.width &&
229 geom.height == output->area.height) {
230 ivi_layout_activate_complete(output, surf);
234 weston_desktop_surface_set_maximized(dsurf, true);
235 weston_desktop_surface_set_size(dsurf,
237 output->area.height);
240 * If the view isn't mapped, we put it onto the hidden layer so it will
241 * start receiving frame events, and will be able to act on our
244 if (!weston_view_is_mapped(view)) {
245 view->is_mapped = true;
246 view->surface->is_mapped = true;
248 weston_view_set_output(view, output->output);
249 weston_layer_entry_insert(&ivi->hidden.view_list, &view->layer_link);
250 weston_view_schedule_repaint(view);
253 surf->desktop.pending_output = output;