2014-05-27 15:29:55 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2014-05-27 15:29:55 +10:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2014-05-27 15:29:55 +10:00
|
|
|
*/
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
2017-06-19 18:38:33 +10:00
|
|
|
#include <getopt.h>
|
2014-05-27 15:29:55 +10:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2017-12-01 09:31:07 +10:00
|
|
|
#include <stdarg.h>
|
2014-05-27 15:29:55 +10:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
#include <libinput.h>
|
|
|
|
|
#include <libinput-util.h>
|
|
|
|
|
|
2014-12-18 14:47:54 +10:00
|
|
|
#include "shared.h"
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
#define clip(val_, min_, max_) min((max_), max((min_), (val_)))
|
|
|
|
|
|
|
|
|
|
struct touch {
|
|
|
|
|
int active;
|
|
|
|
|
int x, y;
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-12 16:39:15 +10:00
|
|
|
struct point {
|
|
|
|
|
double x, y;
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
struct window {
|
2017-06-19 18:38:33 +10:00
|
|
|
struct tools_options options;
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
GtkWidget *win;
|
|
|
|
|
GtkWidget *area;
|
|
|
|
|
int width, height; /* of window */
|
|
|
|
|
|
|
|
|
|
/* sprite position */
|
2014-06-23 23:32:29 +02:00
|
|
|
double x, y;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
/* abs position */
|
|
|
|
|
int absx, absy;
|
|
|
|
|
|
|
|
|
|
/* scroll bar positions */
|
2015-04-22 15:31:21 +10:00
|
|
|
double vx, vy;
|
|
|
|
|
double hx, hy;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
/* touch positions */
|
|
|
|
|
struct touch touches[32];
|
|
|
|
|
|
|
|
|
|
/* l/m/r mouse buttons */
|
|
|
|
|
int l, m, r;
|
2014-07-04 08:56:44 +10:00
|
|
|
|
2015-05-22 10:40:16 +10:00
|
|
|
/* touchpad swipe */
|
|
|
|
|
struct {
|
|
|
|
|
int nfingers;
|
|
|
|
|
double x, y;
|
|
|
|
|
} swipe;
|
|
|
|
|
|
2015-05-22 11:14:41 +10:00
|
|
|
struct {
|
|
|
|
|
int nfingers;
|
|
|
|
|
double scale;
|
|
|
|
|
double angle;
|
|
|
|
|
double x, y;
|
|
|
|
|
} pinch;
|
|
|
|
|
|
2015-11-05 14:37:29 +10:00
|
|
|
struct {
|
|
|
|
|
double x, y;
|
|
|
|
|
double x_in, y_in;
|
2015-11-11 13:39:43 +10:00
|
|
|
double x_down, y_down;
|
|
|
|
|
double x_up, y_up;
|
2015-11-05 14:37:29 +10:00
|
|
|
double pressure;
|
|
|
|
|
double distance;
|
|
|
|
|
double tilt_x, tilt_y;
|
2016-01-12 16:39:15 +10:00
|
|
|
|
|
|
|
|
/* these are for the delta coordinates, but they're not
|
2017-02-27 15:24:09 +10:00
|
|
|
* deltas, they are converted into abs positions */
|
2016-01-12 16:39:15 +10:00
|
|
|
size_t ndeltas;
|
|
|
|
|
struct point deltas[64];
|
2015-11-05 14:37:29 +10:00
|
|
|
} tool;
|
|
|
|
|
|
2014-07-04 08:56:44 +10:00
|
|
|
struct libinput_device *devices[50];
|
2014-05-27 15:29:55 +10:00
|
|
|
};
|
|
|
|
|
|
2016-10-24 11:06:23 +10:00
|
|
|
LIBINPUT_ATTRIBUTE_PRINTF(1, 2)
|
2017-06-19 18:38:33 +10:00
|
|
|
static inline void
|
2014-05-27 15:29:55 +10:00
|
|
|
msg(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
printf("info: ");
|
|
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
vprintf(fmt, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
static inline void
|
|
|
|
|
draw_gestures(struct window *w, cairo_t *cr)
|
2014-05-27 15:29:55 +10:00
|
|
|
{
|
2016-01-29 16:05:25 +10:00
|
|
|
int i;
|
|
|
|
|
int offset;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2015-05-22 10:40:16 +10:00
|
|
|
/* swipe */
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_translate(cr, w->swipe.x, w->swipe.y);
|
|
|
|
|
for (i = 0; i < w->swipe.nfingers; i++) {
|
|
|
|
|
cairo_set_source_rgb(cr, .8, .8, .4);
|
|
|
|
|
cairo_arc(cr, (i - 2) * 40, 0, 20, 0, 2 * M_PI);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) { /* 4 fg max */
|
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
|
cairo_arc(cr, (i - 2) * 40, 0, 20, 0, 2 * M_PI);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
}
|
|
|
|
|
cairo_restore(cr);
|
|
|
|
|
|
2015-05-22 11:14:41 +10:00
|
|
|
/* 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);
|
|
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
draw_scrollbars(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
2014-05-27 15:29:55 +10:00
|
|
|
cairo_set_source_rgb(cr, .4, .8, 0);
|
|
|
|
|
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_rectangle(cr, w->vx - 10, w->vy - 20, 20, 40);
|
|
|
|
|
cairo_rectangle(cr, w->hx - 20, w->hy - 10, 40, 20);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
cairo_restore(cr);
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
draw_touchpoints(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
struct touch *t;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
static inline void
|
|
|
|
|
draw_abs_pointer(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
2014-05-27 15:29:55 +10:00
|
|
|
cairo_set_source_rgb(cr, .2, .4, .8);
|
|
|
|
|
|
|
|
|
|
cairo_save(cr);
|
2014-07-03 09:54:29 +10:00
|
|
|
cairo_arc(cr, w->absx, w->absy, 10, 0, 2 * M_PI);
|
2014-05-27 15:29:55 +10:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
cairo_restore(cr);
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
static inline void
|
|
|
|
|
draw_buttons(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
2014-05-27 15:29:55 +10:00
|
|
|
cairo_save(cr);
|
|
|
|
|
if (w->l || w->m || w->r) {
|
|
|
|
|
cairo_set_source_rgb(cr, .2, .8, .8);
|
|
|
|
|
if (w->l)
|
|
|
|
|
cairo_rectangle(cr, w->width/2 - 100, w->height - 200, 70, 30);
|
|
|
|
|
if (w->m)
|
|
|
|
|
cairo_rectangle(cr, w->width/2 - 20, w->height - 200, 40, 30);
|
|
|
|
|
if (w->r)
|
|
|
|
|
cairo_rectangle(cr, w->width/2 + 30, w->height - 200, 70, 30);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
|
cairo_rectangle(cr, w->width/2 - 100, w->height - 200, 70, 30);
|
|
|
|
|
cairo_rectangle(cr, w->width/2 - 20, w->height - 200, 40, 30);
|
|
|
|
|
cairo_rectangle(cr, w->width/2 + 30, w->height - 200, 70, 30);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
cairo_restore(cr);
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
draw_tablet(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
double x, y;
|
2016-12-05 20:31:31 +10:00
|
|
|
int first, last;
|
|
|
|
|
size_t mask;
|
2016-01-29 16:05:25 +10:00
|
|
|
int i;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2015-11-05 14:37:29 +10:00
|
|
|
/* tablet tool, square for prox-in location */
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_set_source_rgb(cr, .8, .8, .8);
|
|
|
|
|
if (w->tool.x_in && w->tool.y_in) {
|
|
|
|
|
cairo_rectangle(cr, w->tool.x_in - 15, w->tool.y_in - 15, 30, 30);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
cairo_restore(cr);
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 13:39:43 +10:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-05 14:37:29 +10:00
|
|
|
if (w->tool.pressure)
|
|
|
|
|
cairo_set_source_rgb(cr, .8, .8, .2);
|
|
|
|
|
|
|
|
|
|
cairo_translate(cr, w->tool.x, w->tool.y);
|
2016-06-27 11:33:49 +10:00
|
|
|
cairo_scale(cr, 1.0 + w->tool.tilt_x/30.0, 1.0 + w->tool.tilt_y/30.0);
|
2015-11-05 14:37:29 +10:00
|
|
|
cairo_arc(cr, 0, 0,
|
|
|
|
|
1 + 10 * max(w->tool.pressure, w->tool.distance),
|
|
|
|
|
0, 2 * M_PI);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
cairo_restore(cr);
|
|
|
|
|
|
2016-01-12 16:39:15 +10:00
|
|
|
/* tablet deltas */
|
|
|
|
|
mask = ARRAY_LENGTH(w->tool.deltas);
|
|
|
|
|
first = max(w->tool.ndeltas + 1, mask) - mask;
|
|
|
|
|
last = w->tool.ndeltas;
|
|
|
|
|
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_set_source_rgb(cr, .8, .8, .2);
|
|
|
|
|
|
|
|
|
|
x = w->tool.deltas[first % mask].x;
|
|
|
|
|
y = w->tool.deltas[first % mask].y;
|
|
|
|
|
cairo_move_to(cr, x, y);
|
|
|
|
|
|
|
|
|
|
for (i = first + 1; i < last; i++) {
|
|
|
|
|
x = w->tool.deltas[i % mask].x;
|
|
|
|
|
y = w->tool.deltas[i % mask].y;
|
|
|
|
|
cairo_line_to(cr, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
draw_pointer(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
2016-01-28 16:31:22 +10:00
|
|
|
/* draw pointer sprite */
|
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_move_to(cr, w->x, w->y);
|
|
|
|
|
cairo_rel_line_to(cr, 10, 15);
|
|
|
|
|
cairo_rel_line_to(cr, -10, 0);
|
|
|
|
|
cairo_rel_line_to(cr, 0, -15);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
cairo_restore(cr);
|
2016-01-29 16:05:25 +10:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 11:04:26 +10:00
|
|
|
static inline void
|
|
|
|
|
draw_background(struct window *w, cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
int x1, x2, y1, y2, x3, y3, x4, y4;
|
|
|
|
|
int cols;
|
|
|
|
|
|
|
|
|
|
/* 10px and 5px grids */
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
|
|
|
|
|
x1 = w->width/2 - 200;
|
|
|
|
|
y1 = w->height/2 - 200;
|
|
|
|
|
x2 = w->width/2 + 200;
|
|
|
|
|
y2 = w->height/2 - 200;
|
|
|
|
|
for (cols = 1; cols < 10; cols++) {
|
|
|
|
|
cairo_move_to(cr, x1 + 10 * cols, y1);
|
|
|
|
|
cairo_rel_line_to(cr, 0, 100);
|
|
|
|
|
cairo_move_to(cr, x1, y1 + 10 * cols);
|
|
|
|
|
cairo_rel_line_to(cr, 100, 0);
|
|
|
|
|
|
|
|
|
|
cairo_move_to(cr, x2 + 5 * cols, y2);
|
|
|
|
|
cairo_rel_line_to(cr, 0, 50);
|
|
|
|
|
cairo_move_to(cr, x2, y2 + 5 * cols);
|
|
|
|
|
cairo_rel_line_to(cr, 50, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3px horiz/vert bar codes */
|
|
|
|
|
x3 = w->width/2 - 200;
|
|
|
|
|
y3 = w->height/2 + 200;
|
|
|
|
|
x4 = w->width/2 + 200;
|
|
|
|
|
y4 = w->height/2 + 100;
|
|
|
|
|
for (cols = 0; cols < 50; cols++) {
|
|
|
|
|
cairo_move_to(cr, x3 + 3 * cols, y3);
|
|
|
|
|
cairo_rel_line_to(cr, 0, 20);
|
|
|
|
|
|
|
|
|
|
cairo_move_to(cr, x4, y4 + 3 * cols);
|
|
|
|
|
cairo_rel_line_to(cr, 20, 0);
|
|
|
|
|
}
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
static gboolean
|
|
|
|
|
draw(GtkWidget *widget, cairo_t *cr, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
struct window *w = data;
|
|
|
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
|
cairo_rectangle(cr, 0, 0, w->width, w->height);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
2016-04-19 11:04:26 +10:00
|
|
|
draw_background(w, cr);
|
|
|
|
|
|
2016-01-29 16:05:25 +10:00
|
|
|
draw_gestures(w, cr);
|
|
|
|
|
draw_scrollbars(w, cr);
|
|
|
|
|
draw_touchpoints(w, cr);
|
|
|
|
|
draw_abs_pointer(w, cr);
|
|
|
|
|
draw_buttons(w, cr);
|
|
|
|
|
draw_tablet(w, cr);
|
|
|
|
|
draw_pointer(w, cr);
|
2016-01-28 16:31:22 +10:00
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
struct window *w = data;
|
2015-03-18 09:44:09 +10:00
|
|
|
GdkDisplay *display;
|
2017-06-13 15:18:56 +10:00
|
|
|
GdkSeat *seat;
|
2015-03-18 09:44:09 +10:00
|
|
|
GdkWindow *window;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
gtk_window_get_size(GTK_WINDOW(widget), &w->width, &w->height);
|
|
|
|
|
|
|
|
|
|
w->x = w->width/2;
|
|
|
|
|
w->y = w->height/2;
|
|
|
|
|
|
|
|
|
|
w->vx = w->width/2;
|
|
|
|
|
w->vy = w->height/2;
|
|
|
|
|
w->hx = w->width/2;
|
|
|
|
|
w->hy = w->height/2;
|
|
|
|
|
|
2015-05-22 10:40:16 +10:00
|
|
|
w->swipe.x = w->width/2;
|
|
|
|
|
w->swipe.y = w->height/2;
|
|
|
|
|
|
2015-05-22 11:14:41 +10:00
|
|
|
w->pinch.scale = 1.0;
|
|
|
|
|
w->pinch.x = w->width/2;
|
|
|
|
|
w->pinch.y = w->height/2;
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w);
|
|
|
|
|
|
2015-03-18 09:44:09 +10:00
|
|
|
window = gdk_event_get_window(event);
|
|
|
|
|
display = gdk_window_get_display(window);
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
gdk_window_set_cursor(gtk_widget_get_window(w->win),
|
2015-03-18 09:44:09 +10:00
|
|
|
gdk_cursor_new_for_display(display,
|
|
|
|
|
GDK_BLANK_CURSOR));
|
2017-06-13 15:18:56 +10:00
|
|
|
|
|
|
|
|
seat = gdk_display_get_default_seat(display);
|
|
|
|
|
gdk_seat_grab(seat,
|
|
|
|
|
window,
|
|
|
|
|
GDK_SEAT_CAPABILITY_ALL_POINTING,
|
|
|
|
|
FALSE, /* owner-events */
|
|
|
|
|
NULL, /* cursor */
|
|
|
|
|
NULL, /* triggering event */
|
|
|
|
|
NULL, /* prepare_func */
|
|
|
|
|
NULL /* prepare_func_data */
|
|
|
|
|
);
|
2014-05-27 15:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
window_init(struct window *w)
|
|
|
|
|
{
|
|
|
|
|
memset(w, 0, sizeof(*w));
|
|
|
|
|
|
|
|
|
|
w->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
gtk_widget_set_events(w->win, 0);
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(w->win), "libinput debugging tool");
|
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(w->win), 1024, 768);
|
|
|
|
|
gtk_window_maximize(GTK_WINDOW(w->win));
|
|
|
|
|
gtk_window_set_resizable(GTK_WINDOW(w->win), TRUE);
|
|
|
|
|
gtk_widget_realize(w->win);
|
|
|
|
|
g_signal_connect(G_OBJECT(w->win), "map-event", G_CALLBACK(map_event_cb), w);
|
|
|
|
|
g_signal_connect(G_OBJECT(w->win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
|
|
|
|
|
|
w->area = gtk_drawing_area_new();
|
|
|
|
|
gtk_widget_set_events(w->area, 0);
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(w->win), w->area);
|
|
|
|
|
gtk_widget_show_all(w->win);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 08:56:44 +10:00
|
|
|
static void
|
|
|
|
|
window_cleanup(struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device **dev;
|
|
|
|
|
ARRAY_FOR_EACH(w->devices, dev) {
|
|
|
|
|
if (*dev)
|
|
|
|
|
libinput_device_unref(*dev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 09:04:10 +10:00
|
|
|
static void
|
|
|
|
|
change_ptraccel(struct window *w, double amount)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device **dev;
|
|
|
|
|
|
|
|
|
|
ARRAY_FOR_EACH(w->devices, dev) {
|
|
|
|
|
double speed;
|
|
|
|
|
enum libinput_config_status status;
|
|
|
|
|
|
|
|
|
|
if (*dev == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!libinput_device_config_accel_is_available(*dev))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
speed = libinput_device_config_accel_get_speed(*dev);
|
|
|
|
|
speed = clip(speed + amount, -1, 1);
|
|
|
|
|
|
|
|
|
|
status = libinput_device_config_accel_set_speed(*dev, speed);
|
|
|
|
|
|
|
|
|
|
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
|
|
|
|
|
msg("%s: failed to change accel to %.2f (%s)\n",
|
|
|
|
|
libinput_device_get_name(*dev),
|
|
|
|
|
speed,
|
|
|
|
|
libinput_config_status_to_str(status));
|
|
|
|
|
} else {
|
|
|
|
|
printf("%s: speed is %.2f\n",
|
|
|
|
|
libinput_device_get_name(*dev),
|
|
|
|
|
speed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
static void
|
|
|
|
|
handle_event_device_notify(struct libinput_event *ev)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *dev = libinput_event_get_device(ev);
|
2014-07-04 08:56:44 +10:00
|
|
|
struct libinput *li;
|
|
|
|
|
struct window *w;
|
2014-05-27 15:29:55 +10:00
|
|
|
const char *type;
|
2016-12-05 20:31:31 +10:00
|
|
|
size_t i;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED)
|
|
|
|
|
type = "added";
|
|
|
|
|
else
|
|
|
|
|
type = "removed";
|
|
|
|
|
|
2014-11-18 11:33:51 +10:00
|
|
|
msg("%s %-30s %s\n",
|
|
|
|
|
libinput_device_get_sysname(dev),
|
|
|
|
|
libinput_device_get_name(dev),
|
|
|
|
|
type);
|
2014-07-21 10:58:24 +10:00
|
|
|
|
2014-07-04 08:56:44 +10:00
|
|
|
li = libinput_event_get_context(ev);
|
2017-06-19 18:38:33 +10:00
|
|
|
w = libinput_get_user_data(li);
|
2015-06-24 15:07:53 +10:00
|
|
|
|
|
|
|
|
tools_device_apply_config(libinput_event_get_device(ev),
|
2017-06-19 18:38:33 +10:00
|
|
|
&w->options);
|
2014-07-04 08:56:44 +10:00
|
|
|
|
|
|
|
|
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) {
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
|
|
|
|
|
if (w->devices[i] == NULL) {
|
|
|
|
|
w->devices[i] = libinput_device_ref(dev);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
|
|
|
|
|
if (w->devices[i] == dev) {
|
|
|
|
|
libinput_device_unref(w->devices[i]);
|
|
|
|
|
w->devices[i] = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_event_motion(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
|
|
|
|
|
double dx = libinput_event_pointer_get_dx(p),
|
|
|
|
|
dy = libinput_event_pointer_get_dy(p);
|
|
|
|
|
|
2014-06-23 23:32:29 +02:00
|
|
|
w->x += dx;
|
|
|
|
|
w->y += dy;
|
|
|
|
|
w->x = clip(w->x, 0.0, w->width);
|
|
|
|
|
w->y = clip(w->y, 0.0, w->height);
|
2014-05-27 15:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_event_absmotion(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
|
2014-07-03 09:57:12 +10:00
|
|
|
double x = libinput_event_pointer_get_absolute_x_transformed(p, w->width),
|
|
|
|
|
y = libinput_event_pointer_get_absolute_y_transformed(p, w->height);
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2014-07-03 09:57:12 +10:00
|
|
|
w->absx = x;
|
|
|
|
|
w->absy = y;
|
2014-05-27 15:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_event_touch(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
|
|
|
|
|
int slot = libinput_event_touch_get_seat_slot(t);
|
|
|
|
|
struct touch *touch;
|
|
|
|
|
double x, y;
|
|
|
|
|
|
2014-07-14 00:15:07 +02:00
|
|
|
if (slot == -1 || slot >= (int) ARRAY_LENGTH(w->touches))
|
2014-05-27 15:29:55 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
touch = &w->touches[slot];
|
|
|
|
|
|
|
|
|
|
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_TOUCH_UP) {
|
|
|
|
|
touch->active = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 09:57:12 +10:00
|
|
|
x = libinput_event_touch_get_x_transformed(t, w->width),
|
|
|
|
|
y = libinput_event_touch_get_y_transformed(t, w->height);
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
touch->active = 1;
|
|
|
|
|
touch->x = (int)x;
|
|
|
|
|
touch->y = (int)y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_event_axis(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
|
2015-01-23 22:31:05 +01:00
|
|
|
double value;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2015-01-23 22:31:05 +01:00
|
|
|
if (libinput_event_pointer_has_axis(p,
|
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
|
|
|
|
|
value = libinput_event_pointer_get_axis_value(p,
|
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
|
2015-04-22 15:31:21 +10:00
|
|
|
w->vy += value;
|
2014-05-27 15:29:55 +10:00
|
|
|
w->vy = clip(w->vy, 0, w->height);
|
2014-12-24 11:10:04 +10:00
|
|
|
}
|
2015-01-23 22:31:05 +01:00
|
|
|
|
|
|
|
|
if (libinput_event_pointer_has_axis(p,
|
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
|
|
|
|
|
value = libinput_event_pointer_get_axis_value(p,
|
|
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
|
2015-04-22 15:31:21 +10:00
|
|
|
w->hx += value;
|
2014-05-27 15:29:55 +10:00
|
|
|
w->hx = clip(w->hx, 0, w->width);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
handle_event_keyboard(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev);
|
2014-07-04 09:04:10 +10:00
|
|
|
unsigned int key = libinput_event_keyboard_get_key(k);
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2014-07-04 09:04:10 +10:00
|
|
|
if (libinput_event_keyboard_get_key_state(k) ==
|
|
|
|
|
LIBINPUT_KEY_STATE_RELEASED)
|
|
|
|
|
return 0;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2014-07-04 09:04:10 +10:00
|
|
|
switch(key) {
|
|
|
|
|
case KEY_ESC:
|
2014-05-27 15:29:55 +10:00
|
|
|
return 1;
|
2014-07-04 09:04:10 +10:00
|
|
|
case KEY_UP:
|
|
|
|
|
change_ptraccel(w, 0.1);
|
|
|
|
|
break;
|
|
|
|
|
case KEY_DOWN:
|
|
|
|
|
change_ptraccel(w, -0.1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_event_button(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
|
|
|
|
|
unsigned int button = libinput_event_pointer_get_button(p);
|
|
|
|
|
int is_press;
|
|
|
|
|
|
|
|
|
|
is_press = libinput_event_pointer_get_button_state(p) == LIBINPUT_BUTTON_STATE_PRESSED;
|
|
|
|
|
|
|
|
|
|
switch (button) {
|
|
|
|
|
case BTN_LEFT:
|
|
|
|
|
w->l = is_press;
|
|
|
|
|
break;
|
|
|
|
|
case BTN_RIGHT:
|
|
|
|
|
w->r = is_press;
|
|
|
|
|
break;
|
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
|
w->m = is_press;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 10:40:16 +10:00
|
|
|
static void
|
|
|
|
|
handle_event_swipe(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_SWIPE_BEGIN:
|
|
|
|
|
w->swipe.nfingers = nfingers;
|
|
|
|
|
w->swipe.x = w->width/2;
|
|
|
|
|
w->swipe.y = w->height/2;
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
|
|
|
|
|
dx = libinput_event_gesture_get_dx(g);
|
|
|
|
|
dy = libinput_event_gesture_get_dy(g);
|
|
|
|
|
w->swipe.x += dx;
|
|
|
|
|
w->swipe.y += dy;
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_END:
|
|
|
|
|
w->swipe.nfingers = 0;
|
|
|
|
|
w->swipe.x = w->width/2;
|
|
|
|
|
w->swipe.y = w->height/2;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 11:14:41 +10:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-05 14:37:29 +10:00
|
|
|
static void
|
|
|
|
|
handle_event_tablet(struct libinput_event *ev, struct window *w)
|
|
|
|
|
{
|
2015-11-16 16:28:55 +10:00
|
|
|
struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev);
|
2015-11-11 13:39:43 +10:00
|
|
|
double x, y;
|
2016-01-12 16:39:15 +10:00
|
|
|
struct point point;
|
|
|
|
|
int idx;
|
|
|
|
|
const int mask = ARRAY_LENGTH(w->tool.deltas);
|
2015-11-05 14:37:29 +10:00
|
|
|
|
2016-01-12 14:41:57 +10:00
|
|
|
x = libinput_event_tablet_tool_get_x_transformed(t, w->width);
|
|
|
|
|
y = libinput_event_tablet_tool_get_y_transformed(t, w->height);
|
|
|
|
|
|
2015-11-05 14:37:29 +10:00
|
|
|
switch (libinput_event_get_type(ev)) {
|
2015-11-16 16:27:46 +10:00
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
|
2015-11-16 16:28:55 +10:00
|
|
|
if (libinput_event_tablet_tool_get_proximity_state(t) ==
|
2016-01-05 14:08:01 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) {
|
2015-11-05 14:37:29 +10:00
|
|
|
w->tool.x_in = 0;
|
|
|
|
|
w->tool.y_in = 0;
|
2015-11-11 13:39:43 +10:00
|
|
|
w->tool.x_down = 0;
|
|
|
|
|
w->tool.y_down = 0;
|
|
|
|
|
w->tool.x_up = 0;
|
|
|
|
|
w->tool.y_up = 0;
|
2015-11-05 14:37:29 +10:00
|
|
|
} else {
|
2016-01-12 14:41:57 +10:00
|
|
|
w->tool.x_in = x;
|
|
|
|
|
w->tool.y_in = y;
|
2016-01-12 16:39:15 +10:00
|
|
|
w->tool.ndeltas = 0;
|
|
|
|
|
w->tool.deltas[0].x = w->width/2;
|
|
|
|
|
w->tool.deltas[0].y = w->height/2;
|
2015-11-05 14:37:29 +10:00
|
|
|
}
|
|
|
|
|
break;
|
2015-11-16 16:27:46 +10:00
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_TIP:
|
2016-01-12 14:40:27 +10:00
|
|
|
w->tool.pressure = libinput_event_tablet_tool_get_pressure(t);
|
|
|
|
|
w->tool.distance = libinput_event_tablet_tool_get_distance(t);
|
|
|
|
|
w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t);
|
|
|
|
|
w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t);
|
2015-11-16 16:28:55 +10:00
|
|
|
if (libinput_event_tablet_tool_get_tip_state(t) ==
|
2015-11-16 15:47:15 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_TIP_DOWN) {
|
2015-11-11 13:39:43 +10:00
|
|
|
w->tool.x_down = x;
|
|
|
|
|
w->tool.y_down = y;
|
|
|
|
|
} else {
|
|
|
|
|
w->tool.x_up = x;
|
|
|
|
|
w->tool.y_up = y;
|
|
|
|
|
}
|
2016-01-12 14:41:57 +10:00
|
|
|
/* fallthrough */
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
|
|
|
|
|
w->tool.x = x;
|
|
|
|
|
w->tool.y = y;
|
|
|
|
|
w->tool.pressure = libinput_event_tablet_tool_get_pressure(t);
|
|
|
|
|
w->tool.distance = libinput_event_tablet_tool_get_distance(t);
|
|
|
|
|
w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t);
|
|
|
|
|
w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t);
|
2016-01-12 16:39:15 +10:00
|
|
|
|
|
|
|
|
/* Add the delta to the last position and store them as abs
|
|
|
|
|
* coordinates */
|
|
|
|
|
idx = w->tool.ndeltas % mask;
|
|
|
|
|
point = w->tool.deltas[idx];
|
|
|
|
|
|
|
|
|
|
idx = (w->tool.ndeltas + 1) % mask;
|
|
|
|
|
point.x += libinput_event_tablet_tool_get_dx(t);
|
|
|
|
|
point.y += libinput_event_tablet_tool_get_dy(t);
|
|
|
|
|
w->tool.deltas[idx] = point;
|
|
|
|
|
w->tool.ndeltas++;
|
2015-11-11 13:39:43 +10:00
|
|
|
break;
|
2015-11-16 16:27:46 +10:00
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
|
2015-11-05 14:37:29 +10:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
static gboolean
|
|
|
|
|
handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li = data;
|
2017-06-19 18:38:33 +10:00
|
|
|
struct window *w = libinput_get_user_data(li);
|
2014-05-27 15:29:55 +10:00
|
|
|
struct libinput_event *ev;
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((ev = libinput_get_event(li))) {
|
|
|
|
|
switch (libinput_event_get_type(ev)) {
|
|
|
|
|
case LIBINPUT_EVENT_NONE:
|
|
|
|
|
abort();
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
|
handle_event_device_notify(ev);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
handle_event_motion(ev, w);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
handle_event_absmotion(ev, w);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
handle_event_touch(ev, w);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
|
|
|
|
handle_event_axis(ev, w);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
handle_event_button(ev, w);
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
|
|
|
|
if (handle_event_keyboard(ev, w)) {
|
|
|
|
|
libinput_event_destroy(ev);
|
|
|
|
|
gtk_main_quit();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-01-22 16:41:50 +01:00
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_SWIPE_END:
|
2015-05-22 10:40:16 +10:00
|
|
|
handle_event_swipe(ev, w);
|
|
|
|
|
break;
|
2015-03-04 15:24:04 +01:00
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
|
|
|
|
|
case LIBINPUT_EVENT_GESTURE_PINCH_END:
|
2015-05-22 11:14:41 +10:00
|
|
|
handle_event_pinch(ev, w);
|
2015-01-22 16:41:50 +01:00
|
|
|
break;
|
2015-11-16 16:27:46 +10:00
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_TIP:
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
|
2015-11-05 14:37:29 +10:00
|
|
|
handle_event_tablet(ev, w);
|
2014-06-25 14:45:08 +10:00
|
|
|
break;
|
2016-01-21 12:35:11 +10:00
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_RING:
|
|
|
|
|
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
|
|
|
|
|
break;
|
2017-01-20 16:54:13 +11:00
|
|
|
case LIBINPUT_EVENT_SWITCH_TOGGLE:
|
|
|
|
|
break;
|
2014-05-27 15:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(ev);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
}
|
|
|
|
|
gtk_widget_queue_draw(w->area);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sockets_init(struct libinput *li)
|
|
|
|
|
{
|
|
|
|
|
GIOChannel *c = g_io_channel_unix_new(libinput_get_fd(li));
|
|
|
|
|
|
|
|
|
|
g_io_channel_set_encoding(c, NULL, NULL);
|
|
|
|
|
g_io_add_watch(c, G_IO_IN, handle_event_libinput, li);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
static void
|
|
|
|
|
usage(void) {
|
|
|
|
|
printf("Usage: libinput debug-gui [options] [--udev <seat>|--device /dev/input/event0]\n");
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
int
|
2017-05-24 10:36:44 +10:00
|
|
|
main(int argc, char **argv)
|
2014-05-27 15:29:55 +10:00
|
|
|
{
|
|
|
|
|
struct window w;
|
2017-09-04 15:07:05 +10:00
|
|
|
struct tools_options options;
|
2014-05-27 15:29:55 +10:00
|
|
|
struct libinput *li;
|
2017-06-19 18:38:33 +10:00
|
|
|
enum tools_backend backend = BACKEND_UDEV;
|
|
|
|
|
const char *seat_or_device = "seat0";
|
|
|
|
|
bool grab = false;
|
|
|
|
|
bool verbose = false;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
|
|
2017-09-04 15:07:05 +10:00
|
|
|
tools_init_options(&options);
|
2017-06-19 18:38:33 +10:00
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
int c;
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
enum {
|
|
|
|
|
OPT_DEVICE = 1,
|
|
|
|
|
OPT_UDEV,
|
|
|
|
|
OPT_GRAB,
|
|
|
|
|
OPT_VERBOSE,
|
|
|
|
|
};
|
|
|
|
|
static struct option opts[] = {
|
|
|
|
|
CONFIGURATION_OPTIONS,
|
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
|
{ "device", required_argument, 0, OPT_DEVICE },
|
|
|
|
|
{ "udev", required_argument, 0, OPT_UDEV },
|
|
|
|
|
{ "grab", no_argument, 0, OPT_GRAB },
|
|
|
|
|
{ "verbose", no_argument, 0, OPT_VERBOSE },
|
|
|
|
|
{ 0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, "h", opts, &option_index);
|
|
|
|
|
if (c == -1)
|
|
|
|
|
break;
|
2014-12-18 14:47:54 +10:00
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
switch(c) {
|
|
|
|
|
case '?':
|
|
|
|
|
exit(1);
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DEVICE:
|
|
|
|
|
backend = BACKEND_DEVICE;
|
|
|
|
|
seat_or_device = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_UDEV:
|
|
|
|
|
backend = BACKEND_UDEV;
|
|
|
|
|
seat_or_device = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_GRAB:
|
|
|
|
|
grab = true;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_VERBOSE:
|
|
|
|
|
verbose = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-09-04 15:07:05 +10:00
|
|
|
if (tools_parse_option(c, optarg, &options) != 0) {
|
2017-06-19 18:38:33 +10:00
|
|
|
usage();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
if (optind < argc) {
|
|
|
|
|
usage();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
li = tools_open_backend(backend, seat_or_device, verbose, grab);
|
2014-12-18 14:47:54 +10:00
|
|
|
if (!li)
|
|
|
|
|
return 1;
|
2014-05-27 15:29:55 +10:00
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
libinput_set_user_data(li, &w);
|
|
|
|
|
|
2014-05-27 15:29:55 +10:00
|
|
|
window_init(&w);
|
2017-09-04 15:07:05 +10:00
|
|
|
w.options = options;
|
2014-05-27 15:29:55 +10:00
|
|
|
sockets_init(li);
|
2015-07-21 11:53:57 +10:00
|
|
|
handle_event_libinput(NULL, 0, li);
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
2014-07-04 08:56:44 +10:00
|
|
|
window_cleanup(&w);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-05-27 15:29:55 +10:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|