aboutsummaryrefslogtreecommitdiffstats
path: root/common/layer_switch.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/layer_switch.c')
-rw-r--r--common/layer_switch.c122
1 files changed, 67 insertions, 55 deletions
diff --git a/common/layer_switch.c b/common/layer_switch.c
index 359e6b9d8..9905741f4 100644
--- a/common/layer_switch.c
+++ b/common/layer_switch.c
@@ -7,94 +7,103 @@
/*
- * Default Layer (0-15)
+ * Default Layer State
*/
-uint8_t default_layer = 0;
+uint32_t default_layer_state = 0;
-void default_layer_set(uint8_t layer)
+static void default_layer_state_set(uint32_t state)
{
- debug("default_layer_set: ");
- debug_dec(default_layer); debug(" to ");
-
- default_layer = layer;
-
- debug_dec(default_layer); debug("\n");
-
+ debug("default_layer_state: ");
+ default_layer_debug(); debug(" to ");
+ default_layer_state = state;
+ default_layer_debug(); debug("\n");
clear_keyboard_but_mods(); // To avoid stuck keys
}
-
-#ifndef NO_ACTION_LAYER
-/*
- * Keymap Layer (0-15)
- */
-uint16_t keymap_stat = 0;
-
-/* return highest layer whose state is on */
-uint8_t keymap_get_layer(void)
+void default_layer_debug(void)
{
- return biton16(keymap_stat);
+ debug_hex32(default_layer_state);
+ debug("("); debug_dec(biton32(default_layer_state)); debug(")");
}
-static void keymap_stat_set(uint16_t stat)
+void default_layer_set(uint8_t layer)
{
- debug("keymap: ");
- keymap_debug(); debug(" to ");
+ default_layer_state_set(1UL<<layer);
+}
- keymap_stat = stat;
+#ifndef NO_ACTION_LAYER
+void default_layer_or(uint32_t state)
+{
+ default_layer_state_set(default_layer_state | state);
+}
+void default_layer_and(uint32_t state)
+{
+ default_layer_state_set(default_layer_state & state);
+}
+void default_layer_xor(uint32_t state)
+{
+ default_layer_state_set(default_layer_state ^ state);
+}
+#endif
- keymap_debug(); debug("\n");
- clear_keyboard_but_mods(); // To avoid stuck keys
-}
+#ifndef NO_ACTION_LAYER
+/*
+ * Keymap Layer State
+ */
+uint32_t layer_state = 0;
-void keymap_clear(void)
+static void layer_state_set(uint32_t state)
{
- keymap_stat_set(0);
+ debug("layer_state: ");
+ layer_debug(); debug(" to ");
+ layer_state = state;
+ layer_debug(); debug("\n");
+ clear_keyboard_but_mods(); // To avoid stuck keys
}
-
-void keymap_set(uint16_t stat)
+void layer_clear(void)
{
- keymap_stat_set(stat);
+ layer_state_set(0);
}
-void keymap_move(uint8_t layer)
+void layer_move(uint8_t layer)
{
- keymap_stat_set(1<<layer);
+ layer_state_set(1UL<<layer);
}
-void keymap_on(uint8_t layer)
+void layer_on(uint8_t layer)
{
- keymap_stat_set(keymap_stat | (1<<layer));
+ layer_state_set(layer_state | (1UL<<layer));
}
-void keymap_off(uint8_t layer)
+void layer_off(uint8_t layer)
{
- keymap_stat_set(keymap_stat & ~(1<<layer));
+ layer_state_set(layer_state & ~(1UL<<layer));
}
-void keymap_invert(uint8_t layer)
+void layer_invert(uint8_t layer)
{
- keymap_stat_set(keymap_stat ^ (1<<layer));
+ layer_state_set(layer_state ^ (1UL<<layer));
}
-void keymap_or(uint16_t stat)
+void layer_or(uint32_t state)
{
- keymap_stat_set(keymap_stat | stat);
+ layer_state_set(layer_state | state);
}
-void keymap_and(uint16_t stat)
+void layer_and(uint32_t state)
{
- keymap_stat_set(keymap_stat & stat);
+ layer_state_set(layer_state & state);
}
-void keymap_xor(uint16_t stat)
+void layer_xor(uint32_t state)
{
- keymap_stat_set(keymap_stat ^ stat);
+ layer_state_set(layer_state ^ state);
}
-void keymap_debug(void)
+void layer_debug(void)
{
- debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")");
+ debug_hex32(layer_state);
+ debug("("); debug_dec(biton32(layer_state)); debug(")");
}
#endif
@@ -106,18 +115,21 @@ action_t layer_switch_get_action(key_t key)
action.code = ACTION_TRANSPARENT;
#ifndef NO_ACTION_LAYER
- /* keymap: top layer first */
- for (int8_t i = 15; i >= 0; i--) {
- if (keymap_stat & (1<<i)) {
+ uint32_t layers = layer_state | default_layer_state;
+ /* check top layer first */
+ for (int8_t i = 31; i >= 0; i--) {
+ if (layers & (1UL<<i)) {
action = action_for_key(i, key);
if (action.code != ACTION_TRANSPARENT) {
return action;
}
}
}
-#endif
-
- /* default layer */
- action = action_for_key(default_layer, key);
+ /* fall back to layer 0 */
+ action = action_for_key(0, key);
+ return action;
+#else
+ action = action_for_key(biton32(default_layer_state), key);
return action;
+#endif
}