Browse Source
* Add uppermost, current layer status widget to oled * Run clang format * Fixup display widget source includes in CMakeLists * Update layer widget to only be enabled on primary half of a split keyboard and shuffle some of the options specific to the widget to be enabled via the widget * Update to latest lvgl/zmk/zephyr ; remove version text from oled per PR * Fixup file names * Remove last remenants of the version display text from the oled * Fixup clang-format Co-authored-by: KemoNine <mcrosson@kemonine.info>xmkb
KemoNine
4 years ago
committed by
GitHub
6 changed files with 104 additions and 6 deletions
@ -0,0 +1,18 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <lvgl.h> |
||||||
|
#include <kernel.h> |
||||||
|
|
||||||
|
struct zmk_widget_layer_status { |
||||||
|
sys_snode_t node; |
||||||
|
lv_obj_t *obj; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent); |
||||||
|
lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget); |
@ -0,0 +1,68 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <logging/log.h> |
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/display/widgets/layer_status.h> |
||||||
|
#include <zmk/events/layer_state_changed.h> |
||||||
|
#include <zmk/event_manager.h> |
||||||
|
#include <zmk/endpoints.h> |
||||||
|
#include <zmk/keymap.h> |
||||||
|
|
||||||
|
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); |
||||||
|
static lv_style_t label_style; |
||||||
|
|
||||||
|
static bool style_initialized = false; |
||||||
|
|
||||||
|
void layer_status_init() { |
||||||
|
if (style_initialized) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
style_initialized = true; |
||||||
|
lv_style_init(&label_style); |
||||||
|
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK); |
||||||
|
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_12); |
||||||
|
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1); |
||||||
|
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1); |
||||||
|
} |
||||||
|
|
||||||
|
void set_layer_symbol(lv_obj_t *label) { |
||||||
|
int active_layer_index = zmk_keymap_highest_layer_active(); |
||||||
|
char text[6] = {}; |
||||||
|
|
||||||
|
LOG_DBG("Layer changed to %i", active_layer_index); |
||||||
|
sprintf(text, LV_SYMBOL_KEYBOARD "%i ", active_layer_index); |
||||||
|
|
||||||
|
lv_label_set_text(label, text); |
||||||
|
} |
||||||
|
|
||||||
|
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent) { |
||||||
|
layer_status_init(); |
||||||
|
widget->obj = lv_label_create(parent, NULL); |
||||||
|
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style); |
||||||
|
|
||||||
|
lv_obj_set_size(widget->obj, 40, 15); |
||||||
|
set_layer_symbol(widget->obj); |
||||||
|
|
||||||
|
sys_slist_append(&widgets, &widget->node); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget) { |
||||||
|
return widget->obj; |
||||||
|
} |
||||||
|
|
||||||
|
int layer_status_listener(const struct zmk_event_header *eh) { |
||||||
|
struct zmk_widget_layer_status *widget; |
||||||
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_layer_symbol(widget->obj); } |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
ZMK_LISTENER(widget_layer_status, layer_status_listener) |
||||||
|
ZMK_SUBSCRIPTION(widget_layer_status, layer_state_changed); |
Loading…
Reference in new issue