From d7cd776faf7b9b083ff916b82d52f6d66340e932 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 19 Aug 2015 14:14:01 -0400 Subject: [PATCH] Add a ratbag_button_set_type This might not be part of the final API, but it is rather convenient to use right now. Signed-off-by: Benjamin Tissoires --- src/libratbag.c | 16 ++++++++++++++++ src/libratbag.h | 15 +++++++++++++++ src/libratbag.sym | 1 + 3 files changed, 32 insertions(+) diff --git a/src/libratbag.c b/src/libratbag.c index d47eb527..e56cb18d 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -609,6 +609,22 @@ ratbag_button_get_type(struct ratbag_button *button) return button->type; } +LIBRATBAG_EXPORT int +ratbag_button_set_type(struct ratbag_button *button, enum ratbag_button_type type) +{ + enum ratbag_button_type orig_type = button->type; + int rc; + + if (!button->device->driver->write_button) + return -ENOTSUP; + + button->type = type; + rc = button->device->driver->write_button(button->device, button->profile, button); + if (rc) + button->type = orig_type; + return rc; +} + LIBRATBAG_EXPORT struct ratbag_button * ratbag_button_ref(struct ratbag_button *button) { diff --git a/src/libratbag.h b/src/libratbag.h index 9b86f025..22b4726b 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -521,6 +521,21 @@ enum ratbag_button_type { enum ratbag_button_type ratbag_button_get_type(struct ratbag_button *button); +/** + * @ingroup device + * + * Change the type of the physical button. This function is intended to be + * used by configuration tools to configure devices. + * + * FIXME: if we do this with linux/input.h instead, we need to add things like + * BTN_RESOLUTION_UP/DOWN there. But this is supposed to describe the + * physical location of the button, so input.h is not a good match. + * + * @return The error code or 0 on success. + */ +int +ratbag_button_set_type(struct ratbag_button *button, enum ratbag_button_type type); + /** * @ingroup device * diff --git a/src/libratbag.sym b/src/libratbag.sym index 41a6e88b..69428bf6 100644 --- a/src/libratbag.sym +++ b/src/libratbag.sym @@ -5,6 +5,7 @@ global: ratbag_create_context; ratbag_button_ref; ratbag_button_get_type; + ratbag_button_set_type; ratbag_button_unref; ratbag_device_unref; ratbag_device_get_active_profile;