summaryrefslogtreecommitdiffstats
path: root/meta-ivi/recipes-graphics/wayland/weston-1.6.0/0006-ivi-shell-a-reference-implementation-how-to-use-ivi-.patch
blob: 846fc66180d8552fb7b0cd69a5b47c80dd6ece78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
From 7fd5b817649f0cb829bb0e033fe371a275810ad8 Mon Sep 17 00:00:00 2001
From: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Date: Tue, 24 Jun 2014 23:06:02 +0900
Subject: [PATCH 06/15] ivi-shell: a reference implementation how to use
 ivi-layout internal APIs

- hmi-controller.so
- introduces hmi-controller.so

The library is used to manage layout of surfaces/layers. Layout change
is triggered by ivi-hmi-controller protocol, ivi-hmi-controller.xml. A
reference how to use the protocol, see ivi-shell-user-interface.c.

In-Vehicle Infotainment system usually manages properties of
surfaces/layers by only a central component which decide where
surfaces/layers shall be. This is differenct use case from desktop
style; each application can request property of its window via xdg-shell
protocol, like fullscreen and set its to top level. In-Vehicle
Infortainment system doesn't allow each application to chagen them from
its application because of safty reasons. The concept of layer is
simillar with a use case of cursor layer of Destop. For In-Vehicle
Infortainment system, it is extended to all applications. For example,
rearview camera application is assigned to a layer to group several
surfaces, e.g. captured image and drawing lines separately. Central
manaegr can control property of the layer of rearview camera.

This reference show examples to implement the central component as a
module of weston.

Default Scene graph of UI is defined in hmi_controller_create. It
consists of
- In the bottom, a base layer to group surfaces of background, panel,
  and buttons
- Next, a application layer to show application surfaces.
- Workspace background layer to show a surface of background image.
- Workspace layer to show launcher to launch application with icons.
  Paths to binary and icon are defined in weston.ini. The width of
  this layer is longer than the size of screen because a workspace
  has several pages and is controlled by motion of input.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

data: add reference image files for weston-ivi-shell-user-interface

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------
ivi-shell/hmi-controller.c from transition animation

------------------------------------------
clients/ivi-shell-user-interface.c from transition animation

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

remove clients/ivi-shell-suer-interface.c

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: clean up LIBS /CFLAGS of hmi-controller

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: clean-up headers to be used for hmi-controller

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: .gitignore update
remove unnecesary lines.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
hmi-controller: change stdbool from unit32_t

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Modification of function name

> Typo in function name.
> [ntanibata] I will fix. -> application

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: fix invalid condition in get_hmi_grab_device

> Should probably compare serial to something.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Fix delete API

> Is this necessary? The client should just eventually (or alreay did)
> get a hangup from the connection, and exit.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Fix minor modifications of hmi_controller_create

> This assignment should be in hmi_controller_create().
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: change int type from array type

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
hmi-controller: Use the weston_config that has already been created.

> > Don't call weston_config_parse(), but have the
> > weston_compositor::config variable passed in here.
> [ntanibata] Yes, the same as previous comment. I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Use the weston_config that has already been created.

> Don't parse, but use weston_compositor::config.
> All this re-parsing of weston.ini might actually slow down your start-up.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
hmi-controller: Fix initialized flag setting bug.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Fix add include file

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: change API name from range_val to clamp

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
hmi-controller: Fix array memory allocation.

> > Declarations mixed up with code. Our style has declarations only in
> > the beginning of a block.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: Change quoted_printable_encode form camelcase

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
add FIXME at calling clock_gettime

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
hmi-controller: Declare variable in the beginning of a block.

> > Declarations mixed up with code. Our style has declarations only
> > in the beginning of a block.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell/hmi-controller.c: remove non-availalable header including

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
Makefile.am: hmi-controller.so needs weston_parser feature to read configs

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: hmi-controller.c, clean-up definition of valueable in the
middle function.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: hmi-controller.c, remove code commented out.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-----------------------------------------------------------
ivi-shell: hmi-controller, modify comments, surface/layer/screen -> ivi_*

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
ivi-shell: hmi-controller. avoid including ivi-layout-private.h

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
ivi-shell: Get hmi_controller from resource when before setup time.

> Every one of these calls commit. Wouldn't it be better to call commit
> only once in the end of this function?
> [ntanibata] Exactly, I will fix it.
> It doesn't make too much sense to pass 'resource' as the argument to
> these function calls. Would be better to pass in struct
> hmi_controller, because that is what every single function needs and
> not the wl_resource.
> [ntanibata] I agree. I will fix it.
> ivi_hmi_controller_UI_ready() is the only function that is actually a
> request handler.
> [ntanibata] Right. I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
ivi-shell: Modification to end of function

> Every one of these calls commit. Wouldn't it be better to call commit
> only once in the end of this function?
> [ntanibata] Exactly, I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
ivi-shell:hmi-controller.c Change type of calculatable variables to signed from unsigned

> FWIW, if you are going to do calculations with these variables, they
> should be signed. If you mix unsigned and signed variables in
> calculations, the result is probably not what you expect in all cases.
> This is just a reminder for you, that you might want to change these in
> the future.
> Weston core categorically uses signed variables for anything that is
> involved in calculations, even if negative values would not make any
> sense for a particular variable.
> Counters (that may wrap around) are of course better stored as unsigned.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
Makefile.am: clean up Makefile.am with FR3 for hmi-controller

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Move register process of destroy signal handler when hmi-controller created.

> This does not belong here with the client launching, it belongs in
> hmicontrollercreate() with the hmi-controller init.
> Where is the function to be called on compositor destroy, anyway?

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: To improve documentary value.

> To improve documentary value, you should have:
> struct hmicontroller *hmictrl = data;

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: remove IVI_SHELL_{LIBS,CFLAGS} from Makefile.am

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Use weston_log() instead.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Should be a tab, not spaces in Makefile.am

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Change type of temporary variables from void *into int32_t *.

> Since it's always an uint32t anyway, might as well use 'uint32t *dest'
> here and drop a cast below.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Remove a unused assignment.

> Useless return. Also pp_surface = NULL; has no use.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Remove unused variables as return value.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Fix invalid calculation.

> 'time' is zero, so why these calculations with it?
> Something is missing here, at least you need a comment explaining what
> it is. I'd assume 'time' shouldn't be zero.
> Maybe a mistake when moving code around.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Set initialized-flag when UI settings succeeded.

> So, if getting any single id from the config fails, you ignore them all,
> do not set up any of the UI components except launchers, and then
>     continue as if nothing went wrong? Seems a bit strange, but if you
>     like it that way, so be it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: remove useless return

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
ivi-shell: Replace weston_client_launch() with weston_client_start()

> Since you are not really using the SIGCHLD handler for anything, a
> better function to call would be weston_client_start().
> Allows you to remove the 'process' field from struct hmi_controller

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Remove casts to (void)

> I don't think we need these casts. The warning about unused arguments is
> disabled, isn't it?
> You should be able to remove casts to (void) from all places.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: fix code mixed with declarations

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: hmi-controller, Set handler to destroy-listener.

> Ok, but do you actually set hmictrl->destroylistener.notify somewhere? I
> can't find it, and if it is not set, you should be getting a crash
> during weston shutdown.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Post error-code if initialize failed.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Check authorization of protocol binding.

> ..and use 'hmictrl' here instead of 'data'. That way the reader sees
> what the userdata for the wlresource is without tracking it further.
> This function is missing authorization checks. Any client is allowed to
> bind to hmicontroller and use it to do whatever they want. You'd
> probably rather want access to hmicontroller to be restricted to the
> client you launch in launchhmiclientprocess().
> To implement the authorization check, you would save the wlclient
> pointer from westonclientlaunch() or westonclientstart(), and compare
> 'client' to the saved pointer here. If the pointers differ, the client
> attempting to bind to hmicontroller is not the one you launched, and so
> you can send a protocol error and just return.
> If you want to implement respawn for the controller client, hook into
> the wlclient destruction, not SIGCHLD. You should hook to the wl_client
> destruction anyway, so you know when to reset the saved client pointer
> to NULL.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: Post invalid-object-error if binding failed.

> missing an error sending.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller: hmi_controller_destroy feature to release memory

> ok, though shouldn't that function be freeing some things? I suspect you
> might want to free struct hmi_controller there, and its members.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

----------------------------------------------------------
hmi-controller.c: indent with tabs

For the stray changes, see 'git show -b <sha1>'.

----------------------------------------------------------
hmi-controller.c: remove unneeded braces from if-statements

----------------------------------------------------------
hmi-controller.c: whitespace fixes

