From 8fbf58778215df0c8286c14e0fe88f59c95f9ae4 Mon Sep 17 00:00:00 2001 From: "Tran Ba Khang(MS/EMC31-XC)" Date: Fri, 6 Jan 2023 14:27:45 +0700 Subject: multi-touch-viewer: add the type of shell selection input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wl_shell and ivi_shell can’t create a surface base on a wl_surface at the same time, so a selection of shell before running the example is required. The ivi_shell is the shell default, passing the wl_shell follow by –s option to select wl_shell Signed-off-by: Tran Ba Khang(MS/EMC31-XC) --- .../multi-touch-viewer/include/window.h | 9 ++- .../multi-touch-viewer/src/multi-touch-viewer.c | 72 +++++++++++++++------- .../multi-touch-viewer/src/window.c | 9 ++- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/ivi-layermanagement-examples/multi-touch-viewer/include/window.h b/ivi-layermanagement-examples/multi-touch-viewer/include/window.h index 40e2925..d81dda6 100644 --- a/ivi-layermanagement-examples/multi-touch-viewer/include/window.h +++ b/ivi-layermanagement-examples/multi-touch-viewer/include/window.h @@ -46,6 +46,12 @@ struct Task struct wl_list link; }; +enum TypeOfShell +{ + WL_SHELL = 1, + IVI_SHELL = 2 +}; + struct WaylandDisplay { struct Task display_task; @@ -57,6 +63,7 @@ struct WaylandDisplay EGLDisplay egldisplay; EGLConfig eglconfig; EGLContext eglcontext; + enum TypeOfShell shell_type; int running; int epoll_fd; @@ -102,7 +109,7 @@ struct WaylandEglWindow }; struct WaylandDisplay* -CreateDisplay(int argc, char **argv); +CreateDisplay(int argc, char **argv, enum TypeOfShell shell_type); void DestroyDisplay(struct WaylandDisplay *p_display); diff --git a/ivi-layermanagement-examples/multi-touch-viewer/src/multi-touch-viewer.c b/ivi-layermanagement-examples/multi-touch-viewer/src/multi-touch-viewer.c index 6645730..5d97ad4 100644 --- a/ivi-layermanagement-examples/multi-touch-viewer/src/multi-touch-viewer.c +++ b/ivi-layermanagement-examples/multi-touch-viewer/src/multi-touch-viewer.c @@ -30,6 +30,7 @@ #include #include #include "multi-touch-viewer.h" +#include "getopt.h" #define WINDOW_TITLE "multi_touch_viewer" #define WINDOW_WIDTH 1080 @@ -69,6 +70,7 @@ static const char *gp_frag_shader_text = static struct touch_event_test_params *gp_test_params = NULL; static int g_is_print_log = 0; +static enum TypeOfShell g_shell_type = IVI_SHELL; /******************************************************************************/ @@ -587,7 +589,7 @@ setup_signal() /******************************************************************************/ -int +static int touch_event_test_main(struct touch_event_test_params *p_params) { struct WaylandDisplay *p_display; @@ -595,7 +597,7 @@ touch_event_test_main(struct touch_event_test_params *p_params) setup_signal(); - p_display = CreateDisplay(0, NULL); + p_display = CreateDisplay(0, NULL, g_shell_type); if (NULL == p_display) { LOG_ERROR("Failed to create display\n"); @@ -641,39 +643,65 @@ touch_event_test_main(struct touch_event_test_params *p_params) return 0; } -void +static void usage(int status) { - printf("usage: multi-touch-viewer [OPTION]\n"); - printf(" -p : print received touch point\n"); + fprintf(stderr, " -h, --help display this help and exit.\n" + " -p, --print-log print received touch point.\n" + " -s, --shell-type select the type of shell, default is the ivi_shell:\n" + " - wl_shell: to using the wl_shell.\n" + " - ivi_shell: to using the ivi_shell.\n"); exit(status); } -int -main(int argc, char **argv) +static void +parse_options(int argc, char *argv[]) { - _UNUSED_(argc); - _UNUSED_(argv); - struct touch_event_test_params params; + int opt = -1, option_index = 0; + static const struct option options[] = { + { "help", no_argument, NULL, 'h' }, + { "print-log", no_argument, NULL, 'p' }, + { "shell-type", required_argument, NULL, 's' }, + { 0, 0, NULL, 0 } + }; - memset(¶ms, 0x00, sizeof params); + while (1) { + opt = getopt_long(argc, argv, "hps:", options, NULL); - if (argc == 2) - { - if (0 == strcmp(argv[1], "-p")) - { - g_is_print_log = 1; - } - else - { - usage(EXIT_SUCCESS); + if (opt == -1) + break; + + switch (opt) { + case 'h': + usage(0); + break; + case 'p': + g_is_print_log = 1; + break; + case 's': + if (strcmp(optarg, "wl_shell") == 0) + g_shell_type = WL_SHELL; + break; + default: + usage(-1); + break; } } + printf("multi-touch-viewer runs with %s and logging %s\n", + (g_shell_type == WL_SHELL) ? "wl_shell" : "ivi_shell", + (g_is_print_log == 1) ? "enable" : "disable"); +} - gp_test_params = ¶ms; +int +main(int argc, char **argv) +{ + parse_options(argc, argv); - wl_list_init(¶ms.touch_point_list); + struct touch_event_test_params params; + memset(¶ms, 0x00, sizeof params); + gp_test_params = ¶ms; + wl_list_init(¶ms.touch_point_list); log_array_init(¶ms.log_array, 500); return touch_event_test_main(¶ms); diff --git a/ivi-layermanagement-examples/multi-touch-viewer/src/window.c b/ivi-layermanagement-examples/multi-touch-viewer/src/window.c index 41b02a9..abd7788 100644 --- a/ivi-layermanagement-examples/multi-touch-viewer/src/window.c +++ b/ivi-layermanagement-examples/multi-touch-viewer/src/window.c @@ -79,12 +79,14 @@ registry_handle_global(void *p_data, struct wl_registry *p_registry, p_display->p_compositor = wl_registry_bind(p_registry, id, &wl_compositor_interface, 1); } - else if (0 == strcmp(p_interface, "wl_shell")) + else if ((0 == strcmp(p_interface, "wl_shell")) && + (p_display->shell_type == WL_SHELL)) { p_display->p_shell = wl_registry_bind(p_registry, id, &wl_shell_interface, 1); } - else if (0 == strcmp(p_interface, "ivi_application")) + else if ((0 == strcmp(p_interface, "ivi_application")) && + (p_display->shell_type == IVI_SHELL)) { p_display->p_ivi_application = wl_registry_bind(p_registry, id, &ivi_application_interface, 1); @@ -500,7 +502,7 @@ DisplayAcquireWindowSurface(struct WaylandDisplay *p_display, } struct WaylandDisplay * -CreateDisplay(int argc, char **argv) +CreateDisplay(int argc, char **argv, enum TypeOfShell shell_type) { struct WaylandDisplay *p_display; @@ -521,6 +523,7 @@ CreateDisplay(int argc, char **argv) return NULL; } + p_display->shell_type = shell_type; p_display->epoll_fd = os_epoll_create_cloexec(); p_display->display_fd = wl_display_get_fd(p_display->p_display); p_display->display_task.run = handle_display_data; -- cgit v1.2.1