From 89168f218728e20927e920fc66c72120cac631d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Mon, 13 Apr 2020 00:59:54 +0100 Subject: [PATCH] hidpp10: add support from writting simple macro actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #900 Signed-off-by: Filipe LaĆ­ns --- src/driver-hidpp10.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 81060ecf..8b188929 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -299,6 +299,8 @@ hidpp10drv_write_button(struct hidpp10_profile *profile, struct hidpp10drv_data *drv_data = ratbag_get_drv_data(device); struct hidpp10_device *hidpp10 = drv_data->dev; uint8_t code; + unsigned int modifiers, key; + int rc; if (hidpp10->profile_type == HIDPP10_PROFILE_UNKNOWN) return -ENOTSUP; @@ -330,6 +332,26 @@ hidpp10drv_write_button(struct hidpp10_profile *profile, profile->buttons[button->index].special.special = code; break; case RATBAG_BUTTON_ACTION_TYPE_MACRO: + rc = ratbag_action_keycode_from_macro(action, &key, &modifiers); + if (rc < 0) { + log_error(device->ratbag, "hidpp10: can't convert macro action to keycode in button %d\n", button->index); + return -EINVAL; + } + + code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, key); + if (code == 0) { + code = ratbag_hidraw_get_consumer_usage_from_keycode(device, key); + if (code == 0) + return -EINVAL; + + profile->buttons[button->index].consumer_control.type = PROFILE_BUTTON_TYPE_CONSUMER_CONTROL; + profile->buttons[button->index].consumer_control.consumer_control = code; + } else { + profile->buttons[button->index].keys.type = PROFILE_BUTTON_TYPE_KEYS; + profile->buttons[button->index].keys.key = code; + profile->buttons[button->index].keys.modifier_flags = modifiers; + } + break; default: return -ENOTSUP; }