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" |
Michael Teyfel | 8f9e92e | 2019-02-01 15:17:35 +0100 | [diff] [blame] | 47 | #include "ivi-layout-private.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 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 70 | /* |
| 71 | * Implementation of ivi_surface |
| 72 | */ |
| 73 | |
| 74 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 75 | ivi_shell_surface_committed(struct weston_surface *, int32_t, int32_t); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 76 | |
| 77 | static struct ivi_shell_surface * |
| 78 | get_ivi_shell_surface(struct weston_surface *surface) |
| 79 | { |
Pekka Paalanen | 94cb06a | 2016-03-16 14:54:12 +0200 | [diff] [blame] | 80 | struct ivi_shell_surface *shsurf; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 81 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 82 | if (surface->committed != ivi_shell_surface_committed) |
Pekka Paalanen | 94cb06a | 2016-03-16 14:54:12 +0200 | [diff] [blame] | 83 | return NULL; |
| 84 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 85 | shsurf = surface->committed_private; |
Pekka Paalanen | 94cb06a | 2016-03-16 14:54:12 +0200 | [diff] [blame] | 86 | assert(shsurf); |
| 87 | assert(shsurf->surface == surface); |
| 88 | |
| 89 | return shsurf; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 90 | } |
| 91 | |
Pekka Paalanen | eaa43fc | 2016-04-12 16:06:58 +0300 | [diff] [blame] | 92 | struct ivi_layout_surface * |
| 93 | shell_get_ivi_layout_surface(struct weston_surface *surface) |
| 94 | { |
| 95 | struct ivi_shell_surface *shsurf; |
| 96 | |
| 97 | shsurf = get_ivi_shell_surface(surface); |
| 98 | if (!shsurf) |
| 99 | return NULL; |
| 100 | |
| 101 | return shsurf->layout_surface; |
| 102 | } |
| 103 | |
Pekka Paalanen | 1f82193 | 2016-03-15 16:57:51 +0200 | [diff] [blame] | 104 | void |
| 105 | shell_surface_send_configure(struct weston_surface *surface, |
| 106 | int32_t width, int32_t height) |
| 107 | { |
| 108 | struct ivi_shell_surface *shsurf; |
| 109 | |
| 110 | shsurf = get_ivi_shell_surface(surface); |
Pekka Paalanen | 1f82193 | 2016-03-15 16:57:51 +0200 | [diff] [blame] | 111 | if (!shsurf) |
| 112 | return; |
| 113 | |
| 114 | if (shsurf->resource) |
| 115 | ivi_surface_send_configure(shsurf->resource, width, height); |
| 116 | } |
| 117 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 118 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 119 | ivi_shell_surface_committed(struct weston_surface *surface, |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 120 | int32_t sx, int32_t sy) |
| 121 | { |
| 122 | struct ivi_shell_surface *ivisurf = get_ivi_shell_surface(surface); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 123 | |
Pekka Paalanen | fd45f60 | 2016-03-16 15:05:03 +0200 | [diff] [blame] | 124 | assert(ivisurf); |
| 125 | if (!ivisurf) |
| 126 | return; |
| 127 | |
| 128 | if (surface->width == 0 || surface->height == 0) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 129 | return; |
| 130 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 131 | if (ivisurf->width != surface->width || |
| 132 | ivisurf->height != surface->height) { |
| 133 | ivisurf->width = surface->width; |
| 134 | ivisurf->height = surface->height; |
| 135 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 136 | ivi_layout_surface_configure(ivisurf->layout_surface, |
| 137 | surface->width, surface->height); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 141 | static int |
| 142 | ivi_shell_surface_get_label(struct weston_surface *surface, |
| 143 | char *buf, |
| 144 | size_t len) |
| 145 | { |
| 146 | struct ivi_shell_surface *shell_surf = get_ivi_shell_surface(surface); |
| 147 | |
| 148 | if (!shell_surf) |
| 149 | return snprintf(buf, len, "unidentified window in ivi-shell"); |
| 150 | |
| 151 | return snprintf(buf, len, "ivi-surface %#x", shell_surf->id_surface); |
| 152 | } |
| 153 | |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 154 | static void |
| 155 | layout_surface_cleanup(struct ivi_shell_surface *ivisurf) |
| 156 | { |
| 157 | assert(ivisurf->layout_surface != NULL); |
| 158 | |
Michael Teyfel | ed28f02 | 2017-10-17 11:10:18 +0200 | [diff] [blame] | 159 | /* destroy weston_surface destroy signal. */ |
| 160 | if (!ivisurf->layout_surface->weston_desktop_surface) |
| 161 | wl_list_remove(&ivisurf->surface_destroy_listener.link); |
| 162 | |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 163 | ivi_layout_surface_destroy(ivisurf->layout_surface); |
| 164 | ivisurf->layout_surface = NULL; |
| 165 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 166 | ivisurf->surface->committed = NULL; |
| 167 | ivisurf->surface->committed_private = NULL; |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 168 | weston_surface_set_label_func(ivisurf->surface, NULL); |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 169 | ivisurf->surface = NULL; |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 170 | } |
| 171 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 172 | /* |
| 173 | * The ivi_surface wl_resource destructor. |
| 174 | * |
| 175 | * Gets called via ivi_surface.destroy request or automatic wl_client clean-up. |
| 176 | */ |
| 177 | static void |
| 178 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 179 | { |
| 180 | struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource); |
Nobuhiko Tanibata | 6809842 | 2015-06-22 15:31:08 +0900 | [diff] [blame] | 181 | |
| 182 | if (ivisurf == NULL) |
| 183 | return; |
| 184 | |
| 185 | assert(ivisurf->resource == resource); |
| 186 | |
| 187 | if (ivisurf->layout_surface != NULL) |
| 188 | layout_surface_cleanup(ivisurf); |
| 189 | |
| 190 | wl_list_remove(&ivisurf->link); |
| 191 | |
| 192 | free(ivisurf); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* Gets called through the weston_surface destroy signal. */ |
| 196 | static void |
| 197 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 198 | { |
| 199 | struct ivi_shell_surface *ivisurf = |
| 200 | container_of(listener, struct ivi_shell_surface, |
| 201 | surface_destroy_listener); |
| 202 | |
| 203 | assert(ivisurf != NULL); |
| 204 | |
Nobuhiko Tanibata | 6f6c938 | 2015-06-22 15:30:53 +0900 | [diff] [blame] | 205 | if (ivisurf->layout_surface != NULL) |
| 206 | layout_surface_cleanup(ivisurf); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* Gets called, when a client sends ivi_surface.destroy request. */ |
| 210 | static void |
| 211 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 212 | { |
| 213 | /* |
| 214 | * Fires the wl_resource destroy signal, and then calls |
| 215 | * ivi_surface wl_resource destructor: shell_destroy_shell_surface() |
| 216 | */ |
| 217 | wl_resource_destroy(resource); |
| 218 | } |
| 219 | |
| 220 | static const struct ivi_surface_interface surface_implementation = { |
| 221 | surface_destroy, |
| 222 | }; |
| 223 | |
| 224 | /** |
| 225 | * Request handler for ivi_application.surface_create. |
| 226 | * |
| 227 | * Creates an ivi_surface protocol object associated with the given wl_surface. |
| 228 | * ivi_surface protocol object is represented by struct ivi_shell_surface. |
| 229 | * |
| 230 | * \param client The client. |
| 231 | * \param resource The ivi_application protocol object. |
| 232 | * \param id_surface The IVI surface ID. |
| 233 | * \param surface_resource The wl_surface protocol object. |
| 234 | * \param id The protocol object id for the new ivi_surface protocol object. |
| 235 | * |
| 236 | * The wl_surface is given the ivi_surface role and associated with a unique |
| 237 | * IVI ID which is used to identify the surface in a controller |
| 238 | * (window manager). |
| 239 | */ |
| 240 | static void |
| 241 | application_surface_create(struct wl_client *client, |
| 242 | struct wl_resource *resource, |
| 243 | uint32_t id_surface, |
| 244 | struct wl_resource *surface_resource, |
| 245 | uint32_t id) |
| 246 | { |
| 247 | struct ivi_shell *shell = wl_resource_get_user_data(resource); |
| 248 | struct ivi_shell_surface *ivisurf; |
| 249 | struct ivi_layout_surface *layout_surface; |
| 250 | struct weston_surface *weston_surface = |
| 251 | wl_resource_get_user_data(surface_resource); |
| 252 | struct wl_resource *res; |
| 253 | |
| 254 | if (weston_surface_set_role(weston_surface, "ivi_surface", |
| 255 | resource, IVI_APPLICATION_ERROR_ROLE) < 0) |
| 256 | return; |
| 257 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 258 | layout_surface = ivi_layout_surface_create(weston_surface, id_surface); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 259 | |
| 260 | /* check if id_ivi is already used for wl_surface*/ |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 261 | if (layout_surface == NULL) { |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 262 | wl_resource_post_error(resource, |
| 263 | IVI_APPLICATION_ERROR_IVI_ID, |
| 264 | "surface_id is already assigned " |
| 265 | "by another app"); |
| 266 | return; |
| 267 | } |
| 268 | |
Michael Teyfel | 8f9e92e | 2019-02-01 15:17:35 +0100 | [diff] [blame] | 269 | layout_surface->weston_desktop_surface = NULL; |
| 270 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 271 | ivisurf = zalloc(sizeof *ivisurf); |
| 272 | if (ivisurf == NULL) { |
| 273 | wl_resource_post_no_memory(resource); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | wl_list_init(&ivisurf->link); |
| 278 | wl_list_insert(&shell->ivi_surface_list, &ivisurf->link); |
| 279 | |
| 280 | ivisurf->shell = shell; |
| 281 | ivisurf->id_surface = id_surface; |
| 282 | |
| 283 | ivisurf->width = 0; |
| 284 | ivisurf->height = 0; |
| 285 | ivisurf->layout_surface = layout_surface; |
Pekka Paalanen | 1f82193 | 2016-03-15 16:57:51 +0200 | [diff] [blame] | 286 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 287 | /* |
| 288 | * The following code relies on wl_surface destruction triggering |
| 289 | * immediateweston_surface destruction |
| 290 | */ |
| 291 | ivisurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 292 | wl_signal_add(&weston_surface->destroy_signal, |
| 293 | &ivisurf->surface_destroy_listener); |
| 294 | |
| 295 | ivisurf->surface = weston_surface; |
| 296 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 297 | weston_surface->committed = ivi_shell_surface_committed; |
| 298 | weston_surface->committed_private = ivisurf; |
Pekka Paalanen | 13281f6 | 2016-03-07 16:19:37 +0200 | [diff] [blame] | 299 | weston_surface_set_label_func(weston_surface, |
| 300 | ivi_shell_surface_get_label); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 301 | |
| 302 | res = wl_resource_create(client, &ivi_surface_interface, 1, id); |
| 303 | if (res == NULL) { |
| 304 | wl_client_post_no_memory(client); |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | ivisurf->resource = res; |
| 309 | |
| 310 | wl_resource_set_implementation(res, &surface_implementation, |
| 311 | ivisurf, shell_destroy_shell_surface); |
| 312 | } |
| 313 | |
| 314 | static const struct ivi_application_interface application_implementation = { |
| 315 | application_surface_create |
| 316 | }; |
| 317 | |
| 318 | /* |
| 319 | * Handle wl_registry.bind of ivi_application global singleton. |
| 320 | */ |
| 321 | static void |
| 322 | bind_ivi_application(struct wl_client *client, |
| 323 | void *data, uint32_t version, uint32_t id) |
| 324 | { |
| 325 | struct ivi_shell *shell = data; |
| 326 | struct wl_resource *resource; |
| 327 | |
| 328 | resource = wl_resource_create(client, &ivi_application_interface, |
| 329 | 1, id); |
| 330 | |
| 331 | wl_resource_set_implementation(resource, |
| 332 | &application_implementation, |
| 333 | shell, NULL); |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * Called through the compositor's destroy signal. |
| 338 | */ |
| 339 | static void |
| 340 | shell_destroy(struct wl_listener *listener, void *data) |
| 341 | { |
| 342 | struct ivi_shell *shell = |
| 343 | container_of(listener, struct ivi_shell, destroy_listener); |
| 344 | struct ivi_shell_surface *ivisurf, *next; |
| 345 | |
Harsha M M | 46cbd0a | 2018-08-07 19:05:03 +0530 | [diff] [blame] | 346 | wl_list_remove(&shell->destroy_listener.link); |
Emre Ucan | cf4113c | 2018-06-05 10:23:00 +0200 | [diff] [blame] | 347 | wl_list_remove(&shell->wake_listener.link); |
| 348 | |
Pekka Paalanen | 32aedb9 | 2021-06-15 16:17:29 +0300 | [diff] [blame] | 349 | weston_desktop_destroy(shell->desktop); |
| 350 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 351 | wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) { |
Harsha M M | 1b470f9 | 2018-08-03 19:22:16 +0530 | [diff] [blame] | 352 | if (ivisurf->layout_surface != NULL) |
| 353 | layout_surface_cleanup(ivisurf); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 354 | wl_list_remove(&ivisurf->link); |
| 355 | free(ivisurf); |
| 356 | } |
| 357 | |
Pekka Paalanen | 9706a80 | 2021-05-14 14:55:26 +0300 | [diff] [blame] | 358 | ivi_layout_fini(); |
| 359 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 360 | free(shell); |
| 361 | } |
| 362 | |
Emre Ucan | cf4113c | 2018-06-05 10:23:00 +0200 | [diff] [blame] | 363 | /* |
| 364 | * Called through the compositor's wake signal. |
| 365 | */ |
| 366 | static void |
| 367 | wake_handler(struct wl_listener *listener, void *data) |
| 368 | { |
| 369 | struct weston_compositor *compositor = data; |
| 370 | |
| 371 | weston_compositor_damage_all(compositor); |
| 372 | } |
| 373 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 374 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 375 | terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 376 | uint32_t key, void *data) |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 377 | { |
| 378 | struct weston_compositor *compositor = data; |
| 379 | |
Pekka Paalanen | 818c20e | 2019-02-06 10:48:51 +0200 | [diff] [blame] | 380 | weston_compositor_exit(compositor); |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void |
Emre Ucan | f85bf15 | 2018-01-25 14:37:38 +0100 | [diff] [blame] | 384 | init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 385 | { |
Emre Ucan | f85bf15 | 2018-01-25 14:37:38 +0100 | [diff] [blame] | 386 | struct weston_config *config = wet_get_config(compositor); |
| 387 | struct weston_config_section *section; |
Daniel Stone | 51d995a | 2019-11-26 00:14:24 +0000 | [diff] [blame] | 388 | bool developermode; |
Emre Ucan | f85bf15 | 2018-01-25 14:37:38 +0100 | [diff] [blame] | 389 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 390 | shell->compositor = compositor; |
| 391 | |
| 392 | wl_list_init(&shell->ivi_surface_list); |
| 393 | |
Emre Ucan | f85bf15 | 2018-01-25 14:37:38 +0100 | [diff] [blame] | 394 | section = weston_config_get_section(config, "ivi-shell", NULL, NULL); |
| 395 | |
| 396 | weston_config_section_get_bool(section, "developermode", |
| 397 | &developermode, 0); |
| 398 | |
| 399 | if (developermode) { |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 400 | weston_install_debug_key_binding(compositor, MODIFIER_SUPER); |
Pekka Paalanen | 6c7a1c7 | 2015-02-19 17:12:19 +0200 | [diff] [blame] | 401 | |
| 402 | weston_compositor_add_key_binding(compositor, KEY_BACKSPACE, |
| 403 | MODIFIER_CTRL | MODIFIER_ALT, |
| 404 | terminate_binding, |
| 405 | compositor); |
| 406 | } |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 407 | } |
| 408 | |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 409 | static void |
| 410 | activate_binding(struct weston_seat *seat, |
| 411 | struct weston_view *focus_view) |
| 412 | { |
| 413 | struct weston_surface *focus = focus_view->surface; |
| 414 | struct weston_surface *main_surface = |
| 415 | weston_surface_get_main_surface(focus); |
| 416 | |
| 417 | if (get_ivi_shell_surface(main_surface) == NULL) |
| 418 | return; |
| 419 | |
Bryce Harrington | 260c2ff | 2016-06-29 19:04:06 -0700 | [diff] [blame] | 420 | weston_seat_set_keyboard_focus(seat, focus); |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 424 | click_to_activate_binding(struct weston_pointer *pointer, |
| 425 | const struct timespec *time, |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 426 | uint32_t button, void *data) |
| 427 | { |
| 428 | if (pointer->grab != &pointer->default_grab) |
| 429 | return; |
| 430 | if (pointer->focus == NULL) |
| 431 | return; |
| 432 | |
| 433 | activate_binding(pointer->seat, pointer->focus); |
| 434 | } |
| 435 | |
| 436 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 437 | touch_to_activate_binding(struct weston_touch *touch, |
| 438 | const struct timespec *time, |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 439 | void *data) |
| 440 | { |
| 441 | if (touch->grab != &touch->default_grab) |
| 442 | return; |
| 443 | if (touch->focus == NULL) |
| 444 | return; |
| 445 | |
| 446 | activate_binding(touch->seat, touch->focus); |
| 447 | } |
| 448 | |
| 449 | static void |
| 450 | shell_add_bindings(struct weston_compositor *compositor, |
| 451 | struct ivi_shell *shell) |
| 452 | { |
| 453 | weston_compositor_add_button_binding(compositor, BTN_LEFT, 0, |
| 454 | click_to_activate_binding, |
| 455 | shell); |
| 456 | weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0, |
| 457 | click_to_activate_binding, |
| 458 | shell); |
| 459 | weston_compositor_add_touch_binding(compositor, 0, |
| 460 | touch_to_activate_binding, |
| 461 | shell); |
| 462 | } |
| 463 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 464 | /* |
Michael Teyfel | 62d6d56 | 2019-02-05 15:25:56 +0100 | [diff] [blame] | 465 | * libweston-desktop |
| 466 | */ |
| 467 | |
| 468 | static void |
| 469 | desktop_surface_ping_timeout(struct weston_desktop_client *client, |
| 470 | void *user_data) |
| 471 | { |
| 472 | /* Not supported */ |
| 473 | } |
| 474 | |
| 475 | static void |
| 476 | desktop_surface_pong(struct weston_desktop_client *client, |
| 477 | void *user_data) |
| 478 | { |
| 479 | /* Not supported */ |
| 480 | } |
| 481 | |
| 482 | static void |
| 483 | desktop_surface_added(struct weston_desktop_surface *surface, |
| 484 | void *user_data) |
| 485 | { |
| 486 | struct ivi_shell *shell = (struct ivi_shell *) user_data; |
| 487 | struct ivi_layout_surface *layout_surface; |
| 488 | struct ivi_shell_surface *ivisurf; |
| 489 | struct weston_surface *weston_surf = |
| 490 | weston_desktop_surface_get_surface(surface); |
| 491 | |
| 492 | layout_surface = ivi_layout_desktop_surface_create(weston_surf); |
| 493 | if (!layout_surface) { |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | layout_surface->weston_desktop_surface = surface; |
| 498 | |
| 499 | ivisurf = zalloc(sizeof *ivisurf); |
| 500 | if (!ivisurf) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | ivisurf->shell = shell; |
| 505 | ivisurf->id_surface = IVI_INVALID_ID; |
| 506 | |
| 507 | ivisurf->width = 0; |
| 508 | ivisurf->height = 0; |
| 509 | ivisurf->layout_surface = layout_surface; |
| 510 | ivisurf->surface = weston_surf; |
| 511 | |
| 512 | weston_desktop_surface_set_user_data(surface, ivisurf); |
| 513 | } |
| 514 | |
| 515 | static void |
| 516 | desktop_surface_removed(struct weston_desktop_surface *surface, |
| 517 | void *user_data) |
| 518 | { |
| 519 | struct ivi_shell_surface *ivisurf = (struct ivi_shell_surface *) |
| 520 | weston_desktop_surface_get_user_data(surface); |
| 521 | |
| 522 | assert(ivisurf != NULL); |
| 523 | |
| 524 | if (ivisurf->layout_surface) |
| 525 | layout_surface_cleanup(ivisurf); |
| 526 | } |
| 527 | |
| 528 | static void |
| 529 | desktop_surface_committed(struct weston_desktop_surface *surface, |
| 530 | int32_t sx, int32_t sy, void *user_data) |
| 531 | { |
| 532 | struct ivi_shell_surface *ivisurf = (struct ivi_shell_surface *) |
| 533 | weston_desktop_surface_get_user_data(surface); |
| 534 | struct weston_surface *weston_surf = |
| 535 | weston_desktop_surface_get_surface(surface); |
| 536 | |
Dongjin Kim | ba89f00 | 2024-09-30 17:49:36 +0900 | [diff] [blame] | 537 | if (!ivisurf) |
Michael Teyfel | 62d6d56 | 2019-02-05 15:25:56 +0100 | [diff] [blame] | 538 | return; |
| 539 | |
| 540 | if (weston_surf->width == 0 || weston_surf->height == 0) |
| 541 | return; |
| 542 | |
| 543 | if (ivisurf->width != weston_surf->width || |
| 544 | ivisurf->height != weston_surf->height) { |
| 545 | ivisurf->width = weston_surf->width; |
| 546 | ivisurf->height = weston_surf->height; |
| 547 | |
| 548 | ivi_layout_desktop_surface_configure(ivisurf->layout_surface, |
| 549 | weston_surf->width, |
| 550 | weston_surf->height); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | static void |
| 555 | desktop_surface_move(struct weston_desktop_surface *surface, |
| 556 | struct weston_seat *seat, uint32_t serial, void *user_data) |
| 557 | { |
| 558 | /* Not supported */ |
| 559 | } |
| 560 | |
| 561 | static void |
| 562 | desktop_surface_resize(struct weston_desktop_surface *surface, |
| 563 | struct weston_seat *seat, uint32_t serial, |
| 564 | enum weston_desktop_surface_edge edges, void *user_data) |
| 565 | { |
| 566 | /* Not supported */ |
| 567 | } |
| 568 | |
| 569 | static void |
| 570 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *surface, |
| 571 | bool fullscreen, |
| 572 | struct weston_output *output, |
| 573 | void *user_data) |
| 574 | { |
| 575 | /* Not supported */ |
| 576 | } |
| 577 | |
| 578 | static void |
| 579 | desktop_surface_maximized_requested(struct weston_desktop_surface *surface, |
| 580 | bool maximized, void *user_data) |
| 581 | { |
| 582 | /* Not supported */ |
| 583 | } |
| 584 | |
| 585 | static void |
| 586 | desktop_surface_minimized_requested(struct weston_desktop_surface *surface, |
| 587 | void *user_data) |
| 588 | { |
| 589 | /* Not supported */ |
| 590 | } |
| 591 | |
| 592 | static void |
| 593 | desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface, |
| 594 | int32_t x, int32_t y, void *user_data) |
| 595 | { |
| 596 | /* Not supported */ |
| 597 | } |
| 598 | |
| 599 | static const struct weston_desktop_api shell_desktop_api = { |
| 600 | .struct_size = sizeof(struct weston_desktop_api), |
| 601 | .ping_timeout = desktop_surface_ping_timeout, |
| 602 | .pong = desktop_surface_pong, |
| 603 | .surface_added = desktop_surface_added, |
| 604 | .surface_removed = desktop_surface_removed, |
| 605 | .committed = desktop_surface_committed, |
| 606 | |
| 607 | .move = desktop_surface_move, |
| 608 | .resize = desktop_surface_resize, |
| 609 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 610 | .maximized_requested = desktop_surface_maximized_requested, |
| 611 | .minimized_requested = desktop_surface_minimized_requested, |
| 612 | .set_xwayland_position = desktop_surface_set_xwayland_position, |
| 613 | }; |
| 614 | |
| 615 | /* |
| 616 | * end of libweston-desktop |
| 617 | */ |
| 618 | |
| 619 | /* |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 620 | * Initialization of ivi-shell. |
| 621 | */ |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 622 | WL_EXPORT int |
Quentin Glidic | da01c1d | 2016-12-02 14:17:08 +0100 | [diff] [blame] | 623 | wet_shell_init(struct weston_compositor *compositor, |
| 624 | int *argc, char *argv[]) |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 625 | { |
| 626 | struct ivi_shell *shell; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 627 | |
| 628 | shell = zalloc(sizeof *shell); |
| 629 | if (shell == NULL) |
| 630 | return -1; |
| 631 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 632 | if (!weston_compositor_add_destroy_listener_once(compositor, |
| 633 | &shell->destroy_listener, |
| 634 | shell_destroy)) { |
| 635 | free(shell); |
| 636 | return 0; |
| 637 | } |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 638 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 639 | init_ivi_shell(compositor, shell); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 640 | |
Emre Ucan | cf4113c | 2018-06-05 10:23:00 +0200 | [diff] [blame] | 641 | shell->wake_listener.notify = wake_handler; |
| 642 | wl_signal_add(&compositor->wake_signal, &shell->wake_listener); |
| 643 | |
Michael Teyfel | 2763b66 | 2017-10-17 11:10:58 +0200 | [diff] [blame] | 644 | shell->desktop = weston_desktop_create(compositor, &shell_desktop_api, shell); |
| 645 | if (!shell->desktop) |
| 646 | goto err_shell; |
| 647 | |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 648 | if (wl_global_create(compositor->wl_display, |
| 649 | &ivi_application_interface, 1, |
| 650 | shell, bind_ivi_application) == NULL) |
Michael Teyfel | 2763b66 | 2017-10-17 11:10:58 +0200 | [diff] [blame] | 651 | goto err_desktop; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 652 | |
Nobuhiko Tanibata | 28dc18c | 2014-12-15 13:22:31 +0900 | [diff] [blame] | 653 | ivi_layout_init_with_compositor(compositor); |
Nobuhiko Tanibata | 0627b4a | 2015-12-09 15:03:47 +0900 | [diff] [blame] | 654 | shell_add_bindings(compositor, shell); |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 655 | |
Michael Teyfel | f2042e1 | 2017-09-26 17:12:08 +0200 | [diff] [blame] | 656 | return IVI_SUCCEEDED; |
Pekka Paalanen | e35b223 | 2015-02-19 17:08:44 +0200 | [diff] [blame] | 657 | |
Michael Teyfel | 2763b66 | 2017-10-17 11:10:58 +0200 | [diff] [blame] | 658 | err_desktop: |
| 659 | weston_desktop_destroy(shell->desktop); |
| 660 | |
Michael Teyfel | f2042e1 | 2017-09-26 17:12:08 +0200 | [diff] [blame] | 661 | err_shell: |
Pekka Paalanen | d2b9b5d | 2019-11-06 12:07:23 +0200 | [diff] [blame] | 662 | wl_list_remove(&shell->destroy_listener.link); |
Michael Teyfel | f2042e1 | 2017-09-26 17:12:08 +0200 | [diff] [blame] | 663 | free(shell); |
| 664 | |
| 665 | return IVI_FAILED; |
Nobuhiko Tanibata | 487adc4 | 2014-11-27 13:22:37 +0900 | [diff] [blame] | 666 | } |