From 1725b7d60659a605db14b893e85a93b63f242e4d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 7 Jun 2024 12:18:40 +1000 Subject: [PATCH] Add support for --set-pressure-range to the debugging tools Part-of: --- tools/libinput-debug-events.c | 8 +++++++- tools/libinput-debug-events.man | 3 +++ tools/libinput-debug-gui.c | 2 ++ tools/libinput-debug-tablet.c | 8 +++++++- tools/shared.c | 28 ++++++++++++++++++++++++++++ tools/shared.h | 7 ++++++- 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index 6230b18f..6e92faee 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -940,9 +940,15 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_TOOL_AXIS: print_tablet_axis_event(ev); break; - case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: { + struct libinput_event_tablet_tool *tev = + libinput_event_get_tablet_tool_event(ev); + struct libinput_tablet_tool *tool = + libinput_event_tablet_tool_get_tool(tev); + tools_tablet_tool_apply_config(tool, &options); print_proximity_event(ev); break; + } case LIBINPUT_EVENT_TABLET_TOOL_TIP: print_tablet_tip_event(ev); break; diff --git a/tools/libinput-debug-events.man b/tools/libinput-debug-events.man index 380312dd..e602edec 100644 --- a/tools/libinput-debug-events.man +++ b/tools/libinput-debug-events.man @@ -125,6 +125,9 @@ Set button mapping for tapping .TP 8 .B \-\-set\-rotation\-angle= Set the rotation angle in degrees (0 to 360). +.TP 8 +.B \-\-set\-pressure\-range=: +Set the tablet tool pressure range to min:max. min and max must be in range [0.0, 1.0]. .SH NOTES .PP Events shown by this tool may not correspond to the events seen by a diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index 4618f49d..fc7b799e 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -1655,6 +1655,7 @@ static void handle_event_tablet(struct libinput_event *ev, struct window *w) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); + struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); double x, y; struct point point; int idx; @@ -1667,6 +1668,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + tools_tablet_tool_apply_config(tool, &w->options); if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { w->tool.x_in = 0; diff --git a/tools/libinput-debug-tablet.c b/tools/libinput-debug-tablet.c index 6666530b..78cc3fec 100644 --- a/tools/libinput-debug-tablet.c +++ b/tools/libinput-debug-tablet.c @@ -381,9 +381,15 @@ handle_libinput_events(struct context *ctx) case LIBINPUT_EVENT_TABLET_TOOL_AXIS: handle_tablet_axis_event(ctx, ev); break; - case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: { + struct libinput_event_tablet_tool *tev = + libinput_event_get_tablet_tool_event(ev); + struct libinput_tablet_tool *tool = + libinput_event_tablet_tool_get_tool(tev); + tools_tablet_tool_apply_config(tool, &options); handle_tablet_proximity_event(ctx, ev); break; + } case LIBINPUT_EVENT_TABLET_TOOL_TIP: handle_tablet_tip_event(ctx, ev); break; diff --git a/tools/shared.c b/tools/shared.c index d8acadcf..9da4bc74 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -120,6 +120,8 @@ tools_init_options(struct tools_options *options) options->custom_npoints = ARRAY_LENGTH(points); options->custom_type = LIBINPUT_ACCEL_TYPE_FALLBACK; options->custom_step = 1.0; + options->pressure_range[0] = 0.0; + options->pressure_range[1] = 1.0; } int @@ -335,6 +337,23 @@ tools_parse_option(int option, fprintf(stderr, "Invalid --set-rotation-angle value\n"); return 1; } + break; + case OPT_PRESSURE_RANGE: { + if (!optarg) + return 1; + + size_t npoints = 0; + double *range = double_array_from_string(optarg, ":", &npoints); + if (npoints != 2 || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) { + free(range); + fprintf(stderr, "Invalid pressure range, must be in format \"min:max\"\n"); + return 1; + } + options->pressure_range[0] = range[0]; + options->pressure_range[1] = range[1]; + free(range); + break; + } } return 0; } @@ -549,6 +568,15 @@ tools_device_apply_config(struct libinput_device *device, libinput_device_config_rotation_set_angle(device, options->angle % 360); } +void +tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool, + struct tools_options *options) +{ + libinput_tablet_tool_config_pressure_range_set(tool, + options->pressure_range[0], + options->pressure_range[1]); +} + static char* find_device(const char *udev_tag) { diff --git a/tools/shared.h b/tools/shared.h index a34e67bb..585e5540 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -64,6 +64,7 @@ enum configuration_options { OPT_CUSTOM_STEP, OPT_CUSTOM_TYPE, OPT_ROTATION_ANGLE, + OPT_PRESSURE_RANGE, }; #define CONFIGURATION_OPTIONS \ @@ -97,7 +98,8 @@ enum configuration_options { { "set-custom-points", required_argument, 0, OPT_CUSTOM_POINTS },\ { "set-custom-step", required_argument, 0, OPT_CUSTOM_STEP },\ { "set-custom-type", required_argument, 0, OPT_CUSTOM_TYPE },\ - { "set-rotation-angle", required_argument, 0, OPT_ROTATION_ANGLE } + { "set-rotation-angle", required_argument, 0, OPT_ROTATION_ANGLE }, \ + { "set-pressure-range", required_argument, 0, OPT_PRESSURE_RANGE } enum tools_backend { BACKEND_NONE, @@ -130,6 +132,7 @@ struct tools_options { size_t custom_npoints; double *custom_points; unsigned int angle; + double pressure_range[2]; }; void tools_init_options(struct tools_options *options); @@ -142,6 +145,8 @@ struct libinput* tools_open_backend(enum tools_backend which, bool *grab); void tools_device_apply_config(struct libinput_device *device, struct tools_options *options); +void tools_tablet_tool_apply_config(struct libinput_tablet_tool *tool, + struct tools_options *options); int tools_exec_command(const char *prefix, int argc, char **argv); bool find_touchpad_device(char *path, size_t path_len);