1
0
forked from drath/libratbag

Factor out ratbag_button_action_match

This will be used often in drivers, so let's have a helper for it.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-08-26 16:55:29 -04:00
parent 08a568aed2
commit 6bc44f4d5f
3 changed files with 25 additions and 36 deletions

View File

@@ -197,25 +197,8 @@ etekcity_button_action_to_raw(const struct ratbag_button_action *action)
struct etekcity_button_mapping *mapping;
ARRAY_FOR_EACH(etekcity_button_mapping, mapping) {
if (mapping->action.type == action->type) {
switch (action->type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
if (mapping->action.action.button != action->action.button)
continue;
break;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
if (mapping->action.action.key.key != action->action.key.key)
continue;
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
if (mapping->action.action.special != action->action.special)
continue;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
/* FIXME: currently, do nothing */
default: /* do nothing, we are good */
break;
}
if (ratbag_button_action_match(&mapping->action, action))
return mapping->raw;
}
}
return 0;

View File

@@ -577,25 +577,8 @@ hidpp20_1b04_get_logical_control_id(const struct ratbag_button_action *action)
const struct hidpp20_1b04_action_mapping *mapping;
ARRAY_FOR_EACH(hidpp20_1b04_logical_mapping, mapping) {
if (mapping->action.type == action->type) {
switch (action->type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
if (mapping->action.action.button != action->action.button)
continue;
break;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
if (mapping->action.action.key.key != action->action.key.key)
continue;
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
if (mapping->action.action.special != action->action.special)
continue;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
/* FIXME: currently, do nothing */
default: /* do nothing, we are good */
break;
}
if (ratbag_button_action_match(&mapping->action, action))
return mapping->value;
}
}
return 0;

View File

@@ -270,6 +270,29 @@ ratbag_profile_get_drv_data(struct ratbag_profile *profile)
return profile->drv_data;
}
static inline int
ratbag_button_action_match(const struct ratbag_button_action *action,
const struct ratbag_button_action *match)
{
if (action->type != match->type)
return 0;
switch (action->type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
return match->action.button == action->action.button;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
return match->action.key.key == action->action.key.key;
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
return match->action.special != action->action.special;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
/* FIXME: currently, do nothing */
default:
break;
}
return 0;
}
/**
* Override the auto-picked hidraw device.
*/