# Re: \[PATCH\] Improve Alps HID Touchpad code

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2016-06-23 00:11:04 
- List: linux-input
- Page: https://ratatoskr.run/linux-input/2016/06/8928135
- Thread: https://ratatoskr.run/linux-input/2016/06/8928130/t.md

```text
On Wed, Jun 22, 2016 at 01:11:08PM +0900, Masaki Ota wrote:
>  
> -		input_event(hdata->input, EV_KEY, BTN_LEFT, left);
> -		input_event(hdata->input, EV_KEY, BTN_RIGHT, right);
> -		input_event(hdata->input, EV_KEY, BTN_MIDDLE, middle);
> +		input_report_key(hdata->input, BTN_LEFT,
> +			data[1] & 0x1);
> +		input_report_key(hdata->input, BTN_RIGHT,
> +			(data[1] & 0x2) >> 1);
> +		input_report_key(hdata->input, BTN_MIDDLE,
> +			(data[1] & 0x4) >> 2);

There is no really need to do shifts as input_report_key() converts
value to 0/1 for you.

> +
> +		input_sync(hdata->input);
>  
>  		return 1;
>  
>  	case U1_SP_ABSOLUTE_REPORT_ID:
> -		sp_x = (data[2] | (data[3] << 8));
> -		sp_y = (data[4] | (data[5] << 8));
> -		sp_z = (data[6] | data[7]) & 0x7FFF;
> -		left = data[1] & 0x1;
> -		right = (data[1] & 0x2) >> 1;
> -		middle = (data[1] & 0x4) >> 2;
> +		sp_x = get_unaligned_le16(data+2);
> +		sp_y = get_unaligned_le16(data+4);
>  
>  		sp_x = sp_x / 8;
>  		sp_y = sp_y / 8;
>  
> -		input_event(priv->input2, EV_REL, REL_X, sp_x);
> -		input_event(priv->input2, EV_REL, REL_Y, sp_y);
> +		input_report_rel(hdata->input2, REL_X, sp_x);
> +		input_report_rel(hdata->input2, REL_Y, sp_y);
>  
> -		input_event(priv->input2, EV_KEY, BTN_LEFT, left);
> -		input_event(priv->input2, EV_KEY, BTN_RIGHT, right);
> -		input_event(priv->input2, EV_KEY, BTN_MIDDLE, middle);
> +		input_report_key(hdata->input2, BTN_LEFT,
> +			data[1] & 0x1);
> +		input_report_key(hdata->input2, BTN_RIGHT,
> +			(data[1] & 0x2) >> 1);
> +		input_report_key(hdata->input2, BTN_MIDDLE,
> +			(data[1] & 0x4) >> 2);

Same here. Maybe Jiri will fix it up by hand while appplying?

Otherwise:

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

-- 
Dmitry
```
