summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2018-04-19 13:48:25 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2018-04-19 16:04:41 +1000
commitaca0e3729a42b76e06c78621163bb0ba9d23193c (patch)
treed735ff5e7e0ba57885fcf563c86fcf70cc2aa70d /tools
parentda02cdffd4b89b3568e3aa7e1f3d3a26d0cc2d2c (diff)
tools: libinput-record: add gesture support
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/libinput-record-verify-yaml.py57
-rw-r--r--tools/libinput-record.c88
2 files changed, 143 insertions, 2 deletions
diff --git a/tools/libinput-record-verify-yaml.py b/tools/libinput-record-verify-yaml.py
index c8f2f90f..f0661d89 100755
--- a/tools/libinput-record-verify-yaml.py
+++ b/tools/libinput-record-verify-yaml.py
@@ -58,7 +58,8 @@ class TestYaml(unittest.TestCase):
continue
for ev in libinput:
- if filter is None or ev['type'] == filter:
+ if (filter is None or ev['type'] == filter or
+ isinstance(filter, list) and ev['type'] in filter):
yield ev
def test_sections_exist(self):
@@ -224,7 +225,11 @@ class TestYaml(unittest.TestCase):
def test_events_libinput_type(self):
types = ['POINTER_MOTION', 'POINTER_MOTION_ABSOLUTE', 'POINTER_AXIS',
'POINTER_BUTTON', 'DEVICE_ADDED', 'KEYBOARD_KEY',
- 'TOUCH_DOWN', 'TOUCH_MOTION', 'TOUCH_UP', 'TOUCH_FRAME']
+ 'TOUCH_DOWN', 'TOUCH_MOTION', 'TOUCH_UP', 'TOUCH_FRAME',
+ 'GESTURE_SWIPE_BEGIN', 'GESTURE_SWIPE_UPDATE',
+ 'GESTURE_SWIPE_END', 'GESTURE_PINCH_BEGIN',
+ 'GESTURE_PINCH_UPDATE', 'GESTURE_PINCH_END',
+ ]
for e in self.libinput_events():
self.assertIn('type', e)
self.assertIn(e['type'], types)
@@ -374,6 +379,54 @@ class TestYaml(unittest.TestCase):
self.assertFalse(need_frame)
+ def test_events_libinput_gesture_pinch(self):
+ keys = ['type', 'time', 'nfingers', 'delta',
+ 'unaccel', 'angle_delta', 'scale']
+ for e in self.libinput_events(['GESTURE_PINCH_BEGIN',
+ 'GESTURE_PINCH_UPDATE',
+ 'GESTURE_PINCH_END']):
+ self.dict_key_crosscheck(e, keys)
+ delta = e['delta']
+ self.assertTrue(isinstance(delta, list))
+ self.assertEqual(len(delta), 2)
+ for d in delta:
+ self.assertTrue(isinstance(d, float))
+ unaccel = e['unaccel']
+ self.assertTrue(isinstance(unaccel, list))
+ self.assertEqual(len(unaccel), 2)
+ for d in unaccel:
+ self.assertTrue(isinstance(d, float))
+
+ adelta = e['angle_delta']
+ self.assertTrue(isinstance(adelta, list))
+ self.assertEqual(len(adelta), 2)
+ for d in adelta:
+ self.assertTrue(isinstance(d, float))
+
+ scale = e['scale']
+ self.assertTrue(isinstance(scale, list))
+ self.assertEqual(len(scale), 2)
+ for d in scale:
+ self.assertTrue(isinstance(d, float))
+
+ def test_events_libinput_gesture_swipe(self):
+ keys = ['type', 'time', 'nfingers', 'delta',
+ 'unaccel']
+ for e in self.libinput_events(['GESTURE_SWIPE_BEGIN',
+ 'GESTURE_SWIPE_UPDATE',
+ 'GESTURE_SWIPE_END']):
+ self.dict_key_crosscheck(e, keys)
+ delta = e['delta']
+ self.assertTrue(isinstance(delta, list))
+ self.assertEqual(len(delta), 2)
+ for d in delta:
+ self.assertTrue(isinstance(d, float))
+ unaccel = e['unaccel']
+ self.assertTrue(isinstance(unaccel, list))
+ self.assertEqual(len(unaccel), 2)
+ for d in unaccel:
+ self.assertTrue(isinstance(d, float))
+
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Verify a YAML recording')
diff --git a/tools/libinput-record.c b/tools/libinput-record.c
index f31c7408..fed63ca2 100644
--- a/tools/libinput-record.c
+++ b/tools/libinput-record.c
@@ -632,6 +632,86 @@ buffer_touch_event(struct record_context *ctx,
}
static void
+buffer_gesture_event(struct record_context *ctx,
+ struct libinput_event *e,
+ struct event *event)
+{
+ enum libinput_event_type etype = libinput_event_get_type(e);
+ struct libinput_event_gesture *g = libinput_event_get_gesture_event(e);
+ const char *type;
+ uint64_t time;
+
+ switch(etype) {
+ case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
+ type = "GESTURE_PINCH_BEGIN";
+ break;
+ case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
+ type = "GESTURE_PINCH_UPDATE";
+ break;
+ case LIBINPUT_EVENT_GESTURE_PINCH_END:
+ type = "GESTURE_PINCH_END";
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
+ type = "GESTURE_SWIPE_BEGIN";
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
+ type = "GESTURE_SWIPE_UPDATE";
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_END:
+ type = "GESTURE_SWIPE_END";
+ break;
+ default:
+ abort();
+ }
+
+ time = ctx->offset ?
+ libinput_event_gesture_get_time_usec(g) - ctx->offset : 0;
+ event->time = time;
+
+ switch (etype) {
+ case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
+ case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
+ case LIBINPUT_EVENT_GESTURE_PINCH_END:
+ snprintf(event->u.libinput.msg,
+ sizeof(event->u.libinput.msg),
+ "{time: %ld.%06ld, type: %s, nfingers: %d, "
+ "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f], "
+ "angle_delta: %6.2f, scale: %6.2f}",
+ time / (int)1e6,
+ time % (int)1e6,
+ type,
+ libinput_event_gesture_get_finger_count(g),
+ libinput_event_gesture_get_dx(g),
+ libinput_event_gesture_get_dy(g),
+ libinput_event_gesture_get_dx_unaccelerated(g),
+ libinput_event_gesture_get_dy_unaccelerated(g),
+ libinput_event_gesture_get_angle_delta(g),
+ libinput_event_gesture_get_scale(g)
+ );
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
+ case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
+ case LIBINPUT_EVENT_GESTURE_SWIPE_END:
+ snprintf(event->u.libinput.msg,
+ sizeof(event->u.libinput.msg),
+ "{time: %ld.%06ld, type: %s, nfingers: %d, "
+ "delta: [%6.2f, %6.2f], unaccel: [%6.2f, %6.2f]}",
+ time / (int)1e6,
+ time % (int)1e6,
+ type,
+ libinput_event_gesture_get_finger_count(g),
+ libinput_event_gesture_get_dx(g),
+ libinput_event_gesture_get_dy(g),
+ libinput_event_gesture_get_dx_unaccelerated(g),
+ libinput_event_gesture_get_dy_unaccelerated(g)
+ );
+ break;
+ default:
+ abort();
+ }
+}
+
+static void
buffer_libinput_event(struct record_context *ctx,
struct libinput_event *e,
struct event *event)
@@ -665,6 +745,14 @@ buffer_libinput_event(struct record_context *ctx,
case LIBINPUT_EVENT_TOUCH_FRAME:
buffer_touch_event(ctx, e, event);
break;
+ case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
+ case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
+ case LIBINPUT_EVENT_GESTURE_PINCH_END:
+ case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
+ case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
+ case LIBINPUT_EVENT_GESTURE_SWIPE_END:
+ buffer_gesture_event(ctx, e, event);
+ break;
default:
break;
}