Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 DENSO CORPORATION |
| 3 | * |
Bryce Harrington | 1f6b0d1 | 2015-06-10 22:48:59 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 10 | * |
Bryce Harrington | 1f6b0d1 | 2015-06-10 22:48:59 -0700 | [diff] [blame] | 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 22 | */ |
| 23 | |
Yong-iL Joh | cd9bb71 | 2015-11-17 16:28:11 +0900 | [diff] [blame] | 24 | #include "config.h" |
| 25 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 26 | #include <sys/wait.h> |
| 27 | #include <unistd.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
| 31 | #include <linux/input.h> |
| 32 | #include <assert.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <signal.h> |
| 35 | #include <sys/mman.h> |
| 36 | #include <getopt.h> |
| 37 | #include <wayland-cursor.h> |
Bill Spitzak | 2ccd9a2 | 2015-08-06 16:24:59 +0100 | [diff] [blame] | 38 | #include <wayland-client-protocol.h> |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 39 | #include "shared/cairo-util.h" |
| 40 | #include "shared/config-parser.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 41 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 42 | #include "shared/os-compatibility.h" |
Bryce Harrington | e99e4bf | 2016-03-16 14:15:18 -0700 | [diff] [blame] | 43 | #include "shared/xalloc.h" |
Bryce Harrington | 0d1a622 | 2016-02-11 16:42:49 -0800 | [diff] [blame] | 44 | #include "shared/zalloc.h" |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 45 | #include "ivi-application-client-protocol.h" |
| 46 | #include "ivi-hmi-controller-client-protocol.h" |
| 47 | |
| 48 | /** |
| 49 | * A reference implementation how to use ivi-hmi-controller interface to |
| 50 | * interact with hmi-controller. This is launched from hmi-controller by using |
| 51 | * hmi_client_start and create a pthread. |
| 52 | * |
| 53 | * The basic flow is as followed, |
| 54 | * 1/ read configuration from weston.ini. |
| 55 | * 2/ draw png file to surface according to configuration of weston.ini |
| 56 | * 3/ set up UI by using ivi-hmi-controller protocol |
| 57 | * 4/ Enter event loop |
| 58 | * 5/ If a surface receives touch/pointer event, followings are invoked |
| 59 | * according to type of event and surface |
| 60 | * 5-1/ If a surface to launch ivi_application receive touch up, it execs |
| 61 | * ivi-application configured in weston.ini. |
| 62 | * 5-2/ If a surface to switch layout mode receive touch up, it sends a request, |
| 63 | * ivi_hmi_controller_switch_mode, to hmi-controller. |
| 64 | * 5-3/ If a surface to show workspace having launchers, it sends a request, |
| 65 | * ivi_hmi_controller_home, to hmi-controller. |
| 66 | * 5-4/ If touch down events happens in workspace, |
| 67 | * ivi_hmi_controller_workspace_control is sent to slide workspace. |
| 68 | * When control finished, event: ivi_hmi_controller_workspace_end_control |
| 69 | * is received. |
| 70 | */ |
| 71 | |
| 72 | /***************************************************************************** |
| 73 | * structure, globals |
| 74 | ****************************************************************************/ |
| 75 | enum cursor_type { |
| 76 | CURSOR_BOTTOM_LEFT, |
| 77 | CURSOR_BOTTOM_RIGHT, |
| 78 | CURSOR_BOTTOM, |
| 79 | CURSOR_DRAGGING, |
| 80 | CURSOR_LEFT_PTR, |
| 81 | CURSOR_LEFT, |
| 82 | CURSOR_RIGHT, |
| 83 | CURSOR_TOP_LEFT, |
| 84 | CURSOR_TOP_RIGHT, |
| 85 | CURSOR_TOP, |
| 86 | CURSOR_IBEAM, |
| 87 | CURSOR_HAND1, |
| 88 | CURSOR_WATCH, |
| 89 | |
| 90 | CURSOR_BLANK |
| 91 | }; |
| 92 | struct wlContextCommon { |
| 93 | struct wl_display *wlDisplay; |
| 94 | struct wl_registry *wlRegistry; |
| 95 | struct wl_compositor *wlCompositor; |
| 96 | struct wl_shm *wlShm; |
| 97 | uint32_t formats; |
| 98 | struct wl_seat *wlSeat; |
| 99 | struct wl_pointer *wlPointer; |
| 100 | struct wl_touch *wlTouch; |
| 101 | struct ivi_application *iviApplication; |
| 102 | struct ivi_hmi_controller *hmiCtrl; |
| 103 | struct hmi_homescreen_setting *hmi_setting; |
| 104 | struct wl_list list_wlContextStruct; |
| 105 | struct wl_surface *enterSurface; |
| 106 | int32_t is_home_on; |
| 107 | struct wl_cursor_theme *cursor_theme; |
| 108 | struct wl_cursor **cursors; |
| 109 | struct wl_surface *pointer_surface; |
| 110 | enum cursor_type current_cursor; |
| 111 | uint32_t enter_serial; |
| 112 | }; |
| 113 | |
| 114 | struct wlContextStruct { |
| 115 | struct wlContextCommon *cmm; |
| 116 | struct wl_surface *wlSurface; |
| 117 | struct wl_buffer *wlBuffer; |
| 118 | cairo_surface_t *ctx_image; |
| 119 | void *data; |
| 120 | uint32_t id_surface; |
| 121 | struct wl_list link; |
| 122 | }; |
| 123 | |
| 124 | struct |
| 125 | hmi_homescreen_srf { |
| 126 | uint32_t id; |
| 127 | char *filePath; |
| 128 | uint32_t color; |
| 129 | }; |
| 130 | |
| 131 | struct |
| 132 | hmi_homescreen_workspace { |
| 133 | struct wl_array launcher_id_array; |
| 134 | struct wl_list link; |
| 135 | }; |
| 136 | |
| 137 | struct |
| 138 | hmi_homescreen_launcher { |
| 139 | uint32_t icon_surface_id; |
| 140 | uint32_t workspace_id; |
| 141 | char *icon; |
| 142 | char *path; |
| 143 | struct wl_list link; |
| 144 | }; |
| 145 | |
| 146 | struct |
| 147 | hmi_homescreen_setting { |
| 148 | struct hmi_homescreen_srf background; |
| 149 | struct hmi_homescreen_srf panel; |
| 150 | struct hmi_homescreen_srf tiling; |
| 151 | struct hmi_homescreen_srf sidebyside; |
| 152 | struct hmi_homescreen_srf fullscreen; |
| 153 | struct hmi_homescreen_srf random; |
| 154 | struct hmi_homescreen_srf home; |
| 155 | struct hmi_homescreen_srf workspace_background; |
| 156 | |
| 157 | struct wl_list workspace_list; |
| 158 | struct wl_list launcher_list; |
| 159 | |
| 160 | char *cursor_theme; |
| 161 | int32_t cursor_size; |
| 162 | uint32_t transition_duration; |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 163 | uint32_t surface_id_offset; |
| 164 | int32_t screen_num; |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 165 | }; |
| 166 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 167 | /***************************************************************************** |
| 168 | * Event Handler |
| 169 | ****************************************************************************/ |
| 170 | |
| 171 | static void |
| 172 | shm_format(void *data, struct wl_shm *pWlShm, uint32_t format) |
| 173 | { |
| 174 | struct wlContextCommon *pCtx = data; |
| 175 | |
| 176 | pCtx->formats |= (1 << format); |
| 177 | } |
| 178 | |
| 179 | static struct wl_shm_listener shm_listenter = { |
| 180 | shm_format |
| 181 | }; |
| 182 | |
| 183 | static int32_t |
| 184 | getIdOfWlSurface(struct wlContextCommon *pCtx, struct wl_surface *wlSurface) |
| 185 | { |
| 186 | struct wlContextStruct *pWlCtxSt = NULL; |
| 187 | |
| 188 | if (NULL == pCtx || NULL == wlSurface ) |
| 189 | return 0; |
| 190 | |
| 191 | wl_list_for_each(pWlCtxSt, &pCtx->list_wlContextStruct, link) { |
| 192 | if (pWlCtxSt->wlSurface == wlSurface) |
| 193 | return pWlCtxSt->id_surface; |
| 194 | } |
| 195 | |
| 196 | return -1; |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | set_pointer_image(struct wlContextCommon *pCtx, uint32_t index) |
| 201 | { |
| 202 | struct wl_cursor *cursor = NULL; |
| 203 | struct wl_cursor_image *image = NULL; |
| 204 | struct wl_buffer *buffer = NULL; |
| 205 | |
| 206 | if (!pCtx->wlPointer || !pCtx->cursors) |
| 207 | return; |
| 208 | |
| 209 | if (CURSOR_BLANK == pCtx->current_cursor) { |
| 210 | wl_pointer_set_cursor(pCtx->wlPointer, pCtx->enter_serial, |
| 211 | NULL, 0, 0); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | cursor = pCtx->cursors[pCtx->current_cursor]; |
| 216 | if (!cursor) |
| 217 | return; |
| 218 | |
| 219 | if (cursor->image_count <= index) { |
| 220 | fprintf(stderr, "cursor index out of range\n"); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | image = cursor->images[index]; |
| 225 | buffer = wl_cursor_image_get_buffer(image); |
| 226 | |
| 227 | if (!buffer) |
| 228 | return; |
| 229 | |
| 230 | wl_pointer_set_cursor(pCtx->wlPointer, pCtx->enter_serial, |
| 231 | pCtx->pointer_surface, |
| 232 | image->hotspot_x, image->hotspot_y); |
| 233 | |
| 234 | wl_surface_attach(pCtx->pointer_surface, buffer, 0, 0); |
| 235 | |
| 236 | wl_surface_damage(pCtx->pointer_surface, 0, 0, |
| 237 | image->width, image->height); |
| 238 | |
| 239 | wl_surface_commit(pCtx->pointer_surface); |
| 240 | } |
| 241 | |
| 242 | static void |
| 243 | PointerHandleEnter(void *data, struct wl_pointer *wlPointer, uint32_t serial, |
| 244 | struct wl_surface *wlSurface, wl_fixed_t sx, wl_fixed_t sy) |
| 245 | { |
| 246 | struct wlContextCommon *pCtx = data; |
| 247 | |
| 248 | pCtx->enter_serial = serial; |
| 249 | pCtx->enterSurface = wlSurface; |
| 250 | set_pointer_image(pCtx, 0); |
| 251 | #ifdef _DEBUG |
| 252 | printf("ENTER PointerHandleEnter: x(%d), y(%d)\n", sx, sy); |
| 253 | #endif |
| 254 | } |
| 255 | |
| 256 | static void |
| 257 | PointerHandleLeave(void *data, struct wl_pointer *wlPointer, uint32_t serial, |
| 258 | struct wl_surface *wlSurface) |
| 259 | { |
| 260 | struct wlContextCommon *pCtx = data; |
| 261 | |
| 262 | pCtx->enterSurface = NULL; |
| 263 | |
| 264 | #ifdef _DEBUG |
| 265 | printf("ENTER PointerHandleLeave: serial(%d)\n", serial); |
| 266 | #endif |
| 267 | } |
| 268 | |
| 269 | static void |
| 270 | PointerHandleMotion(void *data, struct wl_pointer *wlPointer, uint32_t time, |
| 271 | wl_fixed_t sx, wl_fixed_t sy) |
| 272 | { |
| 273 | #ifdef _DEBUG |
| 274 | printf("ENTER PointerHandleMotion: x(%d), y(%d)\n", sx, sy); |
| 275 | #endif |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * if a surface assigned as launcher receives touch-off event, invoking |
| 280 | * ivi-application which configured in weston.ini with path to binary. |
| 281 | */ |
| 282 | extern char **environ; /*defied by libc */ |
| 283 | |
| 284 | static pid_t |
| 285 | execute_process(char *path, char *argv[]) |
| 286 | { |
| 287 | pid_t pid = fork(); |
| 288 | if (pid < 0) |
| 289 | fprintf(stderr, "Failed to fork\n"); |
| 290 | |
| 291 | if (pid) |
| 292 | return pid; |
| 293 | |
| 294 | if (-1 == execve(path, argv, environ)) { |
| 295 | fprintf(stderr, "Failed to execve %s\n", path); |
| 296 | exit(1); |
| 297 | } |
| 298 | |
| 299 | return pid; |
| 300 | } |
| 301 | |
| 302 | static int32_t |
| 303 | launcher_button(uint32_t surfaceId, struct wl_list *launcher_list) |
| 304 | { |
| 305 | struct hmi_homescreen_launcher *launcher = NULL; |
| 306 | |
| 307 | wl_list_for_each(launcher, launcher_list, link) { |
| 308 | char *argv[] = { NULL }; |
| 309 | |
| 310 | if (surfaceId != launcher->icon_surface_id) |
| 311 | continue; |
| 312 | |
| 313 | execute_process(launcher->path, argv); |
| 314 | |
| 315 | return 1; |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * is-method to identify a surface set as launcher in workspace or workspace |
| 323 | * itself. This is-method is used to decide whether request; |
| 324 | * ivi_hmi_controller_workspace_control is sent or not. |
| 325 | */ |
| 326 | static int32_t |
| 327 | isWorkspaceSurface(uint32_t id, struct hmi_homescreen_setting *hmi_setting) |
| 328 | { |
| 329 | struct hmi_homescreen_launcher *launcher = NULL; |
| 330 | |
| 331 | if (id == hmi_setting->workspace_background.id) |
| 332 | return 1; |
| 333 | |
| 334 | wl_list_for_each(launcher, &hmi_setting->launcher_list, link) { |
| 335 | if (id == launcher->icon_surface_id) |
| 336 | return 1; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Decide which request is sent to hmi-controller |
| 344 | */ |
| 345 | static void |
| 346 | touch_up(struct ivi_hmi_controller *hmi_ctrl, uint32_t id_surface, |
| 347 | int32_t *is_home_on, struct hmi_homescreen_setting *hmi_setting) |
| 348 | { |
| 349 | if (launcher_button(id_surface, &hmi_setting->launcher_list)) { |
| 350 | *is_home_on = 0; |
| 351 | ivi_hmi_controller_home(hmi_ctrl, IVI_HMI_CONTROLLER_HOME_OFF); |
| 352 | } else if (id_surface == hmi_setting->tiling.id) { |
| 353 | ivi_hmi_controller_switch_mode(hmi_ctrl, |
| 354 | IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING); |
| 355 | } else if (id_surface == hmi_setting->sidebyside.id) { |
| 356 | ivi_hmi_controller_switch_mode(hmi_ctrl, |
| 357 | IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE); |
| 358 | } else if (id_surface == hmi_setting->fullscreen.id) { |
| 359 | ivi_hmi_controller_switch_mode(hmi_ctrl, |
| 360 | IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN); |
| 361 | } else if (id_surface == hmi_setting->random.id) { |
| 362 | ivi_hmi_controller_switch_mode(hmi_ctrl, |
| 363 | IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM); |
| 364 | } else if (id_surface == hmi_setting->home.id) { |
| 365 | *is_home_on = !(*is_home_on); |
| 366 | if (*is_home_on) { |
| 367 | ivi_hmi_controller_home(hmi_ctrl, |
| 368 | IVI_HMI_CONTROLLER_HOME_ON); |
| 369 | } else { |
| 370 | ivi_hmi_controller_home(hmi_ctrl, |
| 371 | IVI_HMI_CONTROLLER_HOME_OFF); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Even handler of Pointer event. IVI system is usually manipulated by touch |
| 378 | * screen. However, some systems also have pointer device. |
| 379 | * Release is the same behavior as touch off |
| 380 | * Pressed is the same behavior as touch on |
| 381 | */ |
| 382 | static void |
| 383 | PointerHandleButton(void *data, struct wl_pointer *wlPointer, uint32_t serial, |
| 384 | uint32_t time, uint32_t button, uint32_t state) |
| 385 | { |
| 386 | struct wlContextCommon *pCtx = data; |
| 387 | struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl; |
| 388 | const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface); |
| 389 | |
| 390 | if (BTN_RIGHT == button) |
| 391 | return; |
| 392 | |
| 393 | switch (state) { |
| 394 | case WL_POINTER_BUTTON_STATE_RELEASED: |
| 395 | touch_up(hmi_ctrl, id_surface, &pCtx->is_home_on, |
| 396 | pCtx->hmi_setting); |
| 397 | break; |
| 398 | |
| 399 | case WL_POINTER_BUTTON_STATE_PRESSED: |
| 400 | |
| 401 | if (isWorkspaceSurface(id_surface, pCtx->hmi_setting)) { |
| 402 | ivi_hmi_controller_workspace_control(hmi_ctrl, |
| 403 | pCtx->wlSeat, |
| 404 | serial); |
| 405 | } |
| 406 | |
| 407 | break; |
| 408 | } |
| 409 | #ifdef _DEBUG |
| 410 | printf("ENTER PointerHandleButton: button(%d), state(%d)\n", |
| 411 | button, state); |
| 412 | #endif |
| 413 | } |
| 414 | |
| 415 | static void |
| 416 | PointerHandleAxis(void *data, struct wl_pointer *wlPointer, uint32_t time, |
| 417 | uint32_t axis, wl_fixed_t value) |
| 418 | { |
| 419 | #ifdef _DEBUG |
| 420 | printf("ENTER PointerHandleAxis: axis(%d), value(%d)\n", axis, value); |
| 421 | #endif |
| 422 | } |
| 423 | |
| 424 | static struct wl_pointer_listener pointer_listener = { |
| 425 | PointerHandleEnter, |
| 426 | PointerHandleLeave, |
| 427 | PointerHandleMotion, |
| 428 | PointerHandleButton, |
| 429 | PointerHandleAxis |
| 430 | }; |
| 431 | |
| 432 | /** |
| 433 | * Even handler of touch event |
| 434 | */ |
| 435 | static void |
| 436 | TouchHandleDown(void *data, struct wl_touch *wlTouch, uint32_t serial, |
| 437 | uint32_t time, struct wl_surface *surface, int32_t id, |
| 438 | wl_fixed_t x_w, wl_fixed_t y_w) |
| 439 | { |
| 440 | struct wlContextCommon *pCtx = data; |
| 441 | struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl; |
| 442 | uint32_t id_surface = 0; |
| 443 | |
| 444 | if (0 == id) |
| 445 | pCtx->enterSurface = surface; |
| 446 | |
| 447 | id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface); |
| 448 | |
| 449 | /** |
| 450 | * When touch down happens on surfaces of workspace, ask |
| 451 | * hmi-controller to start control workspace to select page of |
| 452 | * workspace. After sending seat to hmi-controller by |
| 453 | * ivi_hmi_controller_workspace_control, |
| 454 | * hmi-controller-homescreen doesn't receive any event till |
| 455 | * hmi-controller sends back it. |
| 456 | */ |
| 457 | if (isWorkspaceSurface(id_surface, pCtx->hmi_setting)) { |
| 458 | ivi_hmi_controller_workspace_control(hmi_ctrl, pCtx->wlSeat, |
| 459 | serial); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | static void |
| 464 | TouchHandleUp(void *data, struct wl_touch *wlTouch, uint32_t serial, |
| 465 | uint32_t time, int32_t id) |
| 466 | { |
| 467 | struct wlContextCommon *pCtx = data; |
| 468 | struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl; |
| 469 | |
| 470 | const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface); |
| 471 | |
| 472 | /** |
| 473 | * triggering event according to touch-up happening on which surface. |
| 474 | */ |
| 475 | if (id == 0){ |
| 476 | touch_up(hmi_ctrl, id_surface, &pCtx->is_home_on, |
| 477 | pCtx->hmi_setting); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | static void |
| 482 | TouchHandleMotion(void *data, struct wl_touch *wlTouch, uint32_t time, |
| 483 | int32_t id, wl_fixed_t x_w, wl_fixed_t y_w) |
| 484 | { |
| 485 | } |
| 486 | |
| 487 | static void |
| 488 | TouchHandleFrame(void *data, struct wl_touch *wlTouch) |
| 489 | { |
| 490 | } |
| 491 | |
| 492 | static void |
| 493 | TouchHandleCancel(void *data, struct wl_touch *wlTouch) |
| 494 | { |
| 495 | } |
| 496 | |
| 497 | static struct wl_touch_listener touch_listener = { |
| 498 | TouchHandleDown, |
| 499 | TouchHandleUp, |
| 500 | TouchHandleMotion, |
| 501 | TouchHandleFrame, |
| 502 | TouchHandleCancel, |
| 503 | }; |
| 504 | |
| 505 | /** |
| 506 | * Handler of capabilities |
| 507 | */ |
| 508 | static void |
| 509 | seat_handle_capabilities(void *data, struct wl_seat *seat, uint32_t caps) |
| 510 | { |
| 511 | struct wlContextCommon *p_wlCtx = (struct wlContextCommon*)data; |
| 512 | struct wl_seat *wlSeat = p_wlCtx->wlSeat; |
| 513 | struct wl_pointer *wlPointer = p_wlCtx->wlPointer; |
| 514 | struct wl_touch *wlTouch = p_wlCtx->wlTouch; |
| 515 | |
| 516 | if (p_wlCtx->hmi_setting->cursor_theme) { |
| 517 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wlPointer){ |
| 518 | wlPointer = wl_seat_get_pointer(wlSeat); |
| 519 | wl_pointer_add_listener(wlPointer, |
| 520 | &pointer_listener, data); |
| 521 | } else |
| 522 | if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wlPointer){ |
| 523 | wl_pointer_destroy(wlPointer); |
| 524 | wlPointer = NULL; |
| 525 | } |
| 526 | p_wlCtx->wlPointer = wlPointer; |
| 527 | } |
| 528 | |
| 529 | if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !wlTouch){ |
| 530 | wlTouch = wl_seat_get_touch(wlSeat); |
| 531 | wl_touch_add_listener(wlTouch, &touch_listener, data); |
| 532 | } else |
| 533 | if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && wlTouch){ |
| 534 | wl_touch_destroy(wlTouch); |
| 535 | wlTouch = NULL; |
| 536 | } |
| 537 | p_wlCtx->wlTouch = wlTouch; |
| 538 | } |
| 539 | |
| 540 | static struct wl_seat_listener seat_Listener = { |
| 541 | seat_handle_capabilities, |
| 542 | }; |
| 543 | |
| 544 | /** |
| 545 | * Registration of event |
| 546 | * This event is received when hmi-controller server finished controlling |
| 547 | * workspace. |
| 548 | */ |
| 549 | static void |
| 550 | ivi_hmi_controller_workspace_end_control(void *data, |
| 551 | struct ivi_hmi_controller *hmi_ctrl, |
| 552 | int32_t is_controlled) |
| 553 | { |
| 554 | struct wlContextCommon *pCtx = data; |
| 555 | const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface); |
| 556 | |
| 557 | if (is_controlled) |
| 558 | return; |
| 559 | |
| 560 | /** |
| 561 | * During being controlled by hmi-controller, any input event is not |
| 562 | * notified. So when control ends with touch up, it invokes launcher |
| 563 | * if up event happens on a launcher surface. |
| 564 | * |
| 565 | */ |
| 566 | if (launcher_button(id_surface, &pCtx->hmi_setting->launcher_list)) { |
| 567 | pCtx->is_home_on = 0; |
| 568 | ivi_hmi_controller_home(hmi_ctrl, IVI_HMI_CONTROLLER_HOME_OFF); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static const struct ivi_hmi_controller_listener hmi_controller_listener = { |
| 573 | ivi_hmi_controller_workspace_end_control |
| 574 | }; |
| 575 | |
| 576 | /** |
| 577 | * Registration of interfaces |
| 578 | */ |
| 579 | static void |
| 580 | registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, |
| 581 | const char *interface, uint32_t version) |
| 582 | { |
| 583 | struct wlContextCommon *p_wlCtx = (struct wlContextCommon*)data; |
| 584 | |
| 585 | if (!strcmp(interface, "wl_compositor")) { |
| 586 | p_wlCtx->wlCompositor = |
| 587 | wl_registry_bind(registry, name, |
| 588 | &wl_compositor_interface, 1); |
| 589 | } else if (!strcmp(interface, "wl_shm")) { |
| 590 | p_wlCtx->wlShm = |
| 591 | wl_registry_bind(registry, name, &wl_shm_interface, 1); |
| 592 | wl_shm_add_listener(p_wlCtx->wlShm, &shm_listenter, p_wlCtx); |
| 593 | } else if (!strcmp(interface, "wl_seat")) { |
| 594 | p_wlCtx->wlSeat = |
| 595 | wl_registry_bind(registry, name, &wl_seat_interface, 1); |
| 596 | wl_seat_add_listener(p_wlCtx->wlSeat, &seat_Listener, data); |
| 597 | } else if (!strcmp(interface, "ivi_application")) { |
| 598 | p_wlCtx->iviApplication = |
| 599 | wl_registry_bind(registry, name, |
| 600 | &ivi_application_interface, 1); |
| 601 | } else if (!strcmp(interface, "ivi_hmi_controller")) { |
| 602 | p_wlCtx->hmiCtrl = |
| 603 | wl_registry_bind(registry, name, |
| 604 | &ivi_hmi_controller_interface, 1); |
| 605 | |
| 606 | ivi_hmi_controller_add_listener(p_wlCtx->hmiCtrl, |
| 607 | &hmi_controller_listener, p_wlCtx); |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 608 | } else if (!strcmp(interface, "wl_output")) { |
| 609 | p_wlCtx->hmi_setting->screen_num++; |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
| 613 | static void |
| 614 | registry_handle_global_remove(void *data, struct wl_registry *registry, |
| 615 | uint32_t name) |
| 616 | { |
| 617 | } |
| 618 | |
| 619 | static const struct wl_registry_listener registry_listener = { |
| 620 | registry_handle_global, |
| 621 | registry_handle_global_remove |
| 622 | }; |
| 623 | |
| 624 | static void |
| 625 | frame_listener_func(void *data, struct wl_callback *callback, uint32_t time) |
| 626 | { |
| 627 | if (callback) |
| 628 | wl_callback_destroy(callback); |
| 629 | } |
| 630 | |
| 631 | static const struct wl_callback_listener frame_listener = { |
| 632 | frame_listener_func |
| 633 | }; |
| 634 | |
| 635 | /* |
| 636 | * The following correspondences between file names and cursors was copied |
| 637 | * from: https://bugs.kde.org/attachment.cgi?id=67313 |
| 638 | */ |
| 639 | static const char *bottom_left_corners[] = { |
| 640 | "bottom_left_corner", |
| 641 | "sw-resize", |
| 642 | "size_bdiag" |
| 643 | }; |
| 644 | |
| 645 | static const char *bottom_right_corners[] = { |
| 646 | "bottom_right_corner", |
| 647 | "se-resize", |
| 648 | "size_fdiag" |
| 649 | }; |
| 650 | |
| 651 | static const char *bottom_sides[] = { |
| 652 | "bottom_side", |
| 653 | "s-resize", |
| 654 | "size_ver" |
| 655 | }; |
| 656 | |
| 657 | static const char *grabbings[] = { |
| 658 | "grabbing", |
| 659 | "closedhand", |
| 660 | "208530c400c041818281048008011002" |
| 661 | }; |
| 662 | |
| 663 | static const char *left_ptrs[] = { |
| 664 | "left_ptr", |
| 665 | "default", |
| 666 | "top_left_arrow", |
| 667 | "left-arrow" |
| 668 | }; |
| 669 | |
| 670 | static const char *left_sides[] = { |
| 671 | "left_side", |
| 672 | "w-resize", |
| 673 | "size_hor" |
| 674 | }; |
| 675 | |
| 676 | static const char *right_sides[] = { |
| 677 | "right_side", |
| 678 | "e-resize", |
| 679 | "size_hor" |
| 680 | }; |
| 681 | |
| 682 | static const char *top_left_corners[] = { |
| 683 | "top_left_corner", |
| 684 | "nw-resize", |
| 685 | "size_fdiag" |
| 686 | }; |
| 687 | |
| 688 | static const char *top_right_corners[] = { |
| 689 | "top_right_corner", |
| 690 | "ne-resize", |
| 691 | "size_bdiag" |
| 692 | }; |
| 693 | |
| 694 | static const char *top_sides[] = { |
| 695 | "top_side", |
| 696 | "n-resize", |
| 697 | "size_ver" |
| 698 | }; |
| 699 | |
| 700 | static const char *xterms[] = { |
| 701 | "xterm", |
| 702 | "ibeam", |
| 703 | "text" |
| 704 | }; |
| 705 | |
| 706 | static const char *hand1s[] = { |
| 707 | "hand1", |
| 708 | "pointer", |
| 709 | "pointing_hand", |
| 710 | "e29285e634086352946a0e7090d73106" |
| 711 | }; |
| 712 | |
| 713 | static const char *watches[] = { |
| 714 | "watch", |
| 715 | "wait", |
| 716 | "0426c94ea35c87780ff01dc239897213" |
| 717 | }; |
| 718 | |
| 719 | struct cursor_alternatives { |
| 720 | const char **names; |
| 721 | size_t count; |
| 722 | }; |
| 723 | |
| 724 | static const struct cursor_alternatives cursors[] = { |
| 725 | { bottom_left_corners, ARRAY_LENGTH(bottom_left_corners) }, |
| 726 | { bottom_right_corners, ARRAY_LENGTH(bottom_right_corners) }, |
| 727 | { bottom_sides, ARRAY_LENGTH(bottom_sides) }, |
| 728 | { grabbings, ARRAY_LENGTH(grabbings) }, |
| 729 | { left_ptrs, ARRAY_LENGTH(left_ptrs) }, |
| 730 | { left_sides, ARRAY_LENGTH(left_sides) }, |
| 731 | { right_sides, ARRAY_LENGTH(right_sides) }, |
| 732 | { top_left_corners, ARRAY_LENGTH(top_left_corners) }, |
| 733 | { top_right_corners, ARRAY_LENGTH(top_right_corners) }, |
| 734 | { top_sides, ARRAY_LENGTH(top_sides) }, |
| 735 | { xterms, ARRAY_LENGTH(xterms) }, |
| 736 | { hand1s, ARRAY_LENGTH(hand1s) }, |
| 737 | { watches, ARRAY_LENGTH(watches) }, |
| 738 | }; |
| 739 | |
| 740 | static void |
| 741 | create_cursors(struct wlContextCommon *cmm) |
| 742 | { |
| 743 | uint32_t i = 0; |
| 744 | uint32_t j = 0; |
| 745 | struct wl_cursor *cursor = NULL; |
| 746 | char *cursor_theme = cmm->hmi_setting->cursor_theme; |
| 747 | int32_t cursor_size = cmm->hmi_setting->cursor_size; |
| 748 | |
| 749 | cmm->cursor_theme = wl_cursor_theme_load(cursor_theme, cursor_size, |
| 750 | cmm->wlShm); |
| 751 | |
| 752 | cmm->cursors = |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 753 | xzalloc(ARRAY_LENGTH(cursors) * sizeof(cmm->cursors[0])); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 754 | |
| 755 | for (i = 0; i < ARRAY_LENGTH(cursors); i++) { |
| 756 | cursor = NULL; |
| 757 | |
| 758 | for (j = 0; !cursor && j < cursors[i].count; ++j) { |
| 759 | cursor = wl_cursor_theme_get_cursor( |
| 760 | cmm->cursor_theme, cursors[i].names[j]); |
| 761 | } |
| 762 | |
| 763 | if (!cursor) { |
| 764 | fprintf(stderr, "could not load cursor '%s'\n", |
| 765 | cursors[i].names[0]); |
| 766 | } |
| 767 | |
| 768 | cmm->cursors[i] = cursor; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | static void |
| 773 | destroy_cursors(struct wlContextCommon *cmm) |
| 774 | { |
| 775 | if (cmm->cursor_theme) |
| 776 | wl_cursor_theme_destroy(cmm->cursor_theme); |
| 777 | |
| 778 | free(cmm->cursors); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Internal method to prepare parts of UI |
| 783 | */ |
| 784 | static void |
| 785 | createShmBuffer(struct wlContextStruct *p_wlCtx) |
| 786 | { |
| 787 | struct wl_shm_pool *pool; |
| 788 | |
| 789 | int fd = -1; |
| 790 | int size = 0; |
| 791 | int width = 0; |
| 792 | int height = 0; |
| 793 | int stride = 0; |
| 794 | |
| 795 | width = cairo_image_surface_get_width(p_wlCtx->ctx_image); |
| 796 | height = cairo_image_surface_get_height(p_wlCtx->ctx_image); |
| 797 | stride = cairo_image_surface_get_stride(p_wlCtx->ctx_image); |
| 798 | |
| 799 | size = stride * height; |
| 800 | |
| 801 | fd = os_create_anonymous_file(size); |
| 802 | if (fd < 0) { |
| 803 | fprintf(stderr, "creating a buffer file for %d B failed: %m\n", |
| 804 | size); |
| 805 | return ; |
| 806 | } |
| 807 | |
| 808 | p_wlCtx->data = |
| 809 | mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 810 | |
| 811 | if (MAP_FAILED == p_wlCtx->data) { |
| 812 | fprintf(stderr, "mmap failed: %m\n"); |
| 813 | close(fd); |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | pool = wl_shm_create_pool(p_wlCtx->cmm->wlShm, fd, size); |
| 818 | p_wlCtx->wlBuffer = wl_shm_pool_create_buffer(pool, 0, |
| 819 | width, |
| 820 | height, |
| 821 | stride, |
| 822 | WL_SHM_FORMAT_ARGB8888); |
| 823 | |
| 824 | if (NULL == p_wlCtx->wlBuffer) { |
| 825 | fprintf(stderr, "wl_shm_create_buffer failed: %m\n"); |
| 826 | close(fd); |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | wl_shm_pool_destroy(pool); |
| 831 | close(fd); |
| 832 | } |
| 833 | |
| 834 | static void |
| 835 | destroyWLContextCommon(struct wlContextCommon *p_wlCtx) |
| 836 | { |
| 837 | destroy_cursors(p_wlCtx); |
| 838 | |
| 839 | if (p_wlCtx->pointer_surface) |
| 840 | wl_surface_destroy(p_wlCtx->pointer_surface); |
| 841 | |
| 842 | if (p_wlCtx->wlCompositor) |
| 843 | wl_compositor_destroy(p_wlCtx->wlCompositor); |
| 844 | } |
| 845 | |
| 846 | static void |
| 847 | destroyWLContextStruct(struct wlContextStruct *p_wlCtx) |
| 848 | { |
| 849 | if (p_wlCtx->wlSurface) |
| 850 | wl_surface_destroy(p_wlCtx->wlSurface); |
| 851 | |
| 852 | if (p_wlCtx->ctx_image) { |
| 853 | cairo_surface_destroy(p_wlCtx->ctx_image); |
| 854 | p_wlCtx->ctx_image = NULL; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | static int |
| 859 | createSurface(struct wlContextStruct *p_wlCtx) |
| 860 | { |
| 861 | p_wlCtx->wlSurface = |
| 862 | wl_compositor_create_surface(p_wlCtx->cmm->wlCompositor); |
| 863 | if (NULL == p_wlCtx->wlSurface) { |
| 864 | printf("Error: wl_compositor_create_surface failed.\n"); |
| 865 | destroyWLContextCommon(p_wlCtx->cmm); |
| 866 | abort(); |
| 867 | } |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | static void |
| 873 | drawImage(struct wlContextStruct *p_wlCtx) |
| 874 | { |
| 875 | struct wl_callback *callback; |
| 876 | |
| 877 | int width = 0; |
| 878 | int height = 0; |
| 879 | int stride = 0; |
| 880 | void *data = NULL; |
| 881 | |
| 882 | width = cairo_image_surface_get_width(p_wlCtx->ctx_image); |
| 883 | height = cairo_image_surface_get_height(p_wlCtx->ctx_image); |
| 884 | stride = cairo_image_surface_get_stride(p_wlCtx->ctx_image); |
| 885 | data = cairo_image_surface_get_data(p_wlCtx->ctx_image); |
| 886 | |
| 887 | memcpy(p_wlCtx->data, data, stride * height); |
| 888 | |
| 889 | wl_surface_attach(p_wlCtx->wlSurface, p_wlCtx->wlBuffer, 0, 0); |
| 890 | wl_surface_damage(p_wlCtx->wlSurface, 0, 0, width, height); |
| 891 | |
| 892 | callback = wl_surface_frame(p_wlCtx->wlSurface); |
| 893 | wl_callback_add_listener(callback, &frame_listener, NULL); |
| 894 | |
| 895 | wl_surface_commit(p_wlCtx->wlSurface); |
| 896 | } |
| 897 | |
| 898 | static void |
| 899 | create_ivisurface(struct wlContextStruct *p_wlCtx, |
| 900 | uint32_t id_surface, |
| 901 | cairo_surface_t *surface) |
| 902 | { |
| 903 | struct ivi_surface *ivisurf = NULL; |
| 904 | |
| 905 | p_wlCtx->ctx_image = surface; |
| 906 | |
| 907 | p_wlCtx->id_surface = id_surface; |
| 908 | wl_list_init(&p_wlCtx->link); |
| 909 | wl_list_insert(&p_wlCtx->cmm->list_wlContextStruct, &p_wlCtx->link); |
| 910 | |
| 911 | createSurface(p_wlCtx); |
| 912 | createShmBuffer(p_wlCtx); |
| 913 | |
| 914 | ivisurf = ivi_application_surface_create(p_wlCtx->cmm->iviApplication, |
| 915 | id_surface, |
| 916 | p_wlCtx->wlSurface); |
| 917 | if (ivisurf == NULL) { |
| 918 | fprintf(stderr, "Failed to create ivi_client_surface\n"); |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | drawImage(p_wlCtx); |
| 923 | } |
| 924 | |
| 925 | static void |
| 926 | create_ivisurfaceFromFile(struct wlContextStruct *p_wlCtx, |
| 927 | uint32_t id_surface, |
| 928 | const char *imageFile) |
| 929 | { |
| 930 | cairo_surface_t *surface = load_cairo_surface(imageFile); |
| 931 | |
| 932 | if (NULL == surface) { |
| 933 | fprintf(stderr, "Failed to load_cairo_surface %s\n", imageFile); |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | create_ivisurface(p_wlCtx, id_surface, surface); |
| 938 | } |
| 939 | |
| 940 | static void |
| 941 | set_hex_color(cairo_t *cr, uint32_t color) |
| 942 | { |
| 943 | cairo_set_source_rgba(cr, |
| 944 | ((color >> 16) & 0xff) / 255.0, |
| 945 | ((color >> 8) & 0xff) / 255.0, |
| 946 | ((color >> 0) & 0xff) / 255.0, |
| 947 | ((color >> 24) & 0xff) / 255.0); |
| 948 | } |
| 949 | |
| 950 | static void |
| 951 | create_ivisurfaceFromColor(struct wlContextStruct *p_wlCtx, |
| 952 | uint32_t id_surface, |
| 953 | uint32_t width, uint32_t height, |
| 954 | uint32_t color) |
| 955 | { |
| 956 | cairo_surface_t *surface = NULL; |
| 957 | cairo_t *cr = NULL; |
| 958 | |
| 959 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 960 | width, height); |
| 961 | |
| 962 | cr = cairo_create(surface); |
| 963 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 964 | cairo_rectangle(cr, 0, 0, width, height); |
| 965 | set_hex_color(cr, color); |
| 966 | cairo_fill(cr); |
| 967 | cairo_destroy(cr); |
| 968 | |
| 969 | create_ivisurface(p_wlCtx, id_surface, surface); |
| 970 | } |
| 971 | |
| 972 | static void |
| 973 | UI_ready(struct ivi_hmi_controller *controller) |
| 974 | { |
| 975 | ivi_hmi_controller_UI_ready(controller); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * Internal method to set up UI by using ivi-hmi-controller |
| 980 | */ |
| 981 | static void |
| 982 | create_background(struct wlContextStruct *p_wlCtx, const uint32_t id_surface, |
| 983 | const char *imageFile) |
| 984 | { |
| 985 | create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile); |
| 986 | } |
| 987 | |
| 988 | static void |
| 989 | create_panel(struct wlContextStruct *p_wlCtx, const uint32_t id_surface, |
| 990 | const char *imageFile) |
| 991 | { |
| 992 | create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile); |
| 993 | } |
| 994 | |
| 995 | static void |
| 996 | create_button(struct wlContextStruct *p_wlCtx, const uint32_t id_surface, |
| 997 | const char *imageFile, uint32_t number) |
| 998 | { |
| 999 | create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile); |
| 1000 | } |
| 1001 | |
| 1002 | static void |
| 1003 | create_home_button(struct wlContextStruct *p_wlCtx, const uint32_t id_surface, |
| 1004 | const char *imageFile) |
| 1005 | { |
| 1006 | create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile); |
| 1007 | } |
| 1008 | |
| 1009 | static void |
| 1010 | create_workspace_background(struct wlContextStruct *p_wlCtx, |
| 1011 | struct hmi_homescreen_srf *srf) |
| 1012 | { |
| 1013 | create_ivisurfaceFromColor(p_wlCtx, srf->id, 1, 1, srf->color); |
| 1014 | } |
| 1015 | |
| 1016 | static void |
| 1017 | create_launchers(struct wlContextCommon *cmm, struct wl_list *launcher_list) |
| 1018 | { |
| 1019 | struct hmi_homescreen_launcher **launchers; |
| 1020 | struct hmi_homescreen_launcher *launcher = NULL; |
| 1021 | |
| 1022 | int launcher_count = wl_list_length(launcher_list); |
| 1023 | int ii = 0; |
| 1024 | int start = 0; |
| 1025 | |
| 1026 | if (0 == launcher_count) |
| 1027 | return; |
| 1028 | |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 1029 | launchers = xzalloc(launcher_count * sizeof(*launchers)); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1030 | |
| 1031 | wl_list_for_each(launcher, launcher_list, link) { |
| 1032 | launchers[ii] = launcher; |
| 1033 | ii++; |
| 1034 | } |
| 1035 | |
| 1036 | for (ii = 0; ii < launcher_count; ii++) { |
| 1037 | int jj = 0; |
| 1038 | |
| 1039 | if (ii != launcher_count - 1 && |
| 1040 | launchers[ii]->workspace_id == |
| 1041 | launchers[ii + 1]->workspace_id) |
| 1042 | continue; |
| 1043 | |
| 1044 | for (jj = start; jj <= ii; jj++) { |
| 1045 | struct wlContextStruct *p_wlCtx; |
| 1046 | |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 1047 | p_wlCtx = xzalloc(sizeof(*p_wlCtx)); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1048 | p_wlCtx->cmm = cmm; |
| 1049 | create_ivisurfaceFromFile(p_wlCtx, |
| 1050 | launchers[jj]->icon_surface_id, |
| 1051 | launchers[jj]->icon); |
| 1052 | } |
| 1053 | |
| 1054 | start = ii + 1; |
| 1055 | } |
| 1056 | |
| 1057 | free(launchers); |
| 1058 | } |
| 1059 | |
| 1060 | /** |
| 1061 | * Internal method to read out weston.ini to get configuration |
| 1062 | */ |
| 1063 | static struct hmi_homescreen_setting * |
| 1064 | hmi_homescreen_setting_create(void) |
| 1065 | { |
Pekka Paalanen | 6c71aae | 2015-03-24 15:56:19 +0200 | [diff] [blame] | 1066 | const char *config_file; |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1067 | struct weston_config *config = NULL; |
| 1068 | struct weston_config_section *shellSection = NULL; |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 1069 | struct hmi_homescreen_setting *setting = xzalloc(sizeof(*setting)); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1070 | struct weston_config_section *section = NULL; |
| 1071 | const char *name = NULL; |
| 1072 | uint32_t workspace_layer_id; |
| 1073 | uint32_t icon_surface_id = 0; |
| 1074 | |
| 1075 | wl_list_init(&setting->workspace_list); |
| 1076 | wl_list_init(&setting->launcher_list); |
| 1077 | |
Pekka Paalanen | 6c71aae | 2015-03-24 15:56:19 +0200 | [diff] [blame] | 1078 | config_file = weston_config_get_name_from_env(); |
| 1079 | config = weston_config_parse(config_file); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1080 | |
| 1081 | shellSection = |
| 1082 | weston_config_get_section(config, "ivi-shell", NULL, NULL); |
| 1083 | |
| 1084 | weston_config_section_get_string( |
| 1085 | shellSection, "cursor-theme", &setting->cursor_theme, NULL); |
| 1086 | |
| 1087 | weston_config_section_get_int( |
| 1088 | shellSection, "cursor-size", &setting->cursor_size, 32); |
| 1089 | |
| 1090 | weston_config_section_get_uint( |
| 1091 | shellSection, "workspace-layer-id", &workspace_layer_id, 3000); |
| 1092 | |
| 1093 | weston_config_section_get_string( |
| 1094 | shellSection, "background-image", &setting->background.filePath, |
| 1095 | DATADIR "/weston/background.png"); |
| 1096 | |
| 1097 | weston_config_section_get_uint( |
| 1098 | shellSection, "background-id", &setting->background.id, 1001); |
| 1099 | |
| 1100 | weston_config_section_get_string( |
| 1101 | shellSection, "panel-image", &setting->panel.filePath, |
| 1102 | DATADIR "/weston/panel.png"); |
| 1103 | |
| 1104 | weston_config_section_get_uint( |
| 1105 | shellSection, "panel-id", &setting->panel.id, 1002); |
| 1106 | |
| 1107 | weston_config_section_get_string( |
| 1108 | shellSection, "tiling-image", &setting->tiling.filePath, |
| 1109 | DATADIR "/weston/tiling.png"); |
| 1110 | |
| 1111 | weston_config_section_get_uint( |
| 1112 | shellSection, "tiling-id", &setting->tiling.id, 1003); |
| 1113 | |
| 1114 | weston_config_section_get_string( |
| 1115 | shellSection, "sidebyside-image", &setting->sidebyside.filePath, |
| 1116 | DATADIR "/weston/sidebyside.png"); |
| 1117 | |
| 1118 | weston_config_section_get_uint( |
| 1119 | shellSection, "sidebyside-id", &setting->sidebyside.id, 1004); |
| 1120 | |
| 1121 | weston_config_section_get_string( |
| 1122 | shellSection, "fullscreen-image", &setting->fullscreen.filePath, |
| 1123 | DATADIR "/weston/fullscreen.png"); |
| 1124 | |
| 1125 | weston_config_section_get_uint( |
| 1126 | shellSection, "fullscreen-id", &setting->fullscreen.id, 1005); |
| 1127 | |
| 1128 | weston_config_section_get_string( |
| 1129 | shellSection, "random-image", &setting->random.filePath, |
| 1130 | DATADIR "/weston/random.png"); |
| 1131 | |
| 1132 | weston_config_section_get_uint( |
| 1133 | shellSection, "random-id", &setting->random.id, 1006); |
| 1134 | |
| 1135 | weston_config_section_get_string( |
| 1136 | shellSection, "home-image", &setting->home.filePath, |
| 1137 | DATADIR "/weston/home.png"); |
| 1138 | |
| 1139 | weston_config_section_get_uint( |
| 1140 | shellSection, "home-id", &setting->home.id, 1007); |
| 1141 | |
| 1142 | weston_config_section_get_uint( |
| 1143 | shellSection, "workspace-background-color", |
| 1144 | &setting->workspace_background.color, 0x99000000); |
| 1145 | |
| 1146 | weston_config_section_get_uint( |
| 1147 | shellSection, "workspace-background-id", |
| 1148 | &setting->workspace_background.id, 2001); |
| 1149 | |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1150 | weston_config_section_get_uint( |
| 1151 | shellSection, "surface-id-offset", &setting->surface_id_offset, 10); |
| 1152 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1153 | icon_surface_id = workspace_layer_id + 1; |
| 1154 | |
| 1155 | while (weston_config_next_section(config, §ion, &name)) { |
| 1156 | struct hmi_homescreen_launcher *launcher; |
| 1157 | |
| 1158 | if (strcmp(name, "ivi-launcher") != 0) |
| 1159 | continue; |
| 1160 | |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 1161 | launcher = xzalloc(sizeof(*launcher)); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1162 | wl_list_init(&launcher->link); |
| 1163 | |
| 1164 | weston_config_section_get_string(section, "icon", |
| 1165 | &launcher->icon, NULL); |
| 1166 | weston_config_section_get_string(section, "path", |
| 1167 | &launcher->path, NULL); |
| 1168 | weston_config_section_get_uint(section, "workspace-id", |
| 1169 | &launcher->workspace_id, 0); |
| 1170 | weston_config_section_get_uint(section, "icon-id", |
| 1171 | &launcher->icon_surface_id, |
| 1172 | icon_surface_id); |
| 1173 | icon_surface_id++; |
| 1174 | |
| 1175 | wl_list_insert(setting->launcher_list.prev, &launcher->link); |
| 1176 | } |
| 1177 | |
| 1178 | weston_config_destroy(config); |
| 1179 | return setting; |
| 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * Main thread |
| 1184 | * |
| 1185 | * The basic flow are as followed, |
| 1186 | * 1/ read configuration from weston.ini by hmi_homescreen_setting_create |
| 1187 | * 2/ draw png file to surface according to configuration of weston.ini and |
| 1188 | * set up UI by using ivi-hmi-controller protocol by each create_* method |
| 1189 | */ |
| 1190 | int main(int argc, char **argv) |
| 1191 | { |
| 1192 | struct wlContextCommon wlCtxCommon; |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1193 | struct wlContextStruct *wlCtx_BackGround; |
| 1194 | struct wlContextStruct *wlCtx_Panel; |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1195 | struct wlContextStruct wlCtx_Button_1; |
| 1196 | struct wlContextStruct wlCtx_Button_2; |
| 1197 | struct wlContextStruct wlCtx_Button_3; |
| 1198 | struct wlContextStruct wlCtx_Button_4; |
| 1199 | struct wlContextStruct wlCtx_HomeButton; |
| 1200 | struct wlContextStruct wlCtx_WorkSpaceBackGround; |
| 1201 | struct wl_list launcher_wlCtxList; |
| 1202 | int ret = 0; |
| 1203 | struct hmi_homescreen_setting *hmi_setting; |
| 1204 | struct wlContextStruct *pWlCtxSt = NULL; |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1205 | int i = 0; |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1206 | |
| 1207 | hmi_setting = hmi_homescreen_setting_create(); |
| 1208 | |
| 1209 | memset(&wlCtxCommon, 0x00, sizeof(wlCtxCommon)); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1210 | memset(&wlCtx_Button_1, 0x00, sizeof(wlCtx_Button_1)); |
| 1211 | memset(&wlCtx_Button_2, 0x00, sizeof(wlCtx_Button_2)); |
| 1212 | memset(&wlCtx_Button_3, 0x00, sizeof(wlCtx_Button_3)); |
| 1213 | memset(&wlCtx_Button_4, 0x00, sizeof(wlCtx_Button_4)); |
| 1214 | memset(&wlCtx_HomeButton, 0x00, sizeof(wlCtx_HomeButton)); |
| 1215 | memset(&wlCtx_WorkSpaceBackGround, 0x00, |
| 1216 | sizeof(wlCtx_WorkSpaceBackGround)); |
| 1217 | wl_list_init(&launcher_wlCtxList); |
| 1218 | wl_list_init(&wlCtxCommon.list_wlContextStruct); |
| 1219 | |
| 1220 | wlCtxCommon.hmi_setting = hmi_setting; |
| 1221 | |
| 1222 | wlCtxCommon.wlDisplay = wl_display_connect(NULL); |
| 1223 | if (NULL == wlCtxCommon.wlDisplay) { |
| 1224 | printf("Error: wl_display_connect failed.\n"); |
| 1225 | return -1; |
| 1226 | } |
| 1227 | |
| 1228 | /* get wl_registry */ |
| 1229 | wlCtxCommon.formats = 0; |
| 1230 | wlCtxCommon.wlRegistry = wl_display_get_registry(wlCtxCommon.wlDisplay); |
| 1231 | wl_registry_add_listener(wlCtxCommon.wlRegistry, |
| 1232 | ®istry_listener, &wlCtxCommon); |
| 1233 | wl_display_roundtrip(wlCtxCommon.wlDisplay); |
| 1234 | |
| 1235 | if (wlCtxCommon.wlShm == NULL) { |
| 1236 | fprintf(stderr, "No wl_shm global\n"); |
| 1237 | exit(1); |
| 1238 | } |
| 1239 | |
| 1240 | wl_display_roundtrip(wlCtxCommon.wlDisplay); |
| 1241 | |
| 1242 | if (!(wlCtxCommon.formats & (1 << WL_SHM_FORMAT_XRGB8888))) { |
| 1243 | fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n"); |
| 1244 | exit(1); |
| 1245 | } |
| 1246 | |
Bryce Harrington | 720e0c9 | 2016-03-16 14:15:20 -0700 | [diff] [blame] | 1247 | wlCtx_BackGround = xzalloc(hmi_setting->screen_num * sizeof(struct wlContextStruct)); |
| 1248 | wlCtx_Panel= xzalloc(hmi_setting->screen_num * sizeof(struct wlContextStruct)); |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1249 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1250 | if (wlCtxCommon.hmi_setting->cursor_theme) { |
| 1251 | create_cursors(&wlCtxCommon); |
| 1252 | |
| 1253 | wlCtxCommon.pointer_surface = |
| 1254 | wl_compositor_create_surface(wlCtxCommon.wlCompositor); |
| 1255 | |
| 1256 | wlCtxCommon.current_cursor = CURSOR_LEFT_PTR; |
| 1257 | } |
| 1258 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1259 | wlCtx_Button_1.cmm = &wlCtxCommon; |
| 1260 | wlCtx_Button_2.cmm = &wlCtxCommon; |
| 1261 | wlCtx_Button_3.cmm = &wlCtxCommon; |
| 1262 | wlCtx_Button_4.cmm = &wlCtxCommon; |
| 1263 | wlCtx_HomeButton.cmm = &wlCtxCommon; |
| 1264 | wlCtx_WorkSpaceBackGround.cmm = &wlCtxCommon; |
| 1265 | |
| 1266 | /* create desktop widgets */ |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1267 | for (i = 0; i < hmi_setting->screen_num; i++) { |
| 1268 | wlCtx_BackGround[i].cmm = &wlCtxCommon; |
| 1269 | create_background(&wlCtx_BackGround[i], |
| 1270 | hmi_setting->background.id + |
| 1271 | (i * hmi_setting->surface_id_offset), |
| 1272 | hmi_setting->background.filePath); |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1273 | |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1274 | wlCtx_Panel[i].cmm = &wlCtxCommon; |
| 1275 | create_panel(&wlCtx_Panel[i], |
| 1276 | hmi_setting->panel.id + (i * hmi_setting->surface_id_offset), |
| 1277 | hmi_setting->panel.filePath); |
| 1278 | } |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1279 | |
| 1280 | create_button(&wlCtx_Button_1, hmi_setting->tiling.id, |
| 1281 | hmi_setting->tiling.filePath, 0); |
| 1282 | |
| 1283 | create_button(&wlCtx_Button_2, hmi_setting->sidebyside.id, |
| 1284 | hmi_setting->sidebyside.filePath, 1); |
| 1285 | |
| 1286 | create_button(&wlCtx_Button_3, hmi_setting->fullscreen.id, |
| 1287 | hmi_setting->fullscreen.filePath, 2); |
| 1288 | |
| 1289 | create_button(&wlCtx_Button_4, hmi_setting->random.id, |
| 1290 | hmi_setting->random.filePath, 3); |
| 1291 | |
| 1292 | create_workspace_background(&wlCtx_WorkSpaceBackGround, |
| 1293 | &hmi_setting->workspace_background); |
| 1294 | |
| 1295 | create_launchers(&wlCtxCommon, &hmi_setting->launcher_list); |
| 1296 | |
| 1297 | create_home_button(&wlCtx_HomeButton, hmi_setting->home.id, |
| 1298 | hmi_setting->home.filePath); |
| 1299 | |
| 1300 | UI_ready(wlCtxCommon.hmiCtrl); |
| 1301 | |
Dawid Gajownik | 74a635b | 2015-08-06 17:12:19 -0300 | [diff] [blame] | 1302 | while (ret != -1) |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1303 | ret = wl_display_dispatch(wlCtxCommon.wlDisplay); |
| 1304 | |
| 1305 | wl_list_for_each(pWlCtxSt, &wlCtxCommon.list_wlContextStruct, link) { |
| 1306 | destroyWLContextStruct(pWlCtxSt); |
| 1307 | } |
| 1308 | |
Nobuhiko Tanibata | 2e65676 | 2015-12-09 15:41:46 +0900 | [diff] [blame] | 1309 | free(wlCtx_BackGround); |
| 1310 | free(wlCtx_Panel); |
| 1311 | |
Nobuhiko Tanibata | 923bc14 | 2014-11-27 13:23:32 +0900 | [diff] [blame] | 1312 | destroyWLContextCommon(&wlCtxCommon); |
| 1313 | |
| 1314 | return 0; |
| 1315 | } |