evdev: keep the absinfo struct around instead of min/max
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 19 Jun 2014 01:11:36 +0000 (11:11 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 19 Jun 2014 02:00:58 +0000 (12:00 +1000)
We'll need that later for conversion to mm.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
src/evdev-mt-touchpad-buttons.c
src/evdev-mt-touchpad.c
src/evdev.c
src/evdev.h

index ce48ed0b8f1eea1b85f07ee224d96f1a09aa451c..45d5d703d46323cb628b4d1c9b63167c99b90d3f 100644 (file)
@@ -565,6 +565,7 @@ tp_init_buttons(struct tp_dispatch *tp,
        struct tp_touch *t;
        int width, height;
        double diagonal;
+       const struct input_absinfo *absinfo_x, *absinfo_y;
 
        tp->buttons.is_clickpad = libevdev_has_property(device->evdev,
                                                        INPUT_PROP_BUTTONPAD);
@@ -580,8 +581,11 @@ tp_init_buttons(struct tp_dispatch *tp,
                        log_bug_kernel("non clickpad without right button?\n");
        }
 
-       width = abs(device->abs.max_x - device->abs.min_x);
-       height = abs(device->abs.max_y - device->abs.min_y);
+       absinfo_x = device->abs.absinfo_x;
+       absinfo_y = device->abs.absinfo_y;
+
+       width = abs(absinfo_x->maximum - absinfo_x->minimum);
+       height = abs(absinfo_y->maximum - absinfo_y->minimum);
        diagonal = sqrt(width*width + height*height);
 
        tp->buttons.motion_dist = diagonal * DEFAULT_BUTTON_MOTION_THRESHOLD;
@@ -590,13 +594,15 @@ tp_init_buttons(struct tp_dispatch *tp,
                tp->buttons.use_clickfinger = true;
 
        if (tp->buttons.is_clickpad && !tp->buttons.use_clickfinger) {
-               tp->buttons.bottom_area.top_edge = height * .8 + device->abs.min_y;
-               tp->buttons.bottom_area.rightbutton_left_edge = width/2 + device->abs.min_x;
+               int xoffset = absinfo_x->minimum,
+                   yoffset = absinfo_y->minimum;
+               tp->buttons.bottom_area.top_edge = height * .8 + yoffset;
+               tp->buttons.bottom_area.rightbutton_left_edge = width/2 + xoffset;
 
                if (tp->buttons.has_topbuttons) {
-                       tp->buttons.top_area.bottom_edge = height * .08 + device->abs.min_y;
-                       tp->buttons.top_area.rightbutton_left_edge = width * .58 + device->abs.min_x;
-                       tp->buttons.top_area.leftbutton_right_edge = width * .42 + device->abs.min_x;
+                       tp->buttons.top_area.bottom_edge = height * .08 + yoffset;
+                       tp->buttons.top_area.rightbutton_left_edge = width * .58 + xoffset;
+                       tp->buttons.top_area.leftbutton_right_edge = width * .42 + xoffset;
                } else {
                        tp->buttons.top_area.bottom_edge = INT_MIN;
                }
index 92e0651a5fd59d749c45ac2335a8bbc34bcf3f5b..787afa4caf8ee9b054cab8b8b91dd9135285c11d 100644 (file)
@@ -750,8 +750,10 @@ tp_init(struct tp_dispatch *tp,
        if (tp_init_slots(tp, device) != 0)
                return -1;
 
-       width = abs(device->abs.max_x - device->abs.min_x);
-       height = abs(device->abs.max_y - device->abs.min_y);
+       width = abs(device->abs.absinfo_x->maximum -
+                   device->abs.absinfo_x->minimum);
+       height = abs(device->abs.absinfo_y->maximum -
+                    device->abs.absinfo_y->minimum);
        diagonal = sqrt(width*width + height*height);
 
        tp->hysteresis.margin_x =
index 51ad5e31a9eeea345abcf599f835140702c16916..907d18e5bc2906706cef1d009e5f9482a16e7929 100644 (file)
@@ -89,13 +89,19 @@ transform_absolute(struct evdev_device *device, int32_t *x, int32_t *y)
        }
 }
 
+static inline double
+scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
+{
+       return (val - absinfo->minimum) * to_range /
+               (absinfo->maximum - absinfo->minimum + 1);
+}
+
 double
 evdev_device_transform_x(struct evdev_device *device,
                         double x,
                         uint32_t width)
 {
-       return (x - device->abs.min_x) * width /
-               (device->abs.max_x - device->abs.min_x + 1);
+       return scale_axis(device->abs.absinfo_x, x, width);
 }
 
 double
@@ -103,8 +109,7 @@ evdev_device_transform_y(struct evdev_device *device,
                         double y,
                         uint32_t height)
 {
-       return (y - device->abs.min_y) * height /
-               (device->abs.max_y - device->abs.min_y + 1);
+       return scale_axis(device->abs.absinfo_y, y, height);
 }
 
 static void
@@ -606,13 +611,11 @@ evdev_configure_device(struct evdev_device *device)
        if (libevdev_has_event_type(evdev, EV_ABS)) {
 
                if ((absinfo = libevdev_get_abs_info(evdev, ABS_X))) {
-                       device->abs.min_x = absinfo->minimum;
-                       device->abs.max_x = absinfo->maximum;
+                       device->abs.absinfo_x = absinfo;
                        has_abs = 1;
                }
                if ((absinfo = libevdev_get_abs_info(evdev, ABS_Y))) {
-                       device->abs.min_y = absinfo->minimum;
-                       device->abs.max_y = absinfo->maximum;
+                       device->abs.absinfo_y = absinfo;
                        has_abs = 1;
                }
                 /* We only handle the slotted Protocol B in weston.
@@ -621,11 +624,9 @@ evdev_configure_device(struct evdev_device *device)
                if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
                    libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) {
                        absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
-                       device->abs.min_x = absinfo->minimum;
-                       device->abs.max_x = absinfo->maximum;
+                       device->abs.absinfo_x = absinfo;
                        absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
-                       device->abs.min_y = absinfo->minimum;
-                       device->abs.max_y = absinfo->maximum;
+                       device->abs.absinfo_y = absinfo;
                        device->is_mt = 1;
                        has_touch = 1;
                        has_mt = 1;
index d057010bc1860a5d5a1b9b1d65796f0eb77151a2..03b6742965d3bd93fa723fad3485c269378ea66e 100644 (file)
@@ -66,7 +66,7 @@ struct evdev_device {
        const char *devname;
        int fd;
        struct {
-               int min_x, max_x, min_y, max_y;
+               const struct input_absinfo *absinfo_x, *absinfo_y;
                int32_t x, y;
 
                int32_t seat_slot;