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
27 #include "ivi-compositor.h"
30 #include <libweston/libweston.h>
31 #include <libweston-desktop/libweston-desktop.h>
34 static struct weston_output *
35 get_default_output(struct weston_compositor *compositor)
37 if (wl_list_empty(&compositor->output_list))
40 return wl_container_of(compositor->output_list.next,
41 struct weston_output, link);
46 desktop_advertise_app(struct wl_listener *listener, void *data)
48 struct ivi_surface *surface;
50 surface = wl_container_of(listener, surface, listener_advertise_app);
52 agl_shell_desktop_advertise_application_id(surface->ivi, surface);
56 desktop_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
62 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
68 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
70 struct ivi_compositor *ivi = userdata;
71 struct weston_desktop_client *dclient;
72 struct wl_client *client;
73 struct ivi_surface *surface;
74 struct ivi_output *active_output = NULL;
75 const char *app_id = NULL;
77 dclient = weston_desktop_surface_get_client(dsurface);
78 client = weston_desktop_client_get_client(dclient);
80 surface = zalloc(sizeof *surface);
82 wl_client_post_no_memory(client);
86 surface->view = weston_desktop_surface_create_view(dsurface);
89 wl_client_post_no_memory(client);
94 surface->dsurface = dsurface;
95 surface->role = IVI_SURFACE_ROLE_NONE;
96 surface->activated_by_default = false;
97 surface->advertised_on_launch = false;
99 wl_signal_init(&surface->signal_advertise_app);
101 surface->listener_advertise_app.notify = desktop_advertise_app;
102 wl_signal_add(&surface->signal_advertise_app,
103 &surface->listener_advertise_app);
105 weston_desktop_surface_set_user_data(dsurface, surface);
107 if (ivi->policy && ivi->policy->api.surface_create &&
108 !ivi->policy->api.surface_create(surface, ivi)) {
109 wl_client_post_no_memory(client);
114 app_id = weston_desktop_surface_get_app_id(dsurface);
116 if ((active_output = ivi_layout_find_with_app_id(app_id, ivi)))
117 ivi_set_pending_desktop_surface_remote(active_output, app_id);
119 /* reset any caps to make sure we apply the new caps */
120 ivi_seat_reset_caps_sent(ivi);
122 if (ivi->shell_client.ready) {
123 ivi_check_pending_desktop_surface(surface);
124 weston_log("Added surface %p, app_id %s, role %s\n", surface,
125 app_id, ivi_layout_get_surface_role_name(surface));
128 * We delay creating "normal" desktop surfaces until later, to
129 * give the shell-client an oppurtunity to set the surface as a
132 weston_log("Added surface %p, app_id %s to pending list\n",
134 wl_list_insert(&ivi->pending_surfaces, &surface->link);
139 desktop_surface_check_last_remote_surfaces(struct ivi_compositor *ivi, enum ivi_surface_role role)
142 struct ivi_surface *surf;
144 wl_list_for_each(surf, &ivi->surfaces, link)
145 if (surf->role == role)
152 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
154 struct ivi_surface *surface =
155 weston_desktop_surface_get_user_data(dsurface);
156 struct weston_surface *wsurface =
157 weston_desktop_surface_get_surface(dsurface);
159 struct ivi_output *output = ivi_layout_get_output_from_surface(surface);
161 wl_list_remove(&surface->listener_advertise_app.link);
162 surface->listener_advertise_app.notify = NULL;
164 /* special corner-case, pending_surfaces which are never activated or
165 * being assigned an output might land here so just remove the surface;
167 * the DESKTOP role can happen here as well, because we can fall-back
168 * to that when we try to determine the role type. Application that
169 * do not set the app_id will be land here, when destroyed */
170 if (output == NULL && (surface->role == IVI_SURFACE_ROLE_NONE ||
171 surface->role == IVI_SURFACE_ROLE_DESKTOP))
172 goto skip_output_asignment;
174 assert(output != NULL);
176 /* resize the active surface to the original size */
177 if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
178 surface->role == IVI_SURFACE_ROLE_SPLIT_V) {
179 if (output && output->active) {
180 ivi_layout_desktop_resize(output->active, output->area_saved);
182 /* restore the area back so we can re-use it again if needed */
183 output->area = output->area_saved;
186 /* reset the active surface as well */
187 if (output && output->active && output->active == surface) {
188 output->active->view->is_mapped = false;
189 output->active->view->surface->is_mapped = false;
191 weston_layer_entry_remove(&output->active->view->layer_link);
192 output->active = NULL;
195 /* check if there's a last 'remote' surface and insert a black
196 * surface view if there's no background set for that output
198 if (desktop_surface_check_last_remote_surfaces(output->ivi,
199 IVI_SURFACE_ROLE_REMOTE))
200 if (!output->background)
201 insert_black_surface(output);
203 if (desktop_surface_check_last_remote_surfaces(output->ivi,
204 IVI_SURFACE_ROLE_DESKTOP))
205 if (!output->background)
206 insert_black_surface(output);
208 if (weston_surface_is_mapped(wsurface)) {
209 weston_desktop_surface_unlink_view(surface->view);
210 weston_view_destroy(surface->view);
213 /* invalidate agl-shell surfaces so we can re-use them when
215 if (surface->role == IVI_SURFACE_ROLE_PANEL) {
216 switch (surface->panel.edge) {
217 case AGL_SHELL_EDGE_TOP:
220 case AGL_SHELL_EDGE_BOTTOM:
221 output->bottom = NULL;
223 case AGL_SHELL_EDGE_LEFT:
226 case AGL_SHELL_EDGE_RIGHT:
227 output->right = NULL;
230 assert(!"Invalid edge detected\n");
232 } else if (surface->role == IVI_SURFACE_ROLE_BACKGROUND) {
233 output->background = NULL;
236 skip_output_asignment:
237 weston_log("Removed surface %p, app_id %s, role %s\n", surface,
238 weston_desktop_surface_get_app_id(dsurface),
239 ivi_layout_get_surface_role_name(surface));
241 /* we weren't added to any list if we are still with 'none' as role */
242 if (surface->role != IVI_SURFACE_ROLE_NONE)
243 wl_list_remove(&surface->link);
249 desktop_committed(struct weston_desktop_surface *dsurface,
250 int32_t sx, int32_t sy, void *userdata)
252 struct ivi_surface *surface =
253 weston_desktop_surface_get_user_data(dsurface);
254 struct ivi_policy *policy = surface->ivi->policy;
256 if (policy && policy->api.surface_commited &&
257 !policy->api.surface_commited(surface, surface->ivi))
260 if (!surface->advertised_on_launch)
261 wl_signal_emit(&surface->signal_advertise_app, surface);
263 weston_compositor_schedule_repaint(surface->ivi->compositor);
265 switch (surface->role) {
266 case IVI_SURFACE_ROLE_DESKTOP:
267 case IVI_SURFACE_ROLE_REMOTE:
268 ivi_layout_desktop_committed(surface);
270 case IVI_SURFACE_ROLE_POPUP:
271 ivi_layout_popup_committed(surface);
273 case IVI_SURFACE_ROLE_FULLSCREEN:
274 ivi_layout_fullscreen_committed(surface);
276 case IVI_SURFACE_ROLE_SPLIT_H:
277 case IVI_SURFACE_ROLE_SPLIT_V:
278 ivi_layout_split_committed(surface);
280 case IVI_SURFACE_ROLE_NONE:
281 case IVI_SURFACE_ROLE_BACKGROUND:
282 case IVI_SURFACE_ROLE_PANEL:
283 default: /* fall through */
289 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
290 struct weston_seat *seat, int32_t x, int32_t y,
297 desktop_set_parent(struct weston_desktop_surface *dsurface,
298 struct weston_desktop_surface *parent, void *userdata)
304 desktop_move(struct weston_desktop_surface *dsurface,
305 struct weston_seat *seat, uint32_t serial, void *userdata)
311 desktop_resize(struct weston_desktop_surface *dsurface,
312 struct weston_seat *seat, uint32_t serial,
313 enum weston_desktop_surface_edge edges, void *user_data)
319 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
320 bool fullscreen, struct weston_output *output,
327 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
328 bool maximized, void *userdata)
334 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
341 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
342 int32_t x, int32_t y, void *userdata)
347 static const struct weston_desktop_api desktop_api = {
348 .struct_size = sizeof desktop_api,
349 .ping_timeout = desktop_ping_timeout,
350 .pong = desktop_pong,
351 .surface_added = desktop_surface_added,
352 .surface_removed = desktop_surface_removed,
353 .committed = desktop_committed,
354 .show_window_menu = desktop_show_window_menu,
355 .set_parent = desktop_set_parent,
356 .move = desktop_move,
357 .resize = desktop_resize,
358 .fullscreen_requested = desktop_fullscreen_requested,
359 .maximized_requested = desktop_maximized_requested,
360 .minimized_requested = desktop_minimized_requested,
361 .set_xwayland_position = desktop_set_xwayland_position,
365 ivi_desktop_init(struct ivi_compositor *ivi)
367 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
369 weston_log("Failed to create desktop globals");