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>
33 #include "agl-shell-desktop-server-protocol.h"
36 static struct weston_output *
37 get_default_output(struct weston_compositor *compositor)
39 if (wl_list_empty(&compositor->output_list))
42 return wl_container_of(compositor->output_list.next,
43 struct weston_output, link);
48 desktop_advertise_app(struct wl_listener *listener, void *data)
50 struct ivi_surface *surface;
52 surface = wl_container_of(listener, surface, listener_advertise_app);
54 agl_shell_desktop_advertise_application_id(surface->ivi, surface);
58 desktop_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
64 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
70 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
72 struct ivi_compositor *ivi = userdata;
73 struct weston_desktop_client *dclient;
74 struct wl_client *client;
75 struct ivi_surface *surface;
76 struct ivi_output *active_output = NULL;
77 const char *app_id = NULL;
79 dclient = weston_desktop_surface_get_client(dsurface);
80 client = weston_desktop_client_get_client(dclient);
82 surface = zalloc(sizeof *surface);
84 wl_client_post_no_memory(client);
88 surface->view = weston_desktop_surface_create_view(dsurface);
91 wl_client_post_no_memory(client);
96 surface->dsurface = dsurface;
97 surface->role = IVI_SURFACE_ROLE_NONE;
98 surface->activated_by_default = false;
99 surface->advertised_on_launch = false;
100 surface->checked_pending = false;
101 wl_list_init(&surface->link);
103 wl_signal_init(&surface->signal_advertise_app);
105 surface->listener_advertise_app.notify = desktop_advertise_app;
106 wl_signal_add(&surface->signal_advertise_app,
107 &surface->listener_advertise_app);
109 weston_desktop_surface_set_user_data(dsurface, surface);
111 if (ivi->policy && ivi->policy->api.surface_create &&
112 !ivi->policy->api.surface_create(surface, ivi)) {
113 wl_client_post_no_memory(client);
118 app_id = weston_desktop_surface_get_app_id(dsurface);
120 if ((active_output = ivi_layout_find_with_app_id(app_id, ivi)))
121 ivi_set_pending_desktop_surface_remote(active_output, app_id);
123 /* reset any caps to make sure we apply the new caps */
124 ivi_seat_reset_caps_sent(ivi);
127 * We delay creating "normal" desktop surfaces until later, to
128 * give the shell-client an oppurtunity to set the surface as a
130 * Also delay the creation in order to have a valid app_id
131 * which will be used to set the proper role.
133 weston_log("Added surface %p, app_id %s to pending list\n",
135 wl_list_insert(&ivi->pending_surfaces, &surface->link);
140 desktop_surface_check_last_remote_surfaces(struct ivi_compositor *ivi, enum ivi_surface_role role)
143 struct ivi_surface *surf;
145 wl_list_for_each(surf, &ivi->surfaces, link)
146 if (surf->role == role)
153 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
155 struct ivi_surface *surface =
156 weston_desktop_surface_get_user_data(dsurface);
157 struct weston_surface *wsurface =
158 weston_desktop_surface_get_surface(dsurface);
159 const char *app_id = NULL;
161 struct ivi_output *output = ivi_layout_get_output_from_surface(surface);
163 wl_list_remove(&surface->listener_advertise_app.link);
164 surface->listener_advertise_app.notify = NULL;
166 app_id = weston_desktop_surface_get_app_id(dsurface);
168 /* special corner-case, pending_surfaces which are never activated or
169 * being assigned an output might land here so just remove the surface;
171 * the DESKTOP role can happen here as well, because we can fall-back
172 * to that when we try to determine the role type. Application that
173 * do not set the app_id will be land here, when destroyed */
174 if (output == NULL && (surface->role == IVI_SURFACE_ROLE_NONE ||
175 surface->role == IVI_SURFACE_ROLE_DESKTOP))
176 goto skip_output_asignment;
178 assert(output != NULL);
180 /* resize the active surface to the original size */
181 if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
182 surface->role == IVI_SURFACE_ROLE_SPLIT_V) {
183 if (output && output->active) {
184 ivi_layout_desktop_resize(output->active, output->area_saved);
186 /* restore the area back so we can re-use it again if needed */
187 output->area = output->area_saved;
190 /* reset the active surface as well */
191 if (output && output->active && output->active == surface) {
192 output->active->view->is_mapped = false;
193 output->active->view->surface->is_mapped = false;
195 weston_layer_entry_remove(&output->active->view->layer_link);
196 output->active = NULL;
199 if (surface->role == IVI_SURFACE_ROLE_REMOTE &&
200 output->type == OUTPUT_REMOTE)
201 ivi_destroy_waltham_destroy(surface);
203 /* check if there's a last 'remote' surface and insert a black
204 * surface view if there's no background set for that output
206 if ((desktop_surface_check_last_remote_surfaces(output->ivi,
207 IVI_SURFACE_ROLE_REMOTE) ||
208 desktop_surface_check_last_remote_surfaces(output->ivi,
209 IVI_SURFACE_ROLE_DESKTOP)) && output->type == OUTPUT_REMOTE)
210 if (!output->background)
211 insert_black_surface(output);
214 if (weston_surface_is_mapped(wsurface)) {
215 weston_desktop_surface_unlink_view(surface->view);
216 weston_view_destroy(surface->view);
219 /* invalidate agl-shell surfaces so we can re-use them when
221 if (surface->role == IVI_SURFACE_ROLE_PANEL) {
222 switch (surface->panel.edge) {
223 case AGL_SHELL_EDGE_TOP:
226 case AGL_SHELL_EDGE_BOTTOM:
227 output->bottom = NULL;
229 case AGL_SHELL_EDGE_LEFT:
232 case AGL_SHELL_EDGE_RIGHT:
233 output->right = NULL;
236 assert(!"Invalid edge detected\n");
238 } else if (surface->role == IVI_SURFACE_ROLE_BACKGROUND) {
239 output->background = NULL;
242 skip_output_asignment:
243 weston_log("Removed surface %p, app_id %s, role %s\n", surface,
244 app_id, ivi_layout_get_surface_role_name(surface));
246 if (app_id && output)
247 shell_advertise_app_state(output->ivi, app_id,
248 NULL, AGL_SHELL_DESKTOP_APP_STATE_DESTROYED);
250 wl_list_remove(&surface->link);
256 desktop_committed(struct weston_desktop_surface *dsurface,
257 int32_t sx, int32_t sy, void *userdata)
259 struct ivi_compositor *ivi = userdata;
260 struct ivi_surface *surface =
261 weston_desktop_surface_get_user_data(dsurface);
262 struct ivi_policy *policy = surface->ivi->policy;
264 if (policy && policy->api.surface_commited &&
265 !policy->api.surface_commited(surface, surface->ivi))
268 if (ivi->shell_client.ready && !surface->checked_pending) {
269 const char * app_id = weston_desktop_surface_get_app_id(dsurface);
270 weston_log("Checking pending surface %p, app_id %s\n", surface,
272 wl_list_remove(&surface->link);
273 wl_list_init(&surface->link);
274 ivi_check_pending_desktop_surface(surface);
275 surface->checked_pending = true;
278 if (!surface->advertised_on_launch &&
279 !wl_list_empty(&surface->ivi->desktop_clients))
280 wl_signal_emit(&surface->signal_advertise_app, surface);
282 weston_compositor_schedule_repaint(surface->ivi->compositor);
284 switch (surface->role) {
285 case IVI_SURFACE_ROLE_DESKTOP:
286 case IVI_SURFACE_ROLE_REMOTE:
287 ivi_layout_desktop_committed(surface);
289 case IVI_SURFACE_ROLE_POPUP:
290 ivi_layout_popup_committed(surface);
292 case IVI_SURFACE_ROLE_FULLSCREEN:
293 ivi_layout_fullscreen_committed(surface);
295 case IVI_SURFACE_ROLE_SPLIT_H:
296 case IVI_SURFACE_ROLE_SPLIT_V:
297 ivi_layout_split_committed(surface);
299 case IVI_SURFACE_ROLE_NONE:
300 case IVI_SURFACE_ROLE_BACKGROUND:
301 case IVI_SURFACE_ROLE_PANEL:
302 default: /* fall through */
308 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
309 struct weston_seat *seat, int32_t x, int32_t y,
316 desktop_set_parent(struct weston_desktop_surface *dsurface,
317 struct weston_desktop_surface *parent, void *userdata)
323 desktop_move(struct weston_desktop_surface *dsurface,
324 struct weston_seat *seat, uint32_t serial, void *userdata)
330 desktop_resize(struct weston_desktop_surface *dsurface,
331 struct weston_seat *seat, uint32_t serial,
332 enum weston_desktop_surface_edge edges, void *user_data)
338 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
339 bool fullscreen, struct weston_output *output,
346 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
347 bool maximized, void *userdata)
353 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
360 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
361 int32_t x, int32_t y, void *userdata)
366 static const struct weston_desktop_api desktop_api = {
367 .struct_size = sizeof desktop_api,
368 .ping_timeout = desktop_ping_timeout,
369 .pong = desktop_pong,
370 .surface_added = desktop_surface_added,
371 .surface_removed = desktop_surface_removed,
372 .committed = desktop_committed,
373 .show_window_menu = desktop_show_window_menu,
374 .set_parent = desktop_set_parent,
375 .move = desktop_move,
376 .resize = desktop_resize,
377 .fullscreen_requested = desktop_fullscreen_requested,
378 .maximized_requested = desktop_maximized_requested,
379 .minimized_requested = desktop_minimized_requested,
380 .set_xwayland_position = desktop_set_xwayland_position,
384 ivi_desktop_init(struct ivi_compositor *ivi)
386 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
388 weston_log("Failed to create desktop globals");