----------------------------------------------------------
hmi-controller.c: remove unneeded casts

----------------------------------------------------------
hmi-controller.c: split long lines
---
 Makefile.am                |   16 +-
 ivi-shell/.gitignore       |    1 +
 ivi-shell/hmi-controller.c | 1710 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1726 insertions(+), 1 deletion(-)
 create mode 100644 ivi-shell/.gitignore
 create mode 100644 ivi-shell/hmi-controller.c

diff --git a/Makefile.am b/Makefile.am
index 112bff2..76780a8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -724,7 +724,8 @@ if ENABLE_IVI_SHELL
 
 module_LTLIBRARIES +=				\
 	$(ivi_layout)				\
-	$(ivi_shell)
+	$(ivi_shell)				\
+	$(hmi_controller)
 
 ivi_layout = ivi-layout.la
 ivi_layout_la_LDFLAGS = -module -avoid-version
@@ -752,6 +753,19 @@ nodist_ivi_shell_la_SOURCES =			\
 
 BUILT_SOURCES += $(nodist_ivi_shell_la_SOURCES)
 
+hmi_controller = hmi-controller.la
+hmi_controller_la_LDFLAGS = -module -avoid-version
+hmi_controller_la_LIBADD = $(COMPOSITOR_LIBS) libshared.la
+hmi_controller_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+hmi_controller_la_SOURCES =				\
+	ivi-shell/ivi-layout-export.h			\
+	ivi-shell/hmi-controller.c
+nodist_hmi_controller_la_SOURCES =			\
+	protocol/ivi-hmi-controller-protocol.c		\
+	protocol/ivi-hmi-controller-server-protocol.h
+
+BUILT_SOURCES += $(nodist_hmi_controller_la_SOURCES)
+
 endif
 
 
