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 uint 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_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"
51 #define ICO_IVI_MAX_COORDINATE 16383
54 struct surface_name *next;
57 char appid[MAX_APPID];
65 #define MAX_CON_NAME 127
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;
78 struct output *output;
79 struct surface *surface;
80 struct surface_name *surface_name;
81 struct surface_name *bgsurface_name;
87 int surface_destroyed;
89 int visible_on_create;
90 char connect[MAX_CON_NAME+1];
94 struct display *display;
96 struct wl_pointer *pointer;
97 struct wl_keyboard *keyboard;
100 struct surface *pointer_focus;
101 struct surface *keyboard_focus;
102 uint32_t last_key, last_key_state;
106 struct display *display;
107 struct wl_output *output;
113 struct display *display;
114 struct wl_surface *surface;
115 struct wl_shell_surface *shell_surface;
116 struct output *output;
120 EGLSurface egl_surface;
123 static void clear_surface(struct display *display);
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)
130 struct input *input = data;
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);
140 pointer_handle_leave(void *data, struct wl_pointer *pointer,
141 uint32_t serial, struct wl_surface *surface)
143 struct input *input = data;
145 input->pointer_focus = NULL;
147 print_log("HOMESCREEN: got pointer leave, surface %p", surface);
151 pointer_handle_motion(void *data, struct wl_pointer *pointer,
152 uint32_t time, wl_fixed_t x, wl_fixed_t y)
154 struct input *input = data;
156 input->x = wl_fixed_to_double(x);
157 input->y = wl_fixed_to_double(y);
159 print_log("HOMESCREEN: got pointer motion (%d,%d)", (int)input->x, (int)input->y);
163 pointer_handle_button(void *data, struct wl_pointer *pointer,
164 uint32_t serial, uint32_t time, uint32_t button, uint32_t state_w)
166 struct input *input = data;
168 enum wl_pointer_button_state state = state_w;
170 bit = 1 << (button - BTN_LEFT);
171 if (state == WL_POINTER_BUTTON_STATE_PRESSED)
172 input->button_mask |= bit;
174 input->button_mask &= ~bit;
175 print_log("HOMESCREEN: got pointer button %u %u", button, state_w);
179 pointer_handle_axis(void *data, struct wl_pointer *pointer,
180 uint32_t time, uint32_t axis, wl_fixed_t value)
182 print_log("HOMESCREEN: got pointer axis %u %d", axis, value);
186 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
187 uint32_t format, int fd, uint32_t size)
190 print_log("HOMESCREEN: got keyboard keymap");
194 keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
195 uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
197 struct input *input = data;
199 input->keyboard_focus = wl_surface_get_user_data(surface);
200 print_log("HOMESCREEN: got keyboard enter, surface %p", surface);
204 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
205 uint32_t serial, struct wl_surface *surface)
207 struct input *input = data;
209 input->keyboard_focus = NULL;
210 print_log("HOMESCREEN: got keyboard leave, surface %p", surface);
214 keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
215 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
217 struct input *input = data;
219 input->last_key = key;
220 input->last_key_state = state;
222 print_log("HOMESCREEN: got keyboard key %u %u", key, state);
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)
230 print_log("HOMESCREEN: got keyboard modifier");
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,
241 static const struct wl_keyboard_listener keyboard_listener = {
242 keyboard_handle_keymap,
243 keyboard_handle_enter,
244 keyboard_handle_leave,
246 keyboard_handle_modifiers,
250 seat_handle_capabilities(void *data, struct wl_seat *seat,
251 enum wl_seat_capability caps)
253 struct input *input = data;
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);
260 else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
261 wl_pointer_destroy(input->pointer);
262 input->pointer = NULL;
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);
270 else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
271 wl_keyboard_destroy(input->keyboard);
272 input->keyboard = NULL;
276 static const struct wl_seat_listener seat_listener = {
277 seat_handle_capabilities,
281 surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *output)
283 struct surface *surface = data;
285 surface->output = wl_output_get_user_data(output);
287 print_log("HOMESCREEN: got surface enter, output %p", surface->output);
291 surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *output)
293 struct surface *surface = data;
295 surface->output = NULL;
297 print_log("HOMESCREEN: got surface leave, output %p",
298 wl_output_get_user_data(output));
301 static const struct wl_surface_listener surface_listener = {
307 create_surface(struct display *display)
309 struct surface *surface;
312 surface = malloc(sizeof *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);
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);
326 wl_display_flush(display->display);
328 id = wl_proxy_get_id((struct wl_proxy *) surface->surface);
329 print_log("HOMESCREEN: create surface = %d", id);
331 poll(NULL, 0, 100); /* Wait for next frame where we'll get events. */
333 wl_display_roundtrip(display->display);
335 surface->dpy = opengl_init(display->display, &surface->conf, &surface->ctx);
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);
348 clear_surface(struct display *display)
350 if (! display->surface) {
351 create_surface(display);
354 opengl_clear_window(display->init_color);
355 opengl_swap_buffer(display->display,
356 display->surface->dpy, display->surface->egl_surface);
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)
365 struct output *output = data;
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);
375 output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
376 int width, int height, int refresh)
378 struct output *output = data;
380 print_log("HOMESCREEN: Event[handle_mode] x/y=%d/%d flags=%08x refresh=%d",
381 width, height, flags, refresh);
383 if (flags & WL_OUTPUT_MODE_CURRENT) {
384 struct display *display = output->display;
386 output->width = width;
387 output->height = height;
389 display->init_width = width;
390 display->init_height = height;
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);
397 else if (display->bg_created == 0) {
398 display->bg_created = 9;
399 create_surface(output->display);
404 static const struct wl_output_listener output_listener = {
405 output_handle_geometry,
410 search_surface(struct display *display, const char *surfname)
412 struct surface_name *p;
414 p = display->surface_name;
416 if (strcmp(p->appid, surfname) == 0) break;
421 return(p->surfaceid);
428 static struct surface_name *
429 search_surfacename(struct display *display, const char *surfname)
431 struct surface_name *p;
433 p = display->surface_name;
435 if (strcmp(p->appid, surfname) == 0) break;
441 static struct surface_name *
442 search_surfaceid(struct display *display, const int surfaceid)
444 struct surface_name *p;
446 p = display->surface_name;
448 if (p->surfaceid == surfaceid) {
457 window_created(void *data, struct ico_window_mgr *ico_window_mgr,
458 uint32_t surfaceid, int32_t pid, const char *appid)
460 struct display *display = data;
461 struct surface_name *p;
462 struct surface_name *fp;
464 display->surface_created = 1;
465 p = display->surface_name;
468 if (p->surfaceid == (int)surfaceid) break;
473 print_log("HOMESCREEN: Event[window_created] surface=%08x(app=%s) exist",
474 (int)surfaceid, appid);
477 print_log("HOMESCREEN: Event[window_created] new surface=%08x(app=%s)",
478 (int)surfaceid, appid);
479 p = malloc(sizeof(struct surface_name));
483 memset(p, 0, sizeof(struct surface_name));
488 display->surface_name = p;
491 p->surfaceid = surfaceid;
493 strncpy(p->appid, appid, MAX_APPID-1);
495 /* Set default size and show */
497 ico_window_mgr_set_positionsize(display->ico_window_mgr, surfaceid,
498 p->x, p->y, p->width, p->height);
501 print_log("HOMESCREEN: Created window[%08x] (app=%s)", (int)surfaceid, appid);
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);
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);
518 window_destroyed(void *data, struct ico_window_mgr *ico_window_mgr, uint32_t surfaceid)
520 struct display *display = data;
521 struct surface_name *p;
522 struct surface_name *fp;
524 display->surface_destroyed = 1;
525 p = search_surfaceid(display, (int)surfaceid);
527 print_log("HOMESCREEN: Event[window_destroyed] surface=%08x dose not exist",
531 print_log("HOMESCREEN: Event[window_destroyed] surface=%08x", (int)surfaceid);
532 if (p == display->surface_name) {
533 display->surface_name = p->next;
536 fp = display->surface_name;
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)
553 struct display *display = data;
554 struct surface_name *p;
556 p = search_surfaceid(display, (int)surfaceid);
558 print_log("HOMESCREEN: Event[window_visible] surface=%08x dose not exist",
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;
566 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, visible, 9);
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)
576 struct display *display = data;
577 struct surface_name *p;
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);
583 p = search_surfaceid(display, (int)surfaceid);
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);
590 print_log("HOMESCREEN: Event[window_configure] can not make table");
597 window_active(void *data, struct ico_window_mgr *ico_window_mgr,
598 uint32_t surfaceid, const uint32_t active)
600 print_log("HOMESCREEN: Event[window_active] surface=%08x acive=%d",
601 (int)surfaceid, (int)active);
604 static const struct ico_window_mgr_listener window_mgr_listener = {
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)
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);
622 cb_input_code(void *data, struct ico_exinput *ico_exinput,
623 const char *device, int32_t input, const char *codename, int32_t code)
625 print_log("HOMESCREEN: Event[input_code] device=%s input=%d code=%s[%d]",
626 device, input, codename, code);
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)
633 print_log("HOMESCREEN: Event[input_input] device=%s input=%d code=%d state=%d",
634 device, input, code, state);
637 static const struct ico_exinput_listener exinput_listener = {
638 cb_input_capabilities,
644 handle_global(void *data, struct wl_registry *registry, uint32_t id,
645 const char *interface, uint32_t version)
647 struct display *display = data;
649 struct output *output;
651 print_log("HOMESCREEN: handle_global: interface=<%s> id=%d", interface, (int)id);
653 if (strcmp(interface, "wl_compositor") == 0) {
654 display->compositor =
655 wl_registry_bind(display->registry, id, &wl_compositor_interface, 1);
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;
664 wl_seat_add_listener(input->seat, &seat_listener, input);
665 display->input = input;
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;
674 print_log("HOMESCREEN: created output global %p", display->output);
676 else if (strcmp(interface, "wl_shell") == 0) {
678 wl_registry_bind(display->registry, id, &wl_shell_interface, 1);
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);
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);
690 ico_window_mgr_set_eventcb(display->ico_window_mgr, 1);
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);
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);
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);
708 ico_window_mgr_set_eventcb(display->ico_window_mgr, 1);
710 display->bg_created = 1;
711 create_surface(display);
715 static const struct wl_registry_listener registry_listener = {
720 skip_spaces(char *buf)
722 while ((*buf == ' ') || (*buf == '\t')) {
729 pars_command(char *buf, char *pt[], const int len)
734 memset(pt, 0, sizeof(int *)*10);
736 for (narg = 0; narg < len; narg++) {
741 if ((*p == ' ') || (*p == '\t') ||
742 (*p == '=') || (*p == ',')) break;
755 launch_app(struct display *display, char *buf)
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);
766 sleep_with_wayland(display->display, 500);
771 kill_app(struct display *display, char *buf)
775 struct surface_name *p;
776 struct surface_name *fp;
778 narg = pars_command(buf, args, 10);
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",
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]);
792 kill(p->pid, SIGKILL);
793 sleep_with_wayland(display->display, 200);
797 p = search_surfacename(display, args[0]);
799 if (p == display->surface_name) {
800 display->surface_name = p->next;
803 fp = display->surface_name;
815 print_log("HOMESCREEN: kill command[kill appid] has no argument");
820 layer_surface(struct display *display, char *buf)
827 narg = pars_command(buf, args, 10);
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);
837 print_log("HOMESCREEN: Unknown surface(%s) at layer command", args[0]);
841 print_log("HOMESCREEN: layer command[layer appid layerid] has no argument");
846 positionsize_surface(struct display *display, char *buf)
851 int x, y, width, height;
853 narg = pars_command(buf, args, 10);
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);
867 print_log("HOMESCREEN: Unknown surface(%s) at positionsize command", args[0]);
871 print_log("HOMESCREEN: positionsize command"
872 "[positionsize appid x y width heigh] has no argument");
877 move_surface(struct display *display, char *buf)
884 narg = pars_command(buf, args, 10);
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,
893 ICO_IVI_MAX_COORDINATE+1,
894 ICO_IVI_MAX_COORDINATE+1);
897 print_log("HOMESCREEN: Unknown surface(%s) at move command", args[0]);
901 print_log("HOMESCREEN: move command[positionsize appid x y] has no argument");
906 resize_surface(struct display *display, char *buf)
913 narg = pars_command(buf, args, 10);
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);
926 print_log("HOMESCREEN: Unknown surface(%s) at resize command", args[0]);
930 print_log("HOMESCREEN: positionsize command"
931 "[resize appid width heigh] has no argument");
936 visible_surface(struct display *display, char *buf)
944 narg = pars_command(buf, args, 10);
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);
955 print_log("HOMESCREEN: Unknown surface(%s) at visible command", args[0]);
959 print_log("HOMESCREEN: visible command[visible appid visible raise] "
965 show_surface(struct display *display, char *buf, const int show)
971 narg = pars_command(buf, args, 10);
973 surfaceid = search_surface(display, args[0]);
974 if (surfaceid >= 0) {
976 print_log("HOMESCREEN: show(%s,%08x)", args[0], surfaceid);
977 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 1, 9);
980 print_log("HOMESCREEN: hide(%s,%08x)", args[0], surfaceid);
981 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 0, 9);
985 print_log("HOMESCREEN: Unknown surface(%s) at show/hide command", args[0]);
989 print_log("HOMESCREEN: show command[show/hide appid] has no argument");
994 raise_surface(struct display *display, char *buf, const int raise)
1000 narg = pars_command(buf, args, 10);
1002 surfaceid = search_surface(display, args[0]);
1003 if (surfaceid >= 0) {
1005 print_log("HOMESCREEN: raise(%s,%08x)", args[0], surfaceid);
1006 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 9, 1);
1009 print_log("HOMESCREEN: lower(%s,%08x)", args[0], surfaceid);
1010 ico_window_mgr_set_visible(display->ico_window_mgr, surfaceid, 9, 0);
1014 print_log("HOMESCREEN: Unknown surface(%s) at raise/lower command", args[0]);
1018 print_log("HOMESCREEN: show command[raise/lower appid] has no argument");
1023 transition_surface(struct display *display, char *buf)
1030 narg = pars_command(buf, args, 10);
1032 surfaceid = search_surface(display, args[0]);
1033 transition = strtol(args[1], (char **)0, 0);
1034 if ((surfaceid >= 0) && (transition >=0)) {
1035 print_log("HOMESCREEN: transition(%s,%08x,%d)", args[0], surfaceid, transition);
1036 ico_window_mgr_set_transition(display->ico_window_mgr, surfaceid, transition);
1039 print_log("HOMESCREEN: Unknown surface(%s) at transition command", args[0]);
1043 print_log("HOMESCREEN: transition command"
1044 "[transition appid transition] has no argument");
1049 visible_layer(struct display *display, char *buf)
1056 narg = pars_command(buf, args, 10);
1058 layer = strtol(args[0], (char **)0, 0);
1059 visible = strtol(args[1], (char **)0, 0);
1060 ico_window_mgr_set_layer_visible(display->ico_window_mgr, layer, visible);
1063 print_log("HOMESCREEN: layer_visible command"
1064 "[layer_visible layer visible] has no argument");
1069 input_add(struct display *display, char *buf)
1076 narg = pars_command(buf, args, 10);
1078 input = strtol(args[1], (char **)0, 0);
1080 fix = strtol(args[3], (char **)0, 0);
1085 if ((input >= 0) && (fix >=0)) {
1086 print_log("HOMESCREEN: input_add(%s.%d to %s[%d])",
1087 args[0], input, args[2], fix);
1088 ico_input_mgr_control_add_input_app(display->ico_input_mgr,
1089 args[2], args[0], input, fix);
1092 print_log("HOMESCREEN: Unknown input(%s) at input_add command", args[1]);
1096 print_log("HOMESCREEN: input_add command[input_add device inputId appid fix] "
1102 input_del(struct display *display, char *buf)
1107 char wk1[32], wk2[32];
1109 narg = pars_command(buf, args, 10);
1111 input = strtol(args[1], (char **)0, 0);
1112 if (args[0][0] == '@') {
1116 if (args[2][0] == '@') {
1120 print_log("HOMESCREEN: input_del(%s.%d to %s)", args[0], input, args[2]);
1121 ico_input_mgr_control_del_input_app(display->ico_input_mgr,
1122 args[2], args[0], input);
1125 print_log("HOMESCREEN: input_del command[input_del device inputId appid] "
1131 input_conf(struct display *display, char *buf)
1138 char wk1[32], wk2[32];
1140 narg = pars_command(buf, args, 10);
1142 type = strtol(args[1], (char **)0, 0);
1143 input = strtol(args[3], (char **)0, 0);
1145 code = strtol(args[5], (char **)0, 0);
1150 strcpy(wk1, args[2]);
1154 if ((type >= 0) && (input >= 0) && (code >=0)) {
1155 ico_input_mgr_device_configure_input(display->ico_input_device, args[0], type,
1156 args[2], input, args[4], code);
1159 print_log("HOMESCREEN: Unknown type(%s),input(%s) or code(%s) "
1160 "at input_conf command", args[1], args[3], args[5]);
1164 print_log("HOMESCREEN: input_conf command[input_conf device type swname input "
1165 "codename code] has no argument");
1170 input_code(struct display *display, char *buf)
1177 narg = pars_command(buf, args, 10);
1179 input = strtol(args[1], (char **)0, 0);
1180 code = strtol(args[3], (char **)0, 0);
1181 if ((input >= 0) && (code >= 0)) {
1182 ico_input_mgr_device_configure_code(display->ico_input_device, args[0], input,
1186 print_log("HOMESCREEN: Unknown input(%s) or code(%s) "
1187 "at input_code command", args[1], args[3]);
1191 print_log("HOMESCREEN: input_conf command[input_code device input codename code] "
1197 input_sw(struct display *display, char *buf)
1207 narg = pars_command(buf, args, 10);
1209 input = strtol(args[1], (char **)0, 0);
1210 code = strtol(args[2], (char **)0, 0);
1211 state = strtol(args[3], (char **)0, 0);
1212 if ((input >= 0) && (state >= 0)) {
1213 gettimeofday(&stv, (struct timezone *)NULL);
1214 timems = (stv.tv_sec % 1000) * 1000 + (stv.tv_usec / 1000);
1215 ico_input_mgr_device_input_event(display->ico_input_device,
1216 timems, args[0], input, code, state);
1219 print_log("HOMESCREEN: Unknown input(%s),code(%s) or state(%s) "
1220 "at input_sw command", args[1], args[2], args[3]);
1224 print_log("HOMESCREEN: input_sw command[input_sw device input code, state] "
1230 send_event(const char *cmd)
1232 static int nmqinfo = 0;
1249 for (pt = 0; cmd[pt]; pt++) {
1250 if ((cmd[pt] >= '0') && (cmd[pt] <= '9')) {
1251 mqkey = mqkey * 10 + cmd[pt] - '0';
1257 for (; cmd[pt] == ' '; pt++) ;
1263 for (i = 0; i < nmqinfo; i++) {
1264 if (mqinfo[i].mqkey == mqkey) {
1265 mqid = mqinfo[i].mqid;
1270 if (nmqinfo >= 10) {
1271 fprintf(stderr, "HOMESCREEN: message queue(%d) overflow\n", mqkey);
1274 mqid = msgget(mqkey, 0);
1276 fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) get error[%d]\n",
1277 mqkey, mqkey, errno);
1280 mqinfo[nmqinfo].mqkey = mqkey;
1281 mqinfo[nmqinfo].mqid = mqid;
1285 memset(&mqbuf, 0, sizeof(mqbuf));
1287 strncpy(mqbuf.buf, &cmd[pt], sizeof(mqbuf)-sizeof(long));
1289 if (msgsnd(mqid, &mqbuf, sizeof(mqbuf)-sizeof(long), 0) < 0) {
1290 fprintf(stderr, "HOMESCREEN: message queue(%d(0x%x)) send error[%d]\n",
1291 mqkey, mqkey, errno);
1300 * test-homescreen < test-case-data-file > test-result-output
1302 int main(int argc, char *argv[])
1304 struct display *display;
1309 display = malloc(sizeof *display);
1311 memset((char *)display, 0, sizeof *display);
1313 display->init_width = 640;
1314 display->init_height = 480;
1315 display->init_color = 0xFF304010;
1317 for (fd = 1; fd < argc; fd++) {
1318 if (argv[fd][0] == '-') {
1319 if (strncasecmp(argv[fd], "-visible=", 9) == 0) {
1320 display->visible_on_create = argv[fd][9] & 1;
1322 else if (strncasecmp(argv[fd], "-display=", 9) == 0) {
1323 strncpy(display->connect, &argv[fd][9], MAX_CON_NAME);
1325 else if (strncasecmp(argv[fd], "-prompt=", 8) == 0) {
1326 display->prompt = argv[fd][8] & 1;
1331 if (display->connect[0]) {
1332 display->display = wl_display_connect(display->connect);
1335 display->display = wl_display_connect(NULL);
1337 assert(display->display);
1339 display->registry = wl_display_get_registry(display->display);
1340 wl_registry_add_listener(display->registry,
1341 ®istry_listener, display);
1342 wl_display_dispatch(display->display);
1347 sleep_with_wayland(display->display, 20);
1348 if (display->prompt) {
1349 printf("HOMESCREEN: "); fflush(stdout);
1351 ret = getdata(display->ico_window_mgr, "HOMESCREEN: ", fd, buf, sizeof(buf));
1353 fprintf(stderr, "HOMESCREEN: read error: fd %d, %m\n", fd);
1356 if (ret == 0) continue;
1357 wl_display_flush(display->display);
1359 if ((strncasecmp(buf, "bye", 3) == 0) ||
1360 (strncasecmp(buf, "quit", 4) == 0) ||
1361 (strncasecmp(buf, "end", 3) == 0)) {
1362 /* Exit, end of test */
1365 else if (strncasecmp(buf, "launch", 6) == 0) {
1366 /* Launch test application */
1367 launch_app(display, &buf[6]);
1369 else if (strncasecmp(buf, "kill", 4) == 0) {
1370 /* Launch test application */
1371 kill_app(display, &buf[4]);
1373 else if (strncasecmp(buf, "layer_visible", 13) == 0) {
1374 /* Change layer visiblety */
1375 visible_layer(display, &buf[13]);
1377 else if (strncasecmp(buf, "layer", 5) == 0) {
1378 /* layer change surface window */
1379 layer_surface(display, &buf[5]);
1381 else if (strncasecmp(buf, "positionsize", 12) == 0) {
1382 /* Move and Ressize surface window*/
1383 positionsize_surface(display, &buf[12]);
1385 else if (strncasecmp(buf, "move", 4) == 0) {
1386 /* Move surface window */
1387 move_surface(display, &buf[4]);
1389 else if (strncasecmp(buf, "resize", 6) == 0) {
1390 /* Resize surface window */
1391 resize_surface(display, &buf[6]);
1393 else if (strncasecmp(buf, "visible", 7) == 0) {
1394 /* Visible and Raise surface window*/
1395 visible_surface(display, &buf[7]);
1397 else if (strncasecmp(buf, "show", 4) == 0) {
1398 /* Show/Hide surface window */
1399 show_surface(display, &buf[4], 1);
1401 else if (strncasecmp(buf, "hide", 4) == 0) {
1402 /* Show/Hide surface window */
1403 show_surface(display, &buf[4], 0);
1405 else if (strncasecmp(buf, "raise", 5) == 0) {
1406 /* Raise/Lower surface window */
1407 raise_surface(display, &buf[5], 1);
1409 else if (strncasecmp(buf, "lower", 5) == 0) {
1410 /* Raise/Lower surface window */
1411 raise_surface(display, &buf[5], 0);
1413 else if (strncasecmp(buf, "transition", 10) == 0) {
1414 /* Set transition surface window*/
1415 transition_surface(display, &buf[10]);
1417 else if (strncasecmp(buf, "input_add", 9) == 0) {
1418 /* Set input switch to application */
1419 input_add(display, &buf[9]);
1421 else if (strncasecmp(buf, "input_del", 9) == 0) {
1422 /* Reset input switch to application*/
1423 input_del(display, &buf[9]);
1425 else if (strncasecmp(buf, "input_conf", 10) == 0) {
1426 /* input switch configuration */
1427 input_conf(display, &buf[10]);
1429 else if (strncasecmp(buf, "input_code", 10) == 0) {
1430 /* input code configuration */
1431 input_code(display, &buf[10]);
1433 else if (strncasecmp(buf, "input_sw", 8) == 0) {
1434 /* input switch event */
1435 input_sw(display, &buf[8]);
1437 else if (strncasecmp(buf, "sleep", 5) == 0) {
1439 msec = sec_str_2_value(&buf[6]);
1440 sleep_with_wayland(display->display, msec);
1442 else if (strncasecmp(buf, "waitcreate", 10) == 0) {
1443 /* Wait surface create */
1444 msec = sec_str_2_value(&buf[11]);
1445 wait_with_wayland(display->display, msec, &display->surface_created);
1447 else if (strncasecmp(buf, "waitdestroy", 11) == 0) {
1448 /* Wait surface destrpy */
1449 msec = sec_str_2_value(&buf[12]);
1450 wait_with_wayland(display->display, msec, &display->surface_destroyed);
1452 else if (strncasecmp(buf, "event", 5) == 0) {
1453 /* Send touch panel event to Weston */
1454 send_event(&buf[6]);
1457 print_log("HOMESCREEN: unknown command[%s]", buf);
1462 print_log("HOMESCREEN: end");