summaryrefslogtreecommitdiff
path: root/clients/ivi-shell-user-interface.c
blob: 06b79a2278f01a1a18cc7b71979de475bf519b2f (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
/*
 * Copyright (C) 2013 DENSO CORPORATION
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "config.h"

#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <linux/input.h>
#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>
#include <getopt.h>
#include <wayland-cursor.h>
#include <wayland-client-protocol.h>
#include "shared/cairo-util.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "ivi-application-client-protocol.h"
#include "ivi-hmi-controller-client-protocol.h"

/**
 * A reference implementation how to use ivi-hmi-controller interface to
 * interact with hmi-controller. This is launched from hmi-controller by using
 * hmi_client_start and create a pthread.
 *
 * The basic flow is as followed,
 * 1/ read configuration from weston.ini.
 * 2/ draw png file to surface according to configuration of weston.ini
 * 3/ set up UI by using ivi-hmi-controller protocol
 * 4/ Enter event loop
 * 5/ If a surface receives touch/pointer event, followings are invoked
 *	according to type of event and surface
 * 5-1/ If a surface to launch ivi_application receive touch up, it execs
 *	  ivi-application configured in weston.ini.
 * 5-2/ If a surface to switch layout mode receive touch up, it sends a request,
 *	  ivi_hmi_controller_switch_mode, to hmi-controller.
 * 5-3/ If a surface to show workspace having launchers, it sends a request,
 *	  ivi_hmi_controller_home, to hmi-controller.
 * 5-4/ If touch down events happens in workspace,
 *	  ivi_hmi_controller_workspace_control is sent to slide workspace.
 *	  When control finished, event: ivi_hmi_controller_workspace_end_control
 *	  is received.
 */

/*****************************************************************************
 *  structure, globals
 ****************************************************************************/
enum cursor_type {
	CURSOR_BOTTOM_LEFT,
	CURSOR_BOTTOM_RIGHT,
	CURSOR_BOTTOM,
	CURSOR_DRAGGING,
	CURSOR_LEFT_PTR,
	CURSOR_LEFT,
	CURSOR_RIGHT,
	CURSOR_TOP_LEFT,
	CURSOR_TOP_RIGHT,
	CURSOR_TOP,
	CURSOR_IBEAM,
	CURSOR_HAND1,
	CURSOR_WATCH,

	CURSOR_BLANK
};
struct wlContextCommon {
	struct wl_display		*wlDisplay;
	struct wl_registry		*wlRegistry;
	struct wl_compositor		*wlCompositor;
	struct wl_shm			*wlShm;
	uint32_t			formats;
	struct wl_seat			*wlSeat;
	struct wl_pointer		*wlPointer;
	struct wl_touch			*wlTouch;
	struct ivi_application		*iviApplication;
	struct ivi_hmi_controller	*hmiCtrl;
	struct hmi_homescreen_setting	*hmi_setting;
	struct wl_list			list_wlContextStruct;
	struct wl_surface		*enterSurface;
	int32_t				is_home_on;
	struct wl_cursor_theme		*cursor_theme;
	struct wl_cursor		**cursors;
	struct wl_surface		*pointer_surface;
	enum   cursor_type		current_cursor;
	uint32_t			enter_serial;
};

struct wlContextStruct {
	struct wlContextCommon	*cmm;
	struct wl_surface	*wlSurface;
	struct wl_buffer	*wlBuffer;
	cairo_surface_t		*ctx_image;
	void			*data;
	uint32_t		id_surface;
	struct wl_list		link;
};

struct
hmi_homescreen_srf {
	uint32_t	id;
	char		*filePath;
	uint32_t	color;
};

struct
hmi_homescreen_workspace {
	struct wl_array	launcher_id_array;
	struct wl_list	link;
};

struct
hmi_homescreen_launcher {
	uint32_t	icon_surface_id;
	uint32_t	workspace_id;
	char		*icon;
	char		*path;
	struct wl_list	link;
};

struct
hmi_homescreen_setting {
	struct hmi_homescreen_srf background;
	struct hmi_homescreen_srf panel;
	struct hmi_homescreen_srf tiling;
	struct hmi_homescreen_srf sidebyside;
	struct hmi_homescreen_srf fullscreen;
	struct hmi_homescreen_srf random;
	struct hmi_homescreen_srf home;
	struct hmi_homescreen_srf workspace_background;

	struct wl_list workspace_list;
	struct wl_list launcher_list;

	char		*cursor_theme;
	int32_t		cursor_size;
	uint32_t	transition_duration;
	uint32_t	surface_id_offset;
	int32_t		screen_num;
};

/*****************************************************************************
 *  Event Handler
 ****************************************************************************/

static void
shm_format(void *data, struct wl_shm *pWlShm, uint32_t format)
{
	struct wlContextCommon *pCtx = data;

	pCtx->formats |= (1 << format);
}

static struct wl_shm_listener shm_listenter = {
	shm_format
};

static int32_t
getIdOfWlSurface(struct wlContextCommon *pCtx, struct wl_surface *wlSurface)
{
	struct wlContextStruct *pWlCtxSt = NULL;

	if (NULL == pCtx || NULL == wlSurface )
		return 0;

	wl_list_for_each(pWlCtxSt, &pCtx->list_wlContextStruct, link) {
		if (pWlCtxSt->wlSurface == wlSurface)
			return pWlCtxSt->id_surface;
	}

	return -1;
}

static void
set_pointer_image(struct wlContextCommon *pCtx, uint32_t index)
{
	struct wl_cursor *cursor = NULL;
	struct wl_cursor_image *image = NULL;
	struct wl_buffer *buffer = NULL;

	if (!pCtx->wlPointer || !pCtx->cursors)
		return;

	if (CURSOR_BLANK == pCtx->current_cursor) {
		wl_pointer_set_cursor(pCtx->wlPointer, pCtx->enter_serial,
							  NULL, 0, 0);
		return;
	}

	cursor = pCtx->cursors[pCtx->current_cursor];
	if (!cursor)
		return;

	if (cursor->image_count <= index) {
		fprintf(stderr, "cursor index out of range\n");
		return;
	}

	image = cursor->images[index];
	buffer = wl_cursor_image_get_buffer(image);

	if (!buffer)
		return;

	wl_pointer_set_cursor(pCtx->wlPointer, pCtx->enter_serial,
			      pCtx->pointer_surface,
			      image->hotspot_x, image->hotspot_y);

	wl_surface_attach(pCtx->pointer_surface, buffer, 0, 0);

	wl_surface_damage(pCtx->pointer_surface, 0, 0,
					  image->width, image->height);

	wl_surface_commit(pCtx->pointer_surface);
}

static void
PointerHandleEnter(void *data, struct wl_pointer *wlPointer, uint32_t serial,
		   struct wl_surface *wlSurface, wl_fixed_t sx, wl_fixed_t sy)
{
	struct wlContextCommon *pCtx = data;

	pCtx->enter_serial = serial;
	pCtx->enterSurface = wlSurface;
	set_pointer_image(pCtx, 0);
#ifdef _DEBUG
	printf("ENTER PointerHandleEnter: x(%d), y(%d)\n", sx, sy);
#endif
}

static void
PointerHandleLeave(void *data, struct wl_pointer *wlPointer, uint32_t serial,
		   struct wl_surface *wlSurface)
{
	struct wlContextCommon *pCtx = data;

	pCtx->enterSurface = NULL;

#ifdef _DEBUG
	printf("ENTER PointerHandleLeave: serial(%d)\n", serial);
#endif
}

static void
PointerHandleMotion(void *data, struct wl_pointer *wlPointer, uint32_t time,
		    wl_fixed_t sx, wl_fixed_t sy)
{
#ifdef _DEBUG
	printf("ENTER PointerHandleMotion: x(%d), y(%d)\n", sx, sy);
#endif
}

/**
 * if a surface assigned as launcher receives touch-off event, invoking
 * ivi-application which configured in weston.ini with path to binary.
 */
extern char **environ; /*defied by libc */

static pid_t
execute_process(char *path, char *argv[])
{
	pid_t pid = fork();
	if (pid < 0)
		fprintf(stderr, "Failed to fork\n");

	if (pid)
		return pid;

	if (-1 == execve(path, argv, environ)) {
		fprintf(stderr, "Failed to execve %s\n", path);
		exit(1);
	}

	return pid;
}

static int32_t
launcher_button(uint32_t surfaceId, struct wl_list *launcher_list)
{
	struct hmi_homescreen_launcher *launcher = NULL;

	wl_list_for_each(launcher, launcher_list, link) {
		char *argv[] = { NULL };

		if (surfaceId != launcher->icon_surface_id)
			continue;

		execute_process(launcher->path, argv);

		return 1;
	}

	return 0;
}

/**
 * is-method to identify a surface set as launcher in workspace or workspace
 * itself. This is-method is used to decide whether request;
 * ivi_hmi_controller_workspace_control is sent or not.
 */
static int32_t
isWorkspaceSurface(uint32_t id, struct hmi_homescreen_setting *hmi_setting)
{
	struct hmi_homescreen_launcher *launcher = NULL;

	if (id == hmi_setting->workspace_background.id)
		return 1;

	wl_list_for_each(launcher, &hmi_setting->launcher_list, link) {
		if (id == launcher->icon_surface_id)
			return 1;
	}

	return 0;
}

/**
 * Decide which request is sent to hmi-controller
 */
static void
touch_up(struct ivi_hmi_controller *hmi_ctrl, uint32_t id_surface,
	 int32_t *is_home_on, struct hmi_homescreen_setting *hmi_setting)
{
	if (launcher_button(id_surface, &hmi_setting->launcher_list)) {
		*is_home_on = 0;
		ivi_hmi_controller_home(hmi_ctrl, IVI_HMI_CONTROLLER_HOME_OFF);
	} else if (id_surface == hmi_setting->tiling.id) {
		ivi_hmi_controller_switch_mode(hmi_ctrl,
				IVI_HMI_CONTROLLER_LAYOUT_MODE_TILING);
	} else if (id_surface == hmi_setting->sidebyside.id) {
		ivi_hmi_controller_switch_mode(hmi_ctrl,
				IVI_HMI_CONTROLLER_LAYOUT_MODE_SIDE_BY_SIDE);
	} else if (id_surface == hmi_setting->fullscreen.id) {
		ivi_hmi_controller_switch_mode(hmi_ctrl,
				IVI_HMI_CONTROLLER_LAYOUT_MODE_FULL_SCREEN);
	} else if (id_surface == hmi_setting->random.id) {
		ivi_hmi_controller_switch_mode(hmi_ctrl,
				IVI_HMI_CONTROLLER_LAYOUT_MODE_RANDOM);
	} else if (id_surface == hmi_setting->home.id) {
		*is_home_on = !(*is_home_on);
		if (*is_home_on) {
			ivi_hmi_controller_home(hmi_ctrl,
						IVI_HMI_CONTROLLER_HOME_ON);
		} else {
			ivi_hmi_controller_home(hmi_ctrl,
						IVI_HMI_CONTROLLER_HOME_OFF);
		}
	}
}

/**
 * Even handler of Pointer event. IVI system is usually manipulated by touch
 * screen. However, some systems also have pointer device.
 * Release is the same behavior as touch off
 * Pressed is the same behavior as touch on
 */
static void
PointerHandleButton(void *data, struct wl_pointer *wlPointer, uint32_t serial,
		    uint32_t time, uint32_t button, uint32_t state)
{
	struct wlContextCommon *pCtx = data;
	struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl;
	const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface);

	if (BTN_RIGHT == button)
		return;

	switch (state) {
	case WL_POINTER_BUTTON_STATE_RELEASED:
		touch_up(hmi_ctrl, id_surface, &pCtx->is_home_on,
			 pCtx->hmi_setting);
		break;

	case WL_POINTER_BUTTON_STATE_PRESSED:

		if (isWorkspaceSurface(id_surface, pCtx->hmi_setting)) {
			ivi_hmi_controller_workspace_control(hmi_ctrl,
							     pCtx->wlSeat,
							     serial);
		}

		break;
	}
#ifdef _DEBUG
	printf("ENTER PointerHandleButton: button(%d), state(%d)\n",
	       button, state);
#endif
}

