fix(keymap): move the toggle layer logic to keymap.c
This commit is contained in:
parent
ae104374c0
commit
7facb6eee8
4 changed files with 17 additions and 7 deletions
|
@ -1,3 +1,9 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Cody McGinnis <brainwart@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/ {
|
||||
behaviors {
|
||||
tog: behavior_toggle_layer {
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
bool zmk_keymap_layer_active(u8_t layer);
|
||||
int zmk_keymap_layer_activate(u8_t layer);
|
||||
int zmk_keymap_layer_deactivate(u8_t layer);
|
||||
int zmk_keymap_layer_toggle(u8_t layer);
|
||||
|
||||
int zmk_keymap_position_state_changed(u32_t position, bool pressed);
|
||||
|
|
|
@ -25,12 +25,7 @@ static int behavior_tog_init(struct device *dev)
|
|||
|
||||
static int tog_keymap_binding_pressed(struct device *dev, u32_t position, u32_t layer, u32_t _)
|
||||
{
|
||||
LOG_DBG("position %d layer %d current %d", position, layer, zmk_keymap_layer_active(layer));
|
||||
|
||||
if (zmk_keymap_layer_active(layer))
|
||||
return zmk_keymap_layer_deactivate(layer);
|
||||
|
||||
return zmk_keymap_layer_activate(layer);
|
||||
return zmk_keymap_layer_toggle(layer);
|
||||
}
|
||||
|
||||
static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _)
|
||||
|
|
|
@ -91,6 +91,14 @@ int zmk_keymap_layer_deactivate(u8_t layer)
|
|||
SET_LAYER_STATE(layer, false);
|
||||
};
|
||||
|
||||
int zmk_keymap_layer_toggle(u8_t layer)
|
||||
{
|
||||
if (zmk_keymap_layer_active(layer))
|
||||
return zmk_keymap_layer_deactivate(layer);
|
||||
|
||||
return zmk_keymap_layer_activate(layer);
|
||||
};
|
||||
|
||||
bool is_active_position(u32_t position, u8_t layer)
|
||||
{
|
||||
return (zmk_keymap_layer_state & BIT(layer)) == BIT(layer)
|
||||
|
|
Loading…
Reference in a new issue