blob: 760bf06d799941190d9d43f7fbefb8b206090319 [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;
75};
76
77struct link_layer {
78 struct ivi_layout_layer *layout_layer;
79 struct wl_list link;
80};
81
82struct hmi_controller_fade {
83 uint32_t is_fade_in;
84 struct wl_list layer_list;
85};
86
87struct hmi_server_setting {
88 uint32_t base_layer_id;
89 uint32_t application_layer_id;
90 uint32_t workspace_background_layer_id;
91 uint32_t workspace_layer_id;
92 int32_t panel_height;
93 uint32_t transition_duration;
94 char *ivi_homescreen;
95};
96
97struct ui_setting {
98 uint32_t background_id;
99 uint32_t panel_id;
100 uint32_t tiling_id;
101 uint32_t sidebyside_id;
102 uint32_t fullscreen_id;
103 uint32_t random_id;
104 uint32_t home_id;
105 uint32_t workspace_background_id;
106};
107
108struct hmi_controller {
109 struct hmi_server_setting *hmi_setting;
110 struct hmi_controller_layer base_layer;
111 struct hmi_controller_layer application_layer;
112 struct hmi_controller_layer workspace_background_layer;
113 struct hmi_controller_layer workspace_layer;
114 enum ivi_hmi_controller_layout_mode layout_mode;
115
116 struct hmi_controller_fade workspace_fade;
117
118 int32_t workspace_count;
119 struct wl_array ui_widgets;
120 int32_t is_initialized;
121
122 struct weston_compositor *compositor;
123 struct wl_listener destroy_listener;
124
125 struct wl_client *user_interface;
126 struct ui_setting ui_setting;
127};
128
129struct launcher_info {
130 uint32_t surface_id;
131 uint32_t workspace_id;
132 int32_t index;
133};
134
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900135const struct ivi_controller_interface *ivi_controller_interface;
136
137int
138controller_module_init(struct weston_compositor *ec,
139 int *argc, char *argv[],
140 const struct ivi_controller_interface *interface,
141 size_t interface_version);
142
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900143/*****************************************************************************
144 * local functions
145 ****************************************************************************/
146static void *
147fail_on_null(void *p, size_t size, char *file, int32_t line)
148{
149 if (size && !p) {
150 weston_log("%s(%d) %zd: out of memory\n", file, line, size);
151 exit(EXIT_FAILURE);
152 }
153
154 return p;
155}
156
157static void *
158mem_alloc(size_t size, char *file, int32_t line)
159{
160 return fail_on_null(calloc(1, size), size, file, line);
161}
162
163#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
164
165static int32_t
166is_surf_in_ui_widget(struct hmi_controller *hmi_ctrl,
167 struct ivi_layout_surface *ivisurf)
168{
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900169 uint32_t id = ivi_controller_interface->get_id_of_surface(ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900170
171 uint32_t *ui_widget_id = NULL;
172 wl_array_for_each(ui_widget_id, &hmi_ctrl->ui_widgets) {
173 if (*ui_widget_id == id)
174 return 1;
175 }
176
177 return 0;
178}
179
180static int
181compare_launcher_info(const void *lhs, const void *rhs)
182{
183 const struct launcher_info *left = lhs;
184 const struct launcher_info *right = rhs;
185
186 if (left->workspace_id < right->workspace_id)
187 return -1;
188
189 if (left->workspace_id > right->workspace_id)
190 return 1;
191
192 if (left->index < right->index)
193 return -1;
194
195 if (left->index > right->index)
196 return 1;
197
198 return 0;
199}
200
201/**
202 * Internal methods called by mainly ivi_hmi_controller_switch_mode
203 * This reference shows 4 examples how to use ivi_layout APIs.
204 */
205static void
206mode_divided_into_tiling(struct hmi_controller *hmi_ctrl,
207 struct ivi_layout_surface **pp_surface,
208 int32_t surface_length,
209 struct hmi_controller_layer *layer)
210{
211 const float surface_width = (float)layer->width * 0.25;
212 const float surface_height = (float)layer->height * 0.5;
213 int32_t surface_x = 0;
214 int32_t surface_y = 0;
215 struct ivi_layout_surface *ivisurf = NULL;
216 struct ivi_layout_surface **surfaces;
217 struct ivi_layout_surface **new_order;
218 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
219
220 int32_t i = 0;
221 int32_t surf_num = 0;
222 uint32_t num = 1;
223
224 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
225 new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
226
227 for (i = 0; i < surface_length; i++) {
228 ivisurf = pp_surface[i];
229
230 /* skip ui widgets */
231 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
232 continue;
233
234 surfaces[surf_num++] = ivisurf;
235 }
236
237 for (i = 0; i < surf_num; i++) {
238 ivisurf = surfaces[i];
239 new_order[i] = ivisurf;
240
241 if (num <= 8) {
242 if (num < 5) {
243 surface_x = (int32_t)((num - 1) * (surface_width));
244 surface_y = 0;
245 } else {
246 surface_x = (int32_t)((num - 5) * (surface_width));
247 surface_y = (int32_t)surface_height;
248 }
249
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900250 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900251 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
252 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900253 ivi_controller_interface->surface_set_visibility(ivisurf, true);
254 ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900255 surface_x, surface_y,
256 (int32_t)surface_width,
257 (int32_t)surface_height);
258
259 num++;
260 continue;
261 }
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900262 ivi_controller_interface->surface_set_visibility(ivisurf, false);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900263 }
264
265 if (surf_num > 0) {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900266 ivi_controller_interface->layer_set_transition(layer->ivilayer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900267 IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER,
268 duration);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900269 }
270
271 free(surfaces);
272 free(new_order);
273}
274
275static void
276mode_divided_into_sidebyside(struct hmi_controller *hmi_ctrl,
277 struct ivi_layout_surface **pp_surface,
278 int32_t surface_length,
279 struct hmi_controller_layer *layer)
280{
281 int32_t surface_width = layer->width / 2;
282 int32_t surface_height = layer->height;
283 struct ivi_layout_surface *ivisurf = NULL;
284
285 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
286 int32_t i = 0;
287 int32_t num = 1;
288
289 for (i = 0; i < surface_length; i++) {
290 ivisurf = pp_surface[i];
291
292 /* skip ui widgets */
293 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
294 continue;
295
296 if (num == 1) {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900297 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900298 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
299 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900300 ivi_controller_interface->surface_set_visibility(ivisurf, true);
301 ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900302 0, 0,
303 surface_width,
304 surface_height);
305
306 num++;
307 continue;
308 } else if (num == 2) {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900309 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900310 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
311 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900312 ivi_controller_interface->surface_set_visibility(ivisurf, true);
313 ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900314 surface_width, 0,
315 surface_width,
316 surface_height);
317
318 num++;
319 continue;
320 }
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900321 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900322 IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY,
323 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900324 ivi_controller_interface->surface_set_visibility(ivisurf, false);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900325 }
326}
327
328static void
329mode_fullscreen_someone(struct hmi_controller *hmi_ctrl,
330 struct ivi_layout_surface **pp_surface,
331 int32_t surface_length,
332 struct hmi_controller_layer *layer)
333{
334 const int32_t surface_width = layer->width;
335 const int32_t surface_height = layer->height;
336 struct ivi_layout_surface *ivisurf = NULL;
337 int32_t i = 0;
338 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
339
340 for (i = 0; i < surface_length; i++) {
341 ivisurf = pp_surface[i];
342
343 /* skip ui widgets */
344 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
345 continue;
346
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900347 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900348 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
349 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900350 ivi_controller_interface->surface_set_visibility(ivisurf, true);
351 ivi_controller_interface->surface_set_destination_rectangle(ivisurf, 0, 0,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900352 surface_width,
353 surface_height);
354 }
355}
356
357static void
358mode_random_replace(struct hmi_controller *hmi_ctrl,
359 struct ivi_layout_surface **pp_surface,
360 int32_t surface_length,
361 struct hmi_controller_layer *layer)
362{
363 const int32_t surface_width = (int32_t)(layer->width * 0.25f);
364 const int32_t surface_height = (int32_t)(layer->height * 0.25f);
365 int32_t surface_x = 0;
366 int32_t surface_y = 0;
367 struct ivi_layout_surface *ivisurf = NULL;
368 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
369 int32_t i = 0;
370
371 for (i = 0; i < surface_length; i++) {
372 ivisurf = pp_surface[i];
373
374 /* skip ui widgets */
375 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
376 continue;
377
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900378 ivi_controller_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900379 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
380 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900381 ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900382 surface_x = rand() % (layer->width - surface_width);
383 surface_y = rand() % (layer->height - surface_height);
384
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900385 ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900386 surface_x,
387 surface_y,
388 surface_width,
389 surface_height);
390 }
391}
392
393static int32_t
394has_application_surface(struct hmi_controller *hmi_ctrl,
395 struct ivi_layout_surface **pp_surface,
396 int32_t surface_length)
397{
398 struct ivi_layout_surface *ivisurf = NULL;
399 int32_t i = 0;
400
401 for (i = 0; i < surface_length; i++) {
402 ivisurf = pp_surface[i];
403
404 /* skip ui widgets */
405 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
406 continue;
407
408 return 1;
409 }
410
411 return 0;
412}
413
414/**
415 * Supports 4 example to layout of application ivi_surfaces;
416 * tiling, side by side, fullscreen, and random.
417 */
418static void
419switch_mode(struct hmi_controller *hmi_ctrl,
420 enum ivi_hmi_controller_layout_mode layout_mode)
421{
422 struct hmi_controller_layer *layer = &hmi_ctrl->application_layer;
423 struct ivi_layout_surface **pp_surface = NULL;
424 int32_t surface_length = 0;
425 int32_t ret = 0;
426
427 if (!hmi_ctrl->is_initialized)
428 return;
429
430 hmi_ctrl->layout_mode = layout_mode;
431
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900432 ret = ivi_controller_interface->get_surfaces(&surface_length, &pp_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900433 assert(!ret);
434
435 if (!has_application_surface(hmi_ctrl, pp_surface, surface_length)) {
436 free(pp_surface);
437 pp_surface = NULL;
438 return;
439 }
440
441 switch (layout_mode) {
442 case IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING:
443 mode_divided_into_tiling(hmi_ctrl, pp_surface, surface_length,
444 layer);
445 break;
446 case IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE:
447 mode_divided_into_sidebyside(hmi_ctrl, pp_surface,
448 surface_length, layer);
449 break;
450 case IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN:
451 mode_fullscreen_someone(hmi_ctrl, pp_surface, surface_length,
452 layer);
453 break;
454 case IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM:
455 mode_random_replace(hmi_ctrl, pp_surface, surface_length,
456 layer);
457 break;
458 }
459
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900460 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900461 free(pp_surface);
462}
463
464/**
465 * Internal method for transition
466 */
467static void
468hmi_controller_fade_run(struct hmi_controller *hmi_ctrl, uint32_t is_fade_in,
469 struct hmi_controller_fade *fade)
470{
471 double tint = is_fade_in ? 1.0 : 0.0;
472 struct link_layer *linklayer = NULL;
473 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
474
475 fade->is_fade_in = is_fade_in;
476
477 wl_list_for_each(linklayer, &fade->layer_list, link) {
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900478 ivi_controller_interface->layer_set_transition(linklayer->layout_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900479 IVI_LAYOUT_TRANSITION_LAYER_FADE,
480 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900481 ivi_controller_interface->layer_set_fade_info(linklayer->layout_layer,
482 is_fade_in, 1.0 - tint, tint);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900483 }
484}
485
486/**
487 * Internal method to create ivi_layer with hmi_controller_layer and
488 * add to a ivi_screen
489 */
490static void
491create_layer(struct ivi_layout_screen *iviscrn,
492 struct hmi_controller_layer *layer)
493{
494 int32_t ret = 0;
495
496 layer->ivilayer =
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900497 ivi_controller_interface->layer_create_with_dimension(layer->id_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900498 layer->width,
499 layer->height);
500 assert(layer->ivilayer != NULL);
501
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900502 ret = ivi_controller_interface->screen_add_layer(iviscrn, layer->ivilayer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900503 assert(!ret);
504
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900505 ret = ivi_controller_interface->layer_set_destination_rectangle(layer->ivilayer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900506 layer->x, layer->y,
507 layer->width,
508 layer->height);
509 assert(!ret);
510
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900511 ret = ivi_controller_interface->layer_set_visibility(layer->ivilayer, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900512 assert(!ret);
513}
514
515/**
516 * Internal set notification
517 */
518static void
519set_notification_create_surface(struct ivi_layout_surface *ivisurf,
520 void *userdata)
521{
522 struct hmi_controller *hmi_ctrl = userdata;
523 struct ivi_layout_layer *application_layer =
524 hmi_ctrl->application_layer.ivilayer;
525 int32_t ret = 0;
526
527 /* skip ui widgets */
528 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
529 return;
530
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900531 ret = ivi_controller_interface->layer_add_surface(application_layer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900532 assert(!ret);
533}
534
535static void
536set_notification_remove_surface(struct ivi_layout_surface *ivisurf,
537 void *userdata)
538{
539 struct hmi_controller *hmi_ctrl = userdata;
540
541 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
542}
543
544static void
545set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
546 void *userdata)
547{
548 struct hmi_controller *hmi_ctrl = userdata;
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900549 struct ivi_layout_layer *application_layer =
550 hmi_ctrl->application_layer.ivilayer;
551 struct weston_surface *surface;
552 struct ivi_layout_surface **ivisurfs;
553 int32_t length = 0;
554 int32_t i;
555
556 /* return if the surface is not application content */
557 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) {
558 return;
559 }
560
561 /*
562 * if application changes size of wl_buffer. The source rectangle shall be
563 * fit to the size.
564 */
565 surface = ivi_controller_interface->surface_get_weston_surface(ivisurf);
566 if (surface) {
567 ivi_controller_interface->surface_set_source_rectangle(
568 ivisurf, 0, 0, surface->width,
569 surface->height);
570 }
571
572 /*
573 * search if the surface is already added to layer.
574 * If not yet, it is newly invoded application to go to switch_mode.
575 */
576 ivi_controller_interface->get_surfaces_on_layer(application_layer,
577 &length, &ivisurfs);
578 for (i = 0; i < length; i++) {
579 if (ivisurf == ivisurfs[i]) {
Michael Vetter2a18a522015-05-15 17:17:47 +0200580 /*
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900581 * if it is non new invoked application, just call
582 * commit_changes to apply source_rectangle.
583 */
584 ivi_controller_interface->commit_changes();
585 return;
586 }
587 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900588
589 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
590}
591
592/**
593 * A hmi_controller used 4 ivi_layers to manage ivi_surfaces. The IDs of
594 * corresponding ivi_layer are defined in weston.ini. Default scene graph
595 * of ivi_layers are initialized in hmi_controller_create
596 */
597static struct hmi_server_setting *
598hmi_server_setting_create(struct weston_compositor *ec)
599{
600 struct hmi_server_setting *setting = MEM_ALLOC(sizeof(*setting));
601 struct weston_config *config = ec->config;
602 struct weston_config_section *shell_section = NULL;
603
604 shell_section = weston_config_get_section(config, "ivi-shell",
605 NULL, NULL);
606
607 weston_config_section_get_uint(shell_section, "base-layer-id",
608 &setting->base_layer_id, 1000);
609
610 weston_config_section_get_uint(shell_section,
611 "workspace-background-layer-id",
612 &setting->workspace_background_layer_id,
613 2000);
614
615 weston_config_section_get_uint(shell_section, "workspace-layer-id",
616 &setting->workspace_layer_id, 3000);
617
618 weston_config_section_get_uint(shell_section, "application-layer-id",
619 &setting->application_layer_id, 4000);
620
621 weston_config_section_get_uint(shell_section, "transition-duration",
622 &setting->transition_duration, 300);
623
624 setting->panel_height = 70;
625
626 weston_config_section_get_string(shell_section,
627 "ivi-shell-user-interface",
628 &setting->ivi_homescreen, NULL);
629
630 return setting;
631}
632
633static void
634hmi_controller_destroy(struct wl_listener *listener, void *data)
635{
636 struct link_layer *link = NULL;
637 struct link_layer *next = NULL;
638 struct hmi_controller *hmi_ctrl =
639 container_of(listener, struct hmi_controller, destroy_listener);
640
641 wl_list_for_each_safe(link, next,
642 &hmi_ctrl->workspace_fade.layer_list, link) {
643 wl_list_remove(&link->link);
644 free(link);
645 }
646
647 wl_array_release(&hmi_ctrl->ui_widgets);
648 free(hmi_ctrl->hmi_setting);
649 free(hmi_ctrl);
650}
651
652/**
653 * This is a starting method called from module_init.
654 * This sets up scene graph of ivi_layers; base, application, workspace
655 * background, and workspace. These ivi_layers are created/added to
656 * ivi_screen in create_layer
657 *
658 * base: to group ivi_surfaces of panel and background
659 * application: to group ivi_surfaces of ivi_applications
660 * workspace background: to group a ivi_surface of background in workspace
661 * workspace: to group ivi_surfaces for launching ivi_applications
662 *
663 * ivi_layers of workspace background and workspace is set to invisible at
664 * first. The properties of it is updated with animation when
665 * ivi_hmi_controller_home is requested.
666 */
667static struct hmi_controller *
668hmi_controller_create(struct weston_compositor *ec)
669{
670 struct ivi_layout_screen **pp_screen = NULL;
671 struct ivi_layout_screen *iviscrn = NULL;
672 int32_t screen_length = 0;
673 int32_t screen_width = 0;
674 int32_t screen_height = 0;
675 struct link_layer *tmp_link_layer = NULL;
676 int32_t panel_height = 0;
677 struct hmi_controller *hmi_ctrl = MEM_ALLOC(sizeof(*hmi_ctrl));
678
679 wl_array_init(&hmi_ctrl->ui_widgets);
680 hmi_ctrl->layout_mode = IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING;
681 hmi_ctrl->hmi_setting = hmi_server_setting_create(ec);
682 hmi_ctrl->compositor = ec;
683
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900684 ivi_controller_interface->get_screens(&screen_length, &pp_screen);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900685
686 iviscrn = pp_screen[0];
687
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900688 ivi_controller_interface->get_screen_resolution(iviscrn, &screen_width,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900689 &screen_height);
690
691 /* init base ivi_layer*/
692 hmi_ctrl->base_layer.x = 0;
693 hmi_ctrl->base_layer.y = 0;
694 hmi_ctrl->base_layer.width = screen_width;
695 hmi_ctrl->base_layer.height = screen_height;
696 hmi_ctrl->base_layer.id_layer = hmi_ctrl->hmi_setting->base_layer_id;
697
698 create_layer(iviscrn, &hmi_ctrl->base_layer);
699
700 panel_height = hmi_ctrl->hmi_setting->panel_height;
701
702 /* init application ivi_layer */
703 hmi_ctrl->application_layer.x = 0;
704 hmi_ctrl->application_layer.y = 0;
705 hmi_ctrl->application_layer.width = screen_width;
706 hmi_ctrl->application_layer.height = screen_height - panel_height;
707 hmi_ctrl->application_layer.id_layer =
708 hmi_ctrl->hmi_setting->application_layer_id;
709
710 create_layer(iviscrn, &hmi_ctrl->application_layer);
711
712 /* init workspace background ivi_layer */
713 hmi_ctrl->workspace_background_layer.x = 0;
714 hmi_ctrl->workspace_background_layer.y = 0;
715 hmi_ctrl->workspace_background_layer.width = screen_width;
716 hmi_ctrl->workspace_background_layer.height =
717 screen_height - panel_height;
718
719 hmi_ctrl->workspace_background_layer.id_layer =
720 hmi_ctrl->hmi_setting->workspace_background_layer_id;
721
722 create_layer(iviscrn, &hmi_ctrl->workspace_background_layer);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900723 ivi_controller_interface->layer_set_opacity(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900724 hmi_ctrl->workspace_background_layer.ivilayer, 0);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900725 ivi_controller_interface->layer_set_visibility(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900726 hmi_ctrl->workspace_background_layer.ivilayer, false);
727
728 /* init workspace ivi_layer */
729 hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
730 hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
731 hmi_ctrl->workspace_layer.width =
732 hmi_ctrl->workspace_background_layer.width;
733 hmi_ctrl->workspace_layer.height =
734 hmi_ctrl->workspace_background_layer.height;
735 hmi_ctrl->workspace_layer.id_layer =
736 hmi_ctrl->hmi_setting->workspace_layer_id;
737
738 create_layer(iviscrn, &hmi_ctrl->workspace_layer);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900739 ivi_controller_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
740 ivi_controller_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900741 false);
742
743 wl_list_init(&hmi_ctrl->workspace_fade.layer_list);
744 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
745 tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
746 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
747 &tmp_link_layer->link);
748 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
749 tmp_link_layer->layout_layer =
750 hmi_ctrl->workspace_background_layer.ivilayer;
751 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
752 &tmp_link_layer->link);
753
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900754 ivi_controller_interface->add_notification_create_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900755 set_notification_create_surface, hmi_ctrl);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900756 ivi_controller_interface->add_notification_remove_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900757 set_notification_remove_surface, hmi_ctrl);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900758 ivi_controller_interface->add_notification_configure_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900759 set_notification_configure_surface, hmi_ctrl);
760
761 hmi_ctrl->destroy_listener.notify = hmi_controller_destroy;
762 wl_signal_add(&hmi_ctrl->compositor->destroy_signal,
763 &hmi_ctrl->destroy_listener);
764
765 free(pp_screen);
766 pp_screen = NULL;
767
768 return hmi_ctrl;
769}
770
771/**
772 * Implementations of ivi-hmi-controller.xml
773 */
774
775/**
776 * A ivi_surface drawing background is identified by id_surface.
777 * Properties of the ivi_surface is set by using ivi_layout APIs according to
778 * the scene graph of UI defined in hmi_controller_create.
779 *
780 * UI ivi_layer is used to add this ivi_surface.
781 */
782static void
783ivi_hmi_controller_set_background(struct hmi_controller *hmi_ctrl,
784 uint32_t id_surface)
785{
786 struct ivi_layout_surface *ivisurf = NULL;
787 struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer;
788 const int32_t dstx = hmi_ctrl->application_layer.x;
789 const int32_t dsty = hmi_ctrl->application_layer.y;
790 const int32_t width = hmi_ctrl->application_layer.width;
791 const int32_t height = hmi_ctrl->application_layer.height;
792 int32_t ret = 0;
793
794 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
795 sizeof(*add_surface_id));
796 *add_surface_id = id_surface;
797
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900798 ivisurf = ivi_controller_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900799 assert(ivisurf != NULL);
800
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900801 ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900802 assert(!ret);
803
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900804 ret = ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900805 dstx, dsty, width, height);
806 assert(!ret);
807
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900808 ret = ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900809 assert(!ret);
810}
811
812/**
813 * A ivi_surface drawing panel is identified by id_surface.
814 * Properties of the ivi_surface is set by using ivi_layout APIs according to
815 * the scene graph of UI defined in hmi_controller_create.
816 *
817 * UI ivi_layer is used to add this ivi_surface.
818 */
819static void
820ivi_hmi_controller_set_panel(struct hmi_controller *hmi_ctrl,
821 uint32_t id_surface)
822{
823 struct ivi_layout_surface *ivisurf = NULL;
824 struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer;
825 const int32_t width = hmi_ctrl->base_layer.width;
826 int32_t ret = 0;
827 int32_t panel_height = 0;
828 const int32_t dstx = 0;
829 int32_t dsty = 0;
830
831 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
832 sizeof(*add_surface_id));
833 *add_surface_id = id_surface;
834
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900835 ivisurf = ivi_controller_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900836 assert(ivisurf != NULL);
837
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900838 ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900839 assert(!ret);
840
841 panel_height = hmi_ctrl->hmi_setting->panel_height;
842
843 dsty = hmi_ctrl->base_layer.height - panel_height;
844
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900845 ret = ivi_controller_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900846 ivisurf, dstx, dsty, width, panel_height);
847 assert(!ret);
848
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900849 ret = ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900850 assert(!ret);
851}
852
853/**
854 * A ivi_surface drawing buttons in panel is identified by id_surface.
855 * It can set several buttons. Properties of the ivi_surface is set by
856 * using ivi_layout APIs according to the scene graph of UI defined in
857 * hmi_controller_create. Additionally, the position of it is shifted to
858 * right when new one is requested.
859 *
860 * UI ivi_layer is used to add these ivi_surfaces.
861 */
862static void
863ivi_hmi_controller_set_button(struct hmi_controller *hmi_ctrl,
864 uint32_t id_surface, int32_t number)
865{
866 struct ivi_layout_surface *ivisurf = NULL;
867 struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer;
868 const int32_t width = 48;
869 const int32_t height = 48;
870 int32_t ret = 0;
871 int32_t panel_height = 0;
872 int32_t dstx = 0;
873 int32_t dsty = 0;
874 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
875 sizeof(*add_surface_id));
876 *add_surface_id = id_surface;
877
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900878 ivisurf = ivi_controller_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900879 assert(ivisurf != NULL);
880
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900881 ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900882 assert(!ret);
883
884 panel_height = hmi_ctrl->hmi_setting->panel_height;
885
886 dstx = (60 * number) + 15;
887 dsty = (hmi_ctrl->base_layer.height - panel_height) + 5;
888
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900889 ret = ivi_controller_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900890 ivisurf,dstx, dsty, width, height);
891 assert(!ret);
892
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900893 ret = ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900894 assert(!ret);
895}
896
897/**
898 * A ivi_surface drawing home button in panel is identified by id_surface.
899 * Properties of the ivi_surface is set by using ivi_layout APIs according to
900 * the scene graph of UI defined in hmi_controller_create.
901 *
902 * UI ivi_layer is used to add these ivi_surfaces.
903 */
904static void
905ivi_hmi_controller_set_home_button(struct hmi_controller *hmi_ctrl,
906 uint32_t id_surface)
907{
908 struct ivi_layout_surface *ivisurf = NULL;
909 struct ivi_layout_layer *ivilayer = hmi_ctrl->base_layer.ivilayer;
910 int32_t ret = 0;
911 int32_t size = 48;
912 int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
913 const int32_t dstx = (hmi_ctrl->base_layer.width - size) / 2;
914 const int32_t dsty = (hmi_ctrl->base_layer.height - panel_height) + 5;
915
916 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
917 sizeof(*add_surface_id));
918 *add_surface_id = id_surface;
919
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900920 ivisurf = ivi_controller_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900921 assert(ivisurf != NULL);
922
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900923 ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900924 assert(!ret);
925
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900926 ret = ivi_controller_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900927 ivisurf, dstx, dsty, size, size);
928 assert(!ret);
929
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900930 ret = ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900931 assert(!ret);
932}
933
934/**
935 * A ivi_surface drawing background of workspace is identified by id_surface.
936 * Properties of the ivi_surface is set by using ivi_layout APIs according to
937 * the scene graph of UI defined in hmi_controller_create.
938 *
939 * A ivi_layer of workspace_background is used to add this ivi_surface.
940 */
941static void
942ivi_hmi_controller_set_workspacebackground(struct hmi_controller *hmi_ctrl,
943 uint32_t id_surface)
944{
945 struct ivi_layout_surface *ivisurf = NULL;
946 struct ivi_layout_layer *ivilayer = NULL;
947 const int32_t width = hmi_ctrl->workspace_background_layer.width;
948 const int32_t height = hmi_ctrl->workspace_background_layer.height;
949 int32_t ret = 0;
950
951 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
952 sizeof(*add_surface_id));
953 *add_surface_id = id_surface;
954 ivilayer = hmi_ctrl->workspace_background_layer.ivilayer;
955
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900956 ivisurf = ivi_controller_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900957 assert(ivisurf != NULL);
958
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900959 ret = ivi_controller_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900960 assert(!ret);
961
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900962 ret = ivi_controller_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900963 0, 0, width, height);
964 assert(!ret);
965
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900966 ret = ivi_controller_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900967 assert(!ret);
968}
969
970/**
971 * A list of ivi_surfaces drawing launchers in workspace is identified by
972 * id_surfaces. Properties of the ivi_surface is set by using ivi_layout
973 * APIs according to the scene graph of UI defined in hmi_controller_create.
974 *
975 * The workspace can have several pages to group ivi_surfaces of launcher.
976 * Each call of this interface increments a number of page to add a group
977 * of ivi_surfaces
978 */
979static void
980ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
981 int32_t icon_size)
982{
983 struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
984 int32_t minspace_x = 10;
985 int32_t minspace_y = minspace_x;
986
987 int32_t width = hmi_ctrl->workspace_layer.width;
988 int32_t height = hmi_ctrl->workspace_layer.height;
989
990 int32_t x_count = (width - minspace_x) / (minspace_x + icon_size);
991 int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count));
992 float fcell_size_x = icon_size + space_x;
993
994 int32_t y_count = (height - minspace_y) / (minspace_y + icon_size);
995 int32_t space_y = (int32_t)((height - y_count * icon_size) / (1.0 + y_count));
996 float fcell_size_y = icon_size + space_y;
997
998 struct weston_config *config = NULL;
999 struct weston_config_section *section = NULL;
1000 const char *name = NULL;
1001 int launcher_count = 0;
1002 struct wl_array launchers;
1003 int32_t nx = 0;
1004 int32_t ny = 0;
1005 int32_t prev = -1;
1006 struct launcher_info *data = NULL;
1007
1008 uint32_t surfaceid = 0;
1009 uint32_t workspaceid = 0;
1010 struct launcher_info *info = NULL;
1011
1012 int32_t x = 0;
1013 int32_t y = 0;
1014 int32_t ret = 0;
1015 struct ivi_layout_surface* layout_surface = NULL;
1016 uint32_t *add_surface_id = NULL;
1017
1018 if (0 == x_count)
1019 x_count = 1;
1020
1021 if (0 == y_count)
1022 y_count = 1;
1023
1024 config = hmi_ctrl->compositor->config;
1025 if (!config)
1026 return;
1027
1028 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1029 if (!section)
1030 return;
1031
1032 wl_array_init(&launchers);
1033
1034 while (weston_config_next_section(config, &section, &name)) {
1035 surfaceid = 0;
1036 workspaceid = 0;
1037 info = NULL;
1038 if (0 != strcmp(name, "ivi-launcher"))
1039 continue;
1040
1041 if (0 != weston_config_section_get_uint(section, "icon-id",
1042 &surfaceid, 0))
1043 continue;
1044
1045 if (0 != weston_config_section_get_uint(section,
1046 "workspace-id",
1047 &workspaceid, 0))
1048 continue;
1049
1050 info = wl_array_add(&launchers, sizeof(*info));
1051
1052 if (info) {
1053 info->surface_id = surfaceid;
1054 info->workspace_id = workspaceid;
1055 info->index = launcher_count;
1056 ++launcher_count;
1057 }
1058 }
1059
1060 qsort(launchers.data, launcher_count, sizeof(struct launcher_info),
1061 compare_launcher_info);
1062
1063 wl_array_for_each(data, &launchers) {
1064 x = 0;
1065 y = 0;
1066 ret = 0;
1067 layout_surface = NULL;
1068 add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1069 sizeof(*add_surface_id));
1070
1071 *add_surface_id = data->surface_id;
1072
1073 if (0 > prev || (uint32_t)prev != data->workspace_id) {
1074 nx = 0;
1075 ny = 0;
1076 prev = data->workspace_id;
1077
1078 if (0 <= prev)
1079 hmi_ctrl->workspace_count++;
1080 }
1081
1082 if (y_count == ny) {
1083 ny = 0;
1084 hmi_ctrl->workspace_count++;
1085 }
1086
1087 x = nx * fcell_size_x + (hmi_ctrl->workspace_count - 1) * width + space_x;
1088 y = ny * fcell_size_y + space_y;
1089
1090 layout_surface =
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001091 ivi_controller_interface->get_surface_from_id(data->surface_id);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001092 assert(layout_surface);
1093
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001094 ret = ivi_controller_interface->layer_add_surface(layer, layout_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001095 assert(!ret);
1096
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001097 ret = ivi_controller_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001098 layout_surface, x, y, icon_size, icon_size);
1099 assert(!ret);
1100
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001101 ret = ivi_controller_interface->surface_set_visibility(layout_surface, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001102 assert(!ret);
1103
1104 nx++;
1105
1106 if (x_count == nx) {
1107 ny++;
1108 nx = 0;
1109 }
1110 }
1111
1112 wl_array_release(&launchers);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001113 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001114}
1115
1116static void
1117ivi_hmi_controller_UI_ready(struct wl_client *client,
1118 struct wl_resource *resource)
1119{
1120 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1121
1122 ivi_hmi_controller_set_background(hmi_ctrl, hmi_ctrl->ui_setting.background_id);
1123 ivi_hmi_controller_set_panel(hmi_ctrl, hmi_ctrl->ui_setting.panel_id);
1124 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.tiling_id, 0);
1125 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.sidebyside_id, 1);
1126 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.fullscreen_id, 2);
1127 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.random_id, 3);
1128 ivi_hmi_controller_set_home_button(hmi_ctrl, hmi_ctrl->ui_setting.home_id);
1129 ivi_hmi_controller_set_workspacebackground(hmi_ctrl, hmi_ctrl->ui_setting.workspace_background_id);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001130 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001131
1132 ivi_hmi_controller_add_launchers(hmi_ctrl, 256);
1133 hmi_ctrl->is_initialized = 1;
1134}
1135
1136/**
1137 * Implementation of request and event of ivi_hmi_controller_workspace_control
1138 * and controlling workspace.
1139 *
1140 * When motion of input is detected in a ivi_surface of workspace background,
1141 * ivi_hmi_controller_workspace_control shall be invoked and to start
1142 * controlling of workspace. The workspace has several pages to show several
1143 * groups of applications.
1144 * The workspace is slid by using ivi-layout to select a a page in layer_set_pos
1145 * according to motion. When motion finished, e.g. touch up detected, control is
1146 * terminated and event:ivi_hmi_controller_workspace_control is notified.
1147 */
1148struct pointer_grab {
1149 struct weston_pointer_grab grab;
1150 struct ivi_layout_layer *layer;
1151 struct wl_resource *resource;
1152};
1153
1154struct touch_grab {
1155 struct weston_touch_grab grab;
1156 struct ivi_layout_layer *layer;
1157 struct wl_resource *resource;
1158};
1159
1160struct move_grab {
1161 wl_fixed_t dst[2];
1162 wl_fixed_t rgn[2][2];
1163 double v[2];
1164 struct timespec start_time;
1165 struct timespec pre_time;
1166 wl_fixed_t start_pos[2];
1167 wl_fixed_t pos[2];
1168 int32_t is_moved;
1169};
1170
1171struct pointer_move_grab {
1172 struct pointer_grab base;
1173 struct move_grab move;
1174};
1175
1176struct touch_move_grab {
1177 struct touch_grab base;
1178 struct move_grab move;
1179 int32_t is_active;
1180};
1181
1182static void
1183pointer_grab_start(struct pointer_grab *grab,
1184 struct ivi_layout_layer *layer,
1185 const struct weston_pointer_grab_interface *interface,
1186 struct weston_pointer *pointer)
1187{
1188 grab->grab.interface = interface;
1189 grab->layer = layer;
1190 weston_pointer_start_grab(pointer, &grab->grab);
1191}
1192
1193static void
1194touch_grab_start(struct touch_grab *grab,
1195 struct ivi_layout_layer *layer,
1196 const struct weston_touch_grab_interface *interface,
1197 struct weston_touch* touch)
1198{
1199 grab->grab.interface = interface;
1200 grab->layer = layer;
1201 weston_touch_start_grab(touch, &grab->grab);
1202}
1203
1204static int32_t
1205clamp(int32_t val, int32_t min, int32_t max)
1206{
1207 if (val < min)
1208 return min;
1209
1210 if (max < val)
1211 return max;
1212
1213 return val;
1214}
1215
1216static void
1217move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource,
1218 wl_fixed_t grab_x, struct ivi_layout_layer *layer)
1219{
1220 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1221 int32_t width = hmi_ctrl->workspace_background_layer.width;
1222
1223 struct timespec time = {0};
1224 double grab_time = 0.0;
1225 double from_motion_time = 0.0;
1226 double pointer_v = 0.0;
1227 int32_t is_flick = 0;
1228 int32_t pos_x = 0;
1229 int32_t pos_y = 0;
1230 int page_no = 0;
1231 double end_pos = 0.0;
1232 uint32_t duration = 0;
1233
1234 clock_gettime(CLOCK_MONOTONIC, &time);
1235
1236 grab_time = 1e+3 * (time.tv_sec - move->start_time.tv_sec) +
1237 1e-6 * (time.tv_nsec - move->start_time.tv_nsec);
1238
1239 from_motion_time = 1e+3 * (time.tv_sec - move->pre_time.tv_sec) +
1240 1e-6 * (time.tv_nsec - move->pre_time.tv_nsec);
1241
1242 pointer_v = move->v[0];
1243
1244 is_flick = grab_time < 400 && 0.4 < fabs(pointer_v);
1245 if (200 < from_motion_time)
1246 pointer_v = 0.0;
1247
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001248 ivi_controller_interface->layer_get_position(layer, &pos_x, &pos_y);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001249
1250
1251 if (is_flick) {
1252 int orgx = wl_fixed_to_int(move->dst[0] + grab_x);
1253 page_no = (-orgx + width / 2) / width;
1254
1255 if (pointer_v < 0.0)
1256 page_no++;
1257 else
1258 page_no--;
1259 } else {
1260 page_no = (-pos_x + width / 2) / width;
1261 }
1262
1263 page_no = clamp(page_no, 0, hmi_ctrl->workspace_count - 1);
1264 end_pos = -page_no * width;
1265
1266 duration = hmi_ctrl->hmi_setting->transition_duration;
1267 ivi_hmi_controller_send_workspace_end_control(resource, move->is_moved);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001268 ivi_controller_interface->layer_set_transition(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001269 IVI_LAYOUT_TRANSITION_LAYER_MOVE,
1270 duration);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001271 ivi_controller_interface->layer_set_destination_rectangle(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001272 end_pos, pos_y,
1273 hmi_ctrl->workspace_background_layer.width,
1274 hmi_ctrl->workspace_background_layer.height);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001275 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001276}
1277
1278static void
1279pointer_move_workspace_grab_end(struct pointer_grab *grab)
1280{
1281 struct pointer_move_grab *pnt_move_grab =
1282 (struct pointer_move_grab *)grab;
1283 struct ivi_layout_layer *layer = pnt_move_grab->base.layer;
1284
1285 move_workspace_grab_end(&pnt_move_grab->move, grab->resource,
1286 grab->grab.pointer->grab_x, layer);
1287
1288 weston_pointer_end_grab(grab->grab.pointer);
1289}
1290
1291static void
1292touch_move_workspace_grab_end(struct touch_grab *grab)
1293{
1294 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1295 struct ivi_layout_layer *layer = tch_move_grab->base.layer;
1296
1297 move_workspace_grab_end(&tch_move_grab->move, grab->resource,
1298 grab->grab.touch->grab_x, layer);
1299
1300 weston_touch_end_grab(grab->grab.touch);
1301}
1302
1303static void
1304pointer_noop_grab_focus(struct weston_pointer_grab *grab)
1305{
1306}
1307
1308static void
1309move_grab_update(struct move_grab *move, wl_fixed_t pointer[2])
1310{
1311 struct timespec timestamp = {0};
1312 int32_t ii = 0;
1313 double dt = 0.0;
1314
1315 clock_gettime(CLOCK_MONOTONIC, &timestamp); //FIXME
1316 dt = (1e+3 * (timestamp.tv_sec - move->pre_time.tv_sec) +
1317 1e-6 * (timestamp.tv_nsec - move->pre_time.tv_nsec));
1318
1319 if (dt < 1e-6)
1320 dt = 1e-6;
1321
1322 move->pre_time = timestamp;
1323
1324 for (ii = 0; ii < 2; ii++) {
1325 wl_fixed_t prepos = move->pos[ii];
1326 move->pos[ii] = pointer[ii] + move->dst[ii];
1327
1328 if (move->pos[ii] < move->rgn[0][ii]) {
1329 move->pos[ii] = move->rgn[0][ii];
1330 move->dst[ii] = move->pos[ii] - pointer[ii];
1331 } else if (move->rgn[1][ii] < move->pos[ii]) {
1332 move->pos[ii] = move->rgn[1][ii];
1333 move->dst[ii] = move->pos[ii] - pointer[ii];
1334 }
1335
1336 move->v[ii] = wl_fixed_to_double(move->pos[ii] - prepos) / dt;
1337
1338 if (!move->is_moved &&
1339 0 < wl_fixed_to_int(move->pos[ii] - move->start_pos[ii]))
1340 move->is_moved = 1;
1341 }
1342}
1343
1344static void
1345layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
1346 wl_fixed_t pos_y)
1347{
1348 int32_t layout_pos_x = 0;
1349 int32_t layout_pos_y = 0;
1350
1351 layout_pos_x = wl_fixed_to_int(pos_x);
1352 layout_pos_y = wl_fixed_to_int(pos_y);
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001353 ivi_controller_interface->layer_set_position(layer, layout_pos_x, layout_pos_y);
1354 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001355}
1356
1357static void
1358pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1359 wl_fixed_t x, wl_fixed_t y)
1360{
1361 struct pointer_move_grab *pnt_move_grab =
1362 (struct pointer_move_grab *)grab;
1363 wl_fixed_t pointer_pos[2] = {x, y};
1364
1365 move_grab_update(&pnt_move_grab->move, pointer_pos);
1366 layer_set_pos(pnt_move_grab->base.layer,
1367 pnt_move_grab->move.pos[0], pnt_move_grab->move.pos[1]);
1368 weston_pointer_move(pnt_move_grab->base.grab.pointer, x, y);
1369}
1370
1371static void
1372touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1373 int touch_id, wl_fixed_t x, wl_fixed_t y)
1374{
1375 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1376
1377 if (!tch_move_grab->is_active)
1378 return;
1379
1380 wl_fixed_t pointer_pos[2] = {
1381 grab->touch->grab_x,
1382 grab->touch->grab_y
1383 };
1384
1385 move_grab_update(&tch_move_grab->move, pointer_pos);
1386 layer_set_pos(tch_move_grab->base.layer,
1387 tch_move_grab->move.pos[0], tch_move_grab->move.pos[1]);
1388}
1389
1390static void
1391pointer_move_workspace_grab_button(struct weston_pointer_grab *grab,
1392 uint32_t time, uint32_t button,
1393 uint32_t state_w)
1394{
1395 if (BTN_LEFT == button &&
1396 WL_POINTER_BUTTON_STATE_RELEASED == state_w) {
1397 struct pointer_grab *pg = (struct pointer_grab *)grab;
1398
1399 pointer_move_workspace_grab_end(pg);
1400 free(grab);
1401 }
1402}
1403
1404static void
1405touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
1406 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1407{
1408}
1409
1410static void
1411touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time,
1412 int touch_id)
1413{
1414 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1415
1416 if (0 == touch_id)
1417 tch_move_grab->is_active = 0;
1418
1419 if (0 == grab->touch->num_tp) {
1420 touch_move_workspace_grab_end(&tch_move_grab->base);
1421 free(grab);
1422 }
1423}
1424
1425static void
1426pointer_move_workspace_grab_cancel(struct weston_pointer_grab *grab)
1427{
1428 struct pointer_grab *pg = (struct pointer_grab *)grab;
1429
1430 pointer_move_workspace_grab_end(pg);
1431 free(grab);
1432}
1433
1434static void
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001435touch_move_workspace_grab_frame(struct weston_touch_grab *grab)
1436{
1437}
1438
1439static void
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001440touch_move_workspace_grab_cancel(struct weston_touch_grab *grab)
1441{
1442 struct touch_grab *tg = (struct touch_grab *)grab;
1443
1444 touch_move_workspace_grab_end(tg);
1445 free(grab);
1446}
1447
1448static const struct weston_pointer_grab_interface pointer_move_grab_workspace_interface = {
1449 pointer_noop_grab_focus,
1450 pointer_move_grab_motion,
1451 pointer_move_workspace_grab_button,
1452 pointer_move_workspace_grab_cancel
1453};
1454
1455static const struct weston_touch_grab_interface touch_move_grab_workspace_interface = {
1456 touch_nope_grab_down,
1457 touch_move_workspace_grab_up,
1458 touch_move_grab_motion,
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001459 touch_move_workspace_grab_frame,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001460 touch_move_workspace_grab_cancel
1461};
1462
1463enum HMI_GRAB_DEVICE {
1464 HMI_GRAB_DEVICE_NONE,
1465 HMI_GRAB_DEVICE_POINTER,
1466 HMI_GRAB_DEVICE_TOUCH
1467};
1468
1469static enum HMI_GRAB_DEVICE
1470get_hmi_grab_device(struct weston_seat *seat, uint32_t serial)
1471{
Derek Foreman1281a362015-07-31 16:55:32 -05001472 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
1473 struct weston_touch *touch = weston_seat_get_touch(seat);
1474
1475 if (pointer &&
1476 pointer->focus &&
1477 pointer->button_count &&
1478 pointer->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001479 return HMI_GRAB_DEVICE_POINTER;
1480
Derek Foreman1281a362015-07-31 16:55:32 -05001481 if (touch &&
1482 touch->focus &&
1483 touch->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001484 return HMI_GRAB_DEVICE_TOUCH;
1485
1486 return HMI_GRAB_DEVICE_NONE;
1487}
1488
1489static void
1490move_grab_init(struct move_grab* move, wl_fixed_t start_pos[2],
1491 wl_fixed_t grab_pos[2], wl_fixed_t rgn[2][2],
1492 struct wl_resource* resource)
1493{
1494 clock_gettime(CLOCK_MONOTONIC, &move->start_time); //FIXME
1495 move->pre_time = move->start_time;
1496 move->pos[0] = start_pos[0];
1497 move->pos[1] = start_pos[1];
1498 move->start_pos[0] = start_pos[0];
1499 move->start_pos[1] = start_pos[1];
1500 move->dst[0] = start_pos[0] - grab_pos[0];
1501 move->dst[1] = start_pos[1] - grab_pos[1];
1502 memcpy(move->rgn, rgn, sizeof(move->rgn));
1503}
1504
1505static void
1506move_grab_init_workspace(struct move_grab* move,
1507 wl_fixed_t grab_x, wl_fixed_t grab_y,
1508 struct wl_resource *resource)
1509{
1510 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1511 struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
1512 int32_t workspace_count = hmi_ctrl->workspace_count;
1513 int32_t workspace_width = hmi_ctrl->workspace_background_layer.width;
1514 int32_t layer_pos_x = 0;
1515 int32_t layer_pos_y = 0;
1516 wl_fixed_t start_pos[2] = {0};
1517 wl_fixed_t rgn[2][2] = {{0}};
1518 wl_fixed_t grab_pos[2] = { grab_x, grab_y };
1519
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001520 ivi_controller_interface->layer_get_position(layer, &layer_pos_x, &layer_pos_y);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001521
1522 start_pos[0] = wl_fixed_from_int(layer_pos_x);
1523 start_pos[1] = wl_fixed_from_int(layer_pos_y);
1524
1525 rgn[0][0] = wl_fixed_from_int(-workspace_width * (workspace_count - 1));
1526
1527 rgn[0][1] = wl_fixed_from_int(0);
1528 rgn[1][0] = wl_fixed_from_int(0);
1529 rgn[1][1] = wl_fixed_from_int(0);
1530
1531 move_grab_init(move, start_pos, grab_pos, rgn, resource);
1532}
1533
1534static struct pointer_move_grab *
1535create_workspace_pointer_move(struct weston_pointer *pointer,
1536 struct wl_resource* resource)
1537{
1538 struct pointer_move_grab *pnt_move_grab =
1539 MEM_ALLOC(sizeof(*pnt_move_grab));
1540
1541 pnt_move_grab->base.resource = resource;
1542 move_grab_init_workspace(&pnt_move_grab->move, pointer->grab_x,
1543 pointer->grab_y, resource);
1544
1545 return pnt_move_grab;
1546}
1547
1548static struct touch_move_grab *
1549create_workspace_touch_move(struct weston_touch *touch,
1550 struct wl_resource* resource)
1551{
1552 struct touch_move_grab *tch_move_grab =
1553 MEM_ALLOC(sizeof(*tch_move_grab));
1554
1555 tch_move_grab->base.resource = resource;
1556 tch_move_grab->is_active = 1;
1557 move_grab_init_workspace(&tch_move_grab->move, touch->grab_x,
1558 touch->grab_y, resource);
1559
1560 return tch_move_grab;
1561}
1562
1563static void
1564ivi_hmi_controller_workspace_control(struct wl_client *client,
1565 struct wl_resource *resource,
1566 struct wl_resource *seat_resource,
1567 uint32_t serial)
1568{
1569 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1570 struct ivi_layout_layer *layer = NULL;
1571 struct pointer_move_grab *pnt_move_grab = NULL;
1572 struct touch_move_grab *tch_move_grab = NULL;
1573 struct weston_seat *seat = NULL;
Derek Foreman1281a362015-07-31 16:55:32 -05001574 struct weston_pointer *pointer;
1575 struct weston_touch *touch;
1576
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001577 enum HMI_GRAB_DEVICE device;
1578
1579 if (hmi_ctrl->workspace_count < 2)
1580 return;
1581
1582 seat = wl_resource_get_user_data(seat_resource);
1583 device = get_hmi_grab_device(seat, serial);
1584
1585 if (HMI_GRAB_DEVICE_POINTER != device &&
1586 HMI_GRAB_DEVICE_TOUCH != device)
1587 return;
1588
1589 layer = hmi_ctrl->workspace_layer.ivilayer;
1590
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001591 ivi_controller_interface->transition_move_layer_cancel(layer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001592
1593 switch (device) {
1594 case HMI_GRAB_DEVICE_POINTER:
Derek Foreman1281a362015-07-31 16:55:32 -05001595 pointer = weston_seat_get_pointer(seat);
1596 pnt_move_grab = create_workspace_pointer_move(pointer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001597 resource);
1598
1599 pointer_grab_start(&pnt_move_grab->base, layer,
1600 &pointer_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001601 pointer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001602 break;
1603
1604 case HMI_GRAB_DEVICE_TOUCH:
Derek Foreman1281a362015-07-31 16:55:32 -05001605 touch = weston_seat_get_touch(seat);
1606 tch_move_grab = create_workspace_touch_move(touch,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001607 resource);
1608
1609 touch_grab_start(&tch_move_grab->base, layer,
1610 &touch_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001611 touch);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001612 break;
1613
1614 default:
1615 break;
1616 }
1617}
1618
1619/**
1620 * Implementation of switch_mode
1621 */
1622static void
1623ivi_hmi_controller_switch_mode(struct wl_client *client,
1624 struct wl_resource *resource,
1625 uint32_t layout_mode)
1626{
1627 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1628
1629 switch_mode(hmi_ctrl, layout_mode);
1630}
1631
1632/**
1633 * Implementation of on/off displaying workspace and workspace background
1634 * ivi_layers.
1635 */
1636static void
1637ivi_hmi_controller_home(struct wl_client *client,
1638 struct wl_resource *resource,
1639 uint32_t home)
1640{
1641 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1642 uint32_t is_fade_in;
1643
1644 if ((IVI_HMI_CONTROLLER_HOME_ON == home &&
1645 !hmi_ctrl->workspace_fade.is_fade_in) ||
1646 (IVI_HMI_CONTROLLER_HOME_OFF == home &&
1647 hmi_ctrl->workspace_fade.is_fade_in)) {
1648 is_fade_in = !hmi_ctrl->workspace_fade.is_fade_in;
1649 hmi_controller_fade_run(hmi_ctrl, is_fade_in,
1650 &hmi_ctrl->workspace_fade);
1651 }
1652
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001653 ivi_controller_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001654}
1655
1656/**
1657 * binding ivi-hmi-controller implementation
1658 */
1659static const struct ivi_hmi_controller_interface ivi_hmi_controller_implementation = {
1660 ivi_hmi_controller_UI_ready,
1661 ivi_hmi_controller_workspace_control,
1662 ivi_hmi_controller_switch_mode,
1663 ivi_hmi_controller_home
1664};
1665
1666static void
1667unbind_hmi_controller(struct wl_resource *resource)
1668{
1669}
1670
1671static void
1672bind_hmi_controller(struct wl_client *client,
1673 void *data, uint32_t version, uint32_t id)
1674{
1675 struct wl_resource *resource = NULL;
1676 struct hmi_controller *hmi_ctrl = data;
1677
1678 if (hmi_ctrl->user_interface != client) {
1679 struct wl_resource *res = wl_client_get_object(client, 1);
1680 wl_resource_post_error(res,
1681 WL_DISPLAY_ERROR_INVALID_OBJECT,
1682 "hmi-controller failed: permission denied");
1683 return;
1684 }
1685
1686 resource = wl_resource_create(
1687 client, &ivi_hmi_controller_interface, 1, id);
1688
1689 wl_resource_set_implementation(
1690 resource, &ivi_hmi_controller_implementation,
1691 hmi_ctrl, unbind_hmi_controller);
1692}
1693
1694static int32_t
1695initialize(struct hmi_controller *hmi_ctrl)
1696{
1697 struct config_command {
1698 char *key;
1699 uint32_t *dest;
1700 };
1701
1702 struct weston_config *config = hmi_ctrl->compositor->config;
1703 struct weston_config_section *section = NULL;
1704 int result = 0;
1705 int i = 0;
1706
1707 const struct config_command uint_commands[] = {
1708 { "background-id", &hmi_ctrl->ui_setting.background_id },
1709 { "panel-id", &hmi_ctrl->ui_setting.panel_id },
1710 { "tiling-id", &hmi_ctrl->ui_setting.tiling_id },
1711 { "sidebyside-id", &hmi_ctrl->ui_setting.sidebyside_id },
1712 { "fullscreen-id", &hmi_ctrl->ui_setting.fullscreen_id },
1713 { "random-id", &hmi_ctrl->ui_setting.random_id },
1714 { "home-id", &hmi_ctrl->ui_setting.home_id },
1715 { "workspace-background-id", &hmi_ctrl->ui_setting.workspace_background_id },
1716 { NULL, NULL }
1717 };
1718
1719 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1720
1721 for (i = 0; -1 != result; ++i) {
1722 const struct config_command *command = &uint_commands[i];
1723
1724 if (!command->key)
1725 break;
1726
1727 if (weston_config_section_get_uint(
1728 section, command->key, command->dest, 0) != 0)
1729 result = -1;
1730 }
1731
1732 if (-1 == result) {
1733 weston_log("Failed to initialize hmi-controller\n");
1734 return 0;
1735 }
1736
1737 return 1;
1738}
1739
1740static void
1741launch_hmi_client_process(void *data)
1742{
1743 struct hmi_controller *hmi_ctrl =
1744 (struct hmi_controller *)data;
1745
1746 hmi_ctrl->user_interface =
1747 weston_client_start(hmi_ctrl->compositor,
1748 hmi_ctrl->hmi_setting->ivi_homescreen);
1749
1750 free(hmi_ctrl->hmi_setting->ivi_homescreen);
1751}
1752
1753/*****************************************************************************
1754 * exported functions
1755 ****************************************************************************/
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001756WL_EXPORT int
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001757controller_module_init(struct weston_compositor *ec,
1758 int *argc, char *argv[],
1759 const struct ivi_controller_interface *interface,
1760 size_t interface_version)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001761{
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001762 struct hmi_controller *hmi_ctrl = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001763 struct wl_event_loop *loop = NULL;
1764
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001765 if (interface_version < sizeof(struct ivi_controller_interface)) {
1766 weston_log("ivi-shell: version mismatch of controller interface");
1767 return -1;
1768 }
1769
1770 ivi_controller_interface = interface;
1771
1772 hmi_ctrl = hmi_controller_create(ec);
1773
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001774 if (!initialize(hmi_ctrl)) {
1775 return -1;
1776 }
1777
1778 if (wl_global_create(ec->wl_display,
1779 &ivi_hmi_controller_interface, 1,
1780 hmi_ctrl, bind_hmi_controller) == NULL) {
1781 return -1;
1782 }
1783
1784 loop = wl_display_get_event_loop(ec->wl_display);
1785 wl_event_loop_add_idle(loop, launch_hmi_client_process, hmi_ctrl);
1786
1787 return 0;
1788}