blob: 8da3d3c862103e5d971095f9d31a3aa5c153f74c [file] [log] [blame]
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001/*
2 * Copyright (C) 2014 DENSO CORPORATION
3 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -07004 * 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 Tanibata4f6853b2014-11-27 13:23:12 +090011 *
Bryce Harringtonaf637c22015-06-11 12:55:55 -070012 * 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 Tanibata4f6853b2014-11-27 13:23:12 +090024 */
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 Cruz867d50e2015-06-15 15:37:10 -070063#include "shared/helpers.h"
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090064
65/*****************************************************************************
66 * structure, globals
67 ****************************************************************************/
68struct hmi_controller_layer {
69 struct ivi_layout_layer *ivilayer;
70 uint32_t id_layer;
71 int32_t x;
72 int32_t y;
73 int32_t width;
74 int32_t height;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +090075 struct wl_list link;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090076};
77
78struct link_layer {
79 struct ivi_layout_layer *layout_layer;
80 struct wl_list link;
81};
82
83struct hmi_controller_fade {
84 uint32_t is_fade_in;
85 struct wl_list layer_list;
86};
87
88struct hmi_server_setting {
89 uint32_t base_layer_id;
90 uint32_t application_layer_id;
91 uint32_t workspace_background_layer_id;
92 uint32_t workspace_layer_id;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +090093 uint32_t base_layer_id_offset;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090094 int32_t panel_height;
95 uint32_t transition_duration;
96 char *ivi_homescreen;
97};
98
99struct ui_setting {
100 uint32_t background_id;
101 uint32_t panel_id;
102 uint32_t tiling_id;
103 uint32_t sidebyside_id;
104 uint32_t fullscreen_id;
105 uint32_t random_id;
106 uint32_t home_id;
107 uint32_t workspace_background_id;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900108 uint32_t surface_id_offset;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900109};
110
111struct hmi_controller {
112 struct hmi_server_setting *hmi_setting;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900113 /* List of struct hmi_controller_layer */
114 struct wl_list base_layer_list;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900115 struct wl_list application_layer_list;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900116 struct hmi_controller_layer workspace_background_layer;
117 struct hmi_controller_layer workspace_layer;
118 enum ivi_hmi_controller_layout_mode layout_mode;
119
120 struct hmi_controller_fade workspace_fade;
121
122 int32_t workspace_count;
123 struct wl_array ui_widgets;
124 int32_t is_initialized;
125
126 struct weston_compositor *compositor;
127 struct wl_listener destroy_listener;
128
129 struct wl_client *user_interface;
130 struct ui_setting ui_setting;
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900131
132 int32_t screen_num;
133 struct ivi_layout_screen **pp_screen;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900134};
135
136struct launcher_info {
137 uint32_t surface_id;
138 uint32_t workspace_id;
139 int32_t index;
140};
141
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000142const struct ivi_layout_interface *ivi_layout_interface;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900143
144int
145controller_module_init(struct weston_compositor *ec,
146 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000147 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900148 size_t interface_version);
149
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900150/*****************************************************************************
151 * local functions
152 ****************************************************************************/
153static void *
154fail_on_null(void *p, size_t size, char *file, int32_t line)
155{
156 if (size && !p) {
157 weston_log("%s(%d) %zd: out of memory\n", file, line, size);
158 exit(EXIT_FAILURE);
159 }
160
161 return p;
162}
163
164static void *
165mem_alloc(size_t size, char *file, int32_t line)
166{
167 return fail_on_null(calloc(1, size), size, file, line);
168}
169
170#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
171
172static int32_t
173is_surf_in_ui_widget(struct hmi_controller *hmi_ctrl,
174 struct ivi_layout_surface *ivisurf)
175{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000176 uint32_t id = ivi_layout_interface->get_id_of_surface(ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900177
178 uint32_t *ui_widget_id = NULL;
179 wl_array_for_each(ui_widget_id, &hmi_ctrl->ui_widgets) {
180 if (*ui_widget_id == id)
181 return 1;
182 }
183
184 return 0;
185}
186
187static int
188compare_launcher_info(const void *lhs, const void *rhs)
189{
190 const struct launcher_info *left = lhs;
191 const struct launcher_info *right = rhs;
192
193 if (left->workspace_id < right->workspace_id)
194 return -1;
195
196 if (left->workspace_id > right->workspace_id)
197 return 1;
198
199 if (left->index < right->index)
200 return -1;
201
202 if (left->index > right->index)
203 return 1;
204
205 return 0;
206}
207
208/**
209 * Internal methods called by mainly ivi_hmi_controller_switch_mode
210 * This reference shows 4 examples how to use ivi_layout APIs.
211 */
212static void
213mode_divided_into_tiling(struct hmi_controller *hmi_ctrl,
214 struct ivi_layout_surface **pp_surface,
215 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900216 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900217{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900218 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900219 const float surface_width = (float)layer->width * 0.25;
220 const float surface_height = (float)layer->height * 0.5;
221 int32_t surface_x = 0;
222 int32_t surface_y = 0;
223 struct ivi_layout_surface *ivisurf = NULL;
224 struct ivi_layout_surface **surfaces;
225 struct ivi_layout_surface **new_order;
226 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900227 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900228
229 int32_t i = 0;
230 int32_t surf_num = 0;
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900231 int32_t idx = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900232
233 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
234 new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
235
236 for (i = 0; i < surface_length; i++) {
237 ivisurf = pp_surface[i];
238
239 /* skip ui widgets */
240 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
241 continue;
242
243 surfaces[surf_num++] = ivisurf;
244 }
245
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900246 wl_list_for_each_reverse(layer, layer_list, link) {
247 if (idx >= surf_num)
248 break;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900249
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900250 ivilayer = layer->ivilayer;
251
252 for (i = 0; i < 8; i++, idx++) {
253 if (idx >= surf_num)
254 break;
255
256 ivisurf = surfaces[idx];
257 new_order[i] = ivisurf;
258 if (i < 4) {
259 surface_x = (int32_t)(i * (surface_width));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900260 surface_y = 0;
261 } else {
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900262 surface_x = (int32_t)((i - 4) * (surface_width));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900263 surface_y = (int32_t)surface_height;
264 }
265
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000266 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900267 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
268 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000269 ivi_layout_interface->surface_set_visibility(ivisurf, true);
270 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900271 surface_x, surface_y,
272 (int32_t)surface_width,
273 (int32_t)surface_height);
274
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900275 }
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900276 ivi_layout_interface->layer_set_render_order(ivilayer, new_order, i);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900277
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900278 ivi_layout_interface->layer_set_transition(ivilayer,
279 IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER,
280 duration);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900281 }
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900282 for (i = idx; i < surf_num; i++)
283 ivi_layout_interface->surface_set_visibility(surfaces[i], false);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900284
285 free(surfaces);
286 free(new_order);
287}
288
289static void
290mode_divided_into_sidebyside(struct hmi_controller *hmi_ctrl,
291 struct ivi_layout_surface **pp_surface,
292 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900293 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900294{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900295 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900296 int32_t surface_width = layer->width / 2;
297 int32_t surface_height = layer->height;
298 struct ivi_layout_surface *ivisurf = NULL;
299
300 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
301 int32_t i = 0;
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900302 struct ivi_layout_surface **surfaces;
303 struct ivi_layout_surface **new_order;
304 struct ivi_layout_layer *ivilayer = NULL;
305 int32_t surf_num = 0;
306 int32_t idx = 0;
307
308 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
309 new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900310
311 for (i = 0; i < surface_length; i++) {
312 ivisurf = pp_surface[i];
313
314 /* skip ui widgets */
315 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
316 continue;
317
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900318 surfaces[surf_num++] = ivisurf;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900319 }
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900320
321 wl_list_for_each_reverse(layer, layer_list, link) {
322 if (idx >= surf_num)
323 break;
324
325 ivilayer = layer->ivilayer;
326
327 for (i = 0; i < 2; i++, idx++) {
328 if (idx >= surf_num)
329 break;
330
331 ivisurf = surfaces[idx];
332 new_order[i] = ivisurf;
333
334 ivi_layout_interface->surface_set_transition(ivisurf,
335 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
336 duration);
337 ivi_layout_interface->surface_set_visibility(ivisurf, true);
338
339 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
340 i * surface_width, 0,
341 surface_width,
342 surface_height);
343 }
344 ivi_layout_interface->layer_set_render_order(ivilayer, new_order, i);
345 }
346
347 for (i = idx; i < surf_num; i++) {
348 ivi_layout_interface->surface_set_transition(surfaces[i],
349 IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY,
350 duration);
351 ivi_layout_interface->surface_set_visibility(surfaces[i], false);
352 }
353
354 free(surfaces);
355 free(new_order);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900356}
357
358static void
359mode_fullscreen_someone(struct hmi_controller *hmi_ctrl,
360 struct ivi_layout_surface **pp_surface,
361 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900362 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900363{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900364 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900365 const int32_t surface_width = layer->width;
366 const int32_t surface_height = layer->height;
367 struct ivi_layout_surface *ivisurf = NULL;
368 int32_t i = 0;
369 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900370 int32_t surf_num = 0;
371 struct ivi_layout_surface **surfaces;
372
373 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900374
375 for (i = 0; i < surface_length; i++) {
376 ivisurf = pp_surface[i];
377
378 /* skip ui widgets */
379 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
380 continue;
381
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900382 surfaces[surf_num++] = ivisurf;
383 }
384 ivi_layout_interface->layer_set_render_order(layer->ivilayer, surfaces, surf_num);
385
386 for (i = 0; i < surf_num; i++) {
387 ivisurf = surfaces[i];
388
389 if ((i > 0) && (i < hmi_ctrl->screen_num)) {
390 layer = wl_container_of(layer->link.prev, layer, link);
391 ivi_layout_interface->layer_set_render_order(layer->ivilayer, &ivisurf, 1);
392 }
393
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000394 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900395 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
396 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000397 ivi_layout_interface->surface_set_visibility(ivisurf, true);
398 ivi_layout_interface->surface_set_destination_rectangle(ivisurf, 0, 0,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900399 surface_width,
400 surface_height);
401 }
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900402
403 free(surfaces);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900404}
405
406static void
407mode_random_replace(struct hmi_controller *hmi_ctrl,
408 struct ivi_layout_surface **pp_surface,
409 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900410 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900411{
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900412 struct hmi_controller_layer *application_layer = NULL;
413 struct hmi_controller_layer **layers = NULL;
414 int32_t surface_width = 0;
415 int32_t surface_height = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900416 int32_t surface_x = 0;
417 int32_t surface_y = 0;
418 struct ivi_layout_surface *ivisurf = NULL;
419 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
420 int32_t i = 0;
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900421 int32_t layer_idx = 0;
422
423 layers = MEM_ALLOC(sizeof(*layers) * hmi_ctrl->screen_num);
424
425 wl_list_for_each(application_layer, layer_list, link) {
426 layers[layer_idx] = application_layer;
427 ivi_layout_interface->layer_set_render_order(layers[layer_idx]->ivilayer,
428 NULL, 0);
429 layer_idx++;
430 }
431
432 /*
433 * This commit change is needed because ivisurface can not belongs to several layers
434 * at the same time. So ivisurfaces shall be removed from layers once and then set them
435 * to layers randomly.
436 */
437 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900438
439 for (i = 0; i < surface_length; i++) {
440 ivisurf = pp_surface[i];
441
442 /* skip ui widgets */
443 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
444 continue;
445
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900446 /* surface determined at random a layer that belongs */
447 layer_idx = rand() % hmi_ctrl->screen_num;
448
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000449 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900450 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
451 duration);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900452
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000453 ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900454
455 surface_width = (int32_t)(layers[layer_idx]->width * 0.25f);
456 surface_height = (int32_t)(layers[layer_idx]->height * 0.25f);
457 surface_x = rand() % (layers[layer_idx]->width - surface_width);
458 surface_y = rand() % (layers[layer_idx]->height - surface_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900459
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000460 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900461 surface_x,
462 surface_y,
463 surface_width,
464 surface_height);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900465
466 ivi_layout_interface->layer_add_surface(layers[layer_idx]->ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900467 }
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900468
469 free(layers);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900470}
471
472static int32_t
473has_application_surface(struct hmi_controller *hmi_ctrl,
474 struct ivi_layout_surface **pp_surface,
475 int32_t surface_length)
476{
477 struct ivi_layout_surface *ivisurf = NULL;
478 int32_t i = 0;
479
480 for (i = 0; i < surface_length; i++) {
481 ivisurf = pp_surface[i];
482
483 /* skip ui widgets */
484 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
485 continue;
486
487 return 1;
488 }
489
490 return 0;
491}
492
493/**
494 * Supports 4 example to layout of application ivi_surfaces;
495 * tiling, side by side, fullscreen, and random.
496 */
497static void
498switch_mode(struct hmi_controller *hmi_ctrl,
499 enum ivi_hmi_controller_layout_mode layout_mode)
500{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900501 struct wl_list *layer = &hmi_ctrl->application_layer_list;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900502 struct ivi_layout_surface **pp_surface = NULL;
503 int32_t surface_length = 0;
504 int32_t ret = 0;
505
506 if (!hmi_ctrl->is_initialized)
507 return;
508
509 hmi_ctrl->layout_mode = layout_mode;
510
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000511 ret = ivi_layout_interface->get_surfaces(&surface_length, &pp_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900512 assert(!ret);
513
514 if (!has_application_surface(hmi_ctrl, pp_surface, surface_length)) {
515 free(pp_surface);
516 pp_surface = NULL;
517 return;
518 }
519
520 switch (layout_mode) {
521 case IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING:
522 mode_divided_into_tiling(hmi_ctrl, pp_surface, surface_length,
523 layer);
524 break;
525 case IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE:
526 mode_divided_into_sidebyside(hmi_ctrl, pp_surface,
527 surface_length, layer);
528 break;
529 case IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN:
530 mode_fullscreen_someone(hmi_ctrl, pp_surface, surface_length,
531 layer);
532 break;
533 case IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM:
534 mode_random_replace(hmi_ctrl, pp_surface, surface_length,
535 layer);
536 break;
537 }
538
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000539 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900540 free(pp_surface);
541}
542
543/**
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900544 * Internal method to get screens from weston core
545 * TODO: shall support hotplug of screens
546 */
547static int32_t
548get_screens(struct hmi_controller *hmi_ctrl)
549{
550 hmi_ctrl->pp_screen = NULL;
551 hmi_ctrl->screen_num = 0;
552 ivi_layout_interface->get_screens(&hmi_ctrl->screen_num, &hmi_ctrl->pp_screen);
553
554 if (hmi_ctrl->pp_screen == NULL)
555 return -1;
556 else
557 return 0;
558}
559
560/**
561 * Internal method to get ivi_layout_screen
562 */
563static struct ivi_layout_screen *
564get_screen(int32_t screen_idx, struct hmi_controller *hmi_ctrl)
565{
566 struct ivi_layout_screen *iviscrn = NULL;
567
568 if (screen_idx > hmi_ctrl->screen_num - 1)
569 weston_log("Invalid index. Return NULL\n");
570 else
571 iviscrn = hmi_ctrl->pp_screen[screen_idx];
572
573 return iviscrn;
574}
575
576/**
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900577 * Internal method for transition
578 */
579static void
580hmi_controller_fade_run(struct hmi_controller *hmi_ctrl, uint32_t is_fade_in,
581 struct hmi_controller_fade *fade)
582{
583 double tint = is_fade_in ? 1.0 : 0.0;
584 struct link_layer *linklayer = NULL;
585 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
586
587 fade->is_fade_in = is_fade_in;
588
589 wl_list_for_each(linklayer, &fade->layer_list, link) {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000590 ivi_layout_interface->layer_set_transition(linklayer->layout_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900591 IVI_LAYOUT_TRANSITION_LAYER_FADE,
592 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000593 ivi_layout_interface->layer_set_fade_info(linklayer->layout_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900594 is_fade_in, 1.0 - tint, tint);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900595 }
596}
597
598/**
599 * Internal method to create ivi_layer with hmi_controller_layer and
600 * add to a ivi_screen
601 */
602static void
603create_layer(struct ivi_layout_screen *iviscrn,
604 struct hmi_controller_layer *layer)
605{
606 int32_t ret = 0;
607
608 layer->ivilayer =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000609 ivi_layout_interface->layer_create_with_dimension(layer->id_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900610 layer->width,
611 layer->height);
612 assert(layer->ivilayer != NULL);
613
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000614 ret = ivi_layout_interface->screen_add_layer(iviscrn, layer->ivilayer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900615 assert(!ret);
616
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000617 ret = ivi_layout_interface->layer_set_destination_rectangle(layer->ivilayer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900618 layer->x, layer->y,
619 layer->width,
620 layer->height);
621 assert(!ret);
622
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000623 ret = ivi_layout_interface->layer_set_visibility(layer->ivilayer, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900624 assert(!ret);
625}
626
627/**
628 * Internal set notification
629 */
630static void
631set_notification_create_surface(struct ivi_layout_surface *ivisurf,
632 void *userdata)
633{
634 struct hmi_controller *hmi_ctrl = userdata;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900635 struct hmi_controller_layer *layer_link =
636 wl_container_of(hmi_ctrl->application_layer_list.prev,
637 layer_link,
638 link);
639 struct ivi_layout_layer *application_layer = layer_link->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900640 int32_t ret = 0;
641
642 /* skip ui widgets */
643 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
644 return;
645
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000646 ret = ivi_layout_interface->layer_add_surface(application_layer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900647 assert(!ret);
648}
649
650static void
651set_notification_remove_surface(struct ivi_layout_surface *ivisurf,
652 void *userdata)
653{
654 struct hmi_controller *hmi_ctrl = userdata;
655
656 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
657}
658
659static void
660set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
661 void *userdata)
662{
663 struct hmi_controller *hmi_ctrl = userdata;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900664 struct hmi_controller_layer *layer_link = NULL;
665 struct ivi_layout_layer *application_layer = NULL;
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900666 struct weston_surface *surface;
667 struct ivi_layout_surface **ivisurfs;
668 int32_t length = 0;
669 int32_t i;
670
671 /* return if the surface is not application content */
672 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) {
673 return;
674 }
675
676 /*
677 * if application changes size of wl_buffer. The source rectangle shall be
678 * fit to the size.
679 */
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000680 surface = ivi_layout_interface->surface_get_weston_surface(ivisurf);
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900681 if (surface) {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000682 ivi_layout_interface->surface_set_source_rectangle(
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900683 ivisurf, 0, 0, surface->width,
684 surface->height);
685 }
686
687 /*
688 * search if the surface is already added to layer.
689 * If not yet, it is newly invoded application to go to switch_mode.
690 */
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900691 wl_list_for_each_reverse(layer_link, &hmi_ctrl->application_layer_list, link) {
692 application_layer = layer_link->ivilayer;
693 ivi_layout_interface->get_surfaces_on_layer(application_layer,
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900694 &length, &ivisurfs);
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900695 for (i = 0; i < length; i++) {
696 if (ivisurf == ivisurfs[i]) {
697 /*
698 * if it is non new invoked application, just call
699 * commit_changes to apply source_rectangle.
700 */
701 ivi_layout_interface->commit_changes();
702 return;
703 }
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900704 }
705 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900706
707 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
708}
709
710/**
711 * A hmi_controller used 4 ivi_layers to manage ivi_surfaces. The IDs of
712 * corresponding ivi_layer are defined in weston.ini. Default scene graph
713 * of ivi_layers are initialized in hmi_controller_create
714 */
715static struct hmi_server_setting *
716hmi_server_setting_create(struct weston_compositor *ec)
717{
718 struct hmi_server_setting *setting = MEM_ALLOC(sizeof(*setting));
719 struct weston_config *config = ec->config;
720 struct weston_config_section *shell_section = NULL;
721
722 shell_section = weston_config_get_section(config, "ivi-shell",
723 NULL, NULL);
724
725 weston_config_section_get_uint(shell_section, "base-layer-id",
726 &setting->base_layer_id, 1000);
727
728 weston_config_section_get_uint(shell_section,
729 "workspace-background-layer-id",
730 &setting->workspace_background_layer_id,
731 2000);
732
733 weston_config_section_get_uint(shell_section, "workspace-layer-id",
734 &setting->workspace_layer_id, 3000);
735
736 weston_config_section_get_uint(shell_section, "application-layer-id",
737 &setting->application_layer_id, 4000);
738
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900739 weston_config_section_get_uint(shell_section, "base-layer-id-offset",
740 &setting->base_layer_id_offset, 10000);
741
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900742 weston_config_section_get_uint(shell_section, "transition-duration",
743 &setting->transition_duration, 300);
744
745 setting->panel_height = 70;
746
747 weston_config_section_get_string(shell_section,
748 "ivi-shell-user-interface",
749 &setting->ivi_homescreen, NULL);
750
751 return setting;
752}
753
754static void
755hmi_controller_destroy(struct wl_listener *listener, void *data)
756{
757 struct link_layer *link = NULL;
758 struct link_layer *next = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900759 struct hmi_controller_layer *ctrl_layer_link = NULL;
760 struct hmi_controller_layer *ctrl_layer_next = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900761 struct hmi_controller *hmi_ctrl =
762 container_of(listener, struct hmi_controller, destroy_listener);
763
764 wl_list_for_each_safe(link, next,
765 &hmi_ctrl->workspace_fade.layer_list, link) {
766 wl_list_remove(&link->link);
767 free(link);
768 }
769
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900770 /* clear base_layer_list */
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900771 wl_list_for_each_safe(ctrl_layer_link, ctrl_layer_next,
772 &hmi_ctrl->base_layer_list, link) {
773 wl_list_remove(&ctrl_layer_link->link);
774 free(ctrl_layer_link);
775 }
776
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900777 /* clear application_layer_list */
778 wl_list_for_each_safe(ctrl_layer_link, ctrl_layer_next,
779 &hmi_ctrl->application_layer_list, link) {
780 wl_list_remove(&ctrl_layer_link->link);
781 free(ctrl_layer_link);
782 }
783
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900784 wl_array_release(&hmi_ctrl->ui_widgets);
785 free(hmi_ctrl->hmi_setting);
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900786 free(hmi_ctrl->pp_screen);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900787 free(hmi_ctrl);
788}
789
790/**
791 * This is a starting method called from module_init.
792 * This sets up scene graph of ivi_layers; base, application, workspace
793 * background, and workspace. These ivi_layers are created/added to
794 * ivi_screen in create_layer
795 *
796 * base: to group ivi_surfaces of panel and background
797 * application: to group ivi_surfaces of ivi_applications
798 * workspace background: to group a ivi_surface of background in workspace
799 * workspace: to group ivi_surfaces for launching ivi_applications
800 *
801 * ivi_layers of workspace background and workspace is set to invisible at
802 * first. The properties of it is updated with animation when
803 * ivi_hmi_controller_home is requested.
804 */
805static struct hmi_controller *
806hmi_controller_create(struct weston_compositor *ec)
807{
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900808 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900809 int32_t screen_width = 0;
810 int32_t screen_height = 0;
811 struct link_layer *tmp_link_layer = NULL;
812 int32_t panel_height = 0;
813 struct hmi_controller *hmi_ctrl = MEM_ALLOC(sizeof(*hmi_ctrl));
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900814 struct hmi_controller_layer *base_layer = NULL;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900815 struct hmi_controller_layer *application_layer = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900816
817 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900818
819 wl_array_init(&hmi_ctrl->ui_widgets);
820 hmi_ctrl->layout_mode = IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING;
821 hmi_ctrl->hmi_setting = hmi_server_setting_create(ec);
822 hmi_ctrl->compositor = ec;
823
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900824 /* TODO: shall support hotplug of screens */
825 if (get_screens(hmi_ctrl) < 0) {
826 weston_log("ivi-shell: Failed to get screens\n");
827 hmi_ctrl = NULL;
828 return hmi_ctrl;
829 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900830
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900831 iviscrn = get_screen(0, hmi_ctrl);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900832
833 /* init base ivi_layer*/
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900834 wl_list_init(&hmi_ctrl->base_layer_list);
835 for (i = 0; i < hmi_ctrl->screen_num; i++) {
836 ivi_layout_interface->get_screen_resolution(get_screen(i, hmi_ctrl),
837 &screen_width,
838 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900839
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900840 base_layer = MEM_ALLOC(1 * sizeof(struct hmi_controller_layer));
841 base_layer->x = 0;
842 base_layer->y = 0;
843 base_layer->width = screen_width;
844 base_layer->height = screen_height;
845 base_layer->id_layer =
846 hmi_ctrl->hmi_setting->base_layer_id +
847 (i * hmi_ctrl->hmi_setting->base_layer_id_offset);
848 wl_list_insert(&hmi_ctrl->base_layer_list, &base_layer->link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900849
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900850 create_layer(get_screen(i, hmi_ctrl), base_layer);
851 }
852
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900853 panel_height = hmi_ctrl->hmi_setting->panel_height;
854
855 /* init application ivi_layer */
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900856 wl_list_init(&hmi_ctrl->application_layer_list);
857 for (i = 0; i < hmi_ctrl->screen_num; i++) {
858 ivi_layout_interface->get_screen_resolution(get_screen(i, hmi_ctrl),
859 &screen_width,
860 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900861
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900862 application_layer = MEM_ALLOC(1 * sizeof(struct hmi_controller_layer));
863 application_layer->x = 0;
864 application_layer->y = 0;
865 application_layer->width = screen_width;
866 application_layer->height = screen_height - panel_height;
867 application_layer->id_layer =
868 hmi_ctrl->hmi_setting->application_layer_id +
869 (i * hmi_ctrl->hmi_setting->base_layer_id_offset);
870 wl_list_insert(&hmi_ctrl->application_layer_list, &application_layer->link);
871
872 create_layer(get_screen(i, hmi_ctrl), application_layer);
873 }
874
875 ivi_layout_interface->get_screen_resolution(iviscrn, &screen_width,
876 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900877
878 /* init workspace background ivi_layer */
879 hmi_ctrl->workspace_background_layer.x = 0;
880 hmi_ctrl->workspace_background_layer.y = 0;
881 hmi_ctrl->workspace_background_layer.width = screen_width;
882 hmi_ctrl->workspace_background_layer.height =
883 screen_height - panel_height;
884
885 hmi_ctrl->workspace_background_layer.id_layer =
886 hmi_ctrl->hmi_setting->workspace_background_layer_id;
887
888 create_layer(iviscrn, &hmi_ctrl->workspace_background_layer);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000889 ivi_layout_interface->layer_set_opacity(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900890 hmi_ctrl->workspace_background_layer.ivilayer, 0);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000891 ivi_layout_interface->layer_set_visibility(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900892 hmi_ctrl->workspace_background_layer.ivilayer, false);
893
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900894
895 wl_list_init(&hmi_ctrl->workspace_fade.layer_list);
896 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900897 tmp_link_layer->layout_layer =
898 hmi_ctrl->workspace_background_layer.ivilayer;
899 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
900 &tmp_link_layer->link);
901
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000902 ivi_layout_interface->add_notification_create_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900903 set_notification_create_surface, hmi_ctrl);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000904 ivi_layout_interface->add_notification_remove_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900905 set_notification_remove_surface, hmi_ctrl);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000906 ivi_layout_interface->add_notification_configure_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900907 set_notification_configure_surface, hmi_ctrl);
908
909 hmi_ctrl->destroy_listener.notify = hmi_controller_destroy;
910 wl_signal_add(&hmi_ctrl->compositor->destroy_signal,
911 &hmi_ctrl->destroy_listener);
912
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900913 return hmi_ctrl;
914}
915
916/**
917 * Implementations of ivi-hmi-controller.xml
918 */
919
920/**
921 * A ivi_surface drawing background is identified by id_surface.
922 * Properties of the ivi_surface is set by using ivi_layout APIs according to
923 * the scene graph of UI defined in hmi_controller_create.
924 *
925 * UI ivi_layer is used to add this ivi_surface.
926 */
927static void
928ivi_hmi_controller_set_background(struct hmi_controller *hmi_ctrl,
929 uint32_t id_surface)
930{
931 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900932 struct hmi_controller_layer *base_layer = NULL;
933 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900934 struct hmi_controller_layer *application_layer =
935 wl_container_of(hmi_ctrl->application_layer_list.prev,
936 application_layer,
937 link);
938 const int32_t dstx = application_layer->x;
939 const int32_t dsty = application_layer->y;
940 const int32_t width = application_layer->width;
941 const int32_t height = application_layer->height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900942 int32_t ret = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900943 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900944
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900945 wl_list_for_each_reverse(base_layer, &hmi_ctrl->base_layer_list, link) {
946 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
947 sizeof(*add_surface_id));
948 *add_surface_id = id_surface + (i * hmi_ctrl->ui_setting.surface_id_offset);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900949
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900950 ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900951
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900952 ivisurf = ivi_layout_interface->get_surface_from_id(*add_surface_id);
953 assert(ivisurf != NULL);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900954
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900955 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
956 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900957
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900958 ret = ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
959 dstx, dsty, width, height);
960 assert(!ret);
961
962 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
963 assert(!ret);
964
965 i++;
966 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900967}
968
969/**
970 * A ivi_surface drawing panel is identified by id_surface.
971 * Properties of the ivi_surface is set by using ivi_layout APIs according to
972 * the scene graph of UI defined in hmi_controller_create.
973 *
974 * UI ivi_layer is used to add this ivi_surface.
975 */
976static void
977ivi_hmi_controller_set_panel(struct hmi_controller *hmi_ctrl,
978 uint32_t id_surface)
979{
980 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900981 struct hmi_controller_layer *base_layer =
982 wl_container_of(hmi_ctrl->base_layer_list.prev,
983 base_layer,
984 link);
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900985 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900986 const int32_t width = base_layer->width;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900987 int32_t ret = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900988 int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900989 const int32_t dstx = 0;
990 int32_t dsty = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900991 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900992
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900993 wl_list_for_each_reverse(base_layer, &hmi_ctrl->base_layer_list, link) {
994 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
995 sizeof(*add_surface_id));
996 *add_surface_id = id_surface + (i * hmi_ctrl->ui_setting.surface_id_offset);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900997
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900998 ivilayer = base_layer->ivilayer;
999 ivisurf = ivi_layout_interface->get_surface_from_id(*add_surface_id);
1000 assert(ivisurf != NULL);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001001
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001002 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
1003 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001004
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001005 dsty = base_layer->height - panel_height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001006
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001007 ret = ivi_layout_interface->surface_set_destination_rectangle(
1008 ivisurf, dstx, dsty, width, panel_height);
1009 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001010
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001011 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
1012 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001013
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001014 i++;
1015 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001016}
1017
1018/**
1019 * A ivi_surface drawing buttons in panel is identified by id_surface.
1020 * It can set several buttons. Properties of the ivi_surface is set by
1021 * using ivi_layout APIs according to the scene graph of UI defined in
1022 * hmi_controller_create. Additionally, the position of it is shifted to
1023 * right when new one is requested.
1024 *
1025 * UI ivi_layer is used to add these ivi_surfaces.
1026 */
1027static void
1028ivi_hmi_controller_set_button(struct hmi_controller *hmi_ctrl,
1029 uint32_t id_surface, int32_t number)
1030{
1031 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001032 struct hmi_controller_layer *base_layer =
1033 wl_container_of(hmi_ctrl->base_layer_list.prev,
1034 base_layer,
1035 link);
1036 struct ivi_layout_layer *ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001037 const int32_t width = 48;
1038 const int32_t height = 48;
1039 int32_t ret = 0;
1040 int32_t panel_height = 0;
1041 int32_t dstx = 0;
1042 int32_t dsty = 0;
1043 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1044 sizeof(*add_surface_id));
1045 *add_surface_id = id_surface;
1046
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001047 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001048 assert(ivisurf != NULL);
1049
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001050 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001051 assert(!ret);
1052
1053 panel_height = hmi_ctrl->hmi_setting->panel_height;
1054
1055 dstx = (60 * number) + 15;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001056 dsty = (base_layer->height - panel_height) + 5;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001057
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001058 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001059 ivisurf,dstx, dsty, width, height);
1060 assert(!ret);
1061
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001062 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001063 assert(!ret);
1064}
1065
1066/**
1067 * A ivi_surface drawing home button in panel is identified by id_surface.
1068 * Properties of the ivi_surface is set by using ivi_layout APIs according to
1069 * the scene graph of UI defined in hmi_controller_create.
1070 *
1071 * UI ivi_layer is used to add these ivi_surfaces.
1072 */
1073static void
1074ivi_hmi_controller_set_home_button(struct hmi_controller *hmi_ctrl,
1075 uint32_t id_surface)
1076{
1077 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001078 struct hmi_controller_layer *base_layer =
1079 wl_container_of(hmi_ctrl->base_layer_list.prev,
1080 base_layer,
1081 link);
1082 struct ivi_layout_layer *ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001083 int32_t ret = 0;
1084 int32_t size = 48;
1085 int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001086 const int32_t dstx = (base_layer->width - size) / 2;
1087 const int32_t dsty = (base_layer->height - panel_height) + 5;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001088
1089 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1090 sizeof(*add_surface_id));
1091 *add_surface_id = id_surface;
1092
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001093 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001094 assert(ivisurf != NULL);
1095
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001096 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001097 assert(!ret);
1098
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001099 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001100 ivisurf, dstx, dsty, size, size);
1101 assert(!ret);
1102
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001103 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001104 assert(!ret);
1105}
1106
1107/**
1108 * A ivi_surface drawing background of workspace is identified by id_surface.
1109 * Properties of the ivi_surface is set by using ivi_layout APIs according to
1110 * the scene graph of UI defined in hmi_controller_create.
1111 *
1112 * A ivi_layer of workspace_background is used to add this ivi_surface.
1113 */
1114static void
1115ivi_hmi_controller_set_workspacebackground(struct hmi_controller *hmi_ctrl,
1116 uint32_t id_surface)
1117{
1118 struct ivi_layout_surface *ivisurf = NULL;
1119 struct ivi_layout_layer *ivilayer = NULL;
1120 const int32_t width = hmi_ctrl->workspace_background_layer.width;
1121 const int32_t height = hmi_ctrl->workspace_background_layer.height;
1122 int32_t ret = 0;
1123
1124 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1125 sizeof(*add_surface_id));
1126 *add_surface_id = id_surface;
1127 ivilayer = hmi_ctrl->workspace_background_layer.ivilayer;
1128
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001129 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001130 assert(ivisurf != NULL);
1131
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001132 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001133 assert(!ret);
1134
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001135 ret = ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001136 0, 0, width, height);
1137 assert(!ret);
1138
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001139 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001140 assert(!ret);
1141}
1142
1143/**
1144 * A list of ivi_surfaces drawing launchers in workspace is identified by
1145 * id_surfaces. Properties of the ivi_surface is set by using ivi_layout
1146 * APIs according to the scene graph of UI defined in hmi_controller_create.
1147 *
1148 * The workspace can have several pages to group ivi_surfaces of launcher.
1149 * Each call of this interface increments a number of page to add a group
1150 * of ivi_surfaces
1151 */
1152static void
1153ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
1154 int32_t icon_size)
1155{
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001156 int32_t minspace_x = 10;
1157 int32_t minspace_y = minspace_x;
1158
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001159 int32_t width = hmi_ctrl->workspace_background_layer.width;
1160 int32_t height = hmi_ctrl->workspace_background_layer.height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001161
1162 int32_t x_count = (width - minspace_x) / (minspace_x + icon_size);
1163 int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count));
1164 float fcell_size_x = icon_size + space_x;
1165
1166 int32_t y_count = (height - minspace_y) / (minspace_y + icon_size);
1167 int32_t space_y = (int32_t)((height - y_count * icon_size) / (1.0 + y_count));
1168 float fcell_size_y = icon_size + space_y;
1169
1170 struct weston_config *config = NULL;
1171 struct weston_config_section *section = NULL;
1172 const char *name = NULL;
1173 int launcher_count = 0;
1174 struct wl_array launchers;
1175 int32_t nx = 0;
1176 int32_t ny = 0;
1177 int32_t prev = -1;
1178 struct launcher_info *data = NULL;
1179
1180 uint32_t surfaceid = 0;
1181 uint32_t workspaceid = 0;
1182 struct launcher_info *info = NULL;
1183
1184 int32_t x = 0;
1185 int32_t y = 0;
1186 int32_t ret = 0;
1187 struct ivi_layout_surface* layout_surface = NULL;
1188 uint32_t *add_surface_id = NULL;
1189
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001190 struct ivi_layout_screen *iviscrn = NULL;
1191 struct link_layer *tmp_link_layer = NULL;
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001192
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001193 if (0 == x_count)
1194 x_count = 1;
1195
1196 if (0 == y_count)
1197 y_count = 1;
1198
1199 config = hmi_ctrl->compositor->config;
1200 if (!config)
1201 return;
1202
1203 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1204 if (!section)
1205 return;
1206
1207 wl_array_init(&launchers);
1208
1209 while (weston_config_next_section(config, &section, &name)) {
1210 surfaceid = 0;
1211 workspaceid = 0;
1212 info = NULL;
1213 if (0 != strcmp(name, "ivi-launcher"))
1214 continue;
1215
1216 if (0 != weston_config_section_get_uint(section, "icon-id",
1217 &surfaceid, 0))
1218 continue;
1219
1220 if (0 != weston_config_section_get_uint(section,
1221 "workspace-id",
1222 &workspaceid, 0))
1223 continue;
1224
1225 info = wl_array_add(&launchers, sizeof(*info));
1226
1227 if (info) {
1228 info->surface_id = surfaceid;
1229 info->workspace_id = workspaceid;
1230 info->index = launcher_count;
1231 ++launcher_count;
1232 }
1233 }
1234
1235 qsort(launchers.data, launcher_count, sizeof(struct launcher_info),
1236 compare_launcher_info);
1237
1238 wl_array_for_each(data, &launchers) {
1239 x = 0;
1240 y = 0;
1241 ret = 0;
1242 layout_surface = NULL;
1243 add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1244 sizeof(*add_surface_id));
1245
1246 *add_surface_id = data->surface_id;
1247
1248 if (0 > prev || (uint32_t)prev != data->workspace_id) {
1249 nx = 0;
1250 ny = 0;
1251 prev = data->workspace_id;
1252
1253 if (0 <= prev)
1254 hmi_ctrl->workspace_count++;
1255 }
1256
1257 if (y_count == ny) {
1258 ny = 0;
1259 hmi_ctrl->workspace_count++;
1260 }
1261
1262 x = nx * fcell_size_x + (hmi_ctrl->workspace_count - 1) * width + space_x;
1263 y = ny * fcell_size_y + space_y;
1264
1265 layout_surface =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001266 ivi_layout_interface->get_surface_from_id(data->surface_id);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001267 assert(layout_surface);
1268
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001269 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001270 layout_surface, x, y, icon_size, icon_size);
1271 assert(!ret);
1272
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001273 nx++;
1274
1275 if (x_count == nx) {
1276 ny++;
1277 nx = 0;
1278 }
1279 }
1280
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001281 /* init workspace ivi_layer */
1282 hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
1283 hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
1284 hmi_ctrl->workspace_layer.width =
1285 hmi_ctrl->workspace_background_layer.width * hmi_ctrl->workspace_count;
1286 hmi_ctrl->workspace_layer.height =
1287 hmi_ctrl->workspace_background_layer.height;
1288 hmi_ctrl->workspace_layer.id_layer =
1289 hmi_ctrl->hmi_setting->workspace_layer_id;
1290
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +09001291 iviscrn = get_screen(0, hmi_ctrl);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001292 create_layer(iviscrn, &hmi_ctrl->workspace_layer);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001293 ivi_layout_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
1294 ivi_layout_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001295 false);
1296
1297 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
1298 tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
1299 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
1300 &tmp_link_layer->link);
1301
1302 /* Add surface to layer */
1303 wl_array_for_each(data, &launchers) {
1304 layout_surface =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001305 ivi_layout_interface->get_surface_from_id(data->surface_id);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001306 assert(layout_surface);
1307
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001308 ret = ivi_layout_interface->layer_add_surface(hmi_ctrl->workspace_layer.ivilayer,
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001309 layout_surface);
1310 assert(!ret);
1311
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001312 ret = ivi_layout_interface->surface_set_visibility(layout_surface, true);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001313 assert(!ret);
1314 }
1315
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001316 wl_array_release(&launchers);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001317 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001318}
1319
1320static void
1321ivi_hmi_controller_UI_ready(struct wl_client *client,
1322 struct wl_resource *resource)
1323{
1324 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1325
1326 ivi_hmi_controller_set_background(hmi_ctrl, hmi_ctrl->ui_setting.background_id);
1327 ivi_hmi_controller_set_panel(hmi_ctrl, hmi_ctrl->ui_setting.panel_id);
1328 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.tiling_id, 0);
1329 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.sidebyside_id, 1);
1330 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.fullscreen_id, 2);
1331 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.random_id, 3);
1332 ivi_hmi_controller_set_home_button(hmi_ctrl, hmi_ctrl->ui_setting.home_id);
1333 ivi_hmi_controller_set_workspacebackground(hmi_ctrl, hmi_ctrl->ui_setting.workspace_background_id);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001334 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001335
1336 ivi_hmi_controller_add_launchers(hmi_ctrl, 256);
1337 hmi_ctrl->is_initialized = 1;
1338}
1339
1340/**
1341 * Implementation of request and event of ivi_hmi_controller_workspace_control
1342 * and controlling workspace.
1343 *
1344 * When motion of input is detected in a ivi_surface of workspace background,
1345 * ivi_hmi_controller_workspace_control shall be invoked and to start
1346 * controlling of workspace. The workspace has several pages to show several
1347 * groups of applications.
1348 * The workspace is slid by using ivi-layout to select a a page in layer_set_pos
1349 * according to motion. When motion finished, e.g. touch up detected, control is
1350 * terminated and event:ivi_hmi_controller_workspace_control is notified.
1351 */
1352struct pointer_grab {
1353 struct weston_pointer_grab grab;
1354 struct ivi_layout_layer *layer;
1355 struct wl_resource *resource;
1356};
1357
1358struct touch_grab {
1359 struct weston_touch_grab grab;
1360 struct ivi_layout_layer *layer;
1361 struct wl_resource *resource;
1362};
1363
1364struct move_grab {
1365 wl_fixed_t dst[2];
1366 wl_fixed_t rgn[2][2];
1367 double v[2];
1368 struct timespec start_time;
1369 struct timespec pre_time;
1370 wl_fixed_t start_pos[2];
1371 wl_fixed_t pos[2];
1372 int32_t is_moved;
1373};
1374
1375struct pointer_move_grab {
1376 struct pointer_grab base;
1377 struct move_grab move;
1378};
1379
1380struct touch_move_grab {
1381 struct touch_grab base;
1382 struct move_grab move;
1383 int32_t is_active;
1384};
1385
1386static void
1387pointer_grab_start(struct pointer_grab *grab,
1388 struct ivi_layout_layer *layer,
1389 const struct weston_pointer_grab_interface *interface,
1390 struct weston_pointer *pointer)
1391{
1392 grab->grab.interface = interface;
1393 grab->layer = layer;
1394 weston_pointer_start_grab(pointer, &grab->grab);
1395}
1396
1397static void
1398touch_grab_start(struct touch_grab *grab,
1399 struct ivi_layout_layer *layer,
1400 const struct weston_touch_grab_interface *interface,
1401 struct weston_touch* touch)
1402{
1403 grab->grab.interface = interface;
1404 grab->layer = layer;
1405 weston_touch_start_grab(touch, &grab->grab);
1406}
1407
1408static int32_t
1409clamp(int32_t val, int32_t min, int32_t max)
1410{
1411 if (val < min)
1412 return min;
1413
1414 if (max < val)
1415 return max;
1416
1417 return val;
1418}
1419
1420static void
1421move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource,
1422 wl_fixed_t grab_x, struct ivi_layout_layer *layer)
1423{
1424 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1425 int32_t width = hmi_ctrl->workspace_background_layer.width;
1426
1427 struct timespec time = {0};
1428 double grab_time = 0.0;
1429 double from_motion_time = 0.0;
1430 double pointer_v = 0.0;
1431 int32_t is_flick = 0;
1432 int32_t pos_x = 0;
1433 int32_t pos_y = 0;
1434 int page_no = 0;
1435 double end_pos = 0.0;
1436 uint32_t duration = 0;
1437
1438 clock_gettime(CLOCK_MONOTONIC, &time);
1439
1440 grab_time = 1e+3 * (time.tv_sec - move->start_time.tv_sec) +
1441 1e-6 * (time.tv_nsec - move->start_time.tv_nsec);
1442
1443 from_motion_time = 1e+3 * (time.tv_sec - move->pre_time.tv_sec) +
1444 1e-6 * (time.tv_nsec - move->pre_time.tv_nsec);
1445
1446 pointer_v = move->v[0];
1447
1448 is_flick = grab_time < 400 && 0.4 < fabs(pointer_v);
1449 if (200 < from_motion_time)
1450 pointer_v = 0.0;
1451
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001452 ivi_layout_interface->layer_get_position(layer, &pos_x, &pos_y);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001453
1454
1455 if (is_flick) {
1456 int orgx = wl_fixed_to_int(move->dst[0] + grab_x);
1457 page_no = (-orgx + width / 2) / width;
1458
1459 if (pointer_v < 0.0)
1460 page_no++;
1461 else
1462 page_no--;
1463 } else {
1464 page_no = (-pos_x + width / 2) / width;
1465 }
1466
1467 page_no = clamp(page_no, 0, hmi_ctrl->workspace_count - 1);
1468 end_pos = -page_no * width;
1469
1470 duration = hmi_ctrl->hmi_setting->transition_duration;
1471 ivi_hmi_controller_send_workspace_end_control(resource, move->is_moved);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001472 ivi_layout_interface->layer_set_transition(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001473 IVI_LAYOUT_TRANSITION_LAYER_MOVE,
1474 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001475 ivi_layout_interface->layer_set_destination_rectangle(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001476 end_pos, pos_y,
Nobuhiko Tanibata4412cd12015-08-24 09:12:37 +09001477 hmi_ctrl->workspace_layer.width,
1478 hmi_ctrl->workspace_layer.height);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001479 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001480}
1481
1482static void
1483pointer_move_workspace_grab_end(struct pointer_grab *grab)
1484{
1485 struct pointer_move_grab *pnt_move_grab =
1486 (struct pointer_move_grab *)grab;
1487 struct ivi_layout_layer *layer = pnt_move_grab->base.layer;
1488
1489 move_workspace_grab_end(&pnt_move_grab->move, grab->resource,
1490 grab->grab.pointer->grab_x, layer);
1491
1492 weston_pointer_end_grab(grab->grab.pointer);
1493}
1494
1495static void
1496touch_move_workspace_grab_end(struct touch_grab *grab)
1497{
1498 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1499 struct ivi_layout_layer *layer = tch_move_grab->base.layer;
1500
1501 move_workspace_grab_end(&tch_move_grab->move, grab->resource,
1502 grab->grab.touch->grab_x, layer);
1503
1504 weston_touch_end_grab(grab->grab.touch);
1505}
1506
1507static void
1508pointer_noop_grab_focus(struct weston_pointer_grab *grab)
1509{
1510}
1511
1512static void
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001513pointer_default_grab_axis(struct weston_pointer_grab *grab,
Peter Hutterer89b6a492016-01-18 15:58:17 +10001514 uint32_t time,
1515 struct weston_pointer_axis_event *event)
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001516{
Peter Hutterer89b6a492016-01-18 15:58:17 +10001517 weston_pointer_send_axis(grab->pointer, time, event);
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001518}
1519
1520static void
Peter Hutterer87743e92016-01-18 16:38:22 +10001521pointer_default_grab_axis_source(struct weston_pointer_grab *grab,
1522 uint32_t source)
1523{
1524 weston_pointer_send_axis_source(grab->pointer, source);
1525}
1526
1527static void
1528pointer_default_grab_frame(struct weston_pointer_grab *grab)
1529{
1530 weston_pointer_send_frame(grab->pointer);
1531}
1532
1533static void
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001534move_grab_update(struct move_grab *move, wl_fixed_t pointer[2])
1535{
1536 struct timespec timestamp = {0};
1537 int32_t ii = 0;
1538 double dt = 0.0;
1539
1540 clock_gettime(CLOCK_MONOTONIC, &timestamp); //FIXME
1541 dt = (1e+3 * (timestamp.tv_sec - move->pre_time.tv_sec) +
1542 1e-6 * (timestamp.tv_nsec - move->pre_time.tv_nsec));
1543
1544 if (dt < 1e-6)
1545 dt = 1e-6;
1546
1547 move->pre_time = timestamp;
1548
1549 for (ii = 0; ii < 2; ii++) {
1550 wl_fixed_t prepos = move->pos[ii];
1551 move->pos[ii] = pointer[ii] + move->dst[ii];
1552
1553 if (move->pos[ii] < move->rgn[0][ii]) {
1554 move->pos[ii] = move->rgn[0][ii];
1555 move->dst[ii] = move->pos[ii] - pointer[ii];
1556 } else if (move->rgn[1][ii] < move->pos[ii]) {
1557 move->pos[ii] = move->rgn[1][ii];
1558 move->dst[ii] = move->pos[ii] - pointer[ii];
1559 }
1560
1561 move->v[ii] = wl_fixed_to_double(move->pos[ii] - prepos) / dt;
1562
1563 if (!move->is_moved &&
1564 0 < wl_fixed_to_int(move->pos[ii] - move->start_pos[ii]))
1565 move->is_moved = 1;
1566 }
1567}
1568
1569static void
1570layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
1571 wl_fixed_t pos_y)
1572{
1573 int32_t layout_pos_x = 0;
1574 int32_t layout_pos_y = 0;
1575
1576 layout_pos_x = wl_fixed_to_int(pos_x);
1577 layout_pos_y = wl_fixed_to_int(pos_y);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001578 ivi_layout_interface->layer_set_position(layer, layout_pos_x, layout_pos_y);
1579 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001580}
1581
1582static void
1583pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001584 struct weston_pointer_motion_event *event)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001585{
1586 struct pointer_move_grab *pnt_move_grab =
1587 (struct pointer_move_grab *)grab;
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001588 wl_fixed_t pointer_pos[2];
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001589
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001590 weston_pointer_motion_to_abs(grab->pointer, event,
1591 &pointer_pos[0], &pointer_pos[1]);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001592 move_grab_update(&pnt_move_grab->move, pointer_pos);
1593 layer_set_pos(pnt_move_grab->base.layer,
1594 pnt_move_grab->move.pos[0], pnt_move_grab->move.pos[1]);
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001595 weston_pointer_move(pnt_move_grab->base.grab.pointer, event);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001596}
1597
1598static void
1599touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1600 int touch_id, wl_fixed_t x, wl_fixed_t y)
1601{
1602 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1603
1604 if (!tch_move_grab->is_active)
1605 return;
1606
1607 wl_fixed_t pointer_pos[2] = {
1608 grab->touch->grab_x,
1609 grab->touch->grab_y
1610 };
1611
1612 move_grab_update(&tch_move_grab->move, pointer_pos);
1613 layer_set_pos(tch_move_grab->base.layer,
1614 tch_move_grab->move.pos[0], tch_move_grab->move.pos[1]);
1615}
1616
1617static void
1618pointer_move_workspace_grab_button(struct weston_pointer_grab *grab,
1619 uint32_t time, uint32_t button,
1620 uint32_t state_w)
1621{
1622 if (BTN_LEFT == button &&
1623 WL_POINTER_BUTTON_STATE_RELEASED == state_w) {
1624 struct pointer_grab *pg = (struct pointer_grab *)grab;
1625
1626 pointer_move_workspace_grab_end(pg);
1627 free(grab);
1628 }
1629}
1630
1631static void
1632touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
1633 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1634{
1635}
1636
1637static void
1638touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time,
1639 int touch_id)
1640{
1641 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1642
1643 if (0 == touch_id)
1644 tch_move_grab->is_active = 0;
1645
1646 if (0 == grab->touch->num_tp) {
1647 touch_move_workspace_grab_end(&tch_move_grab->base);
1648 free(grab);
1649 }
1650}
1651
1652static void
1653pointer_move_workspace_grab_cancel(struct weston_pointer_grab *grab)
1654{
1655 struct pointer_grab *pg = (struct pointer_grab *)grab;
1656
1657 pointer_move_workspace_grab_end(pg);
1658 free(grab);
1659}
1660
1661static void
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001662touch_move_workspace_grab_frame(struct weston_touch_grab *grab)
1663{
1664}
1665
1666static void
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001667touch_move_workspace_grab_cancel(struct weston_touch_grab *grab)
1668{
1669 struct touch_grab *tg = (struct touch_grab *)grab;
1670
1671 touch_move_workspace_grab_end(tg);
1672 free(grab);
1673}
1674
1675static const struct weston_pointer_grab_interface pointer_move_grab_workspace_interface = {
1676 pointer_noop_grab_focus,
1677 pointer_move_grab_motion,
1678 pointer_move_workspace_grab_button,
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001679 pointer_default_grab_axis,
Peter Hutterer87743e92016-01-18 16:38:22 +10001680 pointer_default_grab_axis_source,
1681 pointer_default_grab_frame,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001682 pointer_move_workspace_grab_cancel
1683};
1684
1685static const struct weston_touch_grab_interface touch_move_grab_workspace_interface = {
1686 touch_nope_grab_down,
1687 touch_move_workspace_grab_up,
1688 touch_move_grab_motion,
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001689 touch_move_workspace_grab_frame,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001690 touch_move_workspace_grab_cancel
1691};
1692
1693enum HMI_GRAB_DEVICE {
1694 HMI_GRAB_DEVICE_NONE,
1695 HMI_GRAB_DEVICE_POINTER,
1696 HMI_GRAB_DEVICE_TOUCH
1697};
1698
1699static enum HMI_GRAB_DEVICE
1700get_hmi_grab_device(struct weston_seat *seat, uint32_t serial)
1701{
Derek Foreman1281a362015-07-31 16:55:32 -05001702 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
1703 struct weston_touch *touch = weston_seat_get_touch(seat);
1704
1705 if (pointer &&
1706 pointer->focus &&
1707 pointer->button_count &&
1708 pointer->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001709 return HMI_GRAB_DEVICE_POINTER;
1710
Derek Foreman1281a362015-07-31 16:55:32 -05001711 if (touch &&
1712 touch->focus &&
1713 touch->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001714 return HMI_GRAB_DEVICE_TOUCH;
1715
1716 return HMI_GRAB_DEVICE_NONE;
1717}
1718
1719static void
1720move_grab_init(struct move_grab* move, wl_fixed_t start_pos[2],
1721 wl_fixed_t grab_pos[2], wl_fixed_t rgn[2][2],
1722 struct wl_resource* resource)
1723{
1724 clock_gettime(CLOCK_MONOTONIC, &move->start_time); //FIXME
1725 move->pre_time = move->start_time;
1726 move->pos[0] = start_pos[0];
1727 move->pos[1] = start_pos[1];
1728 move->start_pos[0] = start_pos[0];
1729 move->start_pos[1] = start_pos[1];
1730 move->dst[0] = start_pos[0] - grab_pos[0];
1731 move->dst[1] = start_pos[1] - grab_pos[1];
1732 memcpy(move->rgn, rgn, sizeof(move->rgn));
1733}
1734
1735static void
1736move_grab_init_workspace(struct move_grab* move,
1737 wl_fixed_t grab_x, wl_fixed_t grab_y,
1738 struct wl_resource *resource)
1739{
1740 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1741 struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
1742 int32_t workspace_count = hmi_ctrl->workspace_count;
1743 int32_t workspace_width = hmi_ctrl->workspace_background_layer.width;
1744 int32_t layer_pos_x = 0;
1745 int32_t layer_pos_y = 0;
1746 wl_fixed_t start_pos[2] = {0};
1747 wl_fixed_t rgn[2][2] = {{0}};
1748 wl_fixed_t grab_pos[2] = { grab_x, grab_y };
1749
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001750 ivi_layout_interface->layer_get_position(layer, &layer_pos_x, &layer_pos_y);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001751
1752 start_pos[0] = wl_fixed_from_int(layer_pos_x);
1753 start_pos[1] = wl_fixed_from_int(layer_pos_y);
1754
1755 rgn[0][0] = wl_fixed_from_int(-workspace_width * (workspace_count - 1));
1756
1757 rgn[0][1] = wl_fixed_from_int(0);
1758 rgn[1][0] = wl_fixed_from_int(0);
1759 rgn[1][1] = wl_fixed_from_int(0);
1760
1761 move_grab_init(move, start_pos, grab_pos, rgn, resource);
1762}
1763
1764static struct pointer_move_grab *
1765create_workspace_pointer_move(struct weston_pointer *pointer,
1766 struct wl_resource* resource)
1767{
1768 struct pointer_move_grab *pnt_move_grab =
1769 MEM_ALLOC(sizeof(*pnt_move_grab));
1770
1771 pnt_move_grab->base.resource = resource;
1772 move_grab_init_workspace(&pnt_move_grab->move, pointer->grab_x,
1773 pointer->grab_y, resource);
1774
1775 return pnt_move_grab;
1776}
1777
1778static struct touch_move_grab *
1779create_workspace_touch_move(struct weston_touch *touch,
1780 struct wl_resource* resource)
1781{
1782 struct touch_move_grab *tch_move_grab =
1783 MEM_ALLOC(sizeof(*tch_move_grab));
1784
1785 tch_move_grab->base.resource = resource;
1786 tch_move_grab->is_active = 1;
1787 move_grab_init_workspace(&tch_move_grab->move, touch->grab_x,
1788 touch->grab_y, resource);
1789
1790 return tch_move_grab;
1791}
1792
1793static void
1794ivi_hmi_controller_workspace_control(struct wl_client *client,
1795 struct wl_resource *resource,
1796 struct wl_resource *seat_resource,
1797 uint32_t serial)
1798{
1799 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1800 struct ivi_layout_layer *layer = NULL;
1801 struct pointer_move_grab *pnt_move_grab = NULL;
1802 struct touch_move_grab *tch_move_grab = NULL;
1803 struct weston_seat *seat = NULL;
Derek Foreman1281a362015-07-31 16:55:32 -05001804 struct weston_pointer *pointer;
1805 struct weston_touch *touch;
1806
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001807 enum HMI_GRAB_DEVICE device;
1808
1809 if (hmi_ctrl->workspace_count < 2)
1810 return;
1811
1812 seat = wl_resource_get_user_data(seat_resource);
1813 device = get_hmi_grab_device(seat, serial);
1814
1815 if (HMI_GRAB_DEVICE_POINTER != device &&
1816 HMI_GRAB_DEVICE_TOUCH != device)
1817 return;
1818
1819 layer = hmi_ctrl->workspace_layer.ivilayer;
1820
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001821 ivi_layout_interface->transition_move_layer_cancel(layer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001822
1823 switch (device) {
1824 case HMI_GRAB_DEVICE_POINTER:
Derek Foreman1281a362015-07-31 16:55:32 -05001825 pointer = weston_seat_get_pointer(seat);
1826 pnt_move_grab = create_workspace_pointer_move(pointer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001827 resource);
1828
1829 pointer_grab_start(&pnt_move_grab->base, layer,
1830 &pointer_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001831 pointer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001832 break;
1833
1834 case HMI_GRAB_DEVICE_TOUCH:
Derek Foreman1281a362015-07-31 16:55:32 -05001835 touch = weston_seat_get_touch(seat);
1836 tch_move_grab = create_workspace_touch_move(touch,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001837 resource);
1838
1839 touch_grab_start(&tch_move_grab->base, layer,
1840 &touch_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001841 touch);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001842 break;
1843
1844 default:
1845 break;
1846 }
1847}
1848
1849/**
1850 * Implementation of switch_mode
1851 */
1852static void
1853ivi_hmi_controller_switch_mode(struct wl_client *client,
1854 struct wl_resource *resource,
1855 uint32_t layout_mode)
1856{
1857 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1858
1859 switch_mode(hmi_ctrl, layout_mode);
1860}
1861
1862/**
1863 * Implementation of on/off displaying workspace and workspace background
1864 * ivi_layers.
1865 */
1866static void
1867ivi_hmi_controller_home(struct wl_client *client,
1868 struct wl_resource *resource,
1869 uint32_t home)
1870{
1871 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1872 uint32_t is_fade_in;
1873
1874 if ((IVI_HMI_CONTROLLER_HOME_ON == home &&
1875 !hmi_ctrl->workspace_fade.is_fade_in) ||
1876 (IVI_HMI_CONTROLLER_HOME_OFF == home &&
1877 hmi_ctrl->workspace_fade.is_fade_in)) {
1878 is_fade_in = !hmi_ctrl->workspace_fade.is_fade_in;
1879 hmi_controller_fade_run(hmi_ctrl, is_fade_in,
1880 &hmi_ctrl->workspace_fade);
1881 }
1882
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001883 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001884}
1885
1886/**
1887 * binding ivi-hmi-controller implementation
1888 */
1889static const struct ivi_hmi_controller_interface ivi_hmi_controller_implementation = {
1890 ivi_hmi_controller_UI_ready,
1891 ivi_hmi_controller_workspace_control,
1892 ivi_hmi_controller_switch_mode,
1893 ivi_hmi_controller_home
1894};
1895
1896static void
1897unbind_hmi_controller(struct wl_resource *resource)
1898{
1899}
1900
1901static void
1902bind_hmi_controller(struct wl_client *client,
1903 void *data, uint32_t version, uint32_t id)
1904{
1905 struct wl_resource *resource = NULL;
1906 struct hmi_controller *hmi_ctrl = data;
1907
1908 if (hmi_ctrl->user_interface != client) {
1909 struct wl_resource *res = wl_client_get_object(client, 1);
1910 wl_resource_post_error(res,
1911 WL_DISPLAY_ERROR_INVALID_OBJECT,
1912 "hmi-controller failed: permission denied");
1913 return;
1914 }
1915
1916 resource = wl_resource_create(
1917 client, &ivi_hmi_controller_interface, 1, id);
1918
1919 wl_resource_set_implementation(
1920 resource, &ivi_hmi_controller_implementation,
1921 hmi_ctrl, unbind_hmi_controller);
1922}
1923
1924static int32_t
1925initialize(struct hmi_controller *hmi_ctrl)
1926{
1927 struct config_command {
1928 char *key;
1929 uint32_t *dest;
1930 };
1931
1932 struct weston_config *config = hmi_ctrl->compositor->config;
1933 struct weston_config_section *section = NULL;
1934 int result = 0;
1935 int i = 0;
1936
1937 const struct config_command uint_commands[] = {
1938 { "background-id", &hmi_ctrl->ui_setting.background_id },
1939 { "panel-id", &hmi_ctrl->ui_setting.panel_id },
1940 { "tiling-id", &hmi_ctrl->ui_setting.tiling_id },
1941 { "sidebyside-id", &hmi_ctrl->ui_setting.sidebyside_id },
1942 { "fullscreen-id", &hmi_ctrl->ui_setting.fullscreen_id },
1943 { "random-id", &hmi_ctrl->ui_setting.random_id },
1944 { "home-id", &hmi_ctrl->ui_setting.home_id },
1945 { "workspace-background-id", &hmi_ctrl->ui_setting.workspace_background_id },
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001946 { "surface-id-offset", &hmi_ctrl->ui_setting.surface_id_offset },
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001947 { NULL, NULL }
1948 };
1949
1950 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1951
1952 for (i = 0; -1 != result; ++i) {
1953 const struct config_command *command = &uint_commands[i];
1954
1955 if (!command->key)
1956 break;
1957
1958 if (weston_config_section_get_uint(
1959 section, command->key, command->dest, 0) != 0)
1960 result = -1;
1961 }
1962
1963 if (-1 == result) {
1964 weston_log("Failed to initialize hmi-controller\n");
1965 return 0;
1966 }
1967
1968 return 1;
1969}
1970
1971static void
1972launch_hmi_client_process(void *data)
1973{
1974 struct hmi_controller *hmi_ctrl =
1975 (struct hmi_controller *)data;
1976
1977 hmi_ctrl->user_interface =
1978 weston_client_start(hmi_ctrl->compositor,
1979 hmi_ctrl->hmi_setting->ivi_homescreen);
1980
1981 free(hmi_ctrl->hmi_setting->ivi_homescreen);
1982}
1983
1984/*****************************************************************************
1985 * exported functions
1986 ****************************************************************************/
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001987WL_EXPORT int
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001988controller_module_init(struct weston_compositor *ec,
1989 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001990 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001991 size_t interface_version)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001992{
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001993 struct hmi_controller *hmi_ctrl = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001994 struct wl_event_loop *loop = NULL;
1995
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001996 if (interface_version < sizeof(struct ivi_layout_interface)) {
Chris Michaelc083af92015-10-01 10:51:29 -04001997 weston_log("ivi-shell: version mismatch of controller interface\n");
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001998 return -1;
1999 }
2000
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00002001 ivi_layout_interface = interface;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002002
2003 hmi_ctrl = hmi_controller_create(ec);
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +09002004 if (hmi_ctrl == NULL)
2005 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09002006
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09002007 if (!initialize(hmi_ctrl)) {
2008 return -1;
2009 }
2010
2011 if (wl_global_create(ec->wl_display,
2012 &ivi_hmi_controller_interface, 1,
2013 hmi_ctrl, bind_hmi_controller) == NULL) {
2014 return -1;
2015 }
2016
2017 loop = wl_display_get_event_loop(ec->wl_display);
2018 wl_event_loop_add_idle(loop, launch_hmi_client_process, hmi_ctrl);
2019
2020 return 0;
2021}