Skip to content

Commit

Permalink
tools: debug-*: show unaccelerated deltas for pointer events
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 Aug 8, 2018
1 parent 28fc00b commit f78d666
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/libinput-debug-events.c
Expand Up @@ -316,10 +316,12 @@ print_motion_event(struct libinput_event *ev)
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
double x = libinput_event_pointer_get_dx(p);
double y = libinput_event_pointer_get_dy(p);
double ux = libinput_event_pointer_get_dx_unaccelerated(p);
double uy = libinput_event_pointer_get_dy_unaccelerated(p);

print_event_time(libinput_event_pointer_get_time(p));

printq("%6.2f/%6.2f\n", x, y);
printq("%6.2f/%6.2f (%+6.2f/%+6.2f)\n", x, y, ux, uy);
}

static void
Expand Down
36 changes: 36 additions & 0 deletions tools/libinput-debug-gui.c
Expand Up @@ -64,6 +64,11 @@ struct window {
/* sprite position */
double x, y;

/* these are for the delta coordinates, but they're not
* deltas, they are converted into abs positions */
size_t ndeltas;
struct point deltas[64];

/* abs position */
int absx, absy;

Expand Down Expand Up @@ -268,6 +273,26 @@ draw_tablet(struct window *w, cairo_t *cr)
cairo_fill(cr);
cairo_restore(cr);

/* pointer deltas */
mask = ARRAY_LENGTH(w->deltas);
first = max(w->ndeltas + 1, mask) - mask;
last = w->ndeltas;

cairo_save(cr);
cairo_set_source_rgb(cr, .8, .5, .2);

x = w->deltas[first % mask].x;
y = w->deltas[first % mask].y;
cairo_move_to(cr, x, y);

for (i = first + 1; i < last; i++) {
x = w->deltas[i % mask].x;
y = w->deltas[i % mask].y;
cairo_line_to(cr, x, y);
}

cairo_stroke(cr);

/* tablet deltas */
mask = ARRAY_LENGTH(w->tool.deltas);
first = max(w->tool.ndeltas + 1, mask) - mask;
Expand Down Expand Up @@ -541,11 +566,22 @@ handle_event_motion(struct libinput_event *ev, struct window *w)
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
double dx = libinput_event_pointer_get_dx(p),
dy = libinput_event_pointer_get_dy(p);
struct point point;
const int mask = ARRAY_LENGTH(w->deltas);
size_t idx;

w->x += dx;
w->y += dy;
w->x = clip(w->x, 0.0, w->width);
w->y = clip(w->y, 0.0, w->height);

idx = w->ndeltas % mask;
point = w->deltas[idx];
idx = (w->ndeltas + 1) % mask;
point.x += libinput_event_pointer_get_dx_unaccelerated(p);
point.y += libinput_event_pointer_get_dy_unaccelerated(p);
w->deltas[idx] = point;
w->ndeltas++;
}

static void
Expand Down

0 comments on commit f78d666

Please sign in to comment.