From d5950255de146f50c1282af96f34020d298a78d9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 20 Jul 2018 10:18:22 +0200 Subject: [PATCH] tablet-v2 tablet_tool grab implementation Implement the basic logic for tablet-v2 tablet_tool's grabs. And plug in the default grab. --- include/wlr/types/wlr_tablet_v2.h | 84 +++++++++++++ rootston/seat.c | 26 ++-- types/tablet_v2/wlr_tablet_v2_tool.c | 181 +++++++++++++++++++++++++++ 3 files changed, 278 insertions(+), 13 deletions(-) diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 0b659f57..3d06bf56 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -18,6 +18,14 @@ struct wlr_tablet_pad_v2_grab { void *data; }; +struct wlr_tablet_tool_v2_grab_interface; + +struct wlr_tablet_tool_v2_grab { + const struct wlr_tablet_tool_v2_grab_interface *interface; + struct wlr_tablet_v2_tablet_tool *tool; + void *data; +}; + struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -54,6 +62,9 @@ struct wlr_tablet_v2_tablet_tool { struct wlr_surface *focused_surface; struct wl_listener surface_destroy; + struct wlr_tablet_tool_v2_grab *grab; + struct wlr_tablet_tool_v2_grab default_grab; + uint32_t proximity_serial; bool is_down; uint32_t down_serial; @@ -156,6 +167,79 @@ void wlr_send_tablet_v2_tablet_tool_button( struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state); + + +void wlr_tablet_v2_tablet_tool_notify_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_tablet_v2_tablet_tool_notify_down(struct wlr_tablet_v2_tablet_tool *tool); +void wlr_tablet_v2_tablet_tool_notify_up(struct wlr_tablet_v2_tablet_tool *tool); + +void wlr_tablet_v2_tablet_tool_notify_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + +void wlr_tablet_v2_tablet_tool_notify_pressure( + struct wlr_tablet_v2_tablet_tool *tool, double pressure); + +void wlr_tablet_v2_tablet_tool_notify_distance( + struct wlr_tablet_v2_tablet_tool *tool, double distance); + +void wlr_tablet_v2_tablet_tool_notify_tilt( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + +void wlr_tablet_v2_tablet_tool_notify_rotation( + struct wlr_tablet_v2_tablet_tool *tool, double degrees); + +void wlr_tablet_v2_tablet_tool_notify_slider( + struct wlr_tablet_v2_tablet_tool *tool, double position); + +void wlr_tablet_v2_tablet_tool_notify_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks); + +void wlr_tablet_v2_tablet_tool_notify_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool); + +void wlr_tablet_v2_tablet_tool_notify_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state); + + +struct wlr_tablet_tool_v2_grab_interface { + void (*proximity_in)( + struct wlr_tablet_tool_v2_grab *grab, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + + void (*down)(struct wlr_tablet_tool_v2_grab *grab); + void (*up)(struct wlr_tablet_tool_v2_grab *grab); + + void (*motion)(struct wlr_tablet_tool_v2_grab *grab, double x, double y); + + void (*pressure)(struct wlr_tablet_tool_v2_grab *grab, double pressure); + + void (*distance)(struct wlr_tablet_tool_v2_grab *grab, double distance); + + void (*tilt)(struct wlr_tablet_tool_v2_grab *grab, double x, double y); + + void (*rotation)(struct wlr_tablet_tool_v2_grab *grab, double degrees); + + void (*slider)(struct wlr_tablet_tool_v2_grab *grab, double position); + + void (*wheel)(struct wlr_tablet_tool_v2_grab *grab, double degrees, int32_t clicks); + + void (*proximity_out)(struct wlr_tablet_tool_v2_grab *grab); + + void (*button)( + struct wlr_tablet_tool_v2_grab *grab, uint32_t button, + enum zwp_tablet_pad_v2_button_state state); + void (*cancel)(struct wlr_tablet_tool_v2_grab *grab); +}; + +void wlr_tablet_tool_v2_start_grab(struct wlr_tablet_v2_tablet_tool *tool, struct wlr_tablet_tool_v2_grab *grab); +void wlr_tablet_tool_v2_end_grab(struct wlr_tablet_v2_tablet_tool *tool); + uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_v2_tablet *tablet, diff --git a/rootston/seat.c b/rootston/seat.c index 54aae49f..343720ae 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -129,21 +129,21 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, struct roots_tablet_tool *roots_tool = tool->data; if (!surface) { - wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + wlr_tablet_v2_tablet_tool_notify_proximity_out(roots_tool->tablet_v2_tool); /* XXX: TODO: Fallback pointer semantics */ return; } if (!wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) { - wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + wlr_tablet_v2_tablet_tool_notify_proximity_out(roots_tool->tablet_v2_tool); /* XXX: TODO: Fallback pointer semantics */ return; } - wlr_send_tablet_v2_tablet_tool_proximity_in(roots_tool->tablet_v2_tool, + wlr_tablet_v2_tablet_tool_notify_proximity_in(roots_tool->tablet_v2_tool, tablet->tablet_v2, surface); - wlr_send_tablet_v2_tablet_tool_motion(roots_tool->tablet_v2_tool, sx, sy); + wlr_tablet_v2_tablet_tool_notify_motion(roots_tool->tablet_v2_tool, sx, sy); } static void handle_tool_axis(struct wl_listener *listener, void *data) { @@ -169,32 +169,32 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { event->x, event->y, event->dx, event->dy); if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { - wlr_send_tablet_v2_tablet_tool_pressure( + wlr_tablet_v2_tablet_tool_notify_pressure( roots_tool->tablet_v2_tool, event->pressure); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { - wlr_send_tablet_v2_tablet_tool_distance( + wlr_tablet_v2_tablet_tool_notify_distance( roots_tool->tablet_v2_tool, event->distance); } if (event->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) { - wlr_send_tablet_v2_tablet_tool_tilt( + wlr_tablet_v2_tablet_tool_notify_tilt( roots_tool->tablet_v2_tool, event->tilt_x, event->tilt_y); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) { - wlr_send_tablet_v2_tablet_tool_rotation( + wlr_tablet_v2_tablet_tool_notify_rotation( roots_tool->tablet_v2_tool, event->rotation); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) { - wlr_send_tablet_v2_tablet_tool_slider( + wlr_tablet_v2_tablet_tool_notify_slider( roots_tool->tablet_v2_tool, event->slider); } if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { - wlr_send_tablet_v2_tablet_tool_wheel( + wlr_tablet_v2_tablet_tool_notify_wheel( roots_tool->tablet_v2_tool, event->wheel_delta, 0); } } @@ -208,9 +208,9 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { struct roots_tablet_tool *roots_tool = event->tool->data; if (event->state == WLR_TABLET_TOOL_TIP_DOWN) { - wlr_send_tablet_v2_tablet_tool_down(roots_tool->tablet_v2_tool); + wlr_tablet_v2_tablet_tool_notify_down(roots_tool->tablet_v2_tool); } else { - wlr_send_tablet_v2_tablet_tool_up(roots_tool->tablet_v2_tool); + wlr_tablet_v2_tablet_tool_notify_up(roots_tool->tablet_v2_tool); } } @@ -235,7 +235,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_button *event = data; struct roots_tablet_tool *roots_tool = event->tool->data; - wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, + wlr_tablet_v2_tablet_tool_notify_button(roots_tool->tablet_v2_tool, (enum zwp_tablet_pad_v2_button_state)event->button, (enum zwp_tablet_pad_v2_button_state)event->state); } diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 62c00a37..9165fb23 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -12,6 +12,8 @@ #include #include +static const struct wlr_tablet_tool_v2_grab_interface default_tool_interface; + static const struct wlr_surface_role tablet_tool_cursor_surface_role = { .name = "wp_tablet_tool-cursor", }; @@ -206,6 +208,9 @@ struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create( tool->wlr_tool = wlr_tool; wl_list_init(&tool->clients); + tool->default_grab.tool = tool; + tool->default_grab.interface = &default_tool_interface; + tool->grab = &tool->default_grab; tool->tool_destroy.notify = handle_wlr_tablet_tool_destroy; @@ -512,3 +517,179 @@ void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool) { } } + +void wlr_tablet_v2_tablet_tool_notify_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + if (tool->grab->interface->proximity_in) { + tool->grab->interface->proximity_in(tool->grab, tablet, surface); + } +} + +void wlr_tablet_v2_tablet_tool_notify_down(struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->grab->interface->down) { + tool->grab->interface->down(tool->grab); + } +} +void wlr_tablet_v2_tablet_tool_notify_up(struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->grab->interface->up) { + tool->grab->interface->up(tool->grab); + } +} + +void wlr_tablet_v2_tablet_tool_notify_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (tool->grab->interface->motion) { + tool->grab->interface->motion(tool->grab, x, y); + } +} + +void wlr_tablet_v2_tablet_tool_notify_pressure( + struct wlr_tablet_v2_tablet_tool *tool, double pressure) { + if (tool->grab->interface->pressure) { + tool->grab->interface->pressure(tool->grab, pressure); + } +} + +void wlr_tablet_v2_tablet_tool_notify_distance( + struct wlr_tablet_v2_tablet_tool *tool, double distance) { + if (tool->grab->interface->distance) { + tool->grab->interface->distance(tool->grab, distance); + } +} + +void wlr_tablet_v2_tablet_tool_notify_tilt( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (tool->grab->interface->tilt) { + tool->grab->interface->tilt(tool->grab, x, y); + } +} + +void wlr_tablet_v2_tablet_tool_notify_rotation( + struct wlr_tablet_v2_tablet_tool *tool, double degrees) { + if (tool->grab->interface->rotation) { + tool->grab->interface->rotation(tool->grab, degrees); + } +} + +void wlr_tablet_v2_tablet_tool_notify_slider( + struct wlr_tablet_v2_tablet_tool *tool, double position) { + if (tool->grab->interface->slider) { + tool->grab->interface->slider(tool->grab, position); + } +} + +void wlr_tablet_v2_tablet_tool_notify_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks) { + if (tool->grab->interface->wheel) { + tool->grab->interface->wheel(tool->grab, degrees, clicks); + } +} + +void wlr_tablet_v2_tablet_tool_notify_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->grab->interface->proximity_out) { + tool->grab->interface->proximity_out(tool->grab); + } +} + +void wlr_tablet_v2_tablet_tool_notify_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state) { + if (tool->grab->interface->button) { + tool->grab->interface->button(tool->grab, button, state); + } +} + +void wlr_tablet_tool_v2_start_grab(struct wlr_tablet_v2_tablet_tool *tool, struct wlr_tablet_tool_v2_grab *grab) { + wlr_tablet_tool_v2_end_grab(tool); + tool->grab = grab; +} + +void wlr_tablet_tool_v2_end_grab(struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->grab->interface->cancel) { + tool->grab->interface->cancel(tool->grab); + } + tool->grab = &tool->default_grab; +} + + +static void default_tool_proximity_in( + struct wlr_tablet_tool_v2_grab *grab, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + wlr_send_tablet_v2_tablet_tool_proximity_in(grab->tool, tablet, surface); +} + +static void default_tool_down(struct wlr_tablet_tool_v2_grab *grab) { + wlr_send_tablet_v2_tablet_tool_down(grab->tool); +} +static void default_tool_up(struct wlr_tablet_tool_v2_grab *grab) { + wlr_send_tablet_v2_tablet_tool_up(grab->tool); +} + +static void default_tool_motion( + struct wlr_tablet_tool_v2_grab *grab, double x, double y) { + wlr_send_tablet_v2_tablet_tool_motion(grab->tool, x, y); +} + +static void default_tool_pressure( + struct wlr_tablet_tool_v2_grab *grab, double pressure) { + wlr_send_tablet_v2_tablet_tool_pressure(grab->tool, pressure); +} + +static void default_tool_distance( + struct wlr_tablet_tool_v2_grab *grab, double distance) { + wlr_send_tablet_v2_tablet_tool_distance(grab->tool, distance); +} + +static void default_tool_tilt( + struct wlr_tablet_tool_v2_grab *grab, double x, double y) { + wlr_send_tablet_v2_tablet_tool_tilt(grab->tool, x, y); +} + +static void default_tool_rotation( + struct wlr_tablet_tool_v2_grab *grab, double degrees) { + wlr_send_tablet_v2_tablet_tool_rotation(grab->tool, degrees); +} + +static void default_tool_slider( + struct wlr_tablet_tool_v2_grab *grab, double position) { + wlr_send_tablet_v2_tablet_tool_slider(grab->tool, position); +} + +static void default_tool_wheel( + struct wlr_tablet_tool_v2_grab *grab, double degrees, int32_t clicks) { + wlr_send_tablet_v2_tablet_tool_wheel(grab->tool, degrees, clicks); +} + +static void default_tool_proximity_out(struct wlr_tablet_tool_v2_grab *grab) { + wlr_send_tablet_v2_tablet_tool_proximity_out(grab->tool); +} + +static void default_tool_button( + struct wlr_tablet_tool_v2_grab *grab, uint32_t button, + enum zwp_tablet_pad_v2_button_state state) { + wlr_send_tablet_v2_tablet_tool_button(grab->tool, button, state); +} + +static void default_tool_cancel(struct wlr_tablet_tool_v2_grab *grab) { + /* Do nothing. Default grab can't be canceled */ +} + +static const struct wlr_tablet_tool_v2_grab_interface default_tool_interface = { + .proximity_in = default_tool_proximity_in, + .down = default_tool_down, + .up = default_tool_up, + .motion = default_tool_motion, + .pressure = default_tool_pressure, + .distance = default_tool_distance, + .tilt = default_tool_tilt, + .rotation = default_tool_rotation, + .slider = default_tool_slider, + .wheel = default_tool_wheel, + .proximity_out = default_tool_proximity_out, + .button = default_tool_button, + .cancel = default_tool_cancel, +};