diff --git a/ivi-shell/.gitignore b/ivi-shell/.gitignore
new file mode 100644
index 0000000..e690c59
--- /dev/null
+++ b/ivi-shell/.gitignore
@@ -0,0 +1 @@
+weston.ini
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
new file mode 100644
index 0000000..b7a6c61
--- /dev/null
+++ b/ivi-shell/hmi-controller.c
@@ -0,0 +1,1710 @@
+/*
+ * Copyright (C) 2014 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * A reference implementation how to use ivi-layout APIs in order to manage
+ * layout of ivi_surfaces/ivi_layers. Layout change is triggered by
+ * ivi-hmi-controller protocol, ivi-hmi-controller.xml. A reference how to
+ * use the protocol, see hmi-controller-homescreen.
+ *
+ * In-Vehicle Infotainment system usually manage properties of
+ * ivi_surfaces/ivi_layers by only a central component which decide where
+ * ivi_surfaces/ivi_layers shall be. This reference show examples to
+ * implement the central component as a module of weston.
+ *
+ * Default Scene graph of UI is defined in hmi_controller_create. It
+ * consists of
+ * - In the bottom, a base ivi_layer to group ivi_surfaces of background,
+ *   panel, and buttons
+ * - Next, a application ivi_layer to show application ivi_surfaces.
+ * - Workspace background ivi_layer to show a ivi_surface of background image.
+ * - Workspace ivi_layer to show launcher to launch application with icons.
+ *   Paths to binary and icon are defined in weston.ini. The width of this
+ *   ivi_layer is longer than the size of ivi_screen because a workspace has
+ *   several pages and is controlled by motion of input.
+ *
+ * TODO: animation method shall be refined
+ * TODO: support fade-in when UI is ready
+ */
+
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/input.h>
+#include <assert.h>
+#include <time.h>
+
+#include "ivi-layout-export.h"
+#include "ivi-hmi-controller-server-protocol.h"
+
+/*****************************************************************************
+ *  structure, globals
+ ****************************************************************************/
+struct hmi_controller_layer {
+	struct ivi_layout_layer *ivilayer;
+	uint32_t id_layer;
+	int32_t x;
+	int32_t y;
+	int32_t width;
+	int32_t height;
+};
+
+struct link_layer {
+	struct ivi_layout_layer *layout_layer;
+	struct wl_list link;
+};
+
+struct hmi_controller_fade {
+	uint32_t is_fade_in;
+	struct wl_list layer_list;
+};
+
+struct hmi_server_setting {
+	uint32_t    base_layer_id;
+	uint32_t    application_layer_id;
+	uint32_t    workspace_background_layer_id;
+	uint32_t    workspace_layer_id;
+	int32_t     panel_height;
+	uint32_t    transition_duration;
+	char       *ivi_homescreen;
+};
+
+struct hmi_controller {
+	struct hmi_server_setting          *hmi_setting;
+	struct hmi_controller_layer         base_layer;
+	struct hmi_controller_layer         application_layer;
+	struct hmi_controller_layer         workspace_background_layer;
+	struct hmi_controller_layer         workspace_layer;
+	enum ivi_hmi_controller_layout_mode layout_mode;
+
+	struct hmi_controller_fade          workspace_fade;
+
+	int32_t                             workspace_count;
+	struct wl_array                     ui_widgets;
+	int32_t                             is_initialized;
+
+	struct weston_compositor           *compositor;
+	struct wl_listener                  destroy_listener;
+
+	struct wl_client                   *user_interface;
+};
+
+struct launcher_info {
+	uint32_t surface_id;
+	uint32_t workspace_id;
+	int32_t index;
+};
+
+/*****************************************************************************
+ *  local functions
+ ****************************************************************************/
+static void *
+fail_on_null(void *p, size_t size, char *file, int32_t line)
+{
+	if (size && !p) {
+		weston_log("%s(%d) %zd: out of memory\n", file, line, size);
+		exit(EXIT_FAILURE);
+	}
+
+	return p;
+}
+
+static void *
+mem_alloc(size_t size, char *file, int32_t line)
+{
+	return fail_on_null(calloc(1, size), size, file, line);
+}
+
+#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
+
+static int32_t
+is_surf_in_ui_widget(struct hmi_controller *hmi_ctrl,
+		     struct ivi_layout_surface *ivisurf)
+{
+	uint32_t id = ivi_layout_get_id_of_surface(ivisurf);
+
+	uint32_t *ui_widget_id = NULL;
+	wl_array_for_each(ui_widget_id, &hmi_ctrl->ui_widgets) {
+		if (*ui_widget_id == id)
+			return 1;
+	}
+
+	return 0;
+}
+
+static int
+compare_launcher_info(const void *lhs, const void *rhs)
+{
+	const struct launcher_info *left = lhs;
+	const struct launcher_info *right = rhs;
+
+	if (left->workspace_id < right->workspace_id)
+		return -1;
+
+	if (left->workspace_id > right->workspace_id)
+		return 1;
+
+	if (left->index < right->index)
+		return -1;
+
+	if (left->index > right->index)
+		return 1;
+
+	return 0;
+}
+
+/**
+ * Internal methods called by mainly ivi_hmi_controller_switch_mode
+ * This reference shows 4 examples how to use ivi_layout APIs.
+ */
+static void
+mode_divided_into_tiling(struct hmi_controller *hmi_ctrl,
+			 struct ivi_layout_surface **pp_surface,
+			 int32_t surface_length,
+			 struct hmi_controller_layer *layer)
+{
+	const float surface_width  = (float)layer->width * 0.25;
+	const float surface_height = (float)layer->height * 0.5;
+	int32_t surface_x = 0;
+	int32_t surface_y = 0;
+	struct ivi_layout_surface *ivisurf  = NULL;
+	struct ivi_layout_surface **surfaces;
+	struct ivi_layout_surface **new_order;
+	const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
+
+	int32_t i = 0;
+	int32_t surf_num = 0;
+	uint32_t num = 1;
+
+	surfaces = MEM_ALLOC(sizeof(*surfaces) * surface_length);
+	new_order = MEM_ALLOC(sizeof(*surfaces) * surface_length);
+
+	for (i = 0; i < surface_length; i++) {
+		ivisurf = pp_surface[i];
+
+		/* skip ui widgets */
+		if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+			continue;
+
+		surfaces[surf_num++] = ivisurf;
+	}
+
+	for (i = 0; i < surf_num; i++) {
+		ivisurf = surfaces[i];
+		new_order[i] = ivisurf;
+
+		if (num <= 8) {
+			if (num < 5) {
+				surface_x = (int32_t)((num - 1) * (surface_width));
+				surface_y = 0;
+			} else {
+				surface_x = (int32_t)((num - 5) * (surface_width));
+				surface_y = (int32_t)surface_height;
+			}
+
+			ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
+					duration);
+			ivi_layout_surface_set_visibility(ivisurf, true);
+			ivi_layout_surface_set_destination_rectangle(ivisurf,
+					surface_x, surface_y,
+					(int32_t)surface_width,
+					(int32_t)surface_height);
+
+			num++;
+			continue;
+		}
+		ivi_layout_surface_set_visibility(ivisurf, false);
+	}
+
+	if (surf_num > 0) {
+		ivi_layout_layer_set_transition(layer->ivilayer,
+				IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER,
+				duration);
+		//TODO: implement IVI_LAYOUT_TRANSITION_LAYER_VIEW_ORDER later.
+		ivi_layout_transition_layer_render_order(layer->ivilayer,
+							 new_order,
+							 surf_num,
+							 duration);
+	}
+
+	free(surfaces);
+	free(new_order);
+}
+
+static void
+mode_divided_into_sidebyside(struct hmi_controller *hmi_ctrl,
+			     struct ivi_layout_surface **pp_surface,
+			     int32_t surface_length,
+			     struct hmi_controller_layer *layer)
+{
+	int32_t surface_width  = layer->width / 2;
+	int32_t surface_height = layer->height;
+	struct ivi_layout_surface *ivisurf  = NULL;
+
+	const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
+	int32_t i = 0;
+	int32_t num = 1;
+
+	for (i = 0; i < surface_length; i++) {
+		ivisurf = pp_surface[i];
+
+		/* skip ui widgets */
+		if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+			continue;
+
+		if (num == 1) {
+			ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
+					duration);
+			ivi_layout_surface_set_visibility(ivisurf, true);
+			ivi_layout_surface_set_destination_rectangle(ivisurf,
+							0, 0,
+							surface_width,
+							surface_height);
+
+			num++;
+			continue;
+		} else if (num == 2) {
+			ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
+					duration);
+			ivi_layout_surface_set_visibility(ivisurf, true);
+			ivi_layout_surface_set_destination_rectangle(ivisurf,
+							surface_width, 0,
+							surface_width,
+							surface_height);
+
+			num++;
+			continue;
+		}
+		ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_FADE_ONLY,
+					duration);
+		ivi_layout_surface_set_visibility(ivisurf, false);
+	}
+}
+
+static void
+mode_fullscreen_someone(struct hmi_controller *hmi_ctrl,
+			struct ivi_layout_surface **pp_surface,
+			int32_t surface_length,
+			struct hmi_controller_layer *layer)
+{
+	const int32_t  surface_width  = layer->width;
+	const int32_t  surface_height = layer->height;
+	struct ivi_layout_surface *ivisurf  = NULL;
+	int32_t i = 0;
+	const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
+
+	for (i = 0; i < surface_length; i++) {
+		ivisurf = pp_surface[i];
+
+		/* skip ui widgets */
+		if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+			continue;
+
+		ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
+					duration);
+		ivi_layout_surface_set_visibility(ivisurf, true);
+		ivi_layout_surface_set_destination_rectangle(ivisurf, 0, 0,
+							     surface_width,
+							     surface_height);
+	}
+}
+
+static void
+mode_random_replace(struct hmi_controller *hmi_ctrl,
+		    struct ivi_layout_surface **pp_surface,
+		    int32_t surface_length,
+		    struct hmi_controller_layer *layer)
+{
+	const int32_t surface_width  = (int32_t)(layer->width * 0.25f);
+	const int32_t surface_height = (int32_t)(layer->height * 0.25f);
+	int32_t surface_x = 0;
+	int32_t surface_y = 0;
+	struct ivi_layout_surface *ivisurf  = NULL;
+	const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
+	int32_t i = 0;
+
+	for (i = 0; i < surface_length; i++) {
+		ivisurf = pp_surface[i];
+
+		/* skip ui widgets */
+		if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+			continue;
+
+		ivi_layout_surface_set_transition(ivisurf,
+					IVI_LAYOUT_TRANSITION_VIEW_DEFAULT,
+					duration);
+		ivi_layout_surface_set_visibility(ivisurf, true);
+		surface_x = rand() % (layer->width - surface_width);
+		surface_y = rand() % (layer->height - surface_height);
+
+		ivi_layout_surface_set_destination_rectangle(ivisurf,
+							     surface_x,
+							     surface_y,
+							     surface_width,
+							     surface_height);
+	}
+}
+
+static int32_t
+has_application_surface(struct hmi_controller *hmi_ctrl,
+			struct ivi_layout_surface **pp_surface,
+			int32_t surface_length)
+{
+	struct ivi_layout_surface *ivisurf  = NULL;
+	int32_t i = 0;
+
+	for (i = 0; i < surface_length; i++) {
+		ivisurf = pp_surface[i];
+
+		/* skip ui widgets */
+		if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+			continue;
+
+		return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * Supports 4 example to layout of application ivi_surfaces;
+ * tiling, side by side, fullscreen, and random.
+ */
+static void
+switch_mode(struct hmi_controller *hmi_ctrl,
+	    enum ivi_hmi_controller_layout_mode layout_mode)
+{
+	struct hmi_controller_layer *layer = &hmi_ctrl->application_layer;
+	struct ivi_layout_surface **pp_surface = NULL;
+	int32_t surface_length = 0;
+	int32_t ret = 0;
+
+	if (!hmi_ctrl->is_initialized)
+		return;
+
+	hmi_ctrl->layout_mode = layout_mode;
+
+	ret = ivi_layout_get_surfaces(&surface_length, &pp_surface);
+	assert(!ret);
+
+	if (!has_application_surface(hmi_ctrl, pp_surface, surface_length)) {
+		free(pp_surface);
+		pp_surface = NULL;
+		return;
+	}
+
+	switch (layout_mode) {
+	case IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING:
+		mode_divided_into_tiling(hmi_ctrl, pp_surface, surface_length,
+					 layer);
+		break;
+	case IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE:
+		mode_divided_into_sidebyside(hmi_ctrl, pp_surface,
+					     surface_length, layer);
+		break;
+	case IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN:
+		mode_fullscreen_someone(hmi_ctrl, pp_surface, surface_length,
+					layer);
+		break;
+	case IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM:
+		mode_random_replace(hmi_ctrl, pp_surface, surface_length,
+				    layer);
+		break;
+	}
+
+	ivi_layout_commit_changes();
+	free(pp_surface);
+}
+
+/**
+ * Internal method for transition
+ */
+static void
+hmi_controller_fade_run(struct hmi_controller *hmi_ctrl, uint32_t is_fade_in,
+			struct hmi_controller_fade *fade)
+{
+	double tint = is_fade_in ? 1.0 : 0.0;
+	struct link_layer *linklayer = NULL;
+	const uint32_t duration = hmi_ctrl->hmi_setting->transition_duration;
+
+	fade->is_fade_in = is_fade_in;
+
+	wl_list_for_each(linklayer, &fade->layer_list, link) {
+		ivi_layout_layer_set_transition(linklayer->layout_layer,
+					IVI_LAYOUT_TRANSITION_LAYER_FADE,
+					duration);
+		ivi_layout_layer_set_fade_info(linklayer->layout_layer,
+					       is_fade_in, 1.0 - tint, tint);
+	}
+}
+
+/**
+ * Internal method to create ivi_layer with hmi_controller_layer and
+ * add to a ivi_screen
+ */
+static void
+create_layer(struct ivi_layout_screen *iviscrn,
+	     struct hmi_controller_layer *layer)
+{
+	int32_t ret = 0;
+
+	layer->ivilayer =
+		ivi_layout_layer_create_with_dimension(layer->id_layer,
+						       layer->width,
+						       layer->height);
+	assert(layer->ivilayer != NULL);
+
+	ret = ivi_layout_screen_add_layer(iviscrn, layer->ivilayer);
+	assert(!ret);
+
+	ret = ivi_layout_layer_set_destination_rectangle(layer->ivilayer,
+							 layer->x, layer->y,
+							 layer->width,
+							 layer->height);
+	assert(!ret);
+
+	ret = ivi_layout_layer_set_visibility(layer->ivilayer, true);
+	assert(!ret);
+}
+
+/**
+ * Internal set notification
+ */
+static void
+set_notification_create_surface(struct ivi_layout_surface *ivisurf,
+				void *userdata)
+{
+	struct hmi_controller *hmi_ctrl = userdata;
+	struct ivi_layout_layer *application_layer =
+		hmi_ctrl->application_layer.ivilayer;
+	int32_t ret = 0;
+
+	/* skip ui widgets */
+	if (is_surf_in_ui_widget(hmi_ctrl, ivisurf))
+		return;
+
+	ret = ivi_layout_layer_add_surface(application_layer, ivisurf);
+	assert(!ret);
+}
+
+static void
+set_notification_remove_surface(struct ivi_layout_surface *ivisurf,
+				void *userdata)
+{
+	struct hmi_controller *hmi_ctrl = userdata;
+
+	switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
+}
+
+static void
+set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
+				   void *userdata)
+{
+	struct hmi_controller *hmi_ctrl = userdata;
+
+	switch_mode(hmi_ctrl, hmi_ctrl->layout_mode);
+}
+
+/**
+ * A hmi_controller used 4 ivi_layers to manage ivi_surfaces. The IDs of
+ * corresponding ivi_layer are defined in weston.ini. Default scene graph
+ * of ivi_layers are initialized in hmi_controller_create
+ */
+static struct hmi_server_setting *
+hmi_server_setting_create(struct weston_compositor *ec)
+{
+	struct hmi_server_setting *setting = MEM_ALLOC(sizeof(*setting));
+	struct weston_config *config = ec->config;
+	struct weston_config_section *shell_section = NULL;
+
+	shell_section = weston_config_get_section(config, "ivi-shell",
+						  NULL, NULL);
+
+	weston_config_section_get_uint(shell_section, "base-layer-id",
+				       &setting->base_layer_id, 1000);
+
+	weston_config_section_get_uint(shell_section,
+				       "workspace-background-layer-id",
+				       &setting->workspace_background_layer_id,
+				       2000);
+
+	weston_config_section_get_uint(shell_section, "workspace-layer-id",
+				       &setting->workspace_layer_id, 3000);
+
+	weston_config_section_get_uint(shell_section, "application-layer-id",
+				       &setting->application_layer_id, 4000);
+
+	weston_config_section_get_uint(shell_section, "transition-duration",
+				       &setting->transition_duration, 300);
+
+	setting->panel_height = 70;
+
+	weston_config_section_get_string(shell_section,
+					 "ivi-shell-user-interface",
+					 &setting->ivi_homescreen, NULL);
+
+	return setting;
+}
+
+static void
+hmi_controller_destroy(struct wl_listener *listener, void *data)
+{
+	struct link_layer *link = NULL;
+	struct link_layer *next = NULL;
+	struct hmi_controller *hmi_ctrl =
+		container_of(listener, struct hmi_controller, destroy_listener);
+
+	wl_list_for_each_safe(link, next,
+			      &hmi_ctrl->workspace_fade.layer_list, link) {
+		wl_list_remove(&link->link);
+		free(link);
+	}
+
+	wl_array_release(&hmi_ctrl->ui_widgets);
+	free(hmi_ctrl->hmi_setting);
+	free(hmi_ctrl);
+}
+
+/**
+ * This is a starting method called from module_init.
+ * This sets up scene graph of ivi_layers; base, application, workspace
+ * background, and workspace. These ivi_layers are created/added to
+ * ivi_screen in create_layer
+ *
+ * base: to group ivi_surfaces of panel and background
+ * application: to group ivi_surfaces of ivi_applications
+ * workspace background: to group a ivi_surface of background in workspace
+ * workspace: to group ivi_surfaces for launching ivi_applications
+ *
+ * ivi_layers of workspace background and workspace is set to invisible at
+ * first. The properties of it is updated with animation when
+ * ivi_hmi_controller_home is requested.
+ */
+static struct hmi_controller *
+hmi_controller_create(struct weston_compositor *ec)
+{
+	struct ivi_layout_screen **pp_screen = NULL;
+	struct ivi_layout_screen *iviscrn  = NULL;
+	int32_t screen_length  = 0;
+	int32_t screen_width   = 0;
+	int32_t screen_height  = 0;
+	struct link_layer *tmp_link_layer = NULL;
+	int32_t panel_height = 0;
+	struct hmi_controller *hmi_ctrl = MEM_ALLOC(sizeof(*hmi_ctrl));
+
+	wl_array_init(&hmi_ctrl->ui_widgets);
+	hmi_ctrl->layout_mode = IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING;
+	hmi_ctrl->hmi_setting = hmi_server_setting_create(ec);
+	hmi_ctrl->compositor = ec;
+
+	ivi_layout_get_screens(&screen_length, &pp_screen);
+
+	iviscrn = pp_screen[0];
+
+	ivi_layout_get_screen_resolution(iviscrn, &screen_width,
+					 &screen_height);
+
+	/* init base ivi_layer*/
+	hmi_ctrl->base_layer.x = 0;
+	hmi_ctrl->base_layer.y = 0;
+	hmi_ctrl->base_layer.width = screen_width;
+	hmi_ctrl->base_layer.height = screen_height;
+	hmi_ctrl->base_layer.id_layer = hmi_ctrl->hmi_setting->base_layer_id;
+
+	create_layer(iviscrn, &hmi_ctrl->base_layer);
+
+	panel_height = hmi_ctrl->hmi_setting->panel_height;
+
+	/* init application ivi_layer */
+	hmi_ctrl->application_layer.x = 0;
+	hmi_ctrl->application_layer.y = 0;
+	hmi_ctrl->application_layer.width = screen_width;
+	hmi_ctrl->application_layer.height = screen_height - panel_height;
+	hmi_ctrl->application_layer.id_layer =
+		hmi_ctrl->hmi_setting->application_layer_id;
+
+	create_layer(iviscrn, &hmi_ctrl->application_layer);
+
+	/* init workspace background ivi_layer */
+	hmi_ctrl->workspace_background_layer.x = 0;
+	hmi_ctrl->workspace_background_layer.y = 0;
+	hmi_ctrl->workspace_background_layer.width = screen_width;
+	hmi_ctrl->workspace_background_layer.height =
+		screen_height - panel_height;
+
+	hmi_ctrl->workspace_background_layer.id_layer =
+		hmi_ctrl->hmi_setting->workspace_background_layer_id;
+
+	create_layer(iviscrn, &hmi_ctrl->workspace_background_layer);
+	ivi_layout_layer_set_opacity(
+		hmi_ctrl->workspace_background_layer.ivilayer, 0);
+	ivi_layout_layer_set_visibility(
+		hmi_ctrl->workspace_background_layer.ivilayer, false);
+
+	/* init workspace ivi_layer */
+	hmi_ctrl->workspace_layer.x = hmi_ctrl->workspace_background_layer.x;
+	hmi_ctrl->workspace_layer.y = hmi_ctrl->workspace_background_layer.y;
+	hmi_ctrl->workspace_layer.width =
+		hmi_ctrl->workspace_background_layer.width;
+	hmi_ctrl->workspace_layer.height =
+		hmi_ctrl->workspace_background_layer.height;
+	hmi_ctrl->workspace_layer.id_layer =
+		hmi_ctrl->hmi_setting->workspace_layer_id;
+
+	create_layer(iviscrn, &hmi_ctrl->workspace_layer);
+	ivi_layout_layer_set_opacity(hmi_ctrl->workspace_layer.ivilayer, 0);
+	ivi_layout_layer_set_visibility(hmi_ctrl->workspace_layer.ivilayer,
+					false);
+
+	wl_list_init(&hmi_ctrl->workspace_fade.layer_list);
+	tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
+	tmp_link_layer->layout_layer = hmi_ctrl->workspace_layer.ivilayer;
+	wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
+		       &tmp_link_layer->link);
+	tmp_link_layer = MEM_ALLOC(sizeof(*tmp_link_layer));
+	tmp_link_layer->layout_layer =
+		hmi_ctrl->workspace_background_layer.ivilayer;
+	wl_list_insert(&hmi_ctrl->workspace_fade.layer_list,
+		       &tmp_link_layer->link);
+
+	ivi_layout_add_notification_create_surface(
+		set_notification_create_surface, hmi_ctrl);
+	ivi_layout_add_notification_remove_surface(
+		set_notification_remove_surface, hmi_ctrl);
+	ivi_layout_add_notification_configure_surface(
+		set_notification_configure_surface, hmi_ctrl);
+
+	hmi_ctrl->destroy_listener.notify = hmi_controller_destroy;
+	wl_signal_add(&hmi_ctrl->compositor->destroy_signal,
+		      &hmi_ctrl->destroy_listener);
+
+	free(pp_screen);
+	pp_screen = NULL;
+
+	return hmi_ctrl;
+}
+
+/**
+ * Implementations of ivi-hmi-controller.xml
+ */
+
+/**
+ * A ivi_surface drawing background is identified by id_surface.
+ * Properties of the ivi_surface is set by using ivi_layout APIs according to
+ * the scene graph of UI defined in hmi_controller_create.
+ *
+ * UI ivi_layer is used to add this ivi_surface.
+ */
+static void
+ivi_hmi_controller_set_background(struct hmi_controller *hmi_ctrl,
+				  uint32_t id_surface)
+{
+	struct ivi_layout_surface *ivisurf = NULL;
+	struct ivi_layout_layer   *ivilayer = hmi_ctrl->base_layer.ivilayer;
+	const int32_t dstx = hmi_ctrl->application_layer.x;
+	const int32_t dsty = hmi_ctrl->application_layer.y;
+	const int32_t width  = hmi_ctrl->application_layer.width;
+	const int32_t height = hmi_ctrl->application_layer.height;
+	int32_t ret = 0;
+
+	uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+						sizeof(*add_surface_id));
+	*add_surface_id = id_surface;
+
+	ivisurf = ivi_layout_get_surface_from_id(id_surface);
+	assert(ivisurf != NULL);
+
+	ret = ivi_layout_layer_add_surface(ivilayer, ivisurf);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_destination_rectangle(ivisurf,
+					dstx, dsty, width, height);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_visibility(ivisurf, true);
+	assert(!ret);
+}
+
+/**
+ * A ivi_surface drawing panel is identified by id_surface.
+ * Properties of the ivi_surface is set by using ivi_layout APIs according to
+ * the scene graph of UI defined in hmi_controller_create.
+ *
+ * UI ivi_layer is used to add this ivi_surface.
+ */
+static void
+ivi_hmi_controller_set_panel(struct hmi_controller *hmi_ctrl,
+			     uint32_t id_surface)
+{
+	struct ivi_layout_surface *ivisurf  = NULL;
+	struct ivi_layout_layer   *ivilayer = hmi_ctrl->base_layer.ivilayer;
+	const int32_t width  = hmi_ctrl->base_layer.width;
+	int32_t ret = 0;
+	int32_t panel_height = 0;
+	const int32_t dstx = 0;
+	int32_t dsty = 0;
+
+	uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+						sizeof(*add_surface_id));
+	*add_surface_id = id_surface;
+
+	ivisurf = ivi_layout_get_surface_from_id(id_surface);
+	assert(ivisurf != NULL);
+
+	ret = ivi_layout_layer_add_surface(ivilayer, ivisurf);
+	assert(!ret);
+
+	panel_height = hmi_ctrl->hmi_setting->panel_height;
+
+	dsty = hmi_ctrl->base_layer.height - panel_height;
+
+	ret = ivi_layout_surface_set_destination_rectangle(
+		ivisurf, dstx, dsty, width, panel_height);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_visibility(ivisurf, true);
+	assert(!ret);
+}
+
+/**
+ * A ivi_surface drawing buttons in panel is identified by id_surface.
+ * It can set several buttons. Properties of the ivi_surface is set by
+ * using ivi_layout APIs according to the scene graph of UI defined in
+ * hmi_controller_create. Additionally, the position of it is shifted to
+ * right when new one is requested.
+ *
+ * UI ivi_layer is used to add these ivi_surfaces.
+ */
+static void
+ivi_hmi_controller_set_button(struct hmi_controller *hmi_ctrl,
+			      uint32_t id_surface, int32_t number)
+{
+	struct ivi_layout_surface *ivisurf  = NULL;
+	struct ivi_layout_layer   *ivilayer = hmi_ctrl->base_layer.ivilayer;
+	const int32_t width  = 48;
+	const int32_t height = 48;
+	int32_t ret = 0;
+	int32_t panel_height = 0;
+	int32_t dstx = 0;
+	int32_t dsty = 0;
+	uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+						sizeof(*add_surface_id));
+	*add_surface_id = id_surface;
+
+	ivisurf = ivi_layout_get_surface_from_id(id_surface);
+	assert(ivisurf != NULL);
+
+	ret = ivi_layout_layer_add_surface(ivilayer, ivisurf);
+	assert(!ret);
+
+	panel_height = hmi_ctrl->hmi_setting->panel_height;
+
+	dstx = (60 * number) + 15;
+	dsty = (hmi_ctrl->base_layer.height - panel_height) + 5;
+
+	ret = ivi_layout_surface_set_destination_rectangle(
+		ivisurf,dstx, dsty, width, height);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_visibility(ivisurf, true);
+	assert(!ret);
+}
+
+/**
+ * A ivi_surface drawing home button in panel is identified by id_surface.
+ * Properties of the ivi_surface is set by using ivi_layout APIs according to
+ * the scene graph of UI defined in hmi_controller_create.
+ *
+ * UI ivi_layer is used to add these ivi_surfaces.
+ */
+static void
+ivi_hmi_controller_set_home_button(struct hmi_controller *hmi_ctrl,
+				   uint32_t id_surface)
+{
+	struct ivi_layout_surface *ivisurf  = NULL;
+	struct ivi_layout_layer   *ivilayer = hmi_ctrl->base_layer.ivilayer;
+	int32_t ret = 0;
+	int32_t size = 48;
+	int32_t panel_height = hmi_ctrl->hmi_setting->panel_height;
+	const int32_t dstx = (hmi_ctrl->base_layer.width - size) / 2;
+	const int32_t dsty = (hmi_ctrl->base_layer.height - panel_height) + 5;
+
+	uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+						sizeof(*add_surface_id));
+	*add_surface_id = id_surface;
+
+	ivisurf = ivi_layout_get_surface_from_id(id_surface);
+	assert(ivisurf != NULL);
+
+	ret = ivi_layout_layer_add_surface(ivilayer, ivisurf);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_destination_rectangle(
+			ivisurf, dstx, dsty, size, size);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_visibility(ivisurf, true);
+	assert(!ret);
+}
+
+/**
+ * A ivi_surface drawing background of workspace is identified by id_surface.
+ * Properties of the ivi_surface is set by using ivi_layout APIs according to
+ * the scene graph of UI defined in hmi_controller_create.
+ *
+ * A ivi_layer of workspace_background is used to add this ivi_surface.
+ */
+static void
+ivi_hmi_controller_set_workspacebackground(struct hmi_controller *hmi_ctrl,
+					   uint32_t id_surface)
+{
+	struct ivi_layout_surface *ivisurf = NULL;
+	struct ivi_layout_layer   *ivilayer = NULL;
+	const int32_t width  = hmi_ctrl->workspace_background_layer.width;
+	const int32_t height = hmi_ctrl->workspace_background_layer.height;
+	int32_t ret = 0;
+
+	uint32_t *add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+						sizeof(*add_surface_id));
+	*add_surface_id = id_surface;
+	ivilayer = hmi_ctrl->workspace_background_layer.ivilayer;
+
+	ivisurf = ivi_layout_get_surface_from_id(id_surface);
+	assert(ivisurf != NULL);
+
+	ret = ivi_layout_layer_add_surface(ivilayer, ivisurf);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_destination_rectangle(ivisurf,
+							   0, 0, width, height);
+	assert(!ret);
+
+	ret = ivi_layout_surface_set_visibility(ivisurf, true);
+	assert(!ret);
+}
+
+/**
+ * A list of ivi_surfaces drawing launchers in workspace is identified by
+ * id_surfaces. Properties of the ivi_surface is set by using ivi_layout
+ * APIs according to the scene graph of UI defined in hmi_controller_create.
+ *
+ * The workspace can have several pages to group ivi_surfaces of launcher.
+ * Each call of this interface increments a number of page to add a group
+ * of ivi_surfaces
+ */
+static void
+ivi_hmi_controller_add_launchers(struct wl_resource *resource,
+				 int32_t icon_size)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
+	int32_t minspace_x = 10;
+	int32_t minspace_y = minspace_x;
+
+	int32_t width  = hmi_ctrl->workspace_layer.width;
+	int32_t height = hmi_ctrl->workspace_layer.height;
+
+	int32_t x_count = (width - minspace_x) / (minspace_x + icon_size);
+	int32_t space_x = (int32_t)((width - x_count * icon_size) / (1.0 + x_count));
+	float fcell_size_x = icon_size + space_x;
+
+	int32_t y_count = (height - minspace_y) / (minspace_y + icon_size);
+	int32_t space_y = (int32_t)((height - y_count * icon_size) / (1.0 + y_count));
+	float fcell_size_y = icon_size + space_y;
+
+	struct weston_config *config = NULL;
+	struct weston_config_section *section = NULL;
+	const char *name = NULL;
+	int launcher_count = 0;
+	struct wl_array launchers;
+	int32_t nx = 0;
+	int32_t ny = 0;
+	int32_t prev = -1;
+	struct launcher_info *data = NULL;
+
+	uint32_t surfaceid = 0;
+	uint32_t workspaceid = 0;
+	struct launcher_info *info = NULL;
+
+	int32_t x = 0;
+	int32_t y = 0;
+	int32_t ret = 0;
+	struct ivi_layout_surface* layout_surface = NULL;
+	uint32_t *add_surface_id = NULL;
+
+	if (0 == x_count)
+		x_count = 1;
+
+	if (0 == y_count)
+		y_count  = 1;
+
+	config = hmi_ctrl->compositor->config;
+	if (!config)
+		return;
+
+	section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
+	if (!section)
+		return;
+
+	wl_array_init(&launchers);
+
+	while (weston_config_next_section(config, &section, &name)) {
+		surfaceid = 0;
+		workspaceid = 0;
+		info = NULL;
+		if (0 != strcmp(name, "ivi-launcher"))
+			continue;
+
+		if (0 != weston_config_section_get_uint(section, "icon-id",
+							&surfaceid, 0))
+			continue;
+
+		if (0 != weston_config_section_get_uint(section,
+							"workspace-id",
+							&workspaceid, 0))
+			continue;
+
+		info = wl_array_add(&launchers, sizeof(*info));
+
+		if (info) {
+			info->surface_id = surfaceid;
+			info->workspace_id = workspaceid;
+			info->index = launcher_count;
+			++launcher_count;
+		}
+	}
+
+	qsort(launchers.data, launcher_count, sizeof(struct launcher_info),
+	      compare_launcher_info);
+
+	wl_array_for_each(data, &launchers) {
+		x = 0;
+		y = 0;
+		ret = 0;
+		layout_surface = NULL;
+		add_surface_id = wl_array_add(&hmi_ctrl->ui_widgets,
+					      sizeof(*add_surface_id));
+
+		*add_surface_id = data->surface_id;
+
+		if (0 > prev || (uint32_t)prev != data->workspace_id) {
+			nx = 0;
+			ny = 0;
+			prev = data->workspace_id;
+
+			if (0 <= prev)
+				hmi_ctrl->workspace_count++;
+		}
+
+		if (y_count == ny) {
+			ny = 0;
+			hmi_ctrl->workspace_count++;
+		}
+
+		x = nx * fcell_size_x + (hmi_ctrl->workspace_count - 1) * width + space_x;
+		y = ny * fcell_size_y  + space_y;
+
+		layout_surface =
+			ivi_layout_get_surface_from_id(data->surface_id);
+		assert(layout_surface);
+
+		ret = ivi_layout_layer_add_surface(layer, layout_surface);
+		assert(!ret);
+
+		ret = ivi_layout_surface_set_destination_rectangle(
+				layout_surface, x, y, icon_size, icon_size);
+		assert(!ret);
+
+		ret = ivi_layout_surface_set_visibility(layout_surface, true);
+		assert(!ret);
+
+		nx++;
+
+		if (x_count == nx) {
+			ny++;
+			nx = 0;
+		}
+	}
+
+	wl_array_release(&launchers);
+	ivi_layout_commit_changes();
+}
+
+static void
+ivi_hmi_controller_UI_ready(struct wl_client *client,
+			    struct wl_resource *resource)
+{
+	struct setting {
+		uint32_t background_id;
+		uint32_t panel_id;
+		uint32_t tiling_id;
+		uint32_t sidebyside_id;
+		uint32_t fullscreen_id;
+		uint32_t random_id;
+		uint32_t home_id;
+		uint32_t workspace_background_id;
+	};
+
+	struct config_command {
+		char *key;
+		uint32_t *dest;
+	};
+
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	struct weston_config *config = hmi_ctrl->compositor->config;
+	struct weston_config_section *section = NULL;
+	struct setting dest;
+	int result = 0;
+	int i = 0;
+
+	const struct config_command uint_commands[] = {
+		{ "background-id", &dest.background_id },
+		{ "panel-id", &dest.panel_id },
+		{ "tiling-id", &dest.tiling_id },
+		{ "sidebyside-id", &dest.sidebyside_id },
+		{ "fullscreen-id", &dest.fullscreen_id },
+		{ "random-id", &dest.random_id },
+		{ "home-id", &dest.home_id },
+		{ "workspace-background-id", &dest.workspace_background_id },
+		{ NULL, NULL }
+	};
+
+	section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
+
+	for (i = 0; -1 != result; ++i) {
+		const struct config_command *command = &uint_commands[i];
+
+		if (!command->key)
+			break;
+
+		if (weston_config_section_get_uint(
+		    section, command->key, command->dest, 0) != 0)
+			result = -1;
+	}
+
+	if (-1 == result) {
+		wl_resource_post_error(resource,
+			IVI_HMI_CONTROLLER_ERROR_CODE_INIT_FAILED,
+			"Failed to initialize hmi-controller.");
+		return;
+	}
+
+	ivi_hmi_controller_set_background(hmi_ctrl, dest.background_id);
+	ivi_hmi_controller_set_panel(hmi_ctrl, dest.panel_id);
+	ivi_hmi_controller_set_button(hmi_ctrl, dest.tiling_id, 0);
+	ivi_hmi_controller_set_button(hmi_ctrl, dest.sidebyside_id, 1);
+	ivi_hmi_controller_set_button(hmi_ctrl, dest.fullscreen_id, 2);
+	ivi_hmi_controller_set_button(hmi_ctrl, dest.random_id, 3);
+	ivi_hmi_controller_set_home_button(hmi_ctrl, dest.home_id);
+	ivi_hmi_controller_set_workspacebackground(hmi_ctrl,
+						dest.workspace_background_id);
+	ivi_layout_commit_changes();
+
+	ivi_hmi_controller_add_launchers(resource, 256);
+	hmi_ctrl->is_initialized = 1;
+}
+
+/**
+ * Implementation of request and event of ivi_hmi_controller_workspace_control
+ * and controlling workspace.
+ *
+ * When motion of input is detected in a ivi_surface of workspace background,
+ * ivi_hmi_controller_workspace_control shall be invoked and to start
+ * controlling of workspace. The workspace has several pages to show several
+ * groups of applications.
+ * The workspace is slid by using ivi-layout to select a a page in layer_set_pos
+ * according to motion. When motion finished, e.g. touch up detected, control is
+ * terminated and event:ivi_hmi_controller_workspace_control is notified.
+ */
+struct pointer_grab {
+	struct weston_pointer_grab grab;
+	struct ivi_layout_layer *layer;
+	struct wl_resource *resource;
+};
+
+struct touch_grab {
+	struct weston_touch_grab grab;
+	struct ivi_layout_layer *layer;
+	struct wl_resource *resource;
+};
+
+struct move_grab {
+	wl_fixed_t dst[2];
+	wl_fixed_t rgn[2][2];
+	double v[2];
+	struct timespec start_time;
+	struct timespec pre_time;
+	wl_fixed_t start_pos[2];
+	wl_fixed_t pos[2];
+	int32_t is_moved;
+};
+
+struct pointer_move_grab {
+	struct pointer_grab base;
+	struct move_grab move;
+};
+
+struct touch_move_grab {
+	struct touch_grab base;
+	struct move_grab move;
+	int32_t is_active;
+};
+
+static void
+pointer_grab_start(struct pointer_grab *grab,
+		   struct ivi_layout_layer *layer,
+		   const struct weston_pointer_grab_interface *interface,
+		   struct weston_pointer *pointer)
+{
+	grab->grab.interface = interface;
+	grab->layer = layer;
+	weston_pointer_start_grab(pointer, &grab->grab);
+}
+
+static void
+touch_grab_start(struct touch_grab *grab,
+		 struct ivi_layout_layer *layer,
+		 const struct weston_touch_grab_interface *interface,
+		 struct weston_touch* touch)
+{
+	grab->grab.interface = interface;
+	grab->layer = layer;
+	weston_touch_start_grab(touch, &grab->grab);
+}
+
+static int32_t
+clamp(int32_t val, int32_t min, int32_t max)
+{
+	if (val < min)
+		return min;
+
+	if (max < val)
+		return max;
+
+	return val;
+}
+
+static void
+move_workspace_grab_end(struct move_grab *move, struct wl_resource* resource,
+			wl_fixed_t grab_x, struct ivi_layout_layer *layer)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	int32_t width = hmi_ctrl->workspace_background_layer.width;
+
+	struct timespec time = {0};
+	double grab_time = 0.0;
+	double  from_motion_time = 0.0;
+	double pointer_v = 0.0;
+	int32_t is_flick = 0;
+	int32_t pos_x = 0;
+	int32_t pos_y = 0;
+	int page_no = 0;
+	double end_pos = 0.0;
+	uint32_t duration = 0;
+
+	clock_gettime(CLOCK_MONOTONIC, &time);
+
+	grab_time = 1e+3 * (time.tv_sec  - move->start_time.tv_sec) +
+		    1e-6 * (time.tv_nsec - move->start_time.tv_nsec);
+
+	from_motion_time = 1e+3 * (time.tv_sec  - move->pre_time.tv_sec) +
+			   1e-6 * (time.tv_nsec - move->pre_time.tv_nsec);
+
+	pointer_v = move->v[0];
+
+	is_flick = grab_time < 400 && 0.4 < fabs(pointer_v);
+	if (200 < from_motion_time)
+		pointer_v = 0.0;
+
+	ivi_layout_layer_get_position(layer, &pos_x, &pos_y);
+
+
+	if (is_flick) {
+		int orgx = wl_fixed_to_int(move->dst[0] + grab_x);
+		page_no = (-orgx + width / 2) / width;
+
+		if (pointer_v < 0.0)
+			page_no++;
+		else
+			page_no--;
+	} else {
+		page_no = (-pos_x + width / 2) / width;
+	}
+
+	page_no = clamp(page_no, 0, hmi_ctrl->workspace_count - 1);
+	end_pos = -page_no * width;
+
+	duration = hmi_ctrl->hmi_setting->transition_duration;
+	ivi_hmi_controller_send_workspace_end_control(resource, move->is_moved);
+	ivi_layout_layer_set_transition(layer,
+					IVI_LAYOUT_TRANSITION_LAYER_MOVE,
+					duration);
+	ivi_layout_layer_set_destination_rectangle(layer,
+				end_pos, pos_y,
+				hmi_ctrl->workspace_background_layer.width,
+				hmi_ctrl->workspace_background_layer.height);
+	ivi_layout_commit_changes();
+}
+
+static void
+pointer_move_workspace_grab_end(struct pointer_grab *grab)
+{
+	struct pointer_move_grab *pnt_move_grab =
+		(struct pointer_move_grab *)grab;
+	struct ivi_layout_layer *layer = pnt_move_grab->base.layer;
+
+	move_workspace_grab_end(&pnt_move_grab->move, grab->resource,
+				grab->grab.pointer->grab_x, layer);
+
+	weston_pointer_end_grab(grab->grab.pointer);
+}
+
+static void
+touch_move_workspace_grab_end(struct touch_grab *grab)
+{
+	struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
+	struct ivi_layout_layer *layer = tch_move_grab->base.layer;
+
+	move_workspace_grab_end(&tch_move_grab->move, grab->resource,
+				grab->grab.touch->grab_x, layer);
+
+	weston_touch_end_grab(grab->grab.touch);
+}
+
+static void
+pointer_noop_grab_focus(struct weston_pointer_grab *grab)
+{
+}
+
+static void
+move_grab_update(struct move_grab *move, wl_fixed_t pointer[2])
+{
+	struct timespec timestamp = {0};
+	int32_t ii = 0;
+	double dt = 0.0;
+
+	clock_gettime(CLOCK_MONOTONIC, &timestamp); //FIXME
+	dt = (1e+3 * (timestamp.tv_sec  - move->pre_time.tv_sec) +
+	      1e-6 * (timestamp.tv_nsec - move->pre_time.tv_nsec));
+
+	if (dt < 1e-6)
+		dt = 1e-6;
+
+	move->pre_time = timestamp;
+
+	for (ii = 0; ii < 2; ii++) {
+		wl_fixed_t prepos = move->pos[ii];
+		move->pos[ii] = pointer[ii] + move->dst[ii];
+
+		if (move->pos[ii] < move->rgn[0][ii]) {
+			move->pos[ii] = move->rgn[0][ii];
+			move->dst[ii] = move->pos[ii] - pointer[ii];
+		} else if (move->rgn[1][ii] < move->pos[ii]) {
+			move->pos[ii] = move->rgn[1][ii];
+			move->dst[ii] = move->pos[ii] - pointer[ii];
+		}
+
+		move->v[ii] = wl_fixed_to_double(move->pos[ii] - prepos) / dt;
+
+		if (!move->is_moved &&
+		    0 < wl_fixed_to_int(move->pos[ii] - move->start_pos[ii]))
+			move->is_moved = 1;
+	}
+}
+
+static void
+layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
+	      wl_fixed_t pos_y)
+{
+	int32_t layout_pos_x = 0;
+	int32_t layout_pos_y = 0;
+
+	layout_pos_x = wl_fixed_to_int(pos_x);
+	layout_pos_y = wl_fixed_to_int(pos_y);
+	ivi_layout_layer_set_position(layer, layout_pos_x, layout_pos_y);
+	ivi_layout_commit_changes();
+}
+
+static void
+pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+			 wl_fixed_t x, wl_fixed_t y)
+{
+	struct pointer_move_grab *pnt_move_grab =
+		(struct pointer_move_grab *)grab;
+	wl_fixed_t pointer_pos[2] = {x, y};
+
+	move_grab_update(&pnt_move_grab->move, pointer_pos);
+	layer_set_pos(pnt_move_grab->base.layer,
+		      pnt_move_grab->move.pos[0], pnt_move_grab->move.pos[1]);
+	weston_pointer_move(pnt_move_grab->base.grab.pointer, x, y);
+}
+
+static void
+touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
+		       int touch_id, wl_fixed_t x, wl_fixed_t y)
+{
+	struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
+
+	if (!tch_move_grab->is_active)
+		return;
+
+	wl_fixed_t pointer_pos[2] = {
+		grab->touch->grab_x,
+		grab->touch->grab_y
+	};
+
+	move_grab_update(&tch_move_grab->move, pointer_pos);
+	layer_set_pos(tch_move_grab->base.layer,
+		      tch_move_grab->move.pos[0], tch_move_grab->move.pos[1]);
+}
+
+static void
+pointer_move_workspace_grab_button(struct weston_pointer_grab *grab,
+				   uint32_t time, uint32_t button,
+				   uint32_t state_w)
+{
+	if (BTN_LEFT == button &&
+	    WL_POINTER_BUTTON_STATE_RELEASED == state_w) {
+		struct pointer_grab *pg = (struct pointer_grab *)grab;
+
+		pointer_move_workspace_grab_end(pg);
+		free(grab);
+	}
+}
+
+static void
+touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
+		     int touch_id, wl_fixed_t sx, wl_fixed_t sy)
+{
+}
+
+static void
+touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time,
+			     int touch_id)
+{
+	struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
+
+	if (0 == touch_id)
+		tch_move_grab->is_active = 0;
+
+	if (0 == grab->touch->num_tp) {
+		touch_move_workspace_grab_end(&tch_move_grab->base);
+		free(grab);
+	}
+}
+
+static void
+pointer_move_workspace_grab_cancel(struct weston_pointer_grab *grab)
+{
+	struct pointer_grab *pg = (struct pointer_grab *)grab;
+
+	pointer_move_workspace_grab_end(pg);
+	free(grab);
+}
+
+static void
+touch_move_workspace_grab_cancel(struct weston_touch_grab *grab)
+{
+	struct touch_grab *tg = (struct touch_grab *)grab;
+
+	touch_move_workspace_grab_end(tg);
+	free(grab);
+}
+
+static const struct weston_pointer_grab_interface pointer_move_grab_workspace_interface = {
+	pointer_noop_grab_focus,
+	pointer_move_grab_motion,
+	pointer_move_workspace_grab_button,
+	pointer_move_workspace_grab_cancel
+};
+
+static const struct weston_touch_grab_interface touch_move_grab_workspace_interface = {
+	touch_nope_grab_down,
+	touch_move_workspace_grab_up,
+	touch_move_grab_motion,
+	touch_move_workspace_grab_cancel
+};
+
+enum HMI_GRAB_DEVICE {
+	HMI_GRAB_DEVICE_NONE,
+	HMI_GRAB_DEVICE_POINTER,
+	HMI_GRAB_DEVICE_TOUCH
+};
+
+static enum HMI_GRAB_DEVICE
+get_hmi_grab_device(struct weston_seat *seat, uint32_t serial)
+{
+	if (seat->pointer &&
+	    seat->pointer->focus &&
+	    seat->pointer->button_count &&
+	    seat->pointer->grab_serial == serial)
+		return HMI_GRAB_DEVICE_POINTER;
+
+	if (seat->touch &&
+	    seat->touch->focus &&
+	    seat->touch->grab_serial == serial)
+		return HMI_GRAB_DEVICE_TOUCH;
+
+	return HMI_GRAB_DEVICE_NONE;
+}
+
+static void
+move_grab_init(struct move_grab* move, wl_fixed_t start_pos[2],
+	       wl_fixed_t grab_pos[2], wl_fixed_t rgn[2][2],
+	       struct wl_resource* resource)
+{
+	clock_gettime(CLOCK_MONOTONIC, &move->start_time); //FIXME
+	move->pre_time = move->start_time;
+	move->pos[0] = start_pos[0];
+	move->pos[1] = start_pos[1];
+	move->start_pos[0] = start_pos[0];
+	move->start_pos[1] = start_pos[1];
+	move->dst[0] = start_pos[0] - grab_pos[0];
+	move->dst[1] = start_pos[1] - grab_pos[1];
+	memcpy(move->rgn, rgn, sizeof(move->rgn));
+}
+
+static void
+move_grab_init_workspace(struct move_grab* move,
+			 wl_fixed_t grab_x, wl_fixed_t grab_y,
+			 struct wl_resource *resource)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	struct ivi_layout_layer *layer = hmi_ctrl->workspace_layer.ivilayer;
+	int32_t workspace_count = hmi_ctrl->workspace_count;
+	int32_t workspace_width = hmi_ctrl->workspace_background_layer.width;
+	int32_t layer_pos_x = 0;
+	int32_t layer_pos_y = 0;
+	wl_fixed_t start_pos[2] = {0};
+	wl_fixed_t rgn[2][2] = {{0}};
+	wl_fixed_t grab_pos[2] = { grab_x, grab_y };
+
+	ivi_layout_layer_get_position(layer, &layer_pos_x, &layer_pos_y);
+
+	start_pos[0] = wl_fixed_from_int(layer_pos_x);
+	start_pos[1] = wl_fixed_from_int(layer_pos_y);
+
+	rgn[0][0] = wl_fixed_from_int(-workspace_width * (workspace_count - 1));
+
+	rgn[0][1] = wl_fixed_from_int(0);
+	rgn[1][0] = wl_fixed_from_int(0);
+	rgn[1][1] = wl_fixed_from_int(0);
+
+	move_grab_init(move, start_pos, grab_pos, rgn, resource);
+}
+
+static struct pointer_move_grab *
+create_workspace_pointer_move(struct weston_pointer *pointer,
+			      struct wl_resource* resource)
+{
+	struct pointer_move_grab *pnt_move_grab =
+		MEM_ALLOC(sizeof(*pnt_move_grab));
+
+	pnt_move_grab->base.resource = resource;
+	move_grab_init_workspace(&pnt_move_grab->move, pointer->grab_x,
+				 pointer->grab_y, resource);
+
+	return pnt_move_grab;
+}
+
+static struct touch_move_grab *
+create_workspace_touch_move(struct weston_touch *touch,
+			    struct wl_resource* resource)
+{
+	struct touch_move_grab *tch_move_grab =
+		MEM_ALLOC(sizeof(*tch_move_grab));
+
+	tch_move_grab->base.resource = resource;
+	tch_move_grab->is_active = 1;
+	move_grab_init_workspace(&tch_move_grab->move, touch->grab_x,
+				 touch->grab_y, resource);
+
+	return tch_move_grab;
+}
+
+static void
+ivi_hmi_controller_workspace_control(struct wl_client *client,
+				     struct wl_resource *resource,
+				     struct wl_resource *seat_resource,
+				     uint32_t serial)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	struct ivi_layout_layer *layer = NULL;
+	struct pointer_move_grab *pnt_move_grab = NULL;
+	struct touch_move_grab *tch_move_grab = NULL;
+	struct weston_seat *seat = NULL;
+	enum HMI_GRAB_DEVICE device;
+
+	if (hmi_ctrl->workspace_count < 2)
+		return;
+
+	seat = wl_resource_get_user_data(seat_resource);
+	device = get_hmi_grab_device(seat, serial);
+
+	if (HMI_GRAB_DEVICE_POINTER != device &&
+	    HMI_GRAB_DEVICE_TOUCH != device)
+		return;
+
+	layer = hmi_ctrl->workspace_layer.ivilayer;
+
+	ivi_layout_transition_move_layer_cancel(layer);
+
+	switch (device) {
+	case HMI_GRAB_DEVICE_POINTER:
+		pnt_move_grab = create_workspace_pointer_move(seat->pointer,
+							      resource);
+
+		pointer_grab_start(&pnt_move_grab->base, layer,
+				   &pointer_move_grab_workspace_interface,
+				   seat->pointer);
+		break;
+
+	case HMI_GRAB_DEVICE_TOUCH:
+		tch_move_grab = create_workspace_touch_move(seat->touch,
+							    resource);
+
+		touch_grab_start(&tch_move_grab->base, layer,
+				 &touch_move_grab_workspace_interface,
+				 seat->touch);
+		break;
+
+	default:
+		break;
+	}
+}
+
+/**
+ * Implementation of switch_mode
+ */
+static void
+ivi_hmi_controller_switch_mode(struct wl_client *client,
+			       struct wl_resource *resource,
+			       uint32_t  layout_mode)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+
+	switch_mode(hmi_ctrl, layout_mode);
+}
+
+/**
+ * Implementation of on/off displaying workspace and workspace background
+ * ivi_layers.
+ */
+static void
+ivi_hmi_controller_home(struct wl_client *client,
+			struct wl_resource *resource,
+			uint32_t home)
+{
+	struct hmi_controller *hmi_ctrl = wl_resource_get_user_data(resource);
+	uint32_t is_fade_in;
+
+	if ((IVI_HMI_CONTROLLER_HOME_ON  == home &&
+	     !hmi_ctrl->workspace_fade.is_fade_in) ||
+	    (IVI_HMI_CONTROLLER_HOME_OFF == home &&
+	     hmi_ctrl->workspace_fade.is_fade_in)) {
+		is_fade_in = !hmi_ctrl->workspace_fade.is_fade_in;
+		hmi_controller_fade_run(hmi_ctrl, is_fade_in,
+					&hmi_ctrl->workspace_fade);
+	}
+
+	ivi_layout_commit_changes();
+}
+
+/**
+ * binding ivi-hmi-controller implementation
+ */
+static const struct ivi_hmi_controller_interface ivi_hmi_controller_implementation = {
+	ivi_hmi_controller_UI_ready,
+	ivi_hmi_controller_workspace_control,
+	ivi_hmi_controller_switch_mode,
+	ivi_hmi_controller_home
+};
+
+static void
+unbind_hmi_controller(struct wl_resource *resource)
+{
+}
+
+static void
+bind_hmi_controller(struct wl_client *client,
+		    void *data, uint32_t version, uint32_t id)
+{
+	struct wl_resource *resource = NULL;
+	struct hmi_controller *hmi_ctrl = data;
+
+	if (hmi_ctrl->user_interface != client) {
+		wl_resource_post_error(resource,
+				WL_DISPLAY_ERROR_INVALID_OBJECT,
+				"hmi-controller failed: permission denied");
+		return;
+	}
+
+	resource = wl_resource_create(
+		client, &ivi_hmi_controller_interface, 1, id);
+
+	wl_resource_set_implementation(
+		resource, &ivi_hmi_controller_implementation,
+		hmi_ctrl, unbind_hmi_controller);
+}
+
+static void
+launch_hmi_client_process(void *data)
+{
+	struct hmi_controller *hmi_ctrl =
+		(struct hmi_controller *)data;
+
+	hmi_ctrl->user_interface =
+		weston_client_start(hmi_ctrl->compositor,
+				    hmi_ctrl->hmi_setting->ivi_homescreen);
+
+	free(hmi_ctrl->hmi_setting->ivi_homescreen);
+}
+
+/*****************************************************************************
+ *  exported functions
+ ****************************************************************************/
+
+WL_EXPORT int
+module_init(struct weston_compositor *ec,
+	    int *argc, char *argv[])
+{
+	struct hmi_controller *hmi_ctrl = hmi_controller_create(ec);
+	struct wl_event_loop *loop = NULL;
+
+	if (wl_global_create(ec->wl_display,
+			     &ivi_hmi_controller_interface, 1,
+			     hmi_ctrl, bind_hmi_controller) == NULL) {
+		return -1;
+	}
+
+	loop = wl_display_get_event_loop(ec->wl_display);
+	wl_event_loop_add_idle(loop, launch_hmi_client_process, hmi_ctrl);
+
+	return 0;
+}
-- 
1.7.9.5