2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 TOYOTA MOTOR CORPORATION
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.
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
24 * @brief HomeScreen for unit test of Weston(Wayland) IVI plugins
36 #include <sys/ioctl.h>
40 #include <sys/types.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"
52 struct surface_name *next;
55 char appid[MAX_APPID];
64 #define MAX_CON_NAME 127
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;
76 struct output *output;
77 struct surface *surface;
78 struct surface_name *surface_name;
79 struct surface_name *bgsurface_name;
85 int surface_destroyed;
87 int visible_on_create;
88 char connect[MAX_CON_NAME+1];
92 struct display *display;
94 struct wl_pointer *pointer;
95 struct wl_keyboard *keyboard;
98 struct surface *pointer_focus;
99 struct surface *keyboard_focus;
100 uint32_t last_key, last_key_state;
104 struct display *display;
105 struct wl_output *output;
111 struct display *display;
112 struct wl_surface *surface;
113 struct wl_shell_surface *shell_surface;
114 struct output *output;
118 EGLSurface egl_surface;
121 static void clear_surface(struct display *display);
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)
128 struct input *input = data;
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);
138 pointer_handle_leave(void *data, struct wl_pointer *pointer,
139 uint32_t serial, struct wl_surface *surface)
141 struct input *input = data;
143 input->pointer_focus = NULL;
145 print_log("HOMESCREEN: got pointer leave, surface %p", surface);
149 pointer_handle_motion(void *data, struct wl_pointer *pointer,
150 uint32_t time, wl_fixed_t x, wl_fixed_t y)
152 struct input *input = data;
154 input->x = wl_fixed_to_double(x);
155 input->y = wl_fixed_to_double(y);
157 print_log("HOMESCREEN: got pointer motion (%d,%d)", (int)input->x, (int)input->y);
161 pointer_handle_button(void *data, struct wl_pointer *pointer,
162 uint32_t serial, uint32_t time, uint32_t button, uint32_t state_w)
164 struct input *input = data;
166 enum wl_pointer_button_state state = state_w;
168 bit = 1 << (button - BTN_LEFT);
169 if (state == WL_POINTER_BUTTON_STATE_PRESSED)
170 input->button_mask |= bit;
172 input->button_mask &= ~bit;
173 print_log("HOMESCREEN: got pointer button %u %u", button, state_w);
177 pointer_handle_axis(void *data, struct wl_pointer *pointer,
178 uint32_t time, uint32_t axis, wl_fixed_t value)
180 print_log("HOMESCREEN: got pointer axis %u %d", axis, value);
184 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
185 uint32_t format, int fd, uint32_t size)
188 print_log("HOMESCREEN: got keyboard keymap");
192 keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
193 uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
195 struct input *input = data;
197 input->keyboard_focus = wl_surface_get_user_data(surface);
198 print_log("HOMESCREEN: got keyboard enter, surface %p", surface);
202 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
203 uint32_t serial, struct wl_surface *surface)
205 struct input *input = data;
207 input->keyboard_focus = NULL;
208 print_log("HOMESCREEN: got keyboard leave, surface %p", surface);
212 keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
213 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
215 struct input *input = data;
217 input->last_key = key;
218 input->last_key_state = state;
220 print_log("HOMESCREEN: got keyboard key %u %u", key, state);
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)
228 print_log("HOMESCREEN: got keyboard modifier");
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,
239 static const struct wl_keyboard_listener keyboard_listener = {
240 keyboard_handle_keymap,
241 keyboard_handle_enter,
242 keyboard_handle_leave,
244 keyboard_handle_modifiers,
248 seat_handle_capabilities(void *data, struct wl_seat *seat,
249 enum wl_seat_capability caps)
251 struct input *input = data;
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);
258 else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
259 wl_pointer_destroy(input->pointer);
260 input->pointer = NULL;
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);
268 else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
269 wl_keyboard_destroy(input->keyboard);
270 input->keyboard = NULL;
274 static const struct wl_seat_listener seat_listener = {
275 seat_handle_capabilities,
279 surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *output)
281 struct surface *surface = data;
283 surface->output = wl_output_get_user_data(output);
285 print_log("HOMESCREEN: got surface enter, output %p", surface->output);
289 surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *output)
291 struct surface *surface = data;
293 surface->output = NULL;
295 print_log("HOMESCREEN: got surface leave, output %p",
296 wl_output_get_user_data(output));
299 static const struct wl_surface_listener surface_listener = {
305 create_surface(struct display *display, const char *title)
307 struct surface *surface;
310 surface = malloc(sizeof *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);
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);
325 wl_display_flush(display->display);
327 id = wl_proxy_get_id((struct wl_proxy *) surface->surface);
328 print_log("HOMESCREEN: create surface = %d", id);
330 poll(NULL, 0, 100); /* Wait for next frame where we'll get events. */
332 wl_display_roundtrip(display->display);
334 surface->dpy = opengl_init(display->display, &surface->conf, &surface->ctx);
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);
347 clear_surface(struct display *display)
349 if (! display->surface) {
350 create_surface(display, "HomeScreen-BG");
353 opengl_clear_window(display->init_color);
354 opengl_swap_buffer(display->display,
355 display->surface->dpy, display->surface->egl_surface);
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)
364 struct output *output = data;
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);
374 output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
375 int width, int height, int refresh)
377 struct output *output = data;
379 print_log("HOMESCREEN: Event[handle_mode] %08x x/y=%d/%d flags=%08x refresh=%d",
380 (int)wl_output, width, height, flags, refresh);
382 if (flags & WL_OUTPUT_MODE_CURRENT) {
383 struct display *display = output->display;
385 output->width = width;
386 output->height = height;
388 display->init_width = width;
389 display->init_height = height;
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);
396 else if (display->bg_created == 0) {
397 display->bg_created = 9;
398 create_surface(display, "HomeScreen-BG");
403 static const struct wl_output_listener output_listener = {
404 output_handle_geometry,
409 search_surface(struct display *display, const char *surfname)
411 struct surface_name *p;
413 p = display->surface_name;
415 if (strcmp(p->appid, surfname) == 0) break;
420 return(p->surfaceid);
427 static struct surface_name *
428 search_surfacename(struct display *display, const char *surfname)
430 struct surface_name *p;
432 p = display->surface_name;
434 if (strcmp(p->appid, surfname) == 0) break;
438 print_log("HOMESCREEN: app(%s) dose not exist", surfname);
443 static struct surface_name *
444 search_surfaceid(struct display *display, const int surfaceid)
446 struct surface_name *p;
448 p = display->surface_name;
450 if (p->surfaceid == surfaceid) {
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)
462 struct display *display = data;
463 struct surface_name *p;
464 struct surface_name *fp;
466 display->surface_created = 1;
467 p = display->surface_name;
470 if (p->surfaceid == (int)surfaceid) break;
475 print_log("HOMESCREEN: Event[window_created] surface=%08x(app=%s,name=%s) exist",
476 (int)surfaceid, appid, winname);
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));
485 memset(p, 0, sizeof(struct surface_name));
490 display->surface_name = p;
493 p->surfaceid = surfaceid;
495 strncpy(p->appid, appid, MAX_APPID-1);
497 /* Set default size and show */
499 ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
500 0, p->x, p->y, p->width, p->height, 0);
503 print_log("HOMESCREEN: Created window[%08x] (app=%s)", (int)surfaceid, appid);
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,
511 display->init_width, display->init_height, 0);
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);
521 window_name(void *data, struct ico_window_mgr *ico_window_mgr,
522 uint32_t surfaceid, const char *winname)
524 print_log("HOMESCREEN: Window Name[%08x] (name=%s)", (int)surfaceid, winname);
528 window_destroyed(void *data, struct ico_window_mgr *ico_window_mgr, uint32_t surfaceid)
530 struct display *display = data;
531 struct surface_name *p;
532 struct surface_name *fp;
534 display->surface_destroyed = 1;
535 p = search_surfaceid(display, (int)surfaceid);
537 print_log("HOMESCREEN: Event[window_destroyed] surface=%08x dose not exist",
541 print_log("HOMESCREEN: Event[window_destroyed] surface=%08x", (int)surfaceid);
542 if (p == display->surface_name) {
543 display->surface_name = p->next;
546 fp = display->surface_name;
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)
563 struct display *display = data;
564 struct surface_name *p;
566 p = search_surfaceid(display, (int)surfaceid);
568 print_log("HOMESCREEN: Event[window_visible] surface=%08x dose not exist",
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;
576 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid,
577 visible, ICO_WINDOW_MGR_V_NOCHANGE, 0);
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)
587 struct display *display = data;
588 struct surface_name *p;
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);
594 p = search_surfaceid(display, (int)surfaceid);
596 print_log("HOMESCREEN: Event[window_configure] surface=%08x dose not exist",
605 window_layer_visible(void *data, struct ico_window_mgr *ico_window_mgr,
606 uint32_t layer, int32_t visible)
608 print_log("HOMESCREEN: Event[layer_visible]layer=%x visible=%d",
609 (int)layer, visible);
613 window_active(void *data, struct ico_window_mgr *ico_window_mgr,
614 uint32_t surfaceid, const int32_t active)
616 print_log("HOMESCREEN: Event[window_active] surface=%08x acive=%d",
617 (int)surfaceid, (int)active);
621 window_surfaces(void *data, struct ico_window_mgr *ico_window_mgr,
622 const char *appid, struct wl_array *surfaces)
624 print_log("HOMESCREEN: Event[app_surfaces] app=%s", appid);
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)
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);
636 static const struct ico_window_mgr_listener window_mgr_listener = {
643 window_layer_visible,
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)
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);
658 cb_input_code(void *data, struct ico_exinput *ico_exinput,
659 const char *device, int32_t input, const char *codename, int32_t code)
661 print_log("HOMESCREEN: Event[input_code] device=%s input=%d code=%s[%d]",
662 device, input, codename, code);
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)
669 print_log("HOMESCREEN: Event[input_input] device=%s input=%d code=%d state=%d",
670 device, input, code, state);
673 static const struct ico_exinput_listener exinput_listener = {
674 cb_input_capabilities,
680 handle_global(void *data, struct wl_registry *registry, uint32_t id,
681 const char *interface, uint32_t version)
683 struct display *display = data;
685 struct output *output;
687 print_log("HOMESCREEN: handle_global: interface=<%s> id=%d", interface, (int)id);
689 if (strcmp(interface, "wl_compositor") == 0) {
690 display->compositor =
691 wl_registry_bind(display->registry, id, &wl_compositor_interface, 1);
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;
700 wl_seat_add_listener(input->seat, &seat_listener, input);
701 display->input = input;
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;
710 print_log("HOMESCREEN: created output global %p", display->output);
712 else if (strcmp(interface, "wl_shell") == 0) {
714 wl_registry_bind(display->registry, id, &wl_shell_interface, 1);
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);
722 ico_window_mgr_declare_manager(display->ico_window_mgr, 1);
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);
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);
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);
740 ico_window_mgr_declare_manager(display->ico_window_mgr, 1);
742 display->bg_created = 1;
743 create_surface(display, "HomeScreen-BG");
747 static const struct wl_registry_listener registry_listener = {
752 skip_spaces(char *buf)
754 while ((*buf == ' ') || (*buf == '\t')) {
761 pars_command(char *buf, char *pt[], const int len)
766 memset(pt, 0, sizeof(int *)*10);
768 for (narg = 0; narg < len; narg++) {
773 if ((*p == ' ') || (*p == '\t') ||
774 (*p == '=') || (*p == ',')) break;
787 launch_app(struct display *display, char *buf)
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);
798 sleep_with_wayland(display->display, 500);
803 kill_app(struct display *display, char *buf)
807 struct surface_name *p;
808 struct surface_name *fp;
810 narg = pars_command(buf, args, 10);
812 p = search_surfacename(display, args[0]);
814 print_log("HOMESCREEN: kill[%s] Application dose not exist", args[0]);
816 else if (kill(p->pid, SIGINT) < 0) {
817 print_log("HOMESCREEN: kill[%s.%d] Application dose not exist",
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]);
827 kill(p->pid, SIGKILL);
828 sleep_with_wayland(display->display, 200);
832 p = search_surfacename(display, args[0]);
834 if (p == display->surface_name) {
835 display->surface_name = p->next;
838 fp = display->surface_name;
850 print_log("HOMESCREEN: kill command[kill appid] has no argument");
855 layer_surface(struct display *display, char *buf)
862 narg = pars_command(buf, args, 10);
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);
872 print_log("HOMESCREEN: Unknown surface(%s) at layer command", args[0]);
876 print_log("HOMESCREEN: layer command[layer appid layerid] has no argument");
881 positionsize_surface(struct display *display, char *buf)
884 struct surface_name *p;
887 int x, y, width, height;
891 narg = pars_command(buf, args, 10);
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);
900 node = strtol(args[5], (char **)0, 0);
909 anima = strtol(args[6], (char **)0, 0);
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);
918 print_log("HOMESCREEN: Unknown surface(%s) at positionsize command", args[0]);
922 print_log("HOMESCREEN: positionsize command"
923 "[positionsize appid x y width heigh node anima] has no argument");
928 move_surface(struct display *display, char *buf)
931 struct surface_name *p;
938 narg = pars_command(buf, args, 10);
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);
945 node = strtol(args[3], (char **)0, 0);
954 anima = strtol(args[4], (char **)0, 0);
957 if ((surfaceid >= 0) && (x >= 0) && (y >=0)) {
958 print_log("HOMESCREEN: move(%s,%08x,%d.%d,%d anima=%d)", args[0], surfaceid,
960 ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
962 ICO_WINDOW_MGR_V_NOCHANGE,
963 ICO_WINDOW_MGR_V_NOCHANGE, anima);
966 print_log("HOMESCREEN: Unknown surface(%s) at move command", args[0]);
970 print_log("HOMESCREEN: move command[positionsize appid x y node anima] has no argument");
975 resize_surface(struct display *display, char *buf)
978 struct surface_name *p;
985 narg = pars_command(buf, args, 10);
987 surfaceid = search_surface(display, args[0]);
988 p = search_surfacename(display, args[0]);
992 width = strtol(args[1], (char **)0, 0);
993 height = strtol(args[2], (char **)0, 0);
995 anima = strtol(args[3], (char **)0, 0);
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);
1006 print_log("HOMESCREEN: Unknown surface(%s) at resize command", args[0]);
1010 print_log("HOMESCREEN: positionsize command"
1011 "[resize appid width heigh anima] has no argument");
1016 visible_surface(struct display *display, char *buf)
1025 narg = pars_command(buf, args, 10);
1027 surfaceid = search_surface(display, args[0]);
1028 visible = strtol(args[1], (char **)0, 0);
1029 raise = strtol(args[2], (char **)0, 0);
1031 anima = strtol(args[3], (char **)0, 0);
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);
1040 print_log("HOMESCREEN: Unknown surface(%s) at visible command", args[0]);
1044 print_log("HOMESCREEN: visible command[visible appid visible raise] "
1050 show_surface(struct display *display, char *buf, const int show)
1057 narg = pars_command(buf, args, 10);
1059 surfaceid = search_surface(display, args[0]);
1061 anima = strtol(args[1], (char **)0, 0);
1063 if (surfaceid >= 0) {
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);
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);
1076 print_log("HOMESCREEN: Unknown surface(%s) at show/hide command", args[0]);
1080 print_log("HOMESCREEN: show command[show/hide appid anima] has no argument");
1085 raise_surface(struct display *display, char *buf, const int raise)
1092 narg = pars_command(buf, args, 10);
1094 surfaceid = search_surface(display, args[0]);
1096 anima = strtol(args[1], (char **)0, 0);
1098 if (surfaceid >= 0) {
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);
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);
1111 print_log("HOMESCREEN: Unknown surface(%s) at raise/lower command", args[0]);
1115 print_log("HOMESCREEN: show command[raise/lower appid anima] has no argument");
1120 animation_surface(struct display *display, char *buf)
1127 narg = pars_command(buf, args, 10);
1129 surfaceid = search_surface(display, args[0]);
1130 if (surfaceid >= 0) {
1132 time = strtol(args[2], (char **)0, 0);
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,
1143 print_log("HOMESCREEN: Unknown surface(%s) at animation command", args[0]);
1147 print_log("HOMESCREEN: animation command"
1148 "[animation appid animation time] has no argument");
1153 visible_layer(struct display *display, char *buf)
1160 narg = pars_command(buf, args, 10);
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);
1167 print_log("HOMESCREEN: layer_visible command"
1168 "[layer_visible layer visible] has no argument");
1173 input_add(struct display *display, char *buf)
1180 narg = pars_command(buf, args, 10);
1182 input = strtol(args[1], (char **)0, 0);
1184 fix = strtol(args[3], (char **)0, 0);
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);
1196 print_log("HOMESCREEN: Unknown input(%s) at input_add command", args[1]);
1200 print_log("HOMESCREEN: input_add command[input_add device inputId appid fix] "
1206 input_del(struct display *display, char *buf)
1211 char wk1[32], wk2[32];
1213 narg = pars_command(buf, args, 10);
1215 input = strtol(args[1], (char **)0, 0);
1216 if (args[0][0] == '@') {
1220 if (args[2][0] == '@') {
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);
1229 print_log("HOMESCREEN: input_del command[input_del device inputId appid] "
1235 input_conf(struct display *display, char *buf)
1242 char wk1[32], wk2[32];
1244 narg = pars_command(buf, args, 10);
1246 type = strtol(args[1], (char **)0, 0);
1247 input = strtol(args[3], (char **)0, 0);
1249 code = strtol(args[5], (char **)0, 0);
1254 strcpy(wk1, args[2]);
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);
1263 print_log("HOMESCREEN: Unknown type(%s),input(%s) or code(%s) "
1264 "at input_conf command", args[1], args[3], args[5]);
1268 print_log("HOMESCREEN: input_conf command[input_conf device type swname input "
1269 "codename code] has no argument");
1274 input_code(struct display *display, char *buf)
1281 narg = pars_command(buf, args, 10);
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,
1290 print_log("HOMESCREEN: Unknown input(%s) or code(%s) "
1291 "at input_code command", args[1], args[3]);
1295 print_log("HOMESCREEN: input_conf command[input_code device input codename code] "
1301 input_sw(struct display *display, char *buf)
1311 narg = pars_command(buf, args, 10);
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);
1323 print_log("HOMESCREEN: Unknown input(%s),code(%s) or state(%s) "
1324 "at input_sw command", args[1], args[2], args[3]);
1328 print_log("HOMESCREEN: input_sw command[input_sw device input code, state] "
1334 send_event(const char *cmd)
1336 static int nmqinfo = 0;
1353 for (pt = 0; cmd[pt]; pt++) {
1354 if ((cmd[pt] >= '0') && (cmd[pt] <= '9')) {
1355 mqkey = mqkey * 10 + cmd[pt] - '0';
1361 for (; cmd[pt] == ' '; pt++) ;
1367 for (i = 0; i < nmqinfo; i++) {
1368 if (mqinfo[i].mqkey == mqkey) {
1369 mqid = mqinfo[i].mqid;
1374 if (nmqinfo >= 10) {
1375 fprintf(stderr, "HOMESCREEN: message queue(%d) overflow\n", mqkey);
1378 mqid = msgget(mqkey, 0);
1380 fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) get error[%d]\n",
1381 mqkey, mqkey, errno);
1384 mqinfo[nmqinfo].mqkey = mqkey;
1385 mqinfo[nmqinfo].mqid = mqid;
1389 memset(&mqbuf, 0, sizeof(mqbuf));
1391 strncpy(mqbuf.buf, &cmd[pt], sizeof(mqbuf)-sizeof(long));
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);
1404 * test-homescreen < test-case-data-file > test-result-output
1406 int main(int argc, char *argv[])
1408 struct display *display;
1413 display = malloc(sizeof *display);
1415 memset((char *)display, 0, sizeof *display);
1417 display->init_width = 640;
1418 display->init_height = 480;
1419 display->init_color = 0xFF304010;
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;
1426 else if (strncasecmp(argv[fd], "-display=", 9) == 0) {
1427 strncpy(display->connect, &argv[fd][9], MAX_CON_NAME);
1429 else if (strncasecmp(argv[fd], "-prompt=", 8) == 0) {
1430 display->prompt = argv[fd][8] & 1;
1435 if (display->connect[0]) {
1436 display->display = wl_display_connect(display->connect);
1439 display->display = wl_display_connect(NULL);
1441 assert(display->display);
1443 display->registry = wl_display_get_registry(display->display);
1444 wl_registry_add_listener(display->registry,
1445 ®istry_listener, display);
1446 wl_display_dispatch(display->display);
1451 sleep_with_wayland(display->display, 20);
1452 if (display->prompt) {
1453 printf("HOMESCREEN: "); fflush(stdout);
1455 ret = getdata(display->ico_window_mgr, "HOMESCREEN: ", fd, buf, sizeof(buf));
1457 fprintf(stderr, "HOMESCREEN: read error: fd %d, %m\n", fd);
1460 if (ret == 0) continue;
1461 wl_display_flush(display->display);
1463 if ((strncasecmp(buf, "bye", 3) == 0) ||
1464 (strncasecmp(buf, "quit", 4) == 0) ||
1465 (strncasecmp(buf, "end", 3) == 0)) {
1466 /* Exit, end of test */
1469 else if (strncasecmp(buf, "launch", 6) == 0) {
1470 /* Launch test application */
1471 launch_app(display, &buf[6]);
1473 else if (strncasecmp(buf, "kill", 4) == 0) {
1474 /* Launch test application */
1475 kill_app(display, &buf[4]);
1477 else if (strncasecmp(buf, "layer_visible", 13) == 0) {
1478 /* Change layer visiblety */
1479 visible_layer(display, &buf[13]);
1481 else if (strncasecmp(buf, "layer", 5) == 0) {
1482 /* layer change surface window */
1483 layer_surface(display, &buf[5]);
1485 else if (strncasecmp(buf, "positionsize", 12) == 0) {
1486 /* Move and Ressize surface window*/
1487 positionsize_surface(display, &buf[12]);
1489 else if (strncasecmp(buf, "move", 4) == 0) {
1490 /* Move surface window */
1491 move_surface(display, &buf[4]);
1493 else if (strncasecmp(buf, "resize", 6) == 0) {
1494 /* Resize surface window */
1495 resize_surface(display, &buf[6]);
1497 else if (strncasecmp(buf, "visible", 7) == 0) {
1498 /* Visible and Raise surface window*/
1499 visible_surface(display, &buf[7]);
1501 else if (strncasecmp(buf, "show", 4) == 0) {
1502 /* Show/Hide surface window */
1503 show_surface(display, &buf[4], 1);
1505 else if (strncasecmp(buf, "hide", 4) == 0) {
1506 /* Show/Hide surface window */
1507 show_surface(display, &buf[4], 0);
1509 else if (strncasecmp(buf, "raise", 5) == 0) {
1510 /* Raise/Lower surface window */
1511 raise_surface(display, &buf[5], 1);
1513 else if (strncasecmp(buf, "lower", 5) == 0) {
1514 /* Raise/Lower surface window */
1515 raise_surface(display, &buf[5], 0);
1517 else if (strncasecmp(buf, "animation", 9) == 0) {
1518 /* Set animation surface window*/
1519 animation_surface(display, &buf[9]);
1521 else if (strncasecmp(buf, "input_add", 9) == 0) {
1522 /* Set input switch to application */
1523 input_add(display, &buf[9]);
1525 else if (strncasecmp(buf, "input_del", 9) == 0) {
1526 /* Reset input switch to application*/
1527 input_del(display, &buf[9]);
1529 else if (strncasecmp(buf, "input_conf", 10) == 0) {
1530 /* input switch configuration */
1531 input_conf(display, &buf[10]);
1533 else if (strncasecmp(buf, "input_code", 10) == 0) {
1534 /* input code configuration */
1535 input_code(display, &buf[10]);
1537 else if (strncasecmp(buf, "input_sw", 8) == 0) {
1538 /* input switch event */
1539 input_sw(display, &buf[8]);
1541 else if (strncasecmp(buf, "sleep", 5) == 0) {
1543 msec = sec_str_2_value(&buf[6]);
1544 sleep_with_wayland(display->display, msec);
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);
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);
1556 else if (strncasecmp(buf, "event", 5) == 0) {
1557 /* Send touch panel event to Weston */
1558 send_event(&buf[6]);
1561 print_log("HOMESCREEN: unknown command[%s]", buf);
1566 print_log("HOMESCREEN: end");