tablet: always allow BTN_STYLUS* for eraser button configuration

If the button we want to map to isn't enabled by the kernel allow
setting the button nonetheless. On some tablets we only get the
actual number of button codes (e.g. BTN_STYLUS only on an Inspiroy 2S)
so not being able to map the eraser button to some other button makes
this whole feature a bit pointless.

Special-case BTN_STYLUS* because these are the ones we'll always allow.

This fixes an issue with the eraser button defaulting to BTN_STYLUS2
on some devices but it couldn't actually be set to that value by the
caller.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1231>
This commit is contained in:
Peter Hutterer 2025-06-19 10:04:21 +10:00 committed by Marge Bot
parent 34da27650d
commit 56f0524115
3 changed files with 15 additions and 5 deletions

View file

@ -1332,9 +1332,6 @@ eraser_button_get_default_mode(struct libinput_tablet_tool *tool)
static enum libinput_config_status
eraser_button_set_button(struct libinput_tablet_tool *tool, uint32_t button)
{
if (!libinput_tablet_tool_has_button(tool, button))
return LIBINPUT_CONFIG_STATUS_INVALID;
switch (button) {
case BTN_STYLUS:
case BTN_STYLUS2:

View file

@ -5109,8 +5109,16 @@ libinput_tablet_tool_config_eraser_button_set_button(struct libinput_tablet_tool
if (!libinput_tablet_tool_config_eraser_button_get_modes(tool))
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
if (!libinput_tablet_tool_has_button(tool, button))
return LIBINPUT_CONFIG_STATUS_INVALID;
switch (button) {
case BTN_STYLUS:
case BTN_STYLUS2:
case BTN_STYLUS3:
break;
default:
if (!libinput_tablet_tool_has_button(tool, button))
return LIBINPUT_CONFIG_STATUS_INVALID;
break;
}
return tool->config.eraser_button.set_button(tool, button);
}

View file

@ -7106,6 +7106,11 @@ libinput_tablet_tool_config_eraser_button_get_default_mode(struct libinput_table
* the eraser mode to @ref LIBINPUT_CONFIG_ERASER_BUTTON_BUTTON via
* libinput_tablet_tool_config_eraser_button_set_mode().
*
* The buttons BTN_STYLUS, BTN_STYLUS2 and BTN_STYLUS2 are always
* allowed, even if libinput_tablet_tool_has_button() returns zero
* for the button. Otherwise, the button must be one that
* libinput_tablet_tool_has_button() returns a nonzero value for.
*
* @param tool The libinput tool
* @param button The button, usually one of BTN_STYLUS, BTN_STYLUS2 or
* BTN_STYLUS3