mirror of https://github.com/zmkfirmware/zmk.git
fix: Properly calculate highest active layer for display.
This commit is contained in:
parent
de38676afd
commit
cca637d66e
|
|
@ -19,13 +19,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
||||
|
||||
struct layer_status_state {
|
||||
uint8_t index;
|
||||
zmk_keymap_layer_index_t index;
|
||||
const char *label;
|
||||
};
|
||||
|
||||
static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) {
|
||||
const char *layer_label = state.label;
|
||||
uint8_t active_layer_index = state.index;
|
||||
zmk_keymap_layer_index_t active_layer_index = state.index;
|
||||
|
||||
if (layer_label == NULL) {
|
||||
char text[6] = {};
|
||||
|
|
@ -44,8 +44,9 @@ static void layer_status_update_cb(struct layer_status_state state) {
|
|||
}
|
||||
|
||||
static struct layer_status_state layer_status_get_state(const zmk_event_t *eh) {
|
||||
uint8_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){.index = index, .label = zmk_keymap_layer_name(index)};
|
||||
zmk_keymap_layer_index_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){
|
||||
.index = index, .label = zmk_keymap_layer_name(zmk_keymap_layer_index_to_id(index))};
|
||||
}
|
||||
|
||||
ZMK_DISPLAY_WIDGET_LISTENER(widget_layer_status, struct layer_status_state, layer_status_update_cb,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ struct output_status_state {
|
|||
};
|
||||
|
||||
struct layer_status_state {
|
||||
uint8_t index;
|
||||
zmk_keymap_layer_index_t index;
|
||||
const char *label;
|
||||
};
|
||||
|
||||
|
|
@ -277,8 +277,9 @@ static void layer_status_update_cb(struct layer_status_state state) {
|
|||
}
|
||||
|
||||
static struct layer_status_state layer_status_get_state(const zmk_event_t *eh) {
|
||||
uint8_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){.index = index, .label = zmk_keymap_layer_name(index)};
|
||||
zmk_keymap_layer_index_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){
|
||||
.index = index, .label = zmk_keymap_layer_name(zmk_keymap_layer_index_to_id(index))};
|
||||
}
|
||||
|
||||
ZMK_DISPLAY_WIDGET_LISTENER(widget_layer_status, struct layer_status_state, layer_status_update_cb,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ zmk_keymap_layer_id_t zmk_keymap_layer_index_to_id(zmk_keymap_layer_index_t laye
|
|||
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(zmk_keymap_layer_id_t layer);
|
||||
zmk_keymap_layer_id_t zmk_keymap_highest_layer_active(void);
|
||||
zmk_keymap_layer_index_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);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
||||
|
||||
struct layer_status_state {
|
||||
uint8_t index;
|
||||
zmk_keymap_layer_index_t index;
|
||||
const char *label;
|
||||
};
|
||||
|
||||
|
|
@ -44,8 +44,9 @@ static void layer_status_update_cb(struct layer_status_state state) {
|
|||
}
|
||||
|
||||
static struct layer_status_state layer_status_get_state(const zmk_event_t *eh) {
|
||||
uint8_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){.index = index, .label = zmk_keymap_layer_name(index)};
|
||||
zmk_keymap_layer_index_t index = zmk_keymap_highest_layer_active();
|
||||
return (struct layer_status_state){
|
||||
.index = index, .label = zmk_keymap_layer_name(zmk_keymap_layer_index_to_id(index))};
|
||||
}
|
||||
|
||||
ZMK_DISPLAY_WIDGET_LISTENER(widget_layer_status, struct layer_status_state, layer_status_update_cb,
|
||||
|
|
|
|||
|
|
@ -182,13 +182,20 @@ bool zmk_keymap_layer_active(zmk_keymap_layer_id_t layer) {
|
|||
return zmk_keymap_layer_active_with_state(layer, _zmk_keymap_layer_state);
|
||||
};
|
||||
|
||||
zmk_keymap_layer_id_t zmk_keymap_highest_layer_active(void) {
|
||||
for (uint8_t layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer > 0; layer--) {
|
||||
if (zmk_keymap_layer_active(layer)) {
|
||||
return layer;
|
||||
zmk_keymap_layer_index_t zmk_keymap_highest_layer_active(void) {
|
||||
for (int layer_idx = ZMK_KEYMAP_LAYERS_LEN - 1;
|
||||
layer_idx >= LAYER_ID_TO_INDEX(_zmk_keymap_layer_default); layer_idx--) {
|
||||
zmk_keymap_layer_id_t layer_id = LAYER_INDEX_TO_ID(layer_idx);
|
||||
|
||||
if (layer_id == ZMK_KEYMAP_LAYER_ID_INVAL) {
|
||||
continue;
|
||||
}
|
||||
if (zmk_keymap_layer_active(layer_id)) {
|
||||
return LAYER_ID_TO_INDEX(layer_id);
|
||||
}
|
||||
}
|
||||
return zmk_keymap_layer_default();
|
||||
|
||||
return LAYER_ID_TO_INDEX(zmk_keymap_layer_default());
|
||||
}
|
||||
|
||||
int zmk_keymap_layer_activate(zmk_keymap_layer_id_t layer) { return set_layer_state(layer, true); };
|
||||
|
|
|
|||
Loading…
Reference in New Issue