From 454f2a84a8710cb9bcf69918d15c22e558a9592e Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 19 Jul 2018 11:35:00 +0200 Subject: tablet-v2 tablet_pad grab implementation Implement the basic logic for tablet-v2 tablet_pad's grabs. And plug in the default grab. Features like "holding" the focus should be implemented via grabs, like they are for pointer and keyboard. --- include/wlr/types/wlr_tablet_v2.h | 62 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index afa74d05..0b659f57 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -10,6 +10,14 @@ /* This can probably be even lower,the tools don't have a lot of buttons */ #define WLR_TABLET_V2_TOOL_BUTTONS_CAP 16 +struct wlr_tablet_pad_v2_grab_interface; + +struct wlr_tablet_pad_v2_grab { + const struct wlr_tablet_pad_v2_grab_interface *interface; + struct wlr_tablet_v2_tablet_pad *pad; + void *data; +}; + struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -70,6 +78,8 @@ struct wlr_tablet_v2_tablet_pad { struct wl_listener pad_destroy; struct wlr_tablet_pad_client_v2 *current_client; + struct wlr_tablet_pad_v2_grab *grab; + struct wlr_tablet_pad_v2_grab default_grab; struct { struct wl_signal button_feedback; // struct wlr_tablet_v2_event_feedback @@ -155,7 +165,7 @@ void wlr_send_tablet_v2_tablet_pad_button( struct wlr_tablet_v2_tablet_pad *pad, size_t button, uint32_t time, enum zwp_tablet_pad_v2_button_state state); -void wlr_send_tablet_v2_tablet_pad_strip( struct wlr_tablet_v2_tablet_pad *pad, +void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad, uint32_t strip, double position, bool finger, uint32_t time); void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, uint32_t ring, double position, bool finger, uint32_t time); @@ -166,6 +176,56 @@ uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pa uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, size_t group, uint32_t mode, uint32_t time); + +uint32_t wlr_tablet_v2_tablet_pad_notify_enter( + struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_tablet_v2_tablet_pad_notify_button( + struct wlr_tablet_v2_tablet_pad *pad, size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state); + +void wlr_tablet_v2_tablet_pad_notify_strip( + struct wlr_tablet_v2_tablet_pad *pad, + uint32_t strip, double position, bool finger, uint32_t time); +void wlr_tablet_v2_tablet_pad_notify_ring( + struct wlr_tablet_v2_tablet_pad *pad, + uint32_t ring, double position, bool finger, uint32_t time); + +uint32_t wlr_tablet_v2_tablet_pad_notify_leave( + struct wlr_tablet_v2_tablet_pad *pad, struct wlr_surface *surface); + +uint32_t wlr_tablet_v2_tablet_pad_notify_mode( + struct wlr_tablet_v2_tablet_pad *pad, + size_t group, uint32_t mode, uint32_t time); + +struct wlr_tablet_pad_v2_grab_interface { + uint32_t (*enter)( + struct wlr_tablet_pad_v2_grab *grab, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + + void (*button)(struct wlr_tablet_pad_v2_grab *grab,size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state); + + void (*strip)(struct wlr_tablet_pad_v2_grab *grab, + uint32_t strip, double position, bool finger, uint32_t time); + void (*ring)(struct wlr_tablet_pad_v2_grab *grab, + uint32_t ring, double position, bool finger, uint32_t time); + + uint32_t (*leave)(struct wlr_tablet_pad_v2_grab *grab, + struct wlr_surface *surface); + + uint32_t (*mode)(struct wlr_tablet_pad_v2_grab *grab, + size_t group, uint32_t mode, uint32_t time); + + void (*cancel)(struct wlr_tablet_pad_v2_grab *grab); +}; + +void wlr_tablet_v2_end_grab(struct wlr_tablet_v2_tablet_pad *pad); +void wlr_tablet_v2_start_grab(struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_pad_v2_grab *grab); + bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, struct wlr_surface *surface); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ -- cgit v1.2.3 From d5950255de146f50c1282af96f34020d298a78d9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 20 Jul 2018 10:18:22 +0200 Subject: 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(-) (limited to 'include') 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, +}; -- cgit v1.2.3 From f64962ace8ac2001b622af9571e9147813a6b3b9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Mon, 23 Jul 2018 10:08:43 +0200 Subject: tablet-v2 tool: Implement implicit grab Implement the tablet-v2 tablet tool's implicit grab semantics for buttons and tip. This avoids losing focus (to other [sub]surfaces) when a button is held, or the tip is down. This should help when the device is used close to a surface's border and would otherwise have to be very precise. --- include/wlr/types/wlr_tablet_v2.h | 3 + rootston/seat.c | 1 + types/tablet_v2/wlr_tablet_v2_tool.c | 136 +++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) (limited to 'include') diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 3d06bf56..e2a39392 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -240,6 +240,9 @@ struct wlr_tablet_tool_v2_grab_interface { 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); +void wlr_tablet_tool_v2_start_implicit_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 343720ae..f308da52 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -209,6 +209,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { if (event->state == WLR_TABLET_TOOL_TIP_DOWN) { wlr_tablet_v2_tablet_tool_notify_down(roots_tool->tablet_v2_tool); + wlr_tablet_tool_v2_start_implicit_grab(roots_tool->tablet_v2_tool); } else { wlr_tablet_v2_tablet_tool_notify_up(roots_tool->tablet_v2_tool); } diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 9165fb23..81c518ab 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -693,3 +693,139 @@ static const struct wlr_tablet_tool_v2_grab_interface default_tool_interface = { .button = default_tool_button, .cancel = default_tool_cancel, }; + +struct implicit_grab_state { + struct wlr_surface *original; + bool released; + + struct wlr_surface *focused; + struct wlr_tablet_v2_tablet *tablet; +}; + +static void check_and_release_implicit_grab(struct wlr_tablet_tool_v2_grab *grab) { + struct implicit_grab_state *state = grab->data; + /* Still button or tip pressed. We should hold the grab */ + if (grab->tool->is_down || grab->tool->num_buttons > 0 || state->released) { + return; + } + + state->released = true; + + /* We should still focus the same surface. Do nothing */ + if (state->original == state->focused) { + wlr_tablet_tool_v2_end_grab(grab->tool); + return; + } + + wlr_send_tablet_v2_tablet_tool_proximity_out(grab->tool); + if (state->focused) { + wlr_send_tablet_v2_tablet_tool_proximity_in(grab->tool, + state->tablet, state->focused); + } + + wlr_tablet_tool_v2_end_grab(grab->tool); +} + +static void implicit_tool_proximity_in( + struct wlr_tablet_tool_v2_grab *grab, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + + /* As long as we got an implicit grab, proximity won't change + * But should track the currently focused surface to change to it when + * the grab is released. + */ + struct implicit_grab_state *state = grab->data; + state->focused = surface; + state->tablet = tablet; +} + +static void implicit_tool_proximity_out(struct wlr_tablet_tool_v2_grab *grab) { + struct implicit_grab_state *state = grab->data; + state->focused = NULL; +} + +static void implicit_tool_down(struct wlr_tablet_tool_v2_grab *grab) { + wlr_send_tablet_v2_tablet_tool_down(grab->tool); +} + +static void implicit_tool_up(struct wlr_tablet_tool_v2_grab *grab) { + wlr_send_tablet_v2_tablet_tool_up(grab->tool); + check_and_release_implicit_grab(grab); +} + +/* Only send the motion event, when we are over the surface for now */ +static void implicit_tool_motion( + struct wlr_tablet_tool_v2_grab *grab, double x, double y) { + struct implicit_grab_state *state = grab->data; + if (state->focused != state->original) { + return; + } + + wlr_send_tablet_v2_tablet_tool_motion(grab->tool, x, y); +} + + +static void implicit_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); + check_and_release_implicit_grab(grab); +} + +static void implicit_tool_cancel(struct wlr_tablet_tool_v2_grab *grab) { + check_and_release_implicit_grab(grab); + free(grab->data); + free(grab); +} + +const struct wlr_tablet_tool_v2_grab_interface implicit_tool_interface = { + .proximity_in = implicit_tool_proximity_in, + .down = implicit_tool_down, + .up = implicit_tool_up, + .motion = implicit_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 = implicit_tool_proximity_out, + .button = implicit_tool_button, + .cancel = implicit_tool_cancel, +}; + +static bool tool_has_implicit_grab(struct wlr_tablet_v2_tablet_tool *tool) { + return tool->grab->interface == &implicit_tool_interface; +} + +void wlr_tablet_tool_v2_start_implicit_grab(struct wlr_tablet_v2_tablet_tool *tool) { + /* Durr */ + if (tool_has_implicit_grab(tool) || !tool->focused_surface) { + return; + } + + /* No current implicit grab */ + if (!(tool->is_down || tool->num_buttons > 0)) { + return; + } + + struct wlr_tablet_tool_v2_grab *grab = + calloc(1, sizeof(struct wlr_tablet_tool_v2_grab)); + if (!grab) { + return; + } + + grab->interface = &implicit_tool_interface; + grab->tool = tool; + struct implicit_grab_state *state = calloc(1, sizeof(struct implicit_grab_state)); + if (!state) { + free(grab); + return; + } + + state->original = tool->focused_surface; + grab->data = state; + + wlr_tablet_tool_v2_start_grab(tool, grab); +} -- cgit v1.2.3