summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-11-11 13:39:43 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2015-11-12 06:52:51 +1000
commit1318ffadb527bdc9e924d4a67becb6a8aa5b1644 (patch)
treee5559bfb6ccec23fda8dc02f00e51945b348a389 /tools
parent30dbd6718ac28a950f5fd66c3bbbf81fac814c8d (diff)
tablet: split out tip handling into a separate event
The tablet tip works like a button in the kernel but is otherwise not really a button. Split it into an explicit tip up/down event instead. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/event-debug.c18
-rw-r--r--tools/event-gui.c34
2 files changed, 52 insertions, 0 deletions
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 05fb1a7..f0ae1dc 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -115,6 +115,9 @@ print_event_header(struct libinput_event *ev)
case LIBINPUT_EVENT_TABLET_PROXIMITY:
type = "TABLET_PROXIMITY";
break;
+ case LIBINPUT_EVENT_TABLET_TIP:
+ type = "TABLET_TIP";
+ break;
case LIBINPUT_EVENT_TABLET_BUTTON:
type = "TABLET_BUTTON";
break;
@@ -279,6 +282,18 @@ print_pointer_button_event(struct libinput_event *ev)
}
static void
+print_tablet_tip_event(struct libinput_event *ev)
+{
+ struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev);
+ enum libinput_tool_tip_state state;
+
+ print_event_time(libinput_event_tablet_get_time(p));
+
+ state = libinput_event_tablet_get_tip_state(p);
+ printf("%s\n", state == LIBINPUT_TOOL_TIP_DOWN ? "down" : "up");
+}
+
+static void
print_tablet_button_event(struct libinput_event *ev)
{
struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev);
@@ -667,6 +682,9 @@ handle_and_print_events(struct libinput *li)
case LIBINPUT_EVENT_TABLET_PROXIMITY:
print_proximity_event(ev);
break;
+ case LIBINPUT_EVENT_TABLET_TIP:
+ print_tablet_tip_event(ev);
+ break;
case LIBINPUT_EVENT_TABLET_BUTTON:
print_tablet_button_event(ev);
break;
diff --git a/tools/event-gui.c b/tools/event-gui.c
index c07213f..a7d8dd9 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -88,6 +88,8 @@ struct window {
struct {
double x, y;
double x_in, y_in;
+ double x_down, y_down;
+ double x_up, y_up;
double pressure;
double distance;
double tilt_x, tilt_y;
@@ -234,6 +236,20 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
cairo_save(cr);
}
+ if (w->tool.x_down && w->tool.y_down) {
+ cairo_rectangle(cr, w->tool.x_down - 10, w->tool.y_down - 10, 20, 20);
+ cairo_stroke(cr);
+ cairo_restore(cr);
+ cairo_save(cr);
+ }
+
+ if (w->tool.x_up && w->tool.y_up) {
+ cairo_rectangle(cr, w->tool.x_up - 10, w->tool.y_up - 10, 20, 20);
+ cairo_stroke(cr);
+ cairo_restore(cr);
+ cairo_save(cr);
+ }
+
if (w->tool.pressure)
cairo_set_source_rgb(cr, .8, .8, .2);
@@ -584,6 +600,7 @@ static void
handle_event_tablet(struct libinput_event *ev, struct window *w)
{
struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev);
+ double x, y;
switch (libinput_event_get_type(ev)) {
case LIBINPUT_EVENT_TABLET_PROXIMITY:
@@ -591,6 +608,10 @@ handle_event_tablet(struct libinput_event *ev, struct window *w)
LIBINPUT_TOOL_PROXIMITY_OUT) {
w->tool.x_in = 0;
w->tool.y_in = 0;
+ w->tool.x_down = 0;
+ w->tool.y_down = 0;
+ w->tool.x_up = 0;
+ w->tool.y_up = 0;
} else {
w->tool.x_in = libinput_event_tablet_get_x_transformed(t,
w->width);
@@ -612,6 +633,18 @@ handle_event_tablet(struct libinput_event *ev, struct window *w)
w->tool.tilt_y = libinput_event_tablet_get_axis_value(t,
LIBINPUT_TABLET_AXIS_TILT_Y);
break;
+ case LIBINPUT_EVENT_TABLET_TIP:
+ x = libinput_event_tablet_get_x_transformed(t, w->width);
+ y = libinput_event_tablet_get_y_transformed(t, w->height);
+ if (libinput_event_tablet_get_tip_state(t) ==
+ LIBINPUT_TOOL_TIP_DOWN) {
+ w->tool.x_down = x;
+ w->tool.y_down = y;
+ } else {
+ w->tool.x_up = x;
+ w->tool.y_up = y;
+ }
+ break;
case LIBINPUT_EVENT_TABLET_BUTTON:
break;
default:
@@ -676,6 +709,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
break;
case LIBINPUT_EVENT_TABLET_AXIS:
case LIBINPUT_EVENT_TABLET_PROXIMITY:
+ case LIBINPUT_EVENT_TABLET_TIP:
case LIBINPUT_EVENT_TABLET_BUTTON:
handle_event_tablet(ev, w);
break;