]>
git.gir.st - tmk_keyboard.git/blob - common/layer_switch.c
6 #include "layer_switch.h"
9 uint8_t default_layer
= 0;
11 uint16_t layer_switch_stat
= 0;
14 uint16_t layer_switch_get_stat(void)
16 return layer_switch_stat
;
19 /* return highest layer whose state is on */
20 uint8_t layer_switch_get_layer(void)
22 return biton16(layer_switch_stat
);
25 static inline void stat_set(uint16_t stat
)
27 debug("layer_switch: ");
28 layer_switch_debug(); debug(" to ");
30 layer_switch_stat
= stat
;
32 layer_switch_debug(); debug("\n");
34 clear_keyboard_but_mods(); // To avoid stuck keys
37 void layer_switch_clear(void)
43 void layer_switch_set(uint16_t stat
)
48 void layer_switch_move(uint8_t layer
)
53 stat_set(0); // fall back to default layer
56 void layer_switch_on(uint8_t layer
)
58 stat_set(layer_switch_stat
| (1<<layer
));
61 void layer_switch_off(uint8_t layer
)
63 stat_set(layer_switch_stat
& ~(1<<layer
));
66 void layer_switch_invert(uint8_t layer
)
68 stat_set(layer_switch_stat
^ (1<<layer
));
71 void layer_switch_or(uint16_t stat
)
73 stat_set(layer_switch_stat
| stat
);
75 void layer_switch_and(uint16_t stat
)
77 stat_set(layer_switch_stat
& stat
);
79 void layer_switch_xor(uint16_t stat
)
81 stat_set(layer_switch_stat
^ stat
);
84 void layer_switch_debug(void)
86 debug_hex16(layer_switch_stat
); debug("("); debug_dec(layer_switch_get_layer()); debug(")");
89 action_t
layer_switch_get_action(key_t key
)
92 action
.code
= ACTION_TRANSPARENT
;
94 /* higher layer first */
95 for (int8_t i
= 15; i
>= 0; i
--) {
96 if (layer_switch_stat
& (1<<i
)) {
97 action
= action_for_key(i
, key
);
98 if (action
.code
!= ACTION_TRANSPARENT
) {