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