tools/debug-events: rework touch event printing
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 20 Oct 2020 23:06:16 +0000 (09:06 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 20 Oct 2020 23:09:50 +0000 (09:09 +1000)
Previously, touch up events did not contain the slot number which makes the
logs ambiguous (e.g. see the one in #532). Fix that, and since doing so would
require extra conditions anyway get rid of the current with/without coords
function and just handle it all inside one function instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-debug-events.c

index 42125dc0880ce511986ad92cb0c845df69fd89e0..358bca4824fe741dcee43018474851d8e38f3ae5 100644 (file)
@@ -520,15 +520,6 @@ print_tablet_axis_event(struct libinput_event *ev)
        printq("\n");
 }
 
-static void
-print_touch_event_without_coords(struct libinput_event *ev)
-{
-       struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
-
-       print_event_time(libinput_event_touch_get_time(t));
-       printq("\n");
-}
-
 static void
 print_proximity_event(struct libinput_event *ev)
 {
@@ -629,21 +620,30 @@ print_proximity_event(struct libinput_event *ev)
 }
 
 static void
-print_touch_event_with_coords(struct libinput_event *ev)
+print_touch_event(struct libinput_event *ev)
 {
        struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
-       double x = libinput_event_touch_get_x_transformed(t, screen_width);
-       double y = libinput_event_touch_get_y_transformed(t, screen_height);
-       double xmm = libinput_event_touch_get_x(t);
-       double ymm = libinput_event_touch_get_y(t);
+       enum libinput_event_type type = libinput_event_get_type(ev);
 
        print_event_time(libinput_event_touch_get_time(t));
 
-       printq("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n",
-              libinput_event_touch_get_slot(t),
-              libinput_event_touch_get_seat_slot(t),
-              x, y,
-              xmm, ymm);
+       if (type != LIBINPUT_EVENT_TOUCH_FRAME) {
+               printq("%d (%d)",
+                      libinput_event_touch_get_slot(t),
+                      libinput_event_touch_get_seat_slot(t));
+       }
+
+       if (type == LIBINPUT_EVENT_TOUCH_DOWN ||
+           type == LIBINPUT_EVENT_TOUCH_MOTION) {
+               double x = libinput_event_touch_get_x_transformed(t, screen_width);
+               double y = libinput_event_touch_get_y_transformed(t, screen_height);
+               double xmm = libinput_event_touch_get_x(t);
+               double ymm = libinput_event_touch_get_y(t);
+
+               printq(" %5.2f/%5.2f (%5.2f/%5.2fmm)", x, y, xmm, ymm);
+       }
+
+       printq("\n");
 }
 
 static void
@@ -855,19 +855,11 @@ handle_and_print_events(struct libinput *li)
                        print_pointer_axis_event(ev);
                        break;
                case LIBINPUT_EVENT_TOUCH_DOWN:
-                       print_touch_event_with_coords(ev);
-                       break;
                case LIBINPUT_EVENT_TOUCH_MOTION:
-                       print_touch_event_with_coords(ev);
-                       break;
                case LIBINPUT_EVENT_TOUCH_UP:
-                       print_touch_event_without_coords(ev);
-                       break;
                case LIBINPUT_EVENT_TOUCH_CANCEL:
-                       print_touch_event_without_coords(ev);
-                       break;
                case LIBINPUT_EVENT_TOUCH_FRAME:
-                       print_touch_event_without_coords(ev);
+                       print_touch_event(ev);
                        break;
                case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
                        print_gesture_event_without_coords(ev);