diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-04-27 03:13:01 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-04-27 18:34:09 +0200 |
commit | ad28f5753315f8aefd1fb848c5975bc58013131b (patch) | |
tree | 292e71676127e5d382a749ca6ba971ab04fe1db2 | |
parent | e51d507799eddf103f7f2df09c2c4bdcd0864ec9 (diff) |
input/tablet: fix up updated axes after rotation
In the case that only one axis received an event, rotating the input can
cause the change to actually happen on the other axis, as far as clients
are concerned.
This commit updates the axes flags to be consistent post-rotation.
Fixes swaywm/sway#4776.
-rw-r--r-- | types/wlr_cursor.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index c7ada3d5..429acd6d 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -539,11 +539,33 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { struct wlr_cursor_device *device; device = wl_container_of(listener, device, tablet_tool_axis); - struct wlr_output *output = - get_mapped_output(device); + struct wlr_output *output = get_mapped_output(device); if (output) { - apply_output_transform(&event->x, &event->y, output->transform); + // In the case that only one axis received an event, rotating the input can + // cause the change to actually happen on the other axis, as far as clients + // are concerned. + // + // Here, we feed apply_output_transform NAN on the axis that didn't change, + // and remap the axes flags based on whether it returns NAN itself. + double x = event->updated_axes & WLR_TABLET_TOOL_AXIS_X ? event->x : NAN; + double y = event->updated_axes & WLR_TABLET_TOOL_AXIS_Y ? event->y : NAN; + + apply_output_transform(&x, &y, output->transform); + + event->updated_axes &= ~(WLR_TABLET_TOOL_AXIS_X | WLR_TABLET_TOOL_AXIS_Y); + event->x = event->y = 0; + + if (!isnan(x)) { + event->updated_axes |= WLR_TABLET_TOOL_AXIS_X; + event->x = x; + } + + if (!isnan(y)) { + event->updated_axes |= WLR_TABLET_TOOL_AXIS_Y; + event->y = y; + } } + wlr_signal_emit_safe(&device->cursor->events.tablet_tool_axis, event); } |