From 7657ac6750488d2557bf35688dd281e37ebe1001 Mon Sep 17 00:00:00 2001 From: Nobuhiko Tanibata Date: Tue, 18 Mar 2014 14:19:48 +0900 Subject: clients: modify example clients to support ivi-application.xml Signed-off-by: Nobuhiko Tanibata --- Makefile.am | 12 ++++++-- clients/simple-egl.c | 70 +++++++++++++++++++++++++++++++++++-------- clients/simple-shm.c | 34 ++++++++++++++++++++- clients/window.c | 84 ++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 161 insertions(+), 39 deletions(-) diff --git a/Makefile.am b/Makefile.am index c4fca527..49c95199 100644 --- a/Makefile.am +++ b/Makefile.am @@ -402,7 +402,9 @@ nodist_weston_simple_shm_SOURCES = \ protocol/xdg-shell-protocol.c \ protocol/xdg-shell-client-protocol.h \ protocol/fullscreen-shell-protocol.c \ - protocol/fullscreen-shell-client-protocol.h + protocol/fullscreen-shell-client-protocol.h \ + protocol/ivi-application-protocol.c \ + protocol/ivi-application-client-protocol.h weston_simple_shm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_CLIENT_CFLAGS) weston_simple_shm_LDADD = $(SIMPLE_CLIENT_LIBS) libshared.la @@ -420,7 +422,9 @@ demo_clients += weston-simple-egl weston_simple_egl_SOURCES = clients/simple-egl.c nodist_weston_simple_egl_SOURCES = \ protocol/xdg-shell-protocol.c \ - protocol/xdg-shell-client-protocol.h + protocol/xdg-shell-client-protocol.h \ + protocol/ivi-application-protocol.c \ + protocol/ivi-application-client-protocol.h weston_simple_egl_CFLAGS = $(AM_CFLAGS) $(SIMPLE_EGL_CLIENT_CFLAGS) weston_simple_egl_LDADD = $(SIMPLE_EGL_CLIENT_LIBS) -lm endif @@ -439,7 +443,9 @@ nodist_libtoytoolkit_la_SOURCES = \ protocol/workspaces-protocol.c \ protocol/workspaces-client-protocol.h \ protocol/xdg-shell-protocol.c \ - protocol/xdg-shell-client-protocol.h + protocol/xdg-shell-client-protocol.h \ + protocol/ivi-application-protocol.c \ + protocol/ivi-application-client-protocol.h BUILT_SOURCES += $(nodist_libtoytoolkit_la_SOURCES) diff --git a/clients/simple-egl.c b/clients/simple-egl.c index 0d4673b5..92f2dc28 100644 --- a/clients/simple-egl.c +++ b/clients/simple-egl.c @@ -41,6 +41,10 @@ #include #include "xdg-shell-client-protocol.h" +#include +#include +#include "protocol/ivi-application-client-protocol.h" +#define IVI_SURFACE_ID 9000 #ifndef EGL_EXT_swap_buffers_with_damage #define EGL_EXT_swap_buffers_with_damage 1 @@ -74,6 +78,7 @@ struct display { EGLConfig conf; } egl; struct window *window; + struct ivi_application *ivi_application; PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage; }; @@ -95,6 +100,7 @@ struct window { struct wl_egl_window *native; struct wl_surface *surface; struct xdg_surface *xdg_surface; + struct ivi_surface *ivi_surface; EGLSurface egl_surface; struct wl_callback *callback; int fullscreen, opaque, buffer_size, frame_sync; @@ -254,7 +260,7 @@ init_gl(struct window *window) } glUseProgram(program); - + window->gl.pos = 0; window->gl.col = 1; @@ -333,13 +339,8 @@ create_surface(struct window *window) { struct display *display = window->display; EGLBoolean ret; - - window->surface = wl_compositor_create_surface(display->compositor); - window->xdg_surface = xdg_shell_get_xdg_surface(display->shell, - window->surface); - xdg_surface_add_listener(window->xdg_surface, - &xdg_surface_listener, window); + window->surface = wl_compositor_create_surface(display->compositor); window->native = wl_egl_window_create(window->surface, @@ -350,7 +351,28 @@ create_surface(struct window *window) display->egl.conf, window->native, NULL); - xdg_surface_set_title(window->xdg_surface, "simple-egl"); + if (display->shell) { + window->xdg_surface = xdg_shell_get_xdg_surface(display->shell, + window->surface); + + xdg_surface_add_listener(window->xdg_surface, + &xdg_surface_listener, window); + + xdg_surface_set_title(window->xdg_surface, "simple-egl"); + } else if (display->ivi_application ) { + uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid(); + window->ivi_surface = + ivi_application_surface_create(display->ivi_application, + id_ivisurf, window->surface); + handle_surface_configure(window, NULL, 250, 250); + + if (window->ivi_surface == NULL) { + fprintf(stderr, "Failed to create ivi_client_surface\n"); + abort(); + } + } else { + assert(0); + } ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, window->egl_surface, window->display->egl.ctx); @@ -359,9 +381,12 @@ create_surface(struct window *window) if (!window->frame_sync) eglSwapInterval(display->egl.dpy, 0); - xdg_surface_request_change_state(window->xdg_surface, - XDG_SURFACE_STATE_FULLSCREEN, - window->fullscreen, 0); + if (display->shell) + { + xdg_surface_request_change_state(window->xdg_surface, + XDG_SURFACE_STATE_FULLSCREEN, + window->fullscreen, 0); + } } static void @@ -536,8 +561,13 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer, struct display *display = data; if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) - xdg_surface_move(display->window->xdg_surface, - display->seat, serial); + { + if (display->shell) + { + xdg_surface_move(display->window->xdg_surface, + display->seat, serial); + } + } } static void @@ -730,6 +760,11 @@ registry_handle_global(void *data, struct wl_registry *registry, // TODO: abort ? } } + else if (strcmp(interface, "ivi_application") == 0) { + d->ivi_application = + wl_registry_bind(registry, name, + &ivi_application_interface, 1); + } } static void @@ -824,6 +859,12 @@ main(int argc, char **argv) fprintf(stderr, "simple-egl exiting\n"); + if (window.display->ivi_application) + { + ivi_surface_destroy(window.ivi_surface); + ivi_application_destroy(window.display->ivi_application); + } + destroy_surface(&window); fini_egl(&display); @@ -838,6 +879,9 @@ main(int argc, char **argv) wl_compositor_destroy(display.compositor); wl_registry_destroy(display.registry); + if (window.display->ivi_application) + wl_display_roundtrip(display.display); + wl_display_flush(display.display); wl_display_disconnect(display.display); diff --git a/clients/simple-shm.c b/clients/simple-shm.c index 2087a0e6..c54b5d73 100644 --- a/clients/simple-shm.c +++ b/clients/simple-shm.c @@ -37,6 +37,10 @@ #include "xdg-shell-client-protocol.h" #include "fullscreen-shell-client-protocol.h" +#include +#include "ivi-application-client-protocol.h" +#define IVI_SURFACE_ID 9000 + struct display { struct wl_display *display; struct wl_registry *registry; @@ -45,6 +49,7 @@ struct display { struct _wl_fullscreen_shell *fshell; struct wl_shm *shm; uint32_t formats; + struct ivi_application *ivi_application; }; struct buffer { @@ -58,6 +63,7 @@ struct window { int width, height; struct wl_surface *surface; struct xdg_surface *xdg_surface; + struct ivi_surface *ivi_surface; struct buffer buffers[2]; struct buffer *prev_buffer; struct wl_callback *callback; @@ -179,11 +185,21 @@ create_window(struct display *display, int width, int height) &xdg_surface_listener, window); xdg_surface_set_title(window->xdg_surface, "simple-shm"); + } else if (display->fshell) { _wl_fullscreen_shell_present_surface(display->fshell, window->surface, _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT, NULL); + } else if (display->ivi_application ) { + uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid(); + window->ivi_surface = + ivi_application_surface_create(display->ivi_application, + id_ivisurf, window->surface); + if (window->ivi_surface == NULL) { + fprintf(stderr, "Failed to create ivi_client_surface\n"); + abort(); + } } else { assert(0); } @@ -369,6 +385,11 @@ registry_handle_global(void *data, struct wl_registry *registry, id, &wl_shm_interface, 1); wl_shm_add_listener(d->shm, &shm_listener, d); } + else if (strcmp(interface, "ivi_application") == 0) { + d->ivi_application = + wl_registry_bind(registry, id, + &ivi_application_interface, 1); + } } static void @@ -413,7 +434,7 @@ create_display(void) } wl_display_get_fd(display->display); - + return display; } @@ -433,6 +454,10 @@ destroy_display(struct display *display) wl_compositor_destroy(display->compositor); wl_registry_destroy(display->registry); + + if (display->ivi_application) + wl_display_roundtrip(display->display); + wl_display_flush(display->display); wl_display_disconnect(display->display); free(display); @@ -472,6 +497,13 @@ main(int argc, char **argv) ret = wl_display_dispatch(display->display); fprintf(stderr, "simple-shm exiting\n"); + + if (window->display->ivi_application) + { + ivi_surface_destroy(window->ivi_surface); + ivi_application_destroy(window->display->ivi_application); + } + destroy_window(window); destroy_display(display); diff --git a/clients/window.c b/clients/window.c index 4592ef96..47434dce 100644 --- a/clients/window.c +++ b/clients/window.c @@ -72,6 +72,10 @@ typedef void *EGLContext; #include "window.h" +#include +#include "ivi-application-client-protocol.h" +#define IVI_SURFACE_ID 9000 + struct shm_pool; struct global { @@ -133,6 +137,7 @@ struct display { int has_rgb565; int seat_version; + struct ivi_application *ivi_application; }; struct window_output { @@ -245,6 +250,7 @@ struct window { struct xdg_popup *xdg_popup; struct window *transient_for; + struct ivi_surface *ivi_surface; struct window_frame *frame; @@ -1373,6 +1379,20 @@ surface_create_surface(struct surface *surface, uint32_t flags) struct display *display = surface->window->display; struct rectangle allocation = surface->allocation; + if (display->ivi_application) + { + if (!surface->toysurface) { + uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid(); + surface->window->ivi_surface = + ivi_application_surface_create(display->ivi_application, + id_ivisurf, surface->surface); + if (surface->window->ivi_surface == NULL) { + fprintf(stderr, "Failed to create ivi_client_surface\n"); + abort(); + } + } + } + if (!surface->toysurface && display->dpy && surface->buffer_type == WINDOW_BUFFER_TYPE_EGL_WINDOW) { surface->toysurface = @@ -1476,6 +1496,12 @@ surface_destroy(struct surface *surface) if (surface->toysurface) surface->toysurface->destroy(surface->toysurface); + if (surface->window->display->ivi_application) + { + ivi_surface_destroy(surface->window->ivi_surface); + ivi_application_destroy(surface->window->display->ivi_application); + } + wl_list_remove(&surface->link); free(surface); } @@ -1490,7 +1516,7 @@ window_destroy(struct window *window) wl_list_remove(&window->redraw_task.link); - wl_list_for_each(input, &display->input_list, link) { + wl_list_for_each(input, &display->input_list, link) { if (input->touch_focus == window) input->touch_focus = NULL; if (input->pointer_focus == window) @@ -3006,7 +3032,7 @@ touch_handle_down(void *data, struct wl_touch *wl_touch, wl_list_insert(&input->touch_point_list, &tp->link); if (widget->touch_down_handler) - (*widget->touch_down_handler)(widget, input, + (*widget->touch_down_handler)(widget, input, serial, time, id, sx, sy, widget->user_data); @@ -4386,7 +4412,7 @@ window_create_internal(struct display *display, int custom) surface = surface_create(window); window->main_surface = surface; - assert(custom || display->xdg_shell); + assert(custom || display->xdg_shell || display->ivi_application); window->custom = custom; window->preferred_format = WINDOW_PREFERRED_FORMAT_NONE; @@ -4409,14 +4435,17 @@ window_create(struct display *display) window = window_create_internal(display, 0); - window->xdg_surface = - xdg_shell_get_xdg_surface(window->display->xdg_shell, - window->main_surface->surface); - fail_on_null(window->xdg_surface); + if (window->display->xdg_shell) + { + window->xdg_surface = + xdg_shell_get_xdg_surface(window->display->xdg_shell, + window->main_surface->surface); + fail_on_null(window->xdg_surface); - xdg_surface_set_user_data(window->xdg_surface, window); - xdg_surface_add_listener(window->xdg_surface, - &xdg_surface_listener, window); + xdg_surface_set_user_data(window->xdg_surface, window); + xdg_surface_add_listener(window->xdg_surface, + &xdg_surface_listener, window); + } return window; } @@ -4634,19 +4663,22 @@ window_show_menu(struct display *display, frame_interior(menu->frame, &ix, &iy, NULL, NULL); - window->xdg_popup = xdg_shell_get_xdg_popup(display->xdg_shell, - window->main_surface->surface, - parent->main_surface->surface, - input->seat, - display_get_serial(window->display), - window->x - ix, - window->y - iy, - 0); - fail_on_null(window->xdg_popup); + if (display->xdg_shell) + { + window->xdg_popup = xdg_shell_get_xdg_popup(display->xdg_shell, + window->main_surface->surface, + parent->main_surface->surface, + input->seat, + display_get_serial(window->display), + window->x - ix, + window->y - iy, + 0); + fail_on_null(window->xdg_popup); - xdg_popup_set_user_data(window->xdg_popup, window); - xdg_popup_add_listener(window->xdg_popup, - &xdg_popup_listener, window); + xdg_popup_set_user_data(window->xdg_popup, window); + xdg_popup_add_listener(window->xdg_popup, + &xdg_popup_listener, window); + } } void @@ -5091,6 +5123,11 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t id, wl_registry_bind(registry, id, &wl_subcompositor_interface, 1); } + else if (strcmp(interface, "ivi_application") == 0) { + d->ivi_application = + wl_registry_bind(registry, id, + &ivi_application_interface, 1); + } if (d->global_handler) d->global_handler(d, id, interface, version, d->user_data); @@ -5400,6 +5437,9 @@ display_destroy(struct display *display) close(display->epoll_fd); + if (display->ivi_application) + wl_display_roundtrip(display->display); + if (!(display->display_fd_events & EPOLLERR) && !(display->display_fd_events & EPOLLHUP)) wl_display_flush(display->display); -- cgit v1.2.1