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 Aug 10, 2024
1 parent a706cf4 commit c0eec26
Show file tree
Hide file tree
Showing 8 changed files with 1,150 additions and 54 deletions.
20 changes: 20 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ 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

if ZMK_KEYMAP_SETTINGS_STORAGE

config ZMK_KEYMAP_LAYER_NAME_MAX_LEN
int "Max Layer Name Length"
default 20

endif

endmenu # Keymaps

rsource "src/studio/Kconfig"

menu "Display/LED Options"
Expand Down
49 changes: 41 additions & 8 deletions app/include/zmk/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,50 @@
#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_add_layer(void);
int zmk_keymap_remove_layer(zmk_keymap_layer_index_t index);
int zmk_keymap_restore_layer(zmk_keymap_layer_id_t id, zmk_keymap_layer_index_t at_index);

int zmk_keymap_move_layer(zmk_keymap_layer_index_t start_idx, zmk_keymap_layer_index_t dest_idx);

int zmk_keymap_set_layer_name(zmk_keymap_layer_id_t id, const char *name, size_t size);

#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 c0eec26

Please sign in to comment.