5 #include "action_layer.h"
18 uint32_t default_layer_state = 0;
20 static void default_layer_state_set(uint32_t state)
22 debug("default_layer_state: ");
23 default_layer_debug(); debug(" to ");
24 default_layer_state = state;
25 default_layer_debug(); debug("\n");
26 clear_keyboard_but_mods(); // To avoid stuck keys
29 void default_layer_debug(void)
31 dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state));
34 void default_layer_set(uint32_t state)
36 default_layer_state_set(state);
39 #ifndef NO_ACTION_LAYER
40 void default_layer_or(uint32_t state)
42 default_layer_state_set(default_layer_state | state);
44 void default_layer_and(uint32_t state)
46 default_layer_state_set(default_layer_state & state);
48 void default_layer_xor(uint32_t state)
50 default_layer_state_set(default_layer_state ^ state);
55 #ifndef NO_ACTION_LAYER
59 uint32_t layer_state = 0;
61 static void layer_state_set(uint32_t state)
63 dprint("layer_state: ");
64 layer_debug(); dprint(" to ");
66 hook_layer_change(layer_state);
67 layer_debug(); dprintln();
68 clear_keyboard_but_mods(); // To avoid stuck keys
71 void layer_clear(void)
76 void layer_move(uint8_t layer)
78 layer_state_set(1UL<<layer);
81 void layer_on(uint8_t layer)
83 layer_state_set(layer_state | (1UL<<layer));
86 void layer_off(uint8_t layer)
88 layer_state_set(layer_state & ~(1UL<<layer));
91 void layer_invert(uint8_t layer)
93 layer_state_set(layer_state ^ (1UL<<layer));
96 void layer_or(uint32_t state)
98 layer_state_set(layer_state | state);
100 void layer_and(uint32_t state)
102 layer_state_set(layer_state & state);
104 void layer_xor(uint32_t state)
106 layer_state_set(layer_state ^ state);
109 void layer_debug(void)
111 dprintf("%08lX(%u)", layer_state, biton32(layer_state));
117 action_t layer_switch_get_action(keypos_t key)
119 action_t action = { .code = ACTION_TRANSPARENT };
121 #ifndef NO_ACTION_LAYER
122 uint32_t layers = layer_state | default_layer_state;
123 /* check top layer first */
124 for (int8_t i = 31; i >= 0; i--) {
125 if (layers & (1UL<<i)) {
126 action = action_for_key(i, key);
127 if (action.code != ACTION_TRANSPARENT) {
132 /* fall back to layer 0 */
133 action = action_for_key(0, key);
136 action = action_for_key(biton32(default_layer_state), key);