more refactor

master
Stefan Dorn 2016-02-04 09:22:40 +00:00
parent 01c9587d31
commit f0da34b909
3 changed files with 84 additions and 62 deletions

View File

@ -64,26 +64,21 @@ void kbfun_transparent(void) {
* layer push/pop functions
* ------------------------------------------------------------------------- */
/*
* While there are only KB_LAYERS number of layer functions,
* there are 1 + KB_LAYERS 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 + KB_LAYERS];
/*
* Push a layer element containing the layer value specified in the keymap to
* the top of the stack, and record the id of that layer element
*/
static void layer_push(uint8_t layer) {
main_layers_pop_id(layer_ids[layer]);
// FIXME necessary?
main_layers_disable(layer);
// 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_top_sticky();
if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) {
main_layers_disable_top();
}
layer_ids[layer] = main_layers_push(layer, eStickyNone);
main_layers_enable(layer, eStickyNone);
}
/*
@ -122,17 +117,17 @@ static void layer_sticky(uint8_t layer) {
uint8_t topSticky = main_layers_top_sticky();
if (main_arg_is_pressed) {
main_layers_pop_id(layer_ids[layer]);
main_layers_disable(layer);
if (topLayer == layer) {
if (topSticky == eStickyOnceUp) {
layer_ids[layer] = main_layers_push(layer, eStickyLock);
main_layers_enable(layer, eStickyLock);
}
} else {
// only the topmost layer on the stack should be in sticky once state
if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) {
main_layers_disable_top();
}
layer_ids[layer] = main_layers_push(layer, eStickyOnceDown);
main_layers_enable(layer, eStickyOnceDown);
// this should be the only place we care about this flag being cleared
main_arg_any_non_trans_key_pressed = false;
}
@ -140,12 +135,12 @@ static void layer_sticky(uint8_t layer) {
if (topLayer == layer) {
if (topSticky == eStickyOnceDown) {
// When releasing this sticky key, pop the layer always
main_layers_pop_id(layer_ids[layer]);
main_layers_disable(layer);
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
layer_ids[layer] = main_layers_push(layer, eStickyOnceUp);
main_layers_enable(layer, eStickyOnceUp);
}
}
}
@ -158,8 +153,7 @@ static void layer_sticky(uint8_t layer) {
* touching any other elements)
*/
static void layer_pop(uint8_t layer) {
main_layers_pop_id(layer_ids[layer]);
layer_ids[layer] = 0;
main_layers_disable(layer);
}
// push/pop functions for all layers

View File

@ -151,41 +151,56 @@ struct layer_stack {
struct layer_stack layers_stack[MAX_ACTIVE_LAYERS];
uint8_t layers_head = 0;
uint8_t layers_ids_in_use[MAX_ACTIVE_LAYERS] = {true};
uint8_t layer_ids[1 + KB_LAYERS];
// ----------------------------------------------------------------------------
// return the highest active layer
uint8_t main_layers_top_layer() {
return layers_stack[layers_head].layer;
// return layers_top;
}
// return if highest active layer is sticky
uint8_t main_layers_top_sticky() {
return layers_stack[layers_head].sticky;
// return layers[layers_top].sticky;
}
// disable the highest active layer
void main_layers_disable_top() {
// TODO remove
main_layers_pop_id(layers_head);
main_layers_disable(layers_top);
}
// enable a layer
void main_layers_enable(uint8_t layer, uint8_t sticky) {
// TODO remove
layer_ids[layer] = main_layers_push(layer, sticky);
// TODO
if (layer > layers_top) {
layers_top = layer;
}
}
// disable a layer
void main_layers_disable(uint8_t layer) {
// TODO remove
main_layers_pop_id(layer_ids[layer]);
layer_ids[layer] = 0;
// TODO
if (layer == layers_top) {
// FIXME
}
}
// ----------------------------------------------------------------------------
/*
* Exec key
* - Execute the keypress or keyrelease function (if it exists) of the key at
* the current possition.
*/
// execute the keypress or keyrelease function (if it exists) of the key at the current possition
void main_exec_key(void) {
void (*key_function)(void) =
( (main_arg_is_pressed)
@ -203,6 +218,16 @@ void main_exec_key(void) {
}
}
// TODO remove all this
/*
* peek()
*

View File

@ -8,49 +8,52 @@
#ifndef MAIN_h
#define MAIN_h
#define MAIN_h
#include <stdbool.h>
#include <stdint.h>
#include "./keyboard/matrix.h"
#include <stdbool.h>
#include <stdint.h>
#include "./keyboard/layout.h"
#include "./keyboard/matrix.h"
// --------------------------------------------------------------------
// --------------------------------------------------------------------
typedef enum StickyState
{
eStickyNone,
eStickyOnceDown,
eStickyOnceUp,
eStickyLock
} StickyState;
typedef enum StickyState
{
eStickyNone,
eStickyOnceDown,
eStickyOnceUp,
eStickyLock
} StickyState;
extern bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS];
extern bool (*main_kb_was_pressed)[KB_ROWS][KB_COLUMNS];
extern bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS];
extern bool (*main_kb_was_pressed)[KB_ROWS][KB_COLUMNS];
extern uint8_t main_layers_pressed[KB_ROWS][KB_COLUMNS];
extern uint8_t main_arg_layer;
extern uint8_t main_arg_layer_offset;
extern uint8_t main_arg_row;
extern uint8_t main_arg_col;
extern bool main_arg_is_pressed;
extern bool main_arg_was_pressed;
extern bool main_arg_any_non_trans_key_pressed;
extern bool main_arg_trans_key_pressed;
extern uint8_t main_layers_pressed[KB_ROWS][KB_COLUMNS];
// --------------------------------------------------------------------
extern uint8_t main_loop_row;
extern uint8_t main_loop_col;
void main_exec_key (void);
extern uint8_t main_arg_layer;
extern uint8_t main_arg_layer_offset;
extern uint8_t main_arg_row;
extern uint8_t main_arg_col;
extern bool main_arg_is_pressed;
extern bool main_arg_was_pressed;
extern bool main_arg_any_non_trans_key_pressed;
extern bool main_arg_trans_key_pressed;
uint8_t main_layers_top_layer (void);
uint8_t main_layers_top_sticky (void);
void main_layers_enable (uint8_t layer, uint8_t sticky);
void main_layers_disable (uint8_t layer);
void main_layers_disable_top (void);
// --------------------------------------------------------------------
// TODO remove all this
uint8_t main_layers_peek (uint8_t offset);
uint8_t main_layers_push (uint8_t layer, uint8_t sticky);
void main_layers_pop_id (uint8_t id);
extern uint8_t layer_ids[1 + KB_LAYERS];
void main_exec_key (void);
uint8_t main_layers_top_layer (void);
uint8_t main_layers_top_sticky (void);
uint8_t main_layers_peek (uint8_t offset);
uint8_t main_layers_push (uint8_t layer, uint8_t sticky);
void main_layers_pop_id (uint8_t id);
#endif