Skip to content

Commit

Permalink
tools: record: wrap the time offset handling into a helper function
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jan 30, 2020
1 parent 8e35a2f commit fb1f0a6
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions tools/libinput-record.c
Expand Up @@ -194,6 +194,12 @@ noiprintf(const struct record_context *ctx, const char *format, ...)
assert(rc != -1 && (unsigned int)rc > 0);
}

static inline uint64_t
time_offset(struct record_context *ctx, uint64_t time)
{
return ctx->offset ? time - ctx->offset : 0;
}

static inline void
print_evdev_event(struct record_context *ctx, struct input_event *ev)
{
Expand Down Expand Up @@ -373,9 +379,7 @@ buffer_key_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_keyboard_get_time_usec(k) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_keyboard_get_time_usec(k));
state = libinput_event_keyboard_get_key_state(k);

key = libinput_event_keyboard_get_key(k);
Expand Down Expand Up @@ -415,9 +419,7 @@ buffer_motion_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_pointer_get_time_usec(p) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_pointer_get_time_usec(p));
event->time = time;
snprintf(event->u.libinput.msg,
sizeof(event->u.libinput.msg),
Expand Down Expand Up @@ -450,8 +452,7 @@ buffer_absmotion_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_pointer_get_time_usec(p) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_pointer_get_time_usec(p));

event->time = time;
snprintf(event->u.libinput.msg,
Expand Down Expand Up @@ -483,8 +484,7 @@ buffer_pointer_button_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_pointer_get_time_usec(p) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_pointer_get_time_usec(p));
button = libinput_event_pointer_get_button(p);
state = libinput_event_pointer_get_button_state(p);

Expand Down Expand Up @@ -519,8 +519,7 @@ buffer_pointer_axis_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_pointer_get_time_usec(p) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_pointer_get_time_usec(p));
if (libinput_event_pointer_has_axis(p,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
h = libinput_event_pointer_get_axis_value(p,
Expand Down Expand Up @@ -590,8 +589,7 @@ buffer_touch_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_touch_get_time_usec(t) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_touch_get_time_usec(t));

if (etype != LIBINPUT_EVENT_TOUCH_FRAME) {
slot = libinput_event_touch_get_slot(t);
Expand Down Expand Up @@ -674,8 +672,7 @@ buffer_gesture_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_gesture_get_time_usec(g) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_gesture_get_time_usec(g));
event->time = time;

switch (etype) {
Expand Down Expand Up @@ -858,10 +855,7 @@ buffer_tablet_tool_proximity_event(struct record_context *ctx,
}

prox = libinput_event_tablet_tool_get_proximity_state(t);

time = ctx->offset ?
libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_tablet_tool_get_time_usec(t));
axes = buffer_tablet_axes(t);

idx = 0;
Expand Down Expand Up @@ -917,9 +911,7 @@ buffer_tablet_tool_button_event(struct record_context *ctx,

button = libinput_event_tablet_tool_get_button(t);
state = libinput_event_tablet_tool_get_button_state(t);

time = ctx->offset ?
libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0;
time = time_offset(ctx, libinput_event_tablet_tool_get_time_usec(t));

event->time = time;
snprintf(event->u.libinput.msg,
Expand Down Expand Up @@ -972,10 +964,7 @@ buffer_tablet_tool_event(struct record_context *ctx,
}

tip = libinput_event_tablet_tool_get_tip_state(t);

time = ctx->offset ?
libinput_event_tablet_tool_get_time_usec(t) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_tablet_tool_get_time_usec(t));
axes = buffer_tablet_axes(t);

event->time = time;
Expand Down Expand Up @@ -1012,9 +1001,7 @@ buffer_tablet_pad_button_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_tablet_pad_get_time_usec(p) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_tablet_pad_get_time_usec(p));
button = libinput_event_tablet_pad_get_button_number(p),
state = libinput_event_tablet_pad_get_button_state(p);
mode = libinput_event_tablet_pad_get_mode(p);
Expand Down Expand Up @@ -1082,9 +1069,7 @@ buffer_tablet_pad_ringstrip_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_tablet_pad_get_time_usec(p) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_tablet_pad_get_time_usec(p));
mode = libinput_event_tablet_pad_get_mode(p);

event->time = time;
Expand Down Expand Up @@ -1119,9 +1104,7 @@ buffer_switch_event(struct record_context *ctx,
abort();
}

time = ctx->offset ?
libinput_event_switch_get_time_usec(s) - ctx->offset : 0;

time = time_offset(ctx, libinput_event_switch_get_time_usec(s));
sw = libinput_event_switch_get_switch(s);
state = libinput_event_switch_get_switch_state(s);

Expand Down

0 comments on commit fb1f0a6

Please sign in to comment.