<div dir="ltr">Oh nice, much simpler. I have a few nitpick comments, but it looks good, and works for me.<div><br></div><div>Reviewed-By: Dima Ryazanov <<a href="mailto:dima@gmail.com">dima@gmail.com</a>></div><div>Tested-By: Dima Ryazanov <<a href="mailto:dima@gmail.com">dima@gmail.com</a>></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 16, 2017 at 1:11 PM, Peter Hutterer <span dir="ltr"><<a href="mailto:peter.hutterer@who-t.net" target="_blank">peter.hutterer@who-t.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">A lot easier to process data in python than in C.<br>
<br>
Signed-off-by: Peter Hutterer <<a href="mailto:peter.hutterer@who-t.net" target="_blank">peter.hutterer@who-t.net</a>><br>
---<br>
 meson.build                           |  10 +-<br>
 tools/libinput-measure-touchp<wbr>ad-tap   | 261 +++++++++++++++++<br>
 tools/libinput-measure-touchp<wbr>ad-tap.c | 509 ------------------------------<wbr>----<br>
 3 files changed, 263 insertions(+), 517 deletions(-)<br>
 create mode 100755 tools/libinput-measure-touchpa<wbr>d-tap<br>
 delete mode 100644 tools/libinput-measure-touchpa<wbr>d-tap.c<br>
<br>
diff --git a/meson.build b/meson.build<br>
index eefe3d61..4d433989 100644<br>
--- a/meson.build<br>
+++ b/meson.build<br>
@@ -414,14 +414,8 @@ configure_file(input : 'tools/libinput-measure.man',<br>
               install_dir : join_paths(get_option('mandir'<wbr>), 'man1')<br>
               )<br>