static void
PointerHandleAxis(void *data, struct wl_pointer *wlPointer, uint32_t time,
		  uint32_t axis, wl_fixed_t value)
{
#ifdef _DEBUG
	printf("ENTER PointerHandleAxis: axis(%d), value(%d)\n", axis, value);
#endif
}

static struct wl_pointer_listener pointer_listener = {
	PointerHandleEnter,
	PointerHandleLeave,
	PointerHandleMotion,
	PointerHandleButton,
	PointerHandleAxis
};

/**
 * Even handler of touch event
 */
static void
TouchHandleDown(void *data, struct wl_touch *wlTouch, uint32_t serial,
		uint32_t time, struct wl_surface *surface, int32_t id,
		wl_fixed_t x_w, wl_fixed_t y_w)
{
	struct wlContextCommon *pCtx = data;
	struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl;
	uint32_t id_surface = 0;

	if (0 == id)
		pCtx->enterSurface = surface;

	id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface);

	/**
	 * When touch down happens on surfaces of workspace, ask
	 * hmi-controller to start control workspace to select page of
	 * workspace. After sending seat to hmi-controller by
	 * ivi_hmi_controller_workspace_control,
	 * hmi-controller-homescreen doesn't receive any event till
	 * hmi-controller sends back it.
	 */
	if (isWorkspaceSurface(id_surface, pCtx->hmi_setting)) {
		ivi_hmi_controller_workspace_control(hmi_ctrl, pCtx->wlSeat,
						     serial);
	}
}

static void
TouchHandleUp(void *data, struct wl_touch *wlTouch, uint32_t serial,
	      uint32_t time, int32_t id)
{
	struct wlContextCommon *pCtx = data;
	struct ivi_hmi_controller *hmi_ctrl = pCtx->hmiCtrl;

	const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface);

	/**
	 * triggering event according to touch-up happening on which surface.
	 */
	if (id == 0){
		touch_up(hmi_ctrl, id_surface, &pCtx->is_home_on,
			 pCtx->hmi_setting);
	}
}

static void
TouchHandleMotion(void *data, struct wl_touch *wlTouch, uint32_t time,
		  int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
{
}

static void
TouchHandleFrame(void *data, struct wl_touch *wlTouch)
{
}

static void
TouchHandleCancel(void *data, struct wl_touch *wlTouch)
{
}

static struct wl_touch_listener touch_listener = {
	TouchHandleDown,
	TouchHandleUp,
	TouchHandleMotion,
	TouchHandleFrame,
	TouchHandleCancel,
};

/**
 * Handler of capabilities
 */
static void
seat_handle_capabilities(void *data, struct wl_seat *seat, uint32_t caps)
{
	struct wlContextCommon *p_wlCtx = (struct wlContextCommon*)data;
	struct wl_seat *wlSeat = p_wlCtx->wlSeat;
	struct wl_pointer *wlPointer = p_wlCtx->wlPointer;
	struct wl_touch *wlTouch = p_wlCtx->wlTouch;

	if (p_wlCtx->hmi_setting->cursor_theme) {
		if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wlPointer){
			wlPointer = wl_seat_get_pointer(wlSeat);
			wl_pointer_add_listener(wlPointer,
						&pointer_listener, data);
		} else
		if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wlPointer){
			wl_pointer_destroy(wlPointer);
			wlPointer = NULL;
		}
		p_wlCtx->wlPointer = wlPointer;
	}

	if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !wlTouch){
		wlTouch = wl_seat_get_touch(wlSeat);
		wl_touch_add_listener(wlTouch, &touch_listener, data);
	} else
	if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && wlTouch){
		wl_touch_destroy(wlTouch);
		wlTouch = NULL;
	}
	p_wlCtx->wlTouch = wlTouch;
}

