Skip to content

Commit

Permalink
fix(studio): Properly return complete keymap from RPC (#2696)
Browse files Browse the repository at this point in the history
Ensure the set active physical layout RPC returns the full keymap
details including the available layers.
  • Loading branch information
petejohanson authored Dec 6, 2024
1 parent b26058b commit 0820991
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/src/studio/keymap_subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,28 @@ static bool encode_keymap_layers(pb_ostream_t *stream, const pb_field_t *field,
return true;
}

zmk_studio_Response get_keymap(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_keymap_Keymap resp = zmk_keymap_Keymap_init_zero;
static void populate_keymap_extra_props(zmk_keymap_Keymap *keymap) {
keymap->max_layer_name_length = CONFIG_ZMK_KEYMAP_LAYER_NAME_MAX_LEN;

resp.layers.funcs.encode = encode_keymap_layers;

resp.max_layer_name_length = CONFIG_ZMK_KEYMAP_LAYER_NAME_MAX_LEN;
resp.available_layers = 0;
keymap->available_layers = 0;

for (zmk_keymap_layer_index_t index = 0; index < ZMK_KEYMAP_LAYERS_LEN; index++) {
zmk_keymap_layer_id_t id = zmk_keymap_layer_index_to_id(index);

if (id == UINT8_MAX) {
resp.available_layers = ZMK_KEYMAP_LAYERS_LEN - index;
keymap->available_layers = ZMK_KEYMAP_LAYERS_LEN - index;
break;
}
}
}

zmk_studio_Response get_keymap(const zmk_studio_Request *req) {
LOG_DBG("");
zmk_keymap_Keymap resp = zmk_keymap_Keymap_init_zero;

resp.layers.funcs.encode = encode_keymap_layers;

populate_keymap_extra_props(&resp);

return KEYMAP_RESPONSE(get_keymap, resp);
}
Expand Down Expand Up @@ -332,6 +337,7 @@ zmk_studio_Response set_active_physical_layout(const zmk_studio_Request *req) {
zmk_keymap_SetActivePhysicalLayoutResponse_init_zero;
resp.which_result = zmk_keymap_SetActivePhysicalLayoutResponse_ok_tag;
resp.result.ok.layers.funcs.encode = encode_keymap_layers;
populate_keymap_extra_props(&resp.result.ok);

if (old == index) {
return KEYMAP_RESPONSE(set_active_physical_layout, resp);
Expand Down

0 comments on commit 0820991

Please sign in to comment.