From c093ac47db77724da008bce2b082cd41dd94442c Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Sun, 13 Jul 2025 21:38:00 +0200 Subject: [PATCH] input: support tablet tool pressure range configuration Needs a wlroots addition to expose libinputs tablet tool handle... --- include/config/rcxml.h | 2 ++ src/config/rcxml.c | 8 ++++++++ src/input/tablet.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 6036be9c..39623f10 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -139,6 +139,8 @@ struct rcxml { struct tablet_tool_config { enum lab_motion motion; double relative_motion_sensitivity; + double min_pressure; + double max_pressure; } tablet_tool; /* libinput */ diff --git a/src/config/rcxml.c b/src/config/rcxml.c index c1b73c35..4d45917a 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -1353,6 +1353,12 @@ entry(xmlNode *node, char *nodename, char *content) } else if (!strcasecmp(nodename, "relativeMotionSensitivity.tabletTool")) { rc.tablet_tool.relative_motion_sensitivity = tablet_get_dbl_if_positive(content, "relativeMotionSensitivity"); + } else if (!strcasecmp(nodename, "minPressure.tabletTool")) { + rc.tablet_tool.min_pressure = + tablet_get_dbl_if_positive(content, "minPressure"); + } else if (!strcasecmp(nodename, "maxPressure.tabletTool")) { + rc.tablet_tool.max_pressure = + tablet_get_dbl_if_positive(content, "maxPressure"); } else if (!strcasecmp(nodename, "ignoreButtonReleasePeriod.menu")) { rc.menu_ignore_button_release_period = atoi(content); } else if (!strcasecmp(nodename, "showIcons.menu")) { @@ -1473,6 +1479,8 @@ rcxml_init(void) tablet_load_default_button_mappings(); rc.tablet_tool.motion = LAB_MOTION_ABSOLUTE; rc.tablet_tool.relative_motion_sensitivity = 1.0; + rc.tablet_tool.min_pressure = 0.0; + rc.tablet_tool.max_pressure = 1.0; rc.repeat_rate = 25; rc.repeat_delay = 600; diff --git a/src/input/tablet.c b/src/input/tablet.c index 319c06b3..a2228a66 100644 --- a/src/input/tablet.c +++ b/src/input/tablet.c @@ -2,11 +2,13 @@ #include "input/tablet.h" #include #include +#include "wlr/backend/libinput.h" #include #include #include #include #include +#include #include "common/macros.h" #include "common/mem.h" #include "common/scene-helpers.h" @@ -336,6 +338,27 @@ handle_tablet_tool_proximity(struct wl_listener *listener, void *data) tool = tablet_tool_create(tablet->seat, ev->tool); } + struct libinput_tablet_tool *libinput_tool = + wlr_libinput_get_tablet_tool_handle(tool->tool_v2->wlr_tool); + + /* + * Configure tool pressure range using libinput. Note that a runtime change + * needs two proximity-in events. First one is for applying the pressure range + * here and second one until it is effectively applied, probably because of + * how lininput applies pressure range changes internally. + */ + if (libinput_tablet_tool_config_pressure_range_is_available(libinput_tool) > 0 + && rc.tablet_tool.min_pressure >= 0.0 + && rc.tablet_tool.max_pressure <= 1.0) { + double min = libinput_tablet_tool_config_pressure_range_get_minimum(libinput_tool); + double max = libinput_tablet_tool_config_pressure_range_get_maximum(libinput_tool); + if (min != rc.tablet_tool.min_pressure || max != rc.tablet_tool.max_pressure) { + wlr_log(WLR_INFO, "tablet tool pressure range configured"); + libinput_tablet_tool_config_pressure_range_set(libinput_tool, + rc.tablet_tool.min_pressure, rc.tablet_tool.max_pressure); + } + } + /* * Enforce mouse emulation when the current tool is a tablet mouse. * Client support for tablet mouses in tablet mode is often incomplete