static struct wl_seat_listener seat_Listener = {
	seat_handle_capabilities,
};

/**
 * Registration of event
 * This event is received when hmi-controller server finished controlling
 * workspace.
 */
static void
ivi_hmi_controller_workspace_end_control(void *data,
					 struct ivi_hmi_controller *hmi_ctrl,
					 int32_t is_controlled)
{
	struct wlContextCommon *pCtx = data;
	const uint32_t id_surface = getIdOfWlSurface(pCtx, pCtx->enterSurface);

	if (is_controlled)
		return;

	/**
	 * During being controlled by hmi-controller, any input event is not
	 * notified. So when control ends with touch up, it invokes launcher
	 * if up event happens on a launcher surface.
	 *
	 */
	if (launcher_button(id_surface, &pCtx->hmi_setting->launcher_list)) {
		pCtx->is_home_on = 0;
		ivi_hmi_controller_home(hmi_ctrl, IVI_HMI_CONTROLLER_HOME_OFF);
	}
}

static const struct ivi_hmi_controller_listener hmi_controller_listener = {
	ivi_hmi_controller_workspace_end_control
};

/**
 * Registration of interfaces
 */
static void
registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
		       const char *interface, uint32_t version)
{
	struct wlContextCommon *p_wlCtx = (struct wlContextCommon*)data;

	if (!strcmp(interface, "wl_compositor")) {
		p_wlCtx->wlCompositor =
			wl_registry_bind(registry, name,
					 &wl_compositor_interface, 1);
	} else if (!strcmp(interface, "wl_shm")) {
		p_wlCtx->wlShm =
			wl_registry_bind(registry, name, &wl_shm_interface, 1);
		wl_shm_add_listener(p_wlCtx->wlShm, &shm_listenter, p_wlCtx);
	} else if (!strcmp(interface, "wl_seat")) {
		/* XXX: should be handling multiple wl_seats */
		if (p_wlCtx->wlSeat)
			return;

		p_wlCtx->wlSeat =
			wl_registry_bind(registry, name, &wl_seat_interface, 1);
		wl_seat_add_listener(p_wlCtx->wlSeat, &seat_Listener, data);
	} else if (!strcmp(interface, "ivi_application")) {
		p_wlCtx->iviApplication =
			wl_registry_bind(registry, name,
					 &ivi_application_interface, 1);
	} else if (!strcmp(interface, "ivi_hmi_controller")) {
		p_wlCtx->hmiCtrl =
			wl_registry_bind(registry, name,
					 &ivi_hmi_controller_interface, 1);

		ivi_hmi_controller_add_listener(p_wlCtx->hmiCtrl,
				&hmi_controller_listener, p_wlCtx);
	} else if (!strcmp(interface, "wl_output")) {
		p_wlCtx->hmi_setting->screen_num++;
	}
}

static void
registry_handle_global_remove(void *data, struct wl_registry *registry,
			      uint32_t name)
{
}

static const struct wl_registry_listener registry_listener = {
	registry_handle_global,
	registry_handle_global_remove
};

static void
frame_listener_func(void *data, struct wl_callback *callback, uint32_t time)
{
	if (callback)
		wl_callback_destroy(callback);
}

static const struct wl_callback_listener frame_listener = {
	frame_listener_func
};

/*
 * The following correspondences between file names and cursors was copied
 * from: https://bugs.kde.org/attachment.cgi?id=67313
 */
static const char *bottom_left_corners[] = {
	"bottom_left_corner",
	"sw-resize",
	"size_bdiag"
};

static const char *bottom_right_corners[] = {
	"bottom_right_corner",
	"se-resize",
	"size_fdiag"
};

static const char *bottom_sides[] = {
	"bottom_side",
	"s-resize",
	"size_ver"
};

static const char *grabbings[] = {
	"grabbing",
	"closedhand",
	"208530c400c041818281048008011002"
};

static const char *left_ptrs[] = {
	"left_ptr",
	"default",
	"top_left_arrow",
	"left-arrow"
};

static const char *left_sides[] = {
	"left_side",
	"w-resize",
	"size_hor"
};

static const char *right_sides[] = {
	"right_side",
	"e-resize",
	"size_hor"
};

static const char *top_left_corners[] = {
	"top_left_corner",
	"nw-resize",
	"size_fdiag"
};

static const char *top_right_corners[] = {
	"top_right_corner",
	"ne-resize",
	"size_bdiag"
};

static const char *top_sides[] = {
	"top_side",
	"n-resize",
	"size_ver"
};

