From 15a91f7b05f2f2ad47a5732637ab1e54a12c984c Mon Sep 17 00:00:00 2001 From: Ryan Prince Date: Mon, 8 Apr 2013 08:46:25 -0700 Subject: [PATCH] fixing a bug in sticky key one time state behavior, cleaning up a comment, and making braces style consistent with the rest of the code. sticky layers in the one time state were being popped anytime kbfun_press_release() was called, which should only happen if the key was defined for the sticky layer, i.e. kbfun_transparent() was not the first function mapped to that key in the topmost layer. --- src/lib/key-functions/public/basic.c | 25 +++++++++---------------- src/main.c | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/lib/key-functions/public/basic.c b/src/lib/key-functions/public/basic.c index 6825c2e..3f1b9d3 100644 --- a/src/lib/key-functions/public/basic.c +++ b/src/lib/key-functions/public/basic.c @@ -80,8 +80,8 @@ void kbfun_transparent(void) { * ------------------------------------------------------------------------- */ // While there are only MAX_LAYER_PUSH_POP_FUNCTIONS number of layer functions, -// there are 1 + MAX_LAYER_PUSH_POP_FUNCTIONS because we still have layer 0 -// even if we will never have a push or pop function for it +// there are 1 + MAX_LAYER_PUSH_POP_FUNCTIONS layer ids because we still have +// layer 0 even if we will never have a push or pop function for it static uint8_t layer_ids[1 + MAX_LAYER_PUSH_POP_FUNCTIONS]; static void layer_push(uint8_t local_id) { @@ -90,8 +90,7 @@ static void layer_push(uint8_t local_id) { // Only the topmost layer on the stack should be in sticky once state, pop // the top layer if it is in sticky once state uint8_t topSticky = main_layers_peek_sticky(0); - if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) - { + if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) { main_layers_pop_id(main_layers_peek(0)); } layer_ids[local_id] = main_layers_push(keycode, eStickyNone); @@ -99,21 +98,18 @@ static void layer_push(uint8_t local_id) { static void layer_sticky(uint8_t local_id) { uint8_t keycode = kb_layout_get(LAYER, ROW, COL); - if (IS_PRESSED) - { + if (IS_PRESSED) { uint8_t topLayer = main_layers_peek(0); uint8_t topSticky = main_layers_peek_sticky(0); main_layers_pop_id(layer_ids[local_id]); - if (topLayer == local_id) - { + if (topLayer == local_id) { if (topSticky == eStickyOnceUp) layer_ids[local_id] = main_layers_push(keycode, eStickyLock); } else { // only the topmost layer on the stack should be in sticky once state - if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) - { + if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) { main_layers_pop_id(layer_ids[topLayer]); } layer_ids[local_id] = main_layers_push(keycode, eStickyOnceDown); @@ -125,14 +121,11 @@ static void layer_sticky(uint8_t local_id) { { uint8_t topLayer = main_layers_peek(0); uint8_t topSticky = main_layers_peek_sticky(0); - if (topLayer == local_id) - { - if (topSticky == eStickyOnceDown) - { + if (topLayer == local_id) { + if (topSticky == eStickyOnceDown) { // When releasing this sticky key, pop the layer always main_layers_pop_id(layer_ids[local_id]); - if (!main_arg_any_non_trans_key_pressed) - { + if (!main_arg_any_non_trans_key_pressed) { // If no key defined for this layer (a non-transparent key) // was pressed, push the layer again, but in the // StickyOnceUp state diff --git a/src/main.c b/src/main.c index db90af0..a1a630f 100644 --- a/src/main.c +++ b/src/main.c @@ -100,6 +100,7 @@ int main(void) { main_arg_row = row; main_arg_col = col; main_arg_layer_offset = 0; + main_arg_trans_key_pressed = false; main_exec_key(); } } @@ -176,7 +177,6 @@ void main_exec_key(void) { ? kb_layout_press_get(layer, row, col) : kb_layout_release_get(layer, row, col) ); - main_arg_trans_key_pressed = false; if (key_function) (*key_function)();