diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index 05d66735..017cd782 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -588,6 +588,11 @@ etekcity_read_button(struct ratbag_button *button) if (action) button->action = *action; button->type = etekcity_raw_to_button_type(button->index); + + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO); } static int diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index ec59f106..3d6a615f 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -79,6 +79,10 @@ hidpp10drv_read_button(struct ratbag_button *button) } button->type = type; + + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL); } static int diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 6ea2ccb8..4e9ad5e3 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -89,6 +89,10 @@ hidpp20drv_read_button(struct ratbag_button *button) action = hidpp20_1b04_get_logical_mapping(mapping); if (action) button->action = *action; + + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY); + ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL); } static int diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 3bb92ce7..9ccbe1f5 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -242,8 +242,16 @@ struct ratbag_button { unsigned index; enum ratbag_button_type type; struct ratbag_button_action action; + uint32_t action_caps; }; +static inline void +ratbag_button_enable_action_type(struct ratbag_button *button, + enum ratbag_button_action_type type) +{ + button->action_caps |= 1 << type; +} + static inline int ratbag_open_path(struct ratbag_device *device, const char *path, int flags) { diff --git a/src/libratbag.c b/src/libratbag.c index 06e10e07..dc81b2e8 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -893,6 +893,23 @@ ratbag_button_get_action_type(struct ratbag_button *button) return button->action.type; } +LIBRATBAG_EXPORT int +ratbag_button_has_action_type(struct ratbag_button *button, + enum ratbag_button_action_type action_type) +{ + switch (action_type) { + case RATBAG_BUTTON_ACTION_TYPE_BUTTON: + case RATBAG_BUTTON_ACTION_TYPE_SPECIAL: + case RATBAG_BUTTON_ACTION_TYPE_KEY: + case RATBAG_BUTTON_ACTION_TYPE_MACRO: + break; + default: + return 0; + } + + return !!(button->action_caps & (1 << action_type)); +} + LIBRATBAG_EXPORT unsigned int ratbag_button_get_button(struct ratbag_button *button) { diff --git a/src/libratbag.h b/src/libratbag.h index ccf5aa50..3fb23885 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -1046,7 +1046,7 @@ ratbag_button_get_action_type(struct ratbag_button *button); * * @note It is a client bug to pass in @ref * RATBAG_BUTTON_ACTION_TYPE_UNKNOWN or @ref - * RATBAG_BUTTON_ACTION_TYPE_UNKNOWN. + * RATBAG_BUTTON_ACTION_TYPE_NONE. * * @param button A previously initialized button * @param action_type An action type diff --git a/src/libratbag.sym b/src/libratbag.sym index 08d28dda..1d689a78 100644 --- a/src/libratbag.sym +++ b/src/libratbag.sym @@ -10,6 +10,7 @@ global: ratbag_button_get_key; ratbag_button_get_special; ratbag_button_get_user_data; + ratbag_button_has_action_type; ratbag_button_ref; ratbag_button_set_button; ratbag_button_set_key;