static const char *xterms[] = {
	"xterm",
	"ibeam",
	"text"
};

static const char *hand1s[] = {
	"hand1",
	"pointer",
	"pointing_hand",
	"e29285e634086352946a0e7090d73106"
};

static const char *watches[] = {
	"watch",
	"wait",
	"0426c94ea35c87780ff01dc239897213"
};

struct cursor_alternatives {
	const char **names;
	size_t count;
};

static const struct cursor_alternatives cursors[] = {
	{ bottom_left_corners, ARRAY_LENGTH(bottom_left_corners) },
	{ bottom_right_corners, ARRAY_LENGTH(bottom_right_corners) },
	{ bottom_sides, ARRAY_LENGTH(bottom_sides) },
	{ grabbings, ARRAY_LENGTH(grabbings) },
	{ left_ptrs, ARRAY_LENGTH(left_ptrs) },
	{ left_sides, ARRAY_LENGTH(left_sides) },
	{ right_sides, ARRAY_LENGTH(right_sides) },
	{ top_left_corners, ARRAY_LENGTH(top_left_corners) },
	{ top_right_corners, ARRAY_LENGTH(top_right_corners) },
	{ top_sides, ARRAY_LENGTH(top_sides) },
	{ xterms, ARRAY_LENGTH(xterms) },
	{ hand1s, ARRAY_LENGTH(hand1s) },
	{ watches, ARRAY_LENGTH(watches) },
};

static void
create_cursors(struct wlContextCommon *cmm)
{
	uint32_t i = 0;
	uint32_t j = 0;
	struct wl_cursor *cursor = NULL;
	char *cursor_theme = cmm->hmi_setting->cursor_theme;
	int32_t cursor_size = cmm->hmi_setting->cursor_size;

	cmm->cursor_theme = wl_cursor_theme_load(cursor_theme, cursor_size,
						 cmm->wlShm);

	cmm->cursors =
		xzalloc(ARRAY_LENGTH(cursors) * sizeof(cmm->cursors[0]));

	for (i = 0; i < ARRAY_LENGTH(cursors); i++) {
		cursor = NULL;

		for (j = 0; !cursor && j < cursors[i].count; ++j) {
			cursor = wl_cursor_theme_get_cursor(
				cmm->cursor_theme, cursors[i].names[j]);
		}

		if (!cursor) {
			fprintf(stderr, "could not load cursor '%s'\n",
					cursors[i].names[0]);
		}

		cmm->cursors[i] = cursor;
	}
}

static void
destroy_cursors(struct wlContextCommon *cmm)
{
	if (cmm->cursor_theme)
		wl_cursor_theme_destroy(cmm->cursor_theme);

	free(cmm->cursors);
}

/**
 * Internal method to prepare parts of UI
 */
static void
createShmBuffer(struct wlContextStruct *p_wlCtx)
{
	struct wl_shm_pool *pool;

	int fd = -1;
	int size = 0;
	int width = 0;
	int height = 0;
	int stride = 0;

	width  = cairo_image_surface_get_width(p_wlCtx->ctx_image);
	height = cairo_image_surface_get_height(p_wlCtx->ctx_image);
	stride = cairo_image_surface_get_stride(p_wlCtx->ctx_image);

	size = stride * height;

	fd = os_create_anonymous_file(size);
	if (fd < 0) {
		fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
			size);
		return ;
	}

	p_wlCtx->data =
		mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

	if (MAP_FAILED == p_wlCtx->data) {
		fprintf(stderr, "mmap failed: %m\n");
		close(fd);
		return;
	}

	pool = wl_shm_create_pool(p_wlCtx->cmm->wlShm, fd, size);
	p_wlCtx->wlBuffer = wl_shm_pool_create_buffer(pool, 0,
						      width,
						      height,
						      stride,
						      WL_SHM_FORMAT_ARGB8888);

	if (NULL == p_wlCtx->wlBuffer) {
		fprintf(stderr, "wl_shm_create_buffer failed: %m\n");
		close(fd);
		return;
	}

	wl_shm_pool_destroy(pool);
	close(fd);
}

static void
destroyWLContextCommon(struct wlContextCommon *p_wlCtx)
{
	destroy_cursors(p_wlCtx);

	if (p_wlCtx->pointer_surface)
		wl_surface_destroy(p_wlCtx->pointer_surface);

	if (p_wlCtx->wlCompositor)
		wl_compositor_destroy(p_wlCtx->wlCompositor);
}

static void
destroyWLContextStruct(struct wlContextStruct *p_wlCtx)
{
	if (p_wlCtx->wlSurface)
		wl_surface_destroy(p_wlCtx->wlSurface);

	if (p_wlCtx->ctx_image) {
		cairo_surface_destroy(p_wlCtx->ctx_image);
		p_wlCtx->ctx_image = NULL;
	}
}

static int
createSurface(struct wlContextStruct *p_wlCtx)
{
	p_wlCtx->wlSurface =
		wl_compositor_create_surface(p_wlCtx->cmm->wlCompositor);
	if (NULL == p_wlCtx->wlSurface) {
		printf("Error: wl_compositor_create_surface failed.\n");
		destroyWLContextCommon(p_wlCtx->cmm);
		abort();
	}

	return 0;
}

