From 272030652a73fd54472726e3ccd693402868fd35 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 17:54:51 +0200 Subject: [PATCH] Implement absolute motion events for wayland --- backend/wayland/backend.c | 13 ++++++++++++- backend/wayland/wl_seat.c | 39 ++++++++++++++++++++++----------------- include/backend/wayland.h | 7 ++++--- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index a6029500..ef480c18 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -63,7 +63,7 @@ static bool wlr_wl_backend_init(struct wlr_backend_state* state) { state->remote_display_src = wl_event_loop_add_fd(loop, fd, events, dispatch_events, state); wl_event_source_check(state->remote_display_src); - + return true; } @@ -102,6 +102,17 @@ bool wlr_backend_is_wl(struct wlr_backend *b) { return b->impl == &backend_impl; } +struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend, + struct wl_surface *surface) { + for (size_t i = 0; i < backend->outputs->length; ++i) { + struct wlr_output *output = backend->outputs->items[i]; + if(output->state->surface == surface) + return output; + } + + return NULL; +} + struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { wlr_log(L_INFO, "Creating wayland backend"); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index f4d3cd52..6d3b8b05 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -17,9 +17,15 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, wl_fixed_t surface_y) { struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); - struct wlr_pointer_state *state = dev->pointer->state; - state->surface_x = wl_fixed_to_double(surface_x); - state->surface_y = wl_fixed_to_double(surface_y); + struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend, + surface); + + if (!output) { + wlr_log(L_ERROR, "pointer entered invalid surface"); + return; + } + + dev->pointer->state->current_output = output; } static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, @@ -32,22 +38,20 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); struct wlr_pointer_state *state = dev->pointer->state; + assert(state->current_output); - double x = wl_fixed_to_double(surface_x); - double y = wl_fixed_to_double(surface_y); + int width, height; + wl_egl_window_get_attached_size(state->current_output->state->egl_window, + &width, &height); - if (x == state->surface_x && y == state->surface_y) - return; - - struct wlr_event_pointer_motion wlr_event; + struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.delta_x = x - state->surface_x; - wlr_event.delta_y = y - state->surface_y; - wl_signal_emit(&dev->pointer->events.motion, &wlr_event); - - state->surface_x = x; - state->surface_y = y; + wlr_event.width_mm = width; + wlr_event.height_mm = height; + wlr_event.x_mm = wl_fixed_to_double(surface_x); + wlr_event.y_mm = wl_fixed_to_double(surface_y); + wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); } static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, @@ -73,7 +77,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, wlr_event.orientation = axis; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; // TODO + wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; wl_signal_emit(&dev->pointer->events.axis, &wlr_event); } @@ -182,7 +186,8 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, return NULL; } - // TODO: any way to retrieve those information? + devstate->backend = state; + int vendor = 0; int product = 0; const char *name = "wayland"; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 8138101c..df817598 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -39,16 +39,17 @@ struct wlr_output_state { }; struct wlr_input_device_state { - enum wlr_input_device_type type; + struct wlr_backend_state* backend; void *resource; }; struct wlr_pointer_state { - double surface_x; - double surface_y; + struct wlr_output *current_output; }; void wlr_wl_registry_poll(struct wlr_backend_state *backend); +struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend, + struct wl_surface *surface); extern const struct wl_seat_listener seat_listener;