Uncomplicate the setting of axis during slot sync
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 12 Feb 2020 12:17:13 +0000 (22:17 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Sun, 16 Feb 2020 22:02:44 +0000 (22:02 +0000)
A few bytes get wasted, but no magic handling of offsets etc are required.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
libevdev/libevdev.c

index 5b1abc75367ec3282d13ebc63ee7c622f07c2b41..f91d1ed5720bf3c41a05a03c5bcf0fdfacb0ef46 100644 (file)
@@ -660,7 +660,7 @@ sync_mt_state(struct libevdev *dev, int create_events)
        int rc;
        int axis, slot;
        int last_reported_slot = 0;
-       unsigned long slot_update[NLONGS(dev->num_slots * ABS_MT_CNT)];
+       unsigned long slot_update[dev->num_slots][NLONGS(ABS_CNT)];
        unsigned long tracking_id_changes[NLONGS(dev->num_slots)];
 
        int need_tracking_id_changes = 0;
@@ -668,8 +668,6 @@ sync_mt_state(struct libevdev *dev, int create_events)
        memset(slot_update, 0, sizeof(slot_update));
        memset(tracking_id_changes, 0, sizeof(tracking_id_changes));
 
-#define AXISBIT(_slot, _axis) (_slot * ABS_MT_CNT + _axis - ABS_MT_MIN)
-
        for (axis = ABS_MT_MIN; axis <= ABS_MT_MAX; axis++) {
                /* EVIOCGMTSLOTS required format */
                struct mt_sync_state {
@@ -701,9 +699,9 @@ sync_mt_state(struct libevdev *dev, int create_events)
 
                        *slot_value(dev, slot, axis) = mt_state.val[slot];
 
-                       set_bit(slot_update, AXISBIT(slot, axis));
+                       set_bit(slot_update[slot], axis);
                        /* note that this slot has updates */
-                       set_bit(slot_update, AXISBIT(slot, ABS_MT_SLOT));
+                       set_bit(slot_update[slot], ABS_MT_SLOT);
                }
        }
 
@@ -727,7 +725,7 @@ sync_mt_state(struct libevdev *dev, int create_events)
        }
 
        for (slot = 0; slot < dev->num_slots;  slot++) {
-               if (!bit_is_set(slot_update, AXISBIT(slot, ABS_MT_SLOT)))
+               if (!bit_is_set(slot_update[slot], ABS_MT_SLOT))
                        continue;
 
                queue_push_event(dev, EV_ABS, ABS_MT_SLOT, slot);
@@ -738,7 +736,7 @@ sync_mt_state(struct libevdev *dev, int create_events)
                            !libevdev_has_event_code(dev, EV_ABS, axis))
                                continue;
 
-                       if (bit_is_set(slot_update, AXISBIT(slot, axis)))
+                       if (bit_is_set(slot_update[slot], axis))
                                queue_push_event(dev, EV_ABS, axis,
                                                 *slot_value(dev, slot, axis));
                }
@@ -756,8 +754,6 @@ sync_mt_state(struct libevdev *dev, int create_events)
        if (dev->current_slot != last_reported_slot)
                queue_push_event(dev, EV_ABS, ABS_MT_SLOT, dev->current_slot);
 
-#undef AXISBIT
-
        rc = 0;
 out:
        return rc ? -errno : 0;