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 <libweston-6/compositor.h>
29 #include <libweston-6/libweston-desktop.h>
32 static struct weston_output *
33 get_default_output(struct weston_compositor *compositor)
35 if (wl_list_empty(&compositor->output_list))
38 return wl_container_of(compositor->output_list.next,
39 struct weston_output, link);
44 desktop_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
50 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
56 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
58 struct ivi_compositor *ivi = userdata;
59 struct weston_desktop_client *dclient;
60 struct wl_client *client;
61 struct ivi_surface *surface;
63 dclient = weston_desktop_surface_get_client(dsurface);
64 client = weston_desktop_client_get_client(dclient);
66 surface = zalloc(sizeof *surface);
68 wl_client_post_no_memory(client);
73 surface->dsurface = dsurface;
74 surface->role = IVI_SURFACE_ROLE_NONE;
75 surface->old_geom.width = -1;
76 surface->old_geom.height = -1;
78 weston_desktop_surface_set_user_data(dsurface, surface);
80 if (ivi->shell_client.ready) {
81 ivi_set_desktop_surface(surface);
83 ivi_reflow_outputs(ivi);
86 * We delay creating "normal" desktop surfaces until later, to
87 * give the shell-client an oppurtunity to set the surface as a
90 wl_list_insert(&ivi->pending_surfaces, &surface->link);
95 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
97 struct ivi_surface *surface =
98 weston_desktop_surface_get_user_data(dsurface);
99 struct weston_surface *wsurface =
100 weston_desktop_surface_get_surface(dsurface);
101 struct ivi_compositor *ivi = surface->ivi;
104 if (surface->role != IVI_SURFACE_ROLE_DESKTOP)
107 if (weston_surface_is_mapped(wsurface)) {
108 weston_desktop_surface_unlink_view(surface->desktop.view);
109 weston_view_destroy(surface->desktop.view);
110 wl_list_remove(&surface->link);
114 ivi_reflow_outputs(ivi);
118 surface_committed(struct ivi_surface *surface)
120 struct ivi_compositor *ivi = surface->ivi;
121 struct weston_desktop_surface *dsurface = surface->dsurface;
122 struct weston_geometry geom, old_geom;
124 old_geom = surface->old_geom;
125 geom = weston_desktop_surface_get_geometry(dsurface);
127 surface->old_geom = geom;
129 if (geom.width != old_geom.width || geom.height != old_geom.height) {
130 ivi_reflow_outputs(ivi);
133 //wl_list_insert(&ivi->surfaces, &surface->link);
137 background_committed(struct ivi_surface *surface)
139 struct ivi_compositor *ivi = surface->ivi;
140 struct ivi_output *output = surface->bg.output;
141 struct weston_output *woutput = output->output;
142 struct weston_desktop_surface *dsurface = surface->dsurface;
143 struct weston_surface *wsurface =
144 weston_desktop_surface_get_surface(dsurface);
146 if (wsurface->is_mapped)
149 surface->bg.view = weston_desktop_surface_create_view(dsurface);
151 weston_view_set_output(surface->bg.view, woutput);
152 weston_view_set_position(surface->bg.view,
155 weston_layer_entry_insert(&ivi->background.view_list,
156 &surface->bg.view->layer_link);
158 weston_view_update_transform(surface->bg.view);
159 weston_view_schedule_repaint(surface->bg.view);
161 wsurface->is_mapped = true;
165 panel_committed(struct ivi_surface *surface)
167 struct ivi_compositor *ivi = surface->ivi;
168 struct ivi_output *output = surface->bg.output;
169 struct weston_output *woutput = output->output;
170 struct weston_desktop_surface *dsurface = surface->dsurface;
171 struct weston_surface *wsurface =
172 weston_desktop_surface_get_surface(dsurface);
173 struct weston_geometry geom;
174 int32_t x = woutput->x;
175 int32_t y = woutput->y;
177 if (wsurface->is_mapped)
180 surface->panel.view = weston_desktop_surface_create_view(dsurface);
182 geom = weston_desktop_surface_get_geometry(dsurface);
183 switch (surface->panel.edge) {
184 case AGL_SHELL_EDGE_TOP:
187 case AGL_SHELL_EDGE_BOTTOM:
188 y += woutput->height - geom.height;
190 case AGL_SHELL_EDGE_LEFT:
193 case AGL_SHELL_EDGE_RIGHT:
194 x += woutput->width - geom.width;
198 weston_view_set_output(surface->panel.view, woutput);
199 weston_view_set_position(surface->panel.view, x, y);
200 weston_layer_entry_insert(&ivi->normal.view_list,
201 &surface->panel.view->layer_link);
203 weston_view_update_transform(surface->panel.view);
204 weston_view_schedule_repaint(surface->panel.view);
206 wsurface->is_mapped = true;
210 desktop_committed(struct weston_desktop_surface *dsurface,
211 int32_t sx, int32_t sy, void *userdata)
213 struct ivi_surface *surface =
214 weston_desktop_surface_get_user_data(dsurface);
216 weston_compositor_schedule_repaint(surface->ivi->compositor);
218 switch (surface->role) {
219 case IVI_SURFACE_ROLE_NONE:
221 case IVI_SURFACE_ROLE_DESKTOP:
222 surface_committed(surface);
224 case IVI_SURFACE_ROLE_BACKGROUND:
225 background_committed(surface);
227 case IVI_SURFACE_ROLE_PANEL:
228 panel_committed(surface);
234 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
235 struct weston_seat *seat, int32_t x, int32_t y,
242 desktop_set_parent(struct weston_desktop_surface *dsurface,
243 struct weston_desktop_surface *parent, void *userdata)
249 desktop_move(struct weston_desktop_surface *dsurface,
250 struct weston_seat *seat, uint32_t serial, void *userdata)
256 desktop_resize(struct weston_desktop_surface *dsurface,
257 struct weston_seat *seat, uint32_t serial,
258 enum weston_desktop_surface_edge edges, void *user_data)
264 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
265 bool fullscreen, struct weston_output *output,
272 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
273 bool maximized, void *userdata)
279 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
286 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
287 int32_t x, int32_t y, void *userdata)
292 static const struct weston_desktop_api desktop_api = {
293 .struct_size = sizeof desktop_api,
294 .ping_timeout = desktop_ping_timeout,
295 .pong = desktop_pong,
296 .surface_added = desktop_surface_added,
297 .surface_removed = desktop_surface_removed,
298 .committed = desktop_committed,
299 .show_window_menu = desktop_show_window_menu,
300 .set_parent = desktop_set_parent,
301 .move = desktop_move,
302 .resize = desktop_resize,
303 .fullscreen_requested = desktop_fullscreen_requested,
304 .maximized_requested = desktop_maximized_requested,
305 .minimized_requested = desktop_minimized_requested,
306 .set_xwayland_position = desktop_set_xwayland_position,
310 ivi_desktop_init(struct ivi_compositor *ivi)
312 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
314 weston_log("Failed to create desktop globals");