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