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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2015-06-24 15:12:54 +10:00
parent b7c414558d
commit f74769e77e
2 changed files with 17 additions and 1 deletions

View file

@ -40,6 +40,7 @@
enum options { enum options {
OPT_DEVICE, OPT_DEVICE,
OPT_UDEV, OPT_UDEV,
OPT_GRAB,
OPT_HELP, OPT_HELP,
OPT_VERBOSE, OPT_VERBOSE,
OPT_TAP_ENABLE, OPT_TAP_ENABLE,
@ -95,6 +96,7 @@ tools_usage()
"is not explicitly specified it is left at each device's default.\n" "is not explicitly specified it is left at each device's default.\n"
"\n" "\n"
"Other options:\n" "Other options:\n"
"--grab .......... Exclusively grab all openend devices\n"
"--verbose ....... Print debugging output.\n" "--verbose ....... Print debugging output.\n"
"--help .......... Print this help.\n", "--help .......... Print this help.\n",
program_invocation_short_name); program_invocation_short_name);
@ -122,14 +124,17 @@ tools_init_context(struct tools_context *context)
} }
int 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) { while (1) {
int c; int c;
int option_index = 0; int option_index = 0;
static struct option opts[] = { static struct option opts[] = {
{ "device", 1, 0, OPT_DEVICE }, { "device", 1, 0, OPT_DEVICE },
{ "udev", 0, 0, OPT_UDEV }, { "udev", 0, 0, OPT_UDEV },
{ "grab", 0, 0, OPT_GRAB },
{ "help", 0, 0, OPT_HELP }, { "help", 0, 0, OPT_HELP },
{ "verbose", 0, 0, OPT_VERBOSE }, { "verbose", 0, 0, OPT_VERBOSE },
{ "enable-tap", 0, 0, OPT_TAP_ENABLE }, { "enable-tap", 0, 0, OPT_TAP_ENABLE },
@ -171,6 +176,9 @@ tools_parse_args(int argc, char **argv, struct tools_options *options)
if (optarg) if (optarg)
options->seat = optarg; options->seat = optarg;
break; break;
case OPT_GRAB:
options->grab = 1;
break;
case OPT_VERBOSE: case OPT_VERBOSE:
options->verbose = 1; options->verbose = 1;
break; break;
@ -352,10 +360,17 @@ open_device(const struct libinput_interface *interface,
static int static int
open_restricted(const char *path, int flags, void *user_data) open_restricted(const char *path, int flags, void *user_data)
{ {
const struct tools_context *context = user_data;
int fd = open(path, flags); int fd = open(path, flags);
if (fd < 0) if (fd < 0)
fprintf(stderr, "Failed to open %s (%s)\n", fprintf(stderr, "Failed to open %s (%s)\n",
path, strerror(errno)); 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; return fd < 0 ? -errno : fd;
} }

View file

@ -35,6 +35,7 @@ struct tools_options {
enum tools_backend backend; enum tools_backend backend;
const char *device; /* if backend is BACKEND_DEVICE */ const char *device; /* if backend is BACKEND_DEVICE */
const char *seat; /* if backend is BACKEND_UDEV */ const char *seat; /* if backend is BACKEND_UDEV */
int grab; /* EVIOCGRAB */
int verbose; int verbose;
int tapping; int tapping;