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