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>
|
|
|
|
|
|
2019-09-06 11:42:09 +10:00
|
|
|
#include <assert.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
#include <errno.h>
|
2015-06-24 14:52:48 +10:00
|
|
|
#include <fcntl.h>
|
2017-09-05 14:12:09 +10:00
|
|
|
#include <fnmatch.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
#include <getopt.h>
|
2025-07-01 16:30:11 +10:00
|
|
|
#include <libevdev/libevdev.h>
|
|
|
|
|
#include <libudev.h>
|
2019-09-06 11:42:09 +10:00
|
|
|
#include <limits.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2017-05-23 15:07:31 +10:00
|
|
|
#include <sys/stat.h>
|
2019-09-06 11:42:09 +10:00
|
|
|
#include <unistd.h>
|
2014-12-18 14:42:42 +10:00
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
#include "util-macros.h"
|
|
|
|
|
#include "util-strings.h"
|
2015-04-21 18:24:39 +10:00
|
|
|
|
2019-03-06 20:16:41 +10:00
|
|
|
#include "builddir.h"
|
2025-04-01 13:42:27 +10:00
|
|
|
#include "libinput-util.h"
|
2025-07-01 16:30:11 +10:00
|
|
|
#include "libinput.h"
|
2014-12-18 14:42:42 +10:00
|
|
|
#include "shared.h"
|
|
|
|
|
|
2020-10-06 15:35:44 +10:00
|
|
|
static uint32_t dispatch_counter = 0;
|
2024-09-06 14:45:30 +10:00
|
|
|
uint32_t log_serial = 0;
|
2020-10-06 15:35:44 +10:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tools_dispatch(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
dispatch_counter++;
|
|
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2025-10-27 12:35:05 +10:00
|
|
|
static int use_color = -1;
|
2020-10-06 15:35:44 +10:00
|
|
|
static uint32_t last_dispatch_no = 0;
|
2020-10-06 16:03:19 +10:00
|
|
|
static bool color_toggle = false;
|
2017-02-13 16:28:28 +10:00
|
|
|
|
2025-10-27 12:35:05 +10:00
|
|
|
if (use_color == -1) {
|
|
|
|
|
if (getenv("NO_COLOR"))
|
|
|
|
|
use_color = 0;
|
|
|
|
|
else if (getenv("FORCE_COLOR"))
|
|
|
|
|
use_color = 1;
|
|
|
|
|
else
|
|
|
|
|
use_color = isatty(STDOUT_FILENO);
|
|
|
|
|
}
|
2017-02-13 16:28:28 +10:00
|
|
|
|
2025-10-27 12:35:05 +10:00
|
|
|
if (use_color) {
|
2020-10-06 16:03:19 +10:00
|
|
|
if (priority >= LIBINPUT_LOG_PRIORITY_ERROR) {
|
2024-11-01 16:00:12 +10:00
|
|
|
if (strstr(format, "client bug: ") ||
|
|
|
|
|
strstr(format, "libinput bug: ") ||
|
|
|
|
|
strstr(format, "kernel bug: "))
|
|
|
|
|
printf(ANSI_BRIGHT_RED);
|
|
|
|
|
else
|
|
|
|
|
printf(ANSI_RED);
|
2020-10-06 16:03:19 +10:00
|
|
|
} else if (priority >= LIBINPUT_LOG_PRIORITY_INFO) {
|
2025-06-18 13:28:34 +10:00
|
|
|
printf(ANSI_BOLD);
|
2020-10-06 16:03:19 +10:00
|
|
|
} else if (priority == LIBINPUT_LOG_PRIORITY_DEBUG) {
|
|
|
|
|
if (dispatch_counter != last_dispatch_no)
|
|
|
|
|
color_toggle = !color_toggle;
|
2025-07-01 16:30:11 +10:00
|
|
|
uint8_t r = 0, g = 135, b = 95 + (color_toggle ? 80 : 0);
|
2020-10-06 16:03:19 +10:00
|
|
|
printf("\x1B[38;2;%u;%u;%um", r, g, b);
|
|
|
|
|
}
|
2017-02-13 16:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
2020-10-06 15:35:44 +10:00
|
|
|
if (priority < LIBINPUT_LOG_PRIORITY_INFO) {
|
|
|
|
|
if (dispatch_counter != last_dispatch_no) {
|
|
|
|
|
last_dispatch_no = dispatch_counter;
|
|
|
|
|
printf("%4u: ", dispatch_counter);
|
|
|
|
|
} else {
|
|
|
|
|
printf(" %4s ", "...");
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-18 15:02:45 +10:00
|
|
|
vprintf(format, args);
|
2017-02-13 16:28:28 +10:00
|
|
|
|
2025-10-27 12:35:05 +10:00
|
|
|
if (use_color)
|
2017-02-13 16:28:28 +10:00
|
|
|
printf(ANSI_NORMAL);
|
2024-09-06 14:45:30 +10:00
|
|
|
|
|
|
|
|
log_serial++;
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2014-12-18 14:42:42 +10:00
|
|
|
void
|
2017-06-19 18:38:33 +10:00
|
|
|
tools_init_options(struct tools_options *options)
|
2014-12-18 14:42:42 +10:00
|
|
|
{
|
|
|
|
|
memset(options, 0, sizeof(*options));
|
2025-04-22 10:25:55 +10:00
|
|
|
options->plugins = -1;
|
|
|
|
|
options->plugin_paths = NULL;
|
2014-12-18 14:42:42 +10:00
|
|
|
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;
|
2022-03-08 01:33:40 +00:00
|
|
|
options->dwtp = -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;
|
2019-03-20 10:56:51 +10:00
|
|
|
options->scroll_button_lock = -1;
|
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;
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
/* initialize accel args */
|
2025-07-01 16:30:11 +10:00
|
|
|
static double points[] = { 0.0, 1.0 };
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
options->custom_points = points;
|
|
|
|
|
options->custom_npoints = ARRAY_LENGTH(points);
|
|
|
|
|
options->custom_type = LIBINPUT_ACCEL_TYPE_FALLBACK;
|
|
|
|
|
options->custom_step = 1.0;
|
2024-06-07 12:18:40 +10:00
|
|
|
options->pressure_range[0] = 0.0;
|
|
|
|
|
options->pressure_range[1] = 1.0;
|
2024-06-19 11:33:44 +10:00
|
|
|
options->calibration[0] = 1.0;
|
|
|
|
|
options->calibration[4] = 1.0;
|
2024-06-13 09:00:21 +10:00
|
|
|
options->area.x1 = 0.0;
|
|
|
|
|
options->area.y1 = 0.0;
|
|
|
|
|
options->area.x2 = 1.0;
|
|
|
|
|
options->area.y2 = 1.0;
|
2025-03-09 17:55:49 +10:00
|
|
|
options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
|
2025-06-02 15:11:08 +10:00
|
|
|
options->eraser_button_mode = LIBINPUT_CONFIG_ERASER_BUTTON_DEFAULT;
|
|
|
|
|
options->eraser_button_button = BTN_STYLUS;
|
|
|
|
|
options->eraser_button_button = 0;
|
2014-12-18 14:42:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-07-01 16:30:11 +10:00
|
|
|
tools_parse_option(int option, const char *optarg, struct tools_options *options)
|
2014-12-18 14:42:42 +10:00
|
|
|
{
|
2025-07-01 16:30:11 +10:00
|
|
|
switch (option) {
|
2025-04-22 10:25:55 +10:00
|
|
|
case OPT_PLUGINS_ENABLE:
|
|
|
|
|
options->plugins = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_PLUGINS_DISABLE:
|
|
|
|
|
options->plugins = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_PLUGIN_PATH:
|
|
|
|
|
options->plugin_paths = strv_from_string(optarg, ":", NULL);
|
|
|
|
|
break;
|
2018-04-12 11:56:43 +10:00
|
|
|
case OPT_TAP_ENABLE:
|
|
|
|
|
options->tapping = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_TAP_DISABLE:
|
|
|
|
|
options->tapping = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_TAP_MAP:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2017-06-19 18:38:33 +10:00
|
|
|
|
2018-04-12 11:56:43 +10:00
|
|
|
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 {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_ENABLE:
|
|
|
|
|
options->drag = 1;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_DISABLE:
|
|
|
|
|
options->drag = 0;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_LOCK_ENABLE:
|
2024-09-02 16:29:02 +02:00
|
|
|
if (optarg) {
|
|
|
|
|
if (streq(optarg, "sticky")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->drag_lock =
|
|
|
|
|
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY;
|
2024-09-02 16:29:02 +02:00
|
|
|
} else if (streq(optarg, "timeout")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->drag_lock =
|
|
|
|
|
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT;
|
2024-09-02 16:29:02 +02:00
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT;
|
|
|
|
|
}
|
2018-04-12 11:56:43 +10:00
|
|
|
break;
|
|
|
|
|
case OPT_DRAG_LOCK_DISABLE:
|
2024-09-02 16:29:02 +02:00
|
|
|
options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
|
2018-04-12 11:56:43 +10:00
|
|
|
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;
|
2022-03-08 01:33:40 +00:00
|
|
|
case OPT_DWTP_ENABLE:
|
|
|
|
|
options->dwtp = LIBINPUT_CONFIG_DWTP_ENABLED;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_DWTP_DISABLE:
|
|
|
|
|
options->dwtp = LIBINPUT_CONFIG_DWTP_DISABLED;
|
|
|
|
|
break;
|
2018-04-12 11:56:43 +10:00
|
|
|
case OPT_CLICK_METHOD:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2017-06-19 18:38:33 +10:00
|
|
|
|
2018-04-12 11:56:43 +10:00
|
|
|
if (streq(optarg, "none")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else if (streq(optarg, "clickfinger")) {
|
|
|
|
|
options->click_method =
|
2025-07-01 16:30:11 +10:00
|
|
|
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else if (streq(optarg, "buttonareas")) {
|
|
|
|
|
options->click_method =
|
2025-07-01 16:30:11 +10:00
|
|
|
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-04-09 18:46:42 -03:00
|
|
|
case OPT_CLICKFINGER_MAP:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (streq(optarg, "lrm")) {
|
|
|
|
|
options->clickfinger_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM;
|
|
|
|
|
} else if (streq(optarg, "lmr")) {
|
|
|
|
|
options->clickfinger_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR;
|
|
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-04-12 11:56:43 +10:00
|
|
|
case OPT_SCROLL_METHOD:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2017-06-19 18:38:33 +10:00
|
|
|
|
2018-04-12 11:56:43 +10:00
|
|
|
if (streq(optarg, "none")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else if (streq(optarg, "twofinger")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else if (streq(optarg, "edge")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else if (streq(optarg, "button")) {
|
2025-07-01 16:30:11 +10:00
|
|
|
options->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
|
2018-04-12 11:56:43 +10:00
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_SCROLL_BUTTON:
|
|
|
|
|
if (!optarg) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2025-07-01 16:30:11 +10:00
|
|
|
options->scroll_button = libevdev_event_code_from_name(EV_KEY, optarg);
|
2018-04-12 11:56:43 +10:00
|
|
|
if (options->scroll_button == -1) {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr, "Invalid button %s\n", optarg);
|
2018-04-12 11:56:43 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-03-20 10:56:51 +10:00
|
|
|
case OPT_SCROLL_BUTTON_LOCK_ENABLE:
|
|
|
|
|
options->scroll_button_lock = true;
|
|
|
|
|
break;
|
|
|
|
|
case OPT_SCROLL_BUTTON_LOCK_DISABLE:
|
|
|
|
|
options->scroll_button_lock = false;
|
|
|
|
|
break;
|
2018-04-12 11:56:43 +10:00
|
|
|
case OPT_SPEED:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
options->speed = atof(optarg);
|
|
|
|
|
break;
|
|
|
|
|
case OPT_PROFILE:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2017-06-19 18:38:33 +10:00
|
|
|
|
2018-04-12 11:56:43 +10:00
|
|
|
if (streq(optarg, "adaptive"))
|
|
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
|
|
|
|
else if (streq(optarg, "flat"))
|
2025-07-01 16:30:11 +10:00
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
else if (streq(optarg, "custom"))
|
2025-07-01 16:30:11 +10:00
|
|
|
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM;
|
2018-04-12 11:56:43 +10:00
|
|
|
else
|
2025-07-01 16:30:11 +10:00
|
|
|
return 1;
|
2018-04-12 11:56:43 +10:00
|
|
|
break;
|
|
|
|
|
case OPT_DISABLE_SENDEVENTS:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2017-09-05 14:12:09 +10:00
|
|
|
|
2018-04-12 11:56:43 +10:00
|
|
|
snprintf(options->disable_pattern,
|
|
|
|
|
sizeof(options->disable_pattern),
|
|
|
|
|
"%s",
|
|
|
|
|
optarg);
|
|
|
|
|
break;
|
2025-03-09 17:55:49 +10:00
|
|
|
case OPT_SENDEVENTS:
|
|
|
|
|
if (streq(optarg, "disabled"))
|
|
|
|
|
options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
|
|
|
|
|
else if (streq(optarg, "enabled"))
|
|
|
|
|
options->sendevents = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
|
|
|
|
|
else if (streq(optarg, "disabled-on-external-mouse"))
|
2025-07-01 16:30:11 +10:00
|
|
|
options->sendevents =
|
|
|
|
|
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
|
2025-03-09 17:55:49 +10:00
|
|
|
else {
|
|
|
|
|
fprintf(stderr, "Invalid sendevents mode: %s\n", optarg);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-05-08 11:24:28 +10:00
|
|
|
case OPT_APPLY_TO:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
snprintf(options->match, sizeof(options->match), "%s", optarg);
|
2019-05-08 11:24:28 +10:00
|
|
|
break;
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
case OPT_CUSTOM_POINTS:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
2025-07-01 16:30:11 +10:00
|
|
|
options->custom_points =
|
|
|
|
|
double_array_from_string(optarg, ";", &options->custom_npoints);
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
if (!options->custom_points || options->custom_npoints < 2) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid --set-custom-points\n"
|
|
|
|
|
"Please provide at least 2 points separated by a semicolon\n"
|
|
|
|
|
" e.g. --set-custom-points=\"1.0;1.5\"\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_CUSTOM_STEP:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
options->custom_step = strtod(optarg, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case OPT_CUSTOM_TYPE:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
if (streq(optarg, "fallback"))
|
|
|
|
|
options->custom_type = LIBINPUT_ACCEL_TYPE_FALLBACK;
|
|
|
|
|
else if (streq(optarg, "motion"))
|
|
|
|
|
options->custom_type = LIBINPUT_ACCEL_TYPE_MOTION;
|
2023-02-18 21:12:13 +02:00
|
|
|
else if (streq(optarg, "scroll"))
|
|
|
|
|
options->custom_type = LIBINPUT_ACCEL_TYPE_SCROLL;
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
else {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid --set-custom-type\n"
|
|
|
|
|
"Valid custom types: fallback|motion|scroll\n");
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-04-18 17:05:41 +10:00
|
|
|
case OPT_ROTATION_ANGLE:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (!safe_atou(optarg, &options->angle)) {
|
|
|
|
|
fprintf(stderr, "Invalid --set-rotation-angle value\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2024-06-07 12:18:40 +10:00
|
|
|
break;
|
|
|
|
|
case OPT_PRESSURE_RANGE: {
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
size_t npoints = 0;
|
2025-07-01 16:30:11 +10:00
|
|
|
_autofree_ double *range =
|
|
|
|
|
double_array_from_string(optarg, ":", &npoints);
|
|
|
|
|
if (npoints != 2 || !range || range[0] < 0.0 || range[1] > 1.0 ||
|
|
|
|
|
range[0] >= range[1]) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid pressure range, must be in format \"min:max\"\n");
|
2024-06-07 12:18:40 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
options->pressure_range[0] = range[0];
|
|
|
|
|
options->pressure_range[1] = range[1];
|
|
|
|
|
break;
|
2025-07-01 16:30:11 +10:00
|
|
|
}
|
2024-06-19 11:33:44 +10:00
|
|
|
case OPT_CALIBRATION: {
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
size_t npoints = 0;
|
2025-07-01 16:30:11 +10:00
|
|
|
_autofree_ double *matrix =
|
|
|
|
|
double_array_from_string(optarg, " ", &npoints);
|
2024-09-20 21:33:38 +10:00
|
|
|
if (!matrix || npoints != 6) {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid calibration matrix, must be 6 space-separated values\n");
|
2024-06-19 11:33:44 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < 6; i++)
|
2025-07-01 16:30:11 +10:00
|
|
|
options->calibration[i] = matrix[i];
|
2024-06-19 11:33:44 +10:00
|
|
|
break;
|
2024-06-13 09:00:21 +10:00
|
|
|
}
|
|
|
|
|
case OPT_AREA: {
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
double x1, x2, y1, y2;
|
|
|
|
|
|
|
|
|
|
if (sscanf(optarg, "%lf/%lf %lf/%lf", &x1, &y1, &x2, &y2) != 4) {
|
|
|
|
|
fprintf(stderr, "Invalid --set-area values\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
options->area.x1 = x1;
|
|
|
|
|
options->area.y1 = y1;
|
|
|
|
|
options->area.x2 = x2;
|
|
|
|
|
options->area.y2 = y2;
|
|
|
|
|
break;
|
2025-07-01 16:30:11 +10:00
|
|
|
}
|
2024-09-06 11:38:35 +10:00
|
|
|
case OPT_3FG_DRAG:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
if (streq(optarg, "3fg"))
|
|
|
|
|
options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG;
|
|
|
|
|
else if (streq(optarg, "4fg"))
|
|
|
|
|
options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG;
|
|
|
|
|
else if (streq(optarg, "disabled"))
|
|
|
|
|
options->drag_3fg = LIBINPUT_CONFIG_3FG_DRAG_DISABLED;
|
|
|
|
|
else {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid --enable-3fg-drag\n"
|
|
|
|
|
"Valid options: 3fg|4fg|disabled\n");
|
2024-09-06 11:38:35 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2025-03-25 15:20:14 +10:00
|
|
|
case OPT_ERASER_BUTTON_MODE:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
if (streq(optarg, "default"))
|
2025-07-01 16:30:11 +10:00
|
|
|
options->eraser_button_mode =
|
|
|
|
|
LIBINPUT_CONFIG_ERASER_BUTTON_DEFAULT;
|
2025-03-25 15:20:14 +10:00
|
|
|
else if (streq(optarg, "button"))
|
2025-07-01 16:30:11 +10:00
|
|
|
options->eraser_button_mode =
|
|
|
|
|
LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON;
|
2025-03-25 15:20:14 +10:00
|
|
|
else {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid --set-eraser-button-mode\n"
|
|
|
|
|
"Valid options: default|button\n");
|
2025-03-25 15:20:14 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OPT_ERASER_BUTTON_BUTTON:
|
|
|
|
|
if (!optarg)
|
|
|
|
|
return 1;
|
|
|
|
|
if (streq(optarg, "BTN_STYLUS"))
|
|
|
|
|
options->eraser_button_button = BTN_STYLUS;
|
|
|
|
|
else if (streq(optarg, "BTN_STYLUS2"))
|
|
|
|
|
options->eraser_button_button = BTN_STYLUS2;
|
|
|
|
|
else if (streq(optarg, "BTN_STYLUS3"))
|
|
|
|
|
options->eraser_button_button = BTN_STYLUS3;
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stderr, "Unsupported eraser button %s\n", optarg);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-12-18 14:42:42 +10:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-12-18 15:02:45 +10:00
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
static int
|
|
|
|
|
open_restricted(const char *path, int flags, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
bool *grab = user_data;
|
|
|
|
|
int fd = open(path, flags);
|
|
|
|
|
|
|
|
|
|
if (fd < 0)
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr, "Failed to open %s (%s)\n", path, strerror(errno));
|
|
|
|
|
else if (grab && *grab && ioctl(fd, EVIOCGRAB, (void *)1) == -1)
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Grab requested, but failed for %s (%s)\n",
|
|
|
|
|
path,
|
|
|
|
|
strerror(errno));
|
2017-06-19 18:38:33 +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,
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-22 10:25:55 +10:00
|
|
|
static int
|
|
|
|
|
add_path(const char *str, size_t index, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput = data;
|
|
|
|
|
libinput_plugin_system_append_default_paths(libinput);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tools_load_plugins(struct libinput *libinput, char **plugin_paths)
|
|
|
|
|
{
|
|
|
|
|
_autofree_ char *builddir = NULL;
|
|
|
|
|
|
|
|
|
|
if (plugin_paths) {
|
|
|
|
|
strv_for_each((const char **)plugin_paths, add_path, libinput);
|
|
|
|
|
strv_free(plugin_paths);
|
|
|
|
|
} else {
|
|
|
|
|
if (builddir_lookup(&builddir)) {
|
|
|
|
|
_autofree_ char *plugindir =
|
|
|
|
|
strdup_printf("%s/plugins", builddir);
|
|
|
|
|
libinput_plugin_system_append_path(libinput, plugindir);
|
|
|
|
|
}
|
|
|
|
|
libinput_plugin_system_append_default_paths(libinput);
|
|
|
|
|
}
|
|
|
|
|
switch (libinput_plugin_system_load_plugins(libinput,
|
2025-10-23 09:43:53 +10:00
|
|
|
LIBINPUT_PLUGIN_SYSTEM_FLAG_NONE)) {
|
2025-04-22 10:25:55 +10:00
|
|
|
case -ENOSYS:
|
|
|
|
|
fprintf(stderr, "Warning: plugins were disabled at compile time");
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:45 +10:00
|
|
|
static struct libinput *
|
2025-04-22 10:25:55 +10:00
|
|
|
tools_open_udev(const char *seat,
|
|
|
|
|
bool verbose,
|
|
|
|
|
bool *grab,
|
|
|
|
|
bool with_plugins,
|
|
|
|
|
char **plugin_paths)
|
2014-12-18 15:02:45 +10:00
|
|
|
{
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2014-12-18 15:02:45 +10:00
|
|
|
if (!udev) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize udev\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&interface, grab, udev);
|
2014-12-18 15:02:45 +10:00
|
|
|
if (!li) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize context from udev\n");
|
2025-04-01 13:42:27 +10:00
|
|
|
return NULL;
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2018-07-19 14:10:32 +10:00
|
|
|
libinput_log_set_handler(li, log_handler);
|
|
|
|
|
if (verbose)
|
2014-12-18 15:02:45 +10:00
|
|
|
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
|
|
|
|
|
|
2025-04-22 10:25:55 +10:00
|
|
|
if (with_plugins)
|
|
|
|
|
tools_load_plugins(li, plugin_paths);
|
|
|
|
|
|
2014-12-18 15:02:45 +10:00
|
|
|
if (libinput_udev_assign_seat(li, seat)) {
|
|
|
|
|
fprintf(stderr, "Failed to set seat\n");
|
2025-04-01 13:42:27 +10:00
|
|
|
return NULL;
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
return steal(&li);
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct libinput *
|
2025-04-22 10:25:55 +10:00
|
|
|
tools_open_device(const char **paths,
|
|
|
|
|
bool verbose,
|
|
|
|
|
bool *grab,
|
|
|
|
|
bool with_plugins,
|
|
|
|
|
char **plugin_paths)
|
2014-12-18 15:02:45 +10:00
|
|
|
{
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(libinput) *li = libinput_path_create_context(&interface, grab);
|
2014-12-18 15:02:45 +10:00
|
|
|
if (!li) {
|
2019-11-25 12:22:19 +10:00
|
|
|
fprintf(stderr, "Failed to initialize path context\n");
|
2014-12-18 15:02:45 +10:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
libinput_log_set_handler(li, log_handler);
|
|
|
|
|
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 10:25:55 +10:00
|
|
|
if (with_plugins)
|
|
|
|
|
tools_load_plugins(li, plugin_paths);
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
const char **p = paths;
|
2019-11-25 12:22:19 +10:00
|
|
|
while (*p) {
|
2025-04-01 13:42:27 +10:00
|
|
|
struct libinput_device *device = libinput_path_add_device(li, *p);
|
2019-11-25 12:22:19 +10:00
|
|
|
if (!device) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize device %s\n", *p);
|
2025-04-01 13:42:27 +10:00
|
|
|
return NULL;
|
2019-11-25 12:22:19 +10:00
|
|
|
}
|
|
|
|
|
p++;
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
return steal(&li);
|
2014-12-18 15:02:45 +10:00
|
|
|
}
|
|
|
|
|
|
2018-07-17 10:02:49 +10:00
|
|
|
static void
|
|
|
|
|
tools_setenv_quirks_dir(void)
|
|
|
|
|
{
|
2025-04-01 13:42:27 +10:00
|
|
|
if (builddir_lookup(NULL))
|
2018-07-17 10:02:49 +10:00
|
|
|
setenv("LIBINPUT_QUIRKS_DIR", LIBINPUT_QUIRKS_SRCDIR, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:45 +10:00
|
|
|
struct libinput *
|
2017-06-19 18:38:33 +10:00
|
|
|
tools_open_backend(enum tools_backend which,
|
2020-02-21 10:28:56 +10:00
|
|
|
const char **seat_or_device,
|
2017-06-19 18:38:33 +10:00
|
|
|
bool verbose,
|
2025-04-22 10:25:55 +10:00
|
|
|
bool *grab,
|
|
|
|
|
bool with_plugins,
|
|
|
|
|
char **plugin_paths)
|
2014-12-18 15:02:45 +10:00
|
|
|
{
|
2017-06-19 18:38:33 +10:00
|
|
|
struct libinput *li;
|
|
|
|
|
|
2018-07-17 10:02:49 +10:00
|
|
|
tools_setenv_quirks_dir();
|
|
|
|
|
|
2017-06-19 18:38:33 +10:00
|
|
|
switch (which) {
|
|
|
|
|
case BACKEND_UDEV:
|
2025-04-22 10:25:55 +10:00
|
|
|
li = tools_open_udev(seat_or_device[0],
|
|
|
|
|
verbose,
|
|
|
|
|
grab,
|
|
|
|
|
with_plugins,
|
|
|
|
|
plugin_paths);
|
2017-06-19 18:38:33 +10:00
|
|
|
break;
|
|
|
|
|
case BACKEND_DEVICE:
|
2025-04-22 10:25:55 +10:00
|
|
|
li = tools_open_device(seat_or_device,
|
|
|
|
|
verbose,
|
|
|
|
|
grab,
|
|
|
|
|
with_plugins,
|
|
|
|
|
plugin_paths);
|
2017-06-19 18:38:33 +10:00
|
|
|
break;
|
|
|
|
|
default:
|
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
|
2025-07-01 16:30:11 +10:00
|
|
|
tools_device_apply_config(struct libinput_device *device, struct tools_options *options)
|
2014-12-18 15:10:09 +10:00
|
|
|
{
|
2019-05-08 11:24:28 +10:00
|
|
|
const char *name = libinput_device_get_name(device);
|
|
|
|
|
|
|
|
|
|
if (libinput_device_config_send_events_get_modes(device) &
|
2025-07-01 16:30:11 +10:00
|
|
|
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED &&
|
2019-05-08 11:24:28 +10:00
|
|
|
fnmatch(options->disable_pattern, name, 0) != FNM_NOMATCH) {
|
2025-07-01 16:30:11 +10:00
|
|
|
libinput_device_config_send_events_set_mode(
|
|
|
|
|
device,
|
|
|
|
|
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
|
2019-05-08 11:24:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen(options->match) > 0 &&
|
|
|
|
|
fnmatch(options->match, name, 0) == FNM_NOMATCH)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-03-09 17:55:49 +10:00
|
|
|
libinput_device_config_send_events_set_mode(device, options->sendevents);
|
|
|
|
|
|
2014-12-18 15:10:09 +10:00
|
|
|
if (options->tapping != -1)
|
|
|
|
|
libinput_device_config_tap_set_enabled(device, options->tapping);
|
2025-07-01 16:30:11 +10:00
|
|
|
if (options->tap_map != (enum libinput_config_tap_button_map) - 1)
|
|
|
|
|
libinput_device_config_tap_set_button_map(device, options->tap_map);
|
2016-01-22 17:59:19 +10:00
|
|
|
if (options->drag != -1)
|
2025-07-01 16:30:11 +10:00
|
|
|
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)
|
2025-07-01 16:30:11 +10:00
|
|
|
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)
|
2025-07-01 16:30:11 +10:00
|
|
|
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);
|
|
|
|
|
|
2022-08-08 13:56:11 +10:00
|
|
|
if (options->dwtp != -1)
|
|
|
|
|
libinput_device_config_dwtp_set_enabled(device, options->dwtp);
|
|
|
|
|
|
2025-07-01 16:30:11 +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
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
if (options->clickfinger_map !=
|
|
|
|
|
(enum libinput_config_clickfinger_button_map) - 1)
|
|
|
|
|
libinput_device_config_click_set_clickfinger_button_map(
|
|
|
|
|
device,
|
|
|
|
|
options->clickfinger_map);
|
2024-04-09 18:46:42 -03:00
|
|
|
|
2025-07-01 16:30:11 +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);
|
2019-03-20 10:56:51 +10:00
|
|
|
if (options->scroll_button_lock != -1)
|
2025-07-01 16:30:11 +10:00
|
|
|
libinput_device_config_scroll_set_button_lock(
|
|
|
|
|
device,
|
|
|
|
|
options->scroll_button_lock);
|
2019-03-20 10:56:51 +10:00
|
|
|
|
2015-08-27 13:13:47 +10:00
|
|
|
if (libinput_device_config_accel_is_available(device)) {
|
2025-07-01 16:30:11 +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);
|
|
|
|
|
}
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
|
|
|
|
|
if (options->profile == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) {
|
2025-07-01 16:30:11 +10:00
|
|
|
_destroy_(libinput_config_accel) *config = libinput_config_accel_create(
|
|
|
|
|
LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM);
|
Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.
This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.
regular filter is Motion type.
constant filter is Fallback type.
This allows possible expansion of new movement types for the
different devices.
The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.
The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-13 00:23:59 +02:00
|
|
|
libinput_config_accel_set_points(config,
|
|
|
|
|
options->custom_type,
|
|
|
|
|
options->custom_step,
|
|
|
|
|
options->custom_npoints,
|
|
|
|
|
options->custom_points);
|
|
|
|
|
libinput_device_config_accel_apply(device, config);
|
|
|
|
|
}
|
2023-04-18 17:05:41 +10:00
|
|
|
|
|
|
|
|
if (options->angle != 0)
|
|
|
|
|
libinput_device_config_rotation_set_angle(device, options->angle % 360);
|
2024-06-19 11:33:44 +10:00
|
|
|
|
|
|
|
|
if (libinput_device_config_calibration_has_matrix(device))
|
2025-07-01 16:30:11 +10:00
|
|
|
libinput_device_config_calibration_set_matrix(device,
|
|
|
|
|
options->calibration);
|
2024-06-13 09:00:21 +10:00
|
|
|
|
|
|
|
|
if (libinput_device_config_area_has_rectangle(device))
|
|
|
|
|
libinput_device_config_area_set_rectangle(device, &options->area);
|
2024-09-06 11:38:35 +10:00
|
|
|
|
|
|
|
|
if (libinput_device_config_3fg_drag_get_finger_count(device) >= 3)
|
|
|
|
|
libinput_device_config_3fg_drag_set_enabled(device, options->drag_3fg);
|
2014-12-18 15:10:09 +10:00
|
|
|
}
|
2017-05-23 15:07:31 +10:00
|
|
|
|
2024-06-07 12:18:40 +10:00
|
|
|
void
|
|
|
|
|
tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool,
|
|
|
|
|
struct tools_options *options)
|
|
|
|
|
{
|
2025-10-23 15:14:52 +10:00
|
|
|
if (options->pressure_range[0] != 0.0 || options->pressure_range[1] != 1.0)
|
|
|
|
|
libinput_tablet_tool_config_pressure_range_set(
|
|
|
|
|
tool,
|
|
|
|
|
options->pressure_range[0],
|
|
|
|
|
options->pressure_range[1]);
|
2025-06-02 15:11:08 +10:00
|
|
|
if (options->eraser_button_button)
|
2025-07-01 16:30:11 +10:00
|
|
|
libinput_tablet_tool_config_eraser_button_set_button(
|
|
|
|
|
tool,
|
|
|
|
|
options->eraser_button_button);
|
|
|
|
|
libinput_tablet_tool_config_eraser_button_set_mode(tool,
|
|
|
|
|
options->eraser_button_mode);
|
2024-06-07 12:18:40 +10:00
|
|
|
}
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
static char *
|
2017-05-23 15:07:31 +10:00
|
|
|
find_device(const char *udev_tag)
|
|
|
|
|
{
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2020-09-15 10:23:38 +08:00
|
|
|
if (!udev)
|
2025-04-01 13:42:27 +10:00
|
|
|
return NULL;
|
2020-09-15 10:23:38 +08:00
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(udev_enumerate) *e = udev_enumerate_new(udev);
|
2017-05-23 15:07:31 +10:00
|
|
|
udev_enumerate_add_match_subsystem(e, "input");
|
|
|
|
|
udev_enumerate_scan_devices(e);
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
struct udev_list_entry *entry = NULL;
|
2017-05-23 15:07:31 +10:00
|
|
|
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
2025-04-01 13:42:27 +10:00
|
|
|
const char *path = udev_list_entry_get_name(entry);
|
|
|
|
|
_unref_(udev_device) *device = udev_device_new_from_syspath(udev, path);
|
2017-05-23 15:07:31 +10:00
|
|
|
if (!device)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
const char *sysname = udev_device_get_sysname(device);
|
2025-01-09 09:04:54 +10:00
|
|
|
if (!strstartswith("event", sysname)) {
|
2017-05-23 15:07:31 +10:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
if (udev_device_get_property_value(device, udev_tag)) {
|
2025-07-01 16:30:11 +10:00
|
|
|
char *device_node =
|
|
|
|
|
safe_strdup(udev_device_get_devnode(device));
|
2025-04-01 13:42:27 +10:00
|
|
|
if (device_node)
|
|
|
|
|
return device_node;
|
|
|
|
|
}
|
2017-05-23 15:07:31 +10:00
|
|
|
}
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
return NULL;
|
2017-05-23 15:07:31 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
find_touchpad_device(char *path, size_t path_len)
|
|
|
|
|
{
|
2025-04-01 13:42:27 +10:00
|
|
|
_autofree_ char *devnode = find_device("ID_INPUT_TOUCHPAD");
|
2017-05-23 15:07:31 +10:00
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
if (devnode)
|
2017-05-23 15:07:31 +10:00
|
|
|
snprintf(path, path_len, "%s", devnode);
|
|
|
|
|
|
|
|
|
|
return devnode != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
is_touchpad_device(const char *devnode)
|
|
|
|
|
{
|
|
|
|
|
struct stat st;
|
|
|
|
|
if (stat(devnode, &st) < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2020-09-15 10:23:38 +08:00
|
|
|
if (!udev)
|
2025-04-01 13:42:27 +10:00
|
|
|
return false;
|
2020-09-15 10:23:38 +08:00
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(udev_device) *dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
|
2017-05-23 15:07:31 +10:00
|
|
|
if (!dev)
|
2025-04-01 13:42:27 +10:00
|
|
|
return false;
|
2017-05-23 15:07:31 +10:00
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
return udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
|
2017-05-23 15:07:31 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
setup_path(void)
|
|
|
|
|
{
|
|
|
|
|
const char *path = getenv("PATH");
|
|
|
|
|
char new_path[PATH_MAX];
|
2018-07-17 10:12:16 +10:00
|
|
|
const char *extra_path = LIBINPUT_TOOL_PATH;
|
2025-04-01 13:42:27 +10:00
|
|
|
_autofree_ char *builddir = NULL;
|
2017-05-23 15:07:31 +10:00
|
|
|
|
2025-04-03 11:23:34 +10:00
|
|
|
builddir_lookup(&builddir);
|
2017-05-23 15:07:31 +10:00
|
|
|
snprintf(new_path,
|
|
|
|
|
sizeof(new_path),
|
|
|
|
|
"%s:%s",
|
2019-03-06 20:16:41 +10:00
|
|
|
builddir ? builddir : extra_path,
|
2017-05-23 15:07:31 +10:00
|
|
|
path ? path : "");
|
|
|
|
|
setenv("PATH", new_path, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
tools_exec_command(const char *prefix, int real_argc, char **real_argv)
|
|
|
|
|
{
|
2025-07-01 16:30:11 +10:00
|
|
|
char *argv[64] = { NULL };
|
2017-05-23 15:07:31 +10:00
|
|
|
char executable[128];
|
|
|
|
|
const char *command;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
assert((size_t)real_argc < ARRAY_LENGTH(argv));
|
|
|
|
|
|
|
|
|
|
command = real_argv[0];
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
rc = snprintf(executable, sizeof(executable), "%s-%s", prefix, command);
|
2017-05-23 15:07:31 +10:00
|
|
|
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);
|
2017-11-09 15:17:37 +10:00
|
|
|
if (rc) {
|
|
|
|
|
if (errno == ENOENT) {
|
2025-07-01 16:30:11 +10:00
|
|
|
fprintf(stderr, "libinput: %s is not installed\n", command);
|
2018-11-01 09:39:49 +10:00
|
|
|
return EXIT_INVALID_USAGE;
|
2017-11-09 15:17:37 +10:00
|
|
|
}
|
2020-08-27 01:17:24 -07:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Failed to execute '%s' (%s)\n",
|
|
|
|
|
command,
|
|
|
|
|
strerror(errno));
|
2017-11-09 15:17:37 +10:00
|
|
|
}
|
2017-05-23 15:07:31 +10:00
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
2018-06-22 16:37:16 +10:00
|
|
|
|
2018-11-05 13:52:41 +10:00
|
|
|
static void
|
2020-11-10 13:32:26 +10:00
|
|
|
sprintf_event_codes(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
|
2018-11-05 13:52:41 +10:00
|
|
|
{
|
|
|
|
|
const struct quirk_tuples *t;
|
|
|
|
|
size_t off = 0;
|
|
|
|
|
int printed;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
2020-11-10 13:32:26 +10:00
|
|
|
quirks_get_tuples(quirks, q, &t);
|
|
|
|
|
name = quirk_get_name(q);
|
2018-11-05 13:52:41 +10:00
|
|
|
printed = snprintf(buf, sz, "%s=", name);
|
|
|
|
|
assert(printed != -1);
|
|
|
|
|
off += printed;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; off < sz && i < t->ntuples; i++) {
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
unsigned int type = t->tuples[i].first;
|
|
|
|
|
unsigned int code = t->tuples[i].second;
|
|
|
|
|
bool enable = t->tuples[i].third;
|
2018-11-05 13:52:41 +10:00
|
|
|
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
const char *name = libevdev_event_code_get_name(type, code);
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
printed = snprintf(buf + off,
|
|
|
|
|
sz - off,
|
|
|
|
|
"%c%s;",
|
|
|
|
|
enable ? '+' : '-',
|
|
|
|
|
name);
|
2018-11-05 13:52:41 +10:00
|
|
|
assert(printed != -1);
|
|
|
|
|
off += printed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 13:32:26 +10:00
|
|
|
static void
|
|
|
|
|
sprintf_input_props(char *buf, size_t sz, struct quirks *quirks, enum quirk q)
|
|
|
|
|
{
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
const struct quirk_tuples *t;
|
2020-11-10 13:32:26 +10:00
|
|
|
size_t off = 0;
|
|
|
|
|
int printed;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
quirks_get_tuples(quirks, q, &t);
|
2020-11-10 13:32:26 +10:00
|
|
|
name = quirk_get_name(q);
|
|
|
|
|
printed = snprintf(buf, sz, "%s=", name);
|
|
|
|
|
assert(printed != -1);
|
|
|
|
|
off += printed;
|
|
|
|
|
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
for (size_t i = 0; off < sz && i < t->ntuples; i++) {
|
|
|
|
|
unsigned int prop = t->tuples[i].first;
|
|
|
|
|
bool enable = t->tuples[i].second;
|
|
|
|
|
|
|
|
|
|
const char *name = libevdev_property_get_name(prop);
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
printed = snprintf(buf + off,
|
|
|
|
|
sz - off,
|
|
|
|
|
"%c%s;",
|
|
|
|
|
enable ? '+' : '-',
|
|
|
|
|
name);
|
2020-11-10 13:32:26 +10:00
|
|
|
assert(printed != -1);
|
|
|
|
|
off += printed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 16:37:16 +10:00
|
|
|
void
|
|
|
|
|
tools_list_device_quirks(struct quirks_context *ctx,
|
|
|
|
|
struct udev_device *device,
|
|
|
|
|
void (*callback)(void *data, const char *str),
|
|
|
|
|
void *userdata)
|
|
|
|
|
{
|
|
|
|
|
char buf[256];
|
|
|
|
|
|
2018-09-18 10:35:51 +10:00
|
|
|
enum quirk q;
|
2018-06-22 16:37:16 +10:00
|
|
|
|
2025-04-01 13:42:27 +10:00
|
|
|
_unref_(quirks) *quirks = quirks_fetch_for_device(ctx, device);
|
2018-06-22 16:37:16 +10:00
|
|
|
if (!quirks)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-27 15:27:46 +10:00
|
|
|
q = QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD;
|
2018-09-18 10:35:51 +10:00
|
|
|
do {
|
|
|
|
|
if (quirks_has_quirk(quirks, q)) {
|
|
|
|
|
const char *name;
|
2020-04-06 23:48:20 +02:00
|
|
|
bool b;
|
2018-06-22 16:37:16 +10:00
|
|
|
|
2018-09-18 10:35:51 +10:00
|
|
|
name = quirk_get_name(q);
|
2020-04-06 23:48:20 +02:00
|
|
|
quirks_get_bool(quirks, q, &b);
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s=%d", name, b ? 1 : 0);
|
2018-08-17 15:12:58 +02:00
|
|
|
callback(userdata, buf);
|
2018-06-22 16:37:16 +10:00
|
|
|
}
|
2025-07-01 16:30:11 +10:00
|
|
|
} while (++q < _QUIRK_LAST_MODEL_QUIRK_);
|
2018-09-18 10:35:51 +10:00
|
|
|
|
|
|
|
|
q = QUIRK_ATTR_SIZE_HINT;
|
|
|
|
|
do {
|
|
|
|
|
if (quirks_has_quirk(quirks, q)) {
|
|
|
|
|
const char *name;
|
|
|
|
|
struct quirk_dimensions dim;
|
|
|
|
|
struct quirk_range r;
|
|
|
|
|
uint32_t v;
|
|
|
|
|
char *s;
|
|
|
|
|
double d;
|
2022-01-15 13:45:48 +01:00
|
|
|
bool b;
|
2018-09-18 10:35:51 +10:00
|
|
|
|
|
|
|
|
name = quirk_get_name(q);
|
|
|
|
|
|
|
|
|
|
switch (q) {
|
|
|
|
|
case QUIRK_ATTR_SIZE_HINT:
|
|
|
|
|
case QUIRK_ATTR_RESOLUTION_HINT:
|
|
|
|
|
quirks_get_dimensions(quirks, q, &dim);
|
2025-07-01 16:30:11 +10:00
|
|
|
snprintf(buf,
|
|
|
|
|
sizeof(buf),
|
|
|
|
|
"%s=%zdx%zd",
|
|
|
|
|
name,
|
|
|
|
|
dim.x,
|
|
|
|
|
dim.y);
|
2018-09-18 10:35:51 +10:00
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
|
|
|
|
case QUIRK_ATTR_TOUCH_SIZE_RANGE:
|
|
|
|
|
case QUIRK_ATTR_PRESSURE_RANGE:
|
|
|
|
|
quirks_get_range(quirks, q, &r);
|
2025-07-01 16:30:11 +10:00
|
|
|
snprintf(buf,
|
|
|
|
|
sizeof(buf),
|
|
|
|
|
"%s=%d:%d",
|
|
|
|
|
name,
|
|
|
|
|
r.upper,
|
|
|
|
|
r.lower);
|
2018-09-18 10:35:51 +10:00
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
|
|
|
|
case QUIRK_ATTR_PALM_SIZE_THRESHOLD:
|
|
|
|
|
case QUIRK_ATTR_PALM_PRESSURE_THRESHOLD:
|
|
|
|
|
case QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD:
|
|
|
|
|
case QUIRK_ATTR_THUMB_SIZE_THRESHOLD:
|
|
|
|
|
quirks_get_uint32(quirks, q, &v);
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s=%u", name, v);
|
|
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
|
|
|
|
case QUIRK_ATTR_LID_SWITCH_RELIABILITY:
|
|
|
|
|
case QUIRK_ATTR_KEYBOARD_INTEGRATION:
|
2020-01-15 14:09:50 +10:00
|
|
|
case QUIRK_ATTR_TRACKPOINT_INTEGRATION:
|
2018-09-18 10:35:51 +10:00
|
|
|
case QUIRK_ATTR_TPKBCOMBO_LAYOUT:
|
|
|
|
|
case QUIRK_ATTR_MSC_TIMESTAMP:
|
|
|
|
|
quirks_get_string(quirks, q, &s);
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s=%s", name, s);
|
|
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
|
|
|
|
case QUIRK_ATTR_TRACKPOINT_MULTIPLIER:
|
|
|
|
|
quirks_get_double(quirks, q, &d);
|
2018-11-05 14:12:00 +10:00
|
|
|
snprintf(buf, sizeof(buf), "%s=%0.2f", name, d);
|
2018-09-18 10:35:51 +10:00
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
|
|
|
|
case QUIRK_ATTR_USE_VELOCITY_AVERAGING:
|
2021-07-25 19:23:06 -07:00
|
|
|
case QUIRK_ATTR_TABLET_SMOOTHING:
|
2025-07-29 10:37:28 +10:00
|
|
|
case QUIRK_ATTR_IS_VIRTUAL:
|
2022-01-15 13:45:48 +01:00
|
|
|
quirks_get_bool(quirks, q, &b);
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s=%d", name, b);
|
2018-09-18 10:35:51 +10:00
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
case QUIRK_ATTR_EVENT_CODE:
|
2020-11-10 13:32:26 +10:00
|
|
|
sprintf_event_codes(buf, sizeof(buf), quirks, q);
|
|
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
quirks: allow overriding of AttrEventCode and AttrInputProp
This switches the quirk from AttrEventCodeEnable/Disable to just
AttrEventCode with a +/- prefix for each entry.
This switches the quirk from AttrInputPropEnable/Disable to just
AttrInputProp with a +/- prefix for each entry.
Previously, both event codes and input props would only apply the
last-matching section entry for a device. Furthermore, an earlier Disable entry
would take precedence over a later Enable entry. For example, a set of
sections with these lines *should* enable left, right and middle:
[first]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;BTN_MIDDLE
[second]
AttrEventCodeDisable=BTN_RIGHT
[third]
AttrEventCodeEnable=BTN_LEFT;BTN_RIGHT;
Alas: the first line was effectively ignored (quirks only returned the
last-matching one, i.e. the one from "third"). And due to implementation
details in evdev.c, the Disable attribute was processed after Enable,
i.e. the device was enabled for left + right and then disabled for
right. As a result, the device only had BTN_LEFT enabled.
Fix this by changing the attribute to carry both enable/disable
information and merging the commands together.
Internally, all quirks matching a device are simply ref'd into an array
in the struct quirks. The applied value is simply the last entry in the
array corresponding to our quirk.
For AttrEventCode and AttrInputProp instead do this:
- switch them to a tuple with the code as first entry and a boolean
enable/disable as second entry
- if the struct quirk already has an entry for either, append the more
recent one to the existing entry (instead of creating a new entry in
the array). This way we have all entries that match and in-order of
precedence - i.e. we can process them left-to-right to end up
with the right state.
Fixes: https://gitlab.freedesktop.org/libinput/libinput/-/issues/821
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-11-15 13:53:43 +10:00
|
|
|
case QUIRK_ATTR_INPUT_PROP:
|
2020-11-10 13:32:26 +10:00
|
|
|
sprintf_input_props(buf, sizeof(buf), quirks, q);
|
2018-11-05 13:52:41 +10:00
|
|
|
callback(userdata, buf);
|
|
|
|
|
break;
|
2018-09-18 10:35:51 +10:00
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-01 16:30:11 +10:00
|
|
|
} while (++q < _QUIRK_LAST_ATTR_QUIRK_);
|
2018-06-22 16:37:16 +10:00
|
|
|
}
|