diff --git a/tools/libinput-measure-touch-size.py b/tools/libinput-measure-touch-size.py index 3997c038..957e6052 100755 --- a/tools/libinput-measure-touch-size.py +++ b/tools/libinput-measure-touch-size.py @@ -268,9 +268,13 @@ class Device(object): if event.value > -1: self.start_new_sequence(event.value) else: - s = self.current_sequence() - s.finalize() - print("\r{}".format(s)) + try: + s = self.current_sequence() + s.finalize() + print("\r{}".format(s)) + except IndexError: + # If the finger was down during start + pass elif event.code == evdev.ecodes.ABS_MT_TOUCH_MAJOR: self.touch.major = event.value elif event.code == evdev.ecodes.ABS_MT_TOUCH_MINOR: @@ -280,11 +284,14 @@ class Device(object): def handle_syn(self, event): if self.touch.dirty: - self.current_sequence().append(self.touch) - print("\r{}".format(self.current_sequence()), end="") - self.touch = Touch(major=self.touch.major, - minor=self.touch.minor, - orientation=self.touch.orientation) + try: + self.current_sequence().append(self.touch) + print("\r{}".format(self.current_sequence()), end="") + self.touch = Touch(major=self.touch.major, + minor=self.touch.minor, + orientation=self.touch.orientation) + except IndexError: + pass def handle_event(self, event): if event.type == evdev.ecodes.EV_ABS: diff --git a/tools/libinput-measure-touchpad-pressure.py b/tools/libinput-measure-touchpad-pressure.py index 892b5e66..c04d8d6d 100755 --- a/tools/libinput-measure-touchpad-pressure.py +++ b/tools/libinput-measure-touchpad-pressure.py @@ -240,13 +240,21 @@ def handle_abs(device, event): if event.value > -1: device.start_new_sequence(event.value) else: - s = device.current_sequence() - s.finalize() - print("\r{}".format(s)) + try: + s = device.current_sequence() + s.finalize() + print("\r{}".format(s)) + except IndexError: + # If the finger was down at startup + pass elif event.code == evdev.ecodes.ABS_MT_PRESSURE: - s = device.current_sequence() - s.append(Touch(pressure=event.value)) - print("\r{}".format(s), end="") + try: + s = device.current_sequence() + s.append(Touch(pressure=event.value)) + print("\r{}".format(s), end="") + except IndexError: + # If the finger was down at startup + pass def handle_event(device, event):