|
|
|
|
|
|
|
|
#include "layer_switch.h" |
|
|
#include "layer_switch.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* default layer indicates base layer */ |
|
|
|
|
|
uint8_t default_layer = 0; |
|
|
|
|
|
/* current layer indicates active layer at this time */ |
|
|
|
|
|
uint8_t current_layer = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void process_action(keyrecord_t *record); |
|
|
static void process_action(keyrecord_t *record); |
|
|
static bool process_tapping(keyrecord_t *record); |
|
|
static bool process_tapping(keyrecord_t *record); |
|
|
static void waiting_buffer_scan_tap(void); |
|
|
static void waiting_buffer_scan_tap(void); |
|
|
|
|
|
|
|
|
return action; |
|
|
return action; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* current layer: 0 means default layer */ |
|
|
|
|
|
if (current_layer) { |
|
|
|
|
|
action = action_for_key(current_layer, key); |
|
|
|
|
|
if (action.code != ACTION_TRANSPARENT) { |
|
|
|
|
|
debug("current layer: used. "); debug_dec(current_layer); debug("\n"); |
|
|
|
|
|
return action; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* default layer */ |
|
|
/* default layer */ |
|
|
debug("default layer: used. \n"); |
|
|
|
|
|
|
|
|
//debug("get_aciton: default layer: "); debug_dec(default_layer); debug("\n"); |
|
|
action = action_for_key(default_layer, key); |
|
|
action = action_for_key(default_layer, key); |
|
|
return action; |
|
|
return action; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (IS_NOEVENT(event)) { return; } |
|
|
if (IS_NOEVENT(event)) { return; } |
|
|
|
|
|
|
|
|
action_t action = get_action(event.key); |
|
|
action_t action = get_action(event.key); |
|
|
debug("ACTION: "); debug_action(action); debug("\n"); |
|
|
|
|
|
|
|
|
debug("ACTION: "); debug_action(action); debug(" "); |
|
|
|
|
|
layer_switch_debug(); debug("["); debug_dec(default_layer); debug("]\n"); |
|
|
|
|
|
|
|
|
switch (action.kind.id) { |
|
|
switch (action.kind.id) { |
|
|
/* Key and Mods */ |
|
|
/* Key and Mods */ |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
/* Layer key */ |
|
|
/* Layer key */ |
|
|
case ACT_LAYER: |
|
|
|
|
|
|
|
|
case ACT_LAYER_SET: |
|
|
switch (action.layer.code) { |
|
|
switch (action.layer.code) { |
|
|
case LAYER_MOMENTARY: /* momentary */ |
|
|
case LAYER_MOMENTARY: /* momentary */ |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// NOTE: This is needed by legacy keymap support |
|
|
// NOTE: This is needed by legacy keymap support |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(0); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_PRESS: |
|
|
case LAYER_ON_PRESS: |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_RELEASE: |
|
|
case LAYER_ON_RELEASE: |
|
|
if (!event.pressed) { |
|
|
if (!event.pressed) { |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_BOTH: |
|
|
case LAYER_ON_BOTH: |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
break; |
|
|
break; |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (tap_count >= TAPPING_TOGGLE) { |
|
|
if (tap_count >= TAPPING_TOGGLE) { |
|
|
debug("LAYER_PRESSED: tap toggle.\n"); |
|
|
debug("LAYER_PRESSED: tap toggle.\n"); |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_PRESS: |
|
|
case LAYER_SET_DEFAULT_ON_PRESS: |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
default_layer = action.layer.val; |
|
|
default_layer = action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(0); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_RELEASE: |
|
|
case LAYER_SET_DEFAULT_ON_RELEASE: |
|
|
if (!event.pressed) { |
|
|
if (!event.pressed) { |
|
|
default_layer = action.layer.val; |
|
|
default_layer = action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(0); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_BOTH: |
|
|
case LAYER_SET_DEFAULT_ON_BOTH: |
|
|
default_layer = action.layer.val; |
|
|
default_layer = action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(0); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
/* tap key */ |
|
|
/* tap key */ |
|
|
|
|
|
|
|
|
register_code(action.layer.code); |
|
|
register_code(action.layer.code); |
|
|
} else { |
|
|
} else { |
|
|
debug("LAYER_SET: No tap: layer_set(on press)\n"); |
|
|
debug("LAYER_SET: No tap: layer_set(on press)\n"); |
|
|
layer_switch(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// NOTE: This is needed by legacy keymap support |
|
|
// NOTE: This is needed by legacy keymap support |
|
|
debug("LAYER_SET: No tap: return to default layer(on release)\n"); |
|
|
debug("LAYER_SET: No tap: return to default layer(on release)\n"); |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
switch (action.layer.code) { |
|
|
switch (action.layer.code) { |
|
|
case LAYER_MOMENTARY: /* momentary */ |
|
|
case LAYER_MOMENTARY: /* momentary */ |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
layer_switch(current_layer | action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() | action.layer.val); |
|
|
} else { |
|
|
} else { |
|
|
layer_switch(current_layer & ~action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() & ~action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_PRESS: |
|
|
case LAYER_ON_PRESS: |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_RELEASE: |
|
|
case LAYER_ON_RELEASE: |
|
|
if (!event.pressed) { |
|
|
if (!event.pressed) { |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_BOTH: |
|
|
case LAYER_ON_BOTH: |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
break; |
|
|
break; |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
debug("LAYER_BIT: tap toggle(press).\n"); |
|
|
debug("LAYER_BIT: tap toggle(press).\n"); |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (tap_count <= TAPPING_TOGGLE) { |
|
|
if (tap_count <= TAPPING_TOGGLE) { |
|
|
debug("LAYER_BIT: tap toggle(release).\n"); |
|
|
debug("LAYER_BIT: tap toggle(release).\n"); |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_PRESS: |
|
|
case LAYER_SET_DEFAULT_ON_PRESS: |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(default_layer); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_RELEASE: |
|
|
case LAYER_SET_DEFAULT_ON_RELEASE: |
|
|
if (!event.pressed) { |
|
|
if (!event.pressed) { |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(default_layer); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_SET_DEFAULT_ON_BOTH: |
|
|
case LAYER_SET_DEFAULT_ON_BOTH: |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
default_layer = default_layer ^ action.layer.val; |
|
|
layer_switch(0); |
|
|
|
|
|
|
|
|
layer_switch_move(default_layer); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
// tap key |
|
|
// tap key |
|
|
|
|
|
|
|
|
register_code(action.layer.code); |
|
|
register_code(action.layer.code); |
|
|
} else { |
|
|
} else { |
|
|
debug("LAYER_BIT: No tap: layer_bit(on press)\n"); |
|
|
debug("LAYER_BIT: No tap: layer_bit(on press)\n"); |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
|
|
|
|
|
|
unregister_code(action.layer.code); |
|
|
unregister_code(action.layer.code); |
|
|
} else { |
|
|
} else { |
|
|
debug("LAYER_BIT: No tap: layer_bit(on release)\n"); |
|
|
debug("LAYER_BIT: No tap: layer_bit(on release)\n"); |
|
|
layer_switch(current_layer ^ action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_PRESS: |
|
|
case LAYER_ON_PRESS: |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_RELEASE: |
|
|
case LAYER_ON_RELEASE: |
|
|
if (!event.pressed) { |
|
|
if (!event.pressed) { |
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case LAYER_ON_BOTH: |
|
|
case LAYER_ON_BOTH: |
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
break; |
|
|
break; |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
|
|
if (event.pressed) { |
|
|
if (event.pressed) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
if (tap_count < TAPPING_TOGGLE) { |
|
|
debug("LAYER_SWITCH: tap toggle(press).\n"); |
|
|
debug("LAYER_SWITCH: tap toggle(press).\n"); |
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (tap_count <= TAPPING_TOGGLE) { |
|
|
if (tap_count <= TAPPING_TOGGLE) { |
|
|
debug("LAYER_SWITCH: tap toggle(release).\n"); |
|
|
debug("LAYER_SWITCH: tap toggle(release).\n"); |
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
debug("LAYER_SWITCH: Tap: register_code\n"); |
|
|
debug("LAYER_SWITCH: Tap: register_code\n"); |
|
|
register_code(action.layer.code); |
|
|
register_code(action.layer.code); |
|
|
} else { |
|
|
} else { |
|
|
debug("LAYER_SWITCH: No tap: layer_switch(on press)\n"); |
|
|
|
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
debug("LAYER_SWITCH: No tap: layer_switch on press\n"); |
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
|
|
debug("LAYER_SWITCH: Tap: unregister_code\n"); |
|
|
debug("LAYER_SWITCH: Tap: unregister_code\n"); |
|
|
unregister_code(action.layer.code); |
|
|
unregister_code(action.layer.code); |
|
|
} else { |
|
|
} else { |
|
|
debug("LAYER_SWITCH: No tap: layer_switch(on release)\n"); |
|
|
|
|
|
layer_switch_inv(action.layer.val); |
|
|
|
|
|
|
|
|
debug("LAYER_SWITCH: No tap: layer_switch on release\n"); |
|
|
|
|
|
layer_switch_invert(action.layer.val); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
host_last_sysytem_report() || host_last_consumer_report()); |
|
|
host_last_sysytem_report() || host_last_consumer_report()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: rename or reinpl with new layer_switch.c |
|
|
|
|
|
void layer_switch(uint8_t new_layer) |
|
|
|
|
|
{ |
|
|
|
|
|
if (current_layer != new_layer) { |
|
|
|
|
|
debug("Layer Switch: "); debug_hex(current_layer); |
|
|
|
|
|
debug(" -> "); debug_hex(new_layer); debug("\n"); |
|
|
|
|
|
|
|
|
|
|
|
current_layer = new_layer; |
|
|
|
|
|
clear_keyboard_but_mods(); // To avoid stuck keys |
|
|
|
|
|
// NOTE: update mods with full scan of matrix? if modifier changes between layers |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool is_tap_key(key_t key) |
|
|
bool is_tap_key(key_t key) |
|
|
{ |
|
|
{ |
|
|
action_t action = get_action(key); |
|
|
action_t action = get_action(key); |
|
|
|
|
|
|
|
|
case ACT_LMODS_TAP: |
|
|
case ACT_LMODS_TAP: |
|
|
case ACT_RMODS_TAP: |
|
|
case ACT_RMODS_TAP: |
|
|
return true; |
|
|
return true; |
|
|
case ACT_LAYER: |
|
|
|
|
|
|
|
|
case ACT_LAYER_SET: |
|
|
case ACT_LAYER_BIT: |
|
|
case ACT_LAYER_BIT: |
|
|
switch (action.layer.code) { |
|
|
switch (action.layer.code) { |
|
|
case LAYER_MOMENTARY: |
|
|
case LAYER_MOMENTARY: |
|
|
|
|
|
|
|
|
case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; |
|
|
case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; |
|
|
case ACT_USAGE: debug("ACT_USAGE"); break; |
|
|
case ACT_USAGE: debug("ACT_USAGE"); break; |
|
|
case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
|
|
case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
|
|
case ACT_LAYER: debug("ACT_LAYER"); break; |
|
|
|
|
|
|
|
|
case ACT_LAYER_SET: debug("ACT_LAYER_SET"); break; |
|
|
case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; |
|
|
case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; |
|
|
case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; |
|
|
|
|
|
|
|
|
case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; |
|
|
case ACT_MACRO: debug("ACT_MACRO"); break; |
|
|
case ACT_MACRO: debug("ACT_MACRO"); break; |
|
|
case ACT_COMMAND: debug("ACT_COMMAND"); break; |
|
|
case ACT_COMMAND: debug("ACT_COMMAND"); break; |
|
|
case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
|
|
case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |