[PATCH] compositor-x11: convert (some) of X11 buttons to linux input

Pekka Paalanen ppaalanen at gmail.com
Thu Dec 8 07:16:32 PST 2011


On Thu,  8 Dec 2011 17:03:17 +0200
Tiago Vignatti <vignatti at freedesktop.org> wrote:

> From: Tiago Vignatti <tiago.vignatti at intel.com>
> 
> Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>

Reviewed-by: Pekka Paalanen <ppaalanen at gmail.com>

For the record, this patch:
- emits booboo instead of some arbitrary button events for wheel
  rotation, so wheel on x11 backend will need more fixing.
- on the x11 backend, swaps the middle and right mouse buttons, so that
  it will be same as with the drm backend.


> ---
>  compositor/compositor-x11.c |   31 +++++++++++++++++++++++++++++--
>  1 files changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c
> index 544d7e2..870d57a 100644
> --- a/compositor/compositor-x11.c
> +++ b/compositor/compositor-x11.c
> @@ -453,6 +453,31 @@ x11_compositor_find_output(struct x11_compositor
> *c, xcb_window_t window) return NULL;
>  }
>  
> +/*
> + * x11_to_rawinput - convert X11 button detail to linux input
> + */
> +static int
> +x11_to_rawinput(int detail)
> +{
> +	switch (detail) {
> +	case 1:
> +		return BTN_LEFT;
> +	case 2:
> +		return BTN_MIDDLE;
> +	case 3:
> +		return BTN_RIGHT;
> +	case 4:
> +	case 5:
> +		/* X11 sends wheel button up and down respectively
> as 4 and 5.
> +		 * But linux input treats as REL_WHEEL, therefore
> not button
> +		 * type at all. If we care about them we have to
> implement a
> +		 * different logic and forward as notify_motion.  */
> +		return -2;
> +	}
> +
> +	return -1;
> +}
> +
>  static int
>  x11_compositor_next_event(struct x11_compositor *c,
>  			  xcb_generic_event_t **event, uint32_t mask)
> @@ -556,13 +581,15 @@ x11_compositor_handle_event(int fd, uint32_t
> mask, void *data) button_press = (xcb_button_press_event_t *) event;
>  			notify_button(c->base.input_device,
>  				      wlsc_compositor_get_time(),
> -				      button_press->detail +
> BTN_LEFT - 1, 1);
> +
> x11_to_rawinput(button_press->detail),
> +				      1);
>  			break;
>  		case XCB_BUTTON_RELEASE:
>  			button_press = (xcb_button_press_event_t *)
> event; notify_button(c->base.input_device,
>  				      wlsc_compositor_get_time(),
> -				      button_press->detail +
> BTN_LEFT - 1, 0);
> +
> x11_to_rawinput(button_press->detail),
> +				      0);
>  			break;
>  
>  		case XCB_MOTION_NOTIFY:



More information about the wayland-devel mailing list