diff options
author | nyorain <nyorain@gmail.com> | 2017-06-22 17:54:51 +0200 |
---|---|---|
committer | nyorain <nyorain@gmail.com> | 2017-06-22 17:55:00 +0200 |
commit | 272030652a73fd54472726e3ccd693402868fd35 (patch) | |
tree | 0078ea896a5c26806cd6bf130a3de781fecce6e6 /backend | |
parent | 0813c1dd39942613d9dd47a60922820b6f1610ef (diff) |
Implement absolute motion events for wayland
Diffstat (limited to 'backend')
-rw-r--r-- | backend/wayland/backend.c | 13 | ||||
-rw-r--r-- | backend/wayland/wl_seat.c | 39 |
2 files changed, 34 insertions, 18 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"; |