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