19c84e6ab40ad99947f77bc4364fd3e3420e536c
[profile/ivi/ico-uxf-homescreen.git] / src / home_screen_main.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   homescreen application main
11  *
12  * @date    Feb-15-2013
13  */
14
15 #include <Eina.h>
16 #include <Evas.h>
17 #include <Ecore.h>
18 #include <Ecore_Evas.h>
19 #include <Ecore_Wayland.h>
20 #include <Edje.h>
21 #include <Elementary.h>
22
23 #include <stdio.h>
24 #include <pthread.h>
25 #include <libwebsockets.h>
26
27 #include "ico_apf.h"
28 #include "ico_uxf.h"
29 #include "ico_uxf_conf.h"
30 #include "ico_syc_apc.h"
31 #include "ico_uxf_conf_ecore.h"
32
33 #include "home_screen_lib.h"
34 #include "home_screen_res.h"
35 #include "home_screen_conf.h"
36 #include "home_screen_parser.h"
37
38 /*============================================================================*/
39 /* definition                                                                 */
40 /*============================================================================*/
41 #define ICO_HS_WINDOW_TYPE_BG    (1)
42 #define ICO_HS_WINDOW_TYPE_TOUCH (2)
43 #define ICO_HS_TOUCH_TIME_OUT    (1.0) /* Long press for timer */
44 typedef struct _hs_tile_info hs_tile_info_t;
45 typedef struct _hs_tile_hide hs_tile_hide_t;
46
47 struct _hs_tile_hide {
48     hs_tile_hide_t *next;               /* next hide app on the same tile */
49     char appid[ICO_UXF_MAX_PROCESS_NAME];
50 };
51
52 struct _hs_tile_info {
53     hs_tile_hide_t *next;
54     int idx; /* index: 0 to ... */
55     int valid; /* 0: invalid, 1:valid */ /* dont't touch now */
56     char appid[ICO_UXF_MAX_PROCESS_NAME]; /* active app id */
57     int type; /* 11:small, 21:h-wide, 12:v-wide, 22:large, 0:others */
58     int l_press; /* 1: long press */
59     int change;
60     int size_x;
61     int size_y;
62     int coord_x;
63     int coord_y;
64 };
65
66 #define HS_DISPLAY_HOMESCREEN   0           /* HomeScreen target display Id     */
67 #define NUM_ONSCREEN_WINDOWS    10          /* max number of windows in OnScreen*/
68
69 #define HS_LAYER_BACKGROUND     0           /* layer of BackGround              */
70 #define HS_LAYER_HOMESCREEN     1           /* layer of HomeScreen menu         */
71 #define HS_LAYER_APPLICATION    2           /* layer of Application             */
72 #define HS_LAYER_SOFTKEYBOARD   3           /* layer of Software Keyboard       */
73 #define HS_LAYER_INTERRUPTAPP   4           /* layer of Interrupted Application */
74 #define HS_LAYER_TOUCH          5           /* layer of TouchPanel              */
75 #define HS_LAYER_ONSCREEN       6           /* layer of OnScreen                */
76
77 /*============================================================================*/
78 /* static(internal) functions prototype                                       */
79 /*============================================================================*/
80 static int hs_is_special_app(const char *appid);
81 static int hs_is_noicon_app(const char *appid);
82 static void hs_set_invisible_all(void);
83 static void hs_set_appscreen(const char *appid);
84 static void hs_tile_start_apps(void);
85 static int hs_tile_init_info(void);
86 static void hs_convert_tile_config(char *in, int *out, int cnt, int val);
87 static Eina_Bool hs_ecore_uxf_eventfd(void *data, Ecore_Fd_Handler *handler);
88 static void hs_uxf_event(int ev, Ico_Uxf_EventDetail dd, int arg);
89 static int hs_get_process_window(const char *appid);
90 static void hs_display_control(const Ico_Uxf_conf_application *conf, const int show);
91 static void hs_sound_control(const Ico_Uxf_conf_application *conf, const int adjust);
92 static void hs_input_control(const Ico_Uxf_conf_application *conf, const int inputsw);
93 static void *hs_create_window(int type);
94 static void hs_touch_up_api_list(void *data, Evas *evas, Evas_Object *obj,
95                                  void *event_info);
96 static void hs_touch_down_api_list(void *data, Evas *evas, Evas_Object *obj,
97                                    void *event_info);
98 static Eina_Bool hs_ecore_timer_event(void *data);
99 static void hs_touch_up_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info);
100 static void hs_touch_down_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info);
101 static void hs_add_touch_listener(Evas *canvas_fg);
102 static void hs_add_bg_image(Evas *canvas_bg);
103 static void hs_terminate_all_app(void);
104 static void hs_regulation_listener(const int appcategory,
105                                    const ico_apc_reguration_control_t control,
106                                    void *user_data);
107
108 /*============================================================================*/
109 /* variables and tables                                                       */
110 /*============================================================================*/
111 char hs_kill_appid[ICO_UXF_MAX_PROCESS_NAME];
112                                          /* set kill 'app id' in touch layer  */
113 char hs_active_onscreen[ICO_UXF_MAX_PROCESS_NAME];
114                                          /* stack 'app id' at active onscreen */
115 hs_window_data_t hs_command_tile_req[ICO_HS_APP_NUM_MAX];
116 hs_window_data_t hs_app_screen_window[ICO_HS_APP_NUM_MAX];
117 char hs_name_homescreen[ICO_UXF_MAX_PROCESS_NAME + 1];
118 static char gStatusbarName[ICO_UXF_MAX_PROCESS_NAME + 1];
119 static char gOnscreenName[ICO_UXF_MAX_PROCESS_NAME + 1];
120 static hs_tile_info_t *hs_tile_info;
121 static int hs_tile_cnt = 0;
122 static int hs_notile_cnt = 0;
123 static int hs_regulation_category = 0;
124 static int hs_regulation_visible = 1;
125
126 /*============================================================================*/
127 /* functions                                                                  */
128 /*============================================================================*/
129 /*--------------------------------------------------------------------------*/
130 /**
131  * @brief   hs_uxf_event
132  *          callback function called by UXF.
133  *
134  * @param[in]   ev                  event kinds
135  * @param[in]   dd                  event detail structure
136  * @param[in]   arg                 user data
137  * @return      none
138  */
139 /*--------------------------------------------------------------------------*/
140 static void
141 hs_uxf_event(int ev, Ico_Uxf_EventDetail dd, int arg)
142 {
143     const Ico_Uxf_conf_application *appConf;
144
145     uifw_trace("... Event=%08x Arg=%d", ev, arg);
146
147     Ico_Uxf_WindowAttr winAttr;
148     int ret;
149     int idx;
150     int dispW, dispH;
151
152     if (ev == ICO_UXF_EVENT_NEWWINDOW) {
153         uifw_trace("  D(Window) ev=%08x disp=%d win=%x x/y=%d/%d w/h=%d/%d v/r/a=%d/%d/%d",
154                    dd.event, dd.window.display, dd.window.window,
155                    dd.window.x, dd.window.y, dd.window.w, dd.window.h,
156                    dd.window.visible, dd.window.raise, dd.window.active);
157         ret = ico_uxf_window_attribute_get(dd.window.window, &winAttr);
158         if (ret == ICO_UXF_EOK) {
159             uifw_trace("  D(Window) appid=%s sub=%d", winAttr.process,
160                        winAttr.subwindow);
161             if (strncmp(winAttr.process, hs_name_homescreen,
162                         ICO_UXF_MAX_PROCESS_NAME) == 0) {
163                 ico_uxf_window_screen_size_get(&dispW, &dispH);
164                 /* HomeScreen APP: BG or TOUCH */
165                 ico_uxf_window_resize(dd.window.window, dispW, dispH
166                         - ICO_HS_SIZE_SB_HEIGHT);
167                 ico_uxf_window_move(dd.window.window, 0, ICO_HS_SIZE_SB_HEIGHT);
168                 ico_uxf_window_show(dd.window.window);
169                 if (winAttr.subwindow > 0) {
170                     /* set layer of HomeScreen TouchPanel window    */
171                     ico_uxf_window_layer(dd.window.window, HS_LAYER_TOUCH);
172                     hs_tile_show_screen();
173                 }
174                 else    {
175                     /* set layer of HomeScreen BackGround window    */
176                     ico_uxf_window_layer(dd.window.window, HS_LAYER_BACKGROUND);
177                 }
178             }
179             else if (strncmp(winAttr.process, gStatusbarName,
180                              ICO_UXF_MAX_PROCESS_NAME) == 0) {
181                 /* set layer of StatusBar window                */
182                 ico_uxf_window_layer(dd.window.window, HS_LAYER_ONSCREEN);
183                 /* show status bar */
184                 ico_uxf_window_show(dd.window.window);
185                 ico_uxf_window_move(dd.window.window, 0, 0);
186                 ico_uxf_window_screen_size_get(&dispW, &dispH);
187                 ico_uxf_window_resize(dd.window.window, dispW, ICO_HS_SIZE_SB_HEIGHT);
188             }
189             else if (strncmp(winAttr.process, gOnscreenName,
190                              ICO_UXF_MAX_PROCESS_NAME) == 0) {
191                 /* set layer of OnScreen window             */
192                 ico_uxf_window_layer(dd.window.window, HS_LAYER_BACKGROUND);
193                 ico_uxf_window_visible_raise(dd.window.window, 1, 0);
194             }
195             else {
196                 /* other normal application */
197                 if (hs_is_special_app(winAttr.process) == FALSE) {
198                     if (hs_is_noicon_app(winAttr.process) != FALSE) {
199                         hs_set_appscreen(winAttr.process);
200                         if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
201                             hs_tile_show_screen();
202                         }
203                     }
204                     else if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
205                         /* set layer of Application in HomeScreen menu  */
206                         ico_uxf_window_layer(dd.window.window, HS_LAYER_HOMESCREEN);
207                         hs_tile_show_screen();
208                     }
209                     else if (hs_stat_touch == ICO_HS_TOUCH_IN_HIDE) {
210                         hs_set_appscreen(winAttr.process);
211                     }
212                 }
213             }
214         }
215     }
216     else if (ev == ICO_UXF_EVENT_TERMPROCESS) {
217         uifw_trace("hs_uxf_event: ICO_UXF_EVENT_TERMPROCESS");
218
219         if (strlen(dd.process.process) != 0) {
220             idx = hs_tile_get_index_app(dd.process.process);
221             if (idx >= 0) {
222                 hs_tile_free_app(idx);
223             }
224             else {
225                 hs_tile_delete_hide(dd.process.process);
226             }
227         }
228     }
229     else if (ev == ICO_UXF_EVENT_ACTIVEWINDOW)  {
230         /* set active window                */
231         if (dd.window.active == ICO_UXF_WINDOW_SELECT)  {
232             if (ico_uxf_window_attribute_get(dd.window.window, &winAttr) == ICO_UXF_EOK)  {
233                 if ((strncmp(winAttr.process, hs_name_homescreen, ICO_UXF_MAX_PROCESS_NAME)
234                         != 0) &&
235                     (strncmp(winAttr.process, gStatusbarName, ICO_UXF_MAX_PROCESS_NAME)
236                         != 0) &&
237                     (strncmp(winAttr.process, gOnscreenName, ICO_UXF_MAX_PROCESS_NAME)
238                         != 0))  {
239                     /* if selected application is soft-keyboard, activate only pointer, */
240                     /* other case activate pointer and keyboard                         */
241                     appConf = ico_uxf_getAppByAppid(winAttr.process);
242                     if ((appConf != NULL) &&
243                         (appConf->display[0].layerId == HS_LAYER_SOFTKEYBOARD)) {
244                         ico_uxf_window_active(dd.window.window,
245                                               ICO_UXF_WINDOW_POINTER_ACTIVE);
246                         ico_uxf_window_raise(dd.window.window);
247                     }
248                     else    {
249                         ico_uxf_window_active(dd.window.window,
250                                                   ICO_UXF_WINDOW_KEYBOARD_ACTIVE);
251                         ico_uxf_window_raise(dd.window.window);
252                         ico_syc_apc_active(winAttr.process);
253                     }
254                 }
255             }
256         }
257     }
258 }
259
260 /*--------------------------------------------------------------------------*/
261 /**
262  * @brief   hs_ecore_uxf_eventfd
263  *          callback function of wayland fd event that is used in UXF.
264  *          if the fd has event, ecore call this function.
265  *
266  * @param[in]   data                user data
267  * @param[in]   handler             handler
268  * @return      none
269  */
270 /*--------------------------------------------------------------------------*/
271 static Eina_Bool
272 hs_ecore_uxf_eventfd(void *data, Ecore_Fd_Handler *handler)
273 {
274     ico_uxf_main_loop_iterate();
275
276     return EINA_TRUE;
277 }
278
279 /*--------------------------------------------------------------------------*/
280 /**
281  * @brief   hs_convert_tile_config
282  *          for read configuration.
283  *          convert configuration string to integer array.
284  *
285  * @param[in]   in                  configuration
286  * @param[out]  out                 integer array
287  * @param[in]   cnt                 count
288  * @param[in]   val                 default value
289  * @return      none
290  */
291 /*--------------------------------------------------------------------------*/
292 static void
293 hs_convert_tile_config(char *in, int *out, int cnt, int val)
294 {
295     int idx;
296     char *tok;
297     char *s = ";";
298
299     for (idx = 0; idx < cnt; idx++) {
300         out[idx] = val;
301     }
302     if (in != NULL) {
303         tok = strtok(in, s);
304         for (idx = 0; idx < cnt; idx++) {
305             out[idx] = atoi(tok);
306             tok = strtok(NULL, s);
307             if (tok == NULL) {
308                 break;
309             }
310         }
311     }
312 }
313
314 /*--------------------------------------------------------------------------*/
315 /**
316  * @brief   hs_get_index_appscreendata
317  *          get applicaton screen data index.
318  *
319  * @param[in]   appid               application id
320  * @return      result
321  * @retval      >=0                 app index
322  * @retval      -1                  not exist
323  */
324 /*--------------------------------------------------------------------------*/
325 int
326 hs_get_index_appscreendata(const char *appid)
327 {
328     int idx = -1;
329     int ii;
330
331     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
332         if (hs_app_screen_window[ii].appid[0] == 0) {
333             if (idx == -1) {
334                 idx = ii;
335             }
336             continue;
337         }
338         if (strncmp(hs_app_screen_window[ii].appid, appid,
339                     ICO_UXF_MAX_PROCESS_NAME) == 0) {
340             return ii;
341         }
342     }
343
344     if (idx >= 0) {
345         strncpy(hs_app_screen_window[idx].appid, appid,
346                 ICO_UXF_MAX_PROCESS_NAME);
347     }
348     return idx;
349 }
350
351 /*--------------------------------------------------------------------------*/
352 /**
353  * @brief   hs_set_appscreen
354  *          set the application screen's status to the applicaton window,
355  *          and visible raise the application window.
356  *
357  * @param[in]   appid               application id
358  * @return      none
359  */
360 /*--------------------------------------------------------------------------*/
361 static void
362 hs_set_appscreen(const char *appid)
363 {
364     int idx;
365     int ret;
366     Ico_Uxf_ProcessWin window;
367     const Ico_Uxf_conf_application *appConf;
368     const Ico_Uxf_Sys_Config       *sysConf;
369     Ico_Uxf_conf_display_zone      *zone;
370
371     idx = hs_get_index_appscreendata(appid);
372
373     if (idx < 0) {
374         return;
375     }
376
377     /* visible raise */
378     ret = ico_uxf_process_window_get(hs_app_screen_window[idx].appid, &window, 1);
379     if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
380         uifw_trace("hs_set_appscreen: app[%d]:visible=%d raise=%d %dx%d(%d,%d)",
381                    idx, hs_app_screen_window[idx].visible, hs_app_screen_window[idx].raise,
382                    hs_app_screen_window[idx].resize_w, hs_app_screen_window[idx].resize_h,
383                    hs_app_screen_window[idx].move_x, hs_app_screen_window[idx].move_y);
384         /* move application window to application layer */
385         appConf = ico_uxf_getAppByAppid(hs_app_screen_window[idx].appid);
386         if (! appConf)  {
387             ico_uxf_window_layer(window.window, HS_LAYER_APPLICATION);
388             /* show application layer                       */
389             ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 1);
390         }
391         else    {
392             ico_uxf_window_layer(window.window, appConf->display[0].layerId);
393             /* show application layer                       */
394             ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, appConf->display[0].layerId, 1);
395
396             if ((hs_app_screen_window[idx].resize_w <= 0) &&
397                 (hs_app_screen_window[idx].resize_h <= 0) &&
398                 (hs_app_screen_window[idx].move_x <= 0) &&
399                 (hs_app_screen_window[idx].move_y <= 0))    {
400                 /* not set size and position, set default(zone size)    */
401                 sysConf = ico_uxf_getSysConfig();
402                 zone = (Ico_Uxf_conf_display_zone *)&sysConf->
403                            display[appConf->display[0].displayId].
404                                zone[appConf->display[0].zoneId];
405                 hs_app_screen_window[idx].resize_w = zone->width;
406                 hs_app_screen_window[idx].resize_h = zone->height;
407                 hs_app_screen_window[idx].move_x = zone->x;
408                 hs_app_screen_window[idx].move_y = zone->y;
409                 hs_app_screen_window[idx].visible = 1;
410                 hs_app_screen_window[idx].raise = 1;
411             }
412         }
413         ico_uxf_window_move(window.window, hs_app_screen_window[idx].move_x,
414                             hs_app_screen_window[idx].move_y);
415         ico_uxf_window_resize(window.window,
416                               hs_app_screen_window[idx].resize_w,
417                               hs_app_screen_window[idx].resize_h);
418         ico_uxf_window_visible_raise(window.window,
419                                      hs_app_screen_window[idx].visible,
420                                      hs_app_screen_window[idx].raise);
421         /* hide HomeScreen layer                        */
422         ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
423     }
424     ico_uxf_main_loop_iterate();
425 }
426
427 /*--------------------------------------------------------------------------*/
428 /**
429  * @brief   hs_set_invisible_all
430  *          set all applicatoin except special applicaion(homescreen
431  *          /statusbar/onscreen) in invisible.
432  *
433  * @param       none
434  * @return      none
435  */
436 /*--------------------------------------------------------------------------*/
437 static void
438 hs_set_invisible_all(void)
439 {
440     uifw_trace("hs_set_invisible_all: Enter");
441
442     /* hide application layer                       */
443     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 0);
444     /* hide HomeScreen layer menu                   */
445     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
446
447     uifw_trace("hs_set_invisible_all: Leave");
448 }
449
450 /*--------------------------------------------------------------------------*/
451 /**
452  * @brief   hs_show_appscreen
453  *          show applicaton screen and raise the indicated application.
454  *
455  * @param[in]   appid               application id
456  * @return      none
457  */
458 /*--------------------------------------------------------------------------*/
459 void
460 hs_show_appscreen(const char *appid)
461 {
462     Ico_Uxf_ProcessWin window;
463     const Ico_Uxf_conf_application *appConf = NULL;
464     int ii, idx;
465     int ret;
466     int dispW, dispH;
467     int sid;
468
469     uifw_trace("hs_show_appscreen: Enter(appid=%s)", appid ? appid : "(NULL)");
470     /* change to noraml mode for AppsControler  */
471     ico_uxf_window_control(NULL, -1, ICO_UXF_APPSCTL_TEMPVISIBLE, 0);
472
473     /* touch to invisible */
474     sid = hs_get_process_window(ICO_HS_APPID_DEFAULT_TOUCH);
475     if (sid >= 0) {
476         ico_uxf_window_hide(sid);
477     }
478     /* all apps invisible */
479     hs_set_invisible_all();
480
481     /* show other apps */
482     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
483         if (hs_app_screen_window[ii].appid[0] == 0)
484             continue;
485         appConf = ico_uxf_getAppByAppid(hs_app_screen_window[ii].appid);
486         if (appConf != NULL) {
487             hs_app_screen_window[ii].category = appConf->categoryId;
488         }
489         if (hs_is_special_app(hs_app_screen_window[ii].appid))
490             continue;
491         if ((appid != NULL) && strncmp(hs_app_screen_window[ii].appid, appid,
492                                        ICO_UXF_MAX_PROCESS_NAME) == 0)
493             continue;
494
495         /* if invisible */
496         ret = ico_uxf_process_window_get(hs_app_screen_window[ii].appid,
497                                          &window, 1);
498         uifw_trace("hs_show_appscreen: window_get app[%s] = %d(visible=%d)",
499                    hs_app_screen_window[ii].appid, ret,
500                    hs_app_screen_window[ii].visible);
501         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
502             if (hs_app_screen_window[ii].visible == 0) {
503             }
504             else {
505                 uifw_trace("hs_show_appscreen: move %d=%dx%d(%d,%d)", ii,
506                            hs_app_screen_window[ii].resize_w,
507                            hs_app_screen_window[ii].resize_h,
508                            hs_app_screen_window[ii].move_x, hs_app_screen_window[ii].move_y);
509                 /* move application window to application layer */
510                 ico_uxf_window_resize(window.window,
511                                       hs_app_screen_window[ii].resize_w,
512                                       hs_app_screen_window[ii].resize_h);
513                 ico_uxf_window_move(window.window,
514                                     hs_app_screen_window[ii].move_x,
515                                     hs_app_screen_window[ii].move_y);
516                 ico_uxf_window_show(window.window);
517                 if (! appConf)  {
518                     ico_uxf_window_layer(window.window, HS_LAYER_APPLICATION);
519                     /* show application layer                       */
520                     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 1);
521                 }
522                 else    {
523                     ico_uxf_window_layer(window.window, appConf->display[0].layerId);
524                     /* show application layer                       */
525                     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN,
526                                           appConf->display[0].layerId, 1);
527                 }
528             }
529         }
530     }
531     /* hide HomeScreen layer menu                   */
532     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
533     /* hide Touch layer                             */
534     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 0);
535     /* hide OnScreen windows                        */
536     hs_hide_onscreen();
537
538     /* show own apps */
539     if (appid != NULL) {
540         idx = hs_get_index_appscreendata(appid);
541         /* if not set pos, load default */
542         appConf = ico_uxf_getAppByAppid(appid);
543         if (appConf != NULL) {
544             int x, y, width, height;
545             (void)ico_uxf_getAppDisplay(appConf, 0, &x, &y, &width, &height);
546
547             if ((hs_app_screen_window[idx].resize_w == -1)
548                     || (hs_app_screen_window[idx].resize_h == -1)) {
549                 hs_app_screen_window[idx].resize_w = width;
550                 hs_app_screen_window[idx].resize_h = height;
551             }
552             if ((hs_app_screen_window[idx].move_x == -1)
553                     || (hs_app_screen_window[idx].move_y == -1)) {
554                 hs_app_screen_window[idx].move_x = x;
555                 hs_app_screen_window[idx].move_y = y;
556             }
557             if ((hs_app_screen_window[idx].resize_w == 0)
558                     && (hs_app_screen_window[idx].resize_h == 0)
559                     && (hs_app_screen_window[idx].move_x == 0)
560                     && (hs_app_screen_window[idx].move_y == 0)) {
561                 /* not have manifest, set default */
562                 ico_uxf_window_screen_size_get(&dispW, &dispH);
563                 hs_app_screen_window[idx].resize_w = dispW;
564                 hs_app_screen_window[idx].resize_h = (dispH - ICO_HS_SIZE_SB_HEIGHT) / 2;
565                 hs_app_screen_window[idx].move_x = 0;
566                 hs_app_screen_window[idx].move_y = ICO_HS_SIZE_SB_HEIGHT;
567             }
568         }
569
570         /* show */
571         ret = ico_uxf_process_window_get(appid, &window, 1);
572         uifw_trace("hs_show_appscreen: window_get app[%s] = %d", appid, ret);
573         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
574             uifw_trace("hs_show_appscreen: move %d=%dx%d(%d,%d)", idx,
575                        hs_app_screen_window[idx].resize_w,
576                        hs_app_screen_window[idx].resize_h,
577                        hs_app_screen_window[idx].move_x,
578                        hs_app_screen_window[idx].move_y);
579             /* window hide and resize (for animation)       */
580             ico_uxf_window_hide(window.window);
581             /* move application window to application layer */
582             ico_uxf_window_resize(window.window,
583                                   hs_app_screen_window[idx].resize_w,
584                                   hs_app_screen_window[idx].resize_h);
585             ico_uxf_window_move(window.window,
586                                 hs_app_screen_window[idx].move_x,
587                                 hs_app_screen_window[idx].move_y);
588             if (! appConf)  {
589                 ico_uxf_window_layer(window.window, HS_LAYER_APPLICATION);
590                 /* show application layer                       */
591                 ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 1);
592             }
593             else    {
594                 ico_uxf_window_layer(window.window, appConf->display[0].layerId);
595                 /* show application layer                       */
596                 ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN,
597                                       appConf->display[0].layerId, 1);
598             }
599             ico_uxf_window_raise(window.window);
600             /* activate application window                  */
601             if ((appConf != NULL) && (appConf->display[0].layerId == HS_LAYER_SOFTKEYBOARD)) {
602                 ico_uxf_window_active(window.window, ICO_UXF_WINDOW_POINTER_ACTIVE);
603             }
604             else    {
605                 ico_uxf_window_active(window.window,
606                                           ICO_UXF_WINDOW_KEYBOARD_ACTIVE);
607             }
608             ico_syc_apc_active(appid);
609
610             hs_app_screen_window[idx].visible = 1;
611             /* hide HomeScreen layer                        */
612             ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
613             /* visible application window with animation    */
614             ico_uxf_window_visible_animation(window.window, 1);
615         }
616     }
617     hs_stat_touch = ICO_HS_TOUCH_IN_HIDE;
618     ico_uxf_main_loop_iterate();
619
620     uifw_trace("hs_show_appscreen: Leave");
621 }
622
623 /*--------------------------------------------------------------------------*/
624 /**
625  * @brief   hs_tile_start_apps
626  *          launch the default application that indicated by configuration
627  *          file.
628  *
629  * @param       none
630  * @return      none
631  */
632 /*--------------------------------------------------------------------------*/
633 static void
634 hs_tile_start_apps(void)
635 {
636     char cName[ICO_UXF_MAX_PROCESS_NAME + 1];
637     int idx, ret;
638     int idx1, idx2;
639     const char *appName;
640     const Ico_Uxf_App_Config *appConf;
641     hs_tile_info_t *tinfo;
642
643     /* excute applications in tile menu */
644     for (idx = 0; idx < hs_tile_cnt; idx++) {
645         tinfo = &hs_tile_info[idx];
646         if (tinfo->valid == 0) continue;
647         sprintf(cName, ICO_HS_CONFIG_TILE_APP"%d", idx);
648         appName = hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN, cName, NULL);
649         if ((appName != NULL) && (strcmp(appName, "none") != 0)) {
650             ret = ico_uxf_process_execute(appName);
651             if (ret >= 0) {
652                 uifw_trace("hs_tile_start_apps: execute tile[%d]=%s", idx, appName);
653                 memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
654                 strncpy(tinfo->appid, appName, ICO_UXF_MAX_PROCESS_NAME);
655             }
656         }
657     }
658
659     /* excute no menu applications      */
660     appConf = ico_uxf_getAppConfig();
661     idx = hs_tile_cnt;
662     for (idx1 = 0; idx1 < appConf->applicationNum; idx1++)  {
663         if (appConf->application[idx1].autostart == 0)  continue;
664         for (idx2 = 0; idx2 < hs_tile_cnt; idx2++)  {
665             if (! strcmp(hs_tile_info[idx2].appid, appConf->application[idx1].appid)) break;
666         }
667         if (idx2 >= hs_tile_cnt)    {
668             ret = ico_uxf_process_execute(appConf->application[idx1].appid);
669             if (ret >= 0) {
670                 uifw_trace("hs_tile_start_apps: execute no tile[%d]=%s",
671                            idx, appConf->application[idx1].appid);
672                 memset(hs_tile_info[idx].appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
673                 strncpy(hs_tile_info[idx].appid,
674                         appConf->application[idx1].appid, ICO_UXF_MAX_PROCESS_NAME);
675                 idx ++;
676                 if ((idx - hs_tile_cnt) >= ICO_HS_NOTILE_APP_MAX)   break;
677             }
678         }
679     }
680     hs_notile_cnt = idx - hs_tile_cnt;
681 }
682
683 /*--------------------------------------------------------------------------*/
684 /**
685  * @brief   hs_tile_init_info
686  *          initialize tile information.
687  *
688  * @param       none
689  * @return      result
690  * @retval      ICO_HS_OK           success
691  * @retval      ICO_HS_ERR          err
692  */
693 /*--------------------------------------------------------------------------*/
694 static int
695 hs_tile_init_info(void)
696 {
697     int idx, row, column;
698     char *sValid = NULL;
699     char *sType = NULL;
700     int *valid = NULL;
701     int *type = NULL;
702     int dispW, dispH;
703     int width, height;
704     int mSide, mTop;
705     int colcnt, rowcnt, tilecnt, tilesize;
706     int try = 0;
707     hs_tile_info_t *tinfo;
708
709     /* count tile */
710     colcnt = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
711                                  ICO_HS_CONFIG_TILE_COLCNT,
712                                  ICO_HS_CONFIG_TILE_COLCNT_DEFAULT);
713     rowcnt = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
714                                  ICO_HS_CONFIG_TILE_ROWCNT,
715                                  ICO_HS_CONFIG_TILE_ROWCNT_DEFAULT);
716     tilecnt = colcnt * rowcnt;
717
718     /* allocate tile info structure */
719     hs_tile_info = malloc(sizeof(hs_tile_info_t) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
720     valid = (int *)malloc(sizeof(int) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
721     type = (int *)malloc(sizeof(int) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
722     if (!hs_tile_info || !valid || !type) {
723         uifw_warn("hs_tile_init_info: Leave(err malloc tile str failed)");
724         return ICO_HS_ERR;
725     }
726     memset(hs_tile_info, 0, sizeof(hs_tile_info_t) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
727
728     /* get screen size */
729     ico_uxf_window_screen_size_get(&dispW, &dispH);
730     while ((dispW < 0) || (dispH < 0)) {
731         ico_uxf_main_loop_iterate();
732         try++;
733         if (try > 10) {
734             uifw_warn("hs_tile_init_info: Leave(cannot get screen size)");
735             return ICO_HS_ERR;
736         }
737         usleep(10000);
738         ico_uxf_window_screen_size_get(&dispW, &dispH);
739     }
740     width = dispW;
741     height = dispH - ICO_HS_SIZE_SB_HEIGHT;
742
743     /* determin tile size (interval the tile is 10 percent of the tile width) */
744     if (((float)width / (float)colcnt) > ((float)height / (float)rowcnt)) {
745         /* tile size based height */
746         tilesize = height / (1.0 * rowcnt + 0.1 * (rowcnt + 1));
747         mSide = (width - (tilesize * colcnt + tilesize * 0.1 * (colcnt + 1)))
748                 / 2;
749         mTop = 0;
750     }
751     else {
752         /* tile size based width */
753         tilesize = width / (1.0 * colcnt + 0.1 * (colcnt + 1));
754         mSide = 0;
755         mTop = (height - (tilesize * rowcnt + tilesize * 0.1 * (rowcnt + 1)))
756                 / 2;
757     }
758     uifw_trace("hs_tile_init_info: mSide=%d mTop=%d disp(%dx%d)", mSide, mTop,
759                dispW, dispH);
760
761     /* get tile config */
762     sValid = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
763                                         ICO_HS_CONFIG_TILE_VALID, NULL);
764     sType = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
765                                        ICO_HS_CONFIG_TILE_TYPE, NULL);
766     hs_convert_tile_config(sValid, valid, tilecnt, 1);
767     hs_convert_tile_config(sType, type, tilecnt, ICO_HS_TILE_SMALL);
768
769     /* set tile parameter */
770     for (idx = 0; idx < tilecnt; idx++) {
771         tinfo = &hs_tile_info[idx];
772         row = idx / colcnt;
773         column = idx % colcnt;
774         tinfo->idx = idx;
775         memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
776         tinfo->valid = valid[idx];
777         tinfo->type = type[idx];
778         if (idx == tilecnt - 1) {
779             tinfo->type = ICO_HS_TILE_OTHERS;
780         }
781         tinfo->l_press = 0;
782         tinfo->change = 0;
783
784         tinfo->coord_x = mSide + tilesize * 0.1 + (tilesize + tilesize * 0.1)
785                 * column;
786         tinfo->coord_y = mTop + ICO_HS_SIZE_SB_HEIGHT + tilesize * 0.1 + (tilesize
787                 + tilesize * 0.1) * row;
788         switch (tinfo->type) {
789         case ICO_HS_TILE_SMALL:
790             tinfo->size_x = tilesize;
791             tinfo->size_y = tilesize;
792             break;
793         case ICO_HS_TILE_HWIDE:
794             tinfo->size_x = tilesize;
795             tinfo->size_y = tilesize * 2.1;
796             break;
797         case ICO_HS_TILE_VWIDE:
798             tinfo->size_x = tilesize * 2.1;
799             tinfo->size_y = tilesize;
800             break;
801         case ICO_HS_TILE_LARGE:
802             tinfo->size_x = tilesize * 2.1;
803             tinfo->size_y = tilesize * 2.1;
804             break;
805         default:
806             tinfo->size_x = tilesize;
807             tinfo->size_y = tilesize;
808             break;
809         }
810
811         uifw_trace("TILE_INFO:tile[%d]={%d,%d,%s,%d,%d,%d,(%dx%d),(%d,%d)}",
812                    idx, tinfo->idx, tinfo->valid, tinfo->appid, tinfo->type,
813                    tinfo->l_press, tinfo->change, tinfo->size_x, tinfo->size_y,
814                    tinfo->coord_x, tinfo->coord_y);
815     }
816
817     hs_tile_cnt = tilecnt;
818
819     return ICO_HS_OK;
820 }
821
822 /*--------------------------------------------------------------------------*/
823 /**
824  * @brief   hs_tile_delete_hide
825  *          delete hide app information.
826  *
827  * @param[in]   appid               application id
828  * @return      none
829  */
830 /*--------------------------------------------------------------------------*/
831 void
832 hs_tile_delete_hide(const char *appid)
833 {
834     int ii;
835     hs_tile_info_t *tinfo;
836     hs_tile_hide_t *hide, *bhide;
837
838     for (ii = 0; ii < hs_tile_cnt; ii++) {
839         tinfo = &hs_tile_info[ii];
840         hide = tinfo->next;
841         bhide = NULL;
842         while (hide) {
843             if (strcmp(appid, hide->appid) == 0) {
844                 if (! bhide) {
845                     tinfo->next = hide->next;
846                 }
847                 else {
848                     bhide->next = hide->next;
849                 }
850                 free(hide);
851                 break;
852             }
853             bhide = hide;
854             hide = hide->next;
855         }
856     }
857
858     return;
859 }
860
861 /*--------------------------------------------------------------------------*/
862 /**
863  * @brief   hs_tile_free_app
864  *          delete all information of the indicated tile.
865  *
866  * @param[in]   idx                 tile index
867  * @return      none
868  */
869 /*--------------------------------------------------------------------------*/
870 void
871 hs_tile_free_app(int idx)
872 {
873     hs_tile_info_t *tinfo;
874     hs_tile_hide_t *hide;
875     int win;
876
877     if ((idx >= 0) && (idx < hs_tile_cnt)) {
878         tinfo = &hs_tile_info[idx];
879         if (tinfo->next) {
880             hide = tinfo->next;
881             tinfo->next = hide->next;
882             strncpy(tinfo->appid, hide->appid, ICO_UXF_MAX_PROCESS_NAME);
883             free(hide);
884         }
885         else {
886             memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
887         }
888     }
889     else {
890         return;
891     }
892
893     if (strlen(hs_active_onscreen) > 0) {
894         return;
895     }
896     if (hs_regulation_visible == 0) {
897         return;
898     }
899
900     if ((hs_stat_touch == ICO_HS_TOUCH_IN_SHOW)
901         && (strlen(tinfo->appid) > 0)) {
902         win = hs_get_process_window(tinfo->appid);
903         if (win > 0) {
904             ico_uxf_window_visible_raise(win, 1, 1);
905         }
906     }
907 }
908
909 /*--------------------------------------------------------------------------*/
910 /**
911  * @brief   hs_tile_show_screen
912  *          show tile screen again.
913  *
914  * @param       none
915  * @return      none
916  */
917 /*--------------------------------------------------------------------------*/
918 void
919 hs_tile_show_screen(void)
920 {
921     Ico_Uxf_ProcessWin window;
922     int ret;
923     int idx, sid;
924     hs_tile_info_t *tinfo;
925
926     if (hs_regulation_visible == 0) {
927         uifw_trace("hs_regulation_visible: regulation, no menu display");
928         return;
929     }
930
931     /* chnage to menu mode for AppsControler        */
932     ico_uxf_window_control(NULL, -1, ICO_UXF_APPSCTL_TEMPVISIBLE, 1);
933
934     /* all apps invisible */
935     /* hide HomeScreen layer menu                   */
936     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
937
938     /* show application tile */
939     for (idx = 0; idx < hs_tile_cnt; idx++) {
940         tinfo = &hs_tile_info[idx];
941         if (tinfo->appid[0] == 0)
942             continue;
943
944         ret = ico_uxf_process_window_get(tinfo->appid, &window, 1);
945         uifw_trace("hs_tile_show_screen: window_get app[%s] = %d(%08x)",
946                    tinfo->appid, ret, window.window);
947         if (((ret > 0) || (ret == ICO_UXF_E2BIG)) && (window.window != 0))  {
948             uifw_trace("hs_tile_show_screen: move %d=%dx%d(%d,%d)", idx,
949                        tinfo->size_x, tinfo->size_y, tinfo->coord_x, tinfo->coord_y);
950             /* move application window to HomeScreen layer  */
951             ico_uxf_window_layer(window.window, HS_LAYER_HOMESCREEN);
952             ico_uxf_window_resize(window.window, tinfo->size_x, tinfo->size_y);
953             ico_uxf_window_move(window.window, tinfo->coord_x, tinfo->coord_y);
954             ico_uxf_window_visible_raise(window.window, 1, 1);
955         }
956     }
957
958     hs_stat_touch = ICO_HS_TOUCH_IN_SHOW;
959     /* visible and raise touch layer */
960     sid = hs_get_process_window(ICO_HS_APPID_DEFAULT_TOUCH);
961     if (sid >= 0) {
962         ico_uxf_window_visible_raise(sid, 1, 1);
963     }
964     /* show HomeScreen layer menu                   */
965     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 1);
966     /* show Touch layer                             */
967     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 1);
968     /* hide application layer                       */
969     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 0);
970
971     ico_uxf_main_loop_iterate();
972 }
973
974 /*--------------------------------------------------------------------------*/
975 /**
976  * @brief   hs_tile_get_index_app
977  *          Get tile index that has indicated application id.
978  *
979  * @param[in]   appid               application id
980  * @return      result
981  * @retval      >=0                 tile index
982  * @retval      -1                  not exist
983  */
984 /*--------------------------------------------------------------------------*/
985 int
986 hs_tile_get_index_app(const char *appid)
987 {
988     int idx;
989     hs_tile_info_t *tinfo;
990
991     for (idx = 0; idx < hs_tile_cnt; idx++) {
992         tinfo = &hs_tile_info[idx];
993         if (strncmp(tinfo->appid, appid, ICO_UXF_MAX_PROCESS_NAME) == 0) {
994             return idx;
995         }
996     }
997
998     return -1;
999 }
1000
1001 /*--------------------------------------------------------------------------*/
1002 /**
1003  * @brief   hs_tile_get_minchange
1004  *          Get a application tile index that has no application
1005  *          or is changed minimum
1006  *
1007  * @param       none
1008  * @return      result
1009  * @retval      >=                  success(tile index)
1010  * @retval      < 0                 error
1011  */
1012 /*--------------------------------------------------------------------------*/
1013 int
1014 hs_tile_get_minchange(void)
1015 {
1016     int ii;
1017     int idx = -1;
1018     int min = -1;
1019     hs_tile_info_t *tinfo;
1020
1021     for (ii = 0; ii < hs_tile_cnt; ii++) {
1022         tinfo = &hs_tile_info[ii];
1023         if ((tinfo->type > ICO_HS_TILE_OTHERS) && ((tinfo->change <= min)
1024                 || (min == -1))) {
1025             idx = ii;
1026             min = tinfo->change;
1027         }
1028         if ((tinfo->type > ICO_HS_TILE_OTHERS) && (strlen(tinfo->appid) == 0)) {
1029             return ii;
1030         }
1031     }
1032
1033     return idx;
1034 }
1035
1036 /*--------------------------------------------------------------------------*/
1037 /**
1038  * @brief   hs_tile_kill_app
1039  *          terminate the indicated application, and free the tile
1040  *          that have the application.
1041  *
1042  * @param[in]   appid               application id
1043  * @return      none
1044  */
1045 /*--------------------------------------------------------------------------*/
1046 void
1047 hs_tile_kill_app(const char *appid)
1048 {
1049     int idx, ret;
1050
1051     idx = hs_tile_get_index_app(appid);
1052
1053     ret = ico_uxf_process_terminate(appid);
1054     if (ret == ICO_UXF_EOK) {
1055         if (idx >= 0) {
1056             hs_tile_free_app(idx);
1057         }
1058         else {
1059             hs_tile_delete_hide(appid);
1060         }
1061     }
1062
1063     return;
1064 }
1065
1066 /*--------------------------------------------------------------------------*/
1067 /**
1068  * @brief   hs_tile_get_index_pos
1069  *          get the tile index of the position.
1070  *
1071  * @param[in]   appid               application id
1072  * @return      tile index
1073  * @retval      >=0                 success
1074  * @retval      ICO_HS_ERR          error
1075  */
1076 /*--------------------------------------------------------------------------*/
1077 int
1078 hs_tile_get_index_pos(int x, int y, int w, int h)
1079 {
1080     int idx = -1;
1081     hs_tile_info_t *tinfo;
1082
1083     for (idx = 0; idx < hs_tile_cnt; idx++) {
1084         tinfo = &hs_tile_info[idx];
1085         if ((tinfo->coord_x == x) && (tinfo->coord_y == y) && (tinfo->size_x
1086                 == w) && (tinfo->size_y == h)) {
1087             return idx;
1088         }
1089     }
1090
1091     return ICO_HS_ERR;
1092 }
1093
1094 /*--------------------------------------------------------------------------*/
1095 /**
1096  * @brief   hs_tile_set_app
1097  *          set the applicaton to the tile of the indicated index.
1098  *
1099  * @param[in]   idx                 tile index
1100  * @param[in]   appid               application id
1101  * @return      none
1102  */
1103 /*--------------------------------------------------------------------------*/
1104 void
1105 hs_tile_set_app(int idx, const char *appid)
1106 {
1107     hs_tile_info_t *tinfo;
1108     hs_tile_hide_t *search, *bsearch, *hide = NULL;
1109     int ii;
1110
1111     uifw_trace("hs_tile_set_app: Enter(idx=%d appid=%s)", idx, appid);
1112
1113     if ((idx < 0) && (idx >= hs_tile_cnt)) {
1114         return;
1115     }
1116
1117     /* check whether the app is same as tile one */
1118     tinfo = &hs_tile_info[idx];
1119     if (strcmp(tinfo->appid, appid) == 0) {
1120         return;
1121     }
1122
1123     /* check whether the app is hide */
1124     for (ii = 0; ii < hs_tile_cnt; ii++) {
1125         tinfo = &hs_tile_info[ii];
1126         if (tinfo->valid == 0) continue;
1127         search = tinfo->next;
1128         bsearch = NULL;
1129         while (search) {
1130             if (strcmp(search->appid, appid) == 0) {
1131                 hide = search;
1132                 if (! bsearch) {
1133                     tinfo->next = search->next;
1134                 }
1135                 else {
1136                     bsearch->next = search->next;
1137                 }
1138                 break;
1139             }
1140             bsearch = search;
1141             search = search->next;
1142         }
1143         if (hide) {
1144             break;
1145         }
1146     }
1147
1148     /* set */
1149     tinfo = &hs_tile_info[idx];
1150     if (tinfo->valid > 0) {
1151         if (strlen(tinfo->appid) != 0) {
1152             int oldwin = hs_get_process_window(tinfo->appid);
1153             if (oldwin > 0) {
1154                 (void) ico_uxf_window_hide(oldwin);
1155             }
1156
1157             if (! hide) {
1158                 hide = malloc(sizeof(hs_tile_hide_t));
1159             }
1160             if (! hide) {
1161                 uifw_warn("hs_tile_set_app: cannot allocate app table");
1162             }
1163             else {
1164                 memset(hide, 0, sizeof(hs_tile_hide_t));
1165                 strncpy(hide->appid, tinfo->appid, ICO_UXF_MAX_PROCESS_NAME);
1166                 if (tinfo->next) {
1167                     hide->next = tinfo->next;
1168                 }
1169                 tinfo->next = hide;
1170             }
1171         }
1172         else {
1173             free(hide);
1174         }
1175
1176         strncpy(tinfo->appid, appid, ICO_UXF_MAX_PROCESS_NAME);
1177         tinfo->change++;
1178     }
1179 }
1180
1181 /*--------------------------------------------------------------------------*/
1182 /**
1183  * @brief   hs_get_process_window
1184  *          get window surface from applicatoin id including special id.
1185  *
1186  * @param[in]   appid               application id
1187  * @return      result
1188  * @retval      >=0                 surface
1189  * @retval      -1                  not exist
1190  */
1191 /*--------------------------------------------------------------------------*/
1192 static int
1193 hs_get_process_window(const char *appid)
1194 {
1195     Ico_Uxf_ProcessWin wins[2];
1196     int ret;
1197
1198     if (strcmp(appid, ICO_HS_APPID_DEFAULT_TOUCH) == 0) {
1199         ret = ico_uxf_process_window_get(hs_name_homescreen, wins, 2);
1200         if ((ret > 1) || (ret == ICO_UXF_E2BIG))    {
1201             return wins[1].window;
1202         }
1203     }
1204     else {
1205         ret = ico_uxf_process_window_get(appid, wins, 1);
1206         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1207             return wins[0].window;
1208         }
1209     }
1210
1211     return -1;
1212 }
1213
1214 /*--------------------------------------------------------------------------*/
1215 /**
1216  * @brief   hs_show_onscreen
1217  *          set onscreen window to visible.
1218  *
1219  * @param       none
1220  * @return      none
1221  */
1222 /*--------------------------------------------------------------------------*/
1223 void
1224 hs_show_onscreen(void)
1225 {
1226     Ico_Uxf_ProcessWin window;
1227     int ret;
1228
1229     ret = ico_uxf_process_window_get(ICO_HS_APPID_DEFAULT_ONS, &window, 1);
1230
1231     if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1232         ico_uxf_window_layer(window.window, HS_LAYER_ONSCREEN);
1233     }
1234 }
1235
1236 /*--------------------------------------------------------------------------*/
1237 /**
1238  * @brief   hs_hide_onscreen
1239  *          set onscreen window to invisible.
1240  *
1241  * @param       none
1242  * @return      none
1243  */
1244 /*--------------------------------------------------------------------------*/
1245 void
1246 hs_hide_onscreen(void)
1247 {
1248     Ico_Uxf_ProcessWin window;
1249     int ret;
1250
1251     ret = ico_uxf_process_window_get(ICO_HS_APPID_DEFAULT_ONS, &window, 1);
1252
1253     if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1254         ico_uxf_window_layer(window.window, HS_LAYER_BACKGROUND);
1255         ico_uxf_window_lower(window.window);
1256     }
1257 }
1258
1259 /*--------------------------------------------------------------------------*/
1260 /**
1261  * @brief   hs_click_escutcheon
1262  *          processing when escutcheon button is clicked.
1263  *
1264  * @param       none
1265  * @return      none
1266  */
1267 /*--------------------------------------------------------------------------*/
1268 void
1269 hs_click_escutcheon(void)
1270 {
1271     uifw_trace("hs_click_escutcheon: Enter(regulation=%d)", hs_regulation_visible);
1272
1273     if (strlen(hs_active_onscreen) > 0) {
1274         uifw_trace("hs_click_escutcheon: Leave(active=%s)", hs_active_onscreen);
1275         return;
1276     }
1277     if (hs_regulation_visible == 0) {
1278         uifw_trace("hs_click_escutcheon: Leave(regulation)");
1279         return;
1280     }
1281
1282     if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
1283         hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1284         uifw_trace("hs_click_escutcheon: hs_show_appscreen");
1285         hs_show_appscreen(NULL);
1286     }
1287     else if (hs_stat_touch == ICO_HS_TOUCH_IN_HIDE) {
1288         hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1289         uifw_trace("hs_click_escutcheon: hs_tile_show_screen");
1290         hs_tile_show_screen();
1291     }
1292     uifw_trace("hs_click_escutcheon: Leave");
1293 }
1294
1295
1296 /*--------------------------------------------------------------------------*/
1297 /**
1298  * @brief   hs_click_applist
1299  *          processing when application list button is clicked.
1300  *
1301  * @param       none
1302  * @return      regulation
1303  * @retval      =0      regulation controlled(no display)
1304  * @retval      =1      no regulation
1305  */
1306 /*--------------------------------------------------------------------------*/
1307 int
1308 hs_click_applist(void)
1309 {
1310     uifw_trace("hs_click_applist: Enter(regulation=%d)", hs_regulation_visible);
1311
1312     if (hs_regulation_visible == 0) {
1313         uifw_trace("hs_click_applist: Leave(regulation)");
1314         return 0;
1315     }
1316
1317     /* operation sound */
1318     hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1319     uifw_trace("hs_click_applist: Leave");
1320
1321     /* show Touch layer                             */
1322     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 1);
1323     /* show OnScreen windows                        */
1324     hs_show_onscreen();
1325
1326     return 1;
1327 }
1328
1329 /*--------------------------------------------------------------------------*/
1330 /**
1331  * @brief   hs_is_special_app
1332  *          return 1 if the application is special one(homescreen)
1333  *          /statusbar/onscreen).
1334  *
1335  * @param[in]   appid       applicationId
1336  * @return      special application
1337  * @retval      1           special application(HomeScreen/StatusBar ... etc)
1338  * @retval      0           normal application
1339  */
1340 /*--------------------------------------------------------------------------*/
1341 static int
1342 hs_is_special_app(const char *appid)
1343 {
1344     if ((strncmp(appid, hs_name_homescreen, ICO_UXF_MAX_PROCESS_NAME) == 0)
1345             || (strncmp(appid, gStatusbarName, ICO_UXF_MAX_PROCESS_NAME) == 0)
1346             || (strncmp(appid, gOnscreenName, ICO_UXF_MAX_PROCESS_NAME) == 0)
1347             || (strncmp(appid, ICO_HS_APPID_DEFAULT_TOUCH,
1348                         ICO_UXF_MAX_PROCESS_NAME) == 0)) {
1349         uifw_trace("hs_is_special_app: app(%s) is special", appid);
1350         return 1;
1351     }
1352     uifw_trace("hs_is_special_app: app(%s) is normal", appid);
1353     return 0;
1354 }
1355
1356 /*--------------------------------------------------------------------------*/
1357 /**
1358  * @brief   hs_is_noicon_app
1359  *          return 1 if the application has no menu icon
1360  *
1361  * @param[in]   appid       applicationId
1362  * @return      no need menu
1363  * @retval      1           no need menu
1364  * @retval      0           need menu
1365  */
1366 /*--------------------------------------------------------------------------*/
1367 static int
1368 hs_is_noicon_app(const char *appid)
1369 {
1370     const Ico_Uxf_conf_application  *appConf;
1371
1372     appConf = ico_uxf_getAppByAppid(appid);
1373     if (! appConf)  {
1374         uifw_trace("hs_is_noicon_app: appid(%s) dose not exist", appid);
1375         return 0;
1376     }
1377
1378     if (appConf->noicon)    {
1379         uifw_trace("hs_is_noicon_app: appid(%s) has no icon", appid);
1380         return 1;
1381     }
1382     uifw_trace("hs_is_noicon_app: appid(%s) has icon", appid);
1383     return 0;
1384 }
1385
1386 /*--------------------------------------------------------------------------*/
1387 /**
1388  * @brief   hs_terminate_all_app
1389  *          terminate all application that homescreen handled
1390  *
1391  * @param       none
1392  * @return      none
1393  */
1394 /*--------------------------------------------------------------------------*/
1395 static void
1396 hs_terminate_all_app(void)
1397 {
1398     Ico_Uxf_ProcessAttr procs[ICO_HS_APP_NUM_MAX];
1399     int cnt;
1400     int ii = 0;
1401
1402     cnt = ico_uxf_process_query_processes(procs, ICO_HS_APP_NUM_MAX);
1403     if (cnt == ICO_UXF_E2BIG)
1404         cnt = ICO_HS_APP_NUM_MAX;
1405     uifw_trace("hs_terminate_all_app: ico_uxf_process_query_processes() = %d",
1406                cnt);
1407     for (ii = 0; ii < cnt; ii++) {
1408         if (hs_is_special_app(procs[ii].process))
1409             continue;
1410         uifw_trace("hs_terminate_all_app: terminate(%s)", procs[ii].process);
1411         ico_uxf_process_terminate(procs[ii].process);
1412     }
1413     ico_uxf_process_terminate(gStatusbarName);
1414     ico_uxf_process_terminate(gOnscreenName);
1415 }
1416
1417 /*--------------------------------------------------------------------------*/
1418 /**
1419  * @brief   hs_req_ctlr_tile
1420  *          processing when homescreen received json command from extra
1421  *          tools.
1422  *
1423  * @param       none
1424  * @return      none
1425  */
1426 /*--------------------------------------------------------------------------*/
1427 void
1428 hs_req_ctlr_tile(void)
1429 {
1430     int ii, ret;
1431     int idx;
1432
1433     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
1434         if ((hs_command_tile_req[ii].appid[0] == 0)
1435                 || (hs_is_special_app(hs_command_tile_req[ii].appid) == TRUE)) {
1436             continue;
1437         }
1438
1439         idx = hs_tile_get_index_app(hs_command_tile_req[ii].appid);
1440
1441         /* terminate app */
1442         if (hs_command_tile_req[ii].terminate != IGNORE) {
1443             ret = ico_uxf_process_terminate(hs_command_tile_req[ii].appid);
1444             if (ret == ICO_UXF_EOK) {
1445                 if (idx >= 0) {
1446                     hs_tile_free_app(idx);
1447                 }
1448             }
1449         }
1450
1451         /* execute app */
1452         if (strlen(hs_command_tile_req[ii].exe_name) > 0) {
1453             ico_uxf_process_execute(hs_command_tile_req[ii].exe_name);
1454         }
1455     }
1456     hs_tile_show_screen();
1457 }
1458
1459 /*--------------------------------------------------------------------------*/
1460 /**
1461  * @brief   hs_touch_up_api_list
1462  *          processing when application list button touch up.
1463  *
1464  * @param       none
1465  * @return      none
1466  */
1467 /*--------------------------------------------------------------------------*/
1468 static void
1469 hs_touch_up_api_list(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1470 {
1471     int idx = *(int *)data;
1472     char buf[ICO_HS_TEMP_BUF_SIZE];
1473     char path[ICO_HS_TEMP_BUF_SIZE];
1474     hs_tile_info_t *tinfo;
1475
1476     tinfo = &hs_tile_info[idx];
1477
1478     /* set the image */
1479     hs_get_image_path(path, sizeof(path));
1480     sprintf(buf, "%s"fname_api_all_off, path);
1481     evas_object_image_file_set(obj, buf, NULL);
1482     /* move and resize in the image */
1483     evas_object_move(obj, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1484     evas_object_resize(obj, tinfo->size_x, tinfo->size_y);
1485     /* show the image */
1486     evas_object_show(obj);
1487
1488     uifw_trace("hs_touch_up_api_list: idx=%d", idx);
1489     strncpy(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1490             sizeof(hs_active_onscreen));
1491     hs_get_ons_edj_path(path, sizeof(path));
1492     sprintf(buf, "OPEN %s%s %s", path, ICO_HS_ONS_APPLI_LIST_NAME,
1493             ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1494     uifw_trace("send '%s' to onscreen", buf);
1495     if (hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_OS, buf) < 0) {
1496         memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
1497     }
1498     hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1499 }
1500
1501 /*--------------------------------------------------------------------------*/
1502 /**
1503  * @brief   hs_touch_down_api_list
1504  *          processing when application list button touch down.
1505  *
1506  * @param       none
1507  * @return      none
1508  */
1509 /*--------------------------------------------------------------------------*/
1510 static void
1511 hs_touch_down_api_list(void *data, Evas *evas, Evas_Object *obj,
1512                        void *event_info)
1513 {
1514     int idx = *(int *)data;
1515     char buf[ICO_HS_TEMP_BUF_SIZE];
1516     char path[ICO_HS_TEMP_BUF_SIZE];
1517     hs_tile_info_t *tinfo;
1518
1519     tinfo = &hs_tile_info[idx];
1520
1521     /* set the image */
1522     hs_get_image_path(path, sizeof(path));
1523     sprintf(buf, "%s"fname_api_all_off, path);
1524     evas_object_image_file_set(obj, buf, NULL);
1525     /* move and resize in the image */
1526     evas_object_move(obj, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1527     evas_object_resize(obj, tinfo->size_x, tinfo->size_y);
1528     /* show the image */
1529     evas_object_show(obj);
1530 }
1531
1532 /*--------------------------------------------------------------------------*/
1533 /**
1534  * @brief   hs_ecore_timer_event
1535  *          handler called when applicaton tile is pushed long term
1536  *          to terminate application.
1537  *
1538  * @param[in]   data                user data
1539  * @return      result
1540  * @retval      ECORE_CALLBACK_CANCEL
1541  *                                  delete this handler
1542  */
1543 /*--------------------------------------------------------------------------*/
1544 static Eina_Bool
1545 hs_ecore_timer_event(void *data)
1546 {
1547     int idx = *(int *)data;
1548     char buf[ICO_HS_TEMP_BUF_SIZE];
1549     char tmp[ICO_HS_TEMP_BUF_SIZE];
1550     hs_tile_info_t *tinfo;
1551
1552     tinfo = &hs_tile_info[idx];
1553     if (tinfo->l_press == 1) {
1554         /* flag reset */
1555         tinfo->l_press = 0;
1556         /* set terminate app id for onscrAppliKill */
1557         if (strlen(tinfo->appid) != 0) {
1558             strncpy(hs_kill_appid, tinfo->appid, sizeof(hs_kill_appid));
1559             uifw_trace("hs_ecore_timer_event :hs_kill_appid = %s", hs_kill_appid);
1560             strncpy(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1561                     sizeof(hs_active_onscreen));
1562             sprintf(buf, "OPEN HomeScreen/src/appli_kill.edj %s",
1563                     ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1564             hs_get_ons_edj_path(tmp, sizeof(tmp));
1565             sprintf(buf, "OPEN %s%s %s", tmp, ICO_HS_ONS_APPLI_KILL_NAME,
1566                     ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1567             uifw_trace("hs_ecore_timer_event: send %s to onscreen", buf);
1568             hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_OS, buf);
1569         }
1570     }
1571     return ECORE_CALLBACK_CANCEL;
1572 }
1573
1574 /*--------------------------------------------------------------------------*/
1575 /**
1576  * @brief   hs_touch_up_tile
1577  *          processing when application tile button touch up.
1578  *
1579  * @param[in]   data                user data
1580  * @param[in]   obj                 evas object of the button
1581  * @param[in]   event_info          evas event infomation
1582  * @return      none
1583  */
1584 /*--------------------------------------------------------------------------*/
1585 static void
1586 hs_touch_up_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1587 {
1588     int idx = *(int *)data;
1589     int ret;
1590     char buf[64];
1591     hs_tile_info_t *tinfo;
1592
1593     uifw_trace("hs_touch_up_tile: idx=%d", idx);
1594
1595     if (strlen(hs_active_onscreen) != 0) {
1596         uifw_trace("hs_touch_up_tile: active=%s", hs_active_onscreen);
1597         return;
1598     }
1599
1600     tinfo = &hs_tile_info[idx];
1601     if (tinfo->l_press == 1) {
1602         /* flag reset */
1603         tinfo->l_press = 0;
1604         /* send a message to extra tools */
1605         if (strlen(tinfo->appid) != 0) {
1606             sprintf(buf, "FOCUS %s", tinfo->appid);
1607             uifw_trace("hs_touch_up_tile: send '%s' to extra tools", buf);
1608             ret = hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_CM, buf);
1609             if (ret < 0) {
1610                 hs_show_appscreen(tinfo->appid);
1611
1612                 hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1613             }
1614         }
1615     }
1616 }
1617
1618 /*--------------------------------------------------------------------------*/
1619 /**
1620  * @brief   hs_touch_down_tile
1621  *          processing when application tile button touch down.
1622  *
1623  * @param[in]   data                user data
1624  * @param[in]   obj                 evas object of the button
1625  * @param[in]   event_info          evas event infomation
1626  * @return      none
1627  */
1628 /*--------------------------------------------------------------------------*/
1629 static void
1630 hs_touch_down_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1631 {
1632     int idx = *(int *)data;
1633     hs_tile_info_t *tinfo;
1634
1635     uifw_trace("hs_touch_down_tile: idx=%d", idx);
1636
1637     tinfo = &hs_tile_info[idx];
1638     tinfo->l_press = 1;
1639     if (strlen(tinfo->appid) != 0) {
1640     }
1641
1642     if (tinfo->type > ICO_HS_TILE_OTHERS) {
1643         /* add timer to detect long push */
1644         ecore_timer_add(ICO_HS_TOUCH_TIME_OUT, hs_ecore_timer_event, &tinfo->idx);
1645     }
1646 }
1647
1648 /*--------------------------------------------------------------------------*/
1649 /**
1650  * @brief   hs_add_bg_image
1651  *          add image to background. if config does not have image file or
1652  *          image file is not exsit, background show default edj.
1653  *
1654  * @param[in]   canvas_bg           evas of background
1655  * @return      none
1656  */
1657 /*--------------------------------------------------------------------------*/
1658 static void
1659 hs_add_bg_image(Evas *canvas_bg)
1660 {
1661     char img[ICO_HS_TEMP_BUF_SIZE];
1662     char path[ICO_HS_TEMP_BUF_SIZE];
1663     char *fname;
1664     Evas_Object *canvas;
1665     Evas_Load_Error err;
1666     int dispW, dispH;
1667
1668     fname = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1669                                        ICO_HS_CONFIG_BG, NULL);
1670     if (!fname) {
1671         uifw_trace("hs_add_bg_image: backgound config is not exist");
1672         return;
1673     }
1674     if (fname[0] == '/') {
1675         snprintf(img, sizeof(img), "%s", fname);
1676     }
1677     else {
1678         hs_get_image_path(path, sizeof(path));
1679         snprintf(img, sizeof(img), "%s/%s", path, fname);
1680     }
1681
1682     ico_uxf_window_screen_size_get(&dispW, &dispH);
1683
1684     canvas = evas_object_image_filled_add(canvas_bg);
1685     evas_object_image_file_set(canvas, img, NULL);
1686     err = evas_object_image_load_error_get(canvas);
1687     if (err != EVAS_LOAD_ERROR_NONE) {
1688         uifw_trace("hs_add_bg_image: backgound image is not exist");
1689     }
1690     else {
1691         evas_object_image_fill_set(canvas, 0, 0, dispW, dispH - ICO_HS_SIZE_SB_HEIGHT);
1692         evas_object_resize(canvas, dispW, dispH - ICO_HS_SIZE_SB_HEIGHT);
1693         evas_object_show(canvas);
1694     }
1695
1696     return;
1697 }
1698
1699 /*--------------------------------------------------------------------------*/
1700 /**
1701  * @brief   hs_add_touch_listener
1702  *          make and add listener to application tile button.
1703  *
1704  * @param[in]   canvas_fg           evas of tile screen
1705  * @return      none
1706  */
1707 /*--------------------------------------------------------------------------*/
1708 static void
1709 hs_add_touch_listener(Evas *canvas_fg)
1710 {
1711     int idx;
1712     char img[ICO_HS_TEMP_BUF_SIZE];
1713     char path[ICO_HS_TEMP_BUF_SIZE];
1714     Evas_Object * canvas;
1715     hs_tile_info_t *tinfo;
1716
1717     /* set image path */
1718     hs_get_image_path(path, sizeof(path));
1719     sprintf(img, "%s"fname_api_all_off, path);
1720
1721     /* setup tile */
1722     for (idx = 0; idx < hs_tile_cnt; idx++) {
1723         tinfo = &hs_tile_info[idx];
1724         if (tinfo->valid == 0)
1725             continue;
1726         /* Creates a reclangle */
1727         canvas = evas_object_rectangle_add(canvas_fg);
1728         /* Set a color or image */
1729         evas_object_color_set(canvas, 0, 0, 0, 0);
1730         /* Move and resize the rectangle */
1731         evas_object_move(canvas, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1732         evas_object_resize(canvas, tinfo->size_x, tinfo->size_y);
1733         /* add event the rectangle */
1734         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_UP,
1735                                        hs_touch_up_tile, &tinfo->idx);
1736         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_DOWN,
1737                                        hs_touch_down_tile, &tinfo->idx);
1738         /* show the rectangle */
1739         evas_object_show(canvas);
1740     }
1741     /* application menu icon */
1742     tinfo = &hs_tile_info[hs_tile_cnt - 1];
1743     if ((tinfo->valid == 0) && (tinfo->type == ICO_HS_TILE_APPLIST)) {
1744         canvas = evas_object_image_filled_add(canvas_fg);
1745         evas_object_image_file_set(canvas, img, NULL);
1746         evas_object_move(canvas, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1747         evas_object_resize(canvas, tinfo->size_x, tinfo->size_y);
1748         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_UP,
1749                                        hs_touch_up_api_list, &tinfo->idx);
1750         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_DOWN,
1751                                        hs_touch_down_api_list, &tinfo->idx);
1752         evas_object_show(canvas);
1753     }
1754 }
1755
1756 /*--------------------------------------------------------------------------*/
1757 /**
1758  * @brief   hs_create_window
1759  *          create background and tile screen window of ecore.
1760  *
1761  * @param[in]   type                background or tile screen
1762  * @return      none
1763  */
1764 /*--------------------------------------------------------------------------*/
1765 static void *
1766 hs_create_window(int type)
1767 {
1768     Evas_Object *edje;
1769     Ecore_Evas * window;
1770     Evas * canvas;
1771     int dispW, dispH;
1772     int width, height;
1773     char path[ICO_HS_TEMP_BUF_SIZE];
1774     char edjfile[ICO_HS_TEMP_BUF_SIZE];
1775
1776     window = ecore_evas_new(NULL, 0, 0, 1, 1, "frame=0");
1777
1778     ecore_main_loop_iterate();
1779     ico_uxf_window_screen_size_get(&dispW, &dispH);
1780     width = dispW;
1781     height = dispH - ICO_HS_SIZE_SB_HEIGHT;
1782
1783     if (!window) {
1784         uifw_warn("HomeScreen: could not create window.");
1785         return NULL;
1786     }
1787
1788     canvas = ecore_evas_get(window);
1789     edje = edje_object_add(canvas);
1790     /* NULL is aborted */
1791     if (!edje) {
1792         uifw_warn("HomeScreen: could not create edje object!");
1793         return NULL;
1794     }
1795
1796     hs_get_edj_path(path, sizeof(path));
1797
1798     if (type == ICO_HS_WINDOW_TYPE_BG) {
1799         ecore_evas_move(window, 0, 0);
1800         ecore_evas_resize(window, width, height);
1801         ecore_evas_show(window);
1802         {
1803             int err = edje_object_load_error_get(edje);
1804             const char *errmsg = edje_load_error_str(err);
1805             sprintf(edjfile, "%s/home_screen_bg.edj", path);
1806             if (!edje_object_file_set(edje, edjfile, "home_screen_bg")) {
1807                 uifw_warn(
1808                           "HomeScreen: could not load 'home_screen_bg' from %s: %s",
1809                           edjfile, errmsg);
1810                 evas_object_del(edje);
1811                 return NULL;
1812             }
1813         }
1814         evas_object_move(edje, 0, 0);
1815         evas_object_resize(edje, width, height);
1816         evas_object_show(edje);
1817
1818         hs_add_bg_image(canvas);
1819     }
1820     else {
1821         ecore_evas_move(window, 0, 0);
1822         ecore_evas_resize(window, width, height);
1823         ecore_evas_alpha_set(window, EINA_TRUE);
1824         ecore_evas_show(window);
1825         {
1826             int err = edje_object_load_error_get(edje);
1827             const char *errmsg = edje_load_error_str(err);
1828             sprintf(edjfile, "%s/home_screen_touch.edj", path);
1829             if (!edje_object_file_set(edje, edjfile, "home_screen_touch")) {
1830                 uifw_warn(
1831                           "HomeScreen: could not load 'home_screen_touch' from %s: %s",
1832                           edjfile, errmsg);
1833                 evas_object_del(edje);
1834                 return NULL;
1835             }
1836         }
1837         evas_object_move(edje, 0, 0);
1838         evas_object_resize(edje, width, height);
1839         evas_object_show(edje);
1840
1841         hs_add_touch_listener(canvas);
1842     }
1843
1844     return edje;
1845 }
1846
1847 /*--------------------------------------------------------------------------*/
1848 /**
1849  * @brief   hs_display_control
1850  *          callback function
1851  *
1852  * @param[in]   conf                configuration
1853  * @param[in]   show                show
1854  * @return      none
1855  */
1856 /*--------------------------------------------------------------------------*/
1857 static void
1858 hs_display_control(const Ico_Uxf_conf_application *conf, const int show)
1859 {
1860     uifw_trace("hs_display_control: app=%s show=%d", conf->appid, show);
1861     /* no need, because all control in AppsController       */
1862 }
1863
1864 /*--------------------------------------------------------------------------*/
1865 /**
1866  * @brief   hs_sound_control
1867  *          callback function
1868  *
1869  * @param[in]   conf                configuration
1870  * @param[in]   adjust              adjust
1871  * @return      none
1872  */
1873 /*--------------------------------------------------------------------------*/
1874 static void
1875 hs_sound_control(const Ico_Uxf_conf_application *conf, const int adjust)
1876 {
1877     uifw_trace("hs_sound_control: app=%s adjust=%d", conf->appid, adjust);
1878     /* no need, because all control in AppsController       */
1879 }
1880
1881 /*--------------------------------------------------------------------------*/
1882 /**
1883  * @brief   hs_input_control
1884  *          callback function
1885  *
1886  * @param[in]   conf                configuration
1887  * @param[in]   inputsw             input switch
1888  * @return      none
1889  */
1890 /*--------------------------------------------------------------------------*/
1891 static void
1892 hs_input_control(const Ico_Uxf_conf_application *conf, const int inputsw)
1893 {
1894     uifw_trace("hs_input_control: app=%s inputsw=%d", conf->appid, inputsw);
1895     /* no need, because all control in AppsController       */
1896 }
1897
1898 /*--------------------------------------------------------------------------*/
1899 /**
1900  * @brief   hs_regulation_listener: change regulation callback(static function)
1901  *
1902  * @param[in]   appcategory     category Id
1903  * @param[in]   control         control(display/sound/input active/inactive)
1904  * @param[in]   user_data       user data(unused)
1905  * @return      none
1906  */
1907 /*--------------------------------------------------------------------------*/
1908 static void
1909 hs_regulation_listener(const int appcategory,
1910                        const ico_apc_reguration_control_t control, void *user_data)
1911 {
1912     if ((appcategory == hs_regulation_category) &&
1913         (control.display != ICO_SYC_APC_REGULATION_NOCHANGE))   {
1914         uifw_trace("hs_regulation_listener: Enter(category=%d disp=%d)",
1915                    appcategory, control.display);
1916
1917         if (control.display == ICO_SYC_APC_REGULATION_REGULATION)   {
1918             /* Invisible by reguration      */
1919             if (hs_regulation_visible)  {
1920                 hs_regulation_visible = 0;
1921                 if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
1922                     uifw_trace("hs_regulation_listener: Change to App screen");
1923                     hs_show_appscreen(NULL);
1924                 }
1925                 hs_hide_onscreen();
1926                 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
1927             }
1928         }
1929         else    {
1930             /* Visible                      */
1931             uifw_trace("hs_regulation_listener: Change to ALl screen");
1932             hs_regulation_visible = 1;
1933         }
1934     }
1935 }
1936
1937 /*--------------------------------------------------------------------------*/
1938 /**
1939  * @brief   main
1940  *          homescreen main. initialize UXF, app manager, and ecore.
1941  *
1942  * @param[in]   argc                counts of argment
1943  * @param[in]   argv                argment
1944  * @return      result
1945  * @retval      >=0                 success
1946  * @retval      -1                  error
1947  */
1948 /*--------------------------------------------------------------------------*/
1949 int
1950 main(int argc, char *argv[])
1951 {
1952     int ii = 0;
1953     int ret;
1954     int port;
1955
1956     /* get pkg name */
1957     char *pkg;
1958     printf("main: %s: %s", getenv("HOME"), getenv("PKG_NAME"));
1959     pkg = getenv("PKG_NAME");
1960     memset(hs_name_homescreen, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
1961     if (pkg) {
1962         strncpy(hs_name_homescreen, pkg, ICO_UXF_MAX_PROCESS_NAME);
1963     }
1964     else {
1965         strncpy(hs_name_homescreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1966                 ICO_UXF_MAX_PROCESS_NAME);
1967     }
1968     strncpy(gStatusbarName,
1969             (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1970                                        ICO_HS_CONFIG_SB,
1971                                        ICO_HS_APPID_DEFAULT_SB),
1972             ICO_UXF_MAX_PROCESS_NAME);
1973     strncpy(gOnscreenName,
1974             (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1975                                        ICO_HS_CONFIG_ONS,
1976                                        ICO_HS_APPID_DEFAULT_ONS),
1977             ICO_UXF_MAX_PROCESS_NAME);
1978     hs_snd_init();
1979
1980     /* init for window mgr */
1981     ret = ico_uxf_init(hs_name_homescreen);
1982     if (ret != ICO_UXF_EOK) {
1983         uifw_error("ico_uxf_init err=%d", ret);
1984         exit(8);
1985     }
1986     ico_uxf_callback_set(ICO_UXF_EVENT_ALL, hs_uxf_event, 0);
1987     memset(hs_app_screen_window, 0, sizeof(hs_app_screen_window));
1988     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
1989         hs_app_screen_window[ii].resize_w = -1;
1990         hs_app_screen_window[ii].resize_h = -1;
1991         hs_app_screen_window[ii].move_x = -1;
1992         hs_app_screen_window[ii].move_y = -1;
1993     }
1994     ico_uxf_main_loop_iterate();
1995
1996     /* init tile info */
1997     ret = hs_tile_init_info();
1998     if (ret < 0) {
1999         uifw_warn("hs_tile_init_info err=%d", ret);
2000     }
2001
2002     /* start onscreen & statusbar apps */
2003     ret = ico_uxf_process_execute(gOnscreenName);
2004     if (ret < 0) {
2005         uifw_warn("ico_uxf_process_execute(%s) err=%d", gOnscreenName, ret);
2006     }
2007     ret = ico_uxf_process_execute(gStatusbarName);
2008     if (ret < 0) {
2009         uifw_warn("ico_uxf_process_execute(%s) err=%d", gStatusbarName, ret);
2010     }
2011     ico_uxf_main_loop_iterate();
2012
2013     /* init EFL */
2014     ecore_evas_init();
2015     edje_init();
2016
2017     /* for communicate other process */
2018     port = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
2019                                ICO_HS_CONFIG_WS_PORT,
2020                                ICO_HS_WS_PORT);
2021     hs_lib_main(port);
2022
2023     /* initialize Application Controller    */
2024     ret = ico_syc_apc_init(hs_display_control, hs_sound_control, hs_input_control);
2025     if (ret != ICO_SYC_EOK) {
2026         uifw_error("ico_syc_apc_init err=%d", ret);
2027     }
2028
2029     /* start default tile apps */
2030     hs_tile_start_apps();
2031     ico_uxf_main_loop_iterate();
2032
2033     /* HomeScreen Menu(background) */
2034     hs_create_window(ICO_HS_WINDOW_TYPE_BG);
2035     /* add callbacks for wayland(wl_window_mgr) */
2036     ecore_main_fd_handler_add(ico_uxf_wl_display_fd(), ECORE_FD_READ,
2037                               hs_ecore_uxf_eventfd, NULL, /* data */
2038                               NULL, NULL);
2039     ecore_main_loop_iterate();
2040     ico_uxf_main_loop_iterate();
2041
2042     /* HomeScreen Menu(touch) */
2043     hs_create_window(ICO_HS_WINDOW_TYPE_TOUCH);
2044
2045     /* initiailze regulation control    */
2046     hs_regulation_category = ico_uxf_getSysCategoryByName("CarSetting");
2047     ico_syc_apc_regulation_listener(hs_regulation_listener, NULL);
2048
2049     if (hs_regulation_visible)  {
2050         uifw_trace("main: no regulation");
2051         hs_tile_show_screen();
2052     }
2053     else    {
2054         uifw_trace("main: regulation");
2055         hs_show_appscreen(NULL);
2056     }
2057
2058     /* add callback to app configuration */
2059     ico_uxf_econf_setAppUpdateCb(NULL);
2060
2061     /* wait events */
2062     ecore_main_loop_begin();
2063
2064     /* terminate Application Controller */
2065     (void) ico_syc_apc_term();
2066
2067     /* terminate all known application */
2068     hs_terminate_all_app();
2069
2070     /* shutdown EFL */
2071     edje_shutdown();
2072     ecore_evas_shutdown();
2073
2074     return 0;
2075 }