Merge branch 'merged-scroll-events'
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 14 Jan 2015 23:48:29 +0000 (09:48 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 15 Jan 2015 00:11:44 +0000 (10:11 +1000)
This is merged on top of the wheel normalization patches. Those introduced an
axis source and an extra "discrete" value to the various internal and external
APIs. This branch changed from a single value to passing dx/dy into all scroll
events.

The conflicts are to change everything to take x, y, x_discrete, y_discrete as
values (and the source axis mask of course).

Conflicts:
src/evdev-mt-touchpad-edge-scroll.c
src/evdev.c
src/libinput-private.h
src/libinput.c

1  2 
src/evdev-mt-touchpad-edge-scroll.c
src/evdev.c
src/libinput-private.h
src/libinput.c
src/libinput.h
src/libinput.sym
test/pointer.c

index 8605034c83c8072e477a8912f6e1742ad35cf37a,6268986a77ff6c71e4fd6d4a095eb2449cf1d9b6..26a86141e6b9b26c815d7c1a286ef710b1e7413d
@@@ -325,10 -325,9 +325,10 @@@ tp_edge_scroll_post_events(struct tp_di
                                if (t->scroll.direction != -1) {
                                        /* Send stop scroll event */
                                        pointer_notify_axis(device, time,
-                                               t->scroll.direction,
+                                               AS_MASK(t->scroll.direction),
                                                LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-                                               0.0,
-                                               0);
 -                                              0.0, 0.0);
++                                              0.0, 0.0,
++                                              0, 0);
                                        t->scroll.direction = -1;
                                }
                                continue;
                if (fabs(*delta) < t->scroll.threshold)
                        continue;
  
-               pointer_notify_axis(device, time, axis,
+               pointer_notify_axis(device, time,
+                                   AS_MASK(axis),
                                    LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-                                   *delta,
-                                   0);
 -                                  dx, dy);
++                                  dx, dy,
++                                  0, 0);
                t->scroll.direction = axis;
  
                tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED);
@@@ -371,10 -370,9 +372,10 @@@ tp_edge_scroll_stop_events(struct tp_di
        tp_for_each_touch(tp, t) {
                if (t->scroll.direction != -1) {
                        pointer_notify_axis(device, time,
-                                           t->scroll.direction,
+                                           AS_MASK(t->scroll.direction),
                                            LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
-                                           0.0,
-                                           0);
++                                          0.0, 0.0,
+                                           0.0, 0.0);
                        t->scroll.direction = -1;
                }
        }
diff --cc src/evdev.c
index 0e78381c38e4c5c5b4294c8e91b0020820f178fa,076db29f1949f797dc589b4d2c5b48b095c3059a..2d73d6906ab185f4b76a4978121ba66fbe2d0cee
@@@ -539,22 -539,20 +539,24 @@@ evdev_process_absolute_motion(struct ev
  static void
  evdev_notify_axis(struct evdev_device *device,
                  uint64_t time,
-                 enum libinput_pointer_axis axis,
+                 uint32_t axes,
                  enum libinput_pointer_axis_source source,
-                 double value,
-                 double discrete)
 -                double x, double y)
++                double x, double y,
++                double x_discrete, double y_discrete)
  {
        if (device->scroll.natural_scrolling_enabled) {
-               value *= -1;
-               discrete *= -1;
+               x *= -1;
+               y *= -1;
++              x_discrete *= -1;
++              y_discrete *= -1;
        }
  
        pointer_notify_axis(&device->base,
                            time,
-                           axis,
+                           axes,
                            source,
-                           value,
-                           discrete);
 -                          x, y);
++                          x, y,
++                          x_discrete, y_discrete);
  }
  
  static inline void
@@@ -579,20 -577,20 +581,24 @@@ evdev_process_relative(struct evdev_dev
                evdev_notify_axis(
                        device,
                        time,
-                       LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
+                       AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL),
                        LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
 -                      0,
 -                      -1 * e->value * device->scroll.wheel_click_angle);
++                      0.0,
 +                      -1 * e->value * device->scroll.wheel_click_angle,
