Browse Source

fix(keymap): move the toggle layer logic to keymap.c

xmkb
Cody McGinnis 4 years ago
parent
commit
7facb6eee8
  1. 8
      app/dts/behaviors/toggle_layer.dtsi
  2. 1
      app/include/zmk/keymap.h
  3. 7
      app/src/behaviors/behavior_toggle_layer.c
  4. 8
      app/src/keymap.c

8
app/dts/behaviors/toggle_layer.dtsi

@ -1,4 +1,10 @@
/ { /*
* Copyright (c) 2020 Cody McGinnis <brainwart@gmail.com>
*
* SPDX-License-Identifier: MIT
*/
/ {
behaviors { behaviors {
tog: behavior_toggle_layer { tog: behavior_toggle_layer {
compatible = "zmk,behavior-toggle-layer"; compatible = "zmk,behavior-toggle-layer";

1
app/include/zmk/keymap.h

@ -3,5 +3,6 @@
bool zmk_keymap_layer_active(u8_t layer); bool zmk_keymap_layer_active(u8_t layer);
int zmk_keymap_layer_activate(u8_t layer); int zmk_keymap_layer_activate(u8_t layer);
int zmk_keymap_layer_deactivate(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); int zmk_keymap_position_state_changed(u32_t position, bool pressed);

7
app/src/behaviors/behavior_toggle_layer.c

@ -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 _) 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)); return zmk_keymap_layer_toggle(layer);
if (zmk_keymap_layer_active(layer))
return zmk_keymap_layer_deactivate(layer);
return zmk_keymap_layer_activate(layer);
} }
static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _) static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _)

8
app/src/keymap.c

@ -91,6 +91,14 @@ int zmk_keymap_layer_deactivate(u8_t layer)
SET_LAYER_STATE(layer, false); 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) bool is_active_position(u32_t position, u8_t layer)
{ {
return (zmk_keymap_layer_state & BIT(layer)) == BIT(layer) return (zmk_keymap_layer_state & BIT(layer)) == BIT(layer)

Loading…
Cancel
Save