Skip to content

Commit

Permalink
fix(keymap): Set bindings with changed layout
Browse files Browse the repository at this point in the history
* Fix bug with setting keymap layer bindings when a non-stock layout
  is selected.
  • Loading branch information
petejohanson committed Nov 1, 2024
1 parent 158bb31 commit 26fcebb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer_id, uint8_t

uint8_t *pending = zmk_keymap_layer_pending_changes[layer_id];

WRITE_BIT(pending[binding_idx / 8], binding_idx % 8, 1);
WRITE_BIT(pending[storage_binding_idx / 8], storage_binding_idx % 8, 1);

// TODO: Need a mutex to protect access to the keymap data?
memcpy(&zmk_keymap[layer_id][storage_binding_idx], &binding, sizeof(binding));
Expand Down Expand Up @@ -483,10 +483,11 @@ static int save_bindings(void) {

for (int kp = 0; kp < ZMK_KEYMAP_LEN; kp++) {
if (pending[kp / 8] & BIT(kp % 8)) {
LOG_DBG("Pending save for layer %d at key position %d", l, kp);

const struct zmk_behavior_binding *binding =
zmk_keymap_get_layer_binding_at_idx(l, kp);
const struct zmk_behavior_binding *binding = &zmk_keymap[l][kp];
LOG_DBG("Pending save for layer %d at key position %d: %s with %d, %d", l, kp,
binding->behavior_dev, binding->param1, binding->param2);

struct zmk_behavior_binding_setting binding_setting = {
.behavior_local_id = zmk_behavior_get_local_id(binding->behavior_dev),
.param1 = binding->param1,
Expand All @@ -512,10 +513,10 @@ static int save_bindings(void) {
LOG_ERR("Failed to save keymap binding at %d on layer %d (%d)", l, kp, ret);
return ret;
}

WRITE_BIT(pending[kp / 8], kp % 8, 0);
}
}

*pending = 0;
}

return 0;
Expand Down

0 comments on commit 26fcebb

Please sign in to comment.