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_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
52 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
58 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
60 struct ivi_compositor *ivi = userdata;
61 struct weston_desktop_client *dclient;
62 struct wl_client *client;
63 struct ivi_surface *surface;
64 struct ivi_output *active_output = NULL;
65 const char *app_id = NULL;
67 dclient = weston_desktop_surface_get_client(dsurface);
68 client = weston_desktop_client_get_client(dclient);
70 surface = zalloc(sizeof *surface);
72 wl_client_post_no_memory(client);
76 surface->view = weston_desktop_surface_create_view(dsurface);
79 wl_client_post_no_memory(client);
84 surface->dsurface = dsurface;
85 surface->role = IVI_SURFACE_ROLE_NONE;
86 surface->activated_by_default = false;
88 if (ivi->policy && ivi->policy->api.surface_create &&
89 !ivi->policy->api.surface_create(surface, ivi)) {
91 wl_client_post_no_memory(client);
95 weston_desktop_surface_set_user_data(dsurface, surface);
97 app_id = weston_desktop_surface_get_app_id(dsurface);
99 if ((active_output = ivi_layout_find_with_app_id(app_id, ivi)))
100 ivi_set_pending_desktop_surface_remote(active_output, app_id);
102 if (ivi->shell_client.ready) {
103 ivi_check_pending_desktop_surface(surface);
104 weston_log("Added surface %p, app_id %s, role %s\n", surface,
105 app_id, ivi_layout_get_surface_role_name(surface));
108 * We delay creating "normal" desktop surfaces until later, to
109 * give the shell-client an oppurtunity to set the surface as a
112 weston_log("Added surface %p, app_id %s to pending list\n",
114 wl_list_insert(&ivi->pending_surfaces, &surface->link);
119 desktop_surface_check_last_remote_surfaces(struct ivi_compositor *ivi, enum ivi_surface_role role)
122 struct ivi_surface *surf;
124 wl_list_for_each(surf, &ivi->surfaces, link)
125 if (surf->role == role)
132 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
134 struct ivi_surface *surface =
135 weston_desktop_surface_get_user_data(dsurface);
136 struct weston_surface *wsurface =
137 weston_desktop_surface_get_surface(dsurface);
139 struct ivi_output *output = ivi_layout_get_output_from_surface(surface);
141 /* special corner-case, pending_surfaces which are never activated or
142 * being assigned an output might land here so just remove the surface */
143 if (output == NULL && surface->role == IVI_SURFACE_ROLE_NONE)
144 goto skip_output_asignment;
146 assert(output != NULL);
148 /* resize the active surface to the original size */
149 if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
150 surface->role == IVI_SURFACE_ROLE_SPLIT_V) {
151 if (output && output->active) {
152 ivi_layout_desktop_resize(output->active, output->area_saved);
154 /* restore the area back so we can re-use it again if needed */
155 output->area = output->area_saved;
158 /* reset the active surface as well */
159 if (output && output->active && output->active == surface) {
160 output->active->view->is_mapped = false;
161 output->active->view->surface->is_mapped = false;
163 weston_layer_entry_remove(&output->active->view->layer_link);
164 output->active = NULL;
167 /* check if there's a last 'remote' surface and insert a black
168 * surface view if there's no background set for that output
170 if (desktop_surface_check_last_remote_surfaces(output->ivi,
171 IVI_SURFACE_ROLE_REMOTE))
172 if (!output->background)
173 insert_black_surface(output);
175 if (desktop_surface_check_last_remote_surfaces(output->ivi,
176 IVI_SURFACE_ROLE_DESKTOP))
177 if (!output->background)
178 insert_black_surface(output);
180 if (weston_surface_is_mapped(wsurface)) {
181 weston_desktop_surface_unlink_view(surface->view);
182 weston_view_destroy(surface->view);
185 /* invalidate agl-shell surfaces so we can re-use them when
187 if (surface->role == IVI_SURFACE_ROLE_PANEL) {
188 switch (surface->panel.edge) {
189 case AGL_SHELL_EDGE_TOP:
192 case AGL_SHELL_EDGE_BOTTOM:
193 output->bottom = NULL;
195 case AGL_SHELL_EDGE_LEFT:
198 case AGL_SHELL_EDGE_RIGHT:
199 output->right = NULL;
202 assert(!"Invalid edge detected\n");
204 } else if (surface->role == IVI_SURFACE_ROLE_BACKGROUND) {
205 output->background = NULL;
208 skip_output_asignment:
209 weston_log("Removed surface %p, app_id %s, role %s\n", surface,
210 weston_desktop_surface_get_app_id(dsurface),
211 ivi_layout_get_surface_role_name(surface));
212 wl_list_remove(&surface->link);
217 desktop_committed(struct weston_desktop_surface *dsurface,
218 int32_t sx, int32_t sy, void *userdata)
220 struct ivi_surface *surface =
221 weston_desktop_surface_get_user_data(dsurface);
222 struct ivi_policy *policy = surface->ivi->policy;
224 if (policy && policy->api.surface_commited &&
225 !policy->api.surface_commited(surface, surface->ivi))
228 weston_compositor_schedule_repaint(surface->ivi->compositor);
230 switch (surface->role) {
231 case IVI_SURFACE_ROLE_DESKTOP:
232 case IVI_SURFACE_ROLE_REMOTE:
233 ivi_layout_desktop_committed(surface);
235 case IVI_SURFACE_ROLE_POPUP:
236 ivi_layout_popup_committed(surface);
238 case IVI_SURFACE_ROLE_FULLSCREEN:
239 ivi_layout_fullscreen_committed(surface);
241 case IVI_SURFACE_ROLE_SPLIT_H:
242 case IVI_SURFACE_ROLE_SPLIT_V:
243 ivi_layout_split_committed(surface);
245 case IVI_SURFACE_ROLE_NONE:
246 case IVI_SURFACE_ROLE_BACKGROUND:
247 case IVI_SURFACE_ROLE_PANEL:
248 default: /* fall through */
254 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
255 struct weston_seat *seat, int32_t x, int32_t y,
262 desktop_set_parent(struct weston_desktop_surface *dsurface,
263 struct weston_desktop_surface *parent, void *userdata)
269 desktop_move(struct weston_desktop_surface *dsurface,
270 struct weston_seat *seat, uint32_t serial, void *userdata)
276 desktop_resize(struct weston_desktop_surface *dsurface,
277 struct weston_seat *seat, uint32_t serial,
278 enum weston_desktop_surface_edge edges, void *user_data)
284 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
285 bool fullscreen, struct weston_output *output,
292 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
293 bool maximized, void *userdata)
299 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
306 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
307 int32_t x, int32_t y, void *userdata)
312 static const struct weston_desktop_api desktop_api = {
313 .struct_size = sizeof desktop_api,
314 .ping_timeout = desktop_ping_timeout,
315 .pong = desktop_pong,
316 .surface_added = desktop_surface_added,
317 .surface_removed = desktop_surface_removed,
318 .committed = desktop_committed,
319 .show_window_menu = desktop_show_window_menu,
320 .set_parent = desktop_set_parent,
321 .move = desktop_move,
322 .resize = desktop_resize,
323 .fullscreen_requested = desktop_fullscreen_requested,
324 .maximized_requested = desktop_maximized_requested,
325 .minimized_requested = desktop_minimized_requested,
326 .set_xwayland_position = desktop_set_xwayland_position,
330 ivi_desktop_init(struct ivi_compositor *ivi)
332 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
334 weston_log("Failed to create desktop globals");