From 7864e778cc10dbc2b0064f0f1953ef5389f0d68b Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Wed, 16 Feb 2011 18:07:57 +0100 Subject: Break out common display functions Signed-off-by: Henrik Rydberg --- tools/Makefile.am | 4 +- tools/common-defs.h | 83 +++++++++++++++++++++++++++++++++++++++++ tools/utouch-frame-test-mtdev.c | 62 +----------------------------- tools/utouch-frame-test-xi2.c | 67 ++------------------------------- 4 files changed, 90 insertions(+), 126 deletions(-) create mode 100644 tools/common-defs.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 3b612cc..50027fb 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = utouch-frame-test-mtdev INCLUDES=-I$(top_srcdir)/include/ -utouch_frame_test_mtdev_SOURCES = utouch-frame-test-mtdev.c +utouch_frame_test_mtdev_SOURCES = common-defs.h utouch-frame-test-mtdev.c utouch_frame_test_mtdev_LDFLAGS = -L$(top_builddir)/src/.libs/ \ -lutouch-frame -lutouch-evemu -lmtdev -lm @@ -12,7 +12,7 @@ AM_CFLAGS = $(XINPUT_CFLAGS) bin_PROGRAMS += utouch-frame-test-xi2 -utouch_frame_test_xi2_SOURCES = utouch-frame-test-xi2.c +utouch_frame_test_xi2_SOURCES = common-defs.h utouch-frame-test-xi2.c utouch_frame_test_xi2_LDFLAGS = $(XINPUT_LIBS) $(X11_LIBS) \ -L$(top_builddir)/src/.libs/ -lutouch-frame diff --git a/tools/common-defs.h b/tools/common-defs.h new file mode 100644 index 0000000..0e08bc5 --- /dev/null +++ b/tools/common-defs.h @@ -0,0 +1,83 @@ +/***************************************************************************** + * + * utouch-frame - Touch Frame Library + * + * Copyright (C) 2010-2011 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Henrik Rydberg + * + ****************************************************************************/ + +static void report_device_caps(utouch_frame_handle fh) +{ + const struct utouch_surface *s = utouch_frame_get_surface(fh); + + fprintf(stderr, "device props:\n"); + if (s->needs_pointer) + fprintf(stderr, "\tpointer\n"); + if (s->is_direct) + fprintf(stderr, "\tdirect\n"); + if (s->is_buttonpad) + fprintf(stderr, "\tbuttonpad\n"); + if (s->is_semi_mt) + fprintf(stderr, "\tsemi_mt\n"); + fprintf(stderr, "device mt events:\n"); + if (s->use_touch_major) + fprintf(stderr, "\ttouch_major\n"); + if (s->use_touch_minor) + fprintf(stderr, "\ttouch_minor\n"); + if (s->use_width_major) + fprintf(stderr, "\twidth_major\n"); + if (s->use_width_minor) + fprintf(stderr, "\twidth_minor\n"); + if (s->use_orientation) + fprintf(stderr, "\torientation\n"); + if (s->use_pressure) + fprintf(stderr, "\tpressure\n"); + if (s->use_distance) + fprintf(stderr, "\tdistance\n"); +} + +static void report_frame(const struct utouch_frame *frame) +{ + int i; + + for (i = 0; i < frame->num_active; i++) { + const struct utouch_contact *t = frame->active[i]; + + fprintf(stderr, "touch %d\n", i); + fprintf(stderr, " slot: %d\n", t->slot); + fprintf(stderr, " id: %d\n", t->id); + fprintf(stderr, " tool_type: %d\n", t->tool_type); + fprintf(stderr, " x: %f\n", t->x); + fprintf(stderr, " y: %f\n", t->y); + fprintf(stderr, " touch_major: %f\n", t->touch_major); + fprintf(stderr, " touch_minor: %f\n", t->touch_minor); + fprintf(stderr, " width_major: %f\n", t->width_major); + fprintf(stderr, " width_minor: %f\n", t->width_minor); + fprintf(stderr, " angle: %f\n", t->orientation); + fprintf(stderr, " pressure: %f\n", t->pressure); + fprintf(stderr, " distance: %f\n", t->distance); + } + + fprintf(stderr, "sync %d %ld %d %d %d\n", + frame->num_active, + frame->time, + frame->sequence_id, + frame->revision, + frame->slot_revision); +} diff --git a/tools/utouch-frame-test-mtdev.c b/tools/utouch-frame-test-mtdev.c index 86f5b64..4838f84 100644 --- a/tools/utouch-frame-test-mtdev.c +++ b/tools/utouch-frame-test-mtdev.c @@ -30,6 +30,7 @@ #include #include #include +#include "common-defs.h" struct frame_test { struct evemu_device *evemu; @@ -69,36 +70,6 @@ static void destroy_all(struct frame_test *test) memset(test, 0, sizeof(*test)); } -static void report_frame(const struct utouch_frame *frame) -{ - int i; - - for (i = 0; i < frame->num_active; i++) { - const struct utouch_contact *t = frame->active[i]; - - fprintf(stderr, "touch %d\n", i); - fprintf(stderr, " slot: %d\n", t->slot); - fprintf(stderr, " id: %d\n", t->id); - fprintf(stderr, " tool_type: %d\n", t->tool_type); - fprintf(stderr, " x: %f\n", t->x); - fprintf(stderr, " y: %f\n", t->y); - fprintf(stderr, " touch_major: %f\n", t->touch_major); - fprintf(stderr, " touch_minor: %f\n", t->touch_minor); - fprintf(stderr, " width_major: %f\n", t->width_major); - fprintf(stderr, " width_minor: %f\n", t->width_minor); - fprintf(stderr, " angle: %f\n", t->orientation); - fprintf(stderr, " pressure: %f\n", t->pressure); - fprintf(stderr, " distance: %f\n", t->distance); - } - - fprintf(stderr, "sync %d %ld %d %d %d\n", - frame->num_active, - frame->time, - frame->sequence_id, - frame->revision, - frame->slot_revision); -} - static void loop_device(struct frame_test *test, int fd) { const struct utouch_frame *frame; @@ -113,35 +84,6 @@ static void loop_device(struct frame_test *test, int fd) } } -static void report_device_caps(struct frame_test *test) -{ - struct utouch_surface *s = utouch_frame_get_surface(test->fh); - fprintf(stderr, "device props:\n"); - if (s->needs_pointer) - fprintf(stderr, "\tpointer\n"); - if (s->is_direct) - fprintf(stderr, "\tdirect\n"); - if (s->is_buttonpad) - fprintf(stderr, "\tbuttonpad\n"); - if (s->is_semi_mt) - fprintf(stderr, "\tsemi_mt\n"); - fprintf(stderr, "device mt events:\n"); - if (s->use_touch_major) - fprintf(stderr, "\ttouch_major\n"); - if (s->use_touch_minor) - fprintf(stderr, "\ttouch_minor\n"); - if (s->use_width_major) - fprintf(stderr, "\twidth_major\n"); - if (s->use_width_minor) - fprintf(stderr, "\twidth_minor\n"); - if (s->use_orientation) - fprintf(stderr, "\torientation\n"); - if (s->use_pressure) - fprintf(stderr, "\tpressure\n"); - if (s->use_distance) - fprintf(stderr, "\tdistance\n"); -} - int main(int argc, char *argv[]) { struct frame_test test; @@ -182,7 +124,7 @@ int main(int argc, char *argv[]) return -1; } - report_device_caps(&test); + report_device_caps(test.fh); loop_device(&test, fd); diff --git a/tools/utouch-frame-test-xi2.c b/tools/utouch-frame-test-xi2.c index df68c1a..015c119 100644 --- a/tools/utouch-frame-test-xi2.c +++ b/tools/utouch-frame-test-xi2.c @@ -30,6 +30,7 @@ #include #include #include +#include "common-defs.h" static int opcode; @@ -91,68 +92,6 @@ static void destroy_all(struct frame_test *test) memset(test, 0, sizeof(*test)); } -static void report_device_caps(struct frame_test *test) -{ - struct utouch_surface *s = utouch_frame_get_surface(test->fh); - fprintf(stderr, "device props:\n"); - if (s->needs_pointer) - fprintf(stderr, "\tpointer\n"); - if (s->is_direct) - fprintf(stderr, "\tdirect\n"); - if (s->is_buttonpad) - fprintf(stderr, "\tbuttonpad\n"); - if (s->is_semi_mt) - fprintf(stderr, "\tsemi_mt\n"); - fprintf(stderr, "device mt events:\n"); - if (s->use_touch_major) - fprintf(stderr, "\ttouch_major\n"); - if (s->use_touch_minor) - fprintf(stderr, "\ttouch_minor\n"); - if (s->use_width_major) - fprintf(stderr, "\twidth_major\n"); - if (s->use_width_minor) - fprintf(stderr, "\twidth_minor\n"); - if (s->use_orientation) - fprintf(stderr, "\torientation\n"); - if (s->use_pressure) - fprintf(stderr, "\tpressure\n"); - if (s->use_distance) - fprintf(stderr, "\tdistance\n"); -} - -static void report_frame(const struct utouch_frame *frame, - const XIDeviceEvent *ev) -{ - int i; - - for (i = 0; i < frame->num_active; i++) { - const struct utouch_contact *t = frame->active[i]; - - fprintf(stderr, "touch %d\n", i); - fprintf(stderr, " slot: %d\n", t->slot); - fprintf(stderr, " id: %d\n", t->id); - fprintf(stderr, " tool_type: %d\n", t->tool_type); - fprintf(stderr, " x: %f\n", t->x); - fprintf(stderr, " y: %f\n", t->y); - fprintf(stderr, " touch_major: %f\n", t->touch_major); - fprintf(stderr, " touch_minor: %f\n", t->touch_minor); - fprintf(stderr, " width_major: %f\n", t->width_major); - fprintf(stderr, " width_minor: %f\n", t->width_minor); - fprintf(stderr, " angle: %f\n", t->orientation); - fprintf(stderr, " pressure: %f\n", t->pressure); - fprintf(stderr, " distance: %f\n", t->distance); - } - - fprintf(stderr, "sync %d %ld %d %d %d %f %f\n", - frame->num_active, - frame->time, - frame->sequence_id, - frame->revision, - frame->slot_revision, - ev->root_x, - ev->root_y); -} - static void handle_event(struct frame_test *test, XEvent *ev) { XGenericEventCookie *gev = &ev->xcookie; @@ -175,7 +114,7 @@ static void handle_event(struct frame_test *test, XEvent *ev) if (gev->type == GenericEvent && gev->extension == opcode) { frame = utouch_frame_pump_xi2(test->fh, dev); if (frame) - report_frame(frame, dev); + report_frame(frame); } XFreeEventData(test->display, gev); break; @@ -229,7 +168,7 @@ int main(int argc, char *argv[]) return -1; } - report_device_caps(&test); + report_device_caps(test.fh); loop_device(&test); -- cgit v1.2.3