Bug fix for TIVI-1002
[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
471     if (hs_stat_touch == ICO_HS_TOUCH_IN_HIDE)  {
472         /* if it is the transition from an application screen to        */
473         /* an other application screen, perform animation at hide screen*/
474         ico_uxf_window_animation_control(0, 1);
475     }
476     else    {
477         /* if it is the transition from menu to an application screen,  */
478         /* do not perform animation at hide appllication screen         */
479         ico_uxf_window_animation_control(0, 0);
480     }
481
482     /* change to noraml mode for AppsControler  */
483     ico_uxf_window_control(NULL, -1, ICO_UXF_APPSCTL_TEMPVISIBLE, 0);
484
485     /* touch to invisible */
486     sid = hs_get_process_window(ICO_HS_APPID_DEFAULT_TOUCH);
487     if (sid >= 0) {
488         ico_uxf_window_hide(sid);
489     }
490     /* all apps invisible */
491     hs_set_invisible_all();
492
493     /* show other apps */
494     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
495         if (hs_app_screen_window[ii].appid[0] == 0)
496             continue;
497         appConf = ico_uxf_getAppByAppid(hs_app_screen_window[ii].appid);
498         if (appConf != NULL) {
499             hs_app_screen_window[ii].category = appConf->categoryId;
500         }
501         if (hs_is_special_app(hs_app_screen_window[ii].appid))
502             continue;
503         if ((appid != NULL) && strncmp(hs_app_screen_window[ii].appid, appid,
504                                        ICO_UXF_MAX_PROCESS_NAME) == 0)
505             continue;
506
507         /* if invisible */
508         ret = ico_uxf_process_window_get(hs_app_screen_window[ii].appid,
509                                          &window, 1);
510         uifw_trace("hs_show_appscreen: window_get app[%s] = %d(visible=%d)",
511                    hs_app_screen_window[ii].appid, ret,
512                    hs_app_screen_window[ii].visible);
513         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
514             if (hs_app_screen_window[ii].visible == 0) {
515             }
516             else {
517                 uifw_trace("hs_show_appscreen: move %d=%dx%d(%d,%d)", ii,
518                            hs_app_screen_window[ii].resize_w,
519                            hs_app_screen_window[ii].resize_h,
520                            hs_app_screen_window[ii].move_x, hs_app_screen_window[ii].move_y);
521                 /* move application window to application layer */
522                 ico_uxf_window_resize(window.window,
523                                       hs_app_screen_window[ii].resize_w,
524                                       hs_app_screen_window[ii].resize_h);
525                 ico_uxf_window_move(window.window,
526                                     hs_app_screen_window[ii].move_x,
527                                     hs_app_screen_window[ii].move_y);
528                 ico_uxf_window_show(window.window);
529                 if (! appConf)  {
530                     ico_uxf_window_layer(window.window, HS_LAYER_APPLICATION);
531                     /* show application layer                       */
532                     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 1);
533                 }
534                 else    {
535                     ico_uxf_window_layer(window.window, appConf->display[0].layerId);
536                     /* show application layer                       */
537                     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN,
538                                           appConf->display[0].layerId, 1);
539                 }
540             }
541         }
542     }
543     /* hide HomeScreen layer menu                   */
544     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
545     /* hide Touch layer                             */
546     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 0);
547     /* hide OnScreen windows                        */
548     hs_hide_onscreen();
549
550     /* show own apps */
551     if (appid != NULL) {
552         idx = hs_get_index_appscreendata(appid);
553         /* if not set pos, load default */
554         appConf = ico_uxf_getAppByAppid(appid);
555         if (appConf != NULL) {
556             int x, y, width, height;
557             (void)ico_uxf_getAppDisplay(appConf, 0, &x, &y, &width, &height);
558
559             if ((hs_app_screen_window[idx].resize_w == -1)
560                     || (hs_app_screen_window[idx].resize_h == -1)) {
561                 hs_app_screen_window[idx].resize_w = width;
562                 hs_app_screen_window[idx].resize_h = height;
563             }
564             if ((hs_app_screen_window[idx].move_x == -1)
565                     || (hs_app_screen_window[idx].move_y == -1)) {
566                 hs_app_screen_window[idx].move_x = x;
567                 hs_app_screen_window[idx].move_y = y;
568             }
569             if ((hs_app_screen_window[idx].resize_w == 0)
570                     && (hs_app_screen_window[idx].resize_h == 0)
571                     && (hs_app_screen_window[idx].move_x == 0)
572                     && (hs_app_screen_window[idx].move_y == 0)) {
573                 /* not have manifest, set default */
574                 ico_uxf_window_screen_size_get(&dispW, &dispH);
575                 hs_app_screen_window[idx].resize_w = dispW;
576                 hs_app_screen_window[idx].resize_h = (dispH - ICO_HS_SIZE_SB_HEIGHT) / 2;
577                 hs_app_screen_window[idx].move_x = 0;
578                 hs_app_screen_window[idx].move_y = ICO_HS_SIZE_SB_HEIGHT;
579             }
580         }
581
582         /* show */
583         ret = ico_uxf_process_window_get(appid, &window, 1);
584         uifw_trace("hs_show_appscreen: window_get app[%s] = %d", appid, ret);
585         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
586             uifw_trace("hs_show_appscreen: move %d=%dx%d(%d,%d)", idx,
587                        hs_app_screen_window[idx].resize_w,
588                        hs_app_screen_window[idx].resize_h,
589                        hs_app_screen_window[idx].move_x,
590                        hs_app_screen_window[idx].move_y);
591             /* window hide and resize (for animation)       */
592             ico_uxf_window_hide(window.window);
593             /* move application window to application layer */
594             ico_uxf_window_resize(window.window,
595                                   hs_app_screen_window[idx].resize_w,
596                                   hs_app_screen_window[idx].resize_h);
597             ico_uxf_window_move(window.window,
598                                 hs_app_screen_window[idx].move_x,
599                                 hs_app_screen_window[idx].move_y);
600             if (! appConf)  {
601                 ico_uxf_window_layer(window.window, HS_LAYER_APPLICATION);
602                 /* show application layer                       */
603                 ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 1);
604             }
605             else    {
606                 ico_uxf_window_layer(window.window, appConf->display[0].layerId);
607                 /* show application layer                       */
608                 ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN,
609                                       appConf->display[0].layerId, 1);
610             }
611             ico_uxf_window_raise(window.window);
612             /* activate application window                  */
613             if ((appConf != NULL) && (appConf->display[0].layerId == HS_LAYER_SOFTKEYBOARD)) {
614                 ico_uxf_window_active(window.window, ICO_UXF_WINDOW_POINTER_ACTIVE);
615             }
616             else    {
617                 ico_uxf_window_active(window.window,
618                                           ICO_UXF_WINDOW_KEYBOARD_ACTIVE);
619             }
620             ico_syc_apc_active(appid);
621
622             hs_app_screen_window[idx].visible = 1;
623             /* hide HomeScreen layer                        */
624             ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
625             /* visible application window with animation    */
626             ico_uxf_window_visible_animation(window.window, 1);
627         }
628     }
629     hs_stat_touch = ICO_HS_TOUCH_IN_HIDE;
630     ico_uxf_window_animation_control(0, 1);     /* change hide animation to default */
631     ico_uxf_main_loop_iterate();
632
633     uifw_trace("hs_show_appscreen: Leave");
634 }
635
636 /*--------------------------------------------------------------------------*/
637 /**
638  * @brief   hs_tile_start_apps
639  *          launch the default application that indicated by configuration
640  *          file.
641  *
642  * @param       none
643  * @return      none
644  */
645 /*--------------------------------------------------------------------------*/
646 static void
647 hs_tile_start_apps(void)
648 {
649     char cName[ICO_UXF_MAX_PROCESS_NAME + 1];
650     int idx, ret;
651     int idx1, idx2;
652     const char *appName;
653     const Ico_Uxf_App_Config *appConf;
654     hs_tile_info_t *tinfo;
655
656     /* excute applications in tile menu */
657     for (idx = 0; idx < hs_tile_cnt; idx++) {
658         tinfo = &hs_tile_info[idx];
659         if (tinfo->valid == 0) continue;
660         sprintf(cName, ICO_HS_CONFIG_TILE_APP"%d", idx);
661         appName = hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN, cName, NULL);
662         if ((appName != NULL) && (strcmp(appName, "none") != 0)) {
663             ret = ico_uxf_process_execute(appName);
664             if (ret >= 0) {
665                 uifw_trace("hs_tile_start_apps: execute tile[%d]=%s", idx, appName);
666                 memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
667                 strncpy(tinfo->appid, appName, ICO_UXF_MAX_PROCESS_NAME);
668             }
669         }
670     }
671
672     /* excute no menu applications      */
673     appConf = ico_uxf_getAppConfig();
674     idx = hs_tile_cnt;
675     for (idx1 = 0; idx1 < appConf->applicationNum; idx1++)  {
676         if (appConf->application[idx1].autostart == 0)  continue;
677         for (idx2 = 0; idx2 < hs_tile_cnt; idx2++)  {
678             if (! strcmp(hs_tile_info[idx2].appid, appConf->application[idx1].appid)) break;
679         }
680         if (idx2 >= hs_tile_cnt)    {
681             ret = ico_uxf_process_execute(appConf->application[idx1].appid);
682             if (ret >= 0) {
683                 uifw_trace("hs_tile_start_apps: execute no tile[%d]=%s",
684                            idx, appConf->application[idx1].appid);
685                 memset(hs_tile_info[idx].appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
686                 strncpy(hs_tile_info[idx].appid,
687                         appConf->application[idx1].appid, ICO_UXF_MAX_PROCESS_NAME);
688                 idx ++;
689                 if ((idx - hs_tile_cnt) >= ICO_HS_NOTILE_APP_MAX)   break;
690             }
691         }
692     }
693     hs_notile_cnt = idx - hs_tile_cnt;
694 }
695
696 /*--------------------------------------------------------------------------*/
697 /**
698  * @brief   hs_tile_init_info
699  *          initialize tile information.
700  *
701  * @param       none
702  * @return      result
703  * @retval      ICO_HS_OK           success
704  * @retval      ICO_HS_ERR          err
705  */
706 /*--------------------------------------------------------------------------*/
707 static int
708 hs_tile_init_info(void)
709 {
710     int idx, row, column;
711     char *sValid = NULL;
712     char *sType = NULL;
713     int *valid = NULL;
714     int *type = NULL;
715     int dispW, dispH;
716     int width, height;
717     int mSide, mTop;
718     int colcnt, rowcnt, tilecnt, tilesize;
719     int try = 0;
720     hs_tile_info_t *tinfo;
721
722     /* count tile */
723     colcnt = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
724                                  ICO_HS_CONFIG_TILE_COLCNT,
725                                  ICO_HS_CONFIG_TILE_COLCNT_DEFAULT);
726     rowcnt = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
727                                  ICO_HS_CONFIG_TILE_ROWCNT,
728                                  ICO_HS_CONFIG_TILE_ROWCNT_DEFAULT);
729     tilecnt = colcnt * rowcnt;
730
731     /* allocate tile info structure */
732     hs_tile_info = malloc(sizeof(hs_tile_info_t) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
733     valid = (int *)malloc(sizeof(int) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
734     type = (int *)malloc(sizeof(int) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
735     if (!hs_tile_info || !valid || !type) {
736         uifw_warn("hs_tile_init_info: Leave(err malloc tile str failed)");
737         return ICO_HS_ERR;
738     }
739     memset(hs_tile_info, 0, sizeof(hs_tile_info_t) * (tilecnt + ICO_HS_NOTILE_APP_MAX));
740
741     /* get screen size */
742     ico_uxf_window_screen_size_get(&dispW, &dispH);
743     while ((dispW < 0) || (dispH < 0)) {
744         ico_uxf_main_loop_iterate();
745         try++;
746         if (try > 10) {
747             uifw_warn("hs_tile_init_info: Leave(cannot get screen size)");
748             return ICO_HS_ERR;
749         }
750         usleep(10000);
751         ico_uxf_window_screen_size_get(&dispW, &dispH);
752     }
753     width = dispW;
754     height = dispH - ICO_HS_SIZE_SB_HEIGHT;
755
756     /* determin tile size (interval the tile is 10 percent of the tile width) */
757     if (((float)width / (float)colcnt) > ((float)height / (float)rowcnt)) {
758         /* tile size based height */
759         tilesize = height / (1.0 * rowcnt + 0.1 * (rowcnt + 1));
760         mSide = (width - (tilesize * colcnt + tilesize * 0.1 * (colcnt + 1)))
761                 / 2;
762         mTop = 0;
763     }
764     else {
765         /* tile size based width */
766         tilesize = width / (1.0 * colcnt + 0.1 * (colcnt + 1));
767         mSide = 0;
768         mTop = (height - (tilesize * rowcnt + tilesize * 0.1 * (rowcnt + 1)))
769                 / 2;
770     }
771     uifw_trace("hs_tile_init_info: mSide=%d mTop=%d disp(%dx%d)", mSide, mTop,
772                dispW, dispH);
773
774     /* get tile config */
775     sValid = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
776                                         ICO_HS_CONFIG_TILE_VALID, NULL);
777     sType = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
778                                        ICO_HS_CONFIG_TILE_TYPE, NULL);
779     hs_convert_tile_config(sValid, valid, tilecnt, 1);
780     hs_convert_tile_config(sType, type, tilecnt, ICO_HS_TILE_SMALL);
781
782     /* set tile parameter */
783     for (idx = 0; idx < tilecnt; idx++) {
784         tinfo = &hs_tile_info[idx];
785         row = idx / colcnt;
786         column = idx % colcnt;
787         tinfo->idx = idx;
788         memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
789         tinfo->valid = valid[idx];
790         tinfo->type = type[idx];
791         if (idx == tilecnt - 1) {
792             tinfo->type = ICO_HS_TILE_OTHERS;
793         }
794         tinfo->l_press = 0;
795         tinfo->change = 0;
796
797         tinfo->coord_x = mSide + tilesize * 0.1 + (tilesize + tilesize * 0.1)
798                 * column;
799         tinfo->coord_y = mTop + ICO_HS_SIZE_SB_HEIGHT + tilesize * 0.1 + (tilesize
800                 + tilesize * 0.1) * row;
801         switch (tinfo->type) {
802         case ICO_HS_TILE_SMALL:
803             tinfo->size_x = tilesize;
804             tinfo->size_y = tilesize;
805             break;
806         case ICO_HS_TILE_HWIDE:
807             tinfo->size_x = tilesize;
808             tinfo->size_y = tilesize * 2.1;
809             break;
810         case ICO_HS_TILE_VWIDE:
811             tinfo->size_x = tilesize * 2.1;
812             tinfo->size_y = tilesize;
813             break;
814         case ICO_HS_TILE_LARGE:
815             tinfo->size_x = tilesize * 2.1;
816             tinfo->size_y = tilesize * 2.1;
817             break;
818         default:
819             tinfo->size_x = tilesize;
820             tinfo->size_y = tilesize;
821             break;
822         }
823
824         uifw_trace("TILE_INFO:tile[%d]={%d,%d,%s,%d,%d,%d,(%dx%d),(%d,%d)}",
825                    idx, tinfo->idx, tinfo->valid, tinfo->appid, tinfo->type,
826                    tinfo->l_press, tinfo->change, tinfo->size_x, tinfo->size_y,
827                    tinfo->coord_x, tinfo->coord_y);
828     }
829
830     hs_tile_cnt = tilecnt;
831
832     return ICO_HS_OK;
833 }
834
835 /*--------------------------------------------------------------------------*/
836 /**
837  * @brief   hs_tile_delete_hide
838  *          delete hide app information.
839  *
840  * @param[in]   appid               application id
841  * @return      none
842  */
843 /*--------------------------------------------------------------------------*/
844 void
845 hs_tile_delete_hide(const char *appid)
846 {
847     int ii;
848     hs_tile_info_t *tinfo;
849     hs_tile_hide_t *hide, *bhide;
850
851     for (ii = 0; ii < hs_tile_cnt; ii++) {
852         tinfo = &hs_tile_info[ii];
853         hide = tinfo->next;
854         bhide = NULL;
855         while (hide) {
856             if (strcmp(appid, hide->appid) == 0) {
857                 if (! bhide) {
858                     tinfo->next = hide->next;
859                 }
860                 else {
861                     bhide->next = hide->next;
862                 }
863                 free(hide);
864                 break;
865             }
866             bhide = hide;
867             hide = hide->next;
868         }
869     }
870
871     return;
872 }
873
874 /*--------------------------------------------------------------------------*/
875 /**
876  * @brief   hs_tile_free_app
877  *          delete all information of the indicated tile.
878  *
879  * @param[in]   idx                 tile index
880  * @return      none
881  */
882 /*--------------------------------------------------------------------------*/
883 void
884 hs_tile_free_app(int idx)
885 {
886     hs_tile_info_t *tinfo;
887     hs_tile_hide_t *hide;
888     int win;
889
890     if ((idx >= 0) && (idx < hs_tile_cnt)) {
891         tinfo = &hs_tile_info[idx];
892         if (tinfo->next) {
893             hide = tinfo->next;
894             tinfo->next = hide->next;
895             strncpy(tinfo->appid, hide->appid, ICO_UXF_MAX_PROCESS_NAME);
896             free(hide);
897         }
898         else {
899             memset(tinfo->appid, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
900         }
901     }
902     else {
903         return;
904     }
905
906     if (strlen(hs_active_onscreen) > 0) {
907         return;
908     }
909     if (hs_regulation_visible == 0) {
910         return;
911     }
912
913     if ((hs_stat_touch == ICO_HS_TOUCH_IN_SHOW)
914         && (strlen(tinfo->appid) > 0)) {
915         win = hs_get_process_window(tinfo->appid);
916         if (win > 0) {
917             ico_uxf_window_visible_raise(win, 1, 1);
918         }
919     }
920 }
921
922 /*--------------------------------------------------------------------------*/
923 /**
924  * @brief   hs_tile_show_screen
925  *          show tile screen again.
926  *
927  * @param       none
928  * @return      none
929  */
930 /*--------------------------------------------------------------------------*/
931 void
932 hs_tile_show_screen(void)
933 {
934     Ico_Uxf_ProcessWin window;
935     int ret;
936     int idx, sid;
937     hs_tile_info_t *tinfo;
938
939     if (hs_regulation_visible == 0) {
940         uifw_trace("hs_regulation_visible: regulation, no menu display");
941         return;
942     }
943
944     /* chnage to menu mode for AppsControler        */
945     ico_uxf_window_control(NULL, -1, ICO_UXF_APPSCTL_TEMPVISIBLE, 1);
946
947     /* all apps invisible */
948     /* hide HomeScreen layer menu                   */
949     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 0);
950
951     /* show application tile */
952     for (idx = 0; idx < hs_tile_cnt; idx++) {
953         tinfo = &hs_tile_info[idx];
954         if (tinfo->appid[0] == 0)
955             continue;
956
957         ret = ico_uxf_process_window_get(tinfo->appid, &window, 1);
958         uifw_trace("hs_tile_show_screen: window_get app[%s] = %d(%08x)",
959                    tinfo->appid, ret, window.window);
960         if (((ret > 0) || (ret == ICO_UXF_E2BIG)) && (window.window != 0))  {
961             uifw_trace("hs_tile_show_screen: move %d=%dx%d(%d,%d)", idx,
962                        tinfo->size_x, tinfo->size_y, tinfo->coord_x, tinfo->coord_y);
963             /* move application window to HomeScreen layer  */
964             ico_uxf_window_layer(window.window, HS_LAYER_HOMESCREEN);
965             ico_uxf_window_resize(window.window, tinfo->size_x, tinfo->size_y);
966             ico_uxf_window_move(window.window, tinfo->coord_x, tinfo->coord_y);
967             ico_uxf_window_visible_raise(window.window, 1, 1);
968         }
969     }
970
971     hs_stat_touch = ICO_HS_TOUCH_IN_SHOW;
972     /* visible and raise touch layer */
973     sid = hs_get_process_window(ICO_HS_APPID_DEFAULT_TOUCH);
974     if (sid >= 0) {
975         ico_uxf_window_visible_raise(sid, 1, 1);
976     }
977     /* show HomeScreen layer menu                   */
978     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_HOMESCREEN, 1);
979     /* show Touch layer                             */
980     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 1);
981     /* hide application layer                       */
982     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_APPLICATION, 0);
983
984     ico_uxf_main_loop_iterate();
985 }
986
987 /*--------------------------------------------------------------------------*/
988 /**
989  * @brief   hs_tile_get_index_app
990  *          Get tile index that has indicated application id.
991  *
992  * @param[in]   appid               application id
993  * @return      result
994  * @retval      >=0                 tile index
995  * @retval      -1                  not exist
996  */
997 /*--------------------------------------------------------------------------*/
998 int
999 hs_tile_get_index_app(const char *appid)
1000 {
1001     int idx;
1002     hs_tile_info_t *tinfo;
1003
1004     for (idx = 0; idx < hs_tile_cnt; idx++) {
1005         tinfo = &hs_tile_info[idx];
1006         if (strncmp(tinfo->appid, appid, ICO_UXF_MAX_PROCESS_NAME) == 0) {
1007             return idx;
1008         }
1009     }
1010
1011     return -1;
1012 }
1013
1014 /*--------------------------------------------------------------------------*/
1015 /**
1016  * @brief   hs_tile_get_minchange
1017  *          Get a application tile index that has no application
1018  *          or is changed minimum
1019  *
1020  * @param       none
1021  * @return      result
1022  * @retval      >=                  success(tile index)
1023  * @retval      < 0                 error
1024  */
1025 /*--------------------------------------------------------------------------*/
1026 int
1027 hs_tile_get_minchange(void)
1028 {
1029     int ii;
1030     int idx = -1;
1031     int min = -1;
1032     hs_tile_info_t *tinfo;
1033
1034     for (ii = 0; ii < hs_tile_cnt; ii++) {
1035         tinfo = &hs_tile_info[ii];
1036         if ((tinfo->type > ICO_HS_TILE_OTHERS) && ((tinfo->change <= min)
1037                 || (min == -1))) {
1038             idx = ii;
1039             min = tinfo->change;
1040         }
1041         if ((tinfo->type > ICO_HS_TILE_OTHERS) && (strlen(tinfo->appid) == 0)) {
1042             return ii;
1043         }
1044     }
1045
1046     return idx;
1047 }
1048
1049 /*--------------------------------------------------------------------------*/
1050 /**
1051  * @brief   hs_tile_kill_app
1052  *          terminate the indicated application, and free the tile
1053  *          that have the application.
1054  *
1055  * @param[in]   appid               application id
1056  * @return      none
1057  */
1058 /*--------------------------------------------------------------------------*/
1059 void
1060 hs_tile_kill_app(const char *appid)
1061 {
1062     int idx, ret;
1063
1064     idx = hs_tile_get_index_app(appid);
1065
1066     ret = ico_uxf_process_terminate(appid);
1067     if (ret == ICO_UXF_EOK) {
1068         if (idx >= 0) {
1069             hs_tile_free_app(idx);
1070         }
1071         else {
1072             hs_tile_delete_hide(appid);
1073         }
1074     }
1075
1076     return;
1077 }
1078
1079 /*--------------------------------------------------------------------------*/
1080 /**
1081  * @brief   hs_tile_get_index_pos
1082  *          get the tile index of the position.
1083  *
1084  * @param[in]   appid               application id
1085  * @return      tile index
1086  * @retval      >=0                 success
1087  * @retval      ICO_HS_ERR          error
1088  */
1089 /*--------------------------------------------------------------------------*/
1090 int
1091 hs_tile_get_index_pos(int x, int y, int w, int h)
1092 {
1093     int idx = -1;
1094     hs_tile_info_t *tinfo;
1095
1096     for (idx = 0; idx < hs_tile_cnt; idx++) {
1097         tinfo = &hs_tile_info[idx];
1098         if ((tinfo->coord_x == x) && (tinfo->coord_y == y) && (tinfo->size_x
1099                 == w) && (tinfo->size_y == h)) {
1100             return idx;
1101         }
1102     }
1103
1104     return ICO_HS_ERR;
1105 }
1106
1107 /*--------------------------------------------------------------------------*/
1108 /**
1109  * @brief   hs_tile_set_app
1110  *          set the applicaton to the tile of the indicated index.
1111  *
1112  * @param[in]   idx                 tile index
1113  * @param[in]   appid               application id
1114  * @return      none
1115  */
1116 /*--------------------------------------------------------------------------*/
1117 void
1118 hs_tile_set_app(int idx, const char *appid)
1119 {
1120     hs_tile_info_t *tinfo;
1121     hs_tile_hide_t *search, *bsearch, *hide = NULL;
1122     int ii;
1123
1124     uifw_trace("hs_tile_set_app: Enter(idx=%d appid=%s)", idx, appid);
1125
1126     if ((idx < 0) && (idx >= hs_tile_cnt)) {
1127         return;
1128     }
1129
1130     /* check whether the app is same as tile one */
1131     tinfo = &hs_tile_info[idx];
1132     if (strcmp(tinfo->appid, appid) == 0) {
1133         return;
1134     }
1135
1136     /* check whether the app is hide */
1137     for (ii = 0; ii < hs_tile_cnt; ii++) {
1138         tinfo = &hs_tile_info[ii];
1139         if (tinfo->valid == 0) continue;
1140         search = tinfo->next;
1141         bsearch = NULL;
1142         while (search) {
1143             if (strcmp(search->appid, appid) == 0) {
1144                 hide = search;
1145                 if (! bsearch) {
1146                     tinfo->next = search->next;
1147                 }
1148                 else {
1149                     bsearch->next = search->next;
1150                 }
1151                 break;
1152             }
1153             bsearch = search;
1154             search = search->next;
1155         }
1156         if (hide) {
1157             break;
1158         }
1159     }
1160
1161     /* set */
1162     tinfo = &hs_tile_info[idx];
1163     if (tinfo->valid > 0) {
1164         if (strlen(tinfo->appid) != 0) {
1165             int oldwin = hs_get_process_window(tinfo->appid);
1166             if (oldwin > 0) {
1167                 (void) ico_uxf_window_hide(oldwin);
1168             }
1169
1170             if (! hide) {
1171                 hide = malloc(sizeof(hs_tile_hide_t));
1172             }
1173             if (! hide) {
1174                 uifw_warn("hs_tile_set_app: cannot allocate app table");
1175             }
1176             else {
1177                 memset(hide, 0, sizeof(hs_tile_hide_t));
1178                 strncpy(hide->appid, tinfo->appid, ICO_UXF_MAX_PROCESS_NAME);
1179                 if (tinfo->next) {
1180                     hide->next = tinfo->next;
1181                 }
1182                 tinfo->next = hide;
1183             }
1184         }
1185         else {
1186             free(hide);
1187         }
1188
1189         strncpy(tinfo->appid, appid, ICO_UXF_MAX_PROCESS_NAME);
1190         tinfo->change++;
1191     }
1192 }
1193
1194 /*--------------------------------------------------------------------------*/
1195 /**
1196  * @brief   hs_get_process_window
1197  *          get window surface from applicatoin id including special id.
1198  *
1199  * @param[in]   appid               application id
1200  * @return      result
1201  * @retval      >=0                 surface
1202  * @retval      -1                  not exist
1203  */
1204 /*--------------------------------------------------------------------------*/
1205 static int
1206 hs_get_process_window(const char *appid)
1207 {
1208     Ico_Uxf_ProcessWin wins[2];
1209     int ret;
1210
1211     if (strcmp(appid, ICO_HS_APPID_DEFAULT_TOUCH) == 0) {
1212         ret = ico_uxf_process_window_get(hs_name_homescreen, wins, 2);
1213         if ((ret > 1) || (ret == ICO_UXF_E2BIG))    {
1214             return wins[1].window;
1215         }
1216     }
1217     else {
1218         ret = ico_uxf_process_window_get(appid, wins, 1);
1219         if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1220             return wins[0].window;
1221         }
1222     }
1223
1224     return -1;
1225 }
1226
1227 /*--------------------------------------------------------------------------*/
1228 /**
1229  * @brief   hs_show_onscreen
1230  *          set onscreen window to visible.
1231  *
1232  * @param       none
1233  * @return      none
1234  */
1235 /*--------------------------------------------------------------------------*/
1236 void
1237 hs_show_onscreen(void)
1238 {
1239     Ico_Uxf_ProcessWin window;
1240     int ret;
1241
1242     ret = ico_uxf_process_window_get(ICO_HS_APPID_DEFAULT_ONS, &window, 1);
1243
1244     if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1245         ico_uxf_window_layer(window.window, HS_LAYER_ONSCREEN);
1246     }
1247 }
1248
1249 /*--------------------------------------------------------------------------*/
1250 /**
1251  * @brief   hs_hide_onscreen
1252  *          set onscreen window to invisible.
1253  *
1254  * @param       none
1255  * @return      none
1256  */
1257 /*--------------------------------------------------------------------------*/
1258 void
1259 hs_hide_onscreen(void)
1260 {
1261     Ico_Uxf_ProcessWin window;
1262     int ret;
1263
1264     ret = ico_uxf_process_window_get(ICO_HS_APPID_DEFAULT_ONS, &window, 1);
1265
1266     if ((ret > 0) || (ret == ICO_UXF_E2BIG))    {
1267         ico_uxf_window_layer(window.window, HS_LAYER_BACKGROUND);
1268         ico_uxf_window_lower(window.window);
1269     }
1270 }
1271
1272 /*--------------------------------------------------------------------------*/
1273 /**
1274  * @brief   hs_click_escutcheon
1275  *          processing when escutcheon button is clicked.
1276  *
1277  * @param       none
1278  * @return      none
1279  */
1280 /*--------------------------------------------------------------------------*/
1281 void
1282 hs_click_escutcheon(void)
1283 {
1284     uifw_trace("hs_click_escutcheon: Enter(regulation=%d)", hs_regulation_visible);
1285
1286     if (strlen(hs_active_onscreen) > 0) {
1287         uifw_trace("hs_click_escutcheon: Leave(active=%s)", hs_active_onscreen);
1288         return;
1289     }
1290     if (hs_regulation_visible == 0) {
1291         uifw_trace("hs_click_escutcheon: Leave(regulation)");
1292         return;
1293     }
1294
1295     if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
1296         hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1297         uifw_trace("hs_click_escutcheon: hs_show_appscreen");
1298         hs_show_appscreen(NULL);
1299     }
1300     else if (hs_stat_touch == ICO_HS_TOUCH_IN_HIDE) {
1301         hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1302         uifw_trace("hs_click_escutcheon: hs_tile_show_screen");
1303         hs_tile_show_screen();
1304     }
1305     uifw_trace("hs_click_escutcheon: Leave");
1306 }
1307
1308
1309 /*--------------------------------------------------------------------------*/
1310 /**
1311  * @brief   hs_click_applist
1312  *          processing when application list button is clicked.
1313  *
1314  * @param       none
1315  * @return      regulation
1316  * @retval      =0      regulation controlled(no display)
1317  * @retval      =1      no regulation
1318  */
1319 /*--------------------------------------------------------------------------*/
1320 int
1321 hs_click_applist(void)
1322 {
1323     uifw_trace("hs_click_applist: Enter(regulation=%d)", hs_regulation_visible);
1324
1325     if (hs_regulation_visible == 0) {
1326         uifw_trace("hs_click_applist: Leave(regulation)");
1327         return 0;
1328     }
1329
1330     /* operation sound */
1331     hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1332     uifw_trace("hs_click_applist: Leave");
1333
1334     /* show Touch layer                             */
1335     ico_uxf_layer_visible(HS_DISPLAY_HOMESCREEN, HS_LAYER_TOUCH, 1);
1336     /* show OnScreen windows                        */
1337     hs_show_onscreen();
1338
1339     return 1;
1340 }
1341
1342 /*--------------------------------------------------------------------------*/
1343 /**
1344  * @brief   hs_is_special_app
1345  *          return 1 if the application is special one(homescreen)
1346  *          /statusbar/onscreen).
1347  *
1348  * @param[in]   appid       applicationId
1349  * @return      special application
1350  * @retval      1           special application(HomeScreen/StatusBar ... etc)
1351  * @retval      0           normal application
1352  */
1353 /*--------------------------------------------------------------------------*/
1354 static int
1355 hs_is_special_app(const char *appid)
1356 {
1357     if ((strncmp(appid, hs_name_homescreen, ICO_UXF_MAX_PROCESS_NAME) == 0)
1358             || (strncmp(appid, gStatusbarName, ICO_UXF_MAX_PROCESS_NAME) == 0)
1359             || (strncmp(appid, gOnscreenName, ICO_UXF_MAX_PROCESS_NAME) == 0)
1360             || (strncmp(appid, ICO_HS_APPID_DEFAULT_TOUCH,
1361                         ICO_UXF_MAX_PROCESS_NAME) == 0)) {
1362         uifw_trace("hs_is_special_app: app(%s) is special", appid);
1363         return 1;
1364     }
1365     uifw_trace("hs_is_special_app: app(%s) is normal", appid);
1366     return 0;
1367 }
1368
1369 /*--------------------------------------------------------------------------*/
1370 /**
1371  * @brief   hs_is_noicon_app
1372  *          return 1 if the application has no menu icon
1373  *
1374  * @param[in]   appid       applicationId
1375  * @return      no need menu
1376  * @retval      1           no need menu
1377  * @retval      0           need menu
1378  */
1379 /*--------------------------------------------------------------------------*/
1380 static int
1381 hs_is_noicon_app(const char *appid)
1382 {
1383     const Ico_Uxf_conf_application  *appConf;
1384
1385     appConf = ico_uxf_getAppByAppid(appid);
1386     if (! appConf)  {
1387         uifw_trace("hs_is_noicon_app: appid(%s) dose not exist", appid);
1388         return 0;
1389     }
1390
1391     if (appConf->noicon)    {
1392         uifw_trace("hs_is_noicon_app: appid(%s) has no icon", appid);
1393         return 1;
1394     }
1395     uifw_trace("hs_is_noicon_app: appid(%s) has icon", appid);
1396     return 0;
1397 }
1398
1399 /*--------------------------------------------------------------------------*/
1400 /**
1401  * @brief   hs_terminate_all_app
1402  *          terminate all application that homescreen handled
1403  *
1404  * @param       none
1405  * @return      none
1406  */
1407 /*--------------------------------------------------------------------------*/
1408 static void
1409 hs_terminate_all_app(void)
1410 {
1411     Ico_Uxf_ProcessAttr procs[ICO_HS_APP_NUM_MAX];
1412     int cnt;
1413     int ii = 0;
1414
1415     cnt = ico_uxf_process_query_processes(procs, ICO_HS_APP_NUM_MAX);
1416     if (cnt == ICO_UXF_E2BIG)
1417         cnt = ICO_HS_APP_NUM_MAX;
1418     uifw_trace("hs_terminate_all_app: ico_uxf_process_query_processes() = %d",
1419                cnt);
1420     for (ii = 0; ii < cnt; ii++) {
1421         if (hs_is_special_app(procs[ii].process))
1422             continue;
1423         uifw_trace("hs_terminate_all_app: terminate(%s)", procs[ii].process);
1424         ico_uxf_process_terminate(procs[ii].process);
1425     }
1426     ico_uxf_process_terminate(gStatusbarName);
1427     ico_uxf_process_terminate(gOnscreenName);
1428 }
1429
1430 /*--------------------------------------------------------------------------*/
1431 /**
1432  * @brief   hs_req_ctlr_tile
1433  *          processing when homescreen received json command from extra
1434  *          tools.
1435  *
1436  * @param       none
1437  * @return      none
1438  */
1439 /*--------------------------------------------------------------------------*/
1440 void
1441 hs_req_ctlr_tile(void)
1442 {
1443     int ii, ret;
1444     int idx;
1445
1446     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
1447         if ((hs_command_tile_req[ii].appid[0] == 0)
1448                 || (hs_is_special_app(hs_command_tile_req[ii].appid) == TRUE)) {
1449             continue;
1450         }
1451
1452         idx = hs_tile_get_index_app(hs_command_tile_req[ii].appid);
1453
1454         /* terminate app */
1455         if (hs_command_tile_req[ii].terminate != IGNORE) {
1456             ret = ico_uxf_process_terminate(hs_command_tile_req[ii].appid);
1457             if (ret == ICO_UXF_EOK) {
1458                 if (idx >= 0) {
1459                     hs_tile_free_app(idx);
1460                 }
1461             }
1462         }
1463
1464         /* execute app */
1465         if (strlen(hs_command_tile_req[ii].exe_name) > 0) {
1466             ico_uxf_process_execute(hs_command_tile_req[ii].exe_name);
1467         }
1468     }
1469     hs_tile_show_screen();
1470 }
1471
1472 /*--------------------------------------------------------------------------*/
1473 /**
1474  * @brief   hs_touch_up_api_list
1475  *          processing when application list button touch up.
1476  *
1477  * @param       none
1478  * @return      none
1479  */
1480 /*--------------------------------------------------------------------------*/
1481 static void
1482 hs_touch_up_api_list(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1483 {
1484     int idx = *(int *)data;
1485     char buf[ICO_HS_TEMP_BUF_SIZE];
1486     char path[ICO_HS_TEMP_BUF_SIZE];
1487     hs_tile_info_t *tinfo;
1488
1489     tinfo = &hs_tile_info[idx];
1490
1491     /* set the image */
1492     hs_get_image_path(path, sizeof(path));
1493     sprintf(buf, "%s"fname_api_all_off, path);
1494     evas_object_image_file_set(obj, buf, NULL);
1495     /* move and resize in the image */
1496     evas_object_move(obj, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1497     evas_object_resize(obj, tinfo->size_x, tinfo->size_y);
1498     /* show the image */
1499     evas_object_show(obj);
1500
1501     uifw_trace("hs_touch_up_api_list: idx=%d", idx);
1502     strncpy(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1503             sizeof(hs_active_onscreen));
1504     hs_get_ons_edj_path(path, sizeof(path));
1505     sprintf(buf, "OPEN %s%s %s", path, ICO_HS_ONS_APPLI_LIST_NAME,
1506             ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1507     uifw_trace("send '%s' to onscreen", buf);
1508     if (hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_OS, buf) < 0) {
1509         memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
1510     }
1511     hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1512 }
1513
1514 /*--------------------------------------------------------------------------*/
1515 /**
1516  * @brief   hs_touch_down_api_list
1517  *          processing when application list button touch down.
1518  *
1519  * @param       none
1520  * @return      none
1521  */
1522 /*--------------------------------------------------------------------------*/
1523 static void
1524 hs_touch_down_api_list(void *data, Evas *evas, Evas_Object *obj,
1525                        void *event_info)
1526 {
1527     int idx = *(int *)data;
1528     char buf[ICO_HS_TEMP_BUF_SIZE];
1529     char path[ICO_HS_TEMP_BUF_SIZE];
1530     hs_tile_info_t *tinfo;
1531
1532     tinfo = &hs_tile_info[idx];
1533
1534     /* set the image */
1535     hs_get_image_path(path, sizeof(path));
1536     sprintf(buf, "%s"fname_api_all_off, path);
1537     evas_object_image_file_set(obj, buf, NULL);
1538     /* move and resize in the image */
1539     evas_object_move(obj, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1540     evas_object_resize(obj, tinfo->size_x, tinfo->size_y);
1541     /* show the image */
1542     evas_object_show(obj);
1543 }
1544
1545 /*--------------------------------------------------------------------------*/
1546 /**
1547  * @brief   hs_ecore_timer_event
1548  *          handler called when applicaton tile is pushed long term
1549  *          to terminate application.
1550  *
1551  * @param[in]   data                user data
1552  * @return      result
1553  * @retval      ECORE_CALLBACK_CANCEL
1554  *                                  delete this handler
1555  */
1556 /*--------------------------------------------------------------------------*/
1557 static Eina_Bool
1558 hs_ecore_timer_event(void *data)
1559 {
1560     int idx = *(int *)data;
1561     char buf[ICO_HS_TEMP_BUF_SIZE];
1562     char tmp[ICO_HS_TEMP_BUF_SIZE];
1563     hs_tile_info_t *tinfo;
1564
1565     tinfo = &hs_tile_info[idx];
1566     if (tinfo->l_press == 1) {
1567         /* flag reset */
1568         tinfo->l_press = 0;
1569         /* set terminate app id for onscrAppliKill */
1570         if (strlen(tinfo->appid) != 0) {
1571             strncpy(hs_kill_appid, tinfo->appid, sizeof(hs_kill_appid));
1572             uifw_trace("hs_ecore_timer_event :hs_kill_appid = %s", hs_kill_appid);
1573             strncpy(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1574                     sizeof(hs_active_onscreen));
1575             sprintf(buf, "OPEN HomeScreen/src/appli_kill.edj %s",
1576                     ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1577             hs_get_ons_edj_path(tmp, sizeof(tmp));
1578             sprintf(buf, "OPEN %s%s %s", tmp, ICO_HS_ONS_APPLI_KILL_NAME,
1579                     ICO_UXF_PROC_DEFAULT_HOMESCREEN);
1580             uifw_trace("hs_ecore_timer_event: send %s to onscreen", buf);
1581             hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_OS, buf);
1582         }
1583     }
1584     return ECORE_CALLBACK_CANCEL;
1585 }
1586
1587 /*--------------------------------------------------------------------------*/
1588 /**
1589  * @brief   hs_touch_up_tile
1590  *          processing when application tile button touch up.
1591  *
1592  * @param[in]   data                user data
1593  * @param[in]   obj                 evas object of the button
1594  * @param[in]   event_info          evas event infomation
1595  * @return      none
1596  */
1597 /*--------------------------------------------------------------------------*/
1598 static void
1599 hs_touch_up_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1600 {
1601     int idx = *(int *)data;
1602     int ret;
1603     char buf[64];
1604     hs_tile_info_t *tinfo;
1605
1606     uifw_trace("hs_touch_up_tile: idx=%d", idx);
1607
1608     if (strlen(hs_active_onscreen) != 0) {
1609         uifw_trace("hs_touch_up_tile: active=%s", hs_active_onscreen);
1610         return;
1611     }
1612
1613     tinfo = &hs_tile_info[idx];
1614     if (tinfo->l_press == 1) {
1615         /* flag reset */
1616         tinfo->l_press = 0;
1617         /* send a message to extra tools */
1618         if (strlen(tinfo->appid) != 0) {
1619             sprintf(buf, "FOCUS %s", tinfo->appid);
1620             uifw_trace("hs_touch_up_tile: send '%s' to extra tools", buf);
1621             ret = hs_lib_event_message(ICO_HS_PROTOCOL_TYPE_CM, buf);
1622             if (ret < 0) {
1623                 hs_show_appscreen(tinfo->appid);
1624
1625                 hs_snd_play(hs_snd_get_filename(ICO_HS_SND_TYPE_DEFAULT));
1626             }
1627         }
1628     }
1629 }
1630
1631 /*--------------------------------------------------------------------------*/
1632 /**
1633  * @brief   hs_touch_down_tile
1634  *          processing when application tile button touch down.
1635  *
1636  * @param[in]   data                user data
1637  * @param[in]   obj                 evas object of the button
1638  * @param[in]   event_info          evas event infomation
1639  * @return      none
1640  */
1641 /*--------------------------------------------------------------------------*/
1642 static void
1643 hs_touch_down_tile(void *data, Evas *evas, Evas_Object *obj, void *event_info)
1644 {
1645     int idx = *(int *)data;
1646     hs_tile_info_t *tinfo;
1647
1648     uifw_trace("hs_touch_down_tile: idx=%d", idx);
1649
1650     tinfo = &hs_tile_info[idx];
1651     tinfo->l_press = 1;
1652     if (strlen(tinfo->appid) != 0) {
1653     }
1654
1655     if (tinfo->type > ICO_HS_TILE_OTHERS) {
1656         /* add timer to detect long push */
1657         ecore_timer_add(ICO_HS_TOUCH_TIME_OUT, hs_ecore_timer_event, &tinfo->idx);
1658     }
1659 }
1660
1661 /*--------------------------------------------------------------------------*/
1662 /**
1663  * @brief   hs_add_bg_image
1664  *          add image to background. if config does not have image file or
1665  *          image file is not exsit, background show default edj.
1666  *
1667  * @param[in]   canvas_bg           evas of background
1668  * @return      none
1669  */
1670 /*--------------------------------------------------------------------------*/
1671 static void
1672 hs_add_bg_image(Evas *canvas_bg)
1673 {
1674     char img[ICO_HS_TEMP_BUF_SIZE];
1675     char path[ICO_HS_TEMP_BUF_SIZE];
1676     char *fname;
1677     Evas_Object *canvas;
1678     Evas_Load_Error err;
1679     int dispW, dispH;
1680
1681     fname = (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1682                                        ICO_HS_CONFIG_BG, NULL);
1683     if (!fname) {
1684         uifw_trace("hs_add_bg_image: backgound config is not exist");
1685         return;
1686     }
1687     if (fname[0] == '/') {
1688         snprintf(img, sizeof(img), "%s", fname);
1689     }
1690     else {
1691         hs_get_image_path(path, sizeof(path));
1692         snprintf(img, sizeof(img), "%s/%s", path, fname);
1693     }
1694
1695     ico_uxf_window_screen_size_get(&dispW, &dispH);
1696
1697     canvas = evas_object_image_filled_add(canvas_bg);
1698     evas_object_image_file_set(canvas, img, NULL);
1699     err = evas_object_image_load_error_get(canvas);
1700     if (err != EVAS_LOAD_ERROR_NONE) {
1701         uifw_trace("hs_add_bg_image: backgound image is not exist");
1702     }
1703     else {
1704         evas_object_image_fill_set(canvas, 0, 0, dispW, dispH - ICO_HS_SIZE_SB_HEIGHT);
1705         evas_object_resize(canvas, dispW, dispH - ICO_HS_SIZE_SB_HEIGHT);
1706         evas_object_show(canvas);
1707     }
1708
1709     return;
1710 }
1711
1712 /*--------------------------------------------------------------------------*/
1713 /**
1714  * @brief   hs_add_touch_listener
1715  *          make and add listener to application tile button.
1716  *
1717  * @param[in]   canvas_fg           evas of tile screen
1718  * @return      none
1719  */
1720 /*--------------------------------------------------------------------------*/
1721 static void
1722 hs_add_touch_listener(Evas *canvas_fg)
1723 {
1724     int idx;
1725     char img[ICO_HS_TEMP_BUF_SIZE];
1726     char path[ICO_HS_TEMP_BUF_SIZE];
1727     Evas_Object * canvas;
1728     hs_tile_info_t *tinfo;
1729
1730     /* set image path */
1731     hs_get_image_path(path, sizeof(path));
1732     sprintf(img, "%s"fname_api_all_off, path);
1733
1734     /* setup tile */
1735     for (idx = 0; idx < hs_tile_cnt; idx++) {
1736         tinfo = &hs_tile_info[idx];
1737         if (tinfo->valid == 0)
1738             continue;
1739         /* Creates a reclangle */
1740         canvas = evas_object_rectangle_add(canvas_fg);
1741         /* Set a color or image */
1742         evas_object_color_set(canvas, 0, 0, 0, 0);
1743         /* Move and resize the rectangle */
1744         evas_object_move(canvas, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1745         evas_object_resize(canvas, tinfo->size_x, tinfo->size_y);
1746         /* add event the rectangle */
1747         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_UP,
1748                                        hs_touch_up_tile, &tinfo->idx);
1749         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_DOWN,
1750                                        hs_touch_down_tile, &tinfo->idx);
1751         /* show the rectangle */
1752         evas_object_show(canvas);
1753     }
1754     /* application menu icon */
1755     tinfo = &hs_tile_info[hs_tile_cnt - 1];
1756     if ((tinfo->valid == 0) && (tinfo->type == ICO_HS_TILE_APPLIST)) {
1757         canvas = evas_object_image_filled_add(canvas_fg);
1758         evas_object_image_file_set(canvas, img, NULL);
1759         evas_object_move(canvas, tinfo->coord_x, tinfo->coord_y - ICO_HS_SIZE_SB_HEIGHT);
1760         evas_object_resize(canvas, tinfo->size_x, tinfo->size_y);
1761         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_UP,
1762                                        hs_touch_up_api_list, &tinfo->idx);
1763         evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_DOWN,
1764                                        hs_touch_down_api_list, &tinfo->idx);
1765         evas_object_show(canvas);
1766     }
1767 }
1768
1769 /*--------------------------------------------------------------------------*/
1770 /**
1771  * @brief   hs_create_window
1772  *          create background and tile screen window of ecore.
1773  *
1774  * @param[in]   type                background or tile screen
1775  * @return      none
1776  */
1777 /*--------------------------------------------------------------------------*/
1778 static void *
1779 hs_create_window(int type)
1780 {
1781     Evas_Object *edje;
1782     Ecore_Evas * window;
1783     Evas * canvas;
1784     int dispW, dispH;
1785     int width, height;
1786     char path[ICO_HS_TEMP_BUF_SIZE];
1787     char edjfile[ICO_HS_TEMP_BUF_SIZE];
1788
1789     window = ecore_evas_new(NULL, 0, 0, 1, 1, "frame=0");
1790
1791     ecore_main_loop_iterate();
1792     ico_uxf_window_screen_size_get(&dispW, &dispH);
1793     width = dispW;
1794     height = dispH - ICO_HS_SIZE_SB_HEIGHT;
1795
1796     if (!window) {
1797         uifw_warn("HomeScreen: could not create window.");
1798         return NULL;
1799     }
1800
1801     canvas = ecore_evas_get(window);
1802     edje = edje_object_add(canvas);
1803     /* NULL is aborted */
1804     if (!edje) {
1805         uifw_warn("HomeScreen: could not create edje object!");
1806         return NULL;
1807     }
1808
1809     hs_get_edj_path(path, sizeof(path));
1810
1811     if (type == ICO_HS_WINDOW_TYPE_BG) {
1812         ecore_evas_move(window, 0, 0);
1813         ecore_evas_resize(window, width, height);
1814         ecore_evas_show(window);
1815         {
1816             int err = edje_object_load_error_get(edje);
1817             const char *errmsg = edje_load_error_str(err);
1818             sprintf(edjfile, "%s/home_screen_bg.edj", path);
1819             if (!edje_object_file_set(edje, edjfile, "home_screen_bg")) {
1820                 uifw_warn(
1821                           "HomeScreen: could not load 'home_screen_bg' from %s: %s",
1822                           edjfile, errmsg);
1823                 evas_object_del(edje);
1824                 return NULL;
1825             }
1826         }
1827         evas_object_move(edje, 0, 0);
1828         evas_object_resize(edje, width, height);
1829         evas_object_show(edje);
1830
1831         hs_add_bg_image(canvas);
1832     }
1833     else {
1834         ecore_evas_move(window, 0, 0);
1835         ecore_evas_resize(window, width, height);
1836         ecore_evas_alpha_set(window, EINA_TRUE);
1837         ecore_evas_show(window);
1838         {
1839             int err = edje_object_load_error_get(edje);
1840             const char *errmsg = edje_load_error_str(err);
1841             sprintf(edjfile, "%s/home_screen_touch.edj", path);
1842             if (!edje_object_file_set(edje, edjfile, "home_screen_touch")) {
1843                 uifw_warn(
1844                           "HomeScreen: could not load 'home_screen_touch' from %s: %s",
1845                           edjfile, errmsg);
1846                 evas_object_del(edje);
1847                 return NULL;
1848             }
1849         }
1850         evas_object_move(edje, 0, 0);
1851         evas_object_resize(edje, width, height);
1852         evas_object_show(edje);
1853
1854         hs_add_touch_listener(canvas);
1855     }
1856
1857     return edje;
1858 }
1859
1860 /*--------------------------------------------------------------------------*/
1861 /**
1862  * @brief   hs_display_control
1863  *          callback function
1864  *
1865  * @param[in]   conf                configuration
1866  * @param[in]   show                show
1867  * @return      none
1868  */
1869 /*--------------------------------------------------------------------------*/
1870 static void
1871 hs_display_control(const Ico_Uxf_conf_application *conf, const int show)
1872 {
1873     uifw_trace("hs_display_control: app=%s show=%d", conf->appid, show);
1874     /* no need, because all control in AppsController       */
1875 }
1876
1877 /*--------------------------------------------------------------------------*/
1878 /**
1879  * @brief   hs_sound_control
1880  *          callback function
1881  *
1882  * @param[in]   conf                configuration
1883  * @param[in]   adjust              adjust
1884  * @return      none
1885  */
1886 /*--------------------------------------------------------------------------*/
1887 static void
1888 hs_sound_control(const Ico_Uxf_conf_application *conf, const int adjust)
1889 {
1890     uifw_trace("hs_sound_control: app=%s adjust=%d", conf->appid, adjust);
1891     /* no need, because all control in AppsController       */
1892 }
1893
1894 /*--------------------------------------------------------------------------*/
1895 /**
1896  * @brief   hs_input_control
1897  *          callback function
1898  *
1899  * @param[in]   conf                configuration
1900  * @param[in]   inputsw             input switch
1901  * @return      none
1902  */
1903 /*--------------------------------------------------------------------------*/
1904 static void
1905 hs_input_control(const Ico_Uxf_conf_application *conf, const int inputsw)
1906 {
1907     uifw_trace("hs_input_control: app=%s inputsw=%d", conf->appid, inputsw);
1908     /* no need, because all control in AppsController       */
1909 }
1910
1911 /*--------------------------------------------------------------------------*/
1912 /**
1913  * @brief   hs_regulation_listener: change regulation callback(static function)
1914  *
1915  * @param[in]   appcategory     category Id
1916  * @param[in]   control         control(display/sound/input active/inactive)
1917  * @param[in]   user_data       user data(unused)
1918  * @return      none
1919  */
1920 /*--------------------------------------------------------------------------*/
1921 static void
1922 hs_regulation_listener(const int appcategory,
1923                        const ico_apc_reguration_control_t control, void *user_data)
1924 {
1925     if ((appcategory == hs_regulation_category) &&
1926         (control.display != ICO_SYC_APC_REGULATION_NOCHANGE))   {
1927         uifw_trace("hs_regulation_listener: Enter(category=%d disp=%d)",
1928                    appcategory, control.display);
1929
1930         if (control.display == ICO_SYC_APC_REGULATION_REGULATION)   {
1931             /* Invisible by reguration      */
1932             if (hs_regulation_visible)  {
1933                 hs_regulation_visible = 0;
1934                 if (hs_stat_touch == ICO_HS_TOUCH_IN_SHOW) {
1935                     uifw_trace("hs_regulation_listener: Change to App screen");
1936                     hs_show_appscreen(NULL);
1937                 }
1938                 hs_hide_onscreen();
1939                 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
1940             }
1941         }
1942         else    {
1943             /* Visible                      */
1944             uifw_trace("hs_regulation_listener: Change to ALl screen");
1945             hs_regulation_visible = 1;
1946         }
1947     }
1948 }
1949
1950 /*--------------------------------------------------------------------------*/
1951 /**
1952  * @brief   main
1953  *          homescreen main. initialize UXF, app manager, and ecore.
1954  *
1955  * @param[in]   argc                counts of argment
1956  * @param[in]   argv                argment
1957  * @return      result
1958  * @retval      >=0                 success
1959  * @retval      -1                  error
1960  */
1961 /*--------------------------------------------------------------------------*/
1962 int
1963 main(int argc, char *argv[])
1964 {
1965     int ii = 0;
1966     int ret;
1967     int port;
1968
1969     /* get pkg name */
1970     char *pkg;
1971     printf("main: %s: %s", getenv("HOME"), getenv("PKG_NAME"));
1972     pkg = getenv("PKG_NAME");
1973     memset(hs_name_homescreen, 0, ICO_UXF_MAX_PROCESS_NAME + 1);
1974     if (pkg) {
1975         strncpy(hs_name_homescreen, pkg, ICO_UXF_MAX_PROCESS_NAME);
1976     }
1977     else {
1978         strncpy(hs_name_homescreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
1979                 ICO_UXF_MAX_PROCESS_NAME);
1980     }
1981     strncpy(gStatusbarName,
1982             (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1983                                        ICO_HS_CONFIG_SB,
1984                                        ICO_HS_APPID_DEFAULT_SB),
1985             ICO_UXF_MAX_PROCESS_NAME);
1986     strncpy(gOnscreenName,
1987             (char *)hs_conf_get_string(ICO_HS_CONFIG_HOMESCREEN,
1988                                        ICO_HS_CONFIG_ONS,
1989                                        ICO_HS_APPID_DEFAULT_ONS),
1990             ICO_UXF_MAX_PROCESS_NAME);
1991     hs_snd_init();
1992
1993     /* init for window mgr */
1994     ret = ico_uxf_init(hs_name_homescreen);
1995     if (ret != ICO_UXF_EOK) {
1996         uifw_error("ico_uxf_init err=%d", ret);
1997         exit(8);
1998     }
1999     ico_uxf_callback_set(ICO_UXF_EVENT_ALL, hs_uxf_event, 0);
2000     memset(hs_app_screen_window, 0, sizeof(hs_app_screen_window));
2001     for (ii = 0; ii < ICO_HS_APP_NUM_MAX; ii++) {
2002         hs_app_screen_window[ii].resize_w = -1;
2003         hs_app_screen_window[ii].resize_h = -1;
2004         hs_app_screen_window[ii].move_x = -1;
2005         hs_app_screen_window[ii].move_y = -1;
2006     }
2007     ico_uxf_main_loop_iterate();
2008
2009     /* init tile info */
2010     ret = hs_tile_init_info();
2011     if (ret < 0) {
2012         uifw_warn("hs_tile_init_info err=%d", ret);
2013     }
2014
2015     /* start onscreen & statusbar apps */
2016     ret = ico_uxf_process_execute(gOnscreenName);
2017     if (ret < 0) {
2018         uifw_warn("ico_uxf_process_execute(%s) err=%d", gOnscreenName, ret);
2019     }
2020     ret = ico_uxf_process_execute(gStatusbarName);
2021     if (ret < 0) {
2022         uifw_warn("ico_uxf_process_execute(%s) err=%d", gStatusbarName, ret);
2023     }
2024     ico_uxf_main_loop_iterate();
2025
2026     /* init EFL */
2027     ecore_evas_init();
2028     edje_init();
2029
2030     /* for communicate other process */
2031     port = hs_conf_get_integer(ICO_HS_CONFIG_HOMESCREEN,
2032                                ICO_HS_CONFIG_WS_PORT,
2033                                ICO_HS_WS_PORT);
2034     hs_lib_main(port);
2035
2036     /* initialize Application Controller    */
2037     ret = ico_syc_apc_init(hs_display_control, hs_sound_control, hs_input_control);
2038     if (ret != ICO_SYC_EOK) {
2039         uifw_error("ico_syc_apc_init err=%d", ret);
2040     }
2041
2042     /* start default tile apps */
2043     hs_tile_start_apps();
2044     ico_uxf_main_loop_iterate();
2045
2046     /* HomeScreen Menu(background) */
2047     hs_create_window(ICO_HS_WINDOW_TYPE_BG);
2048     /* add callbacks for wayland(wl_window_mgr) */
2049     ecore_main_fd_handler_add(ico_uxf_wl_display_fd(), ECORE_FD_READ,
2050                               hs_ecore_uxf_eventfd, NULL, /* data */
2051                               NULL, NULL);
2052     ecore_main_loop_iterate();
2053     ico_uxf_main_loop_iterate();
2054
2055     /* HomeScreen Menu(touch) */
2056     hs_create_window(ICO_HS_WINDOW_TYPE_TOUCH);
2057
2058     /* initiailze regulation control    */
2059     hs_regulation_category = ico_uxf_getSysCategoryByName("CarSetting");
2060     ico_syc_apc_regulation_listener(hs_regulation_listener, NULL);
2061
2062     if (hs_regulation_visible)  {
2063         uifw_trace("main: no regulation");
2064         hs_tile_show_screen();
2065     }
2066     else    {
2067         uifw_trace("main: regulation");
2068         hs_show_appscreen(NULL);
2069     }
2070
2071     /* add callback to app configuration */
2072     ico_uxf_econf_setAppUpdateCb(NULL);
2073
2074     /* wait events */
2075     ecore_main_loop_begin();
2076
2077     /* terminate Application Controller */
2078     (void) ico_syc_apc_term();
2079
2080     /* terminate all known application */
2081     hs_terminate_all_app();
2082
2083     /* shutdown EFL */
2084     edje_shutdown();
2085     ecore_evas_shutdown();
2086
2087     return 0;
2088 }