From 302efc14ca95f9833f47423169375a88ddcacea7 Mon Sep 17 00:00:00 2001 From: "junghoon13.son" Date: Thu, 2 Apr 2015 15:37:26 +0900 Subject: [PATCH] Input implementation - initial version - wayland backend module - core module - wl_seat Change-Id: I726e04421cacacf8a25d366656e5f059e810a192 --- src/input.c | 363 +++++++++++++++++++++++++ src/modules/wayland/wayland-common.c | 12 - src/modules/wayland/wayland-input.c | 273 ++++++++++++++++--- src/modules/wayland/wayland-internal.h | 30 +- src/pepper-internal.h | 42 +++ src/pepper.h | 62 +++++ 6 files changed, 726 insertions(+), 56 deletions(-) diff --git a/src/input.c b/src/input.c index aded7fb..c1a66da 100644 --- a/src/input.c +++ b/src/input.c @@ -1 +1,364 @@ #include "pepper-internal.h" + +static void +unbind_resource(struct wl_resource *resource) +{ + wl_list_remove(wl_resource_get_link(resource)); +} + +static void +pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial, + struct wl_resource *surface_resource, int32_t x, int32_t y) +{ + /* TODO */ + return; +} + +static void +pointer_release(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct wl_pointer_interface pointer_interface = +{ + pointer_set_cursor, + pointer_release, +}; + +static void +seat_get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource); + struct wl_resource *r; + + if (!seat->pointer) + return; + + r = wl_resource_create(client, &wl_pointer_interface, + wl_resource_get_version(resource), id); + if (!r) + { + wl_client_post_no_memory(client); + return; + } + + wl_list_insert(&seat->pointer->resources, wl_resource_get_link(r)); + wl_resource_set_implementation(r, &pointer_interface, seat->pointer, unbind_resource); + + /* TODO */ + + return; +} + +static void +keyboard_release(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct wl_keyboard_interface keyboard_interface = +{ + keyboard_release, +}; + +static void +seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource); + struct wl_resource *r; + + if (!seat->keyboard) + return; + + r = wl_resource_create(client, &wl_keyboard_interface, + wl_resource_get_version(resource), id); + if (!r) + { + wl_client_post_no_memory(client); + return; + } + + wl_list_insert(&seat->keyboard->resources, wl_resource_get_link(r)); + wl_resource_set_implementation(r, &keyboard_interface, seat, unbind_resource); + + /* TODO */ + + return; +} + +static void +touch_release(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct wl_touch_interface touch_interface = +{ + touch_release, +}; + +static void +seat_get_touch(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource); + struct wl_resource *r; + + if (!seat->touch) + return; + + r = wl_resource_create(client, &wl_touch_interface, wl_resource_get_version(resource), id); + if (!r) + { + wl_client_post_no_memory(client); + return; + } + + wl_list_insert(&seat->touch->resources, wl_resource_get_link(r)); + wl_resource_set_implementation(r, &touch_interface, seat, unbind_resource); + + /* TODO */ + + return; +} + +static const struct wl_seat_interface seat_interface = { + seat_get_pointer, + seat_get_keyboard, + seat_get_touch, +}; + +static void +bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + pepper_seat_t *seat = (pepper_seat_t *)data; + struct wl_resource *resource; + + resource = wl_resource_create(client, &wl_seat_interface, version/*FIXME*/, id); + wl_list_insert(&seat->resources, wl_resource_get_link(resource)); + wl_resource_set_implementation(resource, &seat_interface, data, unbind_resource); +} + +static pepper_pointer_t * +pointer_create(pepper_seat_t *seat) +{ + pepper_pointer_t *pointer; + + pointer = (pepper_pointer_t *)pepper_calloc(1, sizeof(pepper_pointer_t)); + if (!pointer) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return NULL; + } + + pointer->seat = seat; + wl_list_init(&pointer->resources); + + return pointer; +} + +static void +pointer_destroy(pepper_seat_t *seat) +{ + struct wl_resource *resource; + struct wl_list *resource_list = &seat->pointer->resources; + + wl_resource_for_each(resource, resource_list) + wl_resource_destroy(resource); + pepper_free(seat->pointer); + + return; +} + +static pepper_keyboard_t * +keyboard_create(pepper_seat_t *seat) +{ + pepper_keyboard_t *keyboard; + + keyboard = (pepper_keyboard_t *)pepper_calloc(1, sizeof(pepper_keyboard_t)); + if (!keyboard) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return NULL; + } + + keyboard->seat = seat; + wl_list_init(&keyboard->resources); + + return keyboard; +} + +static void +keyboard_destroy(pepper_seat_t *seat) +{ + struct wl_resource *resource; + struct wl_list *resource_list = &seat->keyboard->resources; + + wl_resource_for_each(resource, resource_list) + wl_resource_destroy(resource); + pepper_free(seat->keyboard); + + return; +} + +static pepper_touch_t * +touch_create(pepper_seat_t *seat) +{ + pepper_touch_t *touch; + + touch = (pepper_touch_t *)pepper_calloc(1, sizeof(pepper_touch_t)); + if (!touch) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return NULL; + } + + touch->seat = seat; + wl_list_init(&touch->resources); + + return touch; +} + +static void +touch_destroy(pepper_seat_t *seat) +{ + struct wl_resource *resource; + struct wl_list *resource_list = &seat->touch->resources; + + wl_resource_for_each(resource, resource_list) + wl_resource_destroy(resource); + pepper_free(seat->touch); + + return; +} + +static void +seat_set_capabilities(pepper_seat_t *seat, uint32_t caps) +{ + struct wl_resource *resource; + + seat->caps = caps; + + if ((caps & WL_SEAT_CAPABILITY_POINTER) && (!seat->pointer)) + { + seat->pointer = pointer_create(seat); + if (!seat->pointer) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return; + } + } + else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && (seat->pointer)) + { + pointer_destroy(seat); + } + + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && (!seat->keyboard)) + { + seat->keyboard = keyboard_create(seat); + if (!seat->keyboard) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return; + } + } + else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (seat->keyboard)) + { + keyboard_destroy(seat); + } + + if ((caps & WL_SEAT_CAPABILITY_TOUCH) && (!seat->touch)) + { + seat->touch = touch_create(seat); + if (!seat->touch) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return; + } + } + else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && (seat->touch)) + { + touch_destroy(seat); + } + + wl_resource_for_each(resource, &seat->resources) + wl_seat_send_capabilities(resource, caps); + + return; +} + +static void +handle_seat_set_capabilities(struct wl_listener *listener, void *data) +{ + pepper_seat_t *seat = wl_container_of(listener, seat, capabilities_listener); + uint32_t caps; + + caps = seat->interface->get_capabilities(data); + seat_set_capabilities(seat, caps); + + return; +} + +static void +seat_set_name(pepper_seat_t *seat, const char *name) +{ + struct wl_resource *resource; + + seat->name = name; + wl_resource_for_each(resource, &seat->resources) + wl_seat_send_name(resource, name); + + return; +} + +static void +handle_seat_set_name(struct wl_listener *listener, void *data) +{ + pepper_seat_t *seat = wl_container_of(listener, seat, name_listener); + const char *name; + + name = seat->interface->get_name(data); + seat_set_name(seat, name); + + return; +} + +PEPPER_API pepper_seat_t * +pepper_compositor_add_seat(pepper_compositor_t *compositor, + const pepper_seat_interface_t *interface, + void *data) +{ + pepper_seat_t *seat; + + seat = (pepper_seat_t *)pepper_calloc(1, sizeof(pepper_seat_t)); + if (!seat) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return NULL; + } + + seat->compositor = compositor; + seat->interface = (pepper_seat_interface_t *)interface; + seat->data = data; + + wl_list_init(&seat->resources); + wl_list_init(&seat->link); + wl_list_insert(&compositor->seat_list, &seat->link); + + seat->capabilities_listener.notify = handle_seat_set_capabilities; + seat->interface->add_capabilities_listener(seat->data, &seat->capabilities_listener); + seat->name_listener.notify = handle_seat_set_name; + seat->interface->add_name_listener(seat->data, &seat->name_listener); + + seat->global = wl_global_create(compositor->display, &wl_seat_interface, 4, seat, + bind_seat); + + return seat; +} + +PEPPER_API pepper_bool_t +pepper_seat_handle_event(pepper_seat_t *seat, pepper_input_event_t *event) +{ + /* TODO */ + return PEPPER_TRUE; +} diff --git a/src/modules/wayland/wayland-common.c b/src/modules/wayland/wayland-common.c index 4ed1873..d171ad3 100644 --- a/src/modules/wayland/wayland-common.c +++ b/src/modules/wayland/wayland-common.c @@ -104,18 +104,6 @@ pepper_wayland_destroy(pepper_wayland_t *conn) if (conn->compositor) wl_compositor_destroy(conn->compositor); - if (conn->seat) - wl_seat_destroy(conn->seat); - - if (conn->pointer) - wl_pointer_destroy(conn->pointer); - - if (conn->keyboard) - wl_keyboard_destroy(conn->keyboard); - - if (conn->touch) - wl_touch_destroy(conn->touch); - if (conn->shell) wl_shell_destroy(conn->shell); } diff --git a/src/modules/wayland/wayland-input.c b/src/modules/wayland/wayland-input.c index 7f5aefc..27f5f2b 100644 --- a/src/modules/wayland/wayland-input.c +++ b/src/modules/wayland/wayland-input.c @@ -5,7 +5,12 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + + seat->pointer_x_last = surface_x; + seat->pointer_y_last = surface_y; + + /* TODO */ } static void @@ -19,21 +24,63 @@ static void pointer_handle_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_POINTER_MOTION; + event.time = time; + event.serial = 0; + event.index = 0; + event.state = 0; + event.value = 0; + event.x = seat->pointer_x_last = surface_x; + event.y = seat->pointer_y_last = surface_y; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_POINTER_BUTTON; + event.time = time; + event.serial = serial; /* FIXME */ + event.index = button; + event.state = state; + event.value = 0; + event.x = seat->pointer_x_last; + event.y = seat->pointer_y_last; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void pointer_handle_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_POINTER_AXIS; + event.time = time; + event.serial = 0; + event.index = axis; + event.value = value; + event.state = 0; + event.x = 0; + event.y = 0; + + pepper_seat_handle_event(seat->base, &event); + + return; } static const struct wl_pointer_listener pointer_listener = @@ -71,7 +118,21 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_KEYBOARD_KEY; + event.time = time; + event.serial = serial; /* FIXME */ + event.index = key; + event.value = 0; + event.state = state; + event.x = 0; + event.y = 0; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void @@ -104,33 +165,87 @@ touch_handle_down(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_TOUCH_DOWN; + event.time = time; + event.serial = serial; /* FIXME */ + event.index = id; + event.value = 0; + event.state = 0; + event.x = seat->touch_x_last = x; + event.y = seat->touch_y_last = y; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void touch_handle_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, int32_t id) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_TOUCH_UP; + event.time = time; + event.serial = serial; /* FIXME */ + event.index = id; + event.value = 0; + event.state = 0; + event.x = seat->touch_x_last; + event.y = seat->touch_y_last; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void touch_handle_motion(void *data, struct wl_touch *touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_TOUCH_MOTION; + event.time = time; + event.serial = 0; + event.index = id; + event.value = 0; + event.state = 0; + event.x = seat->touch_x_last = x; + event.y = seat->touch_y_last = y; + + pepper_seat_handle_event(seat->base, &event); + + return; } static void touch_handle_frame(void *data, struct wl_touch *touch) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_TOUCH_FRAME; + pepper_seat_handle_event(seat->base, &event); + + return; } static void touch_handle_cancel(void *data, struct wl_touch *touch) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)seat; + pepper_input_event_t event; + + event.type = PEPPER_INPUT_EVENT_TOUCH_CANCEL; + pepper_seat_handle_event(seat->base, &event); + + return; } static const struct wl_touch_listener touch_listener = @@ -143,54 +258,65 @@ static const struct wl_touch_listener touch_listener = }; static void -seat_handle_caps(void *data, struct wl_seat *seat, enum wl_seat_capability caps) +seat_handle_caps(void *data, struct wl_seat *s, enum wl_seat_capability caps) { - pepper_wayland_t *conn = data; + wayland_seat_t *seat = (wayland_seat_t *)data; - if ((caps & WL_SEAT_CAPABILITY_POINTER) && (!conn->pointer)) - { - conn->pointer = wl_seat_get_pointer(seat); + if (seat->seat != s) /* FIXME */ + return; - if (conn->seat) - wl_pointer_add_listener(conn->pointer, &pointer_listener, conn->seat); + if ((caps & WL_SEAT_CAPABILITY_POINTER) && (!seat->pointer)) + { + seat->pointer = wl_seat_get_pointer(seat->seat); + if (seat->pointer) + wl_pointer_add_listener(seat->pointer, &pointer_listener, seat); } - else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && (conn->pointer)) + else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && (seat->pointer)) { - wl_pointer_release(conn->pointer); - conn->pointer = NULL; + wl_pointer_release(seat->pointer); + seat->pointer = NULL; } - if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && (!conn->keyboard)) + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && (!seat->keyboard)) { - conn->keyboard = wl_seat_get_keyboard(seat); - - if (conn->seat) - wl_keyboard_add_listener(conn->keyboard, &keyboard_listener, conn->seat); + seat->keyboard = wl_seat_get_keyboard(seat->seat); + if (seat->keyboard) + wl_keyboard_add_listener(seat->keyboard, &keyboard_listener, seat); } - else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (conn->keyboard)) + else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (seat->keyboard)) { - wl_keyboard_release(conn->keyboard); - conn->keyboard = NULL; + wl_keyboard_release(seat->keyboard); + seat->keyboard = NULL; } - if ((caps & WL_SEAT_CAPABILITY_TOUCH) && (!conn->touch)) + if ((caps & WL_SEAT_CAPABILITY_TOUCH) && (!seat->touch)) { - conn->touch = wl_seat_get_touch(seat); - - if (conn->seat) - wl_touch_add_listener(conn->touch, &touch_listener, conn->seat); + seat->touch = wl_seat_get_touch(seat->seat); + if (seat->touch) + wl_touch_add_listener(seat->touch, &touch_listener, seat); } - else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && (conn->touch)) + else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && (seat->touch)) { - wl_touch_release(conn->touch); - conn->touch = NULL; + wl_touch_release(seat->touch); + seat->touch = NULL; } + + seat->caps = caps; + wl_signal_emit(&seat->capability_signal, seat); } static void -seat_handle_name(void *data, struct wl_seat *seat, const char *name) +seat_handle_name(void *data, struct wl_seat *s, const char *name) { - PEPPER_TRACE("TODO: %s\n", __FUNCTION__); + wayland_seat_t *seat = (wayland_seat_t *)data; + + if (seat->seat != s) /* FIXME */ + return; + + seat->name = pepper_string_copy(name); + wl_signal_emit(&seat->name_signal, seat); + + return; } static const struct wl_seat_listener seat_listener = @@ -199,10 +325,77 @@ static const struct wl_seat_listener seat_listener = seat_handle_name, }; +static void +wayland_seat_destroy(void *data) +{ + wayland_seat_t *seat = (wayland_seat_t *)data; + /* TODO: */ + return; +} + +static void +wayland_seat_add_capability_listener(void *data, struct wl_listener *listener) +{ + wayland_seat_t *seat = (wayland_seat_t *)data; + wl_signal_add(&seat->capability_signal, listener); + return; +} + +static void +wayland_seat_add_name_listener(void *data, struct wl_listener *listener) +{ + wayland_seat_t *seat = (wayland_seat_t *)data; + wl_signal_add(&seat->name_signal, listener); + return; +} + +static uint32_t +wayland_seat_get_capabilities(void *data) +{ + wayland_seat_t *seat = (wayland_seat_t *)data; + return seat->caps; +} + +static const char * +wayland_seat_get_name(void *data) +{ + wayland_seat_t *seat = (wayland_seat_t *)data; + return seat->name; +} + +static const pepper_seat_interface_t wayland_seat_interface = +{ + wayland_seat_destroy, + wayland_seat_add_capability_listener, + wayland_seat_add_name_listener, + wayland_seat_get_capabilities, + wayland_seat_get_name, +}; + void wayland_handle_global_seat(pepper_wayland_t *conn, struct wl_registry *registry, uint32_t name, uint32_t version) { - conn->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); - wl_seat_add_listener(conn->seat, &seat_listener, conn); + wayland_seat_t *seat; + + seat = (wayland_seat_t *)pepper_calloc(1, sizeof(wayland_seat_t)); + if (!seat) + { + PEPPER_ERROR("Failed to allocate memory in %s\n", __FUNCTION__); + return; + } + + seat->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1); + wl_seat_add_listener(seat->seat, &seat_listener, seat); + + wl_signal_init(&seat->capability_signal); + wl_signal_init(&seat->name_signal); + + seat->base = pepper_compositor_add_seat(conn->pepper, &wayland_seat_interface, seat); + seat->id = name; + + wl_list_init(&seat->link); + wl_list_insert(&conn->seat_list, &seat->link); + + return; } diff --git a/src/modules/wayland/wayland-internal.h b/src/modules/wayland/wayland-internal.h index fe9b891..c6f52a2 100644 --- a/src/modules/wayland/wayland-internal.h +++ b/src/modules/wayland/wayland-internal.h @@ -3,6 +3,7 @@ #include typedef struct wayland_output wayland_output_t; +typedef struct wayland_seat wayland_seat_t; struct pepper_wayland { @@ -16,13 +17,11 @@ struct pepper_wayland struct wl_registry *registry; struct wl_compositor *compositor; - struct wl_seat *seat; - struct wl_pointer *pointer; - struct wl_keyboard *keyboard; - struct wl_touch *touch; struct wl_shell *shell; + struct wl_list seat_list; struct wl_signal destroy_signal; + }; struct wayland_output @@ -41,6 +40,29 @@ struct wayland_output struct wl_shell_surface *shell_surface; }; +struct wayland_seat +{ + pepper_seat_t *base; + + uint32_t id; + uint32_t caps; + char *name; + + struct wl_seat *seat; + struct wl_pointer *pointer; + struct wl_keyboard *keyboard; + struct wl_touch *touch; + + wl_fixed_t pointer_x_last; + wl_fixed_t pointer_y_last; + wl_fixed_t touch_x_last; /* FIXME */ + wl_fixed_t touch_y_last; /* FIXME */ + + struct wl_list link; + struct wl_signal capability_signal; + struct wl_signal name_signal; +}; + void wayland_handle_global_seat(pepper_wayland_t *conn, struct wl_registry *registry, uint32_t name, uint32_t version); diff --git a/src/pepper-internal.h b/src/pepper-internal.h index 67f59a7..3f7e5bb 100644 --- a/src/pepper-internal.h +++ b/src/pepper-internal.h @@ -18,6 +18,7 @@ struct pepper_compositor struct wl_display *display; struct wl_list surfaces; struct wl_list regions; + struct wl_list seat_list; }; struct pepper_output @@ -130,4 +131,45 @@ pepper_buffer_reference(pepper_buffer_t *buffer); void pepper_buffer_unreference(pepper_buffer_t *buffer); +/* Input */ +struct pepper_seat +{ + pepper_compositor_t *compositor; + pepper_pointer_t *pointer; + pepper_keyboard_t *keyboard; + pepper_touch_t *touch; + + struct wl_global *global; + struct wl_list resources; + struct wl_list link; + + struct wl_listener capabilities_listener; + struct wl_listener name_listener; + + enum wl_seat_capability caps; + const char *name; + + /* Backend-specific variables. */ + pepper_seat_interface_t *interface; + void *data; +}; + +struct pepper_pointer +{ + pepper_seat_t *seat; + struct wl_list resources; +}; + +struct pepper_keyboard +{ + pepper_seat_t *seat; + struct wl_list resources; +}; + +struct pepper_touch +{ + pepper_seat_t *seat; + struct wl_list resources; +}; + #endif /* PEPPER_INTERNAL_H */ diff --git a/src/pepper.h b/src/pepper.h index a80cf4e..a93e619 100644 --- a/src/pepper.h +++ b/src/pepper.h @@ -25,6 +25,14 @@ typedef struct pepper_output_mode pepper_output_mode_t; typedef struct pepper_output pepper_output_t; typedef struct pepper_output_interface pepper_output_interface_t; +typedef struct pepper_seat_interface pepper_seat_interface_t; +typedef struct pepper_seat pepper_seat_t; +typedef struct pepper_pointer pepper_pointer_t; +typedef struct pepper_keyboard pepper_keyboard_t; +typedef struct pepper_touch pepper_touch_t; + +typedef struct pepper_input_event pepper_input_event_t; + typedef enum { PEPPER_RENDER_METHOD_NONE, @@ -82,6 +90,11 @@ pepper_compositor_add_output(pepper_compositor_t *compositor, const pepper_output_interface_t *interface, void *data); +PEPPER_API pepper_seat_t * +pepper_compositor_add_seat(pepper_compositor_t *compositor, + const pepper_seat_interface_t *interface, + void *data); + PEPPER_API pepper_compositor_t * pepper_output_get_compositor(pepper_output_t *output); @@ -107,6 +120,55 @@ PEPPER_API pepper_bool_t pepper_output_set_mode(pepper_output_t *output, const pepper_output_mode_t *mode); /* Input. */ +struct pepper_seat_interface +{ + void (*destroy)(void *data); + void (*add_capabilities_listener)(void *data, struct wl_listener *listener); + void (*add_name_listener)(void *data, struct wl_listener *listener); + + uint32_t (*get_capabilities)(void *data); + const char * (*get_name)(void *data); +}; + +enum pepper_input_event_type +{ + PEPPER_INPUT_EVENT_POINTER_BUTTON, + PEPPER_INPUT_EVENT_POINTER_MOTION, + PEPPER_INPUT_EVENT_POINTER_AXIS, + PEPPER_INPUT_EVENT_KEYBOARD_KEY, + PEPPER_INPUT_EVENT_TOUCH_DOWN, + PEPPER_INPUT_EVENT_TOUCH_UP, + PEPPER_INPUT_EVENT_TOUCH_MOTION, + PEPPER_INPUT_EVENT_TOUCH_FRAME, + PEPPER_INPUT_EVENT_TOUCH_CANCEL, +}; + +enum pepper_input_event_state +{ + PEPPER_INPUT_EVENT_STATE_RELEASED, + PEPPER_INPUT_EVENT_STATE_PRESSED, +}; + +enum pepper_input_event_axis +{ + PEPPER_INPUT_EVENT_AXIS_VERTICAL, + PEPPER_INPUT_EVENT_AXIS_HORIZONTAL, +}; + +struct pepper_input_event +{ + uint32_t type; + uint32_t time; + uint32_t serial; + uint32_t index; /* button, key, touch id or axis */ + uint32_t state; + wl_fixed_t value; + wl_fixed_t x; + wl_fixed_t y; +}; + +PEPPER_API pepper_bool_t +pepper_seat_handle_event(pepper_seat_t *seat, pepper_input_event_t *event); #ifdef __cplusplus } -- 2.34.1