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