2014-12-18 14:42:42 +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-12-18 14:42:42 +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-12-18 14:42:42 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
2015-06-24 14:52:48 +10:00
|
|
|
#include <fcntl.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2017-05-23 15:07:31 +10:00
|
|
|
#include <sys/stat.h>
|
2014-12-18 15:02:45 +10:00
|
|
|
#include <libudev.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
|
2015-04-21 18:24:39 +10:00
|
|
|
#include <libevdev/libevdev.h>
|
2015-05-26 08:46:05 +10:00
|
|
|
#include <libinput-util.h>
|
2015-04-21 18:24:39 +10:00
|
|
|
|
2014-12-18 14:42:42 +10:00
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
|
|
enum options {
|
|
|
|
|
OPT_DEVICE,
|
|
|
|
|
OPT_UDEV,
|
2015-06-24 15:12:54 +10:00
|
|
|
OPT_GRAB,
|
2014-12-18 14:42:42 +10:00
|
|
|
OPT_HELP,
|
|
|
|
|
OPT_VERBOSE,
|
|
|
|
|
OPT_TAP_ENABLE,
|
|
|
|
|
OPT_TAP_DISABLE,
|
2016-07-21 11:46:05 +10:00
|
|
|
OPT_TAP_MAP,
|
2016-01-22 17:59:19 +10:00
|
|
|
OPT_DRAG_ENABLE,
|
|
|
|
|
OPT_DRAG_DISABLE,
|
2015-06-22 11:07:31 +10:00
|
|
|
OPT_DRAG_LOCK_ENABLE,
|
|
|
|
|
OPT_DRAG_LOCK_DISABLE,
|
2014-12-18 15:10:59 +10:00
|
|
|
OPT_NATURAL_SCROLL_ENABLE,
|
|
|
|
|
OPT_NATURAL_SCROLL_DISABLE,
|
2014-12-18 15:14:09 +10:00
|
|
|
OPT_LEFT_HANDED_ENABLE,
|
|
|
|
|
OPT_LEFT_HANDED_DISABLE,
|
2015-04-14 12:08:33 +10:00
|
|
|
OPT_MIDDLEBUTTON_ENABLE,
|
|
|
|
|
OPT_MIDDLEBUTTON_DISABLE,
|
2015-07-08 15:03:06 +10:00
|
|
|
OPT_DWT_ENABLE,
|
|
|
|
|
OPT_DWT_DISABLE,
|
2015-01-16 10:16:47 +10:00
|
|
|
OPT_CLICK_METHOD,
|
2015-04-21 11:57:23 +10:00
|
|
|
OPT_SCROLL_METHOD,
|
2015-04-21 18:24:39 +10:00
|
|
|
OPT_SCROLL_BUTTON,
|
2015-04-10 15:45:59 +10:00
|
|
|
OPT_SPEED,
|
2015-08-27 13:13:47 +10:00
|
|
|
OPT_PROFILE,
|
2017-02-13 11:07:03 +10:00
|
|
|
OPT_SHOW_KEYCODES,
|
2017-02-24 16:11:46 +10:00
|
|
|
OPT_QUIET,
|
2014-12-18 14:42:42 +10:00
|
|
|
};
|
|
|
|
|
|
2016-10-24 11:06:23 +10:00
|
|
|
LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
|
2014-12-18 15:02:45 +10:00
|
|
|
static void
|
|
|
|
|
log_handler(struct libinput *li,
|
|
|
|
|
enum libinput_log_priority priority,
|
|
|
|
|
const char *format,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
2017-02-13 16:28:28 +10:00
|
|
|
static int is_tty = -1;
|
|
|
|
|
|
|
|
|
|
if (is_tty == -1)
|
|
|
|
|
is_tty = isatty(STDOUT_FILENO);
|
|
|
|
|
|
|
|
|
|
if (is_tty) {
|
|
|
|
|
if (priority >= LIBINPUT_LOG_PRIORITY_ERROR)
|
|
|
|
|
printf(ANSI_RED);
|
|
|
|
|
else if (priority >= LIBINPUT_LOG_PRIORITY_INFO)
|
|
|
|
|
printf(ANSI_HIGHLIGHT);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:45 +10:00
|
|
|
vprintf(format, args);
|
2017-02-13 16:28:28 +10:00
|
|
|
|
|
|
|
|
if (is_tty && priority >= LIBINPUT_LOG_PRIORITY_INFO)
|
|
|
|
|
printf(ANSI_NORMAL);
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2014-12-18 14:42:42 +10:00
|
|
|
void
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(const char *command)
|
2014-12-18 14:42:42 +10:00
|
|
|
{
|
2017-05-25 15:42:46 +10:00
|
|
|
printf("Usage: libinput %s [options] [--udev [<seat>]|--device /dev/input/event0]\n",
|
|
|
|
|
command);
|
2014-12-18 14:42:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-24 15:07:53 +10:00
|
|
|
tools_init_context(struct tools_context *context)
|
2014-12-18 14:42:42 +10:00
|
|
|
{
|
2015-06-24 15:07:53 +10:00
|
|
|
struct tools_options *options = &context->options;
|
|
|
|
|
|
|
|
|
|
context->user_data = NULL;
|
|
|
|
|
|
2014-12-18 14:42:42 +10:00
|
|
|
memset(options, 0, sizeof(*options));
|
|
|
|
|
options->tapping = -1;
|
2016-07-21 11:46:05 +10:00
|
|
|
options->tap_map = -1;
|
2016-01-22 17:59:19 +10:00
|
|
|
options->drag = -1;
|
2015-06-22 11:07:31 +10:00
|
|
|
options->drag_lock = -1;
|
2014-12-18 15:10:59 +10:00
|
|
|
options->natural_scroll = -1;
|
2014-12-18 15:14:09 +10:00
|
|
|
options->left_handed = -1;
|
2015-04-14 12:08:33 +10:00
|
|
|
options->middlebutton = -1;
|
2015-07-08 15:03:06 +10:00
|
|
|
options->dwt = -1;
|
2015-01-16 10:16:47 +10:00
|
|
|
options->click_method = -1;
|
2015-04-21 11:57:23 +10:00
|
|
|
options->scroll_method = -1;
|
2015-04-21 18:24:39 +10:00
|
|
|
options->scroll_button = -1;
|
2014-12-18 14:42:42 +10:00
|
|
|
options->backend = BACKEND_UDEV;
|
|
|
|
|
options->seat = "seat0";
|
2015-04-10 15:45:59 +10:00
|
|
|
options->speed = 0.0;
|
2015-08-27 13:13:47 +10:00
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
2017-02-13 11:07:03 +10:00
|
|
|
options->show_keycodes = false;
|
2014-12-18 14:42:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_parse_args(const char *command,
|
|
|
|
|
int argc,
|
|
|
|
|
char **argv,
|
|
|
|
|
struct tools_context *context)
|
2014-12-18 14:42:42 +10:00
|
|
|
{
|
2015-06-24 15:12:54 +10:00
|
|
|
struct tools_options *options = &context->options;
|
|
|
|
|
|
2014-12-18 14:42:42 +10:00
|
|
|
while (1) {
|
|
|
|
|
int c;
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
static struct option opts[] = {
|
2017-03-24 10:11:02 +10:00
|
|
|
{ "device", required_argument, 0, OPT_DEVICE },
|
|
|
|
|
{ "udev", no_argument, 0, OPT_UDEV },
|
|
|
|
|
{ "grab", no_argument, 0, OPT_GRAB },
|
|
|
|
|
{ "help", no_argument, 0, OPT_HELP },
|
|
|
|
|
{ "verbose", no_argument, 0, OPT_VERBOSE },
|
|
|
|
|
{ "quiet", no_argument, 0, OPT_QUIET },
|
|
|
|
|
{ "enable-tap", no_argument, 0, OPT_TAP_ENABLE },
|
|
|
|
|
{ "disable-tap", no_argument, 0, OPT_TAP_DISABLE },
|
|
|
|
|
{ "enable-drag", no_argument, 0, OPT_DRAG_ENABLE },
|
|
|
|
|
{ "disable-drag", no_argument, 0, OPT_DRAG_DISABLE },
|
|
|
|
|
{ "enable-drag-lock", no_argument, 0, OPT_DRAG_LOCK_ENABLE },
|
|
|
|
|
{ "disable-drag-lock", no_argument, 0, OPT_DRAG_LOCK_DISABLE },
|
|
|
|
|
{ "enable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_ENABLE },
|
|
|
|
|
{ "disable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_DISABLE },
|
|
|
|
|
{ "enable-left-handed", no_argument, 0, OPT_LEFT_HANDED_ENABLE },
|
|
|
|
|
{ "disable-left-handed", no_argument, 0, OPT_LEFT_HANDED_DISABLE },
|
|
|
|
|
{ "enable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_ENABLE },
|
|
|
|
|
{ "disable-middlebutton", no_argument, 0, OPT_MIDDLEBUTTON_DISABLE },
|
|
|
|
|
{ "enable-dwt", no_argument, 0, OPT_DWT_ENABLE },
|
|
|
|
|
{ "disable-dwt", no_argument, 0, OPT_DWT_DISABLE },
|
|
|
|
|
{ "set-click-method", required_argument, 0, OPT_CLICK_METHOD },
|
|
|
|
|
{ "set-scroll-method", required_argument, 0, OPT_SCROLL_METHOD },
|
|
|
|
|
{ "set-scroll-button", required_argument, 0, OPT_SCROLL_BUTTON },
|
|
|
|
|
{ "set-profile", required_argument, 0, OPT_PROFILE },
|
|
|
|
|
{ "set-tap-map", required_argument, 0, OPT_TAP_MAP },
|
|
|
|
|
{ "set-speed", required_argument, 0, OPT_SPEED },
|
|
|
|
|
{ "show-keycodes", no_argument, 0, OPT_SHOW_KEYCODES },
|
2014-12-18 14:42:42 +10:00
|
|
|
{ 0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, "h", opts, &option_index);
|
|
|
|
|
if (c == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch(c) {
|
2015-08-18 15:46:41 +10:00
|
|
|
case 'h':
|
|
|
|
|
case OPT_HELP:
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
exit(0);
|
|
|
|
|
case OPT_DEVICE:
|
|
|
|
|
options->backend = BACKEND_DEVICE;
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
options->device = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_UDEV:
|
|
|
|
|
options->backend = BACKEND_UDEV;
|
|
|
|
|
if (optarg)
|
|
|
|
|
options->seat = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_GRAB:
|
|
|
|
|
options->grab = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_VERBOSE:
|
2017-05-25 10:12:26 +10:00
|
|
|
options->verbose = 1;
|
2015-08-18 15:46:41 +10:00
|
|
|
break;
|
|
|
|
|
case OPT_TAP_ENABLE:
|
|
|
|
|
options->tapping = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_TAP_DISABLE:
|
|
|
|
|
options->tapping = 0;
|
|
|
|
|
break;
|
2016-07-21 11:46:05 +10:00
|
|
|
case OPT_TAP_MAP:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2016-07-21 11:46:05 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (streq(optarg, "lrm")) {
|
|
|
|
|
options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
|
|
|
|
|
} else if (streq(optarg, "lmr")) {
|
|
|
|
|
options->tap_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
|
|
|
|
|
} else {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2016-07-21 11:46:05 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-01-22 17:59:19 +10:00
|
|
|
case OPT_DRAG_ENABLE:
|
|
|
|
|
options->drag = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_DISABLE:
|
|
|
|
|
options->drag = 0;
|
|
|
|
|
break;
|
2015-08-18 15:46:41 +10:00
|
|
|
case OPT_DRAG_LOCK_ENABLE:
|
|
|
|
|
options->drag_lock = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_LOCK_DISABLE:
|
|
|
|
|
options->drag_lock = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_NATURAL_SCROLL_ENABLE:
|
|
|
|
|
options->natural_scroll = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_NATURAL_SCROLL_DISABLE:
|
|
|
|
|
options->natural_scroll = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_LEFT_HANDED_ENABLE:
|
|
|
|
|
options->left_handed = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_LEFT_HANDED_DISABLE:
|
|
|
|
|
options->left_handed = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_MIDDLEBUTTON_ENABLE:
|
|
|
|
|
options->middlebutton = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_MIDDLEBUTTON_DISABLE:
|
|
|
|
|
options->middlebutton = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DWT_ENABLE:
|
|
|
|
|
options->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DWT_DISABLE:
|
|
|
|
|
options->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_CLICK_METHOD:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (streq(optarg, "none")) {
|
|
|
|
|
options->click_method =
|
|
|
|
|
LIBINPUT_CONFIG_CLICK_METHOD_NONE;
|
|
|
|
|
} else if (streq(optarg, "clickfinger")) {
|
|
|
|
|
options->click_method =
|
|
|
|
|
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
|
|
|
|
|
} else if (streq(optarg, "buttonareas")) {
|
|
|
|
|
options->click_method =
|
|
|
|
|
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
|
|
|
|
|
} else {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_SCROLL_METHOD:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (streq(optarg, "none")) {
|
|
|
|
|
options->scroll_method =
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
|
|
|
|
} else if (streq(optarg, "twofinger")) {
|
|
|
|
|
options->scroll_method =
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_2FG;
|
|
|
|
|
} else if (streq(optarg, "edge")) {
|
|
|
|
|
options->scroll_method =
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_EDGE;
|
|
|
|
|
} else if (streq(optarg, "button")) {
|
|
|
|
|
options->scroll_method =
|
|
|
|
|
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
|
|
|
|
|
} else {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2014-12-18 14:42:42 +10:00
|
|
|
return 1;
|
2015-08-18 15:46:41 +10:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_SCROLL_BUTTON:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
options->scroll_button =
|
|
|
|
|
libevdev_event_code_from_name(EV_KEY,
|
|
|
|
|
optarg);
|
|
|
|
|
if (options->scroll_button == -1) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid button %s\n",
|
|
|
|
|
optarg);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_SPEED:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
options->speed = atof(optarg);
|
|
|
|
|
break;
|
2015-08-27 13:13:47 +10:00
|
|
|
case OPT_PROFILE:
|
|
|
|
|
if (!optarg) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-27 13:13:47 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (streq(optarg, "adaptive")) {
|
|
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
|
|
|
|
} else if (streq(optarg, "flat")) {
|
|
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
|
|
|
|
|
} else {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-27 13:13:47 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-02-13 11:07:03 +10:00
|
|
|
case OPT_SHOW_KEYCODES:
|
|
|
|
|
options->show_keycodes = true;
|
|
|
|
|
break;
|
2017-02-24 16:11:46 +10:00
|
|
|
case OPT_QUIET:
|
2017-05-25 10:12:26 +10:00
|
|
|
options->quiet = true;
|
2017-02-24 16:11:46 +10:00
|
|
|
break;
|
2015-08-18 15:46:41 +10:00
|
|
|
default:
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2015-08-18 15:46:41 +10:00
|
|
|
return 1;
|
2014-12-18 14:42:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (optind < argc) {
|
2017-05-25 15:42:46 +10:00
|
|
|
tools_usage(command);
|
2014-12-18 14:42:42 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-12-18 15:02:45 +10:00
|
|
|
|
|
|
|
|
static struct libinput *
|
|
|
|
|
open_udev(const struct libinput_interface *interface,
|
2014-12-23 11:13:33 +10:00
|
|
|
void *userdata,
|
2014-12-18 15:02:45 +10:00
|
|
|
const char *seat,
|
|
|
|
|
int verbose)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct udev *udev = udev_new();
|
|
|
|
|
|
|
|
|
|
if (!udev) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize udev\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-23 11:13:33 +10:00
|
|
|
li = libinput_udev_create_context(interface, userdata, udev);
|
2014-12-18 15:02:45 +10:00
|
|
|
if (!li) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize context from udev\n");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
libinput_log_set_handler(li, log_handler);
|
|
|
|
|
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (libinput_udev_assign_seat(li, seat)) {
|
|
|
|
|
fprintf(stderr, "Failed to set seat\n");
|
|
|
|
|
libinput_unref(li);
|
|
|
|
|
li = NULL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
udev_unref(udev);
|
|
|
|
|
return li;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct libinput *
|
|
|
|
|
open_device(const struct libinput_interface *interface,
|
2014-12-23 11:13:33 +10:00
|
|
|
void *userdata,
|
2014-12-18 15:02:45 +10:00
|
|
|
const char *path,
|
|
|
|
|
int verbose)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
|
2014-12-23 11:13:33 +10:00
|
|
|
li = libinput_path_create_context(interface, userdata);
|
2014-12-18 15:02:45 +10:00
|
|
|
if (!li) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize context from %s\n", path);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
libinput_log_set_handler(li, log_handler);
|
|
|
|
|
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li, path);
|
|
|
|
|
if (!device) {
|
|
|
|
|
fprintf(stderr, "Failed to initialized device %s\n", path);
|
|
|
|
|
libinput_unref(li);
|
|
|
|
|
li = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return li;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 14:52:48 +10:00
|
|
|
static int
|
|
|
|
|
open_restricted(const char *path, int flags, void *user_data)
|
|
|
|
|
{
|
2015-06-24 15:12:54 +10:00
|
|
|
const struct tools_context *context = user_data;
|
2015-06-24 14:52:48 +10:00
|
|
|
int fd = open(path, flags);
|
2015-06-24 15:12:54 +10:00
|
|
|
|
2015-06-24 14:52:48 +10:00
|
|
|
if (fd < 0)
|
|
|
|
|
fprintf(stderr, "Failed to open %s (%s)\n",
|
|
|
|
|
path, strerror(errno));
|
2015-06-24 15:12:54 +10:00
|
|
|
else if (context->options.grab &&
|
|
|
|
|
ioctl(fd, EVIOCGRAB, (void*)1) == -1)
|
|
|
|
|
fprintf(stderr, "Grab requested, but failed for %s (%s)\n",
|
|
|
|
|
path, strerror(errno));
|
|
|
|
|
|
2015-06-24 14:52:48 +10:00
|
|
|
return fd < 0 ? -errno : fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
close_restricted(int fd, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct libinput_interface interface = {
|
|
|
|
|
.open_restricted = open_restricted,
|
|
|
|
|
.close_restricted = close_restricted,
|
|
|
|
|
};
|
|
|
|
|
|
2014-12-18 15:02:45 +10:00
|
|
|
struct libinput *
|
2015-06-24 15:07:53 +10:00
|
|
|
tools_open_backend(struct tools_context *context)
|
2014-12-18 15:02:45 +10:00
|
|
|
{
|
|
|
|
|
struct libinput *li = NULL;
|
2015-06-24 15:07:53 +10:00
|
|
|
struct tools_options *options = &context->options;
|
2014-12-18 15:02:45 +10:00
|
|
|
|
|
|
|
|
if (options->backend == BACKEND_UDEV) {
|
2017-05-11 13:44:36 +10:00
|
|
|
li = open_udev(&interface,
|
|
|
|
|
context,
|
|
|
|
|
options->seat,
|
2017-05-25 10:12:26 +10:00
|
|
|
options->verbose);
|
2014-12-18 15:02:45 +10:00
|
|
|
} else if (options->backend == BACKEND_DEVICE) {
|
2017-05-11 13:44:36 +10:00
|
|
|
li = open_device(&interface,
|
|
|
|
|
context,
|
|
|
|
|
options->device,
|
2017-05-25 10:12:26 +10:00
|
|
|
options->verbose);
|
2017-05-25 15:34:30 +10:00
|
|
|
} else {
|
2014-12-18 15:02:45 +10:00
|
|
|
abort();
|
2017-05-25 15:34:30 +10:00
|
|
|
}
|
2014-12-18 15:02:45 +10:00
|
|
|
|
|
|
|
|
return li;
|
|
|
|
|
}
|
2014-12-18 15:10:09 +10:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tools_device_apply_config(struct libinput_device *device,
|
|
|
|
|
struct tools_options *options)
|
|
|
|
|
{
|
|
|
|
|
if (options->tapping != -1)
|
|
|
|
|
libinput_device_config_tap_set_enabled(device, options->tapping);
|
2016-12-05 20:31:31 +10:00
|
|
|
if (options->tap_map != (enum libinput_config_tap_button_map)-1)
|
2016-07-21 11:46:05 +10:00
|
|
|
libinput_device_config_tap_set_button_map(device,
|
|
|
|
|
options->tap_map);
|
2016-01-22 17:59:19 +10:00
|
|
|
if (options->drag != -1)
|
|
|
|
|
libinput_device_config_tap_set_drag_enabled(device,
|
|
|
|
|
options->drag);
|
2015-06-22 11:07:31 +10:00
|
|
|
if (options->drag_lock != -1)
|
|
|
|
|
libinput_device_config_tap_set_drag_lock_enabled(device,
|
|
|
|
|
options->drag_lock);
|
2014-12-18 15:10:59 +10:00
|
|
|
if (options->natural_scroll != -1)
|
|
|
|
|
libinput_device_config_scroll_set_natural_scroll_enabled(device,
|
|
|
|
|
options->natural_scroll);
|
2014-12-18 15:14:09 +10:00
|
|
|
if (options->left_handed != -1)
|
2015-01-06 21:20:22 -05:00
|
|
|
libinput_device_config_left_handed_set(device, options->left_handed);
|
2015-04-14 12:08:33 +10:00
|
|
|
if (options->middlebutton != -1)
|
|
|
|
|
libinput_device_config_middle_emulation_set_enabled(device,
|
|
|
|
|
options->middlebutton);
|
2015-01-16 10:16:47 +10:00
|
|
|
|
2015-07-08 15:03:06 +10:00
|
|
|
if (options->dwt != -1)
|
|
|
|
|
libinput_device_config_dwt_set_enabled(device, options->dwt);
|
|
|
|
|
|
2016-12-05 20:31:31 +10:00
|
|
|
if (options->click_method != (enum libinput_config_click_method)-1)
|
2015-01-16 10:16:47 +10:00
|
|
|
libinput_device_config_click_set_method(device, options->click_method);
|
2015-04-10 15:45:59 +10:00
|
|
|
|
2016-12-05 20:31:31 +10:00
|
|
|
if (options->scroll_method != (enum libinput_config_scroll_method)-1)
|
2015-04-21 11:57:23 +10:00
|
|
|
libinput_device_config_scroll_set_method(device,
|
|
|
|
|
options->scroll_method);
|
2015-04-21 18:24:39 +10:00
|
|
|
if (options->scroll_button != -1)
|
|
|
|
|
libinput_device_config_scroll_set_button(device,
|
|
|
|
|
options->scroll_button);
|
2015-04-21 11:57:23 +10:00
|
|
|
|
2015-08-27 13:13:47 +10:00
|
|
|
if (libinput_device_config_accel_is_available(device)) {
|
2015-04-10 15:45:59 +10:00
|
|
|
libinput_device_config_accel_set_speed(device,
|
|
|
|
|
options->speed);
|
2015-08-27 13:13:47 +10:00
|
|
|
if (options->profile != LIBINPUT_CONFIG_ACCEL_PROFILE_NONE)
|
|
|
|
|
libinput_device_config_accel_set_profile(device,
|
|
|
|
|
options->profile);
|
|
|
|
|
}
|
2014-12-18 15:10:09 +10:00
|
|
|
}
|
2017-05-23 15:07:31 +10:00
|
|
|
|
|
|
|
|
static char*
|
|
|
|
|
find_device(const char *udev_tag)
|
|
|
|
|
{
|
|
|
|
|
struct udev *udev;
|
|
|
|
|
struct udev_enumerate *e;
|
|
|
|
|
struct udev_list_entry *entry;
|
|
|
|
|
struct udev_device *device;
|
|
|
|
|
const char *path, *sysname;
|
|
|
|
|
char *device_node = NULL;
|
|
|
|
|
|
|
|
|
|
udev = udev_new();
|
|
|
|
|
e = udev_enumerate_new(udev);
|
|
|
|
|
udev_enumerate_add_match_subsystem(e, "input");
|
|
|
|
|
udev_enumerate_scan_devices(e);
|
|
|
|
|
|
|
|
|
|
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
|
|
|
|
path = udev_list_entry_get_name(entry);
|
|
|
|
|
device = udev_device_new_from_syspath(udev, path);
|
|
|
|
|
if (!device)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
sysname = udev_device_get_sysname(device);
|
|
|
|
|
if (strncmp("event", sysname, 5) != 0) {
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (udev_device_get_property_value(device, udev_tag))
|
|
|
|
|
device_node = strdup(udev_device_get_devnode(device));
|
|
|
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
|
|
|
|
|
|
if (device_node)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
udev_enumerate_unref(e);
|
|
|
|
|
udev_unref(udev);
|
|
|
|
|
|
|
|
|
|
return device_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
find_touchpad_device(char *path, size_t path_len)
|
|
|
|
|
{
|
|
|
|
|
char *devnode = find_device("ID_INPUT_TOUCHPAD");
|
|
|
|
|
|
|
|
|
|
if (devnode) {
|
|
|
|
|
snprintf(path, path_len, "%s", devnode);
|
|
|
|
|
free(devnode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devnode != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
is_touchpad_device(const char *devnode)
|
|
|
|
|
{
|
|
|
|
|
struct udev *udev;
|
|
|
|
|
struct udev_device *dev = NULL;
|
|
|
|
|
struct stat st;
|
|
|
|
|
bool is_touchpad = false;
|
|
|
|
|
|
|
|
|
|
if (stat(devnode, &st) < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
udev = udev_new();
|
|
|
|
|
dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
|
|
|
|
|
if (!dev)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
is_touchpad = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
|
|
|
|
|
out:
|
|
|
|
|
if (dev)
|
|
|
|
|
udev_device_unref(dev);
|
|
|
|
|
udev_unref(udev);
|
|
|
|
|
|
|
|
|
|
return is_touchpad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
setup_path(void)
|
|
|
|
|
{
|
|
|
|
|
const char *path = getenv("PATH");
|
|
|
|
|
char new_path[PATH_MAX];
|
|
|
|
|
|
|
|
|
|
snprintf(new_path,
|
|
|
|
|
sizeof(new_path),
|
|
|
|
|
"%s:%s",
|
|
|
|
|
LIBINPUT_TOOL_PATH,
|
|
|
|
|
path ? path : "");
|
|
|
|
|
setenv("PATH", new_path, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
tools_exec_command(const char *prefix, int real_argc, char **real_argv)
|
|
|
|
|
{
|
|
|
|
|
char *argv[64] = {NULL};
|
|
|
|
|
char executable[128];
|
|
|
|
|
const char *command;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
assert((size_t)real_argc < ARRAY_LENGTH(argv));
|
|
|
|
|
|
|
|
|
|
command = real_argv[0];
|
|
|
|
|
|
|
|
|
|
rc = snprintf(executable,
|
|
|
|
|
sizeof(executable),
|
|
|
|
|
"%s-%s",
|
|
|
|
|
prefix,
|
|
|
|
|
command);
|
|
|
|
|
if (rc >= (int)sizeof(executable)) {
|
|
|
|
|
fprintf(stderr, "Failed to assemble command.\n");
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argv[0] = executable;
|
|
|
|
|
for (int i = 1; i < real_argc; i++)
|
|
|
|
|
argv[i] = real_argv[i];
|
|
|
|
|
|
|
|
|
|
setup_path();
|
|
|
|
|
|
|
|
|
|
rc = execvp(executable, argv);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Failed to execute '%s' (%s)\n",
|
|
|
|
|
command,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|