Bug fix TIVI-976 ,TIVI-974 and addition of the window animation interface.
[profile/ivi/ico-uxf-weston-plugin.git] / tests / test-homescreen.c
1 /*
2  * Copyright © 2012 Intel Corporation
3  * Copyright © 2013 TOYOTA MOTOR CORPORATION
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting documentation, and
9  * that the name of the copyright holders not be used in advertising or
10  * publicity pertaining to distribution of the software without specific,
11  * written prior permission.  The copyright holders make no representations
12  * about the suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21  * OF THIS SOFTWARE.
22  */
23 /**
24  * @brief   HomeScreen for uint test of Weston(Wayland) IVI plugins
25  *
26  * @date    Feb-08-2013
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <assert.h>
34 #include <poll.h>
35 #include <errno.h>
36 #include <sys/ioctl.h>
37 #include <sys/ipc.h>
38 #include <sys/msg.h>
39 #include <sys/time.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <signal.h>
43 #include <linux/input.h>
44 #include <wayland-client.h>
45 #include "ico_ivi_shell-client-protocol.h"
46 #include "ico_window_mgr-client-protocol.h"
47 #include "ico_input_mgr-client-protocol.h"
48 #include "test-common.h"
49
50 #define MAX_APPID   128
51 #define ICO_IVI_MAX_COORDINATE  16383
52
53 struct surface_name {
54     struct surface_name *next;
55     int     surfaceid;
56     int     pid;
57     char    appid[MAX_APPID];
58     int     x;
59     int     y;
60     int     width;
61     int     height;
62     int     visible;
63 };
64
65 #define MAX_CON_NAME    127
66
67 struct display {
68     struct wl_display *display;
69     struct wl_registry *registry;
70     struct wl_compositor *compositor;
71     struct wl_shell *shell;
72     struct ico_ivi_shell *ico_ivi_shell;
73     struct ico_window_mgr *ico_window_mgr;
74     struct ico_input_mgr_control *ico_input_mgr;
75     struct ico_input_mgr_device *ico_input_device;
76     struct ico_exinput *ico_exinput;
77     struct input *input;
78     struct output *output;
79     struct surface *surface;
80     struct surface_name *surface_name;
81     struct surface_name *bgsurface_name;
82     int    bg_created;
83     int    init_color;
84     int    init_width;
85     int    init_height;
86     int    surface_created;
87     int    surface_destroyed;
88     int    prompt;
89     int    visible_on_create;
90     char   connect[MAX_CON_NAME+1];
91 };
92
93 struct input {
94     struct display *display;
95     struct wl_seat *seat;
96     struct wl_pointer *pointer;
97     struct wl_keyboard *keyboard;
98     float x, y;
99     uint32_t button_mask;
100     struct surface *pointer_focus;
101     struct surface *keyboard_focus;
102     uint32_t last_key, last_key_state;
103 };
104
105 struct output {
106     struct display *display;
107     struct wl_output *output;
108     int x, y;
109     int width, height;
110 };
111
112 struct surface {
113     struct display *display;
114     struct wl_surface *surface;
115     struct wl_shell_surface *shell_surface;
116     struct output *output;
117     EGLDisplay  dpy;
118     EGLConfig   conf;
119     EGLContext  ctx;
120     EGLSurface  egl_surface;
121 };
122
123 static void clear_surface(struct display *display);
124
125 static void
126 pointer_handle_enter(void *data, struct wl_pointer *pointer,
127                      uint32_t serial, struct wl_surface *surface,
128                      wl_fixed_t x, wl_fixed_t y)
129 {
130     struct input *input = data;
131
132     input->pointer_focus = wl_surface_get_user_data(surface);
133     input->x = wl_fixed_to_double(x);
134     input->y = wl_fixed_to_double(y);
135     print_log("HOMESCREEN: got pointer enter (%d,%d), surface %p",
136               (int)input->x, (int)input->y, surface);
137 }
138
139 static void
140 pointer_handle_leave(void *data, struct wl_pointer *pointer,
141                      uint32_t serial, struct wl_surface *surface)
142 {
143     struct input *input = data;
144
145     input->pointer_focus = NULL;
146
147     print_log("HOMESCREEN: got pointer leave, surface %p", surface);
148 }
149
150 static void
151 pointer_handle_motion(void *data, struct wl_pointer *pointer,
152                       uint32_t time, wl_fixed_t x, wl_fixed_t y)
153 {
154     struct input *input = data;
155
156     input->x = wl_fixed_to_double(x);
157     input->y = wl_fixed_to_double(y);
158
159     print_log("HOMESCREEN: got pointer motion (%d,%d)", (int)input->x, (int)input->y);
160 }
161
162 static void
163 pointer_handle_button(void *data, struct wl_pointer *pointer,
164                       uint32_t serial, uint32_t time, uint32_t button, uint32_t state_w)
165 {
166     struct input *input = data;
167     uint32_t bit;
168     enum wl_pointer_button_state state = state_w;
169
170     bit = 1 << (button - BTN_LEFT);
171     if (state == WL_POINTER_BUTTON_STATE_PRESSED)
172         input->button_mask |= bit;
173     else
174         input->button_mask &= ~bit;
175     print_log("HOMESCREEN: got pointer button %u %u", button, state_w);
176 }
177
178 static void
179 pointer_handle_axis(void *data, struct wl_pointer *pointer,
180                     uint32_t time, uint32_t axis, wl_fixed_t value)
181 {
182     print_log("HOMESCREEN: got pointer axis %u %d", axis, value);
183 }
184
185 static void
186 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
187                        uint32_t format, int fd, uint32_t size)
188 {
189     close(fd);
190     print_log("HOMESCREEN: got keyboard keymap");
191 }
192
193 static void
194 keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
195                       uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
196 {
197     struct input *input = data;
198
199     input->keyboard_focus = wl_surface_get_user_data(surface);
200     print_log("HOMESCREEN: got keyboard enter, surface %p", surface);
201 }
202
203 static void
204 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
205                       uint32_t serial, struct wl_surface *surface)
206 {
207     struct input *input = data;
208
209     input->keyboard_focus = NULL;
210     print_log("HOMESCREEN: got keyboard leave, surface %p", surface);
211 }
212
213 static void
214 keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
215                     uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
216 {
217     struct input *input = data;
218
219     input->last_key = key;
220     input->last_key_state = state;
221
222     print_log("HOMESCREEN: got keyboard key %u %u", key, state);
223 }
224
225 static void
226 keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
227                           uint32_t serial, uint32_t mods_depressed,
228                           uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
229 {
230     print_log("HOMESCREEN: got keyboard modifier");
231 }
232
233 static const struct wl_pointer_listener pointer_listener = {
234     pointer_handle_enter,
235     pointer_handle_leave,
236     pointer_handle_motion,
237     pointer_handle_button,
238     pointer_handle_axis,
239 };
240
241 static const struct wl_keyboard_listener keyboard_listener = {
242     keyboard_handle_keymap,
243     keyboard_handle_enter,
244     keyboard_handle_leave,
245     keyboard_handle_key,
246     keyboard_handle_modifiers,
247 };
248
249 static void
250 seat_handle_capabilities(void *data, struct wl_seat *seat,
251                          enum wl_seat_capability caps)
252 {
253     struct input *input = data;
254
255     if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
256         input->pointer = wl_seat_get_pointer(seat);
257         wl_pointer_set_user_data(input->pointer, input);
258         wl_pointer_add_listener(input->pointer, &pointer_listener, input);
259     }
260     else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
261         wl_pointer_destroy(input->pointer);
262         input->pointer = NULL;
263     }
264
265     if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
266         input->keyboard = wl_seat_get_keyboard(seat);
267         wl_keyboard_set_user_data(input->keyboard, input);
268         wl_keyboard_add_listener(input->keyboard, &keyboard_listener, input);
269     }
270     else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
271         wl_keyboard_destroy(input->keyboard);
272         input->keyboard = NULL;
273     }
274 }
275
276 static const struct wl_seat_listener seat_listener = {
277     seat_handle_capabilities,
278 };
279
280 static void
281 surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *output)
282 {
283     struct surface *surface = data;
284
285     surface->output = wl_output_get_user_data(output);
286
287     print_log("HOMESCREEN: got surface enter, output %p", surface->output);
288 }
289
290 static void
291 surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *output)
292 {
293     struct surface *surface = data;
294
295     surface->output = NULL;
296
297     print_log("HOMESCREEN: got surface leave, output %p",
298               wl_output_get_user_data(output));
299 }
300
301 static const struct wl_surface_listener surface_listener = {
302     surface_enter,
303     surface_leave
304 };
305
306 static void
307 create_surface(struct display *display)
308 {
309     struct surface *surface;
310     int id;
311
312     surface = malloc(sizeof *surface);
313     assert(surface);
314     surface->display = display;
315     display->surface = surface;
316     surface->surface = wl_compositor_create_surface(display->compositor);
317     wl_surface_add_listener(surface->surface, &surface_listener, surface);
318
319     if (display->shell) {
320         surface->shell_surface =
321             wl_shell_get_shell_surface(display->shell, surface->surface);
322         if (surface->shell_surface) {
323             wl_shell_surface_set_toplevel(surface->shell_surface);
324         }
325     }
326     wl_display_flush(display->display);
327
328     id = wl_proxy_get_id((struct wl_proxy *) surface->surface);
329     print_log("HOMESCREEN: create surface = %d", id);
330
331     poll(NULL, 0, 100); /* Wait for next frame where we'll get events. */
332
333     wl_display_roundtrip(display->display);
334
335     surface->dpy = opengl_init(display->display, &surface->conf, &surface->ctx);
336     if (surface->dpy)   {
337         surface->egl_surface = opengl_create_window(display->display, surface->surface,
338                                                     surface->dpy, surface->conf,
339                                                     surface->ctx, display->init_width,
340                                                     display->init_height,
341                                                     display->init_color);
342         clear_surface(display);
343         print_log("HOMESCREEN: created egl_surface %08x", (int)surface->egl_surface);
344     }
345 }
346
347 static void
348 clear_surface(struct display *display)
349 {
350     if (! display->surface) {
351         create_surface(display);
352     }
353     else    {
354         opengl_clear_window(display->init_color);
355         opengl_swap_buffer(display->display,
356                            display->surface->dpy, display->surface->egl_surface);
357     }
358 }
359
360 static void
361 output_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
362                        int physical_width, int physical_height, int subpixel,
363                        const char *make, const char *model, int32_t transform)
364 {
365     struct output *output = data;
366
367     print_log("HOMESCREEN: Event[handle_geometry] x/y=%d/%d p.w/h=%d/%d trans=%d",
368               x, y, physical_width, physical_height, transform);
369
370     output->x = x;
371     output->y = y;
372 }
373
374 static void
375 output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
376                    int width, int height, int refresh)
377 {
378     struct output *output = data;
379
380     print_log("HOMESCREEN: Event[handle_mode] x/y=%d/%d flags=%08x refresh=%d",
381               width, height, flags, refresh);
382
383     if (flags & WL_OUTPUT_MODE_CURRENT) {
384         struct display  *display = output->display;
385
386         output->width = width;
387         output->height = height;
388
389         display->init_width = width;
390         display->init_height = height;
391
392         if (display->bgsurface_name)    {
393             ico_window_mgr_set_positionsize(display->ico_window_mgr,
394                                             display->bgsurface_name->surfaceid,
395                                             0, 0, width, height);
396         }
397         else if (display->bg_created == 0)  {
398             display->bg_created = 9;
399             create_surface(output->display);
400         }
401     }
402 }
403
404 static const struct wl_output_listener output_listener = {
405     output_handle_geometry,
406     output_handle_mode
407 };
408
409 static int
410 search_surface(struct display *display, const char *surfname)
411 {
412     struct surface_name     *p;
413
414     p = display->surface_name;
415     while (p)   {
416         if (strcmp(p->appid, surfname) == 0)    break;
417         p = p->next;
418     }
419
420     if (p)  {
421         return(p->surfaceid);
422     }
423     else    {
424         return(-1);
425     }
426 }
427
428 static struct surface_name *
429 search_surfacename(struct display *display, const char *surfname)
430 {
431     struct surface_name     *p;
432
433     p = display->surface_name;
434     while (p)   {
435         if (strcmp(p->appid, surfname) == 0)    break;
436         p = p->next;
437     }
438     return(p);
439 }
440
441 static struct surface_name *
442 search_surfaceid(struct display *display, const int surfaceid)
443 {
444     struct surface_name     *p;
445
446     p = display->surface_name;
447     while (p)   {
448         if (p->surfaceid == surfaceid)  {
449             return(p);
450         }
451         p = p->next;
452     }
453     return(NULL);
454 }
455
456 static void
457 window_created(void *data, struct ico_window_mgr *ico_window_mgr,
458                uint32_t surfaceid, int32_t pid, const char *appid)
459 {
460     struct display *display = data;
461     struct surface_name     *p;
462     struct surface_name     *fp;
463
464     display->surface_created = 1;
465     p = display->surface_name;
466     fp = NULL;
467     while (p)   {
468         if (p->surfaceid == (int)surfaceid) break;
469         fp = p;
470         p = p->next;
471     }
472     if (p)  {
473         print_log("HOMESCREEN: Event[window_created] surface=%08x(app=%s) exist",
474                   (int)surfaceid, appid);
475     }
476     else    {
477         print_log("HOMESCREEN: Event[window_created] new surface=%08x(app=%s)",
478                   (int)surfaceid, appid);
479         p = malloc(sizeof(struct surface_name));
480         if (! p)    {
481             return;
482         }
483         memset(p, 0, sizeof(struct surface_name));
484         if (fp) {
485             fp->next = p;
486         }
487         else    {
488             display->surface_name = p;
489         }
490     }
491     p->surfaceid = surfaceid;
492     p->pid = pid;
493     strncpy(p->appid, appid, MAX_APPID-1);
494
495     /* Set default size and show        */
496     if (p->width > 0)   {
497         ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
498                                         p->x, p->y, p->width, p->height);
499     }
500
501     print_log("HOMESCREEN: Created window[%08x] (app=%s)", (int)surfaceid, appid);
502
503     if (strncasecmp(appid, "test-homescreen", 15) == 0) {
504         display->bgsurface_name = p;
505         if (display->bg_created == 1)   {
506             display->bg_created = 9;
507             ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
508                                             0, 0, display->init_width, display->init_height);
509         }
510         ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 1, 0);
511         print_log("HOMESCREEN: Created window[%08x] (app=%s) Visible",
512                   (int)surfaceid, appid);
513         p->visible = 1;
514     }
515 }
516
517 static void
518 window_destroyed(void *data, struct ico_window_mgr *ico_window_mgr, uint32_t surfaceid)
519 {
520     struct display *display = data;
521     struct surface_name     *p;
522     struct surface_name     *fp;
523
524     display->surface_destroyed = 1;
525     p = search_surfaceid(display, (int)surfaceid);
526     if (! p)    {
527         print_log("HOMESCREEN: Event[window_destroyed] surface=%08x dose not exist",
528                   (int)surfaceid);
529     }
530     else    {
531         print_log("HOMESCREEN: Event[window_destroyed] surface=%08x", (int)surfaceid);
532         if (p == display->surface_name) {
533             display->surface_name = p->next;
534         }
535         else    {
536             fp = display->surface_name;
537             while (fp)  {
538                 if (fp->next == p)  {
539                     fp->next = p->next;
540                     break;
541                 }
542                 fp = fp->next;
543             }
544         }
545         free(p);
546     }
547 }
548
549 static void
550 window_visible(void *data, struct ico_window_mgr *ico_window_mgr,
551                uint32_t surfaceid, int32_t visible, int32_t raise, int32_t hint)
552 {
553     struct display *display = data;
554     struct surface_name     *p;
555
556     p = search_surfaceid(display, (int)surfaceid);
557     if (! p)    {
558         print_log("HOMESCREEN: Event[window_visible] surface=%08x dose not exist",
559                   (int)surfaceid);
560     }
561     else    {
562         print_log("HOMESCREEN: Event[window_visible] surface=%08x "
563                   "visible=%d raise=%d hint=%d", (int)surfaceid, visible, raise, hint);
564         p->visible = visible;
565         if (hint == 0)  {
566             ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, visible, 9);
567         }
568     }
569 }
570
571 static void
572 window_configure(void *data, struct ico_window_mgr *ico_window_mgr,
573                  uint32_t surfaceid, const char *appid, int32_t layer,
574                  int32_t x, int32_t y, int32_t width, int32_t height, int32_t hint)
575 {
576     struct display *display = data;
577     struct surface_name     *p;
578
579     print_log("HOMESCREEN: Event[window_configure] surface=%08x "
580               "app=%s x/y=%d/%d w/h=%d/%d hint=%d",
581               (int)surfaceid, appid, x, y, width, height, hint);
582
583     p = search_surfaceid(display, (int)surfaceid);
584     if (! p)    {
585         print_log("HOMESCREEN: Event[window_configure] surface=%08x(app=%s) new create",
586                   (int)surfaceid, appid);
587         window_created(data, ico_window_mgr, surfaceid, 0, appid);
588         p = search_surfaceid(display, (int)surfaceid);
589         if (! p)    {
590             print_log("HOMESCREEN: Event[window_configure] can not make table");
591             return;
592         }
593     }
594 }
595
596 static void
597 window_active(void *data, struct ico_window_mgr *ico_window_mgr,
598               uint32_t surfaceid, const uint32_t active)
599 {
600     print_log("HOMESCREEN: Event[window_active] surface=%08x acive=%d",
601               (int)surfaceid, (int)active);
602 }
603
604 static const struct ico_window_mgr_listener window_mgr_listener = {
605     window_created,
606     window_destroyed,
607     window_visible,
608     window_configure,
609     window_active
610 };
611
612 static void
613 cb_input_capabilities(void *data, struct ico_exinput *ico_exinput,
614                       const char *device, int32_t type, const char *swname, int32_t input,
615                       const char *codename, int32_t code)
616 {
617     print_log("HOMESCREEN: Event[input_capabilities] device=%s type=%d sw=%s input=%d "
618               "code=%s[%d]", device, type, swname, input, codename, code);
619 }
620
621 static void
622 cb_input_code(void *data, struct ico_exinput *ico_exinput,
623               const char *device, int32_t input, const char *codename, int32_t code)
624 {
625     print_log("HOMESCREEN: Event[input_code] device=%s input=%d code=%s[%d]",
626               device, input, codename, code);
627 }
628
629 static void
630 cb_input_input(void *data, struct ico_exinput *ico_exinput, uint32_t time,
631                const char *device, int32_t input, int32_t code, int32_t state)
632 {
633     print_log("HOMESCREEN: Event[input_input] device=%s input=%d code=%d state=%d",
634               device, input, code, state);
635 }
636
637 static const struct ico_exinput_listener exinput_listener = {
638     cb_input_capabilities,
639     cb_input_code,
640     cb_input_input
641 };
642
643 static void
644 handle_global(void *data, struct wl_registry *registry, uint32_t id,
645               const char *interface, uint32_t version)
646 {
647     struct display *display = data;
648     struct input *input;
649     struct output *output;
650
651     print_log("HOMESCREEN: handle_global: interface=<%s> id=%d", interface, (int)id);
652
653     if (strcmp(interface, "wl_compositor") == 0) {
654         display->compositor =
655             wl_registry_bind(display->registry, id, &wl_compositor_interface, 1);
656     }
657     else if (strcmp(interface, "wl_seat") == 0) {
658         input = calloc(1, sizeof *input);
659         input->display = display;
660         input->seat = wl_registry_bind(display->registry, id, &wl_seat_interface, 1);
661         input->pointer_focus = NULL;
662         input->keyboard_focus = NULL;
663
664         wl_seat_add_listener(input->seat, &seat_listener, input);
665         display->input = input;
666     }
667     else if (strcmp(interface, "wl_output") == 0) {
668         output = malloc(sizeof *output);
669         output->display = display;
670         output->output = wl_registry_bind(display->registry, id, &wl_output_interface, 1);
671         wl_output_add_listener(output->output, &output_listener, output);
672         display->output = output;
673
674         print_log("HOMESCREEN: created output global %p", display->output);
675     }
676     else if (strcmp(interface, "wl_shell") == 0)    {
677         display->shell =
678             wl_registry_bind(display->registry, id, &wl_shell_interface, 1);
679     }
680     else if (strcmp(interface, "ico_ivi_shell") == 0)   {
681         display->ico_ivi_shell =
682             wl_registry_bind(display->registry, id, &ico_ivi_shell_interface, 1);
683     }
684     else if (strcmp(interface, "ico_window_mgr") == 0)  {
685         display->ico_window_mgr =
686             wl_registry_bind(display->registry, id, &ico_window_mgr_interface, 1);
687         ico_window_mgr_add_listener(display->ico_window_mgr, &window_mgr_listener, display);
688         print_log("HOMESCREEN: created window_mgr global %p", display->ico_window_mgr);
689
690         ico_window_mgr_set_eventcb(display->ico_window_mgr, 1);
691     }
692     else if (strcmp(interface, "ico_input_mgr_control") == 0)   {
693         display->ico_input_mgr = wl_registry_bind(display->registry, id,
694                                                   &ico_input_mgr_control_interface, 1);
695         print_log("HOMESCREEN: created input_mgr global %p", display->ico_input_mgr);
696     }
697     else if (strcmp(interface, "ico_input_mgr_device") == 0)   {
698         display->ico_input_device = wl_registry_bind(display->registry, id,
699                                                      &ico_input_mgr_device_interface, 1);
700         print_log("HOMESCREEN: created input_device global %p", display->ico_input_device);
701     }
702     else if (strcmp(interface, "ico_exinput") == 0)   {
703         display->ico_exinput =
704             wl_registry_bind(display->registry, id, &ico_exinput_interface, 1);
705         ico_exinput_add_listener(display->ico_exinput, &exinput_listener, display);
706         print_log("HOMESCREEN: created exinput global %p", display->ico_exinput);
707
708         ico_window_mgr_set_eventcb(display->ico_window_mgr, 1);
709
710         display->bg_created = 1;
711         create_surface(display);
712     }
713 }
714
715 static const struct wl_registry_listener registry_listener = {
716     handle_global
717 };
718
719 static char *
720 skip_spaces(char *buf)
721 {
722     while ((*buf == ' ') || (*buf == '\t')) {
723         buf++;
724     }
725     return(buf);
726 }
727
728 static int
729 pars_command(char *buf, char *pt[], const int len)
730 {
731     char    *p;
732     int     narg;
733
734     memset(pt, 0, sizeof(int *)*10);
735     p = buf;
736     for (narg = 0; narg < len; narg++)  {
737         p = skip_spaces(p);
738         if (*p == 0)    break;
739         pt[narg] = p;
740         for (; *p; p++) {
741             if ((*p == ' ') || (*p == '\t') ||
742                 (*p == '=') || (*p == ',')) break;
743         }
744         if (*p == 0)    {
745             narg++;
746             break;
747         }
748         *p = 0;
749         p++;
750     }
751     return (narg);
752 }
753
754 static void
755 launch_app(struct display *display, char *buf)
756 {
757     char    sbuf[256];
758
759     display->surface_created = 0;
760     display->surface_destroyed = 0;
761     snprintf(sbuf, sizeof(sbuf)-1, "%s &", skip_spaces(buf));
762     if (system(sbuf) < 0)   {
763         print_log("HOMESCREEN: Can not launch application[%s]", sbuf);
764     }
765     else    {
766         sleep_with_wayland(display->display, 500);
767     }
768 }
769
770 static void
771 kill_app(struct display *display, char *buf)
772 {
773     char    *args[10];
774     int     narg;
775     struct surface_name     *p;
776     struct surface_name     *fp;
777
778     narg = pars_command(buf, args, 10);
779     if (narg >= 1)  {
780         p = search_surfacename(display, args[0]);
781         if (kill(p->pid, SIGINT) < 0)   {
782             print_log("HOMESCREEN: kill[%s.%d] Application dose not exist",
783                       p->appid, p->pid);
784         }
785         else    {
786             sleep_with_wayland(display->display, 300);
787             p = search_surfacename(display, args[0]);
788             if ((p != NULL) && (kill(p->pid, SIGTERM) >= 0))    {
789                 sleep_with_wayland(display->display, 200);
790                 p = search_surfacename(display, args[0]);
791                 if (p)  {
792                     kill(p->pid, SIGKILL);
793                     sleep_with_wayland(display->display, 200);
794                 }
795             }
796         }
797         p = search_surfacename(display, args[0]);
798         if (p)  {
799             if (p == display->surface_name) {
800                 display->surface_name = p->next;
801             }
802             else    {
803                 fp = display->surface_name;
804                 while (fp)  {
805                     if (fp->next == p)  {
806                         fp->next = p->next;
807                         break;
808                     }
809                 }
810             }
811             free(p);
812         }
813     }
814     else    {
815         print_log("HOMESCREEN: kill command[kill appid] has no argument");
816     }
817 }
818
819 static void
820 layer_surface(struct display *display, char *buf)
821 {
822     char    *args[10];
823     int     narg;
824     int     surfaceid;
825     int     layerid;
826
827     narg = pars_command(buf, args, 10);
828     if (narg >= 2)  {
829         surfaceid = search_surface(display, args[0]);
830         layerid = strtol(args[1], (char **)0, 0);
831         if ((surfaceid >= 0) && (layerid >= 0)) {
832             print_log("HOMESCREEN: set_window_layer(%s,%08x)",
833                       args[0], surfaceid, layerid);
834             ico_window_mgr_set_window_layer(display->ico_window_mgr, surfaceid, layerid);
835         }
836         else    {
837             print_log("HOMESCREEN: Unknown surface(%s) at layer command", args[0]);
838         }
839     }
840     else    {
841         print_log("HOMESCREEN: layer command[layer appid layerid] has no argument");
842     }
843 }
844
845 static void
846 positionsize_surface(struct display *display, char *buf)
847 {
848     char    *args[10];
849     int     narg;
850     int     surfaceid;
851     int     x, y, width, height;
852
853     narg = pars_command(buf, args, 10);
854     if (narg >= 5)  {
855         surfaceid = search_surface(display, args[0]);
856         x = strtol(args[1], (char **)0, 0);
857         y = strtol(args[2], (char **)0, 0);
858         width = strtol(args[3], (char **)0, 0);
859         height = strtol(args[4], (char **)0, 0);
860         if ((surfaceid >= 0) && (x >= 0) && (y >=0) && (width >= 0) && (height >=0))    {
861             print_log("HOMESCREEN: set_positionsize(%s,%08x,%d,%d,%d,%d)",
862                       args[0], surfaceid, x, y, width, height);
863             ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
864                                             x, y, width, height);
865         }
866         else    {
867             print_log("HOMESCREEN: Unknown surface(%s) at positionsize command", args[0]);
868         }
869     }
870     else    {
871         print_log("HOMESCREEN: positionsize command"
872                   "[positionsize appid x y width heigh] has no argument");
873     }
874 }
875
876 static void
877 move_surface(struct display *display, char *buf)
878 {
879     char    *args[10];
880     int     narg;
881     int     surfaceid;
882     int     x, y;
883
884     narg = pars_command(buf, args, 10);
885     if (narg >= 3)  {
886         surfaceid = search_surface(display, args[0]);
887         x = strtol(args[1], (char **)0, 0);
888         y = strtol(args[2], (char **)0, 0);
889         if ((surfaceid >= 0) && (x >= 0) && (y >=0))    {
890             print_log("HOMESCREEN: move(%s,%08x,%d,%d)", args[0], surfaceid, x, y);
891             ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
892                                             x, y,
893                                             ICO_IVI_MAX_COORDINATE+1,
894                                             ICO_IVI_MAX_COORDINATE+1);
895         }
896         else    {
897             print_log("HOMESCREEN: Unknown surface(%s) at move command", args[0]);
898         }
899     }
900     else    {
901         print_log("HOMESCREEN: move command[positionsize appid x y] has no argument");
902     }
903 }
904
905 static void
906 resize_surface(struct display *display, char *buf)
907 {
908     char    *args[10];
909     int     narg;
910     int     surfaceid;
911     int     width, height;
912
913     narg = pars_command(buf, args, 10);
914     if (narg >= 3)  {
915         surfaceid = search_surface(display, args[0]);
916         width = strtol(args[1], (char **)0, 0);
917         height = strtol(args[2], (char **)0, 0);
918         if ((surfaceid >= 0) && (width >= 0) && (height >=0))   {
919             print_log("HOMESCREEN: resize(%s,%08x,%d,%d)",
920                       args[0], surfaceid, width, height);
921             ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
922                                             ICO_IVI_MAX_COORDINATE+1,
923                                             ICO_IVI_MAX_COORDINATE+1, width, height);
924         }
925         else    {
926             print_log("HOMESCREEN: Unknown surface(%s) at resize command", args[0]);
927         }
928     }
929     else    {
930         print_log("HOMESCREEN: positionsize command"
931                   "[resize appid width heigh] has no argument");
932     }
933 }
934
935 static void
936 visible_surface(struct display *display, char *buf)
937 {
938     char    *args[10];
939     int     narg;
940     int     surfaceid;
941     int     visible;
942     int     raise;
943
944     narg = pars_command(buf, args, 10);
945     if (narg >= 3)  {
946         surfaceid = search_surface(display, args[0]);
947         visible = strtol(args[1], (char **)0, 0);
948         raise = strtol(args[2], (char **)0, 0);
949         if ((surfaceid >= 0) && (visible >= 0) && (raise >=0))  {
950             print_log("HOMESCREEN: visible(%s,%08x,%d,%d)",
951                       args[0], surfaceid, visible, raise);
952             ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, visible, raise);
953         }
954         else    {
955             print_log("HOMESCREEN: Unknown surface(%s) at visible command", args[0]);
956         }
957     }
958     else    {
959         print_log("HOMESCREEN: visible command[visible appid visible raise] "
960                   "has no argument");
961     }
962 }
963
964 static void
965 show_surface(struct display *display, char *buf, const int show)
966 {
967     char    *args[10];
968     int     narg;
969     int     surfaceid;
970
971     narg = pars_command(buf, args, 10);
972     if (narg >= 1)  {
973         surfaceid = search_surface(display, args[0]);
974         if (surfaceid >= 0) {
975             if (show)   {
976                 print_log("HOMESCREEN: show(%s,%08x)", args[0], surfaceid);
977                 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 1, 9);
978             }
979             else    {
980                 print_log("HOMESCREEN: hide(%s,%08x)", args[0], surfaceid);
981                 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 0, 9);
982             }
983         }
984         else    {
985             print_log("HOMESCREEN: Unknown surface(%s) at show/hide command", args[0]);
986         }
987     }
988     else    {
989         print_log("HOMESCREEN: show command[show/hide appid] has no argument");
990     }
991 }
992
993 static void
994 raise_surface(struct display *display, char *buf, const int raise)
995 {
996     char    *args[10];
997     int     narg;
998     int     surfaceid;
999
1000     narg = pars_command(buf, args, 10);
1001     if (narg >= 1)  {
1002         surfaceid = search_surface(display, args[0]);
1003         if (surfaceid >= 0) {
1004             if (raise)  {
1005                 print_log("HOMESCREEN: raise(%s,%08x)", args[0], surfaceid);
1006                 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 9, 1);
1007             }
1008             else    {
1009                 print_log("HOMESCREEN: lower(%s,%08x)", args[0], surfaceid);
1010                 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 9, 0);
1011             }
1012         }
1013         else    {
1014             print_log("HOMESCREEN: Unknown surface(%s) at raise/lower command", args[0]);
1015         }
1016     }
1017     else    {
1018         print_log("HOMESCREEN: show command[raise/lower appid] has no argument");
1019     }
1020 }
1021
1022 static void
1023 animation_surface(struct display *display, char *buf)
1024 {
1025     char    *args[10];
1026     int     narg;
1027     int     surfaceid;
1028
1029     narg = pars_command(buf, args, 10);
1030     if (narg >= 2)  {
1031         surfaceid = search_surface(display, args[0]);
1032         if (surfaceid >= 0) {
1033             print_log("HOMESCREEN: animation(%s,%08x,%d)", args[0], surfaceid, args[1]);
1034             ico_window_mgr_set_animation(display->ico_window_mgr, surfaceid, args[1]);
1035         }
1036         else    {
1037             print_log("HOMESCREEN: Unknown surface(%s) at animation command", args[0]);
1038         }
1039     }
1040     else    {
1041         print_log("HOMESCREEN: animation command"
1042                   "[animation appid animation] has no argument");
1043     }
1044 }
1045
1046 static void
1047 visible_layer(struct display *display, char *buf)
1048 {
1049     char    *args[10];
1050     int     narg;
1051     int     layer;
1052     int     visible;
1053
1054     narg = pars_command(buf, args, 10);
1055     if (narg >= 2)  {
1056         layer = strtol(args[0], (char **)0, 0);
1057         visible = strtol(args[1], (char **)0, 0);
1058         ico_window_mgr_set_layer_visible(display->ico_window_mgr, layer, visible);
1059     }
1060     else    {
1061         print_log("HOMESCREEN: layer_visible command"
1062                   "[layer_visible layer visible] has no argument");
1063     }
1064 }
1065
1066 static void
1067 input_add(struct display *display, char *buf)
1068 {
1069     char    *args[10];
1070     int     narg;
1071     int     input;
1072     int     fix;
1073
1074     narg = pars_command(buf, args, 10);
1075     if (narg >= 3)  {
1076         input = strtol(args[1], (char **)0, 0);
1077         if (narg >= 4)  {
1078             fix = strtol(args[3], (char **)0, 0);
1079         }
1080         else    {
1081             fix = 0;
1082         }
1083         if ((input >= 0) && (fix >=0))  {
1084             print_log("HOMESCREEN: input_add(%s.%d to %s[%d])",
1085                       args[0], input, args[2], fix);
1086             ico_input_mgr_control_add_input_app(display->ico_input_mgr,
1087                                                 args[2], args[0], input, fix);
1088         }
1089         else    {
1090             print_log("HOMESCREEN: Unknown input(%s) at input_add command", args[1]);
1091         }
1092     }
1093     else    {
1094         print_log("HOMESCREEN: input_add command[input_add device inputId appid fix] "
1095                   "has no argument");
1096     }
1097 }
1098
1099 static void
1100 input_del(struct display *display, char *buf)
1101 {
1102     char    *args[10];
1103     int     narg;
1104     int     input;
1105     char    wk1[32], wk2[32];
1106
1107     narg = pars_command(buf, args, 10);
1108     if (narg >= 3)  {
1109         input = strtol(args[1], (char **)0, 0);
1110         if (args[0][0] == '@')  {
1111             wk1[0] = 0;
1112             args[0] = wk1;
1113         }
1114         if (args[2][0] == '@')  {
1115             wk2[0] = 0;
1116             args[2] = wk2;
1117         }
1118         print_log("HOMESCREEN: input_del(%s.%d to %s)", args[0], input, args[2]);
1119         ico_input_mgr_control_del_input_app(display->ico_input_mgr,
1120                                             args[2], args[0], input);
1121     }
1122     else    {
1123         print_log("HOMESCREEN: input_del command[input_del device inputId appid] "
1124                   "has no argument");
1125     }
1126 }
1127
1128 static void
1129 input_conf(struct display *display, char *buf)
1130 {
1131     char    *args[10];
1132     int     narg;
1133     int     type;
1134     int     input;
1135     int     code;
1136     char    wk1[32], wk2[32];
1137
1138     narg = pars_command(buf, args, 10);
1139     if (narg >= 4)  {
1140         type = strtol(args[1], (char **)0, 0);
1141         input = strtol(args[3], (char **)0, 0);
1142         if (narg >= 6)  {
1143             code = strtol(args[5], (char **)0, 0);
1144         }
1145         else    {
1146             code = 0;
1147             args[4] = wk1;
1148             strcpy(wk1, args[2]);
1149             args[5] = wk2;
1150             strcpy(wk2, "0");
1151         }
1152         if ((type >= 0) && (input >= 0) && (code >=0))  {
1153             ico_input_mgr_device_configure_input(display->ico_input_device, args[0], type,
1154                                                  args[2], input, args[4], code);
1155         }
1156         else    {
1157             print_log("HOMESCREEN: Unknown type(%s),input(%s) or code(%s) "
1158                       "at input_conf command", args[1], args[3], args[5]);
1159         }
1160     }
1161     else    {
1162         print_log("HOMESCREEN: input_conf command[input_conf device type swname input "
1163                   "codename code] has no argument");
1164     }
1165 }
1166
1167 static void
1168 input_code(struct display *display, char *buf)
1169 {
1170     char    *args[10];
1171     int     narg;
1172     int     input;
1173     int     code;
1174
1175     narg = pars_command(buf, args, 10);
1176     if (narg >= 4)  {
1177         input = strtol(args[1], (char **)0, 0);
1178         code = strtol(args[3], (char **)0, 0);
1179         if ((input >= 0) && (code >= 0))    {
1180             ico_input_mgr_device_configure_code(display->ico_input_device, args[0], input,
1181                                                 args[2], code);
1182         }
1183         else    {
1184             print_log("HOMESCREEN: Unknown input(%s) or code(%s) "
1185                       "at input_code command", args[1], args[3]);
1186         }
1187     }
1188     else    {
1189         print_log("HOMESCREEN: input_conf command[input_code device input codename code] "
1190                   "has no argument");
1191     }
1192 }
1193
1194 static void
1195 input_sw(struct display *display, char *buf)
1196 {
1197     char    *args[10];
1198     int     narg;
1199     int     timems;
1200     int     input;
1201     int     code;
1202     int     state;
1203     struct timeval  stv;
1204
1205     narg = pars_command(buf, args, 10);
1206     if (narg >= 4)  {
1207         input = strtol(args[1], (char **)0, 0);
1208         code = strtol(args[2], (char **)0, 0);
1209         state = strtol(args[3], (char **)0, 0);
1210         if ((input >= 0) && (state >= 0))   {
1211             gettimeofday(&stv, (struct timezone *)NULL);
1212             timems = (stv.tv_sec % 1000) * 1000 + (stv.tv_usec / 1000);
1213             ico_input_mgr_device_input_event(display->ico_input_device,
1214                                              timems, args[0], input, code, state);
1215         }
1216         else    {
1217             print_log("HOMESCREEN: Unknown input(%s),code(%s) or state(%s) "
1218                       "at input_sw command", args[1], args[2], args[3]);
1219         }
1220     }
1221     else    {
1222         print_log("HOMESCREEN: input_sw command[input_sw device input code, state] "
1223                   "has no argument");
1224     }
1225 }
1226
1227 static void
1228 send_event(const char *cmd)
1229 {
1230     static int  nmqinfo = 0;
1231     static struct   {
1232         int     mqkey;
1233         int     mqid;
1234     }           mqinfo[10];
1235     int     mqkey;
1236     int     mqid;
1237     struct {
1238         long    mtype;
1239         char    buf[240];
1240     }       mqbuf;
1241     int     pt, i;
1242
1243     if (cmd == NULL)    {
1244         return;
1245     }
1246     mqkey = 0;
1247     for (pt = 0; cmd[pt]; pt++) {
1248         if ((cmd[pt] >= '0') && (cmd[pt] <= '9'))   {
1249             mqkey = mqkey * 10 + cmd[pt] - '0';
1250         }
1251         else    {
1252             break;
1253         }
1254     }
1255     for (; cmd[pt] == ' '; pt++)    ;
1256
1257     if (mqkey <= 0) {
1258         mqkey = 5551;
1259         pt = 0;
1260     }
1261     for (i = 0; i < nmqinfo; i++)   {
1262         if (mqinfo[i].mqkey == mqkey)   {
1263             mqid = mqinfo[i].mqid;
1264             break;
1265         }
1266     }
1267     if (i >= nmqinfo)   {
1268         if (nmqinfo >= 10)  {
1269             fprintf(stderr, "HOMESCREEN: message queue(%d) overflow\n", mqkey);
1270             return;
1271         }
1272         mqid = msgget(mqkey, 0);
1273         if (mqid < 0)   {
1274             fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) get error[%d]\n",
1275                     mqkey, mqkey, errno);
1276             return;
1277         }
1278         mqinfo[nmqinfo].mqkey = mqkey;
1279         mqinfo[nmqinfo].mqid = mqid;
1280         nmqinfo ++;
1281     }
1282
1283     memset(&mqbuf, 0, sizeof(mqbuf));
1284     mqbuf.mtype = 1;
1285     strncpy(mqbuf.buf, &cmd[pt], sizeof(mqbuf)-sizeof(long));
1286
1287     if (msgsnd(mqid, &mqbuf, sizeof(mqbuf)-sizeof(long), 0) < 0)    {
1288         fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) send error[%d]\n",
1289                 mqkey, mqkey, errno);
1290         return;
1291     }
1292 }
1293
1294 /*
1295  * Main Program
1296  *
1297  *   usage:
1298  *     test-homescreen < test-case-data-file > test-result-output
1299  */
1300 int main(int argc, char *argv[])
1301 {
1302     struct display *display;
1303     char buf[256];
1304     int ret, fd;
1305     int msec;
1306
1307     display = malloc(sizeof *display);
1308     assert(display);
1309     memset((char *)display, 0, sizeof *display);
1310
1311     display->init_width = 640;
1312     display->init_height = 480;
1313     display->init_color = 0xFF304010;
1314
1315     for (fd = 1; fd < argc; fd++)   {
1316         if (argv[fd][0] == '-') {
1317             if (strncasecmp(argv[fd], "-visible=", 9) == 0) {
1318                 display->visible_on_create = argv[fd][9] & 1;
1319             }
1320             else if (strncasecmp(argv[fd], "-display=", 9) == 0)    {
1321                 strncpy(display->connect, &argv[fd][9], MAX_CON_NAME);
1322             }
1323             else if (strncasecmp(argv[fd], "-prompt=", 8) == 0) {
1324                 display->prompt = argv[fd][8] & 1;
1325             }
1326         }
1327     }
1328
1329     if (display->connect[0])    {
1330         display->display = wl_display_connect(display->connect);
1331     }
1332     else    {
1333         display->display = wl_display_connect(NULL);
1334     }
1335     assert(display->display);
1336
1337     display->registry = wl_display_get_registry(display->display);
1338     wl_registry_add_listener(display->registry,
1339                  &registry_listener, display);
1340     wl_display_dispatch(display->display);
1341
1342     fd = 0;
1343
1344     while (1) {
1345         sleep_with_wayland(display->display, 20);
1346         if (display->prompt)    {
1347             printf("HOMESCREEN: "); fflush(stdout);
1348         }
1349         ret = getdata(display->ico_window_mgr, "HOMESCREEN: ", fd, buf, sizeof(buf));
1350         if (ret < 0) {
1351             fprintf(stderr, "HOMESCREEN: read error: fd %d, %m\n", fd);
1352             return -1;
1353         }
1354         if (ret == 0)   continue;
1355         wl_display_flush(display->display);
1356
1357         if ((strncasecmp(buf, "bye", 3) == 0) ||
1358             (strncasecmp(buf, "quit", 4) == 0) ||
1359             (strncasecmp(buf, "end", 3) == 0))  {
1360             /* Exit, end of test            */
1361             return 0;
1362         }
1363         else if (strncasecmp(buf, "launch", 6) == 0) {
1364             /* Launch test application      */
1365             launch_app(display, &buf[6]);
1366         }
1367         else if (strncasecmp(buf, "kill", 4) == 0) {
1368             /* Launch test application      */
1369             kill_app(display, &buf[4]);
1370         }
1371         else if (strncasecmp(buf, "layer_visible", 13) == 0) {
1372             /* Change layer visiblety       */
1373             visible_layer(display, &buf[13]);
1374         }
1375         else if (strncasecmp(buf, "layer", 5) == 0) {
1376             /* layer change surface window  */
1377             layer_surface(display, &buf[5]);
1378         }
1379         else if (strncasecmp(buf, "positionsize", 12) == 0) {
1380             /* Move and Ressize surface window*/
1381             positionsize_surface(display, &buf[12]);
1382         }
1383         else if (strncasecmp(buf, "move", 4) == 0) {
1384             /* Move surface window          */
1385             move_surface(display, &buf[4]);
1386         }
1387         else if (strncasecmp(buf, "resize", 6) == 0) {
1388             /* Resize surface window        */
1389             resize_surface(display, &buf[6]);
1390         }
1391         else if (strncasecmp(buf, "visible", 7) == 0) {
1392             /* Visible and Raise surface window*/
1393             visible_surface(display, &buf[7]);
1394         }
1395         else if (strncasecmp(buf, "show", 4) == 0) {
1396             /* Show/Hide surface window     */
1397             show_surface(display, &buf[4], 1);
1398         }
1399         else if (strncasecmp(buf, "hide", 4) == 0) {
1400             /* Show/Hide surface window     */
1401             show_surface(display, &buf[4], 0);
1402         }
1403         else if (strncasecmp(buf, "raise", 5) == 0) {
1404             /* Raise/Lower surface window   */
1405             raise_surface(display, &buf[5], 1);
1406         }
1407         else if (strncasecmp(buf, "lower", 5) == 0) {
1408             /* Raise/Lower surface window   */
1409             raise_surface(display, &buf[5], 0);
1410         }
1411         else if (strncasecmp(buf, "animation", 9) == 0) {
1412             /* Set animation surface window*/
1413             animation_surface(display, &buf[9]);
1414         }
1415         else if (strncasecmp(buf, "input_add", 9) == 0) {
1416             /* Set input switch to application */
1417             input_add(display, &buf[9]);
1418         }
1419         else if (strncasecmp(buf, "input_del", 9) == 0) {
1420             /* Reset input switch to application*/
1421             input_del(display, &buf[9]);
1422         }
1423         else if (strncasecmp(buf, "input_conf", 10) == 0) {
1424             /* input switch configuration       */
1425             input_conf(display, &buf[10]);
1426         }
1427         else if (strncasecmp(buf, "input_code", 10) == 0) {
1428             /* input code configuration         */
1429             input_code(display, &buf[10]);
1430         }
1431         else if (strncasecmp(buf, "input_sw", 8) == 0) {
1432             /* input switch event               */
1433             input_sw(display, &buf[8]);
1434         }
1435         else if (strncasecmp(buf, "sleep", 5) == 0) {
1436             /* Sleep                            */
1437             msec = sec_str_2_value(&buf[6]);
1438             sleep_with_wayland(display->display, msec);
1439         }
1440         else if (strncasecmp(buf, "waitcreate", 10) == 0) {
1441             /* Wait surface create              */
1442             msec = sec_str_2_value(&buf[11]);
1443             wait_with_wayland(display->display, msec, &display->surface_created);
1444         }
1445         else if (strncasecmp(buf, "waitdestroy", 11) == 0) {
1446             /* Wait surface destrpy             */
1447             msec = sec_str_2_value(&buf[12]);
1448             wait_with_wayland(display->display, msec, &display->surface_destroyed);
1449         }
1450         else if (strncasecmp(buf, "event", 5) == 0) {
1451             /* Send touch panel event to Weston */
1452             send_event(&buf[6]);
1453         }
1454         else {
1455             print_log("HOMESCREEN: unknown command[%s]", buf);
1456             return -1;
1457         }
1458     }
1459
1460     print_log("HOMESCREEN: end");
1461
1462     send_event(NULL);
1463
1464     return(0);
1465 }
1466