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;
65 dclient = weston_desktop_surface_get_client(dsurface);
66 client = weston_desktop_client_get_client(dclient);
68 surface = zalloc(sizeof *surface);
70 wl_client_post_no_memory(client);
74 surface->view = weston_desktop_surface_create_view(dsurface);
77 wl_client_post_no_memory(client);
82 surface->dsurface = dsurface;
83 surface->role = IVI_SURFACE_ROLE_NONE;
84 surface->activated_by_default = false;
86 if (ivi->policy && ivi->policy->api.surface_create &&
87 !ivi->policy->api.surface_create(surface, ivi)) {
89 wl_client_post_no_memory(client);
93 weston_desktop_surface_set_user_data(dsurface, surface);
95 if (ivi->shell_client.ready) {
96 ivi_check_pending_desktop_surface(surface);
99 * We delay creating "normal" desktop surfaces until later, to
100 * give the shell-client an oppurtunity to set the surface as a
103 wl_list_insert(&ivi->pending_surfaces, &surface->link);
108 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
110 struct ivi_surface *surface =
111 weston_desktop_surface_get_user_data(dsurface);
112 struct weston_surface *wsurface =
113 weston_desktop_surface_get_surface(dsurface);
115 struct ivi_output *output;
117 if (surface->role == IVI_SURFACE_ROLE_DESKTOP)
118 output = surface->desktop.last_output;
119 else if (surface->role == IVI_SURFACE_ROLE_POPUP)
120 output = surface->popup.output;
121 else if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
122 surface->role == IVI_SURFACE_ROLE_SPLIT_V)
123 output = surface->split.output;
124 else if (surface->role == IVI_SURFACE_ROLE_FULLSCREEN)
125 output = surface->fullscreen.output;
129 /* resize the active surface to the original size */
130 if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
131 surface->role == IVI_SURFACE_ROLE_SPLIT_V) {
132 if (output && output->active) {
133 ivi_layout_desktop_resize(output->active, output->area_saved);
135 /* restore the area back so we can re-use it again if needed */
136 output->area = output->area_saved;
139 /* reset the active surface as well */
140 if (output && output->active && output->active == surface) {
141 output->active->view->is_mapped = false;
142 output->active->view->surface->is_mapped = false;
144 weston_layer_entry_remove(&output->active->view->layer_link);
145 output->active = NULL;
147 if (weston_surface_is_mapped(wsurface)) {
148 weston_desktop_surface_unlink_view(surface->view);
149 weston_view_destroy(surface->view);
152 /* invalidate agl-shell surfaces so we can re-use them when
154 if (surface->role == IVI_SURFACE_ROLE_PANEL) {
155 switch (surface->panel.edge) {
156 case AGL_SHELL_EDGE_TOP:
159 case AGL_SHELL_EDGE_BOTTOM:
160 output->bottom = NULL;
162 case AGL_SHELL_EDGE_LEFT:
165 case AGL_SHELL_EDGE_RIGHT:
166 output->right = NULL;
169 assert(!"Invalid edge detected\n");
171 } else if (surface->role == IVI_SURFACE_ROLE_BACKGROUND) {
172 output->background = NULL;
175 wl_list_remove(&surface->link);
180 desktop_committed(struct weston_desktop_surface *dsurface,
181 int32_t sx, int32_t sy, void *userdata)
183 struct ivi_surface *surface =
184 weston_desktop_surface_get_user_data(dsurface);
185 struct ivi_policy *policy = surface->ivi->policy;
187 if (policy && policy->api.surface_commited &&
188 !policy->api.surface_commited(surface, surface->ivi))
191 weston_compositor_schedule_repaint(surface->ivi->compositor);
193 switch (surface->role) {
194 case IVI_SURFACE_ROLE_DESKTOP:
195 ivi_layout_desktop_committed(surface);
197 case IVI_SURFACE_ROLE_PANEL:
198 ivi_layout_panel_committed(surface);
200 case IVI_SURFACE_ROLE_POPUP:
201 ivi_layout_popup_committed(surface);
203 case IVI_SURFACE_ROLE_FULLSCREEN:
204 ivi_layout_fullscreen_committed(surface);
206 case IVI_SURFACE_ROLE_SPLIT_H:
207 case IVI_SURFACE_ROLE_SPLIT_V:
208 ivi_layout_split_committed(surface);
210 case IVI_SURFACE_ROLE_NONE:
211 case IVI_SURFACE_ROLE_BACKGROUND:
212 default: /* fall through */
218 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
219 struct weston_seat *seat, int32_t x, int32_t y,
226 desktop_set_parent(struct weston_desktop_surface *dsurface,
227 struct weston_desktop_surface *parent, void *userdata)
233 desktop_move(struct weston_desktop_surface *dsurface,
234 struct weston_seat *seat, uint32_t serial, void *userdata)
240 desktop_resize(struct weston_desktop_surface *dsurface,
241 struct weston_seat *seat, uint32_t serial,
242 enum weston_desktop_surface_edge edges, void *user_data)
248 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
249 bool fullscreen, struct weston_output *output,
256 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
257 bool maximized, void *userdata)
263 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
270 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
271 int32_t x, int32_t y, void *userdata)
276 static const struct weston_desktop_api desktop_api = {
277 .struct_size = sizeof desktop_api,
278 .ping_timeout = desktop_ping_timeout,
279 .pong = desktop_pong,
280 .surface_added = desktop_surface_added,
281 .surface_removed = desktop_surface_removed,
282 .committed = desktop_committed,
283 .show_window_menu = desktop_show_window_menu,
284 .set_parent = desktop_set_parent,
285 .move = desktop_move,
286 .resize = desktop_resize,
287 .fullscreen_requested = desktop_fullscreen_requested,
288 .maximized_requested = desktop_maximized_requested,
289 .minimized_requested = desktop_minimized_requested,
290 .set_xwayland_position = desktop_set_xwayland_position,
294 ivi_desktop_init(struct ivi_compositor *ivi)
296 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
298 weston_log("Failed to create desktop globals");