mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2026-05-05 07:38:02 +02:00
tools: change touchpad-edge-detector to require physical size
Almost no-one does the calculations for me to update the udev rules (and some rules were submitted with the <x resolution> placeholders left in). Require the user to specify the physical size so we just copy/paste the actual udev rule. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
4dd93f0108
commit
911106230a
2 changed files with 34 additions and 17 deletions
|
|
@ -66,6 +66,8 @@ if test "x$lt_cv_prog_gnu_ld" = "xyes"; then
|
||||||
fi
|
fi
|
||||||
AC_SUBST([GNU_LD_FLAGS], $with_ldflags)
|
AC_SUBST([GNU_LD_FLAGS], $with_ldflags)
|
||||||
|
|
||||||
|
AC_CHECK_LIB([m], [round])
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG()
|
PKG_PROG_PKG_CONFIG()
|
||||||
PKG_CHECK_MODULES(CHECK, [check >= 0.9.9], [HAVE_CHECK="yes"], [HAVE_CHECK="no"])
|
PKG_CHECK_MODULES(CHECK, [check >= 0.9.9], [HAVE_CHECK="yes"], [HAVE_CHECK="no"])
|
||||||
if test "x$HAVE_CHECK" = "xyes"; then
|
if test "x$HAVE_CHECK" = "xyes"; then
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <math.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -43,10 +44,11 @@
|
||||||
|
|
||||||
static int
|
static int
|
||||||
usage(void) {
|
usage(void) {
|
||||||
printf("Usage: %s /dev/input/event0\n", program_invocation_short_name);
|
printf("Usage: %s 12x34 /dev/input/event0\n", program_invocation_short_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("This tool reads the touchpad events from the kernel and calculates\n "
|
printf("This tool reads the touchpad events from the kernel and calculates\n "
|
||||||
"the minimum and maximum for the x and y coordinates, respectively.\n");
|
"the minimum and maximum for the x and y coordinates, respectively.\n"
|
||||||
|
"The first argument is the physical size of the touchpad in mm.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,6 +56,10 @@ struct dimensions {
|
||||||
int top, bottom, left, right;
|
int top, bottom, left, right;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct size {
|
||||||
|
int w, h;
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
print_current_values(const struct dimensions *d)
|
print_current_values(const struct dimensions *d)
|
||||||
{
|
{
|
||||||
|
|
@ -168,15 +174,20 @@ dmi_matchstr(struct libevdev *dev, char *match, size_t sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_udev_override_rule(struct libevdev *dev, const struct dimensions *dim) {
|
print_udev_override_rule(struct libevdev *dev,
|
||||||
|
const struct dimensions *dim,
|
||||||
|
const struct size *size) {
|
||||||
const struct input_absinfo *x, *y;
|
const struct input_absinfo *x, *y;
|
||||||
char match[PATH_MAX];
|
char match[PATH_MAX];
|
||||||
int w, h;
|
int w, h;
|
||||||
|
int xres, yres;
|
||||||
|
|
||||||
x = libevdev_get_abs_info(dev, ABS_X);
|
x = libevdev_get_abs_info(dev, ABS_X);
|
||||||
y = libevdev_get_abs_info(dev, ABS_Y);
|
y = libevdev_get_abs_info(dev, ABS_Y);
|
||||||
w = x->maximum - x->minimum;
|
w = x->maximum - x->minimum;
|
||||||
h = y->maximum - y->minimum;
|
h = y->maximum - y->minimum;
|
||||||
|
xres = round((double)w/size->w);
|
||||||
|
yres = round((double)h/size->h);
|
||||||
|
|
||||||
if (x->resolution && y->resolution) {
|
if (x->resolution && y->resolution) {
|
||||||
printf("Touchpad size as listed by the kernel: %dx%dmm\n",
|
printf("Touchpad size as listed by the kernel: %dx%dmm\n",
|
||||||
|
|
@ -185,9 +196,8 @@ print_udev_override_rule(struct libevdev *dev, const struct dimensions *dim) {
|
||||||
printf("Touchpad has no resolution, size unknown\n");
|
printf("Touchpad has no resolution, size unknown\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Calculate resolution as:\n");
|
printf("User-specified touchpad size: %dx%dmm\n", size->w, size->h);
|
||||||
printf(" x axis: %d/<width in mm>\n", w);
|
printf("Calculated ranges: %d/%d\n", w, h);
|
||||||
printf(" y axis: %d/<height in mm>\n", h);
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Suggested udev rule:\n");
|
printf("Suggested udev rule:\n");
|
||||||
|
|
||||||
|
|
@ -203,16 +213,16 @@ print_udev_override_rule(struct libevdev *dev, const struct dimensions *dim) {
|
||||||
|
|
||||||
printf("# <Laptop model description goes here>\n"
|
printf("# <Laptop model description goes here>\n"
|
||||||
"evdev:%s*\n"
|
"evdev:%s*\n"
|
||||||
" EVDEV_ABS_00=%d:%d:<x resolution>\n"
|
" EVDEV_ABS_00=%d:%d:%d\n"
|
||||||
" EVDEV_ABS_01=%d:%d:<y resolution>\n",
|
" EVDEV_ABS_01=%d:%d:%d\n",
|
||||||
match,
|
match,
|
||||||
dim->left, dim->right,
|
dim->left, dim->right, xres,
|
||||||
dim->top, dim->bottom);
|
dim->top, dim->bottom, yres);
|
||||||
if (libevdev_has_event_code(dev, EV_ABS, ABS_MT_POSITION_X))
|
if (libevdev_has_event_code(dev, EV_ABS, ABS_MT_POSITION_X))
|
||||||
printf(" EVDEV_ABS_35=%d:%d:<x resolution>\n"
|
printf(" EVDEV_ABS_35=%d:%d:%d\n"
|
||||||
" EVDEV_ABS_36=%d:%d:<y resolution>\n",
|
" EVDEV_ABS_36=%d:%d:%d\n",
|
||||||
dim->left, dim->right,
|
dim->left, dim->right, xres,
|
||||||
dim->top, dim->bottom);
|
dim->top, dim->bottom, yres);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv) {
|
int main (int argc, char **argv) {
|
||||||
|
|
@ -221,11 +231,16 @@ int main (int argc, char **argv) {
|
||||||
const char *path;
|
const char *path;
|
||||||
struct libevdev *dev;
|
struct libevdev *dev;
|
||||||
struct dimensions dim;
|
struct dimensions dim;
|
||||||
|
struct size size;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 3)
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
path = argv[1];
|
if (sscanf(argv[1], "%dx%d", &size.w, &size.h) != 2 ||
|
||||||
|
size.w <= 0 || size.h <= 0)
|
||||||
|
return usage();
|
||||||
|
|
||||||
|
path = argv[2];
|
||||||
if (path[0] == '-')
|
if (path[0] == '-')
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
|
|
@ -273,7 +288,7 @@ int main (int argc, char **argv) {
|
||||||
rc = mainloop(dev, &dim);
|
rc = mainloop(dev, &dim);
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
|
||||||
print_udev_override_rule(dev, &dim);
|
print_udev_override_rule(dev, &dim, &size);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
libevdev_free(dev);
|
libevdev_free(dev);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue