summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2018-05-03 13:51:00 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2018-05-03 14:03:30 +1000
commitb476345959e36681592046bb5d4a0239dd375212 (patch)
treeacb77bf8b919886c489eade0b4ec290d70742f10 /tools
parent8bf2c5ae16c068b01573ae03a9ceb0421b2e4471 (diff)
tools: libinput-record: print switch events in --with-libinput
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/libinput-record-verify-yaml.py16
-rw-r--r--tools/libinput-record.c39
2 files changed, 54 insertions, 1 deletions
diff --git a/tools/libinput-record-verify-yaml.py b/tools/libinput-record-verify-yaml.py
index fb90481c..8bde4ca3 100755
--- a/tools/libinput-record-verify-yaml.py
+++ b/tools/libinput-record-verify-yaml.py
@@ -233,7 +233,7 @@ class TestYaml(unittest.TestCase):
'TABLET_TOOL_AXIS', 'TABLET_TOOL_PROXIMITY',
'TABLET_TOOL_BUTTON', 'TABLET_TOOL_TIP',
'TABLET_PAD_STRIP', 'TABLET_PAD_RING',
- 'TABLET_PAD_BUTTON'
+ 'TABLET_PAD_BUTTON', 'SWITCH_TOGGLE',
]
for e in self.libinput_events():
self.assertIn('type', e)
@@ -615,6 +615,20 @@ class TestYaml(unittest.TestCase):
except KeyError:
pass
+ def test_events_libinput_switch(self):
+ keys = ['type', 'time', 'switch', 'state']
+
+ for e in self.libinput_events('SWITCH_TOGGLE'):
+ self.dict_key_crosscheck(e, keys)
+
+ s = e['switch']
+ self.assertTrue(isinstance(s, int))
+ self.assertIn(s, [0x00, 0x01])
+
+ # yaml converts on/off to true/false
+ state = e['state']
+ self.assertTrue(isinstance(state, bool))
+
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Verify a YAML recording')
diff --git a/tools/libinput-record.c b/tools/libinput-record.c
index a2c00cf2..f0a41058 100644
--- a/tools/libinput-record.c
+++ b/tools/libinput-record.c
@@ -1090,6 +1090,42 @@ buffer_tablet_pad_ringstrip_event(struct record_context *ctx,
}
static void
+buffer_switch_event(struct record_context *ctx,
+ struct libinput_event *e,
+ struct event *event)
+{
+ struct libinput_event_switch *s = libinput_event_get_switch_event(e);
+ enum libinput_switch_state state;
+ uint32_t sw;
+ const char *type;
+ uint64_t time;
+
+ switch(libinput_event_get_type(e)) {
+ case LIBINPUT_EVENT_SWITCH_TOGGLE:
+ type = "SWITCH_TOGGLE";
+ break;
+ default:
+ abort();
+ }
+
+ time = ctx->offset ?
+ libinput_event_switch_get_time_usec(s) - ctx->offset : 0;
+
+ sw = libinput_event_switch_get_switch(s);
+ state = libinput_event_switch_get_switch_state(s);
+
+ event->time = time;
+ snprintf(event->u.libinput.msg,
+ sizeof(event->u.libinput.msg),
+ "{time: %ld.%06ld, type: %s, switch: %d, state: %s}",
+ time / (int)1e6,
+ time % (int)1e6,
+ type,
+ sw,
+ state == LIBINPUT_SWITCH_STATE_ON ? "on" : "off");
+}
+
+static void
buffer_libinput_event(struct record_context *ctx,
struct libinput_event *e,
struct event *event)
@@ -1148,6 +1184,9 @@ buffer_libinput_event(struct record_context *ctx,
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
buffer_tablet_pad_ringstrip_event(ctx, e, event);
break;
+ case LIBINPUT_EVENT_SWITCH_TOGGLE:
+ buffer_switch_event(ctx, e, event);
+ break;
default:
break;
}