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.
f13
Ryan Prince 2013-04-08 08:46:25 -07:00
parent 2d5c6084c0
commit 15a91f7b05
2 changed files with 10 additions and 17 deletions

View File

@ -80,8 +80,8 @@ void kbfun_transparent(void) {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
// While there are only MAX_LAYER_PUSH_POP_FUNCTIONS number of layer functions, // 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 // there are 1 + MAX_LAYER_PUSH_POP_FUNCTIONS layer ids because we still have
// even if we will never have a push or pop function for it // 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 uint8_t layer_ids[1 + MAX_LAYER_PUSH_POP_FUNCTIONS];
static void layer_push(uint8_t local_id) { 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 // Only the topmost layer on the stack should be in sticky once state, pop
// the top layer if it is in sticky once state // the top layer if it is in sticky once state
uint8_t topSticky = main_layers_peek_sticky(0); 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)); main_layers_pop_id(main_layers_peek(0));
} }
layer_ids[local_id] = main_layers_push(keycode, eStickyNone); 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) { static void layer_sticky(uint8_t local_id) {
uint8_t keycode = kb_layout_get(LAYER, ROW, COL); uint8_t keycode = kb_layout_get(LAYER, ROW, COL);
if (IS_PRESSED) if (IS_PRESSED) {
{
uint8_t topLayer = main_layers_peek(0); uint8_t topLayer = main_layers_peek(0);
uint8_t topSticky = main_layers_peek_sticky(0); uint8_t topSticky = main_layers_peek_sticky(0);
main_layers_pop_id(layer_ids[local_id]); main_layers_pop_id(layer_ids[local_id]);
if (topLayer == local_id) if (topLayer == local_id) {
{
if (topSticky == eStickyOnceUp) if (topSticky == eStickyOnceUp)
layer_ids[local_id] = main_layers_push(keycode, eStickyLock); layer_ids[local_id] = main_layers_push(keycode, eStickyLock);
} }
else else
{ {
// only the topmost layer on the stack should be in sticky once state // 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]); main_layers_pop_id(layer_ids[topLayer]);
} }
layer_ids[local_id] = main_layers_push(keycode, eStickyOnceDown); 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 topLayer = main_layers_peek(0);
uint8_t topSticky = main_layers_peek_sticky(0); uint8_t topSticky = main_layers_peek_sticky(0);
if (topLayer == local_id) if (topLayer == local_id) {
{ if (topSticky == eStickyOnceDown) {
if (topSticky == eStickyOnceDown)
{
// When releasing this sticky key, pop the layer always // When releasing this sticky key, pop the layer always
main_layers_pop_id(layer_ids[local_id]); 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) // If no key defined for this layer (a non-transparent key)
// was pressed, push the layer again, but in the // was pressed, push the layer again, but in the
// StickyOnceUp state // StickyOnceUp state

View File

@ -100,6 +100,7 @@ int main(void) {
main_arg_row = row; main_arg_row = row;
main_arg_col = col; main_arg_col = col;
main_arg_layer_offset = 0; main_arg_layer_offset = 0;
main_arg_trans_key_pressed = false;
main_exec_key(); main_exec_key();
} }
} }
@ -176,7 +177,6 @@ void main_exec_key(void) {
? kb_layout_press_get(layer, row, col) ? kb_layout_press_get(layer, row, col)
: kb_layout_release_get(layer, row, col) ); : kb_layout_release_get(layer, row, col) );
main_arg_trans_key_pressed = false;
if (key_function) if (key_function)
(*key_function)(); (*key_function)();