Implement ratbag_button_has_action_type

etekcity suppports macros already, the other two don't. hidpp10 doesn't
support any write stuff but let's claim we do anyway.

The driver hook for this isn't ideal, read_button is called during init but
we should set all this up during probe and then use read_button exclusively to
update the button, not set the capabilities as well.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2015-09-02 10:07:24 +10:00
parent 0d4a7486de
commit c01c37fcbf
7 changed files with 40 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@@ -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)
{

View File

@@ -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)
{

View File

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

View File

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