Skip to content

Commit

Permalink
feat(keymap): Add binding get/set, layer movement
Browse files Browse the repository at this point in the history
* Add keymap API for getting/setting a bindings
  in keymap layers.
* Add layer move support via intemediary ordering array.
* Add settings storage for keymap changes.
  • Loading branch information
petejohanson committed Jul 6, 2024
1 parent d6c872e commit 0d06a92
Show file tree
Hide file tree
Showing 7 changed files with 798 additions and 49 deletions.
12 changes: 12 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ rsource "src/split/Kconfig"
#Basic Keyboard Setup
endmenu

menu "Keymaps"

config ZMK_KEYMAP_LAYER_REORDERING
bool "Layer Reordering Support"

config ZMK_KEYMAP_SETTINGS_STORAGE
bool "Settings Save/Load"
depends on SETTINGS
depends on ZMK_BEHAVIOR_LOCAL_IDS

endmenu # Keymaps

rsource "src/studio/Kconfig"

menu "Display/LED Options"
Expand Down
43 changes: 35 additions & 8 deletions app/include/zmk/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,44 @@
#define ZMK_KEYMAP_LAYERS_LEN \
(DT_FOREACH_CHILD(DT_INST(0, zmk_keymap), ZMK_LAYER_CHILD_LEN_PLUS_ONE) 0)

typedef uint8_t zmk_keymap_layer_id_t;
typedef uint8_t zmk_keymap_layer_index_t;

typedef uint32_t zmk_keymap_layers_state_t;

uint8_t zmk_keymap_layer_default(void);
zmk_keymap_layer_id_t zmk_keymap_layer_index_to_id(zmk_keymap_layer_index_t layer_index);

zmk_keymap_layer_id_t zmk_keymap_layer_default(void);
zmk_keymap_layers_state_t zmk_keymap_layer_state(void);
bool zmk_keymap_layer_active(uint8_t layer);
uint8_t zmk_keymap_highest_layer_active(void);
int zmk_keymap_layer_activate(uint8_t layer);
int zmk_keymap_layer_deactivate(uint8_t layer);
int zmk_keymap_layer_toggle(uint8_t layer);
int zmk_keymap_layer_to(uint8_t layer);
const char *zmk_keymap_layer_name(uint8_t layer);
bool zmk_keymap_layer_active(zmk_keymap_layer_id_t layer);
zmk_keymap_layer_id_t zmk_keymap_highest_layer_active(void);
int zmk_keymap_layer_activate(zmk_keymap_layer_id_t layer);
int zmk_keymap_layer_deactivate(zmk_keymap_layer_id_t layer);
int zmk_keymap_layer_toggle(zmk_keymap_layer_id_t layer);
int zmk_keymap_layer_to(zmk_keymap_layer_id_t layer);
const char *zmk_keymap_layer_name(zmk_keymap_layer_id_t layer);

const struct zmk_behavior_binding *zmk_keymap_get_layer_binding_at_idx(zmk_keymap_layer_id_t layer,
uint8_t binding_idx);
int zmk_keymap_set_layer_binding_at_idx(zmk_keymap_layer_id_t layer, uint8_t binding_idx,
const struct zmk_behavior_binding binding);

#if IS_ENABLED(CONFIG_ZMK_KEYMAP_LAYER_REORDERING)

int zmk_keymap_move_layer(zmk_keymap_layer_index_t start_idx, zmk_keymap_layer_index_t dest_idx);

#endif

/**
* @brief Check if there are any unsaved keymap changes.
*
* @retval 0 if there are no changes.
* @retval 1 if there are changes.
*/
int zmk_keymap_check_unsaved_changes(void);

int zmk_keymap_save_changes(void);
int zmk_keymap_discard_changes(void);

int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pressed,
int64_t timestamp);
Expand Down
Loading

0 comments on commit 0d06a92

Please sign in to comment.