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