mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
sinowealth: add support for writing key button actions
This commit is contained in:
committed by
Ilya guterman
parent
6ac5ba6dbb
commit
72f8708e0e
@@ -1126,6 +1126,40 @@ sinowealth_update_profile_from_buttons(struct ratbag_profile *profile)
|
||||
}
|
||||
}
|
||||
|
||||
/* @return 0 on success or an error code. */
|
||||
static int
|
||||
sinowealth_button_set_key_action_from_macro(struct ratbag_device *device, struct ratbag_button *button, struct sinowealth_button_data *button_data)
|
||||
{
|
||||
if (button->action.type != RATBAG_BUTTON_ACTION_TYPE_MACRO) {
|
||||
log_debug(device->ratbag, "Internal bug: non-macro action is passed to macro to key action converter");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ratbag_button_action *action = &button->action;
|
||||
|
||||
int rc = 0;
|
||||
unsigned int key = 0;
|
||||
unsigned int modifiers = 0;
|
||||
|
||||
rc = ratbag_action_keycode_from_macro(action, &key, &modifiers);
|
||||
if (rc < 0) {
|
||||
log_error(device->ratbag, "Could not make a keycode from macro for button %d\n", button->index);
|
||||
return rc;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -1149,6 +1183,9 @@ 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);
|
||||
break;
|
||||
default:
|
||||
log_debug(device->ratbag, "Can't set unsupported action type %#x to button %u\n", action->action.special, button->index);
|
||||
break;
|
||||
@@ -1272,6 +1309,7 @@ sinowealth_init_profile(struct ratbag_device *device)
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY);
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
|
||||
Reference in New Issue
Block a user