static void
drawImage(struct wlContextStruct *p_wlCtx)
{
	struct wl_callback *callback;

	int width = 0;
	int height = 0;
	int stride = 0;
	void *data = NULL;

	width = cairo_image_surface_get_width(p_wlCtx->ctx_image);
	height = cairo_image_surface_get_height(p_wlCtx->ctx_image);
	stride = cairo_image_surface_get_stride(p_wlCtx->ctx_image);
	data = cairo_image_surface_get_data(p_wlCtx->ctx_image);

	memcpy(p_wlCtx->data, data, stride * height);

	wl_surface_attach(p_wlCtx->wlSurface, p_wlCtx->wlBuffer, 0, 0);
	wl_surface_damage(p_wlCtx->wlSurface, 0, 0, width, height);

	callback = wl_surface_frame(p_wlCtx->wlSurface);
	wl_callback_add_listener(callback, &frame_listener, NULL);

	wl_surface_commit(p_wlCtx->wlSurface);
}

static void
create_ivisurface(struct wlContextStruct *p_wlCtx,
				  uint32_t id_surface,
				  cairo_surface_t *surface)
{
	struct ivi_surface *ivisurf = NULL;

	p_wlCtx->ctx_image = surface;

	p_wlCtx->id_surface = id_surface;
	wl_list_init(&p_wlCtx->link);
	wl_list_insert(&p_wlCtx->cmm->list_wlContextStruct, &p_wlCtx->link);

	createSurface(p_wlCtx);
	createShmBuffer(p_wlCtx);

	ivisurf = ivi_application_surface_create(p_wlCtx->cmm->iviApplication,
						 id_surface,
						 p_wlCtx->wlSurface);
	if (ivisurf == NULL) {
		fprintf(stderr, "Failed to create ivi_client_surface\n");
		return;
	}

	drawImage(p_wlCtx);
}

static void
create_ivisurfaceFromFile(struct wlContextStruct *p_wlCtx,
			  uint32_t id_surface,
			  const char *imageFile)
{
	cairo_surface_t *surface = load_cairo_surface(imageFile);

	if (NULL == surface) {
		fprintf(stderr, "Failed to load_cairo_surface %s\n", imageFile);
		return;
	}

	create_ivisurface(p_wlCtx, id_surface, surface);
}

static void
set_hex_color(cairo_t *cr, uint32_t color)
{
	cairo_set_source_rgba(cr,
		((color >> 16) & 0xff) / 255.0,
		((color >>  8) & 0xff) / 255.0,
		((color >>  0) & 0xff) / 255.0,
		((color >> 24) & 0xff) / 255.0);
}

static void
create_ivisurfaceFromColor(struct wlContextStruct *p_wlCtx,
			   uint32_t id_surface,
			   uint32_t width, uint32_t height,
			   uint32_t color)
{
	cairo_surface_t *surface = NULL;
	cairo_t *cr = NULL;

	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
					     width, height);

	cr = cairo_create(surface);
	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_rectangle(cr, 0, 0, width, height);
	set_hex_color(cr, color);
	cairo_fill(cr);
	cairo_destroy(cr);

	create_ivisurface(p_wlCtx, id_surface, surface);
}

static void
UI_ready(struct ivi_hmi_controller *controller)
{
	ivi_hmi_controller_UI_ready(controller);
}

/**
 * Internal method to set up UI by using ivi-hmi-controller
 */
static void
create_background(struct wlContextStruct *p_wlCtx, const uint32_t id_surface,
		  const char *imageFile)
{
	create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile);
}

static void
create_panel(struct wlContextStruct *p_wlCtx, const uint32_t id_surface,
	     const char *imageFile)
{
	create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile);
}

static void
create_button(struct wlContextStruct *p_wlCtx, const uint32_t id_surface,
	      const char *imageFile, uint32_t number)
{
	create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile);
}

static void
create_home_button(struct wlContextStruct *p_wlCtx, const uint32_t id_surface,
		   const char *imageFile)
{
	create_ivisurfaceFromFile(p_wlCtx, id_surface, imageFile);
}

static void
create_workspace_background(struct wlContextStruct *p_wlCtx,
			    struct hmi_homescreen_srf *srf)
{
	create_ivisurfaceFromColor(p_wlCtx, srf->id, 1, 1, srf->color);
}

static void
create_launchers(struct wlContextCommon *cmm, struct wl_list *launcher_list)
{
	struct hmi_homescreen_launcher **launchers;
	struct hmi_homescreen_launcher *launcher = NULL;

	int launcher_count = wl_list_length(launcher_list);
	int ii = 0;
	int start = 0;

	if (0 == launcher_count)
		return;

	launchers = xzalloc(launcher_count * sizeof(*launchers));

	wl_list_for_each(launcher, launcher_list, link) {
		launchers[ii] = launcher;
		ii++;
	}

	for (ii = 0; ii < launcher_count; ii++) {
		int jj = 0;

		if (ii != launcher_count - 1 &&
		    launchers[ii]->workspace_id ==
		    launchers[ii + 1]->workspace_id)
			continue;

		for (jj = start; jj <= ii; jj++) {
			struct wlContextStruct *p_wlCtx;

			p_wlCtx = xzalloc(sizeof(*p_wlCtx));
			p_wlCtx->cmm = cmm;
			create_ivisurfaceFromFile(p_wlCtx,
						  launchers[jj]->icon_surface_id,
						  launchers[jj]->icon);
		}

		start = ii + 1;
	}

	free(launchers);
}

