From dd609c06a9d9503e9147b83e03df5b97c08762ad Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Mon, 14 Nov 2022 14:12:27 +0300 Subject: [PATCH] sinowealth: fix writing of `key` button action type It did not work *ever* as the helper function was only called when action type was `key` but the function checked if it was a `macro`. --- src/driver-sinowealth.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/driver-sinowealth.c b/src/driver-sinowealth.c index 5b4fba74..a70fd626 100644 --- a/src/driver-sinowealth.c +++ b/src/driver-sinowealth.c @@ -1241,6 +1241,29 @@ sinowealth_button_set_key_action_from_macro(struct ratbag_device *device, struct return 0; } +/* @return 0 on success or an error code. */ +static int +sinowealth_button_set_key_action(struct ratbag_device *device, const struct ratbag_button *button, struct sinowealth_button_data *button_data) +{ + assert(button->action.type == RATBAG_BUTTON_ACTION_TYPE_KEY); + + const unsigned int key = button->action.action.key.key; + // libratbag doesn't support modifiers in `key` actions. + const unsigned int modifiers = 0; + + const uint8_t raw_key = ratbag_hidraw_get_keyboard_usage_from_keycode(device, key); + if (raw_key == 0) { + log_debug(device->ratbag, "Could not set unsupported key %#x to button %u\n", key, button->index); + return -1; + } + + button_data->type = SINOWEALTH_BUTTON_TYPE_KEY; + button_data->key.modifiers = modifiers; + button_data->key.key = raw_key; + + return 0; +} + static int sinowealth_update_buttons_from_profile(struct ratbag_profile *profile) { @@ -1265,7 +1288,7 @@ sinowealth_update_buttons_from_profile(struct ratbag_profile *profile) switch (action->type) { case RATBAG_BUTTON_ACTION_TYPE_KEY: - sinowealth_button_set_key_action_from_macro(device, button, button_data); + sinowealth_button_set_key_action(device, button, button_data); break; case RATBAG_BUTTON_ACTION_TYPE_MACRO: { /* Make the button activate a macro.