From 5a75c90d0153eb8f57993d17a3a0884ed8eb6907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 10 Dec 2008 13:16:50 -0500 Subject: [PATCH] Feed button events through compositor. This also generalizes the code to send events to a surface a bit. --- egl-compositor.c | 8 ++++++-- evdev.c | 8 ++++++++ wayland.c | 50 +++++++++++++++++++----------------------------- wayland.h | 12 ++++++++---- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/egl-compositor.c b/egl-compositor.c index c05f3631..917364fa 100644 --- a/egl-compositor.c +++ b/egl-compositor.c @@ -758,8 +758,8 @@ notify_pointer_motion(struct wl_compositor *compositor, if (es) { sx = (x - es->map.x) * es->width / es->map.width; sy = (y - es->map.y) * es->height / es->map.height; - wl_display_post_surface_motion(ec->wl_display, es->wl_surface, - source, x, y, sx, sy); + wl_surface_post_event(es->wl_surface, source, + WL_INPUT_MOTION, x, y, sx, sy); } ec->pointer->map.x = x - hotspot_x; @@ -784,6 +784,10 @@ notify_pointer_button(struct wl_compositor *compositor, if (es) { wl_list_remove(&es->link); wl_list_insert(ec->surface_list.prev, &es->link); + + /* FIXME: Swallow click on raise? */ + wl_surface_post_event(es->wl_surface, source, + WL_INPUT_BUTTON, button, state); } schedule_repaint(ec); diff --git a/evdev.c b/evdev.c index beba634b..beeca29e 100644 --- a/evdev.c +++ b/evdev.c @@ -42,10 +42,18 @@ struct wl_input_device { static const struct wl_method input_device_methods[] = { }; +static const struct wl_event input_device_events[] = { + { "motion", "ii" }, + { "button", "uu" }, + { "key", "uu" }, +}; + static const struct wl_interface input_device_interface = { "input_device", 1, ARRAY_LENGTH(input_device_methods), input_device_methods, + ARRAY_LENGTH(input_device_events), + input_device_events, }; static void wl_input_device_data(int fd, uint32_t mask, void *data) diff --git a/wayland.c b/wayland.c index c1ccd746..8f03d10f 100644 --- a/wayland.c +++ b/wayland.c @@ -212,13 +212,12 @@ void wl_client_destroy(struct wl_client *client); static void -wl_client_marshal(struct wl_client *client, struct wl_object *sender, - uint32_t opcode, ...) +wl_client_vmarshal(struct wl_client *client, struct wl_object *sender, + uint32_t opcode, va_list ap) { const struct wl_event *event; struct wl_object *object; uint32_t args[10], size; - va_list ap; int i, count; event = &sender->interface->events[opcode]; @@ -226,7 +225,6 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender, assert(count <= ARRAY_LENGTH(args)); size = 0; - va_start(ap, opcode); for (i = 2; i < count; i++) { switch (event->signature[i - 2]) { case 'u': @@ -249,7 +247,6 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender, break; } } - va_end(ap); size += 2 * sizeof args[0]; args[0] = sender->id; @@ -257,6 +254,17 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender, wl_connection_write(client->connection, args, size); } +static void +wl_client_marshal(struct wl_client *client, struct wl_object *sender, + uint32_t opcode, ...) +{ + va_list ap; + + va_start(ap, opcode); + wl_client_vmarshal(client, sender, opcode, ap); + va_end(ap); +} + static void wl_client_demarshal(struct wl_client *client, struct wl_object *target, const struct wl_method *method, size_t size) @@ -628,26 +636,16 @@ wl_display_send_event(struct wl_display *display, uint32_t *data, size_t size) } } -#define WL_INPUT_MOTION 0 -#define WL_INPUT_BUTTON 1 -#define WL_INPUT_KEY 2 - WL_EXPORT void -wl_display_post_surface_motion(struct wl_display *display, - struct wl_surface *surface, - struct wl_object *source, - int32_t x, int32_t y, int32_t sx, int32_t sy) +wl_surface_post_event(struct wl_surface *surface, + struct wl_object *sender, + uint32_t event, ...) { - uint32_t p[6]; - - p[0] = source->id; - p[1] = (sizeof p << 16) | WL_INPUT_MOTION; - p[2] = x; - p[3] = y; - p[4] = sx; - p[5] = sy; + va_list ap; - wl_connection_write(surface->client->connection, p, sizeof p); + va_start(ap, event); + wl_client_vmarshal(surface->client, sender, event, ap); + va_end(ap); } WL_EXPORT void @@ -683,18 +681,10 @@ wl_display_post_button_event(struct wl_display *display, struct wl_object *source, int button, int state) { const struct wl_compositor_interface *interface; - uint32_t p[4]; interface = display->compositor->interface; interface->notify_pointer_button(display->compositor, source, button, state); - - p[0] = source->id; - p[1] = (sizeof p << 16) | WL_INPUT_BUTTON; - p[2] = button; - p[3] = state; - - wl_display_send_event(display, p, sizeof p); } WL_EXPORT void diff --git a/wayland.h b/wayland.h index 1f338af2..61258339 100644 --- a/wayland.h +++ b/wayland.h @@ -135,11 +135,15 @@ wl_display_post_key_event(struct wl_display *display, void wl_display_post_frame(struct wl_display *display, uint32_t frame, uint32_t msecs); + +#define WL_INPUT_MOTION 0 +#define WL_INPUT_BUTTON 1 +#define WL_INPUT_KEY 2 + void -wl_display_post_surface_motion(struct wl_display *display, - struct wl_surface *surface, - struct wl_object *source, - int x, int y, int sx, int sy); +wl_surface_post_event(struct wl_surface *surface, + struct wl_object *sender, + uint32_t event, ...); struct wl_compositor { const struct wl_compositor_interface *interface;