mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-05 08:48:02 +02:00
tools: handle pinch event in event-gui
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
f3f2b312ea
commit
bca183ec8e
1 changed files with 68 additions and 1 deletions
|
|
@ -78,6 +78,13 @@ struct window {
|
||||||
double x, y;
|
double x, y;
|
||||||
} swipe;
|
} swipe;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int nfingers;
|
||||||
|
double scale;
|
||||||
|
double angle;
|
||||||
|
double x, y;
|
||||||
|
} pinch;
|
||||||
|
|
||||||
struct libinput_device *devices[50];
|
struct libinput_device *devices[50];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -110,7 +117,7 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
|
||||||
{
|
{
|
||||||
struct window *w = data;
|
struct window *w = data;
|
||||||
struct touch *t;
|
struct touch *t;
|
||||||
int i;
|
int i, offset;
|
||||||
|
|
||||||
cairo_set_source_rgb(cr, 1, 1, 1);
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
cairo_rectangle(cr, 0, 0, w->width, w->height);
|
cairo_rectangle(cr, 0, 0, w->width, w->height);
|
||||||
|
|
@ -132,6 +139,26 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
|
||||||
}
|
}
|
||||||
cairo_restore(cr);
|
cairo_restore(cr);
|
||||||
|
|
||||||
|
/* pinch */
|
||||||
|
cairo_save(cr);
|
||||||
|
offset = w->pinch.scale * 100;
|
||||||
|
cairo_translate(cr, w->pinch.x, w->pinch.y);
|
||||||
|
cairo_rotate(cr, w->pinch.angle * M_PI/180.0);
|
||||||
|
if (w->pinch.nfingers > 0) {
|
||||||
|
cairo_set_source_rgb(cr, .4, .4, .8);
|
||||||
|
cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI);
|
||||||
|
cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI);
|
||||||
|
cairo_fill(cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||||
|
cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
|
||||||
|
cairo_restore(cr);
|
||||||
|
|
||||||
/* draw pointer sprite */
|
/* draw pointer sprite */
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||||
cairo_save(cr);
|
cairo_save(cr);
|
||||||
|
|
@ -212,6 +239,10 @@ map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||||
w->swipe.x = w->width/2;
|
w->swipe.x = w->width/2;
|
||||||
w->swipe.y = w->height/2;
|
w->swipe.y = w->height/2;
|
||||||
|
|
||||||
|
w->pinch.scale = 1.0;
|
||||||
|
w->pinch.x = w->width/2;
|
||||||
|
w->pinch.y = w->height/2;
|
||||||
|
|
||||||
g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w);
|
g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w);
|
||||||
|
|
||||||
window = gdk_event_get_window(event);
|
window = gdk_event_get_window(event);
|
||||||
|
|
@ -485,6 +516,41 @@ handle_event_swipe(struct libinput_event *ev, struct window *w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_event_pinch(struct libinput_event *ev, struct window *w)
|
||||||
|
{
|
||||||
|
struct libinput_event_gesture *g = libinput_event_get_gesture_event(ev);
|
||||||
|
int nfingers;
|
||||||
|
double dx, dy;
|
||||||
|
|
||||||
|
nfingers = libinput_event_gesture_get_finger_count(g);
|
||||||
|
|
||||||
|
switch (libinput_event_get_type(ev)) {
|
||||||
|
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
|
||||||
|
w->pinch.nfingers = nfingers;
|
||||||
|
w->pinch.x = w->width/2;
|
||||||
|
w->pinch.y = w->height/2;
|
||||||
|
break;
|
||||||
|
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
|
||||||
|
dx = libinput_event_gesture_get_dx(g);
|
||||||
|
dy = libinput_event_gesture_get_dy(g);
|
||||||
|
w->pinch.x += dx;
|
||||||
|
w->pinch.y += dy;
|
||||||
|
w->pinch.scale = libinput_event_gesture_get_scale(g);
|
||||||
|
w->pinch.angle += libinput_event_gesture_get_angle_delta(g);
|
||||||
|
break;
|
||||||
|
case LIBINPUT_EVENT_GESTURE_PINCH_END:
|
||||||
|
w->pinch.nfingers = 0;
|
||||||
|
w->pinch.x = w->width/2;
|
||||||
|
w->pinch.y = w->height/2;
|
||||||
|
w->pinch.angle = 0.0;
|
||||||
|
w->pinch.scale = 1.0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
|
handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
|
||||||
{
|
{
|
||||||
|
|
@ -538,6 +604,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
|
||||||
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
|
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
|
||||||
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
|
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
|
||||||
case LIBINPUT_EVENT_GESTURE_PINCH_END:
|
case LIBINPUT_EVENT_GESTURE_PINCH_END:
|
||||||
|
handle_event_pinch(ev, w);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue