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,
1035                                                                                  ICO_WINDOW_MGR_ANIMATION_CHANGE_VISIBLE, args[1]);
1036         }
1037         else    {
1038             print_log("HOMESCREEN: Unknown surface(%s) at animation command", args[0]);
1039         }
1040     }
1041     else    {
1042         print_log("HOMESCREEN: animation command"
1043                   "[animation appid animation] has no argument");
1044     }
1045 }
1046
1047 static void
1048 visible_layer(struct display *display, char *buf)
1049 {
1050     char    *args[10];
1051     int     narg;
1052     int     layer;
1053     int     visible;
1054
1055     narg = pars_command(buf, args, 10);
1056     if (narg >= 2)  {
1057         layer = strtol(args[0], (char **)0, 0);
1058         visible = strtol(args[1], (char **)0, 0);
1059         ico_window_mgr_set_layer_visible(display->ico_window_mgr, layer, visible);
1060     }
1061     else    {
1062         print_log("HOMESCREEN: layer_visible command"
1063                   "[layer_visible layer visible] has no argument");
1064     }
1065 }
1066
1067 static void
1068 input_add(struct display *display, char *buf)
1069 {
1070     char    *args[10];
1071     int     narg;
1072     int     input;
1073     int     fix;
1074
1075     narg = pars_command(buf, args, 10);
1076     if (narg >= 3)  {
1077         input = strtol(args[1], (char **)0, 0);
1078         if (narg >= 4)  {
1079             fix = strtol(args[3], (char **)0, 0);
1080         }
1081         else    {
1082             fix = 0;
1083         }
1084         if ((input >= 0) && (fix >=0))  {
1085             print_log("HOMESCREEN: input_add(%s.%d to %s[%d])",
1086                       args[0], input, args[2], fix);
1087             ico_input_mgr_control_add_input_app(display->ico_input_mgr,
1088                                                 args[2], args[0], input, fix);
1089         }
1090         else    {
1091             print_log("HOMESCREEN: Unknown input(%s) at input_add command", args[1]);
1092         }
1093     }
1094     else    {
1095         print_log("HOMESCREEN: input_add command[input_add device inputId appid fix] "
1096                   "has no argument");
1097     }
1098 }
1099
1100 static void
1101 input_del(struct display *display, char *buf)
1102 {
1103     char    *args[10];
1104     int     narg;
1105     int     input;
1106     char    wk1[32], wk2[32];
1107
1108     narg = pars_command(buf, args, 10);
1109     if (narg >= 3)  {
1110         input = strtol(args[1], (char **)0, 0);
1111         if (args[0][0] == '@')  {
1112             wk1[0] = 0;
1113             args[0] = wk1;
1114         }
1115         if (args[2][0] == '@')  {
1116             wk2[0] = 0;
1117             args[2] = wk2;
1118         }
1119         print_log("HOMESCREEN: input_del(%s.%d to %s)", args[0], input, args[2]);
1120         ico_input_mgr_control_del_input_app(display->ico_input_mgr,
1121                                             args[2], args[0], input);
1122     }
1123     else    {
1124         print_log("HOMESCREEN: input_del command[input_del device inputId appid] "
1125                   "has no argument");
1126     }
1127 }
1128
1129 static void
1130 input_conf(struct display *display, char *buf)
1131 {
1132     char    *args[10];
1133     int     narg;
1134     int     type;
1135     int     input;
1136     int     code;
1137     char    wk1[32], wk2[32];
1138
1139     narg = pars_command(buf, args, 10);
1140     if (narg >= 4)  {
1141         type = strtol(args[1], (char **)0, 0);
1142         input = strtol(args[3], (char **)0, 0);
1143         if (narg >= 6)  {
1144             code = strtol(args[5], (char **)0, 0);
1145         }
1146         else    {
1147             code = 0;
1148             args[4] = wk1;
1149             strcpy(wk1, args[2]);
1150             args[5] = wk2;
1151             strcpy(wk2, "0");
1152         }
1153         if ((type >= 0) && (input >= 0) && (code >=0))  {
1154             ico_input_mgr_device_configure_input(display->ico_input_device, args[0], type,
1155                                                  args[2], input, args[4], code);
1156         }
1157         else    {
1158             print_log("HOMESCREEN: Unknown type(%s),input(%s) or code(%s) "
1159                       "at input_conf command", args[1], args[3], args[5]);
1160         }
1161     }
1162     else    {
1163         print_log("HOMESCREEN: input_conf command[input_conf device type swname input "
1164                   "codename code] has no argument");
1165     }
1166 }
1167
1168 static void
1169 input_code(struct display *display, char *buf)
1170 {
1171     char    *args[10];
1172     int     narg;
1173     int     input;
1174     int     code;
1175
1176     narg = pars_command(buf, args, 10);
1177     if (narg >= 4)  {
1178         input = strtol(args[1], (char **)0, 0);
1179         code = strtol(args[3], (char **)0, 0);
1180         if ((input >= 0) && (code >= 0))    {
1181             ico_input_mgr_device_configure_code(display->ico_input_device, args[0], input,
1182                                                 args[2], code);
1183         }
1184         else    {
1185             print_log("HOMESCREEN: Unknown input(%s) or code(%s) "
1186                       "at input_code command", args[1], args[3]);
1187         }
1188     }
1189     else    {
1190         print_log("HOMESCREEN: input_conf command[input_code device input codename code] "
1191                   "has no argument");
1192     }
1193 }
1194
1195 static void
1196 input_sw(struct display *display, char *buf)
1197 {
1198     char    *args[10];
1199     int     narg;
1200     int     timems;
1201     int     input;
1202     int     code;
1203     int     state;
1204     struct timeval  stv;
1205
1206     narg = pars_command(buf, args, 10);
1207     if (narg >= 4)  {
1208         input = strtol(args[1], (char **)0, 0);
1209         code = strtol(args[2], (char **)0, 0);
1210         state = strtol(args[3], (char **)0, 0);
1211         if ((input >= 0) && (state >= 0))   {
1212             gettimeofday(&stv, (struct timezone *)NULL);
1213             timems = (stv.tv_sec % 1000) * 1000 + (stv.tv_usec / 1000);
1214             ico_input_mgr_device_input_event(display->ico_input_device,
1215                                              timems, args[0], input, code, state);
1216         }
1217         else    {
1218             print_log("HOMESCREEN: Unknown input(%s),code(%s) or state(%s) "
1219                       "at input_sw command", args[1], args[2], args[3]);
1220         }
1221     }
1222     else    {
1223         print_log("HOMESCREEN: input_sw command[input_sw device input code, state] "
1224                   "has no argument");
1225     }
1226 }
1227
1228 static void
1229 send_event(const char *cmd)
1230 {
1231     static int  nmqinfo = 0;
1232     static struct   {
1233         int     mqkey;
1234         int     mqid;
1235     }           mqinfo[10];
1236     int     mqkey;
1237     int     mqid;
1238     struct {
1239         long    mtype;
1240         char    buf[240];
1241     }       mqbuf;
1242     int     pt, i;
1243
1244     if (cmd == NULL)    {
1245         return;
1246     }
1247     mqkey = 0;
1248     for (pt = 0; cmd[pt]; pt++) {
1249         if ((cmd[pt] >= '0') && (cmd[pt] <= '9'))   {
1250             mqkey = mqkey * 10 + cmd[pt] - '0';
1251         }
1252         else    {
1253             break;
1254         }
1255     }
1256     for (; cmd[pt] == ' '; pt++)    ;
1257
1258     if (mqkey <= 0) {
1259         mqkey = 5551;
1260         pt = 0;
1261     }
1262     for (i = 0; i < nmqinfo; i++)   {
1263         if (mqinfo[i].mqkey == mqkey)   {
1264             mqid = mqinfo[i].mqid;
1265             break;
1266         }
1267     }
1268     if (i >= nmqinfo)   {
1269         if (nmqinfo >= 10)  {
1270             fprintf(stderr, "HOMESCREEN: message queue(%d) overflow\n", mqkey);
1271             return;
1272         }
1273         mqid = msgget(mqkey, 0);
1274         if (mqid < 0)   {
1275             fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) get error[%d]\n",
1276                     mqkey, mqkey, errno);
1277             return;
1278         }
1279         mqinfo[nmqinfo].mqkey = mqkey;
1280         mqinfo[nmqinfo].mqid = mqid;
1281         nmqinfo ++;
1282     }
1283
1284     memset(&mqbuf, 0, sizeof(mqbuf));
1285     mqbuf.mtype = 1;
1286     strncpy(mqbuf.buf, &cmd[pt], sizeof(mqbuf)-sizeof(long));
1287
1288     if (msgsnd(mqid, &mqbuf, sizeof(mqbuf)-sizeof(long), 0) < 0)    {
1289         fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) send error[%d]\n",
1290                 mqkey, mqkey, errno);
1291         return;
1292     }
1293 }
1294
1295 /*
1296  * Main Program
1297  *
1298  *   usage:
1299  *     test-homescreen < test-case-data-file > test-result-output
1300  */
1301 int main(int argc, char *argv[])
1302 {
1303     struct display *display;
1304     char buf[256];
1305     int ret, fd;
1306     int msec;
1307
1308     display = malloc(sizeof *display);
1309     assert(display);
1310     memset((char *)display, 0, sizeof *display);
1311
1312     display->init_width = 640;
1313     display->init_height = 480;
1314     display->init_color = 0xFF304010;
1315
1316     for (fd = 1; fd < argc; fd++)   {
1317         if (argv[fd][0] == '-') {
1318             if (strncasecmp(argv[fd], "-visible=", 9) == 0) {
1319                 display->visible_on_create = argv[fd][9] & 1;
1320             }
1321             else if (strncasecmp(argv[fd], "-display=", 9) == 0)    {
1322                 strncpy(display->connect, &argv[fd][9], MAX_CON_NAME);
1323             }
1324             else if (strncasecmp(argv[fd], "-prompt=", 8) == 0) {
1325                 display->prompt = argv[fd][8] & 1;
1326             }
1327         }
1328     }
1329
1330     if (display->connect[0])    {
1331         display->display = wl_display_connect(display->connect);
1332     }
1333     else    {
1334         display->display = wl_display_connect(NULL);
1335     }
1336     assert(display->display);
1337
1338     display->registry = wl_display_get_registry(display->display);
1339     wl_registry_add_listener(display->registry,
1340                  &registry_listener, display);
1341     wl_display_dispatch(display->display);
1342
1343     fd = 0;
1344
1345     while (1) {
1346         sleep_with_wayland(display->display, 20);
1347         if (display->prompt)    {
1348             printf("HOMESCREEN: "); fflush(stdout);
1349         }
1350         ret = getdata(display->ico_window_mgr, "HOMESCREEN: ", fd, buf, sizeof(buf));
1351         if (ret < 0) {
1352             fprintf(stderr, "HOMESCREEN: read error: fd %d, %m\n", fd);
1353             return -1;
1354         }
1355         if (ret == 0)   continue;
1356         wl_display_flush(display->display);
1357
1358         if ((strncasecmp(buf, "bye", 3) == 0) ||
1359             (strncasecmp(buf, "quit", 4) == 0) ||
1360             (strncasecmp(buf, "end", 3) == 0))  {
1361             /* Exit, end of test            */
1362             return 0;
1363         }
1364         else if (strncasecmp(buf, "launch", 6) == 0) {
1365             /* Launch test application      */
1366             launch_app(display, &buf[6]);
1367         }
1368         else if (strncasecmp(buf, "kill", 4) == 0) {
1369             /* Launch test application      */
1370             kill_app(display, &buf[4]);
1371         }
1372         else if (strncasecmp(buf, "layer_visible", 13) == 0) {
1373             /* Change layer visiblety       */
1374             visible_layer(display, &buf[13]);
1375         }
1376         else if (strncasecmp(buf, "layer", 5) == 0) {
1377             /* layer change surface window  */
1378             layer_surface(display, &buf[5]);
1379         }
1380         else if (strncasecmp(buf, "positionsize", 12) == 0) {
1381             /* Move and Ressize surface window*/
1382             positionsize_surface(display, &buf[12]);
1383         }
1384         else if (strncasecmp(buf, "move", 4) == 0) {
1385             /* Move surface window          */
1386             move_surface(display, &buf[4]);
1387         }
1388         else if (strncasecmp(buf, "resize", 6) == 0) {
1389             /* Resize surface window        */
1390             resize_surface(display, &buf[6]);
1391         }
1392         else if (strncasecmp(buf, "visible", 7) == 0) {
1393             /* Visible and Raise surface window*/
1394             visible_surface(display, &buf[7]);
1395         }
1396         else if (strncasecmp(buf, "show", 4) == 0) {
1397             /* Show/Hide surface window     */
1398             show_surface(display, &buf[4], 1);
1399         }
1400         else if (strncasecmp(buf, "hide", 4) == 0) {
1401             /* Show/Hide surface window     */
1402             show_surface(display, &buf[4], 0);
1403         }
1404         else if (strncasecmp(buf, "raise", 5) == 0) {
1405             /* Raise/Lower surface window   */
1406             raise_surface(display, &buf[5], 1);
1407         }
1408         else if (strncasecmp(buf, "lower", 5) == 0) {
1409             /* Raise/Lower surface window   */
1410             raise_surface(display, &buf[5], 0);
1411         }
1412         else if (strncasecmp(buf, "animation", 9) == 0) {
1413             /* Set animation surface window*/
1414             animation_surface(display, &buf[9]);
1415         }
1416         else if (strncasecmp(buf, "input_add", 9) == 0) {
1417             /* Set input switch to application */
1418             input_add(display, &buf[9]);
1419         }
1420         else if (strncasecmp(buf, "input_del", 9) == 0) {
1421             /* Reset input switch to application*/
1422             input_del(display, &buf[9]);
1423         }
1424         else if (strncasecmp(buf, "input_conf", 10) == 0) {
1425             /* input switch configuration       */
1426             input_conf(display, &buf[10]);
1427         }
1428         else if (strncasecmp(buf, "input_code", 10) == 0) {
1429             /* input code configuration         */
1430             input_code(display, &buf[10]);
1431         }
1432         else if (strncasecmp(buf, "input_sw", 8) == 0) {
1433             /* input switch event               */
1434             input_sw(display, &buf[8]);
1435         }
1436         else if (strncasecmp(buf, "sleep", 5) == 0) {
1437             /* Sleep                            */
1438             msec = sec_str_2_value(&buf[6]);
1439             sleep_with_wayland(display->display, msec);
1440         }
1441         else if (strncasecmp(buf, "waitcreate", 10) == 0) {
1442             /* Wait surface create              */
1443             msec = sec_str_2_value(&buf[11]);
1444             wait_with_wayland(display->display, msec, &display->surface_created);
1445         }
1446         else if (strncasecmp(buf, "waitdestroy", 11) == 0) {
1447             /* Wait surface destrpy             */
1448             msec = sec_str_2_value(&buf[12]);
1449             wait_with_wayland(display->display, msec, &display->surface_destroyed);
1450         }
1451         else if (strncasecmp(buf, "event", 5) == 0) {
1452             /* Send touch panel event to Weston */
1453             send_event(&buf[6]);
1454         }
1455         else {
1456             print_log("HOMESCREEN: unknown command[%s]", buf);
1457             return -1;
1458         }
1459     }
1460
1461     print_log("HOMESCREEN: end");
1462
1463     send_event(NULL);
1464
1465     return(0);
1466 }
1467