[PATCH 2/3] evdev: avoid sending back to clients events generated by accelerometers

Kristian Høgsberg krh at bitplanet.net
Fri Aug 19 06:39:47 PDT 2011


On Fri, Aug 19, 2011 at 8:06 AM, Tiago Vignatti
<tiago.vignatti at intel.com> wrote:
> As a general rule we don't want to restrict the registration of any
> input devices in the compositor. So instead ignoring accelerometer type
> of devices, this patch introduces the concept of devices with cursor
> (has_cursor), where motion events will be generated only on those.

I'd rather just not add the device in this case.  Just return -1 from
evdev_configure_device() and then free the struct and return NULL in
evdev_input_device_create().  And dont use stdbool.h, we just use
ints.

Kristian

> We may want to adjust the protocol later for clients that care for
> these devices only, generating a special event.
>
> Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
> ---
> My reak motivation for doing so was that my accelerometer fd doesn't stop to
> spit data when the compositor is reading it. So I ended up with a wacky effect
> of the cursor moving all the time in random positions.
>
>  compositor/evdev.c |   19 ++++++++++++++++++-
>  1 files changed, 18 insertions(+), 1 deletions(-)
>
> diff --git a/compositor/evdev.c b/compositor/evdev.c
> index 150ca04..df82881 100644
> --- a/compositor/evdev.c
> +++ b/compositor/evdev.c
> @@ -20,6 +20,7 @@
>  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  */
>
> +#include <stdbool.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -41,6 +42,7 @@ struct evdev_input_device {
>        int fd;
>        int min_x, max_x, min_y, max_y;
>        int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value;
> +       int has_cursor;
>  };
>
>  static int
> @@ -183,7 +185,7 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
>        if (dx != 0 || dy != 0)
>                notify_motion(&device->master->base.input_device,
>                              time, x + dx, y + dy);
> -       if (absolute_event)
> +       if (absolute_event && device->has_cursor)
>                notify_motion(&device->master->base.input_device, time, x, y);
>
>        return 1;
> @@ -207,9 +209,14 @@ evdev_configure_device(struct evdev_input_device *device)
>        unsigned long ev_bits[NBITS(EV_MAX)];
>        unsigned long abs_bits[NBITS(ABS_MAX)];
>        unsigned long key_bits[NBITS(KEY_MAX)];
> +       bool has_key, has_abs;
> +
> +       has_key = 0;
> +       has_abs = 0;
>
>        ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits);
>        if (TEST_BIT(ev_bits, EV_ABS)) {
> +               has_abs = 1;
>                ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)),
>                      abs_bits);
>                if (TEST_BIT(abs_bits, ABS_X)) {
> @@ -224,12 +231,21 @@ evdev_configure_device(struct evdev_input_device *device)
>                }
>        }
>        if (TEST_BIT(ev_bits, EV_KEY)) {
> +               has_key = 1;
>                ioctl(device->fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)),
>                      key_bits);
>                if (TEST_BIT(key_bits, BTN_TOOL_FINGER) &&
>                             !TEST_BIT(key_bits, BTN_TOOL_PEN))
>                        device->is_touchpad = 1;
>        }
> +
> +       /* This rule tries to catch accelerometer devices. We simply mark it as
> +        * device without cursor, so later in evdev_input_device_data ->
> +        * notify_motion, the compositor refuses to send it back to clients. We
> +        * may want to adjust the protocol later adding a proper event for
> +        * dealing with accelerometers */
> +       if (has_abs && !has_key)
> +               device->has_cursor = 0;
>  }
>
>  static struct evdev_input_device *
> @@ -248,6 +264,7 @@ evdev_input_device_create(struct evdev_input *master,
>        device->new_y = 1;
>        device->master = master;
>        device->is_touchpad = 0;
> +       device->has_cursor = 1;
>
>        device->fd = open(path, O_RDONLY);
>        if (device->fd < 0) {
> --
> 1.7.2.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>


More information about the wayland-devel mailing list