[PATCH libinput 2/2] extend tools to print and display touch event properties
Andreas Pokorny
andreas.pokorny at canonical.com
Sun Sep 6 05:55:13 PDT 2015
event-gui draws the touch contact as two concentric ellipses that indicate
contact pressure through oppacity.
Signed-off-by: Andreas Pokorny <andreas.pokorny at canonical.com>
---
tools/event-debug.c | 30 ++++++++++++++++++++++++++++--
tools/event-gui.c | 30 ++++++++++++++++++++++++++++--
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 1ac0086..3ee9907 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -300,14 +300,40 @@ print_touch_event_with_coords(struct libinput_event *ev)
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);
+ double major = libinput_event_touch_get_major_transformed(
+ t,
+ screen_width,
+ screen_height);
+ double minor = libinput_event_touch_get_minor_transformed(
+ t,
+ screen_width,
+ screen_height);
+ double majormm = libinput_event_touch_get_major(t);
+ double minormm = libinput_event_touch_get_minor(t);
+ double pressure = libinput_event_touch_get_pressure(t);
+ double orientation = libinput_event_touch_get_orientation(t);
+ int has_major = libinput_event_touch_has_major(t);
+ int has_minor = libinput_event_touch_has_minor(t);
+ int has_orientation = libinput_event_touch_has_orientation(t);
+ int has_pressure = libinput_event_touch_has_pressure(t);
print_event_time(libinput_event_touch_get_time(t));
- printf("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n",
+ printf("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm) %5.2f/%5.2f "
+ "(%5.2f/%5.2fmm) %3.2f° %1.5f [%d%d%d%d]\n",
libinput_event_touch_get_slot(t),
libinput_event_touch_get_seat_slot(t),
x, y,
- xmm, ymm);
+ xmm, ymm,
+ major, minor,
+ majormm, minormm,
+ orientation,
+ pressure,
+ has_major,
+ has_minor,
+ has_orientation,
+ has_pressure
+ );
}
static void
diff --git a/tools/event-gui.c b/tools/event-gui.c
index 0b0e9d7..7c2b546 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -49,6 +49,9 @@ struct tools_context context;
struct touch {
int active;
int x, y;
+ double major, minor;
+ double angle;
+ double pressure;
};
struct window {
@@ -179,12 +182,21 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
cairo_restore(cr);
/* touch points */
- cairo_set_source_rgb(cr, .8, .2, .2);
ARRAY_FOR_EACH(w->touches, t) {
cairo_save(cr);
- cairo_arc(cr, t->x, t->y, 10, 0, 2 * M_PI);
+ /* paint a filled ellipse with the original major minor values */
+ cairo_set_source_rgba(cr, .8, .2, .2, 0.5 + t->pressure / 2.);
+ cairo_translate (cr, t->x, t->y);
+ cairo_rotate(cr, t->angle * (M_PI / 180.0));
+ cairo_scale (cr, t->minor, t->major);
+ cairo_arc(cr, 0., 0., 1., 0, 2 * M_PI);
cairo_fill(cr);
+
+ /* paint a larger surrounding ellipse */
+ cairo_arc(cr, 0., 0., 4., 0, 2 * M_PI);
+ cairo_stroke(cr);
+
cairo_restore(cr);
}
@@ -394,6 +406,8 @@ handle_event_touch(struct libinput_event *ev, struct window *w)
int slot = libinput_event_touch_get_seat_slot(t);
struct touch *touch;
double x, y;
+ double major;
+ double minor;
if (slot == -1 || slot >= (int) ARRAY_LENGTH(w->touches))
return;
@@ -407,10 +421,22 @@ handle_event_touch(struct libinput_event *ev, struct window *w)
x = libinput_event_touch_get_x_transformed(t, w->width),
y = libinput_event_touch_get_y_transformed(t, w->height);
+ major = libinput_event_touch_get_major_transformed(t, w->width, w->height);
+ minor = libinput_event_touch_get_minor_transformed(t, w->width, w->height);
+
+ if (!libinput_event_touch_has_major(t))
+ major = 10.0;
+
+ if (!libinput_event_touch_has_minor(t))
+ minor = major;
touch->active = 1;
touch->x = (int)x;
touch->y = (int)y;
+ touch->major = major;
+ touch->minor = minor;
+ touch->angle = libinput_event_touch_get_orientation(t);
+ touch->pressure = libinput_event_touch_get_pressure(t);
}
static void
--
2.5.0
More information about the wayland-devel
mailing list