<br>
-libinput_measure_touchpad_tap<wbr>_sources = [ 'tools/libinput-measure-touchp<wbr>ad-tap.c' ]<br>
-executable('libinput-measure-<wbr>touchpad-tap',<br>
-          libinput_measure_touchpad_tap_<wbr>sources,<br>
-          dependencies : deps_tools,<br>
-          include_directories : [includes_src, includes_include],<br>
-          install_dir : libinput_tool_path,<br>
-          install : true,<br>
-          )<br>
+install_data('tools/libinput-<wbr>measure-touchpad-tap',<br>
+            install_dir : libinput_tool_path)<br>
 configure_file(input : 'tools/libinput-measure-touchp<wbr>ad-tap.man',<br>
               output : 'libinput-measure-touchpad-tap<wbr>.1',<br>
               configuration : man_config,<br>
diff --git a/tools/libinput-measure-touch<wbr>pad-tap b/tools/libinput-measure-touch<wbr>pad-tap<br>
new file mode 100755<br>
index 00000000..165cd65a<br>
--- /dev/null<br>
+++ b/tools/libinput-measure-touch<wbr>pad-tap<br>
@@ -0,0 +1,261 @@<br>
+#!/usr/bin/python3<br>
+# vim: set expandtab shiftwidth=4:<br>
+# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */<br>
+#<br>
+# Copyright © 2017 Red Hat, Inc.<br>
+#<br>
+# Permission is hereby granted, free of charge, to any person obtaining a<br>
+# copy of this software and associated documentation files (the "Software"),<br>
+# to deal in the Software without restriction, including without limitation<br>
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+# and/or sell copies of the Software, and to permit persons to whom the<br>
+# Software is furnished to do so, subject to the following conditions:<br>
+#<br>
+# The above copyright notice and this permission notice (including the next<br>
+# paragraph) shall be included in all copies or substantial portions of the<br>
+# Software.<br>
+#<br>
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+# DEALINGS IN THE SOFTWARE.<br>
+#<br>
+<br>
+import sys<br>
+import argparse<br>
+try:<br>
+    import evdev<br>
+    import evdev.ecodes<br>
+    import textwrap<br>
+    import pyudev<br>
+except ModuleNotFoundError as e:<br>
+    print('Error: {}'.format(str(e)), file=sys.stderr)<br></blockquote><div><br></div><div>"str" is redundant here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    print('One or more python modules are missing. Please install those '<br>
+          'modules and re-run this tool.')<br>
+    sys.exit(1)<br>
+<br>
+print_dest = sys.stdout<br>
+<br>
+<br>
+def error(msg, **kwargs):<br>
+    print(msg, **kwargs, file=sys.stderr)<br>
+<br>
+<br>
+def msg(msg, **kwargs):<br>
+    print(msg, **kwargs, file=print_dest, flush=True)<br>
+<br>
+<br>
+def tv2us(sec, usec):<br>
+    return sec * 1000000 + usec<br>
+<br>
+<br>
+def us2ms(us):<br>
+    return int(us/1000)<br>
+<br>
+<br>
+class Touch(object):<br>
+    def __init__(self, down):<br>
+        self._down = down<br>
+        self._up = down<br>
+<br>
+    @property<br>
+    def up(self):<br>
+        return us2ms(self._up)<br>
+<br>
+    @up.setter<br>
+    def up(self, up):<br>
+        assert(up > self.down)<br></blockquote><div><br></div><div>Should this be "up >= self.down"? Or is it not possible to have the same timestamp?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+        self._up = up<br>
+<br>
+    @property<br>
+    def down(self):<br>
+        return us2ms(self._down)<br>
+<br>
+    @property<br>
+    def tdelta(self):<br>
+        return self.up - self.down<br>
+<br>
+<br>
+class InvalidDeviceError(Exception):<br>
+    pass<br>
+<br>
+<br>
+class Device(object):<br>
+    def __init__(self, path):<br>
+        if path is None:<br>
+            self.path = self._find_touch_device()<br>
+        else:<br>
+            self.path = path<br>
+<br>
+        self.device = evdev.InputDevice(self.path)<br>
+        # capabilities returns a dict with the EV_* codes as key,<br>
+        # each of which is a list of tuples of (code, AbsInfo)<br>
+        #<br>
+        # Get the abs list first (or empty list if missing),<br>
+        # then extract the pressure absinfo from that<br>
+        codes = self.device.capabilities(absin<wbr>fo=True).get(<br>
+                evdev.ecodes.EV_KEY, []<br>
+               )<br>
+<br>
+        if evdev.ecodes.BTN_TOUCH not in codes:<br>
+            raise InvalidDeviceError("device does not have BTN_TOUCH")<br>
+<br>
+        self.touches = []<br>
+<br>
+    def _find_touch_device(self):<br>
+        context = pyudev.Context()<br>
+        device_node = None<br>
+        for device in context.list_devices(subsystem<wbr>='input'):<br>
+            if not device.device_node or \<br></blockquote><div><br></div><div>Parenthesis are preferred over \ (according to PEP 8)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                    not device.device_node.startswith(<wbr>'/dev/input/event'):<br>
+                continue<br>
+<br>
+            # pick the touchpad by default, fallback to the first<br>
+            # touchscreen only when there is no touchpad<br>
+            if device.get('ID_INPUT_TOUCHPAD'<wbr>, 0):<br>
+                device_node = device.device_node<br>
+                break<br>
+<br>
+            if device.get('ID_INPUT_TOUCHSCRE<wbr>EN', 0) and device_node is None:<br>
+                device_node = device.device_node<br>
+<br>
+        if device_node is not None:<br>
+            return device_node<br>
+<br>
+        print("Unable to find a touch device.", file=sys.stderr)<br></blockquote><div><br></div><div>Use the "error" helper? Or better yet, raise an exception instead of sys.exit.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+        sys.exit(1)<br>
+<br>
+    def handle_btn_touch(self, event):<br>
+        if event.value != 0:<br>
+            t = Touch(tv2us(event.sec, event.usec))<br>
+            self.touches.append(t)<br>
+        else:<br>
+            self.touches[-1].up = tv2us(event.sec, event.usec)<br>
+            msg("\rTouch sequences detected: {}".format(len(self.touches)),<br>
+                end='')<br>
+<br>
+    def handle_key(self, event):<br>
+        tapcodes = [evdev.ecodes.BTN_TOOL_DOUBLET<wbr>AP,<br>
+                    evdev.ecodes.BTN_TOOL_TRIPLETA<wbr>P,<br>
+                    evdev.ecodes.BTN_TOOL_QUADTAP,<br>
+                    evdev.ecodes.BTN_TOOL_QUINTTAP<wbr>]<br>
+        if event.code in tapcodes and event.value > 0:<br>
+            error("\rThis tool cannot handle multiple fingers, "<br>
+                  "output will be invalid")<br>
+            return<br>
+<br>
+        if event.code == evdev.ecodes.BTN_TOUCH:<br>
+            self.handle_btn_touch(event)<br>
+<br>
+    def handle_syn(self, event):<br>
+        if self.touch.dirty:<br>
+            self.current_sequence().append<wbr>(self.touch)<br>
+            self.touch = Touch(major=self.touch.major,<br>
+                               minor=self.touch.minor,<br>
+                               orientation=self.touch.orient<wbr>ation)<br>
+<br>
+    def handle_event(self, event):<br>
+        if event.type == evdev.ecodes.EV_KEY:<br>
+            self.handle_key(event)<br>
+<br>
+    def read_events(self):<br>
+        for event in self.device.read_loop():<br>
+            self.handle_event(event)<br>
+<br>
+    def print_summary(self):<br>
+        deltas = sorted([t.tdelta for t in self.touches])<br></blockquote><div><br></div><div>Nit: don't need [ and ] here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+        dmax = max(deltas)<br>
+        dmin = min(deltas)<br>
+<br>
+        l = len(deltas)<br>
+<br>
+        davg = sum(deltas)/l<br>
+        dmedian = deltas[int(l/2)]<br>
+        d95pc = deltas[int(l * 0.95)]<br>
+        d90pc = deltas[int(l * 0.90)]<br>
+<br>
+        print("Time: ")<br>
+        print("  Max delta: {}ms".format(int(dmax)))<br>
+        print("  Min delta: {}ms".format(int(dmin)))<br>
+        print("  Average delta: {}ms".format(int(davg)))<br>
+        print("  Median delta: {}ms".format(int(dmedian)))<br>
+        print("  90th percentile: {}ms".format(int(d90pc)))<br>
+        print("  95th percentile: {}ms".format(int(d95pc)))<br>
+<br>
+    def print_dat(self):<br>
+        print("# libinput-measure-touchpad-tap"<wbr>)<br>
+        print(textwrap.dedent('''\<br>
+              # File contents:<br>
+              #    This file contains multiple prints of the data in<br>
+              #    different sort order. Row number is index of touch<br>
+              #    point within each group. Comparing data across groups<br>
+              #    will result in invalid analysis.<br>
+              # Columns (1-indexed):<br>
+              # Group 1, sorted by time of occurence<br>
+              #  1: touch down time in ms, offset by first event<br>
+              #  2: touch up time in ms, offset by first event<br>
+              #  3: time delta in ms);<br>
+              # Group 2, sorted by touch down-up delta time (ascending)<br>
+              #  4: touch down time in ms, offset by first event<br>
+              #  5: touch up time in ms, offset by first event<br>
+              #  6: time delta in ms<br>
+              '''))<br>
+<br>
+        deltas = [t for t in self.touches]<br>
+        deltas_sorted = sorted(deltas, key=lambda t: t.tdelta)<br>
+<br>
+        offset = deltas[0].down<br>
+<br>
+        for t1, t2 in zip(deltas, deltas_sorted):<br>
+            print(t1.down - offset, t1.up - offset, t1.tdelta,<br>
+                  t2.down - offset, t2.up - offset, t2.tdelta)<br>
+<br>
+    def print(self, format):<br>
+        if not self.touches:<br>
+            error("No tap data available")<br>
+            return<br>
+<br>
+        if format == 'summary':<br>
+            self.print_summary()<br>
+        elif format == 'dat':<br>
+            self.print_dat()<br>
+<br>
+<br>
+def main(args):<br>
+    parser = argparse.ArgumentParser(<br>
+            description="Measure tap-to-click properties of devices"<br>
+    )<br>
+    parser.add_argument('path', metavar='/dev/input/event0',<br></blockquote><div><br></div><div>"/dev/input/event0" should probably be the default value, not the metavar?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                        nargs='?', type=str, help='Path to device (optional)')<br>
+    parser.add_argument('--format'<wbr>, metavar='format',<br>
+                        choices=['summary', 'dat'],<br>
+                        default='summary',<br>
+                        help='data format to print ("summary" or "dat")')<br>
+    args = parser.parse_args()<br>
+<br>
+    if not sys.stdout.isatty():<br>
+        global print_dest<br>
+        print_dest = sys.stderr<br>
+<br>
+    try:<br>
+        device = Device(args.path)<br>
+        error("Ready for recording data.\n"<br>
+              "Tap the touchpad multiple times with a single finger only.\n"<br>
+              "For useful data we recommend at least 20 taps.\n"<br>
+              "Ctrl+C to exit")<br>
+        device.read_events()<br>
+    except KeyboardInterrupt:<br>
+        msg('')<br>
+        device.print(args.format)<br>
+    except (PermissionError, OSError):<br>
+        print("Error: failed to open device")<br></blockquote><div><br></div><div>Might as well print out the exception, too.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    except InvalidDeviceError as e:<br>
+        print("Error: {}".format(e))<br>
+<br>
+<br>
+if __name__ == "__main__":<br>
+    main(sys.argv)<br>
diff --git a/tools/libinput-measure-touch<wbr>pad-tap.c b/tools/libinput-measure-touch<wbr>pad-tap.c<br>
deleted file mode 100644<br>
index 735202c1..00000000<br>
--- a/tools/libinput-measure-touch<wbr>pad-tap.c<br>
+++ /dev/null<br>
@@ -1,509 +0,0 @@<br>
-/*<br>
- * Copyright © 2017 Red Hat, Inc.<br>
- *<br>
- * Permission is hereby granted, free of charge, to any person obtaining a<br>
- * copy of this software and associated documentation files (the "Software"),<br>
- * to deal in the Software without restriction, including without limitation<br>
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
- * and/or sell copies of the Software, and to permit persons to whom the<br>
- * Software is furnished to do so, subject to the following conditions:<br>
- *<br>
- * The above copyright notice and this permission notice (including the next<br>
- * paragraph) shall be included in all copies or substantial portions of the<br>
- * Software.<br>
- *<br>
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
- * DEALINGS IN THE SOFTWARE.<br>
- */<br>
-<br>
-#include "config.h"<br>
-<br>
-#include <errno.h><br>
-#include <fcntl.h><br>
-#include <getopt.h><br>
-#include <poll.h><br>
-#include <signal.h><br>
-#include <stdbool.h><br>
-#include <stdio.h><br>
-#include <string.h><br>
-#include <unistd.h><br>
-#include <sys/signalfd.h><br>
-<br>
-#include <libudev.h><br>
-#include <libevdev/libevdev.h><br>
-<br>
-#include <libinput-util.h><br>
-#include <libinput-version.h><br>
-<br>
-#include "shared.h"<br>
-<br>
-static bool print_dat_file;<br>
-/* interactive goes to stdout unless we're redirected, then it goes to<br>
- * stderr */<br>
-static FILE *pdest;<br>
-<br>
-#define error(...) fprintf(stderr, __VA_ARGS__)<br>
-#define msg(...) fprintf(pdest, __VA_ARGS__)<br>
-<br>
-struct touch {<br>
-       uint32_t tdown, tup; /* in ms */<br>
-};<br>
-<br>
-struct tap_data {<br>
-       struct touch *touches;<br>
-       size_t touches_sz;<br>
-       unsigned int count;<br>
-<br>
-       uint32_t toffset; /* in ms */<br>
-};<br>
-<br>
-static inline uint32_t<br>
-touch_tdelta_ms(const struct touch *t)<br>
-{<br>
-       return t->tup - t->tdown;<br>
-}<br>
-<br>
-static inline struct tap_data *<br>
-tap_data_new(void)<br>
-{<br>
-       struct tap_data *tap_data;<br>
-<br>
-       tap_data = zalloc(sizeof(struct tap_data));<br>
-<br>
-       return tap_data;<br>
-}<br>
-<br>
-static inline unsigned int<br>
-tap_data_ntouches(struct tap_data *tap_data)<br>
-{<br>
-       return tap_data->count;<br>
-}<br>
-<br>
-static inline void<br>
-tap_data_free(struct tap_data **tap_data)<br>
-{<br>
-       free((*tap_data)->touches);<br>
-       free((*tap_data));<br>
-       *tap_data = NULL;<br>
-}<br>
-<br>
-static inline struct touch *<br>
-tap_data_get_current_touch(st<wbr>ruct tap_data *tap_data)<br>
-{<br>
-       assert(tap_data->count > 0);<br>
-<br>
-       return &tap_data->touches[tap_data->c<wbr>ount - 1];<br>
-}<br>
-<br>
-static inline struct touch *<br>
-tap_data_get_touch(struct tap_data *tap_data, unsigned int idx)<br>
-{<br>
-       assert(idx < tap_data->count);<br>
-<br>
-       return &tap_data->touches[idx];<br>
-}<br>
-<br>
-#define tap_data_for_each(tapdata_, t_) \<br>
-       for (unsigned i_ = 0; i_ < (tapdata_)->count && (t_ = &(tapdata_)->touches[i_]); i_++)<br>
-<br>
-static inline struct tap_data *<br>
-tap_data_duplicate_sorted(con<wbr>st struct tap_data *src,<br>
-                         int (*cmp)(const void *a, const void *b))<br>
-{<br>
-       struct tap_data *dest = tap_data_new();<br>
-<br>
-       assert(src->count > 0);<br>
-<br>
-       dest->count = src->count;<br>
-       dest->toffset = src->toffset;<br>
-       dest->touches_sz = dest->count;<br>
-       dest->touches = zalloc(dest->count * sizeof(*dest->touches));<br>
-<br>
-       memcpy(dest->touches,<br>
-              src->touches,<br>
-              dest->count * sizeof(*dest->touches));<br>
-<br>
-       if (cmp)<br>
-               qsort(dest->touches,<br>
-                     dest->count,<br>
-                     sizeof(*dest->touches),<br>
-                     cmp);<br>
-<br>
-       return dest;<br>
-}<br>
-<br>
-static inline struct touch*<br>
-tap_data_new_touch(struct tap_data *tap_data)<br>
-{<br>
-       tap_data->count++;<br>
-       if (tap_data->touches_sz < tap_data->count) {<br>
-               tap_data->touches_sz += 50;<br>
-               tap_data->touches = realloc(tap_data->touches,<br>
-                            tap_data->touches_sz * sizeof(*tap_data->touches));<br>
-               if (tap_data->touches == NULL) {<br>
-                       error("Allocation error. Oops\n");<br>
-                       abort();<br>
-               }<br>
-               memset(&tap_data->touches[<wbr>tap_data->count - 1],<br>
-                      0,<br>
-                      sizeof(*tap_data->touches));<br>
-       }<br>
-<br>
-       return &tap_data->touches[tap_data->c<wbr>ount - 1];<br>
-}<br>
-<br>
-static int<br>
-sort_by_time_delta(const void *ap, const void *bp)<br>
-{<br>
-       const struct touch *a = ap;<br>
-       const struct touch *b = bp;<br>
-       uint32_t da, db;<br>
-<br>
-       da = touch_tdelta_ms(a);<br>
-       db = touch_tdelta_ms(b);<br>
-<br>
-       return da == db ? 0 : da > db ? 1 : -1;<br>
-}<br>
-<br>
-static inline void<br>
-print_statistics(struct tap_data *tap_data)<br>
-{<br>
-       uint64_t delta_sum = 0;<br>
-       uint32_t average;<br>
-       uint32_t max = 0,<br>
-                min = UINT_MAX;<br>
-       struct tap_data *data_sorted_tdelta;<br>
-       struct touch *t,<br>
-                    *median,<br>
-                    *pc90,<br>
-                    *pc95;<br>
-<br>
-       if (tap_data->count == 0) {<br>
-               error("No tap data available.\n");<br>
-               return;<br>
-       }<br>
-<br>
-       tap_data_for_each(tap_data, t) {<br>
-               uint32_t delta = touch_tdelta_ms(t);<br>
-<br>
-               delta_sum += delta;<br>
-               max = max(delta, max);<br>
-               min = min(delta, min);<br>
-       }<br>
-<br>
-       average = delta_sum/tap_data_ntouches(ta<wbr>p_data);<br>
-<br>
-       printf("Time:\n");<br>
-       printf("  Max delta: %dms\n", max);<br>
-       printf("  Min delta: %dms\n", min);<br>
-       printf("  Average delta: %dms\n", average);<br>
-<br>
-       /* Median, 90th, 95th percentile, requires sorting by time delta */<br>
-       data_sorted_tdelta = tap_data_duplicate_sorted(tap_<wbr>data,<br>
-                                                      sort_by_time_delta);<br>
-       median = tap_data_get_touch(tap_data,<br>
-                                   tap_data_ntouches(tap_data)/<wbr>2);<br>
-       pc90= tap_data_get_touch(tap_data,<br>
-                                tap_data_ntouches(tap_data) * 0.9);<br>
-       pc95 = tap_data_get_touch(tap_data,<br>
-                                 tap_data_ntouches(tap_data) * 0.95);<br>
-       printf("  Median delta: %dms\n", touch_tdelta_ms(median));<br>
-       printf("  90th percentile: %dms\n", touch_tdelta_ms(pc90));<br>
-       printf("  95th percentile: %dms\n", touch_tdelta_ms(pc95));<br>
-<br>
-       tap_data_free(&data_sorted_td<wbr>elta);<br>
-}<br>
-<br>
-static inline void<br>
-print_dat(struct tap_data *tap_data)<br>
-{<br>
-       unsigned int i;<br>
-       struct touch *t;<br>
-       struct tap_data *sorted;<br>
-<br>
-       printf("# libinput-measure-touchpad-tap (v%s)\n", LIBINPUT_VERSION);<br>
-       printf("# File contents:\n"<br>
-              "#    This file contains multiple prints of the data in different\n"<br>
-              "#    sort order. Row number is index of touch point within each group.\n"<br>
-              "#    Comparing data across groups will result in invalid analysis.\n"<br>
-              "# Columns (1-indexed):\n");<br>
-       printf("# Group 1, sorted by time of occurence\n"<br>
-              "#  1: touch down time in ms, offset by first event\n"<br>
-              "#  2: touch up time in ms, offset by first event\n"<br>
-              "#  3: time delta in ms\n");<br>
-       printf("# Group 2, sorted by touch down-up delta time (ascending)\n"<br>
-              "#  4: touch down time in ms, offset by first event\n"<br>
-              "#  5: touch up time in ms, offset by first event\n"<br>
-              "#  6: time delta in ms\n");<br>
-<br>
-       sorted = tap_data_duplicate_sorted(tap_<wbr>data, sort_by_time_delta);<br>
-<br>
-       for (i = 0; i < tap_data_ntouches(tap_data); i++) {<br>
-               t = tap_data_get_touch(tap_data, i);<br>
-               printf("%d %d %d ",<br>
-                      t->tdown,<br>
-                      t->tup,<br>
-                      touch_tdelta_ms(t));<br>
-<br>
-               t = tap_data_get_touch(sorted, i);<br>
-               printf("%d %d %d ",<br>
-                      t->tdown,<br>
-                      t->tup,<br>
-                      touch_tdelta_ms(t));<br>
-<br>
-               printf("\n");<br>
-       }<br>
-<br>
-       tap_data_free(&sorted);<br>
-}<br>
-<br>
-static inline void<br>
-handle_btn_touch(struct tap_data *tap_data,<br>
-                struct libevdev *evdev,<br>
-                const struct input_event *ev)<br>
-{<br>
-<br>
-       if (ev->value) {<br>
-               struct touch *new_touch = tap_data_new_touch(tap_data);<br>
-<br>
-               new_touch->tdown = us2ms(tv2us(&ev->time)) - tap_data->toffset;<br>
-       } else {<br>
-               struct touch *current = tap_data_get_current_touch(tap<wbr>_data);<br>
-<br>
-               msg("\rTouch sequences detected: %d", tap_data->count);<br>
-<br>
-               current->tup = us2ms(tv2us(&ev->time)) - tap_data->toffset;<br>
-       }<br>
-}<br>
-<br>
-static inline bool<br>
-handle_key(struct tap_data *tap_data,<br>
-          struct libevdev *evdev,<br>
-          const struct input_event *ev)<br>
-{<br>
-       switch (ev->code) {<br>
-       case BTN_TOOL_DOUBLETAP:<br>
-       case BTN_TOOL_TRIPLETAP:<br>
-       case BTN_TOOL_QUADTAP:<br>
-       case BTN_TOOL_QUINTTAP:<br>
-               error("This tool only supports single-finger taps. Aborting.\n");<br>
-               return false;<br>
-       case BTN_TOUCH:<br>
-               handle_btn_touch(tap_data, evdev, ev);<br>
-               break;<br>
-       default:<br>
-               break;<br>
-       }<br>
-<br>
-       return true;<br>
-}<br>
-<br>
-static inline bool<br>
-handle_abs(struct tap_data *tap_data,<br>
-          struct libevdev *evdev,<br>
-          const struct input_event *ev)<br>
-{<br>
-       return true;<br>
-}<br>
-<br>
-static inline bool<br>
-handle_event(struct tap_data *tap_data,<br>
-            struct libevdev *evdev,<br>
-            const struct input_event *ev)<br>
-{<br>
-       bool rc = true;<br>
-<br>
-       if (tap_data->toffset == 0)<br>
-               tap_data->toffset = us2ms(tv2us(&ev->time));<br>
-<br>
-       switch (ev->type) {<br>
-       default:<br>
-               error("Unexpected event %s %s (%d, %d). Aborting.\n",<br>
-                     libevdev_event_type_get_name(<wbr>ev->type),<br>
-                     libevdev_event_code_get_name(<wbr>ev->type, ev->code),<br>
-                     ev->type,<br>
-                     ev->code);<br>
-               break;<br>
-       case EV_KEY:<br>
-               rc = handle_key(tap_data, evdev, ev);<br>
-               break;<br>
-       case EV_ABS:<br>
-               rc = handle_abs(tap_data, evdev, ev);<br>
-               break;<br>
-       case EV_SYN:<br>
-               rc = true;<br>
-               break;<br>
-       }<br>
-<br>
-       return rc;<br>
-}<br>
-<br>
-static int<br>
-loop(struct tap_data *data, const char *path)<br>
-{<br>
-       struct libevdev *evdev;<br>
-       struct pollfd fds[2];<br>
-       sigset_t mask;<br>
-       int fd;<br>
-       int rc;<br>
-<br>
-       fd = open(path, O_RDONLY|O_NONBLOCK);<br>
-       if (fd < 0) {<br>
-               error("Failed to open device: %s\n", strerror(errno));<br>
-               return EXIT_FAILURE;<br>
-       }<br>
-<br>
-       rc = libevdev_new_from_fd(fd, &evdev);<br>
-       if (rc < 0) {<br>
-               error("Failed to init device: %s\n", strerror(-rc));<br>
-               close(fd);<br>
-               return EXIT_FAILURE;<br>
-       }<br>
-       libevdev_set_clock_id(evdev, CLOCK_MONOTONIC);<br>
-<br>
-       fds[0].fd = fd;<br>
-       fds[0].events = POLLIN;<br>
-<br>
-       sigemptyset(&mask);<br>
-       sigaddset(&mask, SIGINT);<br>
-       fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);<br>
-       fds[1].events = POLLIN;<br>
-<br>
-       sigprocmask(SIG_BLOCK, &mask, NULL);<br>
-<br>
-       rc = EXIT_FAILURE;<br>
-<br>
-       error("Ready for recording data.\n"<br>
-             "Tap the touchpad multiple times with a single finger only.\n"<br>
-             "For useful data we recommend at least 20 taps.\n"<br>
-             "Ctrl+C to exit\n");<br>
-<br>
-       while (poll(fds, 2, -1)) {<br>
-               struct input_event ev;<br>
-               int rc;<br>
-<br>
-               if (fds[1].revents)<br>
-                       break;<br>
-<br>
-               do {<br>
-                       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &ev);<br>
-                       if (rc == LIBEVDEV_READ_STATUS_SYNC) {<br>
-                               error("Error: cannot keep up\n");<br>
-                               goto out;<br>
-                       } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {<br>
-                               if (!handle_event(data, evdev, &ev))<br>
-                                       goto out;<br>
-                       } else if (rc != -EAGAIN && rc < 0) {<br>
-                               error("Error: %s\n", strerror(-rc));<br>
-                               goto out;<br>
-                       }<br>
-               } while (rc != -EAGAIN);<br>
-       }<br>
-<br>
-       rc = EXIT_SUCCESS;<br>
-out:<br>
-       close(fd);<br>
-       if (evdev)<br>
-               libevdev_free(evdev);<br>
-<br>
-       printf("\n");<br>
-<br>
-       return rc;<br>
-}<br>
-<br>
-static inline void<br>
-usage(void)<br>
-{<br>
-       printf("Usage: libinput measure touchpad-tap [--help] [/dev/input/event0]\n");<br>
-}<br>
-<br>
-int<br>
-main(int argc, char **argv)<br>
-{<br>
-       struct tap_data *tap_data;<br>
-       char path[PATH_MAX];<br>
-       int option_index = 0;<br>
-       const char *format = "summary";<br>
-       int rc;<br>
-<br>
-       while (1) {<br>
-               enum opts {<br>
-                       OPT_HELP,<br>
-                       OPT_FORMAT,<br>
-               };<br>
-               static struct option opts[] = {<br>
-                       { "help",             no_argument, 0, OPT_HELP },<br>
-                       { "format",     required_argument, 0, OPT_FORMAT},<br>
-                       { 0, 0, 0, 0 },<br>
-               };<br>
-               int c;<br>
-<br>
-               c = getopt_long(argc, argv, "", opts, &option_index);<br>
-               if (c == -1)<br>
-                       break;<br>
-<br>
-               switch(c) {<br>
-               case OPT_HELP:<br>
-                       usage();<br>
-                       return EXIT_SUCCESS;;<br>
-               case OPT_FORMAT:<br>
-                       format = optarg;<br>
-                       break;<br>
-               default:<br>
-                       usage();<br>
-                       return EXIT_FAILURE;<br>
-               }<br>
-       }<br>
-<br>
-       if (streq(format, "summary")) {<br>
-               print_dat_file = false;<br>
-       } else if (streq(format, "dat")) {<br>
-               print_dat_file = true;<br>
-       } else {<br>
-               error("Unknown print format '%s'\n", format);<br>
-               return EXIT_FAILURE;<br>
-       }<br>
-<br>
-       if (optind == argc) {<br>
-               if (!find_touchpad_device(path, sizeof(path))) {<br>
-                       error("Failed to find a touchpad device.\n");<br>
-                       return EXIT_FAILURE;<br>
-               }<br>
-       } else {<br>
-               snprintf(path, sizeof(path), "%s", argv[optind]);<br>
-               if (!is_touchpad_device(path)) {<br>
-                       error("Device is not a touchpad.\n");<br>
-                       return EXIT_FAILURE;<br>
-               }<br>
-       }<br>
-<br>
-       if (!isatty(STDOUT_FILENO)) {<br>
-               pdest = stderr;<br>
-       } else {<br>
-               pdest = stdout;<br>
-               setbuf(stdout, NULL);<br>
-       }<br>
-<br>
-       tap_data = tap_data_new();<br>
-       rc = loop(tap_data, path);<br>
-<br>
-       if (rc != EXIT_SUCCESS)<br>
-               goto out;<br>
-<br>
-       msg("\n");<br>
-<br>
-       if (print_dat_file)<br>
-               print_dat(tap_data);<br>
-       else<br>
-               print_statistics(tap_data);<br>
-<br>
-out:<br>
-       tap_data_free(&tap_data);<br>
-<br>
-       return rc;<br>
-}<br>
<span class="gmail-m_4905074322119878968gmail-HOEnZb"><font color="#888888">--<br>
2.13.6<br>
<br>
______________________________<wbr>_________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org" target="_blank">wayland-devel@lists.freedeskto<wbr>p.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div></div></div>