2 * Copyright (C) 2013 DENSO CORPORATION
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * ivi-shell supports a type of shell for In-Vehicle Infotainment system.
25 * In-Vehicle Infotainment system traditionally manages surfaces with global
26 * identification. A protocol, ivi_application, supports such a feature
27 * by implementing a request, ivi_application::surface_creation defined in
28 * ivi_application.xml.
30 * The ivi-shell explicitly loads a module to add business logic like how to
31 * layout surfaces by using internal ivi-layout APIs.
40 #include "ivi-shell.h"
41 #include "ivi-application-server-protocol.h"
42 #include "ivi-layout-export.h"
43 #include "ivi-layout-private.h"
45 /* Representation of ivi_surface protocol object. */
46 struct ivi_shell_surface
48 struct wl_resource* resource;
49 struct ivi_shell *shell;
50 struct ivi_layout_surface *layout_surface;
52 struct weston_surface *surface;
53 struct wl_listener surface_destroy_listener;
62 struct wl_listener configured_listener;
65 struct ivi_shell_setting
71 * Implementation of ivi_surface
75 surface_configure_notify(struct wl_listener *listener, void *data)
77 struct ivi_layout_surface *layout_surf =
78 (struct ivi_layout_surface *)data;
80 struct ivi_shell_surface *shell_surf =
81 container_of(listener,
82 struct ivi_shell_surface,
85 int32_t dest_width = 0;
86 int32_t dest_height = 0;
88 ivi_layout_surface_get_dimension(layout_surf,
89 &dest_width, &dest_height);
91 if (shell_surf->resource)
92 ivi_surface_send_configure(shell_surf->resource,
93 dest_width, dest_height);
97 ivi_shell_surface_configure(struct weston_surface *, int32_t, int32_t);
99 static struct ivi_shell_surface *
100 get_ivi_shell_surface(struct weston_surface *surface)
102 if (surface->configure == ivi_shell_surface_configure)
103 return surface->configure_private;
109 ivi_shell_surface_configure(struct weston_surface *surface,
110 int32_t sx, int32_t sy)
112 struct ivi_shell_surface *ivisurf = get_ivi_shell_surface(surface);
113 struct weston_view *view;
119 if (surface->width == 0 || surface->height == 0 || ivisurf == NULL)
122 view = ivi_layout_get_weston_view(ivisurf->layout_surface);
127 if (ivisurf->width != surface->width ||
128 ivisurf->height != surface->height) {
129 ivisurf->width = surface->width;
130 ivisurf->height = surface->height;
132 weston_view_to_global_float(view, 0, 0, &from_x, &from_y);
133 weston_view_to_global_float(view, sx, sy, &to_x, &to_y);
135 weston_view_set_position(view,
136 view->geometry.x + to_x - from_x,
137 view->geometry.y + to_y - from_y);
138 weston_view_update_transform(view);
140 ivi_layout_surface_configure(ivisurf->layout_surface,
141 surface->width, surface->height);
146 * The ivi_surface wl_resource destructor.
148 * Gets called via ivi_surface.destroy request or automatic wl_client clean-up.
151 shell_destroy_shell_surface(struct wl_resource *resource)
153 struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource);
154 if (ivisurf != NULL) {
155 ivisurf->resource = NULL;
159 /* Gets called through the weston_surface destroy signal. */
161 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
163 struct ivi_shell_surface *ivisurf =
164 container_of(listener, struct ivi_shell_surface,
165 surface_destroy_listener);
167 assert(ivisurf != NULL);
169 if (ivisurf->surface!=NULL) {
170 ivisurf->surface->configure = NULL;
171 ivisurf->surface->configure_private = NULL;
172 ivisurf->surface = NULL;
175 wl_list_remove(&ivisurf->surface_destroy_listener.link);
176 wl_list_remove(&ivisurf->link);
178 if (ivisurf->resource != NULL) {
179 wl_resource_set_user_data(ivisurf->resource, NULL);
180 ivisurf->resource = NULL;
186 /* Gets called, when a client sends ivi_surface.destroy request. */
188 surface_destroy(struct wl_client *client, struct wl_resource *resource)
191 * Fires the wl_resource destroy signal, and then calls
192 * ivi_surface wl_resource destructor: shell_destroy_shell_surface()
194 wl_resource_destroy(resource);
197 static const struct ivi_surface_interface surface_implementation = {
202 * Request handler for ivi_application.surface_create.
204 * Creates an ivi_surface protocol object associated with the given wl_surface.
205 * ivi_surface protocol object is represented by struct ivi_shell_surface.
207 * \param client The client.
208 * \param resource The ivi_application protocol object.
209 * \param id_surface The IVI surface ID.
210 * \param surface_resource The wl_surface protocol object.
211 * \param id The protocol object id for the new ivi_surface protocol object.
213 * The wl_surface is given the ivi_surface role and associated with a unique
214 * IVI ID which is used to identify the surface in a controller
218 application_surface_create(struct wl_client *client,
219 struct wl_resource *resource,
221 struct wl_resource *surface_resource,
224 struct ivi_shell *shell = wl_resource_get_user_data(resource);
225 struct ivi_shell_surface *ivisurf;
226 struct ivi_layout_surface *layout_surface;
227 struct weston_surface *weston_surface =
228 wl_resource_get_user_data(surface_resource);
229 struct wl_resource *res;
231 if (weston_surface_set_role(weston_surface, "ivi_surface",
232 resource, IVI_APPLICATION_ERROR_ROLE) < 0)
235 layout_surface = ivi_layout_surface_create(weston_surface, id_surface);
237 /* check if id_ivi is already used for wl_surface*/
238 if (layout_surface == NULL){
239 wl_resource_post_error(resource,
240 IVI_APPLICATION_ERROR_IVI_ID,
241 "surface_id is already assigned "
246 ivisurf = zalloc(sizeof *ivisurf);
247 if (ivisurf == NULL) {
248 wl_resource_post_no_memory(resource);
252 wl_list_init(&ivisurf->link);
253 wl_list_insert(&shell->ivi_surface_list, &ivisurf->link);
255 ivisurf->shell = shell;
256 ivisurf->id_surface = id_surface;
260 ivisurf->layout_surface = layout_surface;
261 ivisurf->configured_listener.notify = surface_configure_notify;
262 ivi_layout_surface_add_configured_listener(layout_surface,
263 &ivisurf->configured_listener);
265 * The following code relies on wl_surface destruction triggering
266 * immediateweston_surface destruction
268 ivisurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
269 wl_signal_add(&weston_surface->destroy_signal,
270 &ivisurf->surface_destroy_listener);
272 ivisurf->surface = weston_surface;
274 weston_surface->configure = ivi_shell_surface_configure;
275 weston_surface->configure_private = ivisurf;
277 res = wl_resource_create(client, &ivi_surface_interface, 1, id);
279 wl_client_post_no_memory(client);
283 ivisurf->resource = res;
285 wl_resource_set_implementation(res, &surface_implementation,
286 ivisurf, shell_destroy_shell_surface);
289 static const struct ivi_application_interface application_implementation = {
290 application_surface_create
294 * Handle wl_registry.bind of ivi_application global singleton.
297 bind_ivi_application(struct wl_client *client,
298 void *data, uint32_t version, uint32_t id)
300 struct ivi_shell *shell = data;
301 struct wl_resource *resource;
303 resource = wl_resource_create(client, &ivi_application_interface,
306 wl_resource_set_implementation(resource,
307 &application_implementation,
312 get_default_view(struct weston_surface *surface)
314 struct ivi_shell_surface *shsurf;
315 struct weston_view *view;
317 if (!surface || wl_list_empty(&surface->views))
320 shsurf = get_ivi_shell_surface(surface);
321 if (shsurf && shsurf->layout_surface) {
322 view = ivi_layout_get_weston_view(shsurf->layout_surface);
327 wl_list_for_each(view, &surface->views, surface_link) {
328 if (weston_view_is_mapped(view))
332 return container_of(surface->views.next,
333 struct weston_view, surface_link);
337 * Called through the compositor's destroy signal.
340 shell_destroy(struct wl_listener *listener, void *data)
342 struct ivi_shell *shell =
343 container_of(listener, struct ivi_shell, destroy_listener);
344 struct ivi_shell_surface *ivisurf, *next;
346 input_panel_destroy(shell);
348 wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) {
349 wl_list_remove(&ivisurf->link);
357 init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell)
359 shell->compositor = compositor;
361 wl_list_init(&shell->ivi_surface_list);
363 weston_layer_init(&shell->input_panel_layer, NULL);
367 ivi_shell_setting_create(struct ivi_shell_setting *dest,
368 struct weston_compositor *compositor)
371 struct weston_config *config = compositor->config;
372 struct weston_config_section *section;
377 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
379 if (weston_config_section_get_string(section, "ivi-module",
380 &dest->ivi_module, NULL) != 0) {
381 weston_log("ivi-shell: No ivi-module set in config\n");
389 * Initialization of ivi-shell.
392 module_init(struct weston_compositor *compositor,
393 int *argc, char *argv[])
395 struct ivi_shell *shell;
396 struct ivi_shell_setting setting = { };
398 shell = zalloc(sizeof *shell);
402 init_ivi_shell(compositor, shell);
404 shell->destroy_listener.notify = shell_destroy;
405 wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
407 if (input_panel_setup(shell) < 0)
410 if (wl_global_create(compositor->wl_display,
411 &ivi_application_interface, 1,
412 shell, bind_ivi_application) == NULL)
415 if (ivi_shell_setting_create(&setting, compositor) != 0)
418 ivi_layout_init_with_compositor(compositor);
421 /* Call module_init of ivi-modules which are defined in weston.ini */
422 if (load_controller_modules(compositor, setting.ivi_module, argc, argv) < 0) {
423 free(setting.ivi_module);
427 free(setting.ivi_module);