libratbag: remove FIXME for simple key action modifiers

Macros can be used for that instead.
This commit is contained in:
Yaroslav Chvanov
2024-03-05 20:03:58 +03:00
parent 1c4ef242fc
commit 8444ceb638
9 changed files with 26 additions and 29 deletions

View File

@@ -117,7 +117,7 @@ asus_driver_load_profile(struct ratbag_device *device, struct ratbag_profile *pr
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
rc = asus_get_linux_key_code(asus_binding->action);
if (rc > 0) {
button->action.action.key.key = (unsigned int)rc;
button->action.action.key = (unsigned int)rc;
} else {
log_debug(device->ratbag, "Unknown button code %02x\n", asus_binding->action);
}
@@ -238,7 +238,7 @@ asus_driver_save_profile(struct ratbag_device *device, struct ratbag_profile *pr
case RATBAG_BUTTON_ACTION_TYPE_KEY:
/* Linux code to ASUS code */
rc = asus_find_key_code(button->action.action.key.key);
rc = asus_find_key_code(button->action.action.key);
if (rc != -1) {
asus_code_dst = (uint8_t)rc;
rc = asus_set_button_action(

View File

@@ -1200,13 +1200,13 @@ gskill_read_button(struct ratbag_button *button)
break;
case GSKILL_BUTTON_FUNCTION_KBD:
act->type = RATBAG_BUTTON_ACTION_TYPE_KEY;
act->action.key.key =
act->action.key =
ratbag_hidraw_get_keycode_from_keyboard_usage(
device, bcfg->params.kbd.hid_code);
break;
case GSKILL_BUTTON_FUNCTION_CONSUMER:
act->type = RATBAG_BUTTON_ACTION_TYPE_KEY;
act->action.key.key =
act->action.key =
ratbag_hidraw_get_keycode_from_consumer_usage(
device, bcfg->params.consumer.code);
break;
@@ -1308,13 +1308,13 @@ gskill_update_button(struct ratbag_button *button)
break;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
code = ratbag_hidraw_get_keyboard_usage_from_keycode(
device, action->action.key.key);
device, action->action.key);
if (code) {
bcfg->type = GSKILL_BUTTON_FUNCTION_KBD;
bcfg->params.kbd.hid_code = code;
} else {
code = ratbag_hidraw_get_consumer_usage_from_keycode(
device, action->action.key.key);
device, action->action.key);
bcfg->type = GSKILL_BUTTON_FUNCTION_CONSUMER;
bcfg->params.consumer.code = code;

View File

@@ -177,13 +177,13 @@ hidpp10drv_map_button(struct ratbag_device *device,
break;
case PROFILE_BUTTON_TYPE_KEYS:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
button->action.action.key.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
button->action.action.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
profile.buttons[button->index].keys.key);
modifiers = profile.buttons[button->index].keys.modifier_flags;
break;
case PROFILE_BUTTON_TYPE_CONSUMER_CONTROL:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
button->action.action.key.key = ratbag_hidraw_get_keycode_from_consumer_usage(device,
button->action.action.key = ratbag_hidraw_get_keycode_from_consumer_usage(device,
profile.buttons[button->index].consumer_control.consumer_control);
break;
case PROFILE_BUTTON_TYPE_SPECIAL:
@@ -202,7 +202,7 @@ hidpp10drv_map_button(struct ratbag_device *device,
}
if (button->action.type == RATBAG_BUTTON_ACTION_TYPE_KEY) {
ret = ratbag_button_macro_new_from_keycode(button, button->action.action.key.key, modifiers);
ret = ratbag_button_macro_new_from_keycode(button, button->action.action.key, modifiers);
if (ret < 0) {
log_error(device->ratbag, "hidpp10: error while reading button %d\n", button->index);
button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
@@ -256,9 +256,9 @@ hidpp10drv_write_button(struct hidpp10_profile *profile,
profile->buttons[button->index].button.button = action->action.button;
break;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, action->action.key.key);
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, action->action.key);
if (code == 0) {
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key.key);
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key);
if (code == 0)
return -EINVAL;

View File

@@ -222,13 +222,13 @@ hidpp20drv_read_button_8100(struct ratbag_button *button)
break;
case HIDPP20_BUTTON_HID_TYPE_KEYBOARD:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
button->action.action.key.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
button->action.action.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
profile->buttons[button->index].keyboard_keys.key);
modifiers = profile->buttons[button->index].keyboard_keys.modifier_flags;
break;
case HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
button->action.action.key.key = ratbag_hidraw_get_keycode_from_consumer_usage(device,
button->action.action.key = ratbag_hidraw_get_keycode_from_consumer_usage(device,
profile->buttons[button->index].consumer_control.consumer_control);
break;
}
@@ -249,7 +249,7 @@ hidpp20drv_read_button_8100(struct ratbag_button *button)
if (button->action.type == RATBAG_BUTTON_ACTION_TYPE_KEY) {
rc = ratbag_button_macro_new_from_keycode(button,
button->action.action.key.key,
button->action.action.key,
modifiers);
if (rc < 0) {
log_error(device->ratbag,
@@ -570,10 +570,10 @@ hidpp20drv_update_button_8100(struct ratbag_button *button)
case RATBAG_BUTTON_ACTION_TYPE_KEY:
type = HIDPP20_BUTTON_HID_TYPE;
subtype = HIDPP20_BUTTON_HID_TYPE_KEYBOARD;
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, action->action.key.key);
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, action->action.key);
if (code == 0) {
subtype = HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL;
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key.key);
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key);
if (code == 0)
return -EINVAL;
}

View File

@@ -1443,7 +1443,7 @@ sinowealth_button_set_key_action(const struct ratbag_button *button, struct sino
return -EINVAL;
}
const unsigned int key = button->action.action.key.key;
const unsigned int key = button->action.action.key;
// libratbag does not support modifiers in simple key actions.
// We can can convert simple enough macros into key actions though, see
// sinowealth_button_key_action_from_simple_macro().

View File

@@ -627,7 +627,7 @@ steelseries_write_buttons(struct ratbag_profile *profile)
msg.msg.parameters[idx + 1] = keyboard_code;
} else {
const uint16_t consumer_code = ratbag_hidraw_get_consumer_usage_from_keycode(
device, action->action.key.key);
device, action->action.key);
msg.msg.parameters[idx] = STEELSERIES_BUTTON_CONSUMER;
msg.msg.parameters[idx + 1] = (uint8_t)consumer_code;
}

