#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <linux/input.h>
+#include <libudev.h>
+#include "linux/input.h"
#include <sys/ioctl.h>
#include <sys/signalfd.h>
uint32_t start_time;
static const uint32_t screen_width = 100;
static const uint32_t screen_height = 100;
+static int verbose = 0;
static void
usage(void)
{
- printf("Usage: %s [--udev [<seat>]|--device /dev/input/event0]\n"
+ printf("Usage: %s [--verbose] [--udev [<seat>]|--device /dev/input/event0]\n"
+ "--verbose ....... Print debugging output.\n"
"--udev <seat>.... Use udev device discovery (default).\n"
" Specifying a seat ID is optional.\n"
"--device /path/to/device .... open the given device only\n",
{ "device", 1, 0, 'd' },
{ "udev", 0, 0, 'u' },
{ "help", 0, 0, 'h' },
+ { "verbose", 0, 0, 'v'},
{ 0, 0, 0, 0}
};
if (optarg)
seat = optarg;
break;
+ case 'v': /* --verbose */
+ verbose = 1;
+ break;
default:
usage();
return 1;
open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
- int clockid = CLOCK_MONOTONIC;
-
- if (fd >= 0 && ioctl(fd, EVIOCSCLOCKID, &clockid) < 0)
- fprintf(stderr, "Changing clock on %s failed, timestamps "
- "will be off\n", path);
-
return fd < 0 ? -errno : fd;
}
close(fd);
}
-const static struct libinput_interface interface = {
+static const struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
case LIBINPUT_EVENT_POINTER_AXIS:
type = "POINTER_AXIS";
break;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
- type = "TOUCH_TOUCH";
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ type = "TOUCH_DOWN";
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ type = "TOUCH_MOTION";
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ type = "TOUCH_UP";
+ break;
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
+ type = "TOUCH_CANCEL";
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
type = "TOUCH_FRAME";
{
struct libinput_device *dev = libinput_event_get_device(ev);
struct libinput_seat *seat = libinput_device_get_seat(dev);
+ double w, h;
- printf("%s %s\n",
+ printf("%s %s",
libinput_seat_get_physical_name(seat),
libinput_seat_get_logical_name(seat));
+
+ if (libinput_device_get_size(dev, &w, &h) == 0)
+ printf("\tsize %.2f/%.2fmm", w, h);
+
+ printf("\n");
}
static void
print_key_event(struct libinput_event *ev)
{
struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev);
- enum libinput_keyboard_key_state state;
+ enum libinput_key_state state;
print_event_time(libinput_event_keyboard_get_time(k));
state = libinput_event_keyboard_get_key_state(k);
printf("%d %s\n",
libinput_event_keyboard_get_key(k),
- state == LIBINPUT_KEYBOARD_KEY_STATE_PRESSED ? "pressed" : "released");
+ state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released");
}
static void
print_motion_event(struct libinput_event *ev)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
- li_fixed_t x = libinput_event_pointer_get_dx(p),
- y = libinput_event_pointer_get_dy(p);
+ double x = libinput_event_pointer_get_dx(p);
+ double y = libinput_event_pointer_get_dy(p);
print_event_time(libinput_event_pointer_get_time(p));
- printf("%6.2f/%6.2f\n",
- li_fixed_to_double(x),
- li_fixed_to_double(y));
+ printf("%6.2f/%6.2f\n", x, y);
}
static void
print_absmotion_event(struct libinput_event *ev)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
- li_fixed_t x = libinput_event_pointer_get_absolute_x_transformed(
+ double x = libinput_event_pointer_get_absolute_x_transformed(
p, screen_width);
- li_fixed_t y = libinput_event_pointer_get_absolute_y_transformed(
+ double y = libinput_event_pointer_get_absolute_y_transformed(
p, screen_height);
print_event_time(libinput_event_pointer_get_time(p));
- printf("%6.2f/%6.2f\n",
- li_fixed_to_double(x),
- li_fixed_to_double(y));
+ printf("%6.2f/%6.2f\n", x, y);
}
static void
print_button_event(struct libinput_event *ev)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
- enum libinput_pointer_button_state state;
+ enum libinput_button_state state;
print_event_time(libinput_event_pointer_get_time(p));
state = libinput_event_pointer_get_button_state(p);
- printf("%3d %s\n",
+ printf("%3d %s, seat count: %u\n",
libinput_event_pointer_get_button(p),
- state == LIBINPUT_POINTER_BUTTON_STATE_PRESSED ? "pressed" : "released");
+ state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released",
+ libinput_event_pointer_get_seat_button_count(p));
}
static void
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
enum libinput_pointer_axis axis = libinput_event_pointer_get_axis(p);
const char *ax;
- li_fixed_t val;
+ double val;
switch (axis) {
- case LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL:
+ case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
ax = "vscroll";
break;
- case LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL:
+ case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
ax = "hscroll";
break;
default:
print_event_time(libinput_event_pointer_get_time(p));
val = libinput_event_pointer_get_axis_value(p);
- printf("%s %.2f\n",
- ax, li_fixed_to_double(val));
+ printf("%s %.2f\n", ax, val);
}
static void
-print_touch_frame_event(struct libinput_event *ev)
+print_touch_event_without_coords(struct libinput_event *ev)
{
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
}
static void
-print_touch_event(struct libinput_event *ev)
+print_touch_event_with_coords(struct libinput_event *ev)
{
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
- li_fixed_t x = libinput_event_touch_get_x_transformed(t, screen_width),
- y = libinput_event_touch_get_y_transformed(t, screen_height);
- const char *type;
-
- switch (libinput_event_touch_get_touch_type(t)) {
- case LIBINPUT_TOUCH_TYPE_DOWN: type = "down"; break;
- case LIBINPUT_TOUCH_TYPE_UP: type = "up"; break;
- case LIBINPUT_TOUCH_TYPE_MOTION: type = "motion"; break;
- case LIBINPUT_TOUCH_TYPE_CANCEL: type = "cancel"; break;
- default:
- abort();
- }
+ double x = libinput_event_touch_get_x_transformed(t, screen_width);
+ 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);
print_event_time(libinput_event_touch_get_time(t));
- printf("%6s %d %5.2f/%5.2f\n",
- type,
+ printf("%d (%d) %5.2f/%5.2f (%5.2f/%5.2fmm)\n",
libinput_event_touch_get_slot(t),
- li_fixed_to_double(x),
- li_fixed_to_double(y));
+ libinput_event_touch_get_seat_slot(t),
+ x, y,
+ xmm, ymm);
}
static int
case LIBINPUT_EVENT_POINTER_AXIS:
print_axis_event(ev);
break;
- case LIBINPUT_EVENT_TOUCH_TOUCH:
- print_touch_event(ev);
+ case LIBINPUT_EVENT_TOUCH_DOWN:
+ print_touch_event_with_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_MOTION:
+ print_touch_event_with_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_UP:
+ print_touch_event_without_coords(ev);
+ break;
+ case LIBINPUT_EVENT_TOUCH_CANCEL:
+ print_touch_event_without_coords(ev);
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
- print_touch_frame_event(ev);
+ print_touch_event_without_coords(ev);
break;
}
close(fds[1].fd);
}
+static void
+log_handler(enum libinput_log_priority priority,
+ void *user_data,
+ const char *format,
+ va_list args)
+{
+ vprintf(format, args);
+}
+
int
main(int argc, char **argv)
{
if (parse_args(argc, argv))
return 1;
+ if (verbose) {
+ libinput_log_set_handler(log_handler, NULL);
+ libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
+ }
+
if (mode == MODE_UDEV) {
if (open_udev(&li))
return 1;
mainloop(li);
+ libinput_destroy(li);
if (udev)
udev_unref(udev);