input: support tablet tool pressure range configuration

Needs a wlroots addition to expose libinputs tablet tool handle...
This commit is contained in:
Jens Peters 2025-07-13 21:38:00 +02:00
parent aa672215b1
commit c093ac47db
No known key found for this signature in database
3 changed files with 33 additions and 0 deletions

View file

@ -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 */

View file

@ -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;

View file

@ -2,11 +2,13 @@
#include "input/tablet.h"
#include <stdlib.h>
#include <linux/input-event-codes.h>
#include "wlr/backend/libinput.h"
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_v2.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#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