aboutsummaryrefslogtreecommitdiff
path: root/common/layer_switch.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/layer_switch.c')
-rw-r--r--common/layer_switch.c66
1 files changed, 51 insertions, 15 deletions
diff --git a/common/layer_switch.c b/common/layer_switch.c
index 9bc804e64..22bfb34f6 100644
--- a/common/layer_switch.c
+++ b/common/layer_switch.c
@@ -2,50 +2,88 @@
2#include "keyboard.h" 2#include "keyboard.h"
3#include "action.h" 3#include "action.h"
4#include "debug.h" 4#include "debug.h"
5#include "util.h"
5#include "layer_switch.h" 6#include "layer_switch.h"
6 7
7 8
9uint8_t default_layer = 0;
10
8uint16_t layer_switch_stat = 0; 11uint16_t layer_switch_stat = 0;
9 12
10 13
11uint16_t layer_switch_stat_get(void) 14uint16_t layer_switch_get_stat(void)
12{ 15{
13 return layer_switch_stat; 16 return layer_switch_stat;
14} 17}
15 18
16void layer_switch_stat_set(uint16_t stat) 19/* return highest layer whose state is on */
20uint8_t layer_switch_get_layer(void)
21{
22 return biton16(layer_switch_stat);
23}
24
25static inline void stat_set(uint16_t stat)
17{ 26{
27 debug("layer_switch: ");
28 layer_switch_debug(); debug(" to ");
29
18 layer_switch_stat = stat; 30 layer_switch_stat = stat;
19 layer_switch_debug(); 31
32 layer_switch_debug(); debug("\n");
33
34 clear_keyboard_but_mods(); // To avoid stuck keys
20} 35}
21 36
22void layer_switch_clear(void) 37void layer_switch_clear(void)
23{ 38{
24 layer_switch_stat = 0; 39 stat_set(0);
25 layer_switch_debug(); 40}
41
42
43void layer_switch_set(uint16_t stat)
44{
45 stat_set(stat);
46}
47
48void layer_switch_move(uint8_t layer)
49{
50 if (layer)
51 stat_set(1<<layer);
52 else
53 stat_set(0); // fall back to default layer
26} 54}
27 55
28void layer_switch_on(uint8_t layer) 56void layer_switch_on(uint8_t layer)
29{ 57{
30 layer_switch_stat |= (1<<layer); 58 stat_set(layer_switch_stat | (1<<layer));
31 layer_switch_debug();
32} 59}
33 60
34void layer_switch_off(uint8_t layer) 61void layer_switch_off(uint8_t layer)
35{ 62{
36 layer_switch_stat &= ~(1<<layer); 63 stat_set(layer_switch_stat & ~(1<<layer));
37 layer_switch_debug(); 64}
65
66void layer_switch_invert(uint8_t layer)
67{
68 stat_set(layer_switch_stat ^ (1<<layer));
38} 69}
39 70
40void layer_switch_inv(uint8_t layer) 71void layer_switch_or(uint16_t stat)
72{
73 stat_set(layer_switch_stat | stat);
74}
75void layer_switch_and(uint16_t stat)
76{
77 stat_set(layer_switch_stat & stat);
78}
79void layer_switch_xor(uint16_t stat)
41{ 80{
42 layer_switch_stat ^= (1<<layer); 81 stat_set(layer_switch_stat ^ stat);
43 layer_switch_debug();
44} 82}
45 83
46void layer_switch_debug(void) 84void layer_switch_debug(void)
47{ 85{
48 debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n"); 86 debug_hex16(layer_switch_stat); debug("("); debug_dec(layer_switch_get_layer()); debug(")");
49} 87}
50 88
51action_t layer_switch_get_action(key_t key) 89action_t layer_switch_get_action(key_t key)
@@ -58,8 +96,6 @@ action_t layer_switch_get_action(key_t key)
58 if (layer_switch_stat & (1<<i)) { 96 if (layer_switch_stat & (1<<i)) {
59 action = action_for_key(i, key); 97 action = action_for_key(i, key);
60 if (action.code != ACTION_TRANSPARENT) { 98 if (action.code != ACTION_TRANSPARENT) {
61 layer_switch_debug();
62 debug("layer_switch: used. "); debug_dec(i); debug("\n");
63 return action; 99 return action;
64 } 100 }
65 } 101 }