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"
29 #include <libweston/libweston.h>
30 #include <libweston-desktop/libweston-desktop.h>
33 static struct weston_output *
34 get_default_output(struct weston_compositor *compositor)
36 if (wl_list_empty(&compositor->output_list))
39 return wl_container_of(compositor->output_list.next,
40 struct weston_output, link);
45 desktop_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
51 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
57 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
59 struct ivi_compositor *ivi = userdata;
60 struct weston_desktop_client *dclient;
61 struct wl_client *client;
62 struct ivi_surface *surface;
64 dclient = weston_desktop_surface_get_client(dsurface);
65 client = weston_desktop_client_get_client(dclient);
67 surface = zalloc(sizeof *surface);
69 wl_client_post_no_memory(client);
73 surface->view = weston_desktop_surface_create_view(dsurface);
76 wl_client_post_no_memory(client);
81 surface->dsurface = dsurface;
82 surface->role = IVI_SURFACE_ROLE_NONE;
83 surface->activated_by_default = false;
85 if (ivi->policy && ivi->policy->api.surface_create &&
86 !ivi->policy->api.surface_create(surface, ivi)) {
88 wl_client_post_no_memory(client);
92 weston_desktop_surface_set_user_data(dsurface, surface);
94 if (ivi->shell_client.ready) {
95 ivi_check_pending_desktop_surface(surface);
98 * We delay creating "normal" desktop surfaces until later, to
99 * give the shell-client an oppurtunity to set the surface as a
102 wl_list_insert(&ivi->pending_surfaces, &surface->link);
107 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
109 struct ivi_surface *surface =
110 weston_desktop_surface_get_user_data(dsurface);
111 struct weston_surface *wsurface =
112 weston_desktop_surface_get_surface(dsurface);
114 struct ivi_output *output;
116 if (surface->role == IVI_SURFACE_ROLE_DESKTOP)
117 output = surface->desktop.last_output;
118 else if (surface->role == IVI_SURFACE_ROLE_POPUP)
119 output = surface->popup.output;
120 else if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
121 surface->role == IVI_SURFACE_ROLE_SPLIT_V)
122 output = surface->split.output;
123 else if (surface->role == IVI_SURFACE_ROLE_FS)
124 output = surface->fs.output;
128 /* resize the active surface to the original size */
129 if (surface->role == IVI_SURFACE_ROLE_SPLIT_H ||
130 surface->role == IVI_SURFACE_ROLE_SPLIT_V) {
131 if (output && output->active) {
132 ivi_layout_desktop_resize(output->active, output->area_saved);
134 /* restore the area back so we can re-use it again if needed */
135 output->area = output->area_saved;
138 /* reset the active surface as well */
139 if (output && output->active && output->active == surface) {
140 output->active->view->is_mapped = false;
141 output->active->view->surface->is_mapped = false;
143 weston_layer_entry_remove(&output->active->view->layer_link);
144 output->active = NULL;
146 if (weston_surface_is_mapped(wsurface)) {
147 weston_desktop_surface_unlink_view(surface->view);
148 weston_view_destroy(surface->view);
151 wl_list_remove(&surface->link);
156 desktop_committed(struct weston_desktop_surface *dsurface,
157 int32_t sx, int32_t sy, void *userdata)
159 struct ivi_surface *surface =
160 weston_desktop_surface_get_user_data(dsurface);
161 struct ivi_policy *policy = surface->ivi->policy;
163 if (policy && policy->api.surface_commited &&
164 !policy->api.surface_commited(surface, surface->ivi))
167 weston_compositor_schedule_repaint(surface->ivi->compositor);
169 switch (surface->role) {
170 case IVI_SURFACE_ROLE_DESKTOP:
171 ivi_layout_desktop_committed(surface);
173 case IVI_SURFACE_ROLE_PANEL:
174 ivi_layout_panel_committed(surface);
176 case IVI_SURFACE_ROLE_POPUP:
177 ivi_layout_popup_committed(surface);
179 case IVI_SURFACE_ROLE_FS:
180 ivi_layout_fs_committed(surface);
182 case IVI_SURFACE_ROLE_SPLIT_H:
183 case IVI_SURFACE_ROLE_SPLIT_V:
184 ivi_layout_split_committed(surface);
186 case IVI_SURFACE_ROLE_NONE:
187 case IVI_SURFACE_ROLE_BACKGROUND:
188 default: /* fall through */
194 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
195 struct weston_seat *seat, int32_t x, int32_t y,
202 desktop_set_parent(struct weston_desktop_surface *dsurface,
203 struct weston_desktop_surface *parent, void *userdata)
209 desktop_move(struct weston_desktop_surface *dsurface,
210 struct weston_seat *seat, uint32_t serial, void *userdata)
216 desktop_resize(struct weston_desktop_surface *dsurface,
217 struct weston_seat *seat, uint32_t serial,
218 enum weston_desktop_surface_edge edges, void *user_data)
224 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
225 bool fullscreen, struct weston_output *output,
232 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
233 bool maximized, void *userdata)
239 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
246 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
247 int32_t x, int32_t y, void *userdata)
252 static const struct weston_desktop_api desktop_api = {
253 .struct_size = sizeof desktop_api,
254 .ping_timeout = desktop_ping_timeout,
255 .pong = desktop_pong,
256 .surface_added = desktop_surface_added,
257 .surface_removed = desktop_surface_removed,
258 .committed = desktop_committed,
259 .show_window_menu = desktop_show_window_menu,
260 .set_parent = desktop_set_parent,
261 .move = desktop_move,
262 .resize = desktop_resize,
263 .fullscreen_requested = desktop_fullscreen_requested,
264 .maximized_requested = desktop_maximized_requested,
265 .minimized_requested = desktop_minimized_requested,
266 .set_xwayland_position = desktop_set_xwayland_position,
270 ivi_desktop_init(struct ivi_compositor *ivi)
272 ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
274 weston_log("Failed to create desktop globals");