[PATCH libinput 2/2] extend tools to print and display touch event properties

2015-11-02 Thread Andreas Pokorny
event-gui draws the touch contact as two concentric ellipses that indicate
contact pressure through oppacity.

Signed-off-by: Andreas Pokorny 
---
 tools/event-debug.c | 29 -
 tools/event-gui.c   | 38 +-
 2 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/tools/event-debug.c b/tools/event-debug.c
index 1ac0086..b0675df 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -300,14 +300,41 @@ 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)",
   libinput_event_touch_get_slot(t),
   libinput_event_touch_get_seat_slot(t),
   x, y,
   xmm, ymm);
+
+   if (has_major)
+   printf(" major:%3.2f/%3.2fmm", major, majormm);
+   if (has_minor)
+   printf(" minor:%3.2f/%3.2fmm", minor, minormm);
+   if (has_orientation)
+   printf(" o:%3.1f°", orientation);
+   if (has_pressure)
+   printf(" p:%1.2f", pressure);
+
+   printf("\n");
 }
 
 static void
diff --git a/tools/event-gui.c b/tools/event-gui.c
index 0b0e9d7..d8187bc 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,13 +182,24 @@ 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);
-   cairo_fill(cr);
-   cairo_restore(cr);
+   if (t->active) {
+   cairo_save(cr);
+   /* 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);
+   }
}
 
/* abs position */
@@ -394,6 +408,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 +423,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

___

Re: [PATCH libinput 2/2] extend tools to print and display touch event properties

2015-10-20 Thread Peter Hutterer
On Sun, Sep 06, 2015 at 02:55:13PM +0200, Andreas Pokorny wrote:
> event-gui draws the touch contact as two concentric ellipses that indicate
> contact pressure through oppacity.
> 
> Signed-off-by: Andreas Pokorny 
> ---
>  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
> +);

whoah, this line gets quite confusing, especially the [1110] at the end (in
my case). can we split this up, so that you only print the values we
actually have?

I'm also going to argue that one decimal precision for the angle
is enough, and two decimals for 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);

(event-gui:21643): Gtk-WARNING **: drawing failure for widget
`GtkDrawingArea': invalid matrix (not invertible)

(event-gui:21643): Gtk-WARNING **: drawing failure for widget `GtkWindow':
invalid matrix (not invertible)

minor/major are 0/0 here, mostly because my screen returns garbage for
major/minor (0.31mm) but this needs to be caught.

Cheers,
   Peter



> + 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);
> +
> + 

[PATCH libinput 2/2] extend tools to print and display touch event properties

2015-09-06 Thread Andreas Pokorny
event-gui draws the touch contact as two concentric ellipses that indicate
contact pressure through oppacity.

Signed-off-by: Andreas Pokorny 
---
 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

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel