From d558745633e83b47e08f362f44164f3965dac2f7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 21 Sep 2017 18:30:04 -0400 Subject: [PATCH] Handle tablet motion in example compositor --- examples/compositor.c | 37 ++++++++++++++++++++++++++++++++++++ include/wlr/types/wlr_seat.h | 2 +- types/wlr_seat.c | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/examples/compositor.c b/examples/compositor.c index fa5f3286d..085cbb0e0 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -7,6 +7,8 @@ #include #include #include +// TODO: BSD et al +#include #include #include #include @@ -59,6 +61,10 @@ struct sample_state { struct wl_listener cursor_button; struct wl_listener cursor_axis; + struct wl_listener tool_axis; + struct wl_listener tool_tip; + struct wl_listener tool_button; + struct wl_listener new_xdg_surface_v6; struct wlr_xdg_surface_v6 *focused_surface; @@ -431,6 +437,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { event->button, event->state); } +static void handle_tool_axis(struct wl_listener *listener, void *data) { + struct sample_state *sample = + wl_container_of(listener, sample, tool_axis); + struct wlr_event_tablet_tool_axis *event = data; + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && + (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(sample->cursor, event->device, + event->x_mm / event->width_mm, event->y_mm / event->height_mm); + update_pointer_position(sample, event->time_sec); + } +} + +static void handle_tool_tip(struct wl_listener *listener, void *data) { + struct sample_state *sample = + wl_container_of(listener, sample, tool_tip); + struct wlr_event_tablet_tool_tip *event = data; + + struct wlr_xdg_surface_v6 *surface = + example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y); + example_set_focused_surface(sample, surface); + + wlr_seat_pointer_send_button(sample->wl_seat, event->time_sec, + BTN_MOUSE, event->state); +} + static void handle_input_add(struct compositor_state *state, struct wlr_input_device *device) { struct sample_state *sample = state->data; @@ -528,6 +559,12 @@ int main(int argc, char *argv[]) { wl_signal_add(&state.cursor->events.axis, &state.cursor_axis); state.cursor_axis.notify = handle_cursor_axis; + wl_signal_add(&state.cursor->events.tablet_tool_axis, &state.tool_axis); + state.tool_axis.notify = handle_tool_axis; + + wl_signal_add(&state.cursor->events.tablet_tool_tip, &state.tool_tip); + state.tool_tip.notify = handle_tool_tip; + compositor_init(&compositor); state.renderer = wlr_gles2_renderer_create(compositor.backend); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 221e4489c..4b433ccb7 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -107,6 +107,6 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, * button event are surface-local. */ void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time, - uint32_t button, enum wlr_button_state state); + uint32_t button, uint32_t state); #endif diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 411c1182b..9a254b357 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -338,7 +338,7 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, } void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time, - uint32_t button, enum wlr_button_state state) { + uint32_t button, uint32_t state) { if (!wlr_seat->pointer_state.focused_handle) { // nobody to send the event to return;