Skip to content

Commit

Permalink
Add metadata to mouse behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Jan 13, 2025
1 parent a3ea44e commit cac8cb3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion app/src/behaviors/behavior_mouse_key_press.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,48 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA)

static const struct behavior_parameter_value_metadata param_values[] = {
{
.value = BIT(0),
.display_name = "Left click",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
},
{
.value = BIT(1),
.display_name = "Right click",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
},
{
.value = BIT(2),
.display_name = "Middle click",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
},
{
.value = BIT(3),
.display_name = "MB4 click",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
},
{
.value = BIT(4),
.display_name = "MB5 click",
.type = BEHAVIOR_PARAMETER_VALUE_TYPE_VALUE,
},
};

static const struct behavior_parameter_metadata_set param_metadata_set[] = {{
.param1_values = param_values,
.param1_values_len = ARRAY_SIZE(param_values),
}};

static const struct behavior_parameter_metadata metadata = {
.sets_len = ARRAY_SIZE(param_metadata_set),
.sets = param_metadata_set,
};

#endif

static int behavior_mouse_key_press_init(const struct device *dev) { return 0; };

static void process_key_state(const struct device *dev, int32_t val, bool pressed) {
Expand Down Expand Up @@ -49,7 +91,12 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
}

static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released,
#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA)
.parameter_metadata = &metadata,
#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA)
};

#define MKP_INST(n) \
BEHAVIOR_DT_INST_DEFINE(n, behavior_mouse_key_press_init, NULL, NULL, NULL, POST_KERNEL, \
Expand Down

0 comments on commit cac8cb3

Please sign in to comment.