tools: add --grab option
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 24 Jun 2015 05:12:54 +0000 (15:12 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 24 Jun 2015 05:19:33 +0000 (15:19 +1000)
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 <peter.hutterer@who-t.net>
tools/shared.c
tools/shared.h

index 0bb03b1..64544c5 100644 (file)
@@ -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;
 }
 
index 442d7cd..a848e2d 100644 (file)
@@ -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;