blob: 0b932d621621baa8f48d7f0f1df185d513f537e1 [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"
Bryce Harringtone99e4bf2016-03-16 14:15:18 -070064#include "shared/xalloc.h"
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090065
66/*****************************************************************************
67 * structure, globals
68 ****************************************************************************/
69struct hmi_controller_layer {
70 struct ivi_layout_layer *ivilayer;
71 uint32_t id_layer;
72 int32_t x;
73 int32_t y;
74 int32_t width;
75 int32_t height;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +090076 struct wl_list link;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090077};
78
79struct link_layer {
80 struct ivi_layout_layer *layout_layer;
81 struct wl_list link;
82};
83
84struct hmi_controller_fade {
85 uint32_t is_fade_in;
86 struct wl_list layer_list;
87};
88
89struct hmi_server_setting {
90 uint32_t base_layer_id;
91 uint32_t application_layer_id;
92 uint32_t workspace_background_layer_id;
93 uint32_t workspace_layer_id;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +090094 uint32_t base_layer_id_offset;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +090095 int32_t panel_height;
96 uint32_t transition_duration;
97 char *ivi_homescreen;
98};
99
100struct ui_setting {
101 uint32_t background_id;
102 uint32_t panel_id;
103 uint32_t tiling_id;
104 uint32_t sidebyside_id;
105 uint32_t fullscreen_id;
106 uint32_t random_id;
107 uint32_t home_id;
108 uint32_t workspace_background_id;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900109 uint32_t surface_id_offset;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900110};
111
112struct hmi_controller {
113 struct hmi_server_setting *hmi_setting;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900114 /* List of struct hmi_controller_layer */
115 struct wl_list base_layer_list;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900116 struct wl_list application_layer_list;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900117 struct hmi_controller_layer workspace_background_layer;
118 struct hmi_controller_layer workspace_layer;
119 enum ivi_hmi_controller_layout_mode layout_mode;
120
121 struct hmi_controller_fade workspace_fade;
122
123 int32_t workspace_count;
124 struct wl_array ui_widgets;
125 int32_t is_initialized;
126
127 struct weston_compositor *compositor;
128 struct wl_listener destroy_listener;
129
130 struct wl_client *user_interface;
131 struct ui_setting ui_setting;
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900132
133 int32_t screen_num;
134 struct ivi_layout_screen **pp_screen;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900135};
136
137struct launcher_info {
138 uint32_t surface_id;
139 uint32_t workspace_id;
140 int32_t index;
141};
142
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000143const struct ivi_layout_interface *ivi_layout_interface;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900144
145int
146controller_module_init(struct weston_compositor *ec,
147 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000148 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900149 size_t interface_version);
150
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900151/*****************************************************************************
152 * local functions
153 ****************************************************************************/
154static void *
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900155mem_alloc(size_t size, char *file, int32_t line)
156{
157 return fail_on_null(calloc(1, size), size, file, line);
158}
159
160#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
161
162static int32_t
163is_surf_in_ui_widget(struct hmi_controller *hmi_ctrl,
164 struct ivi_layout_surface *ivisurf)
165{
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000166 uint32_t id = ivi_layout_interface->get_id_of_surface(ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900167
168 uint32_t *ui_widget_id = NULL;
169 wl_array_for_each(ui_widget_id, &hmi_ctrl->ui_widgets) {
170 if (*ui_widget_id == id)
171 return 1;
172 }
173
174 return 0;
175}
176
177static int
178compare_launcher_info(const void *lhs, const void *rhs)
179{
180 const struct launcher_info *left = lhs;
181 const struct launcher_info *right = rhs;
182
183 if (left->workspace_id < right->workspace_id)
184 return -1;
185
186 if (left->workspace_id > right->workspace_id)
187 return 1;
188
189 if (left->index < right->index)
190 return -1;
191
192 if (left->index > right->index)
193 return 1;
194
195 return 0;
196}
197
198/**
199 * Internal methods called by mainly ivi_hmi_controller_switch_mode
200 * This reference shows 4 examples how to use ivi_layout APIs.
201 */
202static void
203mode_divided_into_tiling(struct hmi_controller *hmi_ctrl,
204 struct ivi_layout_surface **pp_surface,
205 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900206 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900207{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900208 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900209 const float surface_width = (float)layer->width * 0.25;
210 const float surface_height = (float)layer->height * 0.5;
211 int32_t surface_x = 0;
212 int32_t surface_y = 0;
213 struct ivi_layout_surface *ivisurf = NULL;
214 struct ivi_layout_surface **surfaces;
215 struct ivi_layout_surface **new_order;
216 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900217 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900218
219 int32_t i = 0;
220 int32_t surf_num = 0;
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900221 int32_t idx = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900222
223 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
224 new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
225
226 for (i = 0; i < surface_length; i++) {
227 ivisurf = pp_surface[i];
228
229 /* skip ui widgets */
230 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
231 continue;
232
233 surfaces[surf_num++] = ivisurf;
234 }
235
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900236 wl_list_for_each_reverse(layer, layer_list, link) {
237 if (idx >= surf_num)
238 break;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900239
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900240 ivilayer = layer->ivilayer;
241
242 for (i = 0; i < 8; i++, idx++) {
243 if (idx >= surf_num)
244 break;
245
246 ivisurf = surfaces[idx];
247 new_order[i] = ivisurf;
248 if (i < 4) {
249 surface_x = (int32_t)(i * (surface_width));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900250 surface_y = 0;
251 } else {
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900252 surface_x = (int32_t)((i - 4) * (surface_width));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900253 surface_y = (int32_t)surface_height;
254 }
255
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000256 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900257 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
258 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000259 ivi_layout_interface->surface_set_visibility(ivisurf, true);
260 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900261 surface_x, surface_y,
262 (int32_t)surface_width,
263 (int32_t)surface_height);
264
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900265 }
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900266 ivi_layout_interface->layer_set_render_order(ivilayer, new_order, i);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900267
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900268 ivi_layout_interface->layer_set_transition(ivilayer,
269 IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER,
270 duration);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900271 }
Nobuhiko Tanibataa8aa91c2015-12-09 15:43:30 +0900272 for (i = idx; i < surf_num; i++)
273 ivi_layout_interface->surface_set_visibility(surfaces[i], false);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900274
275 free(surfaces);
276 free(new_order);
277}
278
279static void
280mode_divided_into_sidebyside(struct hmi_controller *hmi_ctrl,
281 struct ivi_layout_surface **pp_surface,
282 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900283 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900284{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900285 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900286 int32_t surface_width = layer->width / 2;
287 int32_t surface_height = layer->height;
288 struct ivi_layout_surface *ivisurf = NULL;
289
290 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
291 int32_t i = 0;
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900292 struct ivi_layout_surface **surfaces;
293 struct ivi_layout_surface **new_order;
294 struct ivi_layout_layer *ivilayer = NULL;
295 int32_t surf_num = 0;
296 int32_t idx = 0;
297
298 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
299 new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900300
301 for (i = 0; i < surface_length; i++) {
302 ivisurf = pp_surface[i];
303
304 /* skip ui widgets */
305 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
306 continue;
307
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900308 surfaces[surf_num++] = ivisurf;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900309 }
Nobuhiko Tanibatad156d9c2015-12-09 15:44:07 +0900310
311 wl_list_for_each_reverse(layer, layer_list, link) {
312 if (idx >= surf_num)
313 break;
314
315 ivilayer = layer->ivilayer;
316
317 for (i = 0; i < 2; i++, idx++) {
318 if (idx >= surf_num)
319 break;
320
321 ivisurf = surfaces[idx];
322 new_order[i] = ivisurf;
323
324 ivi_layout_interface->surface_set_transition(ivisurf,
325 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
326 duration);
327 ivi_layout_interface->surface_set_visibility(ivisurf, true);
328
329 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
330 i * surface_width, 0,
331 surface_width,
332 surface_height);
333 }
334 ivi_layout_interface->layer_set_render_order(ivilayer, new_order, i);
335 }
336
337 for (i = idx; i < surf_num; i++) {
338 ivi_layout_interface->surface_set_transition(surfaces[i],
339 IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY,
340 duration);
341 ivi_layout_interface->surface_set_visibility(surfaces[i], false);
342 }
343
344 free(surfaces);
345 free(new_order);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900346}
347
348static void
349mode_fullscreen_someone(struct hmi_controller *hmi_ctrl,
350 struct ivi_layout_surface **pp_surface,
351 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900352 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900353{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900354 struct hmi_controller_layer *layer = wl_container_of(layer_list->prev, layer, link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900355 const int32_t surface_width = layer->width;
356 const int32_t surface_height = layer->height;
357 struct ivi_layout_surface *ivisurf = NULL;
358 int32_t i = 0;
359 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900360 int32_t surf_num = 0;
361 struct ivi_layout_surface **surfaces;
362
363 surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900364
365 for (i = 0; i < surface_length; i++) {
366 ivisurf = pp_surface[i];
367
368 /* skip ui widgets */
369 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
370 continue;
371
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900372 surfaces[surf_num++] = ivisurf;
373 }
374 ivi_layout_interface->layer_set_render_order(layer->ivilayer, surfaces, surf_num);
375
376 for (i = 0; i < surf_num; i++) {
377 ivisurf = surfaces[i];
378
379 if ((i > 0) && (i < hmi_ctrl->screen_num)) {
380 layer = wl_container_of(layer->link.prev, layer, link);
381 ivi_layout_interface->layer_set_render_order(layer->ivilayer, &ivisurf, 1);
382 }
383
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000384 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900385 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
386 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000387 ivi_layout_interface->surface_set_visibility(ivisurf, true);
388 ivi_layout_interface->surface_set_destination_rectangle(ivisurf, 0, 0,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900389 surface_width,
390 surface_height);
391 }
Nobuhiko Tanibataa7ffa682015-12-09 15:45:20 +0900392
393 free(surfaces);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900394}
395
396static void
397mode_random_replace(struct hmi_controller *hmi_ctrl,
398 struct ivi_layout_surface **pp_surface,
399 int32_t surface_length,
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900400 struct wl_list *layer_list)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900401{
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900402 struct hmi_controller_layer *application_layer = NULL;
403 struct hmi_controller_layer **layers = NULL;
404 int32_t surface_width = 0;
405 int32_t surface_height = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900406 int32_t surface_x = 0;
407 int32_t surface_y = 0;
408 struct ivi_layout_surface *ivisurf = NULL;
409 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
410 int32_t i = 0;
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900411 int32_t layer_idx = 0;
412
413 layers = MEM_ALLOC(sizeof(*layers) * hmi_ctrl->screen_num);
414
415 wl_list_for_each(application_layer, layer_list, link) {
416 layers[layer_idx] = application_layer;
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900417 layer_idx++;
418 }
419
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900420 for (i = 0; i < surface_length; i++) {
421 ivisurf = pp_surface[i];
422
423 /* skip ui widgets */
424 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
425 continue;
426
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900427 /* surface determined at random a layer that belongs */
428 layer_idx = rand() % hmi_ctrl->screen_num;
429
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000430 ivi_layout_interface->surface_set_transition(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900431 IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
432 duration);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900433
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000434 ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900435
436 surface_width = (int32_t)(layers[layer_idx]->width * 0.25f);
437 surface_height = (int32_t)(layers[layer_idx]->height * 0.25f);
438 surface_x = rand() % (layers[layer_idx]->width - surface_width);
439 surface_y = rand() % (layers[layer_idx]->height - surface_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900440
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000441 ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900442 surface_x,
443 surface_y,
444 surface_width,
445 surface_height);
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900446
447 ivi_layout_interface->layer_add_surface(layers[layer_idx]->ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900448 }
Nobuhiko Tanibata1c2201b2015-12-09 15:45:52 +0900449
450 free(layers);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900451}
452
453static int32_t
454has_application_surface(struct hmi_controller *hmi_ctrl,
455 struct ivi_layout_surface **pp_surface,
456 int32_t surface_length)
457{
458 struct ivi_layout_surface *ivisurf = NULL;
459 int32_t i = 0;
460
461 for (i = 0; i < surface_length; i++) {
462 ivisurf = pp_surface[i];
463
464 /* skip ui widgets */
465 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
466 continue;
467
468 return 1;
469 }
470
471 return 0;
472}
473
474/**
475 * Supports 4 example to layout of application ivi_surfaces;
476 * tiling, side by side, fullscreen, and random.
477 */
478static void
479switch_mode(struct hmi_controller *hmi_ctrl,
480 enum ivi_hmi_controller_layout_mode layout_mode)
481{
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900482 struct wl_list *layer = &hmi_ctrl->application_layer_list;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900483 struct ivi_layout_surface **pp_surface = NULL;
484 int32_t surface_length = 0;
485 int32_t ret = 0;
486
487 if (!hmi_ctrl->is_initialized)
488 return;
489
490 hmi_ctrl->layout_mode = layout_mode;
491
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000492 ret = ivi_layout_interface->get_surfaces(&surface_length, &pp_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900493 assert(!ret);
494
495 if (!has_application_surface(hmi_ctrl, pp_surface, surface_length)) {
496 free(pp_surface);
497 pp_surface = NULL;
498 return;
499 }
500
501 switch (layout_mode) {
502 case IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING:
503 mode_divided_into_tiling(hmi_ctrl, pp_surface, surface_length,
504 layer);
505 break;
506 case IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE:
507 mode_divided_into_sidebyside(hmi_ctrl, pp_surface,
508 surface_length, layer);
509 break;
510 case IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN:
511 mode_fullscreen_someone(hmi_ctrl, pp_surface, surface_length,
512 layer);
513 break;
514 case IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM:
515 mode_random_replace(hmi_ctrl, pp_surface, surface_length,
516 layer);
517 break;
518 }
519
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000520 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900521 free(pp_surface);
522}
523
524/**
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900525 * Internal method to get screens from weston core
526 * TODO: shall support hotplug of screens
527 */
528static int32_t
529get_screens(struct hmi_controller *hmi_ctrl)
530{
531 hmi_ctrl->pp_screen = NULL;
532 hmi_ctrl->screen_num = 0;
533 ivi_layout_interface->get_screens(&hmi_ctrl->screen_num, &hmi_ctrl->pp_screen);
534
535 if (hmi_ctrl->pp_screen == NULL)
536 return -1;
537 else
538 return 0;
539}
540
541/**
542 * Internal method to get ivi_layout_screen
543 */
544static struct ivi_layout_screen *
545get_screen(int32_t screen_idx, struct hmi_controller *hmi_ctrl)
546{
547 struct ivi_layout_screen *iviscrn = NULL;
548
549 if (screen_idx > hmi_ctrl->screen_num - 1)
550 weston_log("Invalid index. Return NULL\n");
551 else
552 iviscrn = hmi_ctrl->pp_screen[screen_idx];
553
554 return iviscrn;
555}
556
557/**
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900558 * Internal method for transition
559 */
560static void
561hmi_controller_fade_run(struct hmi_controller *hmi_ctrl, uint32_t is_fade_in,
562 struct hmi_controller_fade *fade)
563{
564 double tint = is_fade_in ? 1.0 : 0.0;
565 struct link_layer *linklayer = NULL;
566 const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
567
568 fade->is_fade_in = is_fade_in;
569
570 wl_list_for_each(linklayer, &fade->layer_list, link) {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000571 ivi_layout_interface->layer_set_transition(linklayer->layout_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900572 IVI_LAYOUT_TRANSITION_LAYER_FADE,
573 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000574 ivi_layout_interface->layer_set_fade_info(linklayer->layout_layer,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +0900575 is_fade_in, 1.0 - tint, tint);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900576 }
577}
578
579/**
580 * Internal method to create ivi_layer with hmi_controller_layer and
581 * add to a ivi_screen
582 */
583static void
584create_layer(struct ivi_layout_screen *iviscrn,
585 struct hmi_controller_layer *layer)
586{
587 int32_t ret = 0;
588
589 layer->ivilayer =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000590 ivi_layout_interface->layer_create_with_dimension(layer->id_layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900591 layer->width,
592 layer->height);
593 assert(layer->ivilayer != NULL);
594
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000595 ret = ivi_layout_interface->screen_add_layer(iviscrn, layer->ivilayer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900596 assert(!ret);
597
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000598 ret = ivi_layout_interface->layer_set_destination_rectangle(layer->ivilayer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900599 layer->x, layer->y,
600 layer->width,
601 layer->height);
602 assert(!ret);
603
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000604 ret = ivi_layout_interface->layer_set_visibility(layer->ivilayer, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900605 assert(!ret);
606}
607
608/**
609 * Internal set notification
610 */
611static void
612set_notification_create_surface(struct ivi_layout_surface *ivisurf,
613 void *userdata)
614{
615 struct hmi_controller *hmi_ctrl = userdata;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900616 struct hmi_controller_layer *layer_link =
617 wl_container_of(hmi_ctrl->application_layer_list.prev,
618 layer_link,
619 link);
620 struct ivi_layout_layer *application_layer = layer_link->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900621 int32_t ret = 0;
622
623 /* skip ui widgets */
624 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
625 return;
626
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000627 ret = ivi_layout_interface->layer_add_surface(application_layer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900628 assert(!ret);
629}
630
631static void
632set_notification_remove_surface(struct ivi_layout_surface *ivisurf,
633 void *userdata)
634{
635 struct hmi_controller *hmi_ctrl = userdata;
636
637 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
638}
639
640static void
641set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
642 void *userdata)
643{
644 struct hmi_controller *hmi_ctrl = userdata;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900645 struct hmi_controller_layer *layer_link = NULL;
646 struct ivi_layout_layer *application_layer = NULL;
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900647 struct weston_surface *surface;
Wataru Natsume9d8b4412016-03-03 19:56:52 +0900648 struct ivi_layout_surface **ivisurfs = NULL;
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900649 int32_t length = 0;
650 int32_t i;
651
652 /* return if the surface is not application content */
653 if (is_surf_in_ui_widget(hmi_ctrl, ivisurf)) {
654 return;
655 }
656
657 /*
658 * if application changes size of wl_buffer. The source rectangle shall be
659 * fit to the size.
660 */
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000661 surface = ivi_layout_interface->surface_get_weston_surface(ivisurf);
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900662 if (surface) {
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000663 ivi_layout_interface->surface_set_source_rectangle(
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900664 ivisurf, 0, 0, surface->width,
665 surface->height);
666 }
667
668 /*
669 * search if the surface is already added to layer.
670 * If not yet, it is newly invoded application to go to switch_mode.
671 */
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900672 wl_list_for_each_reverse(layer_link, &hmi_ctrl->application_layer_list, link) {
673 application_layer = layer_link->ivilayer;
674 ivi_layout_interface->get_surfaces_on_layer(application_layer,
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900675 &length, &ivisurfs);
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900676 for (i = 0; i < length; i++) {
677 if (ivisurf == ivisurfs[i]) {
678 /*
679 * if it is non new invoked application, just call
680 * commit_changes to apply source_rectangle.
681 */
682 ivi_layout_interface->commit_changes();
Wataru Natsume9d8b4412016-03-03 19:56:52 +0900683 free(ivisurfs);
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900684 return;
685 }
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900686 }
Wataru Natsume9d8b4412016-03-03 19:56:52 +0900687 free(ivisurfs);
688 ivisurfs = NULL;
Nobuhiko Tanibata65160dc2015-04-27 17:00:25 +0900689 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900690
691 switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
692}
693
694/**
695 * A hmi_controller used 4 ivi_layers to manage ivi_surfaces. The IDs of
696 * corresponding ivi_layer are defined in weston.ini. Default scene graph
697 * of ivi_layers are initialized in hmi_controller_create
698 */
699static struct hmi_server_setting *
700hmi_server_setting_create(struct weston_compositor *ec)
701{
702 struct hmi_server_setting *setting = MEM_ALLOC(sizeof(*setting));
703 struct weston_config *config = ec->config;
704 struct weston_config_section *shell_section = NULL;
705
706 shell_section = weston_config_get_section(config, "ivi-shell",
707 NULL, NULL);
708
709 weston_config_section_get_uint(shell_section, "base-layer-id",
710 &setting->base_layer_id, 1000);
711
712 weston_config_section_get_uint(shell_section,
713 "workspace-background-layer-id",
714 &setting->workspace_background_layer_id,
715 2000);
716
717 weston_config_section_get_uint(shell_section, "workspace-layer-id",
718 &setting->workspace_layer_id, 3000);
719
720 weston_config_section_get_uint(shell_section, "application-layer-id",
721 &setting->application_layer_id, 4000);
722
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900723 weston_config_section_get_uint(shell_section, "base-layer-id-offset",
724 &setting->base_layer_id_offset, 10000);
725
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900726 weston_config_section_get_uint(shell_section, "transition-duration",
727 &setting->transition_duration, 300);
728
729 setting->panel_height = 70;
730
731 weston_config_section_get_string(shell_section,
732 "ivi-shell-user-interface",
733 &setting->ivi_homescreen, NULL);
734
735 return setting;
736}
737
738static void
739hmi_controller_destroy(struct wl_listener *listener, void *data)
740{
741 struct link_layer *link = NULL;
742 struct link_layer *next = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900743 struct hmi_controller_layer *ctrl_layer_link = NULL;
744 struct hmi_controller_layer *ctrl_layer_next = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900745 struct hmi_controller *hmi_ctrl =
746 container_of(listener, struct hmi_controller, destroy_listener);
747
748 wl_list_for_each_safe(link, next,
749 &hmi_ctrl->workspace_fade.layer_list, link) {
750 wl_list_remove(&link->link);
751 free(link);
752 }
753
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900754 /* clear base_layer_list */
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900755 wl_list_for_each_safe(ctrl_layer_link, ctrl_layer_next,
756 &hmi_ctrl->base_layer_list, link) {
757 wl_list_remove(&ctrl_layer_link->link);
758 free(ctrl_layer_link);
759 }
760
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900761 /* clear application_layer_list */
762 wl_list_for_each_safe(ctrl_layer_link, ctrl_layer_next,
763 &hmi_ctrl->application_layer_list, link) {
764 wl_list_remove(&ctrl_layer_link->link);
765 free(ctrl_layer_link);
766 }
767
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900768 wl_array_release(&hmi_ctrl->ui_widgets);
769 free(hmi_ctrl->hmi_setting);
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900770 free(hmi_ctrl->pp_screen);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900771 free(hmi_ctrl);
772}
773
774/**
775 * This is a starting method called from module_init.
776 * This sets up scene graph of ivi_layers; base, application, workspace
777 * background, and workspace. These ivi_layers are created/added to
778 * ivi_screen in create_layer
779 *
780 * base: to group ivi_surfaces of panel and background
781 * application: to group ivi_surfaces of ivi_applications
782 * workspace background: to group a ivi_surface of background in workspace
783 * workspace: to group ivi_surfaces for launching ivi_applications
784 *
785 * ivi_layers of workspace background and workspace is set to invisible at
786 * first. The properties of it is updated with animation when
787 * ivi_hmi_controller_home is requested.
788 */
789static struct hmi_controller *
790hmi_controller_create(struct weston_compositor *ec)
791{
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900792 struct ivi_layout_screen *iviscrn = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900793 int32_t screen_width = 0;
794 int32_t screen_height = 0;
795 struct link_layer *tmp_link_layer = NULL;
796 int32_t panel_height = 0;
797 struct hmi_controller *hmi_ctrl = MEM_ALLOC(sizeof(*hmi_ctrl));
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900798 struct hmi_controller_layer *base_layer = NULL;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900799 struct hmi_controller_layer *application_layer = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900800
801 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900802
803 wl_array_init(&hmi_ctrl->ui_widgets);
804 hmi_ctrl->layout_mode = IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING;
805 hmi_ctrl->hmi_setting = hmi_server_setting_create(ec);
806 hmi_ctrl->compositor = ec;
807
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900808 /* TODO: shall support hotplug of screens */
809 if (get_screens(hmi_ctrl) < 0) {
810 weston_log("ivi-shell: Failed to get screens\n");
811 hmi_ctrl = NULL;
812 return hmi_ctrl;
813 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900814
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +0900815 iviscrn = get_screen(0, hmi_ctrl);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900816
817 /* init base ivi_layer*/
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900818 wl_list_init(&hmi_ctrl->base_layer_list);
819 for (i = 0; i < hmi_ctrl->screen_num; i++) {
820 ivi_layout_interface->get_screen_resolution(get_screen(i, hmi_ctrl),
821 &screen_width,
822 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900823
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900824 base_layer = MEM_ALLOC(1 * sizeof(struct hmi_controller_layer));
825 base_layer->x = 0;
826 base_layer->y = 0;
827 base_layer->width = screen_width;
828 base_layer->height = screen_height;
829 base_layer->id_layer =
830 hmi_ctrl->hmi_setting->base_layer_id +
831 (i * hmi_ctrl->hmi_setting->base_layer_id_offset);
832 wl_list_insert(&hmi_ctrl->base_layer_list, &base_layer->link);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900833
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900834 create_layer(get_screen(i, hmi_ctrl), base_layer);
835 }
836
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900837 panel_height = hmi_ctrl->hmi_setting->panel_height;
838
839 /* init application ivi_layer */
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900840 wl_list_init(&hmi_ctrl->application_layer_list);
841 for (i = 0; i < hmi_ctrl->screen_num; i++) {
842 ivi_layout_interface->get_screen_resolution(get_screen(i, hmi_ctrl),
843 &screen_width,
844 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900845
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900846 application_layer = MEM_ALLOC(1 * sizeof(struct hmi_controller_layer));
847 application_layer->x = 0;
848 application_layer->y = 0;
849 application_layer->width = screen_width;
850 application_layer->height = screen_height - panel_height;
851 application_layer->id_layer =
852 hmi_ctrl->hmi_setting->application_layer_id +
853 (i * hmi_ctrl->hmi_setting->base_layer_id_offset);
854 wl_list_insert(&hmi_ctrl->application_layer_list, &application_layer->link);
855
856 create_layer(get_screen(i, hmi_ctrl), application_layer);
857 }
858
859 ivi_layout_interface->get_screen_resolution(iviscrn, &screen_width,
860 &screen_height);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900861
862 /* init workspace background ivi_layer */
863 hmi_ctrl->workspace_background_layer.x = 0;
864 hmi_ctrl->workspace_background_layer.y = 0;
865 hmi_ctrl->workspace_background_layer.width = screen_width;
866 hmi_ctrl->workspace_background_layer.height =
867 screen_height - panel_height;
868
869 hmi_ctrl->workspace_background_layer.id_layer =
870 hmi_ctrl->hmi_setting->workspace_background_layer_id;
871
872 create_layer(iviscrn, &hmi_ctrl->workspace_background_layer);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000873 ivi_layout_interface->layer_set_opacity(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900874 hmi_ctrl->workspace_background_layer.ivilayer, 0);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000875 ivi_layout_interface->layer_set_visibility(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900876 hmi_ctrl->workspace_background_layer.ivilayer, false);
877
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900878
879 wl_list_init(&hmi_ctrl->workspace_fade.layer_list);
880 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900881 tmp_link_layer->layout_layer =
882 hmi_ctrl->workspace_background_layer.ivilayer;
883 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
884 &tmp_link_layer->link);
885
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000886 ivi_layout_interface->add_notification_create_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900887 set_notification_create_surface, hmi_ctrl);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000888 ivi_layout_interface->add_notification_remove_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900889 set_notification_remove_surface, hmi_ctrl);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +0000890 ivi_layout_interface->add_notification_configure_surface(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900891 set_notification_configure_surface, hmi_ctrl);
892
893 hmi_ctrl->destroy_listener.notify = hmi_controller_destroy;
894 wl_signal_add(&hmi_ctrl->compositor->destroy_signal,
895 &hmi_ctrl->destroy_listener);
896
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900897 return hmi_ctrl;
898}
899
900/**
901 * Implementations of ivi-hmi-controller.xml
902 */
903
904/**
905 * A ivi_surface drawing background is identified by id_surface.
906 * Properties of the ivi_surface is set by using ivi_layout APIs according to
907 * the scene graph of UI defined in hmi_controller_create.
908 *
909 * UI ivi_layer is used to add this ivi_surface.
910 */
911static void
912ivi_hmi_controller_set_background(struct hmi_controller *hmi_ctrl,
913 uint32_t id_surface)
914{
915 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900916 struct hmi_controller_layer *base_layer = NULL;
917 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibatad789c662015-12-09 15:42:46 +0900918 struct hmi_controller_layer *application_layer =
919 wl_container_of(hmi_ctrl->application_layer_list.prev,
920 application_layer,
921 link);
922 const int32_t dstx = application_layer->x;
923 const int32_t dsty = application_layer->y;
924 const int32_t width = application_layer->width;
925 const int32_t height = application_layer->height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900926 int32_t ret = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900927 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900928
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900929 wl_list_for_each_reverse(base_layer, &hmi_ctrl->base_layer_list, link) {
930 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
931 sizeof(*add_surface_id));
932 *add_surface_id = id_surface + (i * hmi_ctrl->ui_setting.surface_id_offset);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900933
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900934 ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900935
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900936 ivisurf = ivi_layout_interface->get_surface_from_id(*add_surface_id);
937 assert(ivisurf != NULL);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900938
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900939 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
940 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900941
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900942 ret = ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
943 dstx, dsty, width, height);
944 assert(!ret);
945
946 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
947 assert(!ret);
948
949 i++;
950 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900951}
952
953/**
954 * A ivi_surface drawing panel is identified by id_surface.
955 * Properties of the ivi_surface is set by using ivi_layout APIs according to
956 * the scene graph of UI defined in hmi_controller_create.
957 *
958 * UI ivi_layer is used to add this ivi_surface.
959 */
960static void
961ivi_hmi_controller_set_panel(struct hmi_controller *hmi_ctrl,
962 uint32_t id_surface)
963{
964 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900965 struct hmi_controller_layer *base_layer =
966 wl_container_of(hmi_ctrl->base_layer_list.prev,
967 base_layer,
968 link);
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900969 struct ivi_layout_layer *ivilayer = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +0900970 const int32_t width = base_layer->width;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900971 int32_t ret = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900972 int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900973 const int32_t dstx = 0;
974 int32_t dsty = 0;
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900975 int32_t i = 0;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900976
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900977 wl_list_for_each_reverse(base_layer, &hmi_ctrl->base_layer_list, link) {
978 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
979 sizeof(*add_surface_id));
980 *add_surface_id = id_surface + (i * hmi_ctrl->ui_setting.surface_id_offset);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900981
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900982 ivilayer = base_layer->ivilayer;
983 ivisurf = ivi_layout_interface->get_surface_from_id(*add_surface_id);
984 assert(ivisurf != NULL);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900985
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900986 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
987 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900988
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900989 dsty = base_layer->height - panel_height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900990
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900991 ret = ivi_layout_interface->surface_set_destination_rectangle(
992 ivisurf, dstx, dsty, width, panel_height);
993 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900994
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900995 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
996 assert(!ret);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +0900997
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +0900998 i++;
999 }
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001000}
1001
1002/**
1003 * A ivi_surface drawing buttons in panel is identified by id_surface.
1004 * It can set several buttons. Properties of the ivi_surface is set by
1005 * using ivi_layout APIs according to the scene graph of UI defined in
1006 * hmi_controller_create. Additionally, the position of it is shifted to
1007 * right when new one is requested.
1008 *
1009 * UI ivi_layer is used to add these ivi_surfaces.
1010 */
1011static void
1012ivi_hmi_controller_set_button(struct hmi_controller *hmi_ctrl,
1013 uint32_t id_surface, int32_t number)
1014{
1015 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001016 struct hmi_controller_layer *base_layer =
1017 wl_container_of(hmi_ctrl->base_layer_list.prev,
1018 base_layer,
1019 link);
1020 struct ivi_layout_layer *ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001021 const int32_t width = 48;
1022 const int32_t height = 48;
1023 int32_t ret = 0;
1024 int32_t panel_height = 0;
1025 int32_t dstx = 0;
1026 int32_t dsty = 0;
1027 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1028 sizeof(*add_surface_id));
1029 *add_surface_id = id_surface;
1030
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001031 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001032 assert(ivisurf != NULL);
1033
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001034 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001035 assert(!ret);
1036
1037 panel_height = hmi_ctrl->hmi_setting->panel_height;
1038
1039 dstx = (60 * number) + 15;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001040 dsty = (base_layer->height - panel_height) + 5;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001041
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001042 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001043 ivisurf,dstx, dsty, width, height);
1044 assert(!ret);
1045
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001046 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001047 assert(!ret);
1048}
1049
1050/**
1051 * A ivi_surface drawing home button in panel is identified by id_surface.
1052 * Properties of the ivi_surface is set by using ivi_layout APIs according to
1053 * the scene graph of UI defined in hmi_controller_create.
1054 *
1055 * UI ivi_layer is used to add these ivi_surfaces.
1056 */
1057static void
1058ivi_hmi_controller_set_home_button(struct hmi_controller *hmi_ctrl,
1059 uint32_t id_surface)
1060{
1061 struct ivi_layout_surface *ivisurf = NULL;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001062 struct hmi_controller_layer *base_layer =
1063 wl_container_of(hmi_ctrl->base_layer_list.prev,
1064 base_layer,
1065 link);
1066 struct ivi_layout_layer *ivilayer = base_layer->ivilayer;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001067 int32_t ret = 0;
1068 int32_t size = 48;
1069 int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
Nobuhiko Tanibata744b0302015-12-09 15:41:00 +09001070 const int32_t dstx = (base_layer->width - size) / 2;
1071 const int32_t dsty = (base_layer->height - panel_height) + 5;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001072
1073 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1074 sizeof(*add_surface_id));
1075 *add_surface_id = id_surface;
1076
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001077 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001078 assert(ivisurf != NULL);
1079
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001080 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001081 assert(!ret);
1082
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001083 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001084 ivisurf, dstx, dsty, size, size);
1085 assert(!ret);
1086
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001087 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001088 assert(!ret);
1089}
1090
1091/**
1092 * A ivi_surface drawing background of workspace is identified by id_surface.
1093 * Properties of the ivi_surface is set by using ivi_layout APIs according to
1094 * the scene graph of UI defined in hmi_controller_create.
1095 *
1096 * A ivi_layer of workspace_background is used to add this ivi_surface.
1097 */
1098static void
1099ivi_hmi_controller_set_workspacebackground(struct hmi_controller *hmi_ctrl,
1100 uint32_t id_surface)
1101{
1102 struct ivi_layout_surface *ivisurf = NULL;
1103 struct ivi_layout_layer *ivilayer = NULL;
1104 const int32_t width = hmi_ctrl->workspace_background_layer.width;
1105 const int32_t height = hmi_ctrl->workspace_background_layer.height;
1106 int32_t ret = 0;
1107
1108 uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1109 sizeof(*add_surface_id));
1110 *add_surface_id = id_surface;
1111 ivilayer = hmi_ctrl->workspace_background_layer.ivilayer;
1112
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001113 ivisurf = ivi_layout_interface->get_surface_from_id(id_surface);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001114 assert(ivisurf != NULL);
1115
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001116 ret = ivi_layout_interface->layer_add_surface(ivilayer, ivisurf);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001117 assert(!ret);
1118
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001119 ret = ivi_layout_interface->surface_set_destination_rectangle(ivisurf,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001120 0, 0, width, height);
1121 assert(!ret);
1122
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001123 ret = ivi_layout_interface->surface_set_visibility(ivisurf, true);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001124 assert(!ret);
1125}
1126
1127/**
1128 * A list of ivi_surfaces drawing launchers in workspace is identified by
1129 * id_surfaces. Properties of the ivi_surface is set by using ivi_layout
1130 * APIs according to the scene graph of UI defined in hmi_controller_create.
1131 *
1132 * The workspace can have several pages to group ivi_surfaces of launcher.
1133 * Each call of this interface increments a number of page to add a group
1134 * of ivi_surfaces
1135 */
1136static void
1137ivi_hmi_controller_add_launchers(struct hmi_controller *hmi_ctrl,
1138 int32_t icon_size)
1139{
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001140 int32_t minspace_x = 10;
1141 int32_t minspace_y = minspace_x;
1142
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001143 int32_t width = hmi_ctrl->workspace_background_layer.width;
1144 int32_t height = hmi_ctrl->workspace_background_layer.height;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001145
1146 int32_t x_count = (width - minspace_x) / (minspace_x + icon_size);
1147 int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count));
1148 float fcell_size_x = icon_size + space_x;
1149
1150 int32_t y_count = (height - minspace_y) / (minspace_y + icon_size);
1151 int32_t space_y = (int32_t)((height - y_count * icon_size) / (1.0 + y_count));
1152 float fcell_size_y = icon_size + space_y;
1153
1154 struct weston_config *config = NULL;
1155 struct weston_config_section *section = NULL;
1156 const char *name = NULL;
1157 int launcher_count = 0;
1158 struct wl_array launchers;
1159 int32_t nx = 0;
1160 int32_t ny = 0;
1161 int32_t prev = -1;
1162 struct launcher_info *data = NULL;
1163
1164 uint32_t surfaceid = 0;
1165 uint32_t workspaceid = 0;
1166 struct launcher_info *info = NULL;
1167
1168 int32_t x = 0;
1169 int32_t y = 0;
1170 int32_t ret = 0;
1171 struct ivi_layout_surface* layout_surface = NULL;
1172 uint32_t *add_surface_id = NULL;
1173
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001174 struct ivi_layout_screen *iviscrn = NULL;
1175 struct link_layer *tmp_link_layer = NULL;
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001176
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001177 if (0 == x_count)
1178 x_count = 1;
1179
1180 if (0 == y_count)
1181 y_count = 1;
1182
1183 config = hmi_ctrl->compositor->config;
1184 if (!config)
1185 return;
1186
1187 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1188 if (!section)
1189 return;
1190
1191 wl_array_init(&launchers);
1192
1193 while (weston_config_next_section(config, &section, &name)) {
1194 surfaceid = 0;
1195 workspaceid = 0;
1196 info = NULL;
1197 if (0 != strcmp(name, "ivi-launcher"))
1198 continue;
1199
1200 if (0 != weston_config_section_get_uint(section, "icon-id",
1201 &surfaceid, 0))
1202 continue;
1203
1204 if (0 != weston_config_section_get_uint(section,
1205 "workspace-id",
1206 &workspaceid, 0))
1207 continue;
1208
1209 info = wl_array_add(&launchers, sizeof(*info));
1210
1211 if (info) {
1212 info->surface_id = surfaceid;
1213 info->workspace_id = workspaceid;
1214 info->index = launcher_count;
1215 ++launcher_count;
1216 }
1217 }
1218
1219 qsort(launchers.data, launcher_count, sizeof(struct launcher_info),
1220 compare_launcher_info);
1221
1222 wl_array_for_each(data, &launchers) {
1223 x = 0;
1224 y = 0;
1225 ret = 0;
1226 layout_surface = NULL;
1227 add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
1228 sizeof(*add_surface_id));
1229
1230 *add_surface_id = data->surface_id;
1231
1232 if (0 > prev || (uint32_t)prev != data->workspace_id) {
1233 nx = 0;
1234 ny = 0;
1235 prev = data->workspace_id;
1236
1237 if (0 <= prev)
1238 hmi_ctrl->workspace_count++;
1239 }
1240
1241 if (y_count == ny) {
1242 ny = 0;
1243 hmi_ctrl->workspace_count++;
1244 }
1245
1246 x = nx * fcell_size_x + (hmi_ctrl->workspace_count - 1) * width + space_x;
1247 y = ny * fcell_size_y + space_y;
1248
1249 layout_surface =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001250 ivi_layout_interface->get_surface_from_id(data->surface_id);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001251 assert(layout_surface);
1252
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001253 ret = ivi_layout_interface->surface_set_destination_rectangle(
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001254 layout_surface, x, y, icon_size, icon_size);
1255 assert(!ret);
1256
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001257 nx++;
1258
1259 if (x_count == nx) {
1260 ny++;
1261 nx = 0;
1262 }
1263 }
1264
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001265 /* init workspace ivi_layer */
1266 hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
1267 hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
1268 hmi_ctrl->workspace_layer.width =
1269 hmi_ctrl->workspace_background_layer.width * hmi_ctrl->workspace_count;
1270 hmi_ctrl->workspace_layer.height =
1271 hmi_ctrl->workspace_background_layer.height;
1272 hmi_ctrl->workspace_layer.id_layer =
1273 hmi_ctrl->hmi_setting->workspace_layer_id;
1274
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +09001275 iviscrn = get_screen(0, hmi_ctrl);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001276 create_layer(iviscrn, &hmi_ctrl->workspace_layer);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001277 ivi_layout_interface->layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
1278 ivi_layout_interface->layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001279 false);
1280
1281 tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
1282 tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
1283 wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
1284 &tmp_link_layer->link);
1285
1286 /* Add surface to layer */
1287 wl_array_for_each(data, &launchers) {
1288 layout_surface =
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001289 ivi_layout_interface->get_surface_from_id(data->surface_id);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001290 assert(layout_surface);
1291
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001292 ret = ivi_layout_interface->layer_add_surface(hmi_ctrl->workspace_layer.ivilayer,
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001293 layout_surface);
1294 assert(!ret);
1295
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001296 ret = ivi_layout_interface->surface_set_visibility(layout_surface, true);
Nobuhiko Tanibatad290f882015-08-24 09:12:23 +09001297 assert(!ret);
1298 }
1299
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001300 wl_array_release(&launchers);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001301 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001302}
1303
1304static void
1305ivi_hmi_controller_UI_ready(struct wl_client *client,
1306 struct wl_resource *resource)
1307{
1308 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1309
1310 ivi_hmi_controller_set_background(hmi_ctrl, hmi_ctrl->ui_setting.background_id);
1311 ivi_hmi_controller_set_panel(hmi_ctrl, hmi_ctrl->ui_setting.panel_id);
1312 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.tiling_id, 0);
1313 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.sidebyside_id, 1);
1314 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.fullscreen_id, 2);
1315 ivi_hmi_controller_set_button(hmi_ctrl, hmi_ctrl->ui_setting.random_id, 3);
1316 ivi_hmi_controller_set_home_button(hmi_ctrl, hmi_ctrl->ui_setting.home_id);
1317 ivi_hmi_controller_set_workspacebackground(hmi_ctrl, hmi_ctrl->ui_setting.workspace_background_id);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001318 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001319
1320 ivi_hmi_controller_add_launchers(hmi_ctrl, 256);
1321 hmi_ctrl->is_initialized = 1;
1322}
1323
1324/**
1325 * Implementation of request and event of ivi_hmi_controller_workspace_control
1326 * and controlling workspace.
1327 *
1328 * When motion of input is detected in a ivi_surface of workspace background,
1329 * ivi_hmi_controller_workspace_control shall be invoked and to start
1330 * controlling of workspace. The workspace has several pages to show several
1331 * groups of applications.
1332 * The workspace is slid by using ivi-layout to select a a page in layer_set_pos
1333 * according to motion. When motion finished, e.g. touch up detected, control is
1334 * terminated and event:ivi_hmi_controller_workspace_control is notified.
1335 */
1336struct pointer_grab {
1337 struct weston_pointer_grab grab;
1338 struct ivi_layout_layer *layer;
1339 struct wl_resource *resource;
1340};
1341
1342struct touch_grab {
1343 struct weston_touch_grab grab;
1344 struct ivi_layout_layer *layer;
1345 struct wl_resource *resource;
1346};
1347
1348struct move_grab {
1349 wl_fixed_t dst[2];
1350 wl_fixed_t rgn[2][2];
1351 double v[2];
1352 struct timespec start_time;
1353 struct timespec pre_time;
1354 wl_fixed_t start_pos[2];
1355 wl_fixed_t pos[2];
1356 int32_t is_moved;
1357};
1358
1359struct pointer_move_grab {
1360 struct pointer_grab base;
1361 struct move_grab move;
1362};
1363
1364struct touch_move_grab {
1365 struct touch_grab base;
1366 struct move_grab move;
1367 int32_t is_active;
1368};
1369
1370static void
1371pointer_grab_start(struct pointer_grab *grab,
1372 struct ivi_layout_layer *layer,
1373 const struct weston_pointer_grab_interface *interface,
1374 struct weston_pointer *pointer)
1375{
1376 grab->grab.interface = interface;
1377 grab->layer = layer;
1378 weston_pointer_start_grab(pointer, &grab->grab);
1379}
1380
1381static void
1382touch_grab_start(struct touch_grab *grab,
1383 struct ivi_layout_layer *layer,
1384 const struct weston_touch_grab_interface *interface,
1385 struct weston_touch* touch)
1386{
1387 grab->grab.interface = interface;
1388 grab->layer = layer;
1389 weston_touch_start_grab(touch, &grab->grab);
1390}
1391
1392static int32_t
1393clamp(int32_t val, int32_t min, int32_t max)
1394{
1395 if (val < min)
1396 return min;
1397
1398 if (max < val)
1399 return max;
1400
1401 return val;
1402}
1403
1404static void
1405move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource,
1406 wl_fixed_t grab_x, struct ivi_layout_layer *layer)
1407{
1408 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1409 int32_t width = hmi_ctrl->workspace_background_layer.width;
Ucan, Emre \(ADITG/SW1\)dfc2d762016-03-04 12:50:24 +00001410 const struct ivi_layout_layer_properties *prop;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001411
1412 struct timespec time = {0};
1413 double grab_time = 0.0;
1414 double from_motion_time = 0.0;
1415 double pointer_v = 0.0;
1416 int32_t is_flick = 0;
1417 int32_t pos_x = 0;
1418 int32_t pos_y = 0;
1419 int page_no = 0;
1420 double end_pos = 0.0;
1421 uint32_t duration = 0;
1422
1423 clock_gettime(CLOCK_MONOTONIC, &time);
1424
1425 grab_time = 1e+3 * (time.tv_sec - move->start_time.tv_sec) +
1426 1e-6 * (time.tv_nsec - move->start_time.tv_nsec);
1427
1428 from_motion_time = 1e+3 * (time.tv_sec - move->pre_time.tv_sec) +
1429 1e-6 * (time.tv_nsec - move->pre_time.tv_nsec);
1430
1431 pointer_v = move->v[0];
1432
1433 is_flick = grab_time < 400 && 0.4 < fabs(pointer_v);
1434 if (200 < from_motion_time)
1435 pointer_v = 0.0;
1436
Ucan, Emre \(ADITG/SW1\)dfc2d762016-03-04 12:50:24 +00001437 prop = ivi_layout_interface->get_properties_of_layer(layer);
1438 pos_x = prop->dest_x;
1439 pos_y = prop->dest_y;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001440
1441 if (is_flick) {
1442 int orgx = wl_fixed_to_int(move->dst[0] + grab_x);
1443 page_no = (-orgx + width / 2) / width;
1444
1445 if (pointer_v < 0.0)
1446 page_no++;
1447 else
1448 page_no--;
1449 } else {
1450 page_no = (-pos_x + width / 2) / width;
1451 }
1452
1453 page_no = clamp(page_no, 0, hmi_ctrl->workspace_count - 1);
1454 end_pos = -page_no * width;
1455
1456 duration = hmi_ctrl->hmi_setting->transition_duration;
1457 ivi_hmi_controller_send_workspace_end_control(resource, move->is_moved);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001458 ivi_layout_interface->layer_set_transition(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001459 IVI_LAYOUT_TRANSITION_LAYER_MOVE,
1460 duration);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001461 ivi_layout_interface->layer_set_destination_rectangle(layer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001462 end_pos, pos_y,
Nobuhiko Tanibata4412cd12015-08-24 09:12:37 +09001463 hmi_ctrl->workspace_layer.width,
1464 hmi_ctrl->workspace_layer.height);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001465 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001466}
1467
1468static void
1469pointer_move_workspace_grab_end(struct pointer_grab *grab)
1470{
1471 struct pointer_move_grab *pnt_move_grab =
1472 (struct pointer_move_grab *)grab;
1473 struct ivi_layout_layer *layer = pnt_move_grab->base.layer;
1474
1475 move_workspace_grab_end(&pnt_move_grab->move, grab->resource,
1476 grab->grab.pointer->grab_x, layer);
1477
1478 weston_pointer_end_grab(grab->grab.pointer);
1479}
1480
1481static void
1482touch_move_workspace_grab_end(struct touch_grab *grab)
1483{
1484 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1485 struct ivi_layout_layer *layer = tch_move_grab->base.layer;
1486
1487 move_workspace_grab_end(&tch_move_grab->move, grab->resource,
1488 grab->grab.touch->grab_x, layer);
1489
1490 weston_touch_end_grab(grab->grab.touch);
1491}
1492
1493static void
1494pointer_noop_grab_focus(struct weston_pointer_grab *grab)
1495{
1496}
1497
1498static void
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001499pointer_default_grab_axis(struct weston_pointer_grab *grab,
Peter Hutterer89b6a492016-01-18 15:58:17 +10001500 uint32_t time,
1501 struct weston_pointer_axis_event *event)
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001502{
Peter Hutterer89b6a492016-01-18 15:58:17 +10001503 weston_pointer_send_axis(grab->pointer, time, event);
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001504}
1505
1506static void
Peter Hutterer87743e92016-01-18 16:38:22 +10001507pointer_default_grab_axis_source(struct weston_pointer_grab *grab,
1508 uint32_t source)
1509{
1510 weston_pointer_send_axis_source(grab->pointer, source);
1511}
1512
1513static void
1514pointer_default_grab_frame(struct weston_pointer_grab *grab)
1515{
1516 weston_pointer_send_frame(grab->pointer);
1517}
1518
1519static void
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001520move_grab_update(struct move_grab *move, wl_fixed_t pointer[2])
1521{
1522 struct timespec timestamp = {0};
1523 int32_t ii = 0;
1524 double dt = 0.0;
1525
1526 clock_gettime(CLOCK_MONOTONIC, &timestamp); //FIXME
1527 dt = (1e+3 * (timestamp.tv_sec - move->pre_time.tv_sec) +
1528 1e-6 * (timestamp.tv_nsec - move->pre_time.tv_nsec));
1529
1530 if (dt < 1e-6)
1531 dt = 1e-6;
1532
1533 move->pre_time = timestamp;
1534
1535 for (ii = 0; ii < 2; ii++) {
1536 wl_fixed_t prepos = move->pos[ii];
1537 move->pos[ii] = pointer[ii] + move->dst[ii];
1538
1539 if (move->pos[ii] < move->rgn[0][ii]) {
1540 move->pos[ii] = move->rgn[0][ii];
1541 move->dst[ii] = move->pos[ii] - pointer[ii];
1542 } else if (move->rgn[1][ii] < move->pos[ii]) {
1543 move->pos[ii] = move->rgn[1][ii];
1544 move->dst[ii] = move->pos[ii] - pointer[ii];
1545 }
1546
1547 move->v[ii] = wl_fixed_to_double(move->pos[ii] - prepos) / dt;
1548
1549 if (!move->is_moved &&
1550 0 < wl_fixed_to_int(move->pos[ii] - move->start_pos[ii]))
1551 move->is_moved = 1;
1552 }
1553}
1554
1555static void
1556layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
1557 wl_fixed_t pos_y)
1558{
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001559 const struct ivi_layout_layer_properties *prop;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001560 int32_t layout_pos_x = 0;
1561 int32_t layout_pos_y = 0;
1562
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001563 prop = ivi_layout_interface->get_properties_of_layer(layer);
1564
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001565 layout_pos_x = wl_fixed_to_int(pos_x);
1566 layout_pos_y = wl_fixed_to_int(pos_y);
Ucan, Emre \(ADITG/SW1\)e62bfd82016-03-04 12:50:46 +00001567 ivi_layout_interface->layer_set_destination_rectangle(layer,
1568 layout_pos_x, layout_pos_y, prop->dest_width, prop->dest_height);
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001569 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001570}
1571
1572static void
1573pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001574 struct weston_pointer_motion_event *event)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001575{
1576 struct pointer_move_grab *pnt_move_grab =
1577 (struct pointer_move_grab *)grab;
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001578 wl_fixed_t pointer_pos[2];
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001579
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001580 weston_pointer_motion_to_abs(grab->pointer, event,
1581 &pointer_pos[0], &pointer_pos[1]);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001582 move_grab_update(&pnt_move_grab->move, pointer_pos);
1583 layer_set_pos(pnt_move_grab->base.layer,
1584 pnt_move_grab->move.pos[0], pnt_move_grab->move.pos[1]);
Jonas Ã…dahld2510102014-10-05 21:39:14 +02001585 weston_pointer_move(pnt_move_grab->base.grab.pointer, event);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001586}
1587
1588static void
1589touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1590 int touch_id, wl_fixed_t x, wl_fixed_t y)
1591{
1592 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1593
1594 if (!tch_move_grab->is_active)
1595 return;
1596
1597 wl_fixed_t pointer_pos[2] = {
1598 grab->touch->grab_x,
1599 grab->touch->grab_y
1600 };
1601
1602 move_grab_update(&tch_move_grab->move, pointer_pos);
1603 layer_set_pos(tch_move_grab->base.layer,
1604 tch_move_grab->move.pos[0], tch_move_grab->move.pos[1]);
1605}
1606
1607static void
1608pointer_move_workspace_grab_button(struct weston_pointer_grab *grab,
1609 uint32_t time, uint32_t button,
1610 uint32_t state_w)
1611{
1612 if (BTN_LEFT == button &&
1613 WL_POINTER_BUTTON_STATE_RELEASED == state_w) {
1614 struct pointer_grab *pg = (struct pointer_grab *)grab;
1615
1616 pointer_move_workspace_grab_end(pg);
1617 free(grab);
1618 }
1619}
1620
1621static void
1622touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
1623 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1624{
1625}
1626
1627static void
1628touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time,
1629 int touch_id)
1630{
1631 struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
1632
1633 if (0 == touch_id)
1634 tch_move_grab->is_active = 0;
1635
1636 if (0 == grab->touch->num_tp) {
1637 touch_move_workspace_grab_end(&tch_move_grab->base);
1638 free(grab);
1639 }
1640}
1641
1642static void
1643pointer_move_workspace_grab_cancel(struct weston_pointer_grab *grab)
1644{
1645 struct pointer_grab *pg = (struct pointer_grab *)grab;
1646
1647 pointer_move_workspace_grab_end(pg);
1648 free(grab);
1649}
1650
1651static void
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001652touch_move_workspace_grab_frame(struct weston_touch_grab *grab)
1653{
1654}
1655
1656static void
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001657touch_move_workspace_grab_cancel(struct weston_touch_grab *grab)
1658{
1659 struct touch_grab *tg = (struct touch_grab *)grab;
1660
1661 touch_move_workspace_grab_end(tg);
1662 free(grab);
1663}
1664
1665static const struct weston_pointer_grab_interface pointer_move_grab_workspace_interface = {
1666 pointer_noop_grab_focus,
1667 pointer_move_grab_motion,
1668 pointer_move_workspace_grab_button,
Jonas Ã…dahl0336ca02014-10-04 16:28:29 +02001669 pointer_default_grab_axis,
Peter Hutterer87743e92016-01-18 16:38:22 +10001670 pointer_default_grab_axis_source,
1671 pointer_default_grab_frame,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001672 pointer_move_workspace_grab_cancel
1673};
1674
1675static const struct weston_touch_grab_interface touch_move_grab_workspace_interface = {
1676 touch_nope_grab_down,
1677 touch_move_workspace_grab_up,
1678 touch_move_grab_motion,
Nobuhiko Tanibata82cc25b2015-02-06 16:08:52 +09001679 touch_move_workspace_grab_frame,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001680 touch_move_workspace_grab_cancel
1681};
1682
1683enum HMI_GRAB_DEVICE {
1684 HMI_GRAB_DEVICE_NONE,
1685 HMI_GRAB_DEVICE_POINTER,
1686 HMI_GRAB_DEVICE_TOUCH
1687};
1688
1689static enum HMI_GRAB_DEVICE
1690get_hmi_grab_device(struct weston_seat *seat, uint32_t serial)
1691{
Derek Foreman1281a362015-07-31 16:55:32 -05001692 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
1693 struct weston_touch *touch = weston_seat_get_touch(seat);
1694
1695 if (pointer &&
1696 pointer->focus &&
1697 pointer->button_count &&
1698 pointer->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001699 return HMI_GRAB_DEVICE_POINTER;
1700
Derek Foreman1281a362015-07-31 16:55:32 -05001701 if (touch &&
1702 touch->focus &&
1703 touch->grab_serial == serial)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001704 return HMI_GRAB_DEVICE_TOUCH;
1705
1706 return HMI_GRAB_DEVICE_NONE;
1707}
1708
1709static void
1710move_grab_init(struct move_grab* move, wl_fixed_t start_pos[2],
1711 wl_fixed_t grab_pos[2], wl_fixed_t rgn[2][2],
1712 struct wl_resource* resource)
1713{
1714 clock_gettime(CLOCK_MONOTONIC, &move->start_time); //FIXME
1715 move->pre_time = move->start_time;
1716 move->pos[0] = start_pos[0];
1717 move->pos[1] = start_pos[1];
1718 move->start_pos[0] = start_pos[0];
1719 move->start_pos[1] = start_pos[1];
1720 move->dst[0] = start_pos[0] - grab_pos[0];
1721 move->dst[1] = start_pos[1] - grab_pos[1];
1722 memcpy(move->rgn, rgn, sizeof(move->rgn));
1723}
1724
1725static void
1726move_grab_init_workspace(struct move_grab* move,
1727 wl_fixed_t grab_x, wl_fixed_t grab_y,
1728 struct wl_resource *resource)
1729{
1730 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1731 struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
Ucan, Emre \(ADITG/SW1\)dfc2d762016-03-04 12:50:24 +00001732 const struct ivi_layout_layer_properties *prop;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001733 int32_t workspace_count = hmi_ctrl->workspace_count;
1734 int32_t workspace_width = hmi_ctrl->workspace_background_layer.width;
1735 int32_t layer_pos_x = 0;
1736 int32_t layer_pos_y = 0;
1737 wl_fixed_t start_pos[2] = {0};
1738 wl_fixed_t rgn[2][2] = {{0}};
1739 wl_fixed_t grab_pos[2] = { grab_x, grab_y };
1740
Ucan, Emre \(ADITG/SW1\)dfc2d762016-03-04 12:50:24 +00001741 prop = ivi_layout_interface->get_properties_of_layer(layer);
1742 layer_pos_x = prop->dest_x;
1743 layer_pos_y = prop->dest_y;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001744
1745 start_pos[0] = wl_fixed_from_int(layer_pos_x);
1746 start_pos[1] = wl_fixed_from_int(layer_pos_y);
1747
1748 rgn[0][0] = wl_fixed_from_int(-workspace_width * (workspace_count - 1));
1749
1750 rgn[0][1] = wl_fixed_from_int(0);
1751 rgn[1][0] = wl_fixed_from_int(0);
1752 rgn[1][1] = wl_fixed_from_int(0);
1753
1754 move_grab_init(move, start_pos, grab_pos, rgn, resource);
1755}
1756
1757static struct pointer_move_grab *
1758create_workspace_pointer_move(struct weston_pointer *pointer,
1759 struct wl_resource* resource)
1760{
1761 struct pointer_move_grab *pnt_move_grab =
1762 MEM_ALLOC(sizeof(*pnt_move_grab));
1763
1764 pnt_move_grab->base.resource = resource;
1765 move_grab_init_workspace(&pnt_move_grab->move, pointer->grab_x,
1766 pointer->grab_y, resource);
1767
1768 return pnt_move_grab;
1769}
1770
1771static struct touch_move_grab *
1772create_workspace_touch_move(struct weston_touch *touch,
1773 struct wl_resource* resource)
1774{
1775 struct touch_move_grab *tch_move_grab =
1776 MEM_ALLOC(sizeof(*tch_move_grab));
1777
1778 tch_move_grab->base.resource = resource;
1779 tch_move_grab->is_active = 1;
1780 move_grab_init_workspace(&tch_move_grab->move, touch->grab_x,
1781 touch->grab_y, resource);
1782
1783 return tch_move_grab;
1784}
1785
1786static void
1787ivi_hmi_controller_workspace_control(struct wl_client *client,
1788 struct wl_resource *resource,
1789 struct wl_resource *seat_resource,
1790 uint32_t serial)
1791{
1792 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1793 struct ivi_layout_layer *layer = NULL;
1794 struct pointer_move_grab *pnt_move_grab = NULL;
1795 struct touch_move_grab *tch_move_grab = NULL;
1796 struct weston_seat *seat = NULL;
Derek Foreman1281a362015-07-31 16:55:32 -05001797 struct weston_pointer *pointer;
1798 struct weston_touch *touch;
1799
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001800 enum HMI_GRAB_DEVICE device;
1801
1802 if (hmi_ctrl->workspace_count < 2)
1803 return;
1804
1805 seat = wl_resource_get_user_data(seat_resource);
1806 device = get_hmi_grab_device(seat, serial);
1807
1808 if (HMI_GRAB_DEVICE_POINTER != device &&
1809 HMI_GRAB_DEVICE_TOUCH != device)
1810 return;
1811
1812 layer = hmi_ctrl->workspace_layer.ivilayer;
1813
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001814 ivi_layout_interface->transition_move_layer_cancel(layer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001815
1816 switch (device) {
1817 case HMI_GRAB_DEVICE_POINTER:
Derek Foreman1281a362015-07-31 16:55:32 -05001818 pointer = weston_seat_get_pointer(seat);
1819 pnt_move_grab = create_workspace_pointer_move(pointer,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001820 resource);
1821
1822 pointer_grab_start(&pnt_move_grab->base, layer,
1823 &pointer_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001824 pointer);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001825 break;
1826
1827 case HMI_GRAB_DEVICE_TOUCH:
Derek Foreman1281a362015-07-31 16:55:32 -05001828 touch = weston_seat_get_touch(seat);
1829 tch_move_grab = create_workspace_touch_move(touch,
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001830 resource);
1831
1832 touch_grab_start(&tch_move_grab->base, layer,
1833 &touch_move_grab_workspace_interface,
Derek Foreman1281a362015-07-31 16:55:32 -05001834 touch);
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001835 break;
1836
1837 default:
1838 break;
1839 }
1840}
1841
1842/**
1843 * Implementation of switch_mode
1844 */
1845static void
1846ivi_hmi_controller_switch_mode(struct wl_client *client,
1847 struct wl_resource *resource,
1848 uint32_t layout_mode)
1849{
1850 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1851
1852 switch_mode(hmi_ctrl, layout_mode);
1853}
1854
1855/**
1856 * Implementation of on/off displaying workspace and workspace background
1857 * ivi_layers.
1858 */
1859static void
1860ivi_hmi_controller_home(struct wl_client *client,
1861 struct wl_resource *resource,
1862 uint32_t home)
1863{
1864 struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
1865 uint32_t is_fade_in;
1866
1867 if ((IVI_HMI_CONTROLLER_HOME_ON == home &&
1868 !hmi_ctrl->workspace_fade.is_fade_in) ||
1869 (IVI_HMI_CONTROLLER_HOME_OFF == home &&
1870 hmi_ctrl->workspace_fade.is_fade_in)) {
1871 is_fade_in = !hmi_ctrl->workspace_fade.is_fade_in;
1872 hmi_controller_fade_run(hmi_ctrl, is_fade_in,
1873 &hmi_ctrl->workspace_fade);
1874 }
1875
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001876 ivi_layout_interface->commit_changes();
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001877}
1878
1879/**
1880 * binding ivi-hmi-controller implementation
1881 */
1882static const struct ivi_hmi_controller_interface ivi_hmi_controller_implementation = {
1883 ivi_hmi_controller_UI_ready,
1884 ivi_hmi_controller_workspace_control,
1885 ivi_hmi_controller_switch_mode,
1886 ivi_hmi_controller_home
1887};
1888
1889static void
1890unbind_hmi_controller(struct wl_resource *resource)
1891{
1892}
1893
1894static void
1895bind_hmi_controller(struct wl_client *client,
1896 void *data, uint32_t version, uint32_t id)
1897{
1898 struct wl_resource *resource = NULL;
1899 struct hmi_controller *hmi_ctrl = data;
1900
1901 if (hmi_ctrl->user_interface != client) {
1902 struct wl_resource *res = wl_client_get_object(client, 1);
1903 wl_resource_post_error(res,
1904 WL_DISPLAY_ERROR_INVALID_OBJECT,
1905 "hmi-controller failed: permission denied");
1906 return;
1907 }
1908
1909 resource = wl_resource_create(
1910 client, &ivi_hmi_controller_interface, 1, id);
1911
1912 wl_resource_set_implementation(
1913 resource, &ivi_hmi_controller_implementation,
1914 hmi_ctrl, unbind_hmi_controller);
1915}
1916
1917static int32_t
1918initialize(struct hmi_controller *hmi_ctrl)
1919{
1920 struct config_command {
1921 char *key;
1922 uint32_t *dest;
1923 };
1924
1925 struct weston_config *config = hmi_ctrl->compositor->config;
1926 struct weston_config_section *section = NULL;
1927 int result = 0;
1928 int i = 0;
1929
1930 const struct config_command uint_commands[] = {
1931 { "background-id", &hmi_ctrl->ui_setting.background_id },
1932 { "panel-id", &hmi_ctrl->ui_setting.panel_id },
1933 { "tiling-id", &hmi_ctrl->ui_setting.tiling_id },
1934 { "sidebyside-id", &hmi_ctrl->ui_setting.sidebyside_id },
1935 { "fullscreen-id", &hmi_ctrl->ui_setting.fullscreen_id },
1936 { "random-id", &hmi_ctrl->ui_setting.random_id },
1937 { "home-id", &hmi_ctrl->ui_setting.home_id },
1938 { "workspace-background-id", &hmi_ctrl->ui_setting.workspace_background_id },
Nobuhiko Tanibata2e656762015-12-09 15:41:46 +09001939 { "surface-id-offset", &hmi_ctrl->ui_setting.surface_id_offset },
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001940 { NULL, NULL }
1941 };
1942
1943 section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
1944
1945 for (i = 0; -1 != result; ++i) {
1946 const struct config_command *command = &uint_commands[i];
1947
1948 if (!command->key)
1949 break;
1950
1951 if (weston_config_section_get_uint(
1952 section, command->key, command->dest, 0) != 0)
1953 result = -1;
1954 }
1955
1956 if (-1 == result) {
1957 weston_log("Failed to initialize hmi-controller\n");
1958 return 0;
1959 }
1960
1961 return 1;
1962}
1963
1964static void
1965launch_hmi_client_process(void *data)
1966{
1967 struct hmi_controller *hmi_ctrl =
1968 (struct hmi_controller *)data;
1969
1970 hmi_ctrl->user_interface =
1971 weston_client_start(hmi_ctrl->compositor,
1972 hmi_ctrl->hmi_setting->ivi_homescreen);
1973
1974 free(hmi_ctrl->hmi_setting->ivi_homescreen);
1975}
1976
1977/*****************************************************************************
1978 * exported functions
1979 ****************************************************************************/
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001980WL_EXPORT int
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001981controller_module_init(struct weston_compositor *ec,
1982 int *argc, char *argv[],
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001983 const struct ivi_layout_interface *interface,
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001984 size_t interface_version)
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001985{
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001986 struct hmi_controller *hmi_ctrl = NULL;
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09001987 struct wl_event_loop *loop = NULL;
1988
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001989 if (interface_version < sizeof(struct ivi_layout_interface)) {
Chris Michaelc083af92015-10-01 10:51:29 -04001990 weston_log("ivi-shell: version mismatch of controller interface\n");
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001991 return -1;
1992 }
1993
Ucan, Emre \(ADITG/SW1\)0c0e51e2015-10-15 14:51:41 +00001994 ivi_layout_interface = interface;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001995
1996 hmi_ctrl = hmi_controller_create(ec);
Nobuhiko Tanibata35711df2015-12-09 15:40:13 +09001997 if (hmi_ctrl == NULL)
1998 return -1;
Nobuhiko Tanibataee8e5832014-12-15 13:25:39 +09001999
Nobuhiko Tanibata4f6853b2014-11-27 13:23:12 +09002000 if (!initialize(hmi_ctrl)) {
2001 return -1;
2002 }
2003
2004 if (wl_global_create(ec->wl_display,
2005 &ivi_hmi_controller_interface, 1,
2006 hmi_ctrl, bind_hmi_controller) == NULL) {
2007 return -1;
2008 }
2009
2010 loop = wl_display_get_event_loop(ec->wl_display);
2011 wl_event_loop_add_idle(loop, launch_hmi_client_process, hmi_ctrl);
2012
2013 return 0;
2014}