Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 DENSO CORPORATION |
| 3 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 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: |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 11 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 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. |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * ivi-shell supports a type of shell for In-Vehicle Infotainment system. |
| 28 | * In-Vehicle Infotainment system traditionally manages surfaces with global |
| 29 | * identification. A protocol, ivi_application, supports such a feature |
| 30 | * by implementing a request, ivi_application::surface_creation defined in |
| 31 | * ivi_application.xml. |
| 32 | * |
| 33 | * The ivi-shell explicitly loads a module to add business logic like how to |
| 34 | * layout surfaces by using internal ivi-layout APIs. |
| 35 | */ |
| 36 | #include "config.h" |
| 37 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 38 | #include <string.h> |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 39 | #include <dlfcn.h> |
| 40 | #include <limits.h> |
| 41 | #include <assert.h> |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 42 | #include <linux/input.h> |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 43 | |
| 44 | #include "ivi-shell.h" |
| 45 | #include "ivi-application-server-protocol.h" |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 46 | #include "ivi-layout-export.h" |
Pekka Paalanen | 32ca791 | 2016-03-15 17:21:00 +0200 | [diff] [blame] | 47 | #include "ivi-layout-shell.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 48 | #include "shared/helpers.h" |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 49 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 50 | /* Representation of ivi_surface protocol object. */ |
| 51 | struct ivi_shell_surface |
| 52 | { |
| 53 | struct wl_resource* resource; |
| 54 | struct ivi_shell *shell; |
| 55 | struct ivi_layout_surface *layout_surface; |
| 56 | |
| 57 | struct weston_surface *surface; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | |
| 60 | uint32_t id_surface; |
| 61 | |
| 62 | int32_t width; |
| 63 | int32_t height; |
| 64 | |
| 65 | struct wl_list link; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct ivi_shell_setting |
| 69 | { |
| 70 | char *ivi_module; |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 71 | int developermode; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * Implementation of ivi_surface |
| 76 | */ |
| 77 | |
| 78 | static void |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 79 | ivi_shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 80 | |
| 81 | static struct ivi_shell_surface * |
| 82 | get_ivi_shell_surface(struct weston_surface *surface) |
| 83 | { |
Pekka Paalanen | 94cb06a | 2016-03-16 14:54:12 +0200 | [diff] [blame^] | 84 | struct ivi_shell_surface *shsurf; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 85 | |
Pekka Paalanen | 94cb06a | 2016-03-16 14:54:12 +0200 | [diff] [blame^] | 86 | if (surface->configure != ivi_shell_surface_configure) |
| 87 | return NULL; |
| 88 | |
| 89 | shsurf = surface->configure_private; |
| 90 | assert(shsurf); |
| 91 | assert(shsurf->surface == surface); |
| 92 | |
| 93 | return shsurf; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 94 | } |
| 95 | |
Pekka Paalanen | 1f82193 | 2016-03-15 16:57:51 +0200 | [diff] [blame] | 96 | void |
| 97 | shell_surface_send_configure(struct weston_surface *surface, |
| 98 | int32_t width, int32_t height) |
| 99 | { |
| 100 | struct ivi_shell_surface *shsurf; |
| 101 | |
| 102 | shsurf = get_ivi_shell_surface(surface); |
| 103 | assert(shsurf); |
| 104 | if (!shsurf) |
| 105 | return; |
| 106 | |
| 107 | if (shsurf->resource) |
| 108 | ivi_surface_send_configure(shsurf->resource, width, height); |
| 109 | } |
| 110 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 111 | static void |
| 112 | ivi_shell_surface_configure(struct weston_surface *surface, |
| 113 | int32_t sx, int32_t sy) |
| 114 | { |
| 115 | struct ivi_shell_surface *ivisurf = get_ivi_shell_surface(surface); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 116 | |
Pekka Paalanen | fd45f60 | 2016-03-16 15:05:03 +0200 | [diff] [blame] | 117 | assert(ivisurf); |
| 118 | if (!ivisurf) |
| 119 | return; |
| 120 | |
| 121 | if (surface->width == 0 || surface->height == 0) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 122 | return; |
| 123 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 124 | if (ivisurf->width != surface->width || |
| 125 | ivisurf->height != surface->height) { |
| 126 | ivisurf->width = surface->width; |
| 127 | ivisurf->height = surface->height; |
| 128 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 129 | ivi_layout_surface_configure(ivisurf->layout_surface, |
| 130 | surface->width, surface->height); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 134 | static int |
| 135 | ivi_shell_surface_get_label(struct weston_surface *surface, |
| 136 | char *buf, |
| 137 | size_t len) |
| 138 | { |
| 139 | struct ivi_shell_surface *shell_surf = get_ivi_shell_surface(surface); |
| 140 | |
| 141 | if (!shell_surf) |
| 142 | return snprintf(buf, len, "unidentified window in ivi-shell"); |
| 143 | |
| 144 | return snprintf(buf, len, "ivi-surface %#x", shell_surf->id_surface); |
| 145 | } |
| 146 | |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 147 | static void |
| 148 | layout_surface_cleanup(struct ivi_shell_surface *ivisurf) |
| 149 | { |
| 150 | assert(ivisurf->layout_surface != NULL); |
| 151 | |
| 152 | ivi_layout_surface_destroy(ivisurf->layout_surface); |
| 153 | ivisurf->layout_surface = NULL; |
| 154 | |
| 155 | ivisurf->surface->configure = NULL; |
| 156 | ivisurf->surface->configure_private = NULL; |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 157 | weston_surface_set_label_func(ivisurf->surface, NULL); |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 158 | ivisurf->surface = NULL; |
| 159 | |
| 160 | // destroy weston_surface destroy signal. |
| 161 | wl_list_remove(&ivisurf->surface_destroy_listener.link); |
| 162 | } |
| 163 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 164 | /* |
| 165 | * The ivi_surface wl_resource destructor. |
| 166 | * |
| 167 | * Gets called via ivi_surface.destroy request or automatic wl_client clean-up. |
| 168 | */ |
| 169 | static void |
| 170 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 171 | { |
| 172 | struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource); |
Nobuhiko Tanibata | 6809842 | 2015-06-22 15:31:08 +0900 | [diff] [blame] | 173 | |
| 174 | if (ivisurf == NULL) |
| 175 | return; |
| 176 | |
| 177 | assert(ivisurf->resource == resource); |
| 178 | |
| 179 | if (ivisurf->layout_surface != NULL) |
| 180 | layout_surface_cleanup(ivisurf); |
| 181 | |
| 182 | wl_list_remove(&ivisurf->link); |
| 183 | |
| 184 | free(ivisurf); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* Gets called through the weston_surface destroy signal. */ |
| 188 | static void |
| 189 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 190 | { |
| 191 | struct ivi_shell_surface *ivisurf = |
| 192 | container_of(listener, struct ivi_shell_surface, |
| 193 | surface_destroy_listener); |
| 194 | |
| 195 | assert(ivisurf != NULL); |
| 196 | |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 197 | if (ivisurf->layout_surface != NULL) |
| 198 | layout_surface_cleanup(ivisurf); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* Gets called, when a client sends ivi_surface.destroy request. */ |
| 202 | static void |
| 203 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 204 | { |
| 205 | /* |
| 206 | * Fires the wl_resource destroy signal, and then calls |
| 207 | * ivi_surface wl_resource destructor: shell_destroy_shell_surface() |
| 208 | */ |
| 209 | wl_resource_destroy(resource); |
| 210 | } |
| 211 | |
| 212 | static const struct ivi_surface_interface surface_implementation = { |
| 213 | surface_destroy, |
| 214 | }; |
| 215 | |
| 216 | /** |
| 217 | * Request handler for ivi_application.surface_create. |
| 218 | * |
| 219 | * Creates an ivi_surface protocol object associated with the given wl_surface. |
| 220 | * ivi_surface protocol object is represented by struct ivi_shell_surface. |
| 221 | * |
| 222 | * \param client The client. |
| 223 | * \param resource The ivi_application protocol object. |
| 224 | * \param id_surface The IVI surface ID. |
| 225 | * \param surface_resource The wl_surface protocol object. |
| 226 | * \param id The protocol object id for the new ivi_surface protocol object. |
| 227 | * |
| 228 | * The wl_surface is given the ivi_surface role and associated with a unique |
| 229 | * IVI ID which is used to identify the surface in a controller |
| 230 | * (window manager). |
| 231 | */ |
| 232 | static void |
| 233 | application_surface_create(struct wl_client *client, |
| 234 | struct wl_resource *resource, |
| 235 | uint32_t id_surface, |
| 236 | struct wl_resource *surface_resource, |
| 237 | uint32_t id) |
| 238 | { |
| 239 | struct ivi_shell *shell = wl_resource_get_user_data(resource); |
| 240 | struct ivi_shell_surface *ivisurf; |
| 241 | struct ivi_layout_surface *layout_surface; |
| 242 | struct weston_surface *weston_surface = |
| 243 | wl_resource_get_user_data(surface_resource); |
| 244 | struct wl_resource *res; |
| 245 | |
| 246 | if (weston_surface_set_role(weston_surface, "ivi_surface", |
| 247 | resource, IVI_APPLICATION_ERROR_ROLE) < 0) |
| 248 | return; |
| 249 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 250 | layout_surface = ivi_layout_surface_create(weston_surface, id_surface); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 251 | |
| 252 | /* check if id_ivi is already used for wl_surface*/ |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 253 | if (layout_surface == NULL) { |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 254 | wl_resource_post_error(resource, |
| 255 | IVI_APPLICATION_ERROR_IVI_ID, |
| 256 | "surface_id is already assigned " |
| 257 | "by another app"); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | ivisurf = zalloc(sizeof *ivisurf); |
| 262 | if (ivisurf == NULL) { |
| 263 | wl_resource_post_no_memory(resource); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | wl_list_init(&ivisurf->link); |
| 268 | wl_list_insert(&shell->ivi_surface_list, &ivisurf->link); |
| 269 | |
| 270 | ivisurf->shell = shell; |
| 271 | ivisurf->id_surface = id_surface; |
| 272 | |
| 273 | ivisurf->width = 0; |
| 274 | ivisurf->height = 0; |
| 275 | ivisurf->layout_surface = layout_surface; |
Pekka Paalanen | 1f82193 | 2016-03-15 16:57:51 +0200 | [diff] [blame] | 276 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 277 | /* |
| 278 | * The following code relies on wl_surface destruction triggering |
| 279 | * immediateweston_surface destruction |
| 280 | */ |
| 281 | ivisurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 282 | wl_signal_add(&weston_surface->destroy_signal, |
| 283 | &ivisurf->surface_destroy_listener); |
| 284 | |
| 285 | ivisurf->surface = weston_surface; |
| 286 | |
| 287 | weston_surface->configure = ivi_shell_surface_configure; |
| 288 | weston_surface->configure_private = ivisurf; |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 289 | weston_surface_set_label_func(weston_surface, |
| 290 | ivi_shell_surface_get_label); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 291 | |
| 292 | res = wl_resource_create(client, &ivi_surface_interface, 1, id); |
| 293 | if (res == NULL) { |
| 294 | wl_client_post_no_memory(client); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | ivisurf->resource = res; |
| 299 | |
| 300 | wl_resource_set_implementation(res, &surface_implementation, |
| 301 | ivisurf, shell_destroy_shell_surface); |
| 302 | } |
| 303 | |
| 304 | static const struct ivi_application_interface application_implementation = { |
| 305 | application_surface_create |
| 306 | }; |
| 307 | |
| 308 | /* |
| 309 | * Handle wl_registry.bind of ivi_application global singleton. |
| 310 | */ |
| 311 | static void |
| 312 | bind_ivi_application(struct wl_client *client, |
| 313 | void *data, uint32_t version, uint32_t id) |
| 314 | { |
| 315 | struct ivi_shell *shell = data; |
| 316 | struct wl_resource *resource; |
| 317 | |
| 318 | resource = wl_resource_create(client, &ivi_application_interface, |
| 319 | 1, id); |
| 320 | |
| 321 | wl_resource_set_implementation(resource, |
| 322 | &application_implementation, |
| 323 | shell, NULL); |
| 324 | } |
| 325 | |
Nobuhiko Tanibata | 0038b73 | 2014-11-27 13:25:34 +0900 | [diff] [blame] | 326 | struct weston_view * |
| 327 | get_default_view(struct weston_surface *surface) |
| 328 | { |
| 329 | struct ivi_shell_surface *shsurf; |
| 330 | struct weston_view *view; |
| 331 | |
| 332 | if (!surface || wl_list_empty(&surface->views)) |
| 333 | return NULL; |
| 334 | |
| 335 | shsurf = get_ivi_shell_surface(surface); |
| 336 | if (shsurf && shsurf->layout_surface) { |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 337 | view = ivi_layout_get_weston_view(shsurf->layout_surface); |
Nobuhiko Tanibata | 0038b73 | 2014-11-27 13:25:34 +0900 | [diff] [blame] | 338 | if (view) |
| 339 | return view; |
| 340 | } |
| 341 | |
| 342 | wl_list_for_each(view, &surface->views, surface_link) { |
| 343 | if (weston_view_is_mapped(view)) |
| 344 | return view; |
| 345 | } |
| 346 | |
| 347 | return container_of(surface->views.next, |
| 348 | struct weston_view, surface_link); |
| 349 | } |
| 350 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 351 | /* |
| 352 | * Called through the compositor's destroy signal. |
| 353 | */ |
| 354 | static void |
| 355 | shell_destroy(struct wl_listener *listener, void *data) |
| 356 | { |
| 357 | struct ivi_shell *shell = |
| 358 | container_of(listener, struct ivi_shell, destroy_listener); |
| 359 | struct ivi_shell_surface *ivisurf, *next; |
| 360 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 361 | text_backend_destroy(shell->text_backend); |
Nobuhiko Tanibata | 0038b73 | 2014-11-27 13:25:34 +0900 | [diff] [blame] | 362 | input_panel_destroy(shell); |
| 363 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 364 | wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) { |
| 365 | wl_list_remove(&ivisurf->link); |
| 366 | free(ivisurf); |
| 367 | } |
| 368 | |
| 369 | free(shell); |
| 370 | } |
| 371 | |
| 372 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 373 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 374 | uint32_t key, void *data) |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 375 | { |
| 376 | struct weston_compositor *compositor = data; |
| 377 | |
| 378 | wl_display_terminate(compositor->wl_display); |
| 379 | } |
| 380 | |
| 381 | static void |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 382 | init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell, |
| 383 | const struct ivi_shell_setting *setting) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 384 | { |
| 385 | shell->compositor = compositor; |
| 386 | |
| 387 | wl_list_init(&shell->ivi_surface_list); |
| 388 | |
Nobuhiko Tanibata | 0038b73 | 2014-11-27 13:25:34 +0900 | [diff] [blame] | 389 | weston_layer_init(&shell->input_panel_layer, NULL); |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 390 | |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 391 | if (setting->developermode) { |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 392 | weston_install_debug_key_binding(compositor, MODIFIER_SUPER); |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 393 | |
| 394 | weston_compositor_add_key_binding(compositor, KEY_BACKSPACE, |
| 395 | MODIFIER_CTRL | MODIFIER_ALT, |
| 396 | terminate_binding, |
| 397 | compositor); |
| 398 | } |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static int |
| 402 | ivi_shell_setting_create(struct ivi_shell_setting *dest, |
Pekka Paalanen | 8a00525 | 2015-03-20 15:53:53 +0200 | [diff] [blame] | 403 | struct weston_compositor *compositor, |
| 404 | int *argc, char *argv[]) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 405 | { |
| 406 | int result = 0; |
| 407 | struct weston_config *config = compositor->config; |
| 408 | struct weston_config_section *section; |
| 409 | |
Pekka Paalanen | 8a00525 | 2015-03-20 15:53:53 +0200 | [diff] [blame] | 410 | const struct weston_option ivi_shell_options[] = { |
| 411 | { WESTON_OPTION_STRING, "ivi-module", 0, &dest->ivi_module }, |
| 412 | }; |
| 413 | |
| 414 | parse_options(ivi_shell_options, ARRAY_LENGTH(ivi_shell_options), |
| 415 | argc, argv); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 416 | |
| 417 | section = weston_config_get_section(config, "ivi-shell", NULL, NULL); |
| 418 | |
Pekka Paalanen | 8a00525 | 2015-03-20 15:53:53 +0200 | [diff] [blame] | 419 | if (!dest->ivi_module && |
| 420 | weston_config_section_get_string(section, "ivi-module", |
| 421 | &dest->ivi_module, NULL) < 0) { |
| 422 | weston_log("Error: ivi-shell: No ivi-module set\n"); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 423 | result = -1; |
| 424 | } |
| 425 | |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 426 | weston_config_section_get_bool(section, "developermode", |
| 427 | &dest->developermode, 0); |
| 428 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 429 | return result; |
| 430 | } |
| 431 | |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 432 | static void |
| 433 | activate_binding(struct weston_seat *seat, |
| 434 | struct weston_view *focus_view) |
| 435 | { |
| 436 | struct weston_surface *focus = focus_view->surface; |
| 437 | struct weston_surface *main_surface = |
| 438 | weston_surface_get_main_surface(focus); |
| 439 | |
| 440 | if (get_ivi_shell_surface(main_surface) == NULL) |
| 441 | return; |
| 442 | |
| 443 | weston_surface_activate(focus, seat); |
| 444 | } |
| 445 | |
| 446 | static void |
| 447 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 448 | uint32_t button, void *data) |
| 449 | { |
| 450 | if (pointer->grab != &pointer->default_grab) |
| 451 | return; |
| 452 | if (pointer->focus == NULL) |
| 453 | return; |
| 454 | |
| 455 | activate_binding(pointer->seat, pointer->focus); |
| 456 | } |
| 457 | |
| 458 | static void |
| 459 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 460 | void *data) |
| 461 | { |
| 462 | if (touch->grab != &touch->default_grab) |
| 463 | return; |
| 464 | if (touch->focus == NULL) |
| 465 | return; |
| 466 | |
| 467 | activate_binding(touch->seat, touch->focus); |
| 468 | } |
| 469 | |
| 470 | static void |
| 471 | shell_add_bindings(struct weston_compositor *compositor, |
| 472 | struct ivi_shell *shell) |
| 473 | { |
| 474 | weston_compositor_add_button_binding(compositor, BTN_LEFT, 0, |
| 475 | click_to_activate_binding, |
| 476 | shell); |
| 477 | weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0, |
| 478 | click_to_activate_binding, |
| 479 | shell); |
| 480 | weston_compositor_add_touch_binding(compositor, 0, |
| 481 | touch_to_activate_binding, |
| 482 | shell); |
| 483 | } |
| 484 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 485 | /* |
| 486 | * Initialization of ivi-shell. |
| 487 | */ |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 488 | WL_EXPORT int |
| 489 | module_init(struct weston_compositor *compositor, |
| 490 | int *argc, char *argv[]) |
| 491 | { |
| 492 | struct ivi_shell *shell; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 493 | struct ivi_shell_setting setting = { }; |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 494 | int retval = -1; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 495 | |
| 496 | shell = zalloc(sizeof *shell); |
| 497 | if (shell == NULL) |
| 498 | return -1; |
| 499 | |
Pekka Paalanen | 8a00525 | 2015-03-20 15:53:53 +0200 | [diff] [blame] | 500 | if (ivi_shell_setting_create(&setting, compositor, argc, argv) != 0) |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 501 | return -1; |
| 502 | |
| 503 | init_ivi_shell(compositor, shell, &setting); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 504 | |
| 505 | shell->destroy_listener.notify = shell_destroy; |
| 506 | wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener); |
| 507 | |
Nobuhiko Tanibata | 0038b73 | 2014-11-27 13:25:34 +0900 | [diff] [blame] | 508 | if (input_panel_setup(shell) < 0) |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 509 | goto out_settings; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 510 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 511 | shell->text_backend = text_backend_init(compositor); |
| 512 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 513 | goto out_settings; |
| 514 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 515 | if (wl_global_create(compositor->wl_display, |
| 516 | &ivi_application_interface, 1, |
| 517 | shell, bind_ivi_application) == NULL) |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 518 | goto out_settings; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 519 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 520 | ivi_layout_init_with_compositor(compositor); |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 521 | shell_add_bindings(compositor, shell); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 522 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 523 | /* Call module_init of ivi-modules which are defined in weston.ini */ |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 524 | if (load_controller_modules(compositor, setting.ivi_module, |
| 525 | argc, argv) < 0) |
| 526 | goto out_settings; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 527 | |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 528 | retval = 0; |
| 529 | |
| 530 | out_settings: |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 531 | free(setting.ivi_module); |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 532 | |
| 533 | return retval; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 534 | } |