diff options
Diffstat (limited to 'sway')
| -rw-r--r-- | sway/input/cursor.c | 16 | ||||
| -rw-r--r-- | sway/input/seat.c | 8 | ||||
| -rw-r--r-- | sway/input/seatop_default.c | 20 | ||||
| -rw-r--r-- | sway/input/seatop_down.c | 24 | 
4 files changed, 67 insertions, 1 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 8121cc84..8de7d950 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -572,7 +572,19 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor,  	struct sway_seat *seat = cursor->seat;  	node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); -	if (surface && wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) { +	// The logic for whether we should send a tablet event or an emulated pointer +	// event is tricky. It comes down to: +	// * If we began a drag on a non-tablet surface (simulated_tool_tip_down), +	//   then we should continue sending emulated pointer events regardless of +	//   whether the surface currently under us accepts tablet or not. +	// * Otherwise, if we are over a surface that accepts tablet, then we should +	//   send tablet events. +	// * If we began a drag over a tablet surface, we should continue sending +	//   tablet events until the drag is released, even if we are now over a +	//   non-tablet surface. +	if (!cursor->simulated_tool_tip_down && +			((surface && wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) || +				wlr_tablet_tool_v2_has_implicit_grab(tool->tablet_v2_tool))) {  		seatop_tablet_tool_motion(seat, tool, time_msec, dx, dy);  	} else {  		wlr_tablet_v2_tablet_tool_notify_proximity_out(tool->tablet_v2_tool); @@ -680,6 +692,8 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) {  		wlr_tablet_v2_tablet_tool_notify_up(sway_tool->tablet_v2_tool);  	} + +	seatop_tablet_tool_tip(seat, sway_tool, event->time_msec, event->state);  }  static struct sway_tablet *get_tablet_for_device(struct sway_cursor *cursor, diff --git a/sway/input/seat.c b/sway/input/seat.c index 233267e0..e5f15613 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1471,6 +1471,14 @@ void seatop_pointer_axis(struct sway_seat *seat,  	}  } +void seatop_tablet_tool_tip(struct sway_seat *seat, +		struct sway_tablet_tool *tool, uint32_t time_msec, +		enum wlr_tablet_tool_tip_state state) { +	if (seat->seatop_impl->tablet_tool_tip) { +		seat->seatop_impl->tablet_tool_tip(seat, tool, time_msec, state); +	} +} +  void seatop_tablet_tool_motion(struct sway_seat *seat,  		struct sway_tablet_tool *tool, uint32_t time_msec, double dx, double dy) {  	if (seat->seatop_impl->tablet_tool_motion) { diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index 64a17157..32c7318b 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -198,6 +198,25 @@ static void state_add_button(struct seatop_default_event *e, uint32_t button) {   * Functions used by handle_button  /   *--------------------------------*/ +static void handle_tablet_tool_tip(struct sway_seat *seat, +		struct sway_tablet_tool *tool, uint32_t time_msec, +		enum wlr_tablet_tool_tip_state state) { +	if (state != WLR_TABLET_TOOL_TIP_DOWN) { +		return; +	} + +	struct sway_cursor *cursor = seat->cursor; + +	struct wlr_surface *surface = NULL; +	double sx, sy; +	struct sway_node *node = node_at_coords(seat, +		cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + +	if (surface && node && node->type == N_CONTAINER) { +		seatop_begin_down(seat, node->sway_container, time_msec, sx, sy); +	} +} +  static void handle_button(struct sway_seat *seat, uint32_t time_msec,  		struct wlr_input_device *device, uint32_t button,  		enum wlr_button_state state) { @@ -649,6 +668,7 @@ static const struct sway_seatop_impl seatop_impl = {  	.button = handle_button,  	.pointer_motion = handle_pointer_motion,  	.pointer_axis = handle_pointer_axis, +	.tablet_tool_tip = handle_tablet_tool_tip,  	.tablet_tool_motion = handle_tablet_tool_motion,  	.rebase = handle_rebase,  	.allow_set_cursor = true, diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c index 358d5c59..dd8be6bf 100644 --- a/sway/input/seatop_down.c +++ b/sway/input/seatop_down.c @@ -1,6 +1,7 @@  #define _POSIX_C_SOURCE 200809L  #include <float.h>  #include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_tablet_v2.h>  #include "sway/input/cursor.h"  #include "sway/input/seat.h"  #include "sway/tree/view.h" @@ -49,6 +50,27 @@ static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec,  	}  } +static void handle_tablet_tool_tip(struct sway_seat *seat, +		struct sway_tablet_tool *tool, uint32_t time_msec, +		enum wlr_tablet_tool_tip_state state) { +	if (state == WLR_TABLET_TOOL_TIP_UP) { +		seatop_begin_default(seat); +	} +} + +static void handle_tablet_tool_motion(struct sway_seat *seat, +		struct sway_tablet_tool *tool, uint32_t time_msec, double dx, double dy) { +	struct seatop_down_event *e = seat->seatop_data; +	struct sway_container *con = e->con; +	if (seat_is_input_allowed(seat, con->view->surface)) { +		double moved_x = seat->cursor->cursor->x - e->ref_lx; +		double moved_y = seat->cursor->cursor->y - e->ref_ly; +		double sx = e->ref_con_lx + moved_x; +		double sy = e->ref_con_ly + moved_y; +		wlr_tablet_v2_tablet_tool_notify_motion(tool->tablet_v2_tool, sx, sy); +	} +} +  static void handle_unref(struct sway_seat *seat, struct sway_container *con) {  	struct seatop_down_event *e = seat->seatop_data;  	if (e->con == con) { @@ -60,6 +82,8 @@ static const struct sway_seatop_impl seatop_impl = {  	.button = handle_button,  	.pointer_motion = handle_pointer_motion,  	.pointer_axis = handle_pointer_axis, +	.tablet_tool_tip = handle_tablet_tool_tip, +	.tablet_tool_motion = handle_tablet_tool_motion,  	.unref = handle_unref,  	.allow_set_cursor = true,  };  | 