View File

@@ -61,7 +61,7 @@ test_read_button(struct ratbag_button *button)
break;
case RATBAG_BUTTON_ACTION_TYPE_KEY:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
button->action.action.key.key = p->buttons[button->index].key;
button->action.action.key = p->buttons[button->index].key;
break;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
button->action.type = RATBAG_BUTTON_ACTION_TYPE_MACRO;

View File

@@ -309,7 +309,7 @@ struct ratbag_profile {
.action.special = sp_ }
#define BUTTON_ACTION_KEY(k_) \
{ .type = RATBAG_BUTTON_ACTION_TYPE_KEY, \
.action.key.key = k_ }
.action.key = k_ }
#define BUTTON_ACTION_MACRO \
{ .type = RATBAG_BUTTON_ACTION_TYPE_MACRO, \
/* FIXME: add the macro keys */ }
@@ -348,10 +348,7 @@ struct ratbag_button_action {
union ratbag_btn_action {
unsigned int button; /* action_type == button */
enum ratbag_button_action_special special; /* action_type == special */
struct {
unsigned int key; /* action_type == key */
/* FIXME: modifiers */
} key;
unsigned int key; /* action_type == key */
} action;
struct ratbag_macro *macro; /* dynamically allocated, so kept aside */
};
@@ -447,7 +444,7 @@ ratbag_button_action_match(const struct ratbag_button_action *action,
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;
return match->action.key == action->action.key;
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
return match->action.special == action->action.special;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
@@ -470,8 +467,8 @@ ratbag_button_macro_new_from_keycode(struct ratbag_button *button,
int
ratbag_action_keycode_from_macro(const struct ratbag_button_action *action,
unsigned int *key_out,
unsigned int *modifiers_out);
unsigned int *key_out,
unsigned int *modifiers_out);
static inline void
ratbag_resolution_set_resolution(struct ratbag_resolution *res,

View File

@@ -1385,7 +1385,7 @@ ratbag_button_get_key(const struct ratbag_button *button)
if (button->action.type != RATBAG_BUTTON_ACTION_TYPE_KEY)
return 0;
return button->action.action.key.key;
return button->action.action.key;
}
LIBRATBAG_EXPORT enum ratbag_error_code
@@ -1400,7 +1400,7 @@ ratbag_button_set_key(struct ratbag_button *button, unsigned int key)
return RATBAG_ERROR_CAPABILITY;
action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
action.action.key.key = key;
action.action.key = key;
ratbag_button_set_action(button, &action);
button->dirty = true;