From f74769e77e2e51b568cf2061e7703eec1405f06d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 24 Jun 2015 15:12:54 +1000 Subject: [PATCH] tools: add --grab option Issues an EVIOCGRAB on the openend devices, providing exclusive access. Makes it easier for debugging, so moving the pointer doesn't accidentally trigger other stuff. Signed-off-by: Peter Hutterer --- tools/shared.c | 17 ++++++++++++++++- tools/shared.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/shared.c b/tools/shared.c index 0bb03b1b..64544c5c 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -40,6 +40,7 @@ enum options { OPT_DEVICE, OPT_UDEV, + OPT_GRAB, OPT_HELP, OPT_VERBOSE, OPT_TAP_ENABLE, @@ -95,6 +96,7 @@ tools_usage() "is not explicitly specified it is left at each device's default.\n" "\n" "Other options:\n" + "--grab .......... Exclusively grab all openend devices\n" "--verbose ....... Print debugging output.\n" "--help .......... Print this help.\n", program_invocation_short_name); @@ -122,14 +124,17 @@ tools_init_context(struct tools_context *context) } int -tools_parse_args(int argc, char **argv, struct tools_options *options) +tools_parse_args(int argc, char **argv, struct tools_context *context) { + struct tools_options *options = &context->options; + while (1) { int c; int option_index = 0; static struct option opts[] = { { "device", 1, 0, OPT_DEVICE }, { "udev", 0, 0, OPT_UDEV }, + { "grab", 0, 0, OPT_GRAB }, { "help", 0, 0, OPT_HELP }, { "verbose", 0, 0, OPT_VERBOSE }, { "enable-tap", 0, 0, OPT_TAP_ENABLE }, @@ -171,6 +176,9 @@ tools_parse_args(int argc, char **argv, struct tools_options *options) if (optarg) options->seat = optarg; break; + case OPT_GRAB: + options->grab = 1; + break; case OPT_VERBOSE: options->verbose = 1; break; @@ -352,10 +360,17 @@ open_device(const struct libinput_interface *interface, static int open_restricted(const char *path, int flags, void *user_data) { + const struct tools_context *context = user_data; int fd = open(path, flags); + if (fd < 0) fprintf(stderr, "Failed to open %s (%s)\n", path, strerror(errno)); + else if (context->options.grab && + ioctl(fd, EVIOCGRAB, (void*)1) == -1) + fprintf(stderr, "Grab requested, but failed for %s (%s)\n", + path, strerror(errno)); + return fd < 0 ? -errno : fd; } diff --git a/tools/shared.h b/tools/shared.h index 442d7cd3..a848e2d1 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -35,6 +35,7 @@ struct tools_options { enum tools_backend backend; const char *device; /* if backend is BACKEND_DEVICE */ const char *seat; /* if backend is BACKEND_UDEV */ + int grab; /* EVIOCGRAB */ int verbose; int tapping;