++                      0.0,
 +                      -1 * e->value);
                break;
        case REL_HWHEEL:
                evdev_flush_pending_event(device, time);
                evdev_notify_axis(
                        device,
                        time,
-                       LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                       AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL),
                        LIBINPUT_POINTER_AXIS_SOURCE_WHEEL,
                        e->value * device->scroll.wheel_click_angle,
-                       e->value);
 -                      0);
++                      0.0,
++                      e->value,
++                      0.0);
                break;
        }
  }
@@@ -1863,27 -1861,20 +1869,20 @@@ evdev_post_scroll(struct evdev_device *
        /* We use the trigger to enable, but the delta from this event for
         * the actual scroll movement. Otherwise we get a jump once
         * scrolling engages */
-       if (dy != 0.0 &&
-           evdev_is_scrolling(device,
-                              LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
-               evdev_notify_axis(device,
-                                 time,
-                                 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
-                                 source,
-                                 dy,
-                                 0);
-       }
+       if (!evdev_is_scrolling(device,
+                              LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
+               dy = 0.0;
+       if (!evdev_is_scrolling(device,
+                              LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
+               dx = 0.0;
  
-       if (dx != 0.0 &&
-           evdev_is_scrolling(device,
-                              LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
+       if (dx != 0.0 || dy != 0.0)
                evdev_notify_axis(device,
                                  time,
-                                 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                                 device->scroll.direction,
                                  source,
--                                dx,
-                                 0);
-       }
 -                                dy);
++                                dx, dy,
++                                0.0, 0.0);
  }
  
  void
@@@ -1892,18 -1883,12 +1891,13 @@@ evdev_stop_scroll(struct evdev_device *
                  enum libinput_pointer_axis_source source)
  {
        /* terminate scrolling with a zero scroll event */
-       if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
-               pointer_notify_axis(&device->base,
-                                   time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
-                                   source,
-                                   0, 0);
-       if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
+       if (device->scroll.direction != 0)
                pointer_notify_axis(&device->base,
                                    time,
-                                   LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                                   device->scroll.direction,
                                    source,
-                                   0, 0);
++                                  0.0, 0.0,
+                                   0.0, 0.0);
  
        device->scroll.buildup_horizontal = 0;
        device->scroll.buildup_vertical = 0;
index 415e53e32a214b7c15f8f939da34ff853e12e0bf,0cb9b259ce9e8154bc10f1e31931c0055cc90d72..012c82d0bfd76be6fb00046ddf781c95905ea9c4
@@@ -278,10 -278,9 +278,12 @@@ pointer_notify_button(struct libinput_d
  void
  pointer_notify_axis(struct libinput_device *device,
                    uint64_t time,
-                   enum libinput_pointer_axis axis,
+                   uint32_t axes,
                    enum libinput_pointer_axis_source source,
-                   double value,
-                   double discrete);
 -                  double x, double y);
++                  double x,
++                  double y,
++                  double x_discrete,
++                  double y_discrete);
  
  void
  touch_notify_touch_down(struct libinput_device *device,
diff --cc src/libinput.c
index 37df9626278ddcef5973ec4886978af9939c0d74,2442b065dfc550fb8a8eca00bc777d08b9443ae6..00ab5f21dbc70d2870cae58d8a9cf57efc874492
@@@ -59,6 -59,6 +59,8 @@@ struct libinput_event_pointer 
        uint32_t time;
        double x;
        double y;
++      double x_discrete;
++      double y_discrete;
        double dx_unaccel;
        double dy_unaccel;
        uint32_t button;
@@@ -387,17 -393,28 +395,50 @@@ libinput_event_pointer_has_axis(struct 
  }
  
  LIBINPUT_EXPORT double
- libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
+ libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event,
+                                     enum libinput_pointer_axis axis)
  {
-       return event->value;
+       struct libinput *libinput = event->base.device->seat->libinput;
+       double value = 0;
+       if (!libinput_event_pointer_has_axis(event, axis)) {
+               log_bug_client(libinput, "value requested for unset axis\n");
+       } else {
+               switch (axis) {
+               case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
+                       value = event->x;
+                       break;
+               case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
+                       value = event->y;
+                       break;
+               }
+       }
+       return value;
  }
  
- libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event)
 +LIBINPUT_EXPORT double
-       return event->discrete;
++libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event,
++                                             enum libinput_pointer_axis axis)
 +{
++      struct libinput *libinput = event->base.device->seat->libinput;
++      double value = 0;
++
++      if (!libinput_event_pointer_has_axis(event, axis)) {
++              log_bug_client(libinput, "value requested for unset axis\n");
++      } else {
++              switch (axis) {
++              case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
++                      value = event->x_discrete;
++                      break;
++              case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
++                      value = event->y_discrete;
++                      break;
++              }
++      }
++      return value;
 +}
 +
  LIBINPUT_EXPORT enum libinput_pointer_axis_source
  libinput_event_pointer_get_axis_source(struct libinput_event_pointer *event)
  {
@@@ -999,10 -1016,9 +1040,10 @@@ pointer_notify_button(struct libinput_d
  void
  pointer_notify_axis(struct libinput_device *device,
                    uint64_t time,
-                   enum libinput_pointer_axis axis,
+                   uint32_t axes,
                    enum libinput_pointer_axis_source source,
-                   double value,
-                   double discrete)
 -                  double x, double y)
++                  double x, double y,
++                  double x_discrete, double y_discrete)
  {
        struct libinput_event_pointer *axis_event;
  
  
        *axis_event = (struct libinput_event_pointer) {
                .time = time,
-               .axis = axis,
-               .value = value,
+               .x = x,
+               .y = y,
                .source = source,
-               .discrete = discrete,
+               .axes = axes,
++              .x_discrete = x_discrete,
++              .y_discrete = y_discrete,
        };
  
        post_device_event(device, time,
diff --cc src/libinput.h
index c6dd57e770c4d1ec1216b891cf9ed50288060ead,89cc0f0933679361405c7f3e7419884d52bd6be4..276660b97286cf7e47ada2b3d0267bea009c90f7
@@@ -683,11 -686,10 +686,12 @@@ libinput_event_pointer_has_axis(struct 
   * @ref LIBINPUT_EVENT_POINTER_AXIS.
   *
   * @return the axis value of this event
 + *
 + * @see libinput_event_pointer_get_axis_value_discrete
   */
  double
- libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event);
+ libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event,
+                                     enum libinput_pointer_axis axis);
  
  /**
   * @ingroup event_pointer
  enum libinput_pointer_axis_source
  libinput_event_pointer_get_axis_source(struct libinput_event_pointer *event);
  
- libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event);
 +/**
 + * @ingroup pointer
 + *
 + * Return the axis value in discrete steps for a given axis event. How a
 + * value translates into a discrete step depends on the source.
 + *
 + * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, the discrete
 + * value correspond to the number of physical mouse clicks.
 + *
 + * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS or @ref
 + * LIBINPUT_POINTER_AXIS_SOURCE_FINGER, the discrete value is always 0.
 + *
 + * @return The discrete value for the given event.
 + *
 + * @see libinput_event_pointer_get_axis_value
 + */
 +double
++libinput_event_pointer_get_axis_value_discrete(struct libinput_event_pointer *event,
++                                             enum libinput_pointer_axis axis);
 +
  /**
   * @ingroup event_pointer
   *
Simple merge
diff --cc test/pointer.c
index 2055c4137c9b57335853ed00c5e4c638f133effd,dd9ea0da2139ee4141c1f0bc67fd3e92363fbd2e..1af4f3850f48abf8efb52144c3c2e11509cd2380
@@@ -375,15 -373,15 +376,17 @@@ test_wheel_event(struct litest_device *
  
        ptrev = libinput_event_get_pointer_event(event);
        ck_assert(ptrev != NULL);
-       ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev),
-                        which == REL_WHEEL ?
+       axis = (which == REL_WHEEL) ?
                                LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL :
-                               LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
-       ck_assert_int_eq(libinput_event_pointer_get_axis_value(ptrev), expected);
+                               LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+       ck_assert_int_eq(libinput_event_pointer_get_axis_value(ptrev, axis),
+                        expected);
        ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
                         LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
-       ck_assert_int_eq(libinput_event_pointer_get_axis_value_discrete(ptrev),
++      ck_assert_int_eq(libinput_event_pointer_get_axis_value_discrete(ptrev, axis),
 +                       discrete);
        libinput_event_destroy(event);
  }