Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 DENSO CORPORATION |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * A reference implementation how to use ivi-layout APIs in order to manage |
| 25 | * layout of ivi_surfaces/ivi_layers. Layout change is triggered by |
| 26 | * ivi-hmi-controller protocol, ivi-hmi-controller.xml. A reference how to |
| 27 | * use the protocol, see hmi-controller-homescreen. |
| 28 | * |
| 29 | * In-Vehicle Infotainment system usually manage properties of |
| 30 | * ivi_surfaces/ivi_layers by only a central component which decide where |
| 31 | * ivi_surfaces/ivi_layers shall be. This reference show examples to |
| 32 | * implement the central component as a module of weston. |
| 33 | * |
| 34 | * Default Scene graph of UI is defined in hmi_controller_create. It |
| 35 | * consists of |
| 36 | * - In the bottom, a base ivi_layer to group ivi_surfaces of background, |
| 37 | * panel, and buttons |
| 38 | * - Next, a application ivi_layer to show application ivi_surfaces. |
| 39 | * - Workspace background ivi_layer to show a ivi_surface of background image. |
| 40 | * - Workspace ivi_layer to show launcher to launch application with icons. |
| 41 | * Paths to binary and icon are defined in weston.ini. The width of this |
| 42 | * ivi_layer is longer than the size of ivi_screen because a workspace has |
| 43 | * several pages and is controlled by motion of input. |
| 44 | * |
| 45 | * TODO: animation method shall be refined |
| 46 | * TODO: support fade-in when UI is ready |
| 47 | */ |
| 48 | |
| 49 | #include <sys/wait.h> |
| 50 | #include <unistd.h> |
| 51 | #include <stdlib.h> |
| 52 | #include <stdio.h> |
| 53 | #include <string.h> |
| 54 | #include <linux/input.h> |
| 55 | #include <assert.h> |
| 56 | #include <time.h> |
| 57 | |
| 58 | #include "ivi-layout-export.h" |
| 59 | #include "ivi-hmi-controller-server-protocol.h" |
| 60 | |
| 61 | /***************************************************************************** |
| 62 | * structure, globals |
| 63 | ****************************************************************************/ |
| 64 | struct hmi_controller_layer { |
| 65 | struct ivi_layout_layer *ivilayer; |
| 66 | uint32_t id_layer; |
| 67 | int32_t x; |
| 68 | int32_t y; |
| 69 | int32_t width; |
| 70 | int32_t height; |
| 71 | }; |
| 72 | |
| 73 | struct link_layer { |
| 74 | struct ivi_layout_layer *layout_layer; |
| 75 | struct wl_list link; |
| 76 | }; |
| 77 | |
| 78 | struct hmi_controller_fade { |
| 79 | uint32_t is_fade_in; |
| 80 | struct wl_list layer_list; |
| 81 | }; |
| 82 | |
| 83 | struct hmi_server_setting { |
| 84 | uint32_t base_layer_id; |
| 85 | uint32_t application_layer_id; |
| 86 | uint32_t workspace_background_layer_id; |
| 87 | uint32_t workspace_layer_id; |
| 88 | int32_t panel_height; |
| 89 | uint32_t transition_duration; |
| 90 | char *ivi_homescreen; |
| 91 | }; |
| 92 | |
| 93 | struct ui_setting { |
| 94 | uint32_t background_id; |
| 95 | uint32_t panel_id; |
| 96 | uint32_t tiling_id; |
| 97 | uint32_t sidebyside_id; |
| 98 | uint32_t fullscreen_id; |
| 99 | uint32_t random_id; |
| 100 | uint32_t home_id; |
| 101 | uint32_t workspace_background_id; |
| 102 | }; |
| 103 | |
| 104 | struct hmi_controller { |
| 105 | struct hmi_server_setting *hmi_setting; |
| 106 | struct hmi_controller_layer base_layer; |
| 107 | struct hmi_controller_layer application_layer; |
| 108 | struct hmi_controller_layer workspace_background_layer; |
| 109 | struct hmi_controller_layer workspace_layer; |
| 110 | enum ivi_hmi_controller_layout_mode layout_mode; |
| 111 | |
| 112 | struct hmi_controller_fade workspace_fade; |
| 113 | |
| 114 | int32_t workspace_count; |
| 115 | struct wl_array ui_widgets; |
| 116 | int32_t is_initialized; |
| 117 | |
| 118 | struct weston_compositor *compositor; |
| 119 | struct wl_listener destroy_listener; |
| 120 | |
| 121 | struct wl_client *user_interface; |
| 122 | struct ui_setting ui_setting; |
| 123 | }; |
| 124 | |
| 125 | struct launcher_info { |
| 126 | uint32_t surface_id; |
| 127 | uint32_t workspace_id; |
| 128 | int32_t index; |
| 129 | }; |
| 130 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 131 | const struct ivi_controller_interface *ivi_controller_interface; |
| 132 | |
| 133 | int |
| 134 | controller_module_init(struct weston_compositor *ec, |
| 135 | int *argc, char *argv[], |
| 136 | const struct ivi_controller_interface *interface, |
| 137 | size_t interface_version); |
| 138 | |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 139 | /***************************************************************************** |
| 140 | * local functions |
| 141 | ****************************************************************************/ |
| 142 | static void * |
| 143 | fail_on_null(void *p, size_t size, char *file, int32_t line) |
| 144 | { |
| 145 | if (size && !p) { |
| 146 | weston_log("%s(%d) %zd: out of memory\n", file, line, size); |
| 147 | exit(EXIT_FAILURE); |
| 148 | } |
| 149 | |
| 150 | return p; |
| 151 | } |
| 152 | |
| 153 | static void * |
| 154 | mem_alloc(size_t size, char *file, int32_t line) |
| 155 | { |
| 156 | return fail_on_null(calloc(1, size), size, file, line); |
| 157 | } |
| 158 | |
| 159 | #define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__) |
| 160 | |
| 161 | static int32_t |
| 162 | is_surf_in_ui_widget(struct hmi_controller *hmi_ctrl, |
| 163 | struct ivi_layout_surface *ivisurf) |
| 164 | { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 165 | uint32_t id = ivi_controller_interface->get_id_of_surface(ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 166 | |
| 167 | uint32_t *ui_widget_id = NULL; |
| 168 | wl_array_for_each(ui_widget_id, &hmi_ctrl->ui_widgets) { |
| 169 | if (*ui_widget_id == id) |
| 170 | return 1; |
| 171 | } |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int |
| 177 | compare_launcher_info(const void *lhs, const void *rhs) |
| 178 | { |
| 179 | const struct launcher_info *left = lhs; |
| 180 | const struct launcher_info *right = rhs; |
| 181 | |
| 182 | if (left->workspace_id < right->workspace_id) |
| 183 | return -1; |
| 184 | |
| 185 | if (left->workspace_id > right->workspace_id) |
| 186 | return 1; |
| 187 | |
| 188 | if (left->index < right->index) |
| 189 | return -1; |
| 190 | |
| 191 | if (left->index > right->index) |
| 192 | return 1; |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Internal methods called by mainly ivi_hmi_controller_switch_mode |
| 199 | * This reference shows 4 examples how to use ivi_layout APIs. |
| 200 | */ |
| 201 | static void |
| 202 | mode_divided_into_tiling(struct hmi_controller *hmi_ctrl, |
| 203 | struct ivi_layout_surface **pp_surface, |
| 204 | int32_t surface_length, |
| 205 | struct hmi_controller_layer *layer) |
| 206 | { |
| 207 | const float surface_width = (float)layer->width * 0.25; |
| 208 | const float surface_height = (float)layer->height * 0.5; |
| 209 | int32_t surface_x = 0; |
| 210 | int32_t surface_y = 0; |
| 211 | struct ivi_layout_surface *ivisurf = NULL; |
| 212 | struct ivi_layout_surface **surfaces; |
| 213 | struct ivi_layout_surface **new_order; |
| 214 | const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration; |
| 215 | |
| 216 | int32_t i = 0; |
| 217 | int32_t surf_num = 0; |
| 218 | uint32_t num = 1; |
| 219 | |
| 220 | surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length); |
| 221 | new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length); |
| 222 | |
| 223 | for (i = 0; i < surface_length; i++) { |
| 224 | ivisurf = pp_surface[i]; |
| 225 | |
| 226 | /* skip ui widgets */ |
| 227 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 228 | continue; |
| 229 | |
| 230 | surfaces[surf_num++] = ivisurf; |
| 231 | } |
| 232 | |
| 233 | for (i = 0; i < surf_num; i++) { |
| 234 | ivisurf = surfaces[i]; |
| 235 | new_order[i] = ivisurf; |
| 236 | |
| 237 | if (num <= 8) { |
| 238 | if (num < 5) { |
| 239 | surface_x = (int32_t)((num - 1) * (surface_width)); |
| 240 | surface_y = 0; |
| 241 | } else { |
| 242 | surface_x = (int32_t)((num - 5) * (surface_width)); |
| 243 | surface_y = (int32_t)surface_height; |
| 244 | } |
| 245 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 246 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 247 | IVI_LAYOUT_TRANSITION_VIEW_DEFAULT, |
| 248 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 249 | ivi_controller_interface->surface_set_visibility(ivisurf, true); |
| 250 | ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 251 | surface_x, surface_y, |
| 252 | (int32_t)surface_width, |
| 253 | (int32_t)surface_height); |
| 254 | |
| 255 | num++; |
| 256 | continue; |
| 257 | } |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 258 | ivi_controller_interface->surface_set_visibility(ivisurf, false); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | if (surf_num > 0) { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 262 | ivi_controller_interface->layer_set_transition(layer->ivilayer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 263 | IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER, |
| 264 | duration); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | free(surfaces); |
| 268 | free(new_order); |
| 269 | } |
| 270 | |
| 271 | static void |
| 272 | mode_divided_into_sidebyside(struct hmi_controller *hmi_ctrl, |
| 273 | struct ivi_layout_surface **pp_surface, |
| 274 | int32_t surface_length, |
| 275 | struct hmi_controller_layer *layer) |
| 276 | { |
| 277 | int32_t surface_width = layer->width / 2; |
| 278 | int32_t surface_height = layer->height; |
| 279 | struct ivi_layout_surface *ivisurf = NULL; |
| 280 | |
| 281 | const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration; |
| 282 | int32_t i = 0; |
| 283 | int32_t num = 1; |
| 284 | |
| 285 | for (i = 0; i < surface_length; i++) { |
| 286 | ivisurf = pp_surface[i]; |
| 287 | |
| 288 | /* skip ui widgets */ |
| 289 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 290 | continue; |
| 291 | |
| 292 | if (num == 1) { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 293 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 294 | IVI_LAYOUT_TRANSITION_VIEW_DEFAULT, |
| 295 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 296 | ivi_controller_interface->surface_set_visibility(ivisurf, true); |
| 297 | ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 298 | 0, 0, |
| 299 | surface_width, |
| 300 | surface_height); |
| 301 | |
| 302 | num++; |
| 303 | continue; |
| 304 | } else if (num == 2) { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 305 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 306 | IVI_LAYOUT_TRANSITION_VIEW_DEFAULT, |
| 307 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 308 | ivi_controller_interface->surface_set_visibility(ivisurf, true); |
| 309 | ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 310 | surface_width, 0, |
| 311 | surface_width, |
| 312 | surface_height); |
| 313 | |
| 314 | num++; |
| 315 | continue; |
| 316 | } |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 317 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 318 | IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY, |
| 319 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 320 | ivi_controller_interface->surface_set_visibility(ivisurf, false); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | static void |
| 325 | mode_fullscreen_someone(struct hmi_controller *hmi_ctrl, |
| 326 | struct ivi_layout_surface **pp_surface, |
| 327 | int32_t surface_length, |
| 328 | struct hmi_controller_layer *layer) |
| 329 | { |
| 330 | const int32_t surface_width = layer->width; |
| 331 | const int32_t surface_height = layer->height; |
| 332 | struct ivi_layout_surface *ivisurf = NULL; |
| 333 | int32_t i = 0; |
| 334 | const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration; |
| 335 | |
| 336 | for (i = 0; i < surface_length; i++) { |
| 337 | ivisurf = pp_surface[i]; |
| 338 | |
| 339 | /* skip ui widgets */ |
| 340 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 341 | continue; |
| 342 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 343 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 344 | IVI_LAYOUT_TRANSITION_VIEW_DEFAULT, |
| 345 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 346 | ivi_controller_interface->surface_set_visibility(ivisurf, true); |
| 347 | ivi_controller_interface->surface_set_destination_rectangle(ivisurf, 0, 0, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 348 | surface_width, |
| 349 | surface_height); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | static void |
| 354 | mode_random_replace(struct hmi_controller *hmi_ctrl, |
| 355 | struct ivi_layout_surface **pp_surface, |
| 356 | int32_t surface_length, |
| 357 | struct hmi_controller_layer *layer) |
| 358 | { |
| 359 | const int32_t surface_width = (int32_t)(layer->width * 0.25f); |
| 360 | const int32_t surface_height = (int32_t)(layer->height * 0.25f); |
| 361 | int32_t surface_x = 0; |
| 362 | int32_t surface_y = 0; |
| 363 | struct ivi_layout_surface *ivisurf = NULL; |
| 364 | const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration; |
| 365 | int32_t i = 0; |
| 366 | |
| 367 | for (i = 0; i < surface_length; i++) { |
| 368 | ivisurf = pp_surface[i]; |
| 369 | |
| 370 | /* skip ui widgets */ |
| 371 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 372 | continue; |
| 373 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 374 | ivi_controller_interface->surface_set_transition(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 375 | IVI_LAYOUT_TRANSITION_VIEW_DEFAULT, |
| 376 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 377 | ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 378 | surface_x = rand() % (layer->width - surface_width); |
| 379 | surface_y = rand() % (layer->height - surface_height); |
| 380 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 381 | ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 382 | surface_x, |
| 383 | surface_y, |
| 384 | surface_width, |
| 385 | surface_height); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | static int32_t |
| 390 | has_application_surface(struct hmi_controller *hmi_ctrl, |
| 391 | struct ivi_layout_surface **pp_surface, |
| 392 | int32_t surface_length) |
| 393 | { |
| 394 | struct ivi_layout_surface *ivisurf = NULL; |
| 395 | int32_t i = 0; |
| 396 | |
| 397 | for (i = 0; i < surface_length; i++) { |
| 398 | ivisurf = pp_surface[i]; |
| 399 | |
| 400 | /* skip ui widgets */ |
| 401 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 402 | continue; |
| 403 | |
| 404 | return 1; |
| 405 | } |
| 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Supports 4 example to layout of application ivi_surfaces; |
| 412 | * tiling, side by side, fullscreen, and random. |
| 413 | */ |
| 414 | static void |
| 415 | switch_mode(struct hmi_controller *hmi_ctrl, |
| 416 | enum ivi_hmi_controller_layout_mode layout_mode) |
| 417 | { |
| 418 | struct hmi_controller_layer *layer = &hmi_ctrl->application_layer; |
| 419 | struct ivi_layout_surface **pp_surface = NULL; |
| 420 | int32_t surface_length = 0; |
| 421 | int32_t ret = 0; |
| 422 | |
| 423 | if (!hmi_ctrl->is_initialized) |
| 424 | return; |
| 425 | |
| 426 | hmi_ctrl->layout_mode = layout_mode; |
| 427 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 428 | ret = ivi_controller_interface->get_surfaces(&surface_length, &pp_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 429 | assert(!ret); |
| 430 | |
| 431 | if (!has_application_surface(hmi_ctrl, pp_surface, surface_length)) { |
| 432 | free(pp_surface); |
| 433 | pp_surface = NULL; |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | switch (layout_mode) { |
| 438 | case IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING: |
| 439 | mode_divided_into_tiling(hmi_ctrl, pp_surface, surface_length, |
| 440 | layer); |
| 441 | break; |
| 442 | case IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE: |
| 443 | mode_divided_into_sidebyside(hmi_ctrl, pp_surface, |
| 444 | surface_length, layer); |
| 445 | break; |
| 446 | case IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN: |
| 447 | mode_fullscreen_someone(hmi_ctrl, pp_surface, surface_length, |
| 448 | layer); |
| 449 | break; |
| 450 | case IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM: |
| 451 | mode_random_replace(hmi_ctrl, pp_surface, surface_length, |
| 452 | layer); |
| 453 | break; |
| 454 | } |
| 455 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 456 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 457 | free(pp_surface); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Internal method for transition |
| 462 | */ |
| 463 | static void |
| 464 | hmi_controller_fade_run(struct hmi_controller *hmi_ctrl, uint32_t is_fade_in, |
| 465 | struct hmi_controller_fade *fade) |
| 466 | { |
| 467 | double tint = is_fade_in ? 1.0 : 0.0; |
| 468 | struct link_layer *linklayer = NULL; |
| 469 | const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration; |
| 470 | |
| 471 | fade->is_fade_in = is_fade_in; |
| 472 | |
| 473 | wl_list_for_each(linklayer, &fade->layer_list, link) { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 474 | ivi_controller_interface->layer_set_transition(linklayer->layout_layer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 475 | IVI_LAYOUT_TRANSITION_LAYER_FADE, |
| 476 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 477 | ivi_controller_interface->layer_set_fade_info(linklayer->layout_layer, |
| 478 | is_fade_in, 1.0 - tint, tint); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Internal method to create ivi_layer with hmi_controller_layer and |
| 484 | * add to a ivi_screen |
| 485 | */ |
| 486 | static void |
| 487 | create_layer(struct ivi_layout_screen *iviscrn, |
| 488 | struct hmi_controller_layer *layer) |
| 489 | { |
| 490 | int32_t ret = 0; |
| 491 | |
| 492 | layer->ivilayer = |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 493 | ivi_controller_interface->layer_create_with_dimension(layer->id_layer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 494 | layer->width, |
| 495 | layer->height); |
| 496 | assert(layer->ivilayer != NULL); |
| 497 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 498 | ret = ivi_controller_interface->screen_add_layer(iviscrn, layer->ivilayer); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 499 | assert(!ret); |
| 500 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 501 | ret = ivi_controller_interface->layer_set_destination_rectangle(layer->ivilayer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 502 | layer->x, layer->y, |
| 503 | layer->width, |
| 504 | layer->height); |
| 505 | assert(!ret); |
| 506 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 507 | ret = ivi_controller_interface->layer_set_visibility(layer->ivilayer, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 508 | assert(!ret); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Internal set notification |
| 513 | */ |
| 514 | static void |
| 515 | set_notification_create_surface(struct ivi_layout_surface *ivisurf, |
| 516 | void *userdata) |
| 517 | { |
| 518 | struct hmi_controller *hmi_ctrl = userdata; |
| 519 | struct ivi_layout_layer *application_layer = |
| 520 | hmi_ctrl->application_layer.ivilayer; |
| 521 | int32_t ret = 0; |
| 522 | |
| 523 | /* skip ui widgets */ |
| 524 | if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) |
| 525 | return; |
| 526 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 527 | ret = ivi_controller_interface->layer_add_surface(application_layer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 528 | assert(!ret); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | set_notification_remove_surface(struct ivi_layout_surface *ivisurf, |
| 533 | void *userdata) |
| 534 | { |
| 535 | struct hmi_controller *hmi_ctrl = userdata; |
| 536 | |
| 537 | switch_mode(hmi_ctrl, hmi_ctrl->layout_mode); |
| 538 | } |
| 539 | |
| 540 | static void |
| 541 | set_notification_configure_surface(struct ivi_layout_surface *ivisurf, |
| 542 | void *userdata) |
| 543 | { |
| 544 | struct hmi_controller *hmi_ctrl = userdata; |
| 545 | |
| 546 | switch_mode(hmi_ctrl, hmi_ctrl->layout_mode); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * A hmi_controller used 4 ivi_layers to manage ivi_surfaces. The IDs of |
| 551 | * corresponding ivi_layer are defined in weston.ini. Default scene graph |
| 552 | * of ivi_layers are initialized in hmi_controller_create |
| 553 | */ |
| 554 | static struct hmi_server_setting * |
| 555 | hmi_server_setting_create(struct weston_compositor *ec) |
| 556 | { |
| 557 | struct hmi_server_setting *setting = MEM_ALLOC(sizeof(*setting)); |
| 558 | struct weston_config *config = ec->config; |
| 559 | struct weston_config_section *shell_section = NULL; |
| 560 | |
| 561 | shell_section = weston_config_get_section(config, "ivi-shell", |
| 562 | NULL, NULL); |
| 563 | |
| 564 | weston_config_section_get_uint(shell_section, "base-layer-id", |
| 565 | &setting->base_layer_id, 1000); |
| 566 | |
| 567 | weston_config_section_get_uint(shell_section, |
| 568 | "workspace-background-layer-id", |
| 569 | &setting->workspace_background_layer_id, |
| 570 | 2000); |
| 571 | |
| 572 | weston_config_section_get_uint(shell_section, "workspace-layer-id", |
| 573 | &setting->workspace_layer_id, 3000); |
| 574 | |
| 575 | weston_config_section_get_uint(shell_section, "application-layer-id", |
| 576 | &setting->application_layer_id, 4000); |
| 577 | |
| 578 | weston_config_section_get_uint(shell_section, "transition-duration", |
| 579 | &setting->transition_duration, 300); |
| 580 | |
| 581 | setting->panel_height = 70; |
| 582 | |
| 583 | weston_config_section_get_string(shell_section, |
| 584 | "ivi-shell-user-interface", |
| 585 | &setting->ivi_homescreen, NULL); |
| 586 | |
| 587 | return setting; |
| 588 | } |
| 589 | |
| 590 | static void |
| 591 | hmi_controller_destroy(struct wl_listener *listener, void *data) |
| 592 | { |
| 593 | struct link_layer *link = NULL; |
| 594 | struct link_layer *next = NULL; |
| 595 | struct hmi_controller *hmi_ctrl = |
| 596 | container_of(listener, struct hmi_controller, destroy_listener); |
| 597 | |
| 598 | wl_list_for_each_safe(link, next, |
| 599 | &hmi_ctrl->workspace_fade.layer_list, link) { |
| 600 | wl_list_remove(&link->link); |
| 601 | free(link); |
| 602 | } |
| 603 | |
| 604 | wl_array_release(&hmi_ctrl->ui_widgets); |
| 605 | free(hmi_ctrl->hmi_setting); |
| 606 | free(hmi_ctrl); |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * This is a starting method called from module_init. |
| 611 | * This sets up scene graph of ivi_layers; base, application, workspace |
| 612 | * background, and workspace. These ivi_layers are created/added to |
| 613 | * ivi_screen in create_layer |
| 614 | * |
| 615 | * base: to group ivi_surfaces of panel and background |
| 616 | * application: to group ivi_surfaces of ivi_applications |
| 617 | * workspace background: to group a ivi_surface of background in workspace |
| 618 | * workspace: to group ivi_surfaces for launching ivi_applications |
| 619 | * |
| 620 | * ivi_layers of workspace background and workspace is set to invisible at |
| 621 | * first. The properties of it is updated with animation when |
| 622 | * ivi_hmi_controller_home is requested. |
| 623 | */ |
| 624 | static struct hmi_controller * |
| 625 | hmi_controller_create(struct weston_compositor *ec) |
| 626 | { |
| 627 | struct ivi_layout_screen **pp_screen = NULL; |
| 628 | struct ivi_layout_screen *iviscrn = NULL; |
| 629 | int32_t screen_length = 0; |
| 630 | int32_t screen_width = 0; |
| 631 | int32_t screen_height = 0; |
| 632 | struct link_layer *tmp_link_layer = NULL; |
| 633 | int32_t panel_height = 0; |
| 634 | struct hmi_controller *hmi_ctrl = MEM_ALLOC(sizeof(*hmi_ctrl)); |
| 635 | |
| 636 | wl_array_init(&hmi_ctrl->ui_widgets); |
| 637 | hmi_ctrl->layout_mode = IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING; |
| 638 | hmi_ctrl->hmi_setting = hmi_server_setting_create(ec); |
| 639 | hmi_ctrl->compositor = ec; |
| 640 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 641 | ivi_controller_interface->get_screens(&screen_length, &pp_screen); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 642 | |
| 643 | iviscrn = pp_screen[0]; |
| 644 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 645 | ivi_controller_interface->get_screen_resolution(iviscrn, &screen_width, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 646 | &screen_height); |
| 647 | |
| 648 | /* init base ivi_layer*/ |
| 649 | hmi_ctrl->base_layer.x = 0; |
| 650 | hmi_ctrl->base_layer.y = 0; |
| 651 | hmi_ctrl->base_layer.width = screen_width; |
| 652 | hmi_ctrl->base_layer.height = screen_height; |
| 653 | hmi_ctrl->base_layer.id_layer = hmi_ctrl->hmi_setting->base_layer_id; |
| 654 | |
| 655 | create_layer(iviscrn, &hmi_ctrl->base_layer); |
| 656 | |
| 657 | panel_height = hmi_ctrl->hmi_setting->panel_height; |
| 658 | |
| 659 | /* init application ivi_layer */ |
| 660 | hmi_ctrl->application_layer.x = 0; |
| 661 | hmi_ctrl->application_layer.y = 0; |
| 662 | hmi_ctrl->application_layer.width = screen_width; |
| 663 | hmi_ctrl->application_layer.height = screen_height - panel_height; |
| 664 | hmi_ctrl->application_layer.id_layer = |
| 665 | hmi_ctrl->hmi_setting->application_layer_id; |
| 666 | |
| 667 | create_layer(iviscrn, &hmi_ctrl->application_layer); |
| 668 | |
| 669 | /* init workspace background ivi_layer */ |
| 670 | hmi_ctrl->workspace_background_layer.x = 0; |
| 671 | hmi_ctrl->workspace_background_layer.y = 0; |
| 672 | hmi_ctrl->workspace_background_layer.width = screen_width; |
| 673 | hmi_ctrl->workspace_background_layer.height = |
| 674 | screen_height - panel_height; |
| 675 | |
| 676 | hmi_ctrl->workspace_background_layer.id_layer = |
| 677 | hmi_ctrl->hmi_setting->workspace_background_layer_id; |
| 678 | |
| 679 | create_layer(iviscrn, &hmi_ctrl->workspace_background_layer); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 680 | ivi_controller_interface->layer_set_opacity( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 681 | hmi_ctrl->workspace_background_layer.ivilayer, 0); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 682 | ivi_controller_interface->layer_set_visibility( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 683 | hmi_ctrl->workspace_background_layer.ivilayer, false); |
| 684 | |
| 685 | /* init workspace ivi_layer */ |
| 686 | hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x; |
| 687 | hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y; |
| 688 | hmi_ctrl->workspace_layer.width = |
| 689 | hmi_ctrl->workspace_background_layer.width; |
| 690 | hmi_ctrl->workspace_layer.height = |
| 691 | hmi_ctrl->workspace_background_layer.height; |
| 692 | hmi_ctrl->workspace_layer.id_layer = |
| 693 | hmi_ctrl->hmi_setting->workspace_layer_id; |
| 694 | |
| 695 | create_layer(iviscrn, &hmi_ctrl->workspace_layer); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 696 | ivi_controller_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0); |
| 697 | ivi_controller_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 698 | false); |
| 699 | |
| 700 | wl_list_init(&hmi_ctrl->workspace_fade.layer_list); |
| 701 | tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer)); |
| 702 | tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer; |
| 703 | wl_list_insert(&hmi_ctrl->workspace_fade.layer_list, |
| 704 | &tmp_link_layer->link); |
| 705 | tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer)); |
| 706 | tmp_link_layer->layout_layer = |
| 707 | hmi_ctrl->workspace_background_layer.ivilayer; |
| 708 | wl_list_insert(&hmi_ctrl->workspace_fade.layer_list, |
| 709 | &tmp_link_layer->link); |
| 710 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 711 | ivi_controller_interface->add_notification_create_surface( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 712 | set_notification_create_surface, hmi_ctrl); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 713 | ivi_controller_interface->add_notification_remove_surface( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 714 | set_notification_remove_surface, hmi_ctrl); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 715 | ivi_controller_interface->add_notification_configure_surface( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 716 | set_notification_configure_surface, hmi_ctrl); |
| 717 | |
| 718 | hmi_ctrl->destroy_listener.notify = hmi_controller_destroy; |
| 719 | wl_signal_add(&hmi_ctrl->compositor->destroy_signal, |
| 720 | &hmi_ctrl->destroy_listener); |
| 721 | |
| 722 | free(pp_screen); |
| 723 | pp_screen = NULL; |
| 724 | |
| 725 | return hmi_ctrl; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Implementations of ivi-hmi-controller.xml |
| 730 | */ |
| 731 | |
| 732 | /** |
| 733 | * A ivi_surface drawing background is identified by id_surface. |
| 734 | * Properties of the ivi_surface is set by using ivi_layout APIs according to |
| 735 | * the scene graph of UI defined in hmi_controller_create. |
| 736 | * |
| 737 | * UI ivi_layer is used to add this ivi_surface. |
| 738 | */ |
| 739 | static void |
| 740 | ivi_hmi_controller_set_background(struct hmi_controller *hmi_ctrl, |
| 741 | uint32_t id_surface) |
| 742 | { |
| 743 | struct ivi_layout_surface *ivisurf = NULL; |
| 744 | struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer; |
| 745 | const int32_t dstx = hmi_ctrl->application_layer.x; |
| 746 | const int32_t dsty = hmi_ctrl->application_layer.y; |
| 747 | const int32_t width = hmi_ctrl->application_layer.width; |
| 748 | const int32_t height = hmi_ctrl->application_layer.height; |
| 749 | int32_t ret = 0; |
| 750 | |
| 751 | uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 752 | sizeof(*add_surface_id)); |
| 753 | *add_surface_id = id_surface; |
| 754 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 755 | ivisurf = ivi_controller_interface->get_surface_from_id(id_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 756 | assert(ivisurf != NULL); |
| 757 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 758 | ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 759 | assert(!ret); |
| 760 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 761 | ret = ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 762 | dstx, dsty, width, height); |
| 763 | assert(!ret); |
| 764 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 765 | ret = ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 766 | assert(!ret); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * A ivi_surface drawing panel is identified by id_surface. |
| 771 | * Properties of the ivi_surface is set by using ivi_layout APIs according to |
| 772 | * the scene graph of UI defined in hmi_controller_create. |
| 773 | * |
| 774 | * UI ivi_layer is used to add this ivi_surface. |
| 775 | */ |
| 776 | static void |
| 777 | ivi_hmi_controller_set_panel(struct hmi_controller *hmi_ctrl, |
| 778 | uint32_t id_surface) |
| 779 | { |
| 780 | struct ivi_layout_surface *ivisurf = NULL; |
| 781 | struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer; |
| 782 | const int32_t width = hmi_ctrl->base_layer.width; |
| 783 | int32_t ret = 0; |
| 784 | int32_t panel_height = 0; |
| 785 | const int32_t dstx = 0; |
| 786 | int32_t dsty = 0; |
| 787 | |
| 788 | uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 789 | sizeof(*add_surface_id)); |
| 790 | *add_surface_id = id_surface; |
| 791 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 792 | ivisurf = ivi_controller_interface->get_surface_from_id(id_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 793 | assert(ivisurf != NULL); |
| 794 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 795 | ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 796 | assert(!ret); |
| 797 | |
| 798 | panel_height = hmi_ctrl->hmi_setting->panel_height; |
| 799 | |
| 800 | dsty = hmi_ctrl->base_layer.height - panel_height; |
| 801 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 802 | ret = ivi_controller_interface->surface_set_destination_rectangle( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 803 | ivisurf, dstx, dsty, width, panel_height); |
| 804 | assert(!ret); |
| 805 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 806 | ret = ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 807 | assert(!ret); |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * A ivi_surface drawing buttons in panel is identified by id_surface. |
| 812 | * It can set several buttons. Properties of the ivi_surface is set by |
| 813 | * using ivi_layout APIs according to the scene graph of UI defined in |
| 814 | * hmi_controller_create. Additionally, the position of it is shifted to |
| 815 | * right when new one is requested. |
| 816 | * |
| 817 | * UI ivi_layer is used to add these ivi_surfaces. |
| 818 | */ |
| 819 | static void |
| 820 | ivi_hmi_controller_set_button(struct hmi_controller *hmi_ctrl, |
| 821 | uint32_t id_surface, int32_t number) |
| 822 | { |
| 823 | struct ivi_layout_surface *ivisurf = NULL; |
| 824 | struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer; |
| 825 | const int32_t width = 48; |
| 826 | const int32_t height = 48; |
| 827 | int32_t ret = 0; |
| 828 | int32_t panel_height = 0; |
| 829 | int32_t dstx = 0; |
| 830 | int32_t dsty = 0; |
| 831 | uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 832 | sizeof(*add_surface_id)); |
| 833 | *add_surface_id = id_surface; |
| 834 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 835 | ivisurf = ivi_controller_interface->get_surface_from_id(id_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 836 | assert(ivisurf != NULL); |
| 837 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 838 | ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 839 | assert(!ret); |
| 840 | |
| 841 | panel_height = hmi_ctrl->hmi_setting->panel_height; |
| 842 | |
| 843 | dstx = (60 * number) + 15; |
| 844 | dsty = (hmi_ctrl->base_layer.height - panel_height) + 5; |
| 845 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 846 | ret = ivi_controller_interface->surface_set_destination_rectangle( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 847 | ivisurf,dstx, dsty, width, height); |
| 848 | assert(!ret); |
| 849 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 850 | ret = ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 851 | assert(!ret); |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * A ivi_surface drawing home button in panel is identified by id_surface. |
| 856 | * Properties of the ivi_surface is set by using ivi_layout APIs according to |
| 857 | * the scene graph of UI defined in hmi_controller_create. |
| 858 | * |
| 859 | * UI ivi_layer is used to add these ivi_surfaces. |
| 860 | */ |
| 861 | static void |
| 862 | ivi_hmi_controller_set_home_button(struct hmi_controller *hmi_ctrl, |
| 863 | uint32_t id_surface) |
| 864 | { |
| 865 | struct ivi_layout_surface *ivisurf = NULL; |
| 866 | struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer; |
| 867 | int32_t ret = 0; |
| 868 | int32_t size = 48; |
| 869 | int32_t panel_height = hmi_ctrl->hmi_setting->panel_height; |
| 870 | const int32_t dstx = (hmi_ctrl->base_layer.width - size) / 2; |
| 871 | const int32_t dsty = (hmi_ctrl->base_layer.height - panel_height) + 5; |
| 872 | |
| 873 | uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 874 | sizeof(*add_surface_id)); |
| 875 | *add_surface_id = id_surface; |
| 876 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 877 | ivisurf = ivi_controller_interface->get_surface_from_id(id_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 878 | assert(ivisurf != NULL); |
| 879 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 880 | ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 881 | assert(!ret); |
| 882 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 883 | ret = ivi_controller_interface->surface_set_destination_rectangle( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 884 | ivisurf, dstx, dsty, size, size); |
| 885 | assert(!ret); |
| 886 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 887 | ret = ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 888 | assert(!ret); |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * A ivi_surface drawing background of workspace is identified by id_surface. |
| 893 | * Properties of the ivi_surface is set by using ivi_layout APIs according to |
| 894 | * the scene graph of UI defined in hmi_controller_create. |
| 895 | * |
| 896 | * A ivi_layer of workspace_background is used to add this ivi_surface. |
| 897 | */ |
| 898 | static void |
| 899 | ivi_hmi_controller_set_workspacebackground(struct hmi_controller *hmi_ctrl, |
| 900 | uint32_t id_surface) |
| 901 | { |
| 902 | struct ivi_layout_surface *ivisurf = NULL; |
| 903 | struct ivi_layout_layer *ivilayer = NULL; |
| 904 | const int32_t width = hmi_ctrl->workspace_background_layer.width; |
| 905 | const int32_t height = hmi_ctrl->workspace_background_layer.height; |
| 906 | int32_t ret = 0; |
| 907 | |
| 908 | uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 909 | sizeof(*add_surface_id)); |
| 910 | *add_surface_id = id_surface; |
| 911 | ivilayer = hmi_ctrl->workspace_background_layer.ivilayer; |
| 912 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 913 | ivisurf = ivi_controller_interface->get_surface_from_id(id_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 914 | assert(ivisurf != NULL); |
| 915 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 916 | ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 917 | assert(!ret); |
| 918 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 919 | ret = ivi_controller_interface->surface_set_destination_rectangle(ivisurf, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 920 | 0, 0, width, height); |
| 921 | assert(!ret); |
| 922 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 923 | ret = ivi_controller_interface->surface_set_visibility(ivisurf, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 924 | assert(!ret); |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * A list of ivi_surfaces drawing launchers in workspace is identified by |
| 929 | * id_surfaces. Properties of the ivi_surface is set by using ivi_layout |
| 930 | * APIs according to the scene graph of UI defined in hmi_controller_create. |
| 931 | * |
| 932 | * The workspace can have several pages to group ivi_surfaces of launcher. |
| 933 | * Each call of this interface increments a number of page to add a group |
| 934 | * of ivi_surfaces |
| 935 | */ |
| 936 | static void |
| 937 | ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl, |
| 938 | int32_t icon_size) |
| 939 | { |
| 940 | struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer; |
| 941 | int32_t minspace_x = 10; |
| 942 | int32_t minspace_y = minspace_x; |
| 943 | |
| 944 | int32_t width = hmi_ctrl->workspace_layer.width; |
| 945 | int32_t height = hmi_ctrl->workspace_layer.height; |
| 946 | |
| 947 | int32_t x_count = (width - minspace_x) / (minspace_x + icon_size); |
| 948 | int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count)); |
| 949 | float fcell_size_x = icon_size + space_x; |
| 950 | |
| 951 | int32_t y_count = (height - minspace_y) / (minspace_y + icon_size); |
| 952 | int32_t space_y = (int32_t)((height - y_count * icon_size) / (1.0 + y_count)); |
| 953 | float fcell_size_y = icon_size + space_y; |
| 954 | |
| 955 | struct weston_config *config = NULL; |
| 956 | struct weston_config_section *section = NULL; |
| 957 | const char *name = NULL; |
| 958 | int launcher_count = 0; |
| 959 | struct wl_array launchers; |
| 960 | int32_t nx = 0; |
| 961 | int32_t ny = 0; |
| 962 | int32_t prev = -1; |
| 963 | struct launcher_info *data = NULL; |
| 964 | |
| 965 | uint32_t surfaceid = 0; |
| 966 | uint32_t workspaceid = 0; |
| 967 | struct launcher_info *info = NULL; |
| 968 | |
| 969 | int32_t x = 0; |
| 970 | int32_t y = 0; |
| 971 | int32_t ret = 0; |
| 972 | struct ivi_layout_surface* layout_surface = NULL; |
| 973 | uint32_t *add_surface_id = NULL; |
| 974 | |
| 975 | if (0 == x_count) |
| 976 | x_count = 1; |
| 977 | |
| 978 | if (0 == y_count) |
| 979 | y_count = 1; |
| 980 | |
| 981 | config = hmi_ctrl->compositor->config; |
| 982 | if (!config) |
| 983 | return; |
| 984 | |
| 985 | section = weston_config_get_section(config, "ivi-shell", NULL, NULL); |
| 986 | if (!section) |
| 987 | return; |
| 988 | |
| 989 | wl_array_init(&launchers); |
| 990 | |
| 991 | while (weston_config_next_section(config, §ion, &name)) { |
| 992 | surfaceid = 0; |
| 993 | workspaceid = 0; |
| 994 | info = NULL; |
| 995 | if (0 != strcmp(name, "ivi-launcher")) |
| 996 | continue; |
| 997 | |
| 998 | if (0 != weston_config_section_get_uint(section, "icon-id", |
| 999 | &surfaceid, 0)) |
| 1000 | continue; |
| 1001 | |
| 1002 | if (0 != weston_config_section_get_uint(section, |
| 1003 | "workspace-id", |
| 1004 | &workspaceid, 0)) |
| 1005 | continue; |
| 1006 | |
| 1007 | info = wl_array_add(&launchers, sizeof(*info)); |
| 1008 | |
| 1009 | if (info) { |
| 1010 | info->surface_id = surfaceid; |
| 1011 | info->workspace_id = workspaceid; |
| 1012 | info->index = launcher_count; |
| 1013 | ++launcher_count; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | qsort(launchers.data, launcher_count, sizeof(struct launcher_info), |
| 1018 | compare_launcher_info); |
| 1019 | |
| 1020 | wl_array_for_each(data, &launchers) { |
| 1021 | x = 0; |
| 1022 | y = 0; |
| 1023 | ret = 0; |
| 1024 | layout_surface = NULL; |
| 1025 | add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets, |
| 1026 | sizeof(*add_surface_id)); |
| 1027 | |
| 1028 | *add_surface_id = data->surface_id; |
| 1029 | |
| 1030 | if (0 > prev || (uint32_t)prev != data->workspace_id) { |
| 1031 | nx = 0; |
| 1032 | ny = 0; |
| 1033 | prev = data->workspace_id; |
| 1034 | |
| 1035 | if (0 <= prev) |
| 1036 | hmi_ctrl->workspace_count++; |
| 1037 | } |
| 1038 | |
| 1039 | if (y_count == ny) { |
| 1040 | ny = 0; |
| 1041 | hmi_ctrl->workspace_count++; |
| 1042 | } |
| 1043 | |
| 1044 | x = nx * fcell_size_x + (hmi_ctrl->workspace_count - 1) * width + space_x; |
| 1045 | y = ny * fcell_size_y + space_y; |
| 1046 | |
| 1047 | layout_surface = |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1048 | ivi_controller_interface->get_surface_from_id(data->surface_id); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1049 | assert(layout_surface); |
| 1050 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1051 | ret = ivi_controller_interface->layer_add_surface(layer, layout_surface); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1052 | assert(!ret); |
| 1053 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1054 | ret = ivi_controller_interface->surface_set_destination_rectangle( |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1055 | layout_surface, x, y, icon_size, icon_size); |
| 1056 | assert(!ret); |
| 1057 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1058 | ret = ivi_controller_interface->surface_set_visibility(layout_surface, true); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1059 | assert(!ret); |
| 1060 | |
| 1061 | nx++; |
| 1062 | |
| 1063 | if (x_count == nx) { |
| 1064 | ny++; |
| 1065 | nx = 0; |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | wl_array_release(&launchers); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1070 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static void |
| 1074 | ivi_hmi_controller_UI_ready(struct wl_client *client, |
| 1075 | struct wl_resource *resource) |
| 1076 | { |
| 1077 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1078 | |
| 1079 | ivi_hmi_controller_set_background(hmi_ctrl, hmi_ctrl->ui_setting.background_id); |
| 1080 | ivi_hmi_controller_set_panel(hmi_ctrl, hmi_ctrl->ui_setting.panel_id); |
| 1081 | ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.tiling_id, 0); |
| 1082 | ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.sidebyside_id, 1); |
| 1083 | ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.fullscreen_id, 2); |
| 1084 | ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.random_id, 3); |
| 1085 | ivi_hmi_controller_set_home_button(hmi_ctrl, hmi_ctrl->ui_setting.home_id); |
| 1086 | ivi_hmi_controller_set_workspacebackground(hmi_ctrl, hmi_ctrl->ui_setting.workspace_background_id); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1087 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1088 | |
| 1089 | ivi_hmi_controller_add_launchers(hmi_ctrl, 256); |
| 1090 | hmi_ctrl->is_initialized = 1; |
| 1091 | } |
| 1092 | |
| 1093 | /** |
| 1094 | * Implementation of request and event of ivi_hmi_controller_workspace_control |
| 1095 | * and controlling workspace. |
| 1096 | * |
| 1097 | * When motion of input is detected in a ivi_surface of workspace background, |
| 1098 | * ivi_hmi_controller_workspace_control shall be invoked and to start |
| 1099 | * controlling of workspace. The workspace has several pages to show several |
| 1100 | * groups of applications. |
| 1101 | * The workspace is slid by using ivi-layout to select a a page in layer_set_pos |
| 1102 | * according to motion. When motion finished, e.g. touch up detected, control is |
| 1103 | * terminated and event:ivi_hmi_controller_workspace_control is notified. |
| 1104 | */ |
| 1105 | struct pointer_grab { |
| 1106 | struct weston_pointer_grab grab; |
| 1107 | struct ivi_layout_layer *layer; |
| 1108 | struct wl_resource *resource; |
| 1109 | }; |
| 1110 | |
| 1111 | struct touch_grab { |
| 1112 | struct weston_touch_grab grab; |
| 1113 | struct ivi_layout_layer *layer; |
| 1114 | struct wl_resource *resource; |
| 1115 | }; |
| 1116 | |
| 1117 | struct move_grab { |
| 1118 | wl_fixed_t dst[2]; |
| 1119 | wl_fixed_t rgn[2][2]; |
| 1120 | double v[2]; |
| 1121 | struct timespec start_time; |
| 1122 | struct timespec pre_time; |
| 1123 | wl_fixed_t start_pos[2]; |
| 1124 | wl_fixed_t pos[2]; |
| 1125 | int32_t is_moved; |
| 1126 | }; |
| 1127 | |
| 1128 | struct pointer_move_grab { |
| 1129 | struct pointer_grab base; |
| 1130 | struct move_grab move; |
| 1131 | }; |
| 1132 | |
| 1133 | struct touch_move_grab { |
| 1134 | struct touch_grab base; |
| 1135 | struct move_grab move; |
| 1136 | int32_t is_active; |
| 1137 | }; |
| 1138 | |
| 1139 | static void |
| 1140 | pointer_grab_start(struct pointer_grab *grab, |
| 1141 | struct ivi_layout_layer *layer, |
| 1142 | const struct weston_pointer_grab_interface *interface, |
| 1143 | struct weston_pointer *pointer) |
| 1144 | { |
| 1145 | grab->grab.interface = interface; |
| 1146 | grab->layer = layer; |
| 1147 | weston_pointer_start_grab(pointer, &grab->grab); |
| 1148 | } |
| 1149 | |
| 1150 | static void |
| 1151 | touch_grab_start(struct touch_grab *grab, |
| 1152 | struct ivi_layout_layer *layer, |
| 1153 | const struct weston_touch_grab_interface *interface, |
| 1154 | struct weston_touch* touch) |
| 1155 | { |
| 1156 | grab->grab.interface = interface; |
| 1157 | grab->layer = layer; |
| 1158 | weston_touch_start_grab(touch, &grab->grab); |
| 1159 | } |
| 1160 | |
| 1161 | static int32_t |
| 1162 | clamp(int32_t val, int32_t min, int32_t max) |
| 1163 | { |
| 1164 | if (val < min) |
| 1165 | return min; |
| 1166 | |
| 1167 | if (max < val) |
| 1168 | return max; |
| 1169 | |
| 1170 | return val; |
| 1171 | } |
| 1172 | |
| 1173 | static void |
| 1174 | move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource, |
| 1175 | wl_fixed_t grab_x, struct ivi_layout_layer *layer) |
| 1176 | { |
| 1177 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1178 | int32_t width = hmi_ctrl->workspace_background_layer.width; |
| 1179 | |
| 1180 | struct timespec time = {0}; |
| 1181 | double grab_time = 0.0; |
| 1182 | double from_motion_time = 0.0; |
| 1183 | double pointer_v = 0.0; |
| 1184 | int32_t is_flick = 0; |
| 1185 | int32_t pos_x = 0; |
| 1186 | int32_t pos_y = 0; |
| 1187 | int page_no = 0; |
| 1188 | double end_pos = 0.0; |
| 1189 | uint32_t duration = 0; |
| 1190 | |
| 1191 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 1192 | |
| 1193 | grab_time = 1e+3 * (time.tv_sec - move->start_time.tv_sec) + |
| 1194 | 1e-6 * (time.tv_nsec - move->start_time.tv_nsec); |
| 1195 | |
| 1196 | from_motion_time = 1e+3 * (time.tv_sec - move->pre_time.tv_sec) + |
| 1197 | 1e-6 * (time.tv_nsec - move->pre_time.tv_nsec); |
| 1198 | |
| 1199 | pointer_v = move->v[0]; |
| 1200 | |
| 1201 | is_flick = grab_time < 400 && 0.4 < fabs(pointer_v); |
| 1202 | if (200 < from_motion_time) |
| 1203 | pointer_v = 0.0; |
| 1204 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1205 | ivi_controller_interface->layer_get_position(layer, &pos_x, &pos_y); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1206 | |
| 1207 | |
| 1208 | if (is_flick) { |
| 1209 | int orgx = wl_fixed_to_int(move->dst[0] + grab_x); |
| 1210 | page_no = (-orgx + width / 2) / width; |
| 1211 | |
| 1212 | if (pointer_v < 0.0) |
| 1213 | page_no++; |
| 1214 | else |
| 1215 | page_no--; |
| 1216 | } else { |
| 1217 | page_no = (-pos_x + width / 2) / width; |
| 1218 | } |
| 1219 | |
| 1220 | page_no = clamp(page_no, 0, hmi_ctrl->workspace_count - 1); |
| 1221 | end_pos = -page_no * width; |
| 1222 | |
| 1223 | duration = hmi_ctrl->hmi_setting->transition_duration; |
| 1224 | ivi_hmi_controller_send_workspace_end_control(resource, move->is_moved); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1225 | ivi_controller_interface->layer_set_transition(layer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1226 | IVI_LAYOUT_TRANSITION_LAYER_MOVE, |
| 1227 | duration); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1228 | ivi_controller_interface->layer_set_destination_rectangle(layer, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1229 | end_pos, pos_y, |
| 1230 | hmi_ctrl->workspace_background_layer.width, |
| 1231 | hmi_ctrl->workspace_background_layer.height); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1232 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | static void |
| 1236 | pointer_move_workspace_grab_end(struct pointer_grab *grab) |
| 1237 | { |
| 1238 | struct pointer_move_grab *pnt_move_grab = |
| 1239 | (struct pointer_move_grab *)grab; |
| 1240 | struct ivi_layout_layer *layer = pnt_move_grab->base.layer; |
| 1241 | |
| 1242 | move_workspace_grab_end(&pnt_move_grab->move, grab->resource, |
| 1243 | grab->grab.pointer->grab_x, layer); |
| 1244 | |
| 1245 | weston_pointer_end_grab(grab->grab.pointer); |
| 1246 | } |
| 1247 | |
| 1248 | static void |
| 1249 | touch_move_workspace_grab_end(struct touch_grab *grab) |
| 1250 | { |
| 1251 | struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; |
| 1252 | struct ivi_layout_layer *layer = tch_move_grab->base.layer; |
| 1253 | |
| 1254 | move_workspace_grab_end(&tch_move_grab->move, grab->resource, |
| 1255 | grab->grab.touch->grab_x, layer); |
| 1256 | |
| 1257 | weston_touch_end_grab(grab->grab.touch); |
| 1258 | } |
| 1259 | |
| 1260 | static void |
| 1261 | pointer_noop_grab_focus(struct weston_pointer_grab *grab) |
| 1262 | { |
| 1263 | } |
| 1264 | |
| 1265 | static void |
| 1266 | move_grab_update(struct move_grab *move, wl_fixed_t pointer[2]) |
| 1267 | { |
| 1268 | struct timespec timestamp = {0}; |
| 1269 | int32_t ii = 0; |
| 1270 | double dt = 0.0; |
| 1271 | |
| 1272 | clock_gettime(CLOCK_MONOTONIC, ×tamp); //FIXME |
| 1273 | dt = (1e+3 * (timestamp.tv_sec - move->pre_time.tv_sec) + |
| 1274 | 1e-6 * (timestamp.tv_nsec - move->pre_time.tv_nsec)); |
| 1275 | |
| 1276 | if (dt < 1e-6) |
| 1277 | dt = 1e-6; |
| 1278 | |
| 1279 | move->pre_time = timestamp; |
| 1280 | |
| 1281 | for (ii = 0; ii < 2; ii++) { |
| 1282 | wl_fixed_t prepos = move->pos[ii]; |
| 1283 | move->pos[ii] = pointer[ii] + move->dst[ii]; |
| 1284 | |
| 1285 | if (move->pos[ii] < move->rgn[0][ii]) { |
| 1286 | move->pos[ii] = move->rgn[0][ii]; |
| 1287 | move->dst[ii] = move->pos[ii] - pointer[ii]; |
| 1288 | } else if (move->rgn[1][ii] < move->pos[ii]) { |
| 1289 | move->pos[ii] = move->rgn[1][ii]; |
| 1290 | move->dst[ii] = move->pos[ii] - pointer[ii]; |
| 1291 | } |
| 1292 | |
| 1293 | move->v[ii] = wl_fixed_to_double(move->pos[ii] - prepos) / dt; |
| 1294 | |
| 1295 | if (!move->is_moved && |
| 1296 | 0 < wl_fixed_to_int(move->pos[ii] - move->start_pos[ii])) |
| 1297 | move->is_moved = 1; |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | static void |
| 1302 | layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x, |
| 1303 | wl_fixed_t pos_y) |
| 1304 | { |
| 1305 | int32_t layout_pos_x = 0; |
| 1306 | int32_t layout_pos_y = 0; |
| 1307 | |
| 1308 | layout_pos_x = wl_fixed_to_int(pos_x); |
| 1309 | layout_pos_y = wl_fixed_to_int(pos_y); |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1310 | ivi_controller_interface->layer_set_position(layer, layout_pos_x, layout_pos_y); |
| 1311 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static void |
| 1315 | pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1316 | wl_fixed_t x, wl_fixed_t y) |
| 1317 | { |
| 1318 | struct pointer_move_grab *pnt_move_grab = |
| 1319 | (struct pointer_move_grab *)grab; |
| 1320 | wl_fixed_t pointer_pos[2] = {x, y}; |
| 1321 | |
| 1322 | move_grab_update(&pnt_move_grab->move, pointer_pos); |
| 1323 | layer_set_pos(pnt_move_grab->base.layer, |
| 1324 | pnt_move_grab->move.pos[0], pnt_move_grab->move.pos[1]); |
| 1325 | weston_pointer_move(pnt_move_grab->base.grab.pointer, x, y); |
| 1326 | } |
| 1327 | |
| 1328 | static void |
| 1329 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1330 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
| 1331 | { |
| 1332 | struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; |
| 1333 | |
| 1334 | if (!tch_move_grab->is_active) |
| 1335 | return; |
| 1336 | |
| 1337 | wl_fixed_t pointer_pos[2] = { |
| 1338 | grab->touch->grab_x, |
| 1339 | grab->touch->grab_y |
| 1340 | }; |
| 1341 | |
| 1342 | move_grab_update(&tch_move_grab->move, pointer_pos); |
| 1343 | layer_set_pos(tch_move_grab->base.layer, |
| 1344 | tch_move_grab->move.pos[0], tch_move_grab->move.pos[1]); |
| 1345 | } |
| 1346 | |
| 1347 | static void |
| 1348 | pointer_move_workspace_grab_button(struct weston_pointer_grab *grab, |
| 1349 | uint32_t time, uint32_t button, |
| 1350 | uint32_t state_w) |
| 1351 | { |
| 1352 | if (BTN_LEFT == button && |
| 1353 | WL_POINTER_BUTTON_STATE_RELEASED == state_w) { |
| 1354 | struct pointer_grab *pg = (struct pointer_grab *)grab; |
| 1355 | |
| 1356 | pointer_move_workspace_grab_end(pg); |
| 1357 | free(grab); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | static void |
| 1362 | touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1363 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1364 | { |
| 1365 | } |
| 1366 | |
| 1367 | static void |
| 1368 | touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time, |
| 1369 | int touch_id) |
| 1370 | { |
| 1371 | struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; |
| 1372 | |
| 1373 | if (0 == touch_id) |
| 1374 | tch_move_grab->is_active = 0; |
| 1375 | |
| 1376 | if (0 == grab->touch->num_tp) { |
| 1377 | touch_move_workspace_grab_end(&tch_move_grab->base); |
| 1378 | free(grab); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | static void |
| 1383 | pointer_move_workspace_grab_cancel(struct weston_pointer_grab *grab) |
| 1384 | { |
| 1385 | struct pointer_grab *pg = (struct pointer_grab *)grab; |
| 1386 | |
| 1387 | pointer_move_workspace_grab_end(pg); |
| 1388 | free(grab); |
| 1389 | } |
| 1390 | |
| 1391 | static void |
Nobuhiko Tanibata | 82cc25b | 2015-02-06 16:08:52 +0900 | [diff] [blame^] | 1392 | touch_move_workspace_grab_frame(struct weston_touch_grab *grab) |
| 1393 | { |
| 1394 | } |
| 1395 | |
| 1396 | static void |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1397 | touch_move_workspace_grab_cancel(struct weston_touch_grab *grab) |
| 1398 | { |
| 1399 | struct touch_grab *tg = (struct touch_grab *)grab; |
| 1400 | |
| 1401 | touch_move_workspace_grab_end(tg); |
| 1402 | free(grab); |
| 1403 | } |
| 1404 | |
| 1405 | static const struct weston_pointer_grab_interface pointer_move_grab_workspace_interface = { |
| 1406 | pointer_noop_grab_focus, |
| 1407 | pointer_move_grab_motion, |
| 1408 | pointer_move_workspace_grab_button, |
| 1409 | pointer_move_workspace_grab_cancel |
| 1410 | }; |
| 1411 | |
| 1412 | static const struct weston_touch_grab_interface touch_move_grab_workspace_interface = { |
| 1413 | touch_nope_grab_down, |
| 1414 | touch_move_workspace_grab_up, |
| 1415 | touch_move_grab_motion, |
Nobuhiko Tanibata | 82cc25b | 2015-02-06 16:08:52 +0900 | [diff] [blame^] | 1416 | touch_move_workspace_grab_frame, |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1417 | touch_move_workspace_grab_cancel |
| 1418 | }; |
| 1419 | |
| 1420 | enum HMI_GRAB_DEVICE { |
| 1421 | HMI_GRAB_DEVICE_NONE, |
| 1422 | HMI_GRAB_DEVICE_POINTER, |
| 1423 | HMI_GRAB_DEVICE_TOUCH |
| 1424 | }; |
| 1425 | |
| 1426 | static enum HMI_GRAB_DEVICE |
| 1427 | get_hmi_grab_device(struct weston_seat *seat, uint32_t serial) |
| 1428 | { |
| 1429 | if (seat->pointer && |
| 1430 | seat->pointer->focus && |
| 1431 | seat->pointer->button_count && |
| 1432 | seat->pointer->grab_serial == serial) |
| 1433 | return HMI_GRAB_DEVICE_POINTER; |
| 1434 | |
| 1435 | if (seat->touch && |
| 1436 | seat->touch->focus && |
| 1437 | seat->touch->grab_serial == serial) |
| 1438 | return HMI_GRAB_DEVICE_TOUCH; |
| 1439 | |
| 1440 | return HMI_GRAB_DEVICE_NONE; |
| 1441 | } |
| 1442 | |
| 1443 | static void |
| 1444 | move_grab_init(struct move_grab* move, wl_fixed_t start_pos[2], |
| 1445 | wl_fixed_t grab_pos[2], wl_fixed_t rgn[2][2], |
| 1446 | struct wl_resource* resource) |
| 1447 | { |
| 1448 | clock_gettime(CLOCK_MONOTONIC, &move->start_time); //FIXME |
| 1449 | move->pre_time = move->start_time; |
| 1450 | move->pos[0] = start_pos[0]; |
| 1451 | move->pos[1] = start_pos[1]; |
| 1452 | move->start_pos[0] = start_pos[0]; |
| 1453 | move->start_pos[1] = start_pos[1]; |
| 1454 | move->dst[0] = start_pos[0] - grab_pos[0]; |
| 1455 | move->dst[1] = start_pos[1] - grab_pos[1]; |
| 1456 | memcpy(move->rgn, rgn, sizeof(move->rgn)); |
| 1457 | } |
| 1458 | |
| 1459 | static void |
| 1460 | move_grab_init_workspace(struct move_grab* move, |
| 1461 | wl_fixed_t grab_x, wl_fixed_t grab_y, |
| 1462 | struct wl_resource *resource) |
| 1463 | { |
| 1464 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1465 | struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer; |
| 1466 | int32_t workspace_count = hmi_ctrl->workspace_count; |
| 1467 | int32_t workspace_width = hmi_ctrl->workspace_background_layer.width; |
| 1468 | int32_t layer_pos_x = 0; |
| 1469 | int32_t layer_pos_y = 0; |
| 1470 | wl_fixed_t start_pos[2] = {0}; |
| 1471 | wl_fixed_t rgn[2][2] = {{0}}; |
| 1472 | wl_fixed_t grab_pos[2] = { grab_x, grab_y }; |
| 1473 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1474 | ivi_controller_interface->layer_get_position(layer, &layer_pos_x, &layer_pos_y); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1475 | |
| 1476 | start_pos[0] = wl_fixed_from_int(layer_pos_x); |
| 1477 | start_pos[1] = wl_fixed_from_int(layer_pos_y); |
| 1478 | |
| 1479 | rgn[0][0] = wl_fixed_from_int(-workspace_width * (workspace_count - 1)); |
| 1480 | |
| 1481 | rgn[0][1] = wl_fixed_from_int(0); |
| 1482 | rgn[1][0] = wl_fixed_from_int(0); |
| 1483 | rgn[1][1] = wl_fixed_from_int(0); |
| 1484 | |
| 1485 | move_grab_init(move, start_pos, grab_pos, rgn, resource); |
| 1486 | } |
| 1487 | |
| 1488 | static struct pointer_move_grab * |
| 1489 | create_workspace_pointer_move(struct weston_pointer *pointer, |
| 1490 | struct wl_resource* resource) |
| 1491 | { |
| 1492 | struct pointer_move_grab *pnt_move_grab = |
| 1493 | MEM_ALLOC(sizeof(*pnt_move_grab)); |
| 1494 | |
| 1495 | pnt_move_grab->base.resource = resource; |
| 1496 | move_grab_init_workspace(&pnt_move_grab->move, pointer->grab_x, |
| 1497 | pointer->grab_y, resource); |
| 1498 | |
| 1499 | return pnt_move_grab; |
| 1500 | } |
| 1501 | |
| 1502 | static struct touch_move_grab * |
| 1503 | create_workspace_touch_move(struct weston_touch *touch, |
| 1504 | struct wl_resource* resource) |
| 1505 | { |
| 1506 | struct touch_move_grab *tch_move_grab = |
| 1507 | MEM_ALLOC(sizeof(*tch_move_grab)); |
| 1508 | |
| 1509 | tch_move_grab->base.resource = resource; |
| 1510 | tch_move_grab->is_active = 1; |
| 1511 | move_grab_init_workspace(&tch_move_grab->move, touch->grab_x, |
| 1512 | touch->grab_y, resource); |
| 1513 | |
| 1514 | return tch_move_grab; |
| 1515 | } |
| 1516 | |
| 1517 | static void |
| 1518 | ivi_hmi_controller_workspace_control(struct wl_client *client, |
| 1519 | struct wl_resource *resource, |
| 1520 | struct wl_resource *seat_resource, |
| 1521 | uint32_t serial) |
| 1522 | { |
| 1523 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1524 | struct ivi_layout_layer *layer = NULL; |
| 1525 | struct pointer_move_grab *pnt_move_grab = NULL; |
| 1526 | struct touch_move_grab *tch_move_grab = NULL; |
| 1527 | struct weston_seat *seat = NULL; |
| 1528 | enum HMI_GRAB_DEVICE device; |
| 1529 | |
| 1530 | if (hmi_ctrl->workspace_count < 2) |
| 1531 | return; |
| 1532 | |
| 1533 | seat = wl_resource_get_user_data(seat_resource); |
| 1534 | device = get_hmi_grab_device(seat, serial); |
| 1535 | |
| 1536 | if (HMI_GRAB_DEVICE_POINTER != device && |
| 1537 | HMI_GRAB_DEVICE_TOUCH != device) |
| 1538 | return; |
| 1539 | |
| 1540 | layer = hmi_ctrl->workspace_layer.ivilayer; |
| 1541 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1542 | ivi_controller_interface->transition_move_layer_cancel(layer); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1543 | |
| 1544 | switch (device) { |
| 1545 | case HMI_GRAB_DEVICE_POINTER: |
| 1546 | pnt_move_grab = create_workspace_pointer_move(seat->pointer, |
| 1547 | resource); |
| 1548 | |
| 1549 | pointer_grab_start(&pnt_move_grab->base, layer, |
| 1550 | &pointer_move_grab_workspace_interface, |
| 1551 | seat->pointer); |
| 1552 | break; |
| 1553 | |
| 1554 | case HMI_GRAB_DEVICE_TOUCH: |
| 1555 | tch_move_grab = create_workspace_touch_move(seat->touch, |
| 1556 | resource); |
| 1557 | |
| 1558 | touch_grab_start(&tch_move_grab->base, layer, |
| 1559 | &touch_move_grab_workspace_interface, |
| 1560 | seat->touch); |
| 1561 | break; |
| 1562 | |
| 1563 | default: |
| 1564 | break; |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | /** |
| 1569 | * Implementation of switch_mode |
| 1570 | */ |
| 1571 | static void |
| 1572 | ivi_hmi_controller_switch_mode(struct wl_client *client, |
| 1573 | struct wl_resource *resource, |
| 1574 | uint32_t layout_mode) |
| 1575 | { |
| 1576 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1577 | |
| 1578 | switch_mode(hmi_ctrl, layout_mode); |
| 1579 | } |
| 1580 | |
| 1581 | /** |
| 1582 | * Implementation of on/off displaying workspace and workspace background |
| 1583 | * ivi_layers. |
| 1584 | */ |
| 1585 | static void |
| 1586 | ivi_hmi_controller_home(struct wl_client *client, |
| 1587 | struct wl_resource *resource, |
| 1588 | uint32_t home) |
| 1589 | { |
| 1590 | struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource); |
| 1591 | uint32_t is_fade_in; |
| 1592 | |
| 1593 | if ((IVI_HMI_CONTROLLER_HOME_ON == home && |
| 1594 | !hmi_ctrl->workspace_fade.is_fade_in) || |
| 1595 | (IVI_HMI_CONTROLLER_HOME_OFF == home && |
| 1596 | hmi_ctrl->workspace_fade.is_fade_in)) { |
| 1597 | is_fade_in = !hmi_ctrl->workspace_fade.is_fade_in; |
| 1598 | hmi_controller_fade_run(hmi_ctrl, is_fade_in, |
| 1599 | &hmi_ctrl->workspace_fade); |
| 1600 | } |
| 1601 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1602 | ivi_controller_interface->commit_changes(); |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * binding ivi-hmi-controller implementation |
| 1607 | */ |
| 1608 | static const struct ivi_hmi_controller_interface ivi_hmi_controller_implementation = { |
| 1609 | ivi_hmi_controller_UI_ready, |
| 1610 | ivi_hmi_controller_workspace_control, |
| 1611 | ivi_hmi_controller_switch_mode, |
| 1612 | ivi_hmi_controller_home |
| 1613 | }; |
| 1614 | |
| 1615 | static void |
| 1616 | unbind_hmi_controller(struct wl_resource *resource) |
| 1617 | { |
| 1618 | } |
| 1619 | |
| 1620 | static void |
| 1621 | bind_hmi_controller(struct wl_client *client, |
| 1622 | void *data, uint32_t version, uint32_t id) |
| 1623 | { |
| 1624 | struct wl_resource *resource = NULL; |
| 1625 | struct hmi_controller *hmi_ctrl = data; |
| 1626 | |
| 1627 | if (hmi_ctrl->user_interface != client) { |
| 1628 | struct wl_resource *res = wl_client_get_object(client, 1); |
| 1629 | wl_resource_post_error(res, |
| 1630 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1631 | "hmi-controller failed: permission denied"); |
| 1632 | return; |
| 1633 | } |
| 1634 | |
| 1635 | resource = wl_resource_create( |
| 1636 | client, &ivi_hmi_controller_interface, 1, id); |
| 1637 | |
| 1638 | wl_resource_set_implementation( |
| 1639 | resource, &ivi_hmi_controller_implementation, |
| 1640 | hmi_ctrl, unbind_hmi_controller); |
| 1641 | } |
| 1642 | |
| 1643 | static int32_t |
| 1644 | initialize(struct hmi_controller *hmi_ctrl) |
| 1645 | { |
| 1646 | struct config_command { |
| 1647 | char *key; |
| 1648 | uint32_t *dest; |
| 1649 | }; |
| 1650 | |
| 1651 | struct weston_config *config = hmi_ctrl->compositor->config; |
| 1652 | struct weston_config_section *section = NULL; |
| 1653 | int result = 0; |
| 1654 | int i = 0; |
| 1655 | |
| 1656 | const struct config_command uint_commands[] = { |
| 1657 | { "background-id", &hmi_ctrl->ui_setting.background_id }, |
| 1658 | { "panel-id", &hmi_ctrl->ui_setting.panel_id }, |
| 1659 | { "tiling-id", &hmi_ctrl->ui_setting.tiling_id }, |
| 1660 | { "sidebyside-id", &hmi_ctrl->ui_setting.sidebyside_id }, |
| 1661 | { "fullscreen-id", &hmi_ctrl->ui_setting.fullscreen_id }, |
| 1662 | { "random-id", &hmi_ctrl->ui_setting.random_id }, |
| 1663 | { "home-id", &hmi_ctrl->ui_setting.home_id }, |
| 1664 | { "workspace-background-id", &hmi_ctrl->ui_setting.workspace_background_id }, |
| 1665 | { NULL, NULL } |
| 1666 | }; |
| 1667 | |
| 1668 | section = weston_config_get_section(config, "ivi-shell", NULL, NULL); |
| 1669 | |
| 1670 | for (i = 0; -1 != result; ++i) { |
| 1671 | const struct config_command *command = &uint_commands[i]; |
| 1672 | |
| 1673 | if (!command->key) |
| 1674 | break; |
| 1675 | |
| 1676 | if (weston_config_section_get_uint( |
| 1677 | section, command->key, command->dest, 0) != 0) |
| 1678 | result = -1; |
| 1679 | } |
| 1680 | |
| 1681 | if (-1 == result) { |
| 1682 | weston_log("Failed to initialize hmi-controller\n"); |
| 1683 | return 0; |
| 1684 | } |
| 1685 | |
| 1686 | return 1; |
| 1687 | } |
| 1688 | |
| 1689 | static void |
| 1690 | launch_hmi_client_process(void *data) |
| 1691 | { |
| 1692 | struct hmi_controller *hmi_ctrl = |
| 1693 | (struct hmi_controller *)data; |
| 1694 | |
| 1695 | hmi_ctrl->user_interface = |
| 1696 | weston_client_start(hmi_ctrl->compositor, |
| 1697 | hmi_ctrl->hmi_setting->ivi_homescreen); |
| 1698 | |
| 1699 | free(hmi_ctrl->hmi_setting->ivi_homescreen); |
| 1700 | } |
| 1701 | |
| 1702 | /***************************************************************************** |
| 1703 | * exported functions |
| 1704 | ****************************************************************************/ |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1705 | WL_EXPORT int |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1706 | controller_module_init(struct weston_compositor *ec, |
| 1707 | int *argc, char *argv[], |
| 1708 | const struct ivi_controller_interface *interface, |
| 1709 | size_t interface_version) |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1710 | { |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1711 | struct hmi_controller *hmi_ctrl = NULL; |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1712 | struct wl_event_loop *loop = NULL; |
| 1713 | |
Nobuhiko Tanibata | ee8e583 | 2014-12-15 13:25:39 +0900 | [diff] [blame] | 1714 | if (interface_version < sizeof(struct ivi_controller_interface)) { |
| 1715 | weston_log("ivi-shell: version mismatch of controller interface"); |
| 1716 | return -1; |
| 1717 | } |
| 1718 | |
| 1719 | ivi_controller_interface = interface; |
| 1720 | |
| 1721 | hmi_ctrl = hmi_controller_create(ec); |
| 1722 | |
Nobuhiko Tanibata | 4f6853b | 2014-11-27 13:23:12 +0900 | [diff] [blame] | 1723 | if (!initialize(hmi_ctrl)) { |
| 1724 | return -1; |
| 1725 | } |
| 1726 | |
| 1727 | if (wl_global_create(ec->wl_display, |
| 1728 | &ivi_hmi_controller_interface, 1, |
| 1729 | hmi_ctrl, bind_hmi_controller) == NULL) { |
| 1730 | return -1; |
| 1731 | } |
| 1732 | |
| 1733 | loop = wl_display_get_event_loop(ec->wl_display); |
| 1734 | wl_event_loop_add_idle(loop, launch_hmi_client_process, hmi_ctrl); |
| 1735 | |
| 1736 | return 0; |
| 1737 | } |