diff options
Diffstat (limited to 'common/layer_stack.c')
| -rw-r--r-- | common/layer_stack.c | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/common/layer_stack.c b/common/layer_stack.c deleted file mode 100644 index 0076bf779..000000000 --- a/common/layer_stack.c +++ /dev/null | |||
| @@ -1,108 +0,0 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include "keyboard.h" | ||
| 3 | #include "layer_stack.h" | ||
| 4 | #include "debug.h" | ||
| 5 | |||
| 6 | |||
| 7 | static uint8_t top_layer = 0; | ||
| 8 | |||
| 9 | /* [0] always works as sentinel and not used for store.*/ | ||
| 10 | static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; | ||
| 11 | |||
| 12 | |||
| 13 | void layer_stack_clear(void) | ||
| 14 | { | ||
| 15 | for (uint8_t i = 0; i < LAYER_STACK_SIZE; i++) { | ||
| 16 | layer_stack[i] = (layer_item_t){ .layer = 0, | ||
| 17 | .next = 0, | ||
| 18 | .used = false }; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | bool layer_stack_push(uint8_t layer) | ||
| 23 | { | ||
| 24 | for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { | ||
| 25 | if (!layer_stack[i].used) { | ||
| 26 | layer_stack[i] = (layer_item_t){ .layer = layer, | ||
| 27 | .next = top_layer, | ||
| 28 | .used = true }; | ||
| 29 | top_layer = i; | ||
| 30 | return true; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | bool layer_stack_pop(void) | ||
| 37 | { | ||
| 38 | if (layer_stack[top_layer].used) { | ||
| 39 | uint8_t popped = top_layer; | ||
| 40 | top_layer = layer_stack[popped].next; | ||
| 41 | layer_stack[popped] = (layer_item_t){}; | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | return false; | ||
| 45 | } | ||
| 46 | |||
| 47 | bool layer_stack_remove(uint8_t layer) | ||
| 48 | { | ||
| 49 | if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) { | ||
| 50 | layer_stack_pop(); | ||
| 51 | debug("layer_stack_remove: top_layer\n"); | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | |||
| 55 | for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) { | ||
| 56 | debug("layer_stack_remove: ["); debug_dec(i); debug("]"); | ||
| 57 | debug_dec(layer_stack[i].layer); debug("\n"); | ||
| 58 | uint8_t removed = layer_stack[i].next; | ||
| 59 | if (layer_stack[removed].used && layer_stack[removed].layer == layer) { | ||
| 60 | layer_stack[i].next = layer_stack[removed].next; | ||
| 61 | layer_stack[removed] = (layer_item_t){}; | ||
| 62 | debug("layer_stack_remove: removed.\n"); | ||
| 63 | return true; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | return false; | ||
| 67 | } | ||
| 68 | |||
| 69 | bool layer_stack_remove_then_push(uint8_t layer) | ||
| 70 | { | ||
| 71 | layer_stack_remove(layer); | ||
| 72 | return layer_stack_push(layer); | ||
| 73 | } | ||
| 74 | |||
| 75 | bool layer_stack_remove_or_push(uint8_t layer) | ||
| 76 | { | ||
| 77 | return (layer_stack_remove(layer)) || layer_stack_push(layer); | ||
| 78 | } | ||
| 79 | |||
| 80 | void layer_stack_debug(void) | ||
| 81 | { | ||
| 82 | debug("layer_stack: "); | ||
| 83 | layer_item_t item = layer_stack[top_layer]; | ||
| 84 | while (item.used) { | ||
| 85 | debug_dec(item.layer); | ||
| 86 | debug("["); debug_dec(item.next); debug("] "); | ||
| 87 | item = layer_stack[item.next]; | ||
| 88 | } | ||
| 89 | debug("\n"); | ||
| 90 | } | ||
| 91 | |||
| 92 | action_t layer_stack_get_action(key_t key) | ||
| 93 | { | ||
| 94 | action_t action; | ||
| 95 | action.code = ACTION_TRANSPARENT; | ||
| 96 | |||
| 97 | /* layer stack */ | ||
| 98 | for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { | ||
| 99 | action = action_for_key(i.layer, key); | ||
| 100 | if (action.code != ACTION_TRANSPARENT) { | ||
| 101 | layer_stack_debug(); | ||
| 102 | debug("layer_stack: used. "); debug_dec(i.layer); debug("\n"); | ||
| 103 | return action; | ||
| 104 | } | ||
| 105 | debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); | ||
| 106 | } | ||
| 107 | return action; | ||
| 108 | } | ||