/**
 * Internal method to read out weston.ini to get configuration
 */
static struct hmi_homescreen_setting *
hmi_homescreen_setting_create(void)
{
	const char *config_file;
	struct weston_config *config = NULL;
	struct weston_config_section *shellSection = NULL;
	struct hmi_homescreen_setting *setting = xzalloc(sizeof(*setting));
	struct weston_config_section *section = NULL;
	const char *name = NULL;
	uint32_t workspace_layer_id;
	uint32_t icon_surface_id = 0;

	wl_list_init(&setting->workspace_list);
	wl_list_init(&setting->launcher_list);

	config_file = weston_config_get_name_from_env();
	config = weston_config_parse(config_file);

	shellSection =
		weston_config_get_section(config, "ivi-shell", NULL, NULL);

	weston_config_section_get_string(
		shellSection, "cursor-theme", &setting->cursor_theme, NULL);

	weston_config_section_get_int(
		shellSection, "cursor-size", &setting->cursor_size, 32);

	weston_config_section_get_uint(
		shellSection, "workspace-layer-id", &workspace_layer_id, 3000);

	weston_config_section_get_string(
		shellSection, "background-image", &setting->background.filePath,
		DATADIR "/weston/background.png");

	weston_config_section_get_uint(
		shellSection, "background-id", &setting->background.id, 1001);

	weston_config_section_get_string(
		shellSection, "panel-image", &setting->panel.filePath,
		DATADIR "/weston/panel.png");

	weston_config_section_get_uint(
		shellSection, "panel-id", &setting->panel.id, 1002);

	weston_config_section_get_string(
		shellSection, "tiling-image", &setting->tiling.filePath,
		DATADIR "/weston/tiling.png");

	weston_config_section_get_uint(
		shellSection, "tiling-id", &setting->tiling.id, 1003);

	weston_config_section_get_string(
		shellSection, "sidebyside-image", &setting->sidebyside.filePath,
		DATADIR "/weston/sidebyside.png");

	weston_config_section_get_uint(
		shellSection, "sidebyside-id", &setting->sidebyside.id, 1004);

	weston_config_section_get_string(
		shellSection, "fullscreen-image", &setting->fullscreen.filePath,
		DATADIR "/weston/fullscreen.png");

	weston_config_section_get_uint(
		shellSection, "fullscreen-id", &setting->fullscreen.id, 1005);

	weston_config_section_get_string(
		shellSection, "random-image", &setting->random.filePath,
		DATADIR "/weston/random.png");

	weston_config_section_get_uint(
		shellSection, "random-id", &setting->random.id, 1006);

	weston_config_section_get_string(
		shellSection, "home-image", &setting->home.filePath,
		DATADIR "/weston/home.png");

	weston_config_section_get_uint(
		shellSection, "home-id", &setting->home.id, 1007);

	weston_config_section_get_uint(
		shellSection, "workspace-background-color",
		&setting->workspace_background.color, 0x99000000);

	weston_config_section_get_uint(
		shellSection, "workspace-background-id",
		&setting->workspace_background.id, 2001);

	weston_config_section_get_uint(
		shellSection, "surface-id-offset", &setting->surface_id_offset, 10);

	icon_surface_id = workspace_layer_id + 1;

	while (weston_config_next_section(config, &section, &name)) {
		struct hmi_homescreen_launcher *launcher;

		if (strcmp(name, "ivi-launcher") != 0)
			continue;

		launcher = xzalloc(sizeof(*launcher));
		wl_list_init(&launcher->link);

		weston_config_section_get_string(section, "icon",
						 &launcher->icon, NULL);
		weston_config_section_get_string(section, "path",
						 &launcher->path, NULL);
		weston_config_section_get_uint(section, "workspace-id",
					       &launcher->workspace_id, 0);
		weston_config_section_get_uint(section, "icon-id",
					       &launcher->icon_surface_id,
					       icon_surface_id);
		icon_surface_id++;

		wl_list_insert(setting->launcher_list.prev, &launcher->link);
	}

	weston_config_destroy(config);
	return setting;
}

/**
 * Main thread
 *
 * The basic flow are as followed,
 * 1/ read configuration from weston.ini by hmi_homescreen_setting_create
 * 2/ draw png file to surface according to configuration of weston.ini and
 *	set up UI by using ivi-hmi-controller protocol by each create_* method
 */
int main(int argc, char **argv)
{
	struct wlContextCommon wlCtxCommon;
	struct wlContextStruct *wlCtx_BackGround;
	struct wlContextStruct *wlCtx_Panel;
	struct wlContextStruct wlCtx_Button_1;
	struct wlContextStruct wlCtx_Button_2;
	struct wlContextStruct wlCtx_Button_3;
	struct wlContextStruct wlCtx_Button_4;
	struct wlContextStruct wlCtx_HomeButton;
	struct wlContextStruct wlCtx_WorkSpaceBackGround;
	struct wl_list launcher_wlCtxList;
	int ret = 0;
	struct hmi_homescreen_setting *hmi_setting;
	struct wlContextStruct *pWlCtxSt = NULL;
	int i = 0;

	hmi_setting = hmi_homescreen_setting_create();

	memset(&wlCtxCommon, 0x00, sizeof(wlCtxCommon));
	memset(&wlCtx_Button_1,   0x00, sizeof(wlCtx_Button_1));
	memset(&wlCtx_Button_2,   0x00, sizeof(wlCtx_Button_2));
	memset(&wlCtx_Button_3,   0x00, sizeof(wlCtx_Button_3));
	memset(&wlCtx_Button_4,   0x00, sizeof(wlCtx_Button_4));
	memset(&wlCtx_HomeButton, 0x00, sizeof(wlCtx_HomeButton));
	memset(&wlCtx_WorkSpaceBackGround, 0x00,
	       sizeof(wlCtx_WorkSpaceBackGround));
	wl_list_init(&launcher_wlCtxList);
	wl_list_init(&wlCtxCommon.list_wlContextStruct);

	wlCtxCommon.hmi_setting = hmi_setting;

	wlCtxCommon.wlDisplay = wl_display_connect(NULL);
	if (NULL == wlCtxCommon.wlDisplay) {
		printf("Error: wl_display_connect failed.\n");
		return -1;
	}

	/* get wl_registry */
	wlCtxCommon.formats = 0;
	wlCtxCommon.wlRegistry = wl_display_get_registry(wlCtxCommon.wlDisplay);
	wl_registry_add_listener(wlCtxCommon.wlRegistry,
				 &registry_listener, &wlCtxCommon);
	wl_display_roundtrip(wlCtxCommon.wlDisplay);

	if (wlCtxCommon.wlShm == NULL) {
		fprintf(stderr, "No wl_shm global\n");
		exit(1);
	}

	wl_display_roundtrip(wlCtxCommon.wlDisplay);

	if (!(wlCtxCommon.formats & (1 << WL_SHM_FORMAT_XRGB8888))) {
		fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n");
		exit(1);
	}

	wlCtx_BackGround = xzalloc(hmi_setting->screen_num * sizeof(struct wlContextStruct));
	wlCtx_Panel= xzalloc(hmi_setting->screen_num * sizeof(struct wlContextStruct));

	if (wlCtxCommon.hmi_setting->cursor_theme) {
		create_cursors(&wlCtxCommon);

		wlCtxCommon.pointer_surface =
			wl_compositor_create_surface(wlCtxCommon.wlCompositor);

		wlCtxCommon.current_cursor = CURSOR_LEFT_PTR;
	}

	wlCtx_Button_1.cmm   = &wlCtxCommon;
	wlCtx_Button_2.cmm   = &wlCtxCommon;
	wlCtx_Button_3.cmm   = &wlCtxCommon;
	wlCtx_Button_4.cmm   = &wlCtxCommon;
	wlCtx_HomeButton.cmm = &wlCtxCommon;
	wlCtx_WorkSpaceBackGround.cmm = &wlCtxCommon;

	/* create desktop widgets */
	for (i = 0; i < hmi_setting->screen_num; i++) {
		wlCtx_BackGround[i].cmm = &wlCtxCommon;
		create_background(&wlCtx_BackGround[i],
				  hmi_setting->background.id +
					(i * hmi_setting->surface_id_offset),
				  hmi_setting->background.filePath);

		wlCtx_Panel[i].cmm = &wlCtxCommon;
		create_panel(&wlCtx_Panel[i],
			     hmi_setting->panel.id + (i * hmi_setting->surface_id_offset),
			     hmi_setting->panel.filePath);
	}

	create_button(&wlCtx_Button_1, hmi_setting->tiling.id,
		      hmi_setting->tiling.filePath, 0);

	create_button(&wlCtx_Button_2, hmi_setting->sidebyside.id,
		      hmi_setting->sidebyside.filePath, 1);

	create_button(&wlCtx_Button_3, hmi_setting->fullscreen.id,
		      hmi_setting->fullscreen.filePath, 2);

	create_button(&wlCtx_Button_4, hmi_setting->random.id,
		      hmi_setting->random.filePath, 3);

	create_workspace_background(&wlCtx_WorkSpaceBackGround,
				    &hmi_setting->workspace_background);

	create_launchers(&wlCtxCommon, &hmi_setting->launcher_list);

	create_home_button(&wlCtx_HomeButton, hmi_setting->home.id,
			   hmi_setting->home.filePath);

	UI_ready(wlCtxCommon.hmiCtrl);

	while (ret != -1)
		ret = wl_display_dispatch(wlCtxCommon.wlDisplay);

	wl_list_for_each(pWlCtxSt, &wlCtxCommon.list_wlContextStruct, link) {
		destroyWLContextStruct(pWlCtxSt);
	}

	free(wlCtx_BackGround);
	free(wlCtx_Panel);

	destroyWLContextCommon(&wlCtxCommon);

	return 0;
}