- for (int r = 0; r < MATRIX_ROWS; r++) {
- matrix_row_t matrix_row = matrix_get_row(r);
- for (int c = 0; c < MATRIX_COLS; c++) {
- if (matrix_row && (1<<c)) {
- if (IS_KEY(get_keycode((key_t){ .row = r, .col = c }))) {
- return true;
- }
- }
- }
+ if (!IS_FN(code)) return;
+ fn_state_bits |= FN_BIT(code);
+ uint8_t new_layer = (fn_state_bits ? keymap_fn_layer(biton(fn_state_bits)) : default_layer);
+ if (current_layer != new_layer) {
+ Kdebug("Layer Switch(on): "); Kdebug_hex(current_layer);
+ Kdebug(" -> "); Kdebug_hex(new_layer); Kdebug("\n");
+
+ clear_keyboard_but_mods();
+ current_layer = new_layer;
+ }
+}
+
+static bool layer_switch_off(uint8_t code)
+{
+ if (!IS_FN(code)) return false;
+ fn_state_bits &= ~FN_BIT(code);
+ uint8_t new_layer = (fn_state_bits ? keymap_fn_layer(biton(fn_state_bits)) : default_layer);
+ if (current_layer != new_layer) {
+ Kdebug("Layer Switch(off): "); Kdebug_hex(current_layer);
+ Kdebug(" -> "); Kdebug_hex(new_layer); Kdebug("\n");
+
+ clear_keyboard_but_mods();
+ current_layer = new_layer;
+ return true;