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