[PATCH libinput] tablet: fix get_x_transformed() and get_y_transformed()

Peter Hutterer peter.hutterer at who-t.net
Sun Jul 20 16:24:36 PDT 2014


On Sun, Jul 20, 2014 at 04:41:29PM -0400, Stephen Chandler Paul wrote:
> After we changed libinput to report values in millimeters as opposed to raw
> coordinates, these two functions never got changed (probably because no one used
> them at the time). As a result, they would incorrectly try to scale the x and y
> axis values in millimeters to the specified height/width, instead of scaling the
> axis values in raw coordinates.
> 
> Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
> ---
>  src/evdev-tablet.c     | 13 +++++++++++++
>  src/evdev-tablet.h     |  2 ++
>  src/libinput-private.h |  8 ++++++++
>  src/libinput.c         | 26 ++++++++++++++++++++------
>  4 files changed, 43 insertions(+), 6 deletions(-)
> 
> diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
> index d1ad4bb..ca8b467 100644
> --- a/src/evdev-tablet.c
> +++ b/src/evdev-tablet.c
> @@ -141,7 +141,12 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
>  
>  		switch (a) {
>  		case LIBINPUT_TABLET_AXIS_X:
> +			tablet->raw_x = absinfo->value;
> +			tablet->axes[a] = evdev_convert_to_mm(absinfo,
> +							      absinfo->value);
> +			break;
>  		case LIBINPUT_TABLET_AXIS_Y:
> +			tablet->raw_y = absinfo->value;
>  			tablet->axes[a] = evdev_convert_to_mm(absinfo,
>  							      absinfo->value);
>  			break;

I think it'd be better here to just store the raw value in axes, then
convert on the fly when a caller requests it. There's no need for us to
store both the converted and the original value.

Cheers,
   Peter


> @@ -168,6 +173,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
>  		tablet_notify_axis(base,
>  				   time,
>  				   tool,
> +				   tablet->raw_x,
> +				   tablet->raw_y,
>  				   tablet->changed_axes,
>  				   tablet->axes);
>  
> @@ -315,6 +322,8 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet,
>  		tablet_notify_button(base,
>  				     time,
>  				     tool,
> +				     tablet->raw_x,
> +				     tablet->raw_y,
>  				     tablet->axes,
>  				     num_button + button_base - 1,
>  				     state);
> @@ -395,6 +404,8 @@ tablet_flush(struct tablet_dispatch *tablet,
>  		tablet_notify_proximity_in(&device->base,
>  					   time,
>  					   tool,
> +					   tablet->raw_x,
> +					   tablet->raw_y,
>  					   tablet->axes);
>  		tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
>  	}
> @@ -427,6 +438,8 @@ tablet_flush(struct tablet_dispatch *tablet,
>  		tablet_notify_proximity_out(&device->base,
>  					    time,
>  					    tool,
> +					    tablet->raw_x,
> +					    tablet->raw_y,
>  					    tablet->axes);
>  		tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
>  		tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
> diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
> index 1b53d20..bfbfb61 100644
> --- a/src/evdev-tablet.h
> +++ b/src/evdev-tablet.h
> @@ -48,6 +48,8 @@ struct tablet_dispatch {
>  	unsigned char status;
>  	unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
>  	double axes[LIBINPUT_TABLET_AXIS_CNT];
> +	int32_t raw_x;
> +	int32_t raw_y;
>  
>  	struct button_state button_state;
>  	struct button_state prev_button_state;
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index dbdf5e6..6656bb5 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -215,6 +215,8 @@ void
>  tablet_notify_axis(struct libinput_device *device,
>  		   uint32_t time,
>  		   struct libinput_tool *tool,
> +		   int32_t raw_x,
> +		   int32_t raw_y,
>  		   unsigned char *changed_axes,
>  		   double *axes);
>  
> @@ -222,18 +224,24 @@ void
>  tablet_notify_proximity_in(struct libinput_device *device,
>  			   uint32_t time,
>  			   struct libinput_tool *tool,
> +			   int32_t raw_x,
> +			   int32_t raw_y,
>  			   double *axes);
>  
>  void
>  tablet_notify_proximity_out(struct libinput_device *device,
>  			    uint32_t time,
>  			    struct libinput_tool *tool,
> +			    int32_t raw_x,
> +			    int32_t raw_y,
>  			    double *axes);
>  
>  void
>  tablet_notify_button(struct libinput_device *device,
>  		     uint32_t time,
>  		     struct libinput_tool *tool,
> +		     int32_t raw_x,
> +		     int32_t raw_y,
>  		     double *axes,
>  		     int32_t button,
>  		     enum libinput_button_state state);
> diff --git a/src/libinput.c b/src/libinput.c
> index 5d26bc9..c0e1600 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -87,6 +87,8 @@ struct libinput_event_tablet {
>  	uint32_t seat_button_count;
>  	uint32_t time;
>  	double axes[LIBINPUT_TABLET_AXIS_CNT];
> +	int32_t raw_x;
> +	int32_t raw_y;
>  	unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
>  	struct libinput_tool *tool;
>  };
> @@ -521,9 +523,7 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event,
>  	if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS)
>  		return 0;
>  
> -	return evdev_device_transform_x(device,
> -					event->axes[LIBINPUT_TABLET_AXIS_X],
> -					width);
> +	return evdev_device_transform_x(device, event->raw_x, width);
>  }
>  
>  LIBINPUT_EXPORT double
> @@ -536,9 +536,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event,
>  	if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS)
>  		return 0;
>  
> -	return evdev_device_transform_y(device,
> -					event->axes[LIBINPUT_TABLET_AXIS_Y],
> -					height);
> +	return evdev_device_transform_y(device, event->raw_y, height);
>  }
>  
>  LIBINPUT_EXPORT struct libinput_tool *
> @@ -1231,6 +1229,8 @@ void
>  tablet_notify_axis(struct libinput_device *device,
>  		   uint32_t time,
>  		   struct libinput_tool *tool,
> +		   int32_t raw_x,
> +		   int32_t raw_y,
>  		   unsigned char *changed_axes,
>  		   double *axes)
>  {
> @@ -1243,6 +1243,8 @@ tablet_notify_axis(struct libinput_device *device,
>  	*axis_event = (struct libinput_event_tablet) {
>  		.time = time,
>  		.tool = tool,
> +		.raw_x = raw_x,
> +		.raw_y = raw_y,
>  	};
>  
>  	memcpy(axis_event->changed_axes,
> @@ -1259,6 +1261,8 @@ void
>  tablet_notify_proximity_in(struct libinput_device *device,
>  			   uint32_t time,
>  			   struct libinput_tool *tool,
> +			   int32_t raw_x,
> +			   int32_t raw_y,
>  			   double *axes)
>  {
>  	struct libinput_event_tablet *proximity_in_event;
> @@ -1270,6 +1274,8 @@ tablet_notify_proximity_in(struct libinput_device *device,
>  	*proximity_in_event = (struct libinput_event_tablet) {
>  		.time = time,
>  		.tool = tool,
> +		.raw_x = raw_x,
> +		.raw_y = raw_y,
>  	};
>  	memcpy(proximity_in_event->axes,
>  	       axes,
> @@ -1284,6 +1290,8 @@ void
>  tablet_notify_proximity_out(struct libinput_device *device,
>  			    uint32_t time,
>  			    struct libinput_tool *tool,
> +			    int32_t raw_x,
> +			    int32_t raw_y,
>  			    double *axes)
>  {
>  	struct libinput_event_tablet *proximity_out_update_event;
> @@ -1295,6 +1303,8 @@ tablet_notify_proximity_out(struct libinput_device *device,
>  	*proximity_out_update_event = (struct libinput_event_tablet) {
>  		.time = time,
>  		.tool = tool,
> +		.raw_x = raw_x,
> +		.raw_y = raw_y,
>  	};
>  	memcpy(proximity_out_update_event->axes,
>  	       axes,
> @@ -1309,6 +1319,8 @@ void
>  tablet_notify_button(struct libinput_device *device,
>  		     uint32_t time,
>  		     struct libinput_tool *tool,
> +		     int32_t raw_x,
> +		     int32_t raw_y,
>  		     double *axes,
>  		     int32_t button,
>  		     enum libinput_button_state state)
> @@ -1327,6 +1339,8 @@ tablet_notify_button(struct libinput_device *device,
>  	*button_event = (struct libinput_event_tablet) {
>  		.time = time,
>  		.tool = tool,
> +		.raw_x = raw_x,
> +		.raw_y = raw_y,
>  		.button = button,
>  		.state = state,
>  		.seat_button_count = seat_button_count,
> -- 
> 1.8.5.5
> 


More information about the wayland-devel mailing list