From ff87151764c10728f11a7e6b1b40c488b94e7cae Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 23 Feb 2021 10:53:31 +1000 Subject: [PATCH] tools/replay: Enter quits if there are no events If we have no events in any of the recorded devices, state that this is the case and make Enter simply quit instead of a pointless while loop. Signed-off-by: Peter Hutterer --- tools/libinput-replay | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/libinput-replay b/tools/libinput-replay index 3ecb77a7..527b9d05 100755 --- a/tools/libinput-replay +++ b/tools/libinput-replay @@ -26,6 +26,7 @@ import os import sys import time +import math import multiprocessing import argparse from pathlib import Path @@ -218,8 +219,7 @@ def first_timestamp(device): except YamlException: pass - import math - return math.inf + return None def wrap(func, *args): @@ -232,9 +232,12 @@ def wrap(func, *args): def loop(args, recording): devices = fetch(recording, "devices") + first_timestamps = tuple( + filter(lambda x: x is not None, [first_timestamp(d) for d in devices]) + ) # All devices need to start replaying at the same time, so let's find # the very first event and offset everything by that timestamp. - toffset = min([first_timestamp(d) for d in devices]) + toffset = min(first_timestamps or [math.inf]) for idx, d in enumerate(devices): uinput = create(d) @@ -243,6 +246,10 @@ def loop(args, recording): d["__index"] = idx d["__first_event_offset"] = toffset + if not first_timestamps: + input("No events in recording. Hit enter to quit") + return + while True: input("Hit enter to start replaying")