layout: Do not delay mapping of desktop surface until commit time
[src/agl-compositor.git] / src / desktop.c
1 /*
2  * Copyright © 2019 Collabora, Ltd.
3  *
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:
11  *
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.
15  *
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
23  * SOFTWARE.
24  */
25
26 #include "ivi-compositor.h"
27
28 #include <libweston-6/compositor.h>
29 #include <libweston-6/libweston-desktop.h>
30
31 #if 0
32 static struct weston_output *
33 get_default_output(struct weston_compositor *compositor)
34 {
35         if (wl_list_empty(&compositor->output_list))
36                 return NULL;
37
38         return wl_container_of(compositor->output_list.next,
39                                struct weston_output, link);
40 }
41 #endif
42
43 static void
44 desktop_ping_timeout(struct weston_desktop_client *dclient, void *userdata)
45 {
46         /* not supported */
47 }
48
49 static void
50 desktop_pong(struct weston_desktop_client *dclient, void *userdata)
51 {
52         /* not supported */
53 }
54
55 static void
56 desktop_surface_added(struct weston_desktop_surface *dsurface, void *userdata)
57 {
58         struct ivi_compositor *ivi = userdata;
59         struct weston_desktop_client *dclient;
60         struct wl_client *client;
61         struct ivi_surface *surface;
62
63         dclient = weston_desktop_surface_get_client(dsurface);
64         client = weston_desktop_client_get_client(dclient);
65
66         surface = zalloc(sizeof *surface);
67         if (!surface) {
68                 wl_client_post_no_memory(client);
69                 return;
70         }
71
72         surface->view = weston_desktop_surface_create_view(dsurface);
73         if (!surface->view) {
74                 free(surface);
75                 wl_client_post_no_memory(client);
76                 return;
77         }
78
79         surface->ivi = ivi;
80         surface->dsurface = dsurface;
81         surface->role = IVI_SURFACE_ROLE_NONE;
82
83         weston_desktop_surface_set_user_data(dsurface, surface);
84
85         if (ivi->shell_client.ready) {
86                 ivi_set_desktop_surface(surface);
87         } else {
88                 /*
89                  * We delay creating "normal" desktop surfaces until later, to
90                  * give the shell-client an oppurtunity to set the surface as a
91                  * background/panel.
92                  */
93                 wl_list_insert(&ivi->pending_surfaces, &surface->link);
94         }
95 }
96
97 static void
98 desktop_surface_removed(struct weston_desktop_surface *dsurface, void *userdata)
99 {
100         struct ivi_surface *surface =
101                 weston_desktop_surface_get_user_data(dsurface);
102         struct weston_surface *wsurface =
103                 weston_desktop_surface_get_surface(dsurface);
104
105         /* TODO */
106         if (surface->role != IVI_SURFACE_ROLE_DESKTOP)
107                 return;
108
109         if (weston_surface_is_mapped(wsurface)) {
110                 weston_desktop_surface_unlink_view(surface->view);
111                 weston_view_destroy(surface->view);
112                 wl_list_remove(&surface->link);
113         }
114         free(surface);
115 }
116
117 static void
118 desktop_committed(struct weston_desktop_surface *dsurface, 
119                   int32_t sx, int32_t sy, void *userdata)
120 {
121         struct ivi_surface *surface =
122                 weston_desktop_surface_get_user_data(dsurface);
123         weston_compositor_schedule_repaint(surface->ivi->compositor);
124
125         switch (surface->role) {
126         case IVI_SURFACE_ROLE_DESKTOP:
127                 ivi_layout_desktop_committed(surface);
128                 break;
129         case IVI_SURFACE_ROLE_PANEL:
130                 ivi_layout_panel_committed(surface);
131                 break;
132         case IVI_SURFACE_ROLE_NONE:
133         case IVI_SURFACE_ROLE_BACKGROUND:
134         default: /* fall through */
135                 break;
136         }
137 }
138
139 static void
140 desktop_show_window_menu(struct weston_desktop_surface *dsurface,
141                          struct weston_seat *seat, int32_t x, int32_t y,
142                          void *userdata)
143 {
144         /* not supported */
145 }
146
147 static void
148 desktop_set_parent(struct weston_desktop_surface *dsurface,
149                    struct weston_desktop_surface *parent, void *userdata)
150 {
151         /* not supported */
152 }
153
154 static void
155 desktop_move(struct weston_desktop_surface *dsurface,
156              struct weston_seat *seat, uint32_t serial, void *userdata)
157 {
158         /* not supported */
159 }
160
161 static void
162 desktop_resize(struct weston_desktop_surface *dsurface,
163                struct weston_seat *seat, uint32_t serial,
164                enum weston_desktop_surface_edge edges, void *user_data)
165 {
166         /* not supported */
167 }
168
169 static void
170 desktop_fullscreen_requested(struct weston_desktop_surface *dsurface,
171                              bool fullscreen, struct weston_output *output,
172                              void *userdata)
173 {
174         /* not supported */
175 }
176
177 static void
178 desktop_maximized_requested(struct weston_desktop_surface *dsurface,
179                             bool maximized, void *userdata)
180 {
181         /* not supported */
182 }
183
184 static void
185 desktop_minimized_requested(struct weston_desktop_surface *dsurface,
186                             void *userdata)
187 {
188         /* not supported */
189 }
190
191 static void
192 desktop_set_xwayland_position(struct weston_desktop_surface *dsurface,
193                               int32_t x, int32_t y, void *userdata)
194 {
195         /* not supported */
196 }
197
198 static const struct weston_desktop_api desktop_api = {
199         .struct_size = sizeof desktop_api,
200         .ping_timeout = desktop_ping_timeout,
201         .pong = desktop_pong,
202         .surface_added = desktop_surface_added,
203         .surface_removed = desktop_surface_removed,
204         .committed = desktop_committed,
205         .show_window_menu = desktop_show_window_menu,
206         .set_parent = desktop_set_parent,
207         .move = desktop_move,
208         .resize = desktop_resize,
209         .fullscreen_requested = desktop_fullscreen_requested,
210         .maximized_requested = desktop_maximized_requested,
211         .minimized_requested = desktop_minimized_requested,
212         .set_xwayland_position = desktop_set_xwayland_position,
213 };
214
215 int
216 ivi_desktop_init(struct ivi_compositor *ivi)
217 {
218         ivi->desktop = weston_desktop_create(ivi->compositor, &desktop_api, ivi);
219         if (!ivi->desktop) {
220                 weston_log("Failed to create desktop globals");
221                 return -1;
222         }
223
224         return 0;
225 }