From 0eb6bd394810caac74e912032bf57d7582338617 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 21 Aug 2015 15:23:14 -0400 Subject: [PATCH] hidpp: fill the ratbag_button info We still need to differentiate logical from physical in button types. Signed-off-by: Benjamin Tissoires --- src/driver-hidpp20.c | 32 ++++++++++++++++++ src/hidpp20.c | 80 +++++++++++++++++++++++++++++++------------- src/hidpp20.h | 12 +++---- 3 files changed, 94 insertions(+), 30 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index a00dc44b..d64ffb4d 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -61,9 +61,39 @@ struct hidpp20drv_data { struct hidpp20_control_id *controls; }; +static enum ratbag_button_action_type +hidpp20drv_raw_to_action(enum ratbag_button_type button_type) +{ + if (button_type == RATBAG_BUTTON_TYPE_UNKNOWN) + return RATBAG_BUTTON_ACTION_TYPE_NONE; + + return RATBAG_BUTTON_ACTION_TYPE_BUTTON; +} + static void hidpp20drv_read_button(struct ratbag_button *button) { + struct ratbag_device *device = button->device; + struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device); + struct hidpp20_control_id *control; + uint16_t mapping; + + if (!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04)) + return; + + control = &drv_data->controls[button->index]; + mapping = control->task_id; + if (control->reporting.divert || control->reporting.persist) + mapping = control->reporting.remapped; + log_debug(device->ratbag, + " - button%d: %s (%02x) %s%s:%d\n", + button->index, + hidpp20_1b04_get_logical_mapping_name(mapping), + mapping, + control->reporting.divert || control->reporting.persist ? "(redirected) " : "", + __FILE__, __LINE__); + button->type = hidpp20_1b04_get_logical_mapping(mapping); + button->action_type = hidpp20drv_raw_to_action(button->type); } static int @@ -84,6 +114,8 @@ hidpp20drv_has_capability(const struct ratbag_device *device, enum ratbag_capabi switch (cap) { case RATBAG_CAP_SWITCHABLE_RESOLUTION: return !!(drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201); + case RATBAG_CAP_BUTTON_KEY: + return !!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04); default: return 0; } diff --git a/src/hidpp20.c b/src/hidpp20.c index 4b53545a..01173b85 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -391,37 +391,58 @@ hidpp20_batterylevel_get_battery_level(struct ratbag_device *device, #define CMD_SPECIAL_KEYS_BUTTONS_GET_COUNT 0x00 #define CMD_SPECIAL_KEYS_BUTTONS_GET_INFO 0x10 #define CMD_SPECIAL_KEYS_BUTTONS_GET_REPORTING 0x20 -#define CMD_SPECIAL_KEYS_BUTTONS_SET_SET_REPORTING 0x30 +#define CMD_SPECIAL_KEYS_BUTTONS_SET_REPORTING 0x30 + +struct hidpp20_1b04_mapping { + uint16_t value; + const char *name; + enum ratbag_button_type type; +}; static const struct hidpp20_1b04_mapping hidpp20_1b04_physical_mapping[] = { - { 80, "Left"}, - { 81, "Right"}, - { 82, "Middle"}, - { 83, "Back"}, - { 86, "Forward"}, - { 195, "AppSwitchGesture"}, - { 196, "SmartShift"}, - { 315, "LedToggle"}, + { 0, "None" , RATBAG_BUTTON_TYPE_NONE}, + { 80, "Left" , RATBAG_BUTTON_TYPE_LEFT}, + { 81, "Right" , RATBAG_BUTTON_TYPE_RIGHT}, + { 82, "Middle" , RATBAG_BUTTON_TYPE_MIDDLE}, + { 83, "Back" , RATBAG_BUTTON_TYPE_SIDE}, + { 86, "Forward" , RATBAG_BUTTON_TYPE_EXTRA}, + { 195, "AppSwitchGesture" , RATBAG_BUTTON_TYPE_UNKNOWN}, + { 196, "SmartShift" , RATBAG_BUTTON_TYPE_UNKNOWN}, + { 315, "LedToggle" , RATBAG_BUTTON_TYPE_UNKNOWN}, }; static const struct hidpp20_1b04_mapping hidpp20_1b04_logical_mapping[] = { - { 56, "Left Click"}, - { 57, "Right Click"}, - { 58, "Middle Click"}, - { 60, "Back Click"}, - { 62, "Forward Click"}, - { 156, "Gesture Button"}, - { 157, "SmartShift"}, - { 221, "LedToggle"}, + { 0, "None" , RATBAG_BUTTON_TYPE_NONE}, + { 56, "Left Click" , RATBAG_BUTTON_TYPE_LEFT}, + { 57, "Right Click" , RATBAG_BUTTON_TYPE_RIGHT}, + { 58, "Middle Click" , RATBAG_BUTTON_TYPE_MIDDLE}, + { 60, "Back Click" , RATBAG_BUTTON_TYPE_SIDE}, + { 62, "Forward Click" , RATBAG_BUTTON_TYPE_EXTRA}, + { 156, "Gesture Button" , RATBAG_BUTTON_TYPE_UNKNOWN}, + { 157, "SmartShift" , RATBAG_BUTTON_TYPE_UNKNOWN}, + { 221, "LedToggle" , RATBAG_BUTTON_TYPE_UNKNOWN}, }; -const char * +enum ratbag_button_type hidpp20_1b04_get_logical_mapping(uint16_t value) { const struct hidpp20_1b04_mapping *map; + ARRAY_FOR_EACH(hidpp20_1b04_logical_mapping, map) { + if (map->value == value) + return map->type; + } + + return RATBAG_BUTTON_TYPE_UNKNOWN; +} + +const char * +hidpp20_1b04_get_logical_mapping_name(uint16_t value) +{ + const struct hidpp20_1b04_mapping *map; + ARRAY_FOR_EACH(hidpp20_1b04_logical_mapping, map) { if (map->value == value) return map->name; @@ -430,11 +451,24 @@ hidpp20_1b04_get_logical_mapping(uint16_t value) return "UNKNOWN"; } -const char * +enum ratbag_button_type hidpp20_1b04_get_physical_mapping(uint16_t value) { const struct hidpp20_1b04_mapping *map; + ARRAY_FOR_EACH(hidpp20_1b04_physical_mapping, map) { + if (map->value == value) + return map->type; + } + + return RATBAG_BUTTON_TYPE_UNKNOWN; +} + +const char * +hidpp20_1b04_get_physical_mapping_name(uint16_t value) +{ + const struct hidpp20_1b04_mapping *map; + ARRAY_FOR_EACH(hidpp20_1b04_physical_mapping, map) { if (map->value == value) return map->name; @@ -565,13 +599,13 @@ int hidpp20_special_key_mouse_get_controls(struct ratbag_device *device, if (rc) goto err; - log_info(device->ratbag, + log_debug(device->ratbag, "control %d: cid: '%s' (%d) tid: '%s' (%d) flags: 0x%02x pos: %d group: %d gmask: 0x%02x raw_XY: %s\n" " reporting: raw_xy: %s persist: %s divert: %s remapped: '%s' (%d)\n", control->index, - hidpp20_1b04_get_physical_mapping(control->control_id), + hidpp20_1b04_get_physical_mapping_name(control->control_id), control->control_id, - hidpp20_1b04_get_logical_mapping(control->task_id), + hidpp20_1b04_get_logical_mapping_name(control->task_id), control->task_id, control->flags, control->position, @@ -581,7 +615,7 @@ int hidpp20_special_key_mouse_get_controls(struct ratbag_device *device, control->reporting.raw_XY ? "yes" : "no", control->reporting.persist ? "yes" : "no", control->reporting.divert ? "yes" : "no", - hidpp20_1b04_get_logical_mapping(control->reporting.remapped), + hidpp20_1b04_get_logical_mapping_name(control->reporting.remapped), control->reporting.remapped); } diff --git a/src/hidpp20.h b/src/hidpp20.h index e96cfa74..4f2c4701 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -129,14 +129,10 @@ struct hidpp20_control_id { uint8_t persist; uint8_t divert; uint16_t remapped; + int updated; } reporting; }; -struct hidpp20_1b04_mapping { - uint16_t value; - const char *name; -}; - /** * allocates a list of controls that has to be freed by the caller. * @@ -145,8 +141,10 @@ struct hidpp20_1b04_mapping { int hidpp20_special_key_mouse_get_controls(struct ratbag_device *device, struct hidpp20_control_id **controls_list); -const char *hidpp20_1b04_get_logical_mapping(uint16_t value); -const char *hidpp20_1b04_get_physical_mapping(uint16_t value); +enum ratbag_button_type hidpp20_1b04_get_logical_mapping(uint16_t value); +const char *hidpp20_1b04_get_logical_mapping_name(uint16_t value); +enum ratbag_button_type hidpp20_1b04_get_physical_mapping(uint16_t value); +const char *hidpp20_1b04_get_physical_mapping_name(uint16_t value); /* -------------------------------------------------------------------------- */ /* 0x2200: Mouse Pointer Basic Optical Sensors */