tools/libinput-replay: interrupt only the ongoing event sequence with ctrl+c
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 19 Dec 2024 01:48:49 +0000 (11:48 +1000)
committerMarge Bot <emma+marge@anholt.net>
Sun, 22 Dec 2024 23:59:22 +0000 (23:59 +0000)
If libinput replay is currently replaying events, stop that sequence and
go back to the start if the user presses Ctrl+C. Only on the second
Ctrl+C do we fully exit.

This helps debugging long recordings where we don't want to keep
producing events after some initial event sequence.

Closes #1064

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1102>

tools/libinput-replay.py

index 25a4a3816f37a4949882979728383ed93ce4374a..67ef28f8c03949c2885674124069bd3652363b00 100755 (executable)
@@ -277,21 +277,25 @@ def loop(args, recording):
         else:
             input("Hit enter to start replaying")
 
-        processes = []
-        for d in devices:
-            p = multiprocessing.Process(target=wrap, args=(replay, d, args.verbose))
-            processes.append(p)
+        try:
+            processes = []
+            for d in devices:
+                p = multiprocessing.Process(target=wrap, args=(replay, d, args.verbose))
+                processes.append(p)
 
-        for p in processes:
-            p.start()
+            for p in processes:
+                p.start()
 
-        for p in processes:
-            p.join()
+            for p in processes:
+                p.join()
 
-        del processes
+            del processes
 
-        if args.once:
-            break
+            if args.once:
+                break
+        except KeyboardInterrupt:
+            print("Event replay interrupted, press Ctrl+C again to exit.")
+            print("Note that the device may not be in a neutral state now.")
 
 
 def create_device_quirk(device):