From 0018e19f07661cbae722d64d94cdf6ee388252ff Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 14 Feb 2013 15:22:59 +0900 Subject: Add layer stack --- common/action.c | 255 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 211 insertions(+), 44 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 6528cd46c8..d0c9ddb0ad 100644 --- a/common/action.c +++ b/common/action.c @@ -163,6 +163,85 @@ static void oneshot_toggle(void) } +/* + * Layer stack + */ +#define LAYER_STACK_SIZE 8 +typedef struct { + uint8_t layer:4; + uint8_t next:3; + bool used; +} layer_item_t; + +static uint8_t top_layer = 0; +// [0] is sentinel and not used. [0] is null item. +static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; + +static bool layer_push(uint8_t layer) +{ + for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { + if (!layer_stack[i].used) { + layer_stack[i] = (layer_item_t){ .layer = layer, + .next = top_layer, + .used = true }; + top_layer = i; + return true; + } + } + return false; +} +static bool layer_pop(void) +{ + if (layer_stack[top_layer].used) { + uint8_t popped = top_layer; + top_layer = layer_stack[popped].next; + layer_stack[popped] = (layer_item_t){}; + return true; + } + return false; +} +static bool layer_remove(uint8_t layer) +{ + if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) { + layer_pop(); + debug("layer_remove: top_layer\n"); + return true; + } + + for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) { + debug("layer_remove: ["); debug_dec(i); debug("]"); + debug_dec(layer_stack[i].layer); debug("\n"); + uint8_t removed = layer_stack[i].next; + if (layer_stack[removed].used && layer_stack[removed].layer == layer) { + layer_stack[i].next = layer_stack[removed].next; + layer_stack[removed] = (layer_item_t){}; + debug("layer_remove: removed.\n"); + return true; + } + } + return false; +} +static bool layer_remove_then_push(uint8_t layer) +{ + layer_remove(layer); + return layer_push(layer); +} +static bool layer_remove_or_push(uint8_t layer) +{ + return (layer_remove(layer)) || layer_push(layer); +} +static void debug_layer_stack(void) +{ + debug("layer_stack: "); + layer_item_t item = layer_stack[top_layer]; + while (item.used) { + debug_dec(item.layer); + debug("["); debug_dec(item.next); debug("]"); + item = layer_stack[item.next]; + } + debug("\n"); +} + void action_exec(keyevent_t event) { @@ -209,13 +288,26 @@ void action_exec(keyevent_t event) static action_t get_action(key_t key) { - action_t action = action_for_key(current_layer, key); + action_t action; + + /* layer stack */ + for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { + action = action_for_key(i.layer, key); + if (action.code != ACTION_TRANSPARENT) { + debug_layer_stack(); + debug("layer_stack: used. "); debug_dec(i.layer); debug("\n"); + return action; + } + debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); + } - /* Transparently use default layer */ + /* current layer */ + action = action_for_key(current_layer, key); + + /* default layer */ if (action.code == ACTION_TRANSPARENT) { - // TODO: layer stacking - action = action_for_key(default_layer, key); debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); + action = action_for_key(default_layer, key); } return action; } @@ -287,7 +379,7 @@ static void process_action(keyrecord_t *record) } else { if (tap_count == 0) { debug("MODS_TAP: Oneshot: cancel/del_mods\n"); - // cancel oneshot by holding. + // cancel oneshot on hold oneshot_cancel(); del_mods(mods); } @@ -390,22 +482,8 @@ static void process_action(keyrecord_t *record) layer_switch(action.layer.val); } break; - case LAYER_DEFAULT: /* default layer */ - switch (action.layer.val) { - case DEFAULT_ON_BOTH: - layer_switch(default_layer); - break; - case DEFAULT_ON_PRESS: - if (event.pressed) { - layer_switch(default_layer); - } - break; - case DEFAULT_ON_RELEASE: - if (!event.pressed) { - layer_switch(default_layer); - } - break; - } + case LAYER_ON_BOTH: + layer_switch(action.layer.val); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { @@ -419,29 +497,39 @@ static void process_action(keyrecord_t *record) } } break; - case LAYER_CHANGE_DEFAULT: /* change default layer */ + case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { default_layer = action.layer.val; layer_switch(default_layer); } break; - default: /* switch layer on hold and key on tap*/ + case LAYER_SET_DEFAULT_ON_RELEASE: + if (!event.pressed) { + default_layer = action.layer.val; + layer_switch(default_layer); + } + break; + case LAYER_SET_DEFAULT_ON_BOTH: + default_layer = action.layer.val; + layer_switch(default_layer); + break; + default: + /* tap key */ if (event.pressed) { - if (tap_count > 0) { - debug("LAYER_PRESSED: Tap: register_code\n"); - register_code(action.layer.code); - } else { - debug("LAYER_PRESSED: No tap: layer_switch\n"); - layer_switch(action.layer.val); - } + if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + debug("LAYER_SET: Tap: register_code\n"); + register_code(action.layer.code); + } else { + debug("LAYER_SET: No tap: layer_set(on press)\n"); + layer_switch(action.layer.val); + } } else { - if (tap_count > 0) { - debug("LAYER_PRESSED: Tap: unregister_code\n"); + if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + debug("LAYER_SET: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - //debug("LAYER_PRESSED: No tap: NO ACTION\n"); // NOTE: This is needed by legacy keymap support - debug("LAYER_PRESSED: No tap: return to default layer\n"); + debug("LAYER_SET: No tap: return to default layer(on release)\n"); layer_switch(default_layer); } } @@ -452,9 +540,9 @@ static void process_action(keyrecord_t *record) switch (action.layer.code) { case LAYER_MOMENTARY: /* momentary */ if (event.pressed) { - layer_switch(current_layer ^ action.layer.val); + layer_switch(current_layer | action.layer.val); } else { - layer_switch(current_layer ^ action.layer.val); + layer_switch(current_layer & ~action.layer.val); } break; case LAYER_ON_PRESS: @@ -467,6 +555,9 @@ static void process_action(keyrecord_t *record) layer_switch(current_layer ^ action.layer.val); } break; + case LAYER_ON_BOTH: + layer_switch(current_layer ^ action.layer.val); + break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { @@ -480,24 +571,30 @@ static void process_action(keyrecord_t *record) } } break; - case 0xFF: - // change default layer + case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { default_layer = current_layer ^ action.layer.val; layer_switch(default_layer); - } else { + } + break; + case LAYER_SET_DEFAULT_ON_RELEASE: + if (!event.pressed) { default_layer = current_layer ^ action.layer.val; layer_switch(default_layer); } break; + case LAYER_SET_DEFAULT_ON_BOTH: + default_layer = current_layer ^ action.layer.val; + layer_switch(default_layer); + break; default: - // with tap key + // tap key if (event.pressed) { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { debug("LAYER_BIT: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("LAYER_BIT: No tap: layer_switch(bit on)\n"); + debug("LAYER_BIT: No tap: layer_bit(on press)\n"); layer_switch(current_layer ^ action.layer.val); } } else { @@ -505,13 +602,79 @@ static void process_action(keyrecord_t *record) debug("LAYER_BIT: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("LAYER_BIT: No tap: layer_switch(bit off)\n"); + debug("LAYER_BIT: No tap: layer_bit(on release)\n"); layer_switch(current_layer ^ action.layer.val); } } break; } break; + case ACT_LAYER_STACK: + switch (action.layer.code) { + case LAYER_MOMENTARY: /* momentary */ + if (event.pressed) { + layer_remove_then_push(action.layer.val); + debug_layer_stack(); + } else { + layer_remove(action.layer.val); + debug_layer_stack(); + } + break; + case LAYER_ON_PRESS: + if (event.pressed) { + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + break; + case LAYER_ON_RELEASE: + if (!event.pressed) { + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + break; + case LAYER_ON_BOTH: + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + break; + case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ + if (event.pressed) { + if (tap_count < TAPPING_TOGGLE) { + debug("LAYER_STACK: tap toggle(press).\n"); + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + } else { + if (tap_count <= TAPPING_TOGGLE) { + debug("LAYER_STACK: tap toggle(release).\n"); + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + } + break; + default: + // tap key + if (event.pressed) { + if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + debug("LAYER_STACK: Tap: register_code\n"); + register_code(action.layer.code); + } else { + debug("LAYER_STACK: No tap: layer_stack(on press)\n"); + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + } else { + if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + debug("LAYER_STACK: Tap: unregister_code\n"); + unregister_code(action.layer.code); + } else { + debug("LAYER_STACK: No tap: layer_stack(on release)\n"); + layer_remove_or_push(action.layer.val); + debug_layer_stack(); + } + } + break; + } + break; /* Extentions */ case ACT_MACRO: @@ -839,7 +1002,10 @@ bool is_tap_key(key_t key) case LAYER_MOMENTARY: case LAYER_ON_PRESS: case LAYER_ON_RELEASE: - case LAYER_DEFAULT: + case LAYER_ON_BOTH: + case LAYER_SET_DEFAULT_ON_PRESS: + case LAYER_SET_DEFAULT_ON_RELEASE: + case LAYER_SET_DEFAULT_ON_BOTH: return false; case LAYER_TAP_TOGGLE: default: /* tap key */ @@ -876,8 +1042,9 @@ static void debug_action(action_t action) case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; case ACT_USAGE: debug("ACT_USAGE"); break; case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; - case ACT_LAYER: debug("ACT_LAYER"); break; + case ACT_LAYER: debug("ACT_LAYER"); break; case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; + case ACT_LAYER_STACK: debug("ACT_LAYER_STACK"); break; case ACT_MACRO: debug("ACT_MACRO"); break; case ACT_COMMAND: debug("ACT_COMMAND"); break; case ACT_FUNCTION: debug("ACT_FUNCTION"); break; -- cgit v1.2.3 From a4aae1c5055d24c400f78fd44618aef5916adc0c Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 15 Feb 2013 12:17:03 +0900 Subject: Change: 0 means default_layer in current_layer now - current_layer indicates active layer at the time - default_layer indicates base layer - default_layer is used when current_layer is 0 - with this LAYER_BIT action works as overlay even if default_layer varies other than layer 0. --- common/action.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index d0c9ddb0ad..38c5933ee3 100644 --- a/common/action.c +++ b/common/action.c @@ -289,6 +289,7 @@ void action_exec(keyevent_t event) static action_t get_action(key_t key) { action_t action; + action.code = ACTION_NO; /* layer stack */ for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { @@ -301,14 +302,18 @@ static action_t get_action(key_t key) debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); } - /* current layer */ - action = action_for_key(current_layer, key); + /* 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 */ - if (action.code == ACTION_TRANSPARENT) { - debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); - action = action_for_key(default_layer, key); - } + debug("default layer: used. \n"); + action = action_for_key(default_layer, key); return action; } @@ -469,7 +474,7 @@ static void process_action(keyrecord_t *record) } else { // NOTE: This is needed by legacy keymap support - layer_switch(default_layer); + layer_switch(0); } break; case LAYER_ON_PRESS: @@ -500,18 +505,18 @@ static void process_action(keyrecord_t *record) case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { default_layer = action.layer.val; - layer_switch(default_layer); + layer_switch(0); } break; case LAYER_SET_DEFAULT_ON_RELEASE: if (!event.pressed) { default_layer = action.layer.val; - layer_switch(default_layer); + layer_switch(0); } break; case LAYER_SET_DEFAULT_ON_BOTH: default_layer = action.layer.val; - layer_switch(default_layer); + layer_switch(0); break; default: /* tap key */ @@ -530,7 +535,7 @@ static void process_action(keyrecord_t *record) } else { // NOTE: This is needed by legacy keymap support debug("LAYER_SET: No tap: return to default layer(on release)\n"); - layer_switch(default_layer); + layer_switch(0); } } break; @@ -573,19 +578,19 @@ static void process_action(keyrecord_t *record) break; case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { - default_layer = current_layer ^ action.layer.val; - layer_switch(default_layer); + default_layer = default_layer ^ action.layer.val; + layer_switch(0); } break; case LAYER_SET_DEFAULT_ON_RELEASE: if (!event.pressed) { - default_layer = current_layer ^ action.layer.val; - layer_switch(default_layer); + default_layer = default_layer ^ action.layer.val; + layer_switch(0); } break; case LAYER_SET_DEFAULT_ON_BOTH: - default_layer = current_layer ^ action.layer.val; - layer_switch(default_layer); + default_layer = default_layer ^ action.layer.val; + layer_switch(0); break; default: // tap key -- cgit v1.2.3 From 768ea72f109fee2411c77bf2fabcbede5f98650d Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 15 Feb 2013 13:47:41 +0900 Subject: Add layer_stack files taking apart from action.c --- common/action.c | 127 ++++++++++---------------------------------------------- 1 file changed, 22 insertions(+), 105 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 38c5933ee3..9a8d75596a 100644 --- a/common/action.c +++ b/common/action.c @@ -24,6 +24,7 @@ along with this program. If not, see . #include "util.h" #include "debug.h" #include "action.h" +#include "layer_stack.h" /* default layer indicates base layer */ @@ -163,85 +164,6 @@ static void oneshot_toggle(void) } -/* - * Layer stack - */ -#define LAYER_STACK_SIZE 8 -typedef struct { - uint8_t layer:4; - uint8_t next:3; - bool used; -} layer_item_t; - -static uint8_t top_layer = 0; -// [0] is sentinel and not used. [0] is null item. -static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; - -static bool layer_push(uint8_t layer) -{ - for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { - if (!layer_stack[i].used) { - layer_stack[i] = (layer_item_t){ .layer = layer, - .next = top_layer, - .used = true }; - top_layer = i; - return true; - } - } - return false; -} -static bool layer_pop(void) -{ - if (layer_stack[top_layer].used) { - uint8_t popped = top_layer; - top_layer = layer_stack[popped].next; - layer_stack[popped] = (layer_item_t){}; - return true; - } - return false; -} -static bool layer_remove(uint8_t layer) -{ - if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) { - layer_pop(); - debug("layer_remove: top_layer\n"); - return true; - } - - for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) { - debug("layer_remove: ["); debug_dec(i); debug("]"); - debug_dec(layer_stack[i].layer); debug("\n"); - uint8_t removed = layer_stack[i].next; - if (layer_stack[removed].used && layer_stack[removed].layer == layer) { - layer_stack[i].next = layer_stack[removed].next; - layer_stack[removed] = (layer_item_t){}; - debug("layer_remove: removed.\n"); - return true; - } - } - return false; -} -static bool layer_remove_then_push(uint8_t layer) -{ - layer_remove(layer); - return layer_push(layer); -} -static bool layer_remove_or_push(uint8_t layer) -{ - return (layer_remove(layer)) || layer_push(layer); -} -static void debug_layer_stack(void) -{ - debug("layer_stack: "); - layer_item_t item = layer_stack[top_layer]; - while (item.used) { - debug_dec(item.layer); - debug("["); debug_dec(item.next); debug("]"); - item = layer_stack[item.next]; - } - debug("\n"); -} - void action_exec(keyevent_t event) { @@ -292,14 +214,9 @@ static action_t get_action(key_t key) action.code = ACTION_NO; /* layer stack */ - for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { - action = action_for_key(i.layer, key); - if (action.code != ACTION_TRANSPARENT) { - debug_layer_stack(); - debug("layer_stack: used. "); debug_dec(i.layer); debug("\n"); - return action; - } - debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); + action = layer_stack_get_action(key); + if (action.code != ACTION_TRANSPARENT) { + return action; } /* current layer: 0 means default layer */ @@ -618,41 +535,41 @@ static void process_action(keyrecord_t *record) switch (action.layer.code) { case LAYER_MOMENTARY: /* momentary */ if (event.pressed) { - layer_remove_then_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_then_push(action.layer.val); + layer_stack_debug(); } else { - layer_remove(action.layer.val); - debug_layer_stack(); + layer_stack_remove(action.layer.val); + layer_stack_debug(); } break; case LAYER_ON_PRESS: if (event.pressed) { - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } break; case LAYER_ON_RELEASE: if (!event.pressed) { - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } break; case LAYER_ON_BOTH: - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { debug("LAYER_STACK: tap toggle(press).\n"); - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } } else { if (tap_count <= TAPPING_TOGGLE) { debug("LAYER_STACK: tap toggle(release).\n"); - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } } break; @@ -664,8 +581,8 @@ static void process_action(keyrecord_t *record) register_code(action.layer.code); } else { debug("LAYER_STACK: No tap: layer_stack(on press)\n"); - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } } else { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { @@ -673,8 +590,8 @@ static void process_action(keyrecord_t *record) unregister_code(action.layer.code); } else { debug("LAYER_STACK: No tap: layer_stack(on release)\n"); - layer_remove_or_push(action.layer.val); - debug_layer_stack(); + layer_stack_remove_or_push(action.layer.val); + layer_stack_debug(); } } break; -- cgit v1.2.3 From d9f287586635a401b8d6a80614bee6dbebe2f18c Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 15 Feb 2013 18:48:36 +0900 Subject: Replace layer_stack with layer_switch --- common/action.c | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 9a8d75596a..4f0a5f9064 100644 --- a/common/action.c +++ b/common/action.c @@ -24,7 +24,7 @@ along with this program. If not, see . #include "util.h" #include "debug.h" #include "action.h" -#include "layer_stack.h" +#include "layer_switch.h" /* default layer indicates base layer */ @@ -213,8 +213,8 @@ static action_t get_action(key_t key) action_t action; action.code = ACTION_NO; - /* layer stack */ - action = layer_stack_get_action(key); + /* layer_switch */ + action = layer_switch_get_action(key); if (action.code != ACTION_TRANSPARENT) { return action; } @@ -531,45 +531,38 @@ static void process_action(keyrecord_t *record) break; } break; - case ACT_LAYER_STACK: + case ACT_LAYER_SWITCH: switch (action.layer.code) { case LAYER_MOMENTARY: /* momentary */ if (event.pressed) { - layer_stack_remove_then_push(action.layer.val); - layer_stack_debug(); + layer_switch_on(action.layer.val); } else { - layer_stack_remove(action.layer.val); - layer_stack_debug(); + layer_switch_off(action.layer.val); } break; case LAYER_ON_PRESS: if (event.pressed) { - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + layer_switch_inv(action.layer.val); } break; case LAYER_ON_RELEASE: if (!event.pressed) { - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + layer_switch_inv(action.layer.val); } break; case LAYER_ON_BOTH: - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + layer_switch_inv(action.layer.val); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { - debug("LAYER_STACK: tap toggle(press).\n"); - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + debug("LAYER_SWITCH: tap toggle(press).\n"); + layer_switch_inv(action.layer.val); } } else { if (tap_count <= TAPPING_TOGGLE) { - debug("LAYER_STACK: tap toggle(release).\n"); - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + debug("LAYER_SWITCH: tap toggle(release).\n"); + layer_switch_inv(action.layer.val); } } break; @@ -577,21 +570,19 @@ static void process_action(keyrecord_t *record) // tap key if (event.pressed) { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_STACK: Tap: register_code\n"); + debug("LAYER_SWITCH: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("LAYER_STACK: No tap: layer_stack(on press)\n"); - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + debug("LAYER_SWITCH: No tap: layer_switch(on press)\n"); + layer_switch_inv(action.layer.val); } } else { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_STACK: Tap: unregister_code\n"); + debug("LAYER_SWITCH: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("LAYER_STACK: No tap: layer_stack(on release)\n"); - layer_stack_remove_or_push(action.layer.val); - layer_stack_debug(); + debug("LAYER_SWITCH: No tap: layer_switch(on release)\n"); + layer_switch_inv(action.layer.val); } } break; @@ -898,6 +889,7 @@ bool sending_anykey(void) 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) { @@ -966,7 +958,7 @@ static void debug_action(action_t action) case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; case ACT_LAYER: debug("ACT_LAYER"); break; case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; - case ACT_LAYER_STACK: debug("ACT_LAYER_STACK"); break; + case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; case ACT_MACRO: debug("ACT_MACRO"); break; case ACT_COMMAND: debug("ACT_COMMAND"); break; case ACT_FUNCTION: debug("ACT_FUNCTION"); break; -- cgit v1.2.3 From e324fa29187dff7868d9d7fd378e0e46d77107a5 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 16 Feb 2013 04:05:58 +0900 Subject: Rewrite layer action with layer_switch --- common/action.c | 107 +++++++++++++++++++++----------------------------------- 1 file changed, 40 insertions(+), 67 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 4f0a5f9064..246fd99d8a 100644 --- a/common/action.c +++ b/common/action.c @@ -27,12 +27,6 @@ along with this program. If not, see . #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 bool process_tapping(keyrecord_t *record); static void waiting_buffer_scan_tap(void); @@ -219,17 +213,8 @@ static action_t get_action(key_t key) 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 */ - debug("default layer: used. \n"); + //debug("get_aciton: default layer: "); debug_dec(default_layer); debug("\n"); action = action_for_key(default_layer, key); return action; } @@ -242,7 +227,8 @@ static void process_action(keyrecord_t *record) if (IS_NOEVENT(event)) { return; } 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) { /* Key and Mods */ @@ -383,57 +369,57 @@ static void process_action(keyrecord_t *record) break; /* Layer key */ - case ACT_LAYER: + case ACT_LAYER_SET: switch (action.layer.code) { case LAYER_MOMENTARY: /* momentary */ if (event.pressed) { - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } else { // NOTE: This is needed by legacy keymap support - layer_switch(0); + layer_switch_move(0); } break; case LAYER_ON_PRESS: if (event.pressed) { - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } break; case LAYER_ON_RELEASE: if (!event.pressed) { - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } break; case LAYER_ON_BOTH: - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } } else { if (tap_count >= TAPPING_TOGGLE) { debug("LAYER_PRESSED: tap toggle.\n"); - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } } break; case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { default_layer = action.layer.val; - layer_switch(0); + layer_switch_move(0); } break; case LAYER_SET_DEFAULT_ON_RELEASE: if (!event.pressed) { default_layer = action.layer.val; - layer_switch(0); + layer_switch_move(0); } break; case LAYER_SET_DEFAULT_ON_BOTH: default_layer = action.layer.val; - layer_switch(0); + layer_switch_move(0); break; default: /* tap key */ @@ -443,7 +429,7 @@ static void process_action(keyrecord_t *record) register_code(action.layer.code); } else { debug("LAYER_SET: No tap: layer_set(on press)\n"); - layer_switch(action.layer.val); + layer_switch_move(action.layer.val); } } else { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { @@ -452,7 +438,7 @@ static void process_action(keyrecord_t *record) } else { // NOTE: This is needed by legacy keymap support debug("LAYER_SET: No tap: return to default layer(on release)\n"); - layer_switch(0); + layer_switch_move(0); } } break; @@ -462,52 +448,52 @@ static void process_action(keyrecord_t *record) switch (action.layer.code) { case LAYER_MOMENTARY: /* momentary */ if (event.pressed) { - layer_switch(current_layer | action.layer.val); + layer_switch_move(layer_switch_get_layer() | action.layer.val); } else { - layer_switch(current_layer & ~action.layer.val); + layer_switch_move(layer_switch_get_layer() & ~action.layer.val); } break; case LAYER_ON_PRESS: if (event.pressed) { - layer_switch(current_layer ^ action.layer.val); + layer_switch_move(layer_switch_get_layer() ^ action.layer.val); } break; case LAYER_ON_RELEASE: if (!event.pressed) { - layer_switch(current_layer ^ action.layer.val); + layer_switch_move(layer_switch_get_layer() ^ action.layer.val); } break; case LAYER_ON_BOTH: - layer_switch(current_layer ^ action.layer.val); + layer_switch_move(layer_switch_get_layer() ^ action.layer.val); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { 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 { if (tap_count <= TAPPING_TOGGLE) { 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; case LAYER_SET_DEFAULT_ON_PRESS: if (event.pressed) { default_layer = default_layer ^ action.layer.val; - layer_switch(0); + layer_switch_move(default_layer); } break; case LAYER_SET_DEFAULT_ON_RELEASE: if (!event.pressed) { default_layer = default_layer ^ action.layer.val; - layer_switch(0); + layer_switch_move(default_layer); } break; case LAYER_SET_DEFAULT_ON_BOTH: default_layer = default_layer ^ action.layer.val; - layer_switch(0); + layer_switch_move(default_layer); break; default: // tap key @@ -517,7 +503,7 @@ static void process_action(keyrecord_t *record) register_code(action.layer.code); } else { 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 { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { @@ -525,7 +511,7 @@ static void process_action(keyrecord_t *record) unregister_code(action.layer.code); } else { 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; @@ -542,27 +528,27 @@ static void process_action(keyrecord_t *record) break; case LAYER_ON_PRESS: if (event.pressed) { - layer_switch_inv(action.layer.val); + layer_switch_invert(action.layer.val); } break; case LAYER_ON_RELEASE: if (!event.pressed) { - layer_switch_inv(action.layer.val); + layer_switch_invert(action.layer.val); } break; case LAYER_ON_BOTH: - layer_switch_inv(action.layer.val); + layer_switch_invert(action.layer.val); break; case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { debug("LAYER_SWITCH: tap toggle(press).\n"); - layer_switch_inv(action.layer.val); + layer_switch_invert(action.layer.val); } } else { if (tap_count <= TAPPING_TOGGLE) { debug("LAYER_SWITCH: tap toggle(release).\n"); - layer_switch_inv(action.layer.val); + layer_switch_invert(action.layer.val); } } break; @@ -573,16 +559,16 @@ static void process_action(keyrecord_t *record) debug("LAYER_SWITCH: Tap: register_code\n"); register_code(action.layer.code); } 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 { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { debug("LAYER_SWITCH: Tap: unregister_code\n"); unregister_code(action.layer.code); } 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; @@ -889,19 +875,6 @@ bool sending_anykey(void) 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) { action_t action = get_action(key); @@ -910,7 +883,7 @@ bool is_tap_key(key_t key) case ACT_LMODS_TAP: case ACT_RMODS_TAP: return true; - case ACT_LAYER: + case ACT_LAYER_SET: case ACT_LAYER_BIT: switch (action.layer.code) { case LAYER_MOMENTARY: @@ -956,9 +929,9 @@ static void debug_action(action_t action) case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; case ACT_USAGE: debug("ACT_USAGE"); 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_SWITCH: debug("ACT_LAYER_SWITCH"); break; + case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; case ACT_MACRO: debug("ACT_MACRO"); break; case ACT_COMMAND: debug("ACT_COMMAND"); break; case ACT_FUNCTION: debug("ACT_FUNCTION"); break; -- cgit v1.2.3 From e0f960a576e090808e5cc25c5368441c11f36ea6 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 20 Feb 2013 11:16:13 +0900 Subject: Add overlay framework --- common/action.c | 356 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 209 insertions(+), 147 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 246fd99d8a..3703b4e8cc 100644 --- a/common/action.c +++ b/common/action.c @@ -202,23 +202,6 @@ void action_exec(keyevent_t event) } } -static action_t get_action(key_t key) -{ - action_t action; - action.code = ACTION_NO; - - /* layer_switch */ - action = layer_switch_get_action(key); - if (action.code != ACTION_TRANSPARENT) { - return action; - } - - /* default layer */ - //debug("get_aciton: default layer: "); debug_dec(default_layer); debug("\n"); - action = action_for_key(default_layer, key); - return action; -} - static void process_action(keyrecord_t *record) { keyevent_t event = record->event; @@ -226,9 +209,11 @@ static void process_action(keyrecord_t *record) if (IS_NOEVENT(event)) { return; } - action_t action = get_action(event.key); - debug("ACTION: "); debug_action(action); debug(" "); - layer_switch_debug(); debug("["); debug_dec(default_layer); debug("]\n"); + action_t action = layer_switch_get_action(event.key); + debug("ACTION: "); debug_action(action); + debug(" overlays: "); overlay_debug(); + debug(" keymaps: "); keymap_debug(); + debug(" default_layer: "); debug_dec(default_layer); debug("\n"); switch (action.kind.id) { /* Key and Mods */ @@ -368,207 +353,292 @@ static void process_action(keyrecord_t *record) #endif break; - /* Layer key */ - case ACT_LAYER_SET: + case ACT_KEYMAP: switch (action.layer.code) { - case LAYER_MOMENTARY: /* momentary */ - if (event.pressed) { - layer_switch_move(action.layer.val); - } - else { - // NOTE: This is needed by legacy keymap support - layer_switch_move(0); - } + /* Keymap Reset */ + case OP_RESET: + default_layer_set(action.layer.val); break; - case LAYER_ON_PRESS: + /* Keymap Reset default layer */ + case (OP_RESET | ON_PRESS): if (event.pressed) { - layer_switch_move(action.layer.val); + default_layer_set(action.layer.val); + overlay_clear(); } break; - case LAYER_ON_RELEASE: + case (OP_RESET | ON_RELEASE): if (!event.pressed) { - layer_switch_move(action.layer.val); + default_layer_set(action.layer.val); + overlay_clear(); } break; - case LAYER_ON_BOTH: - layer_switch_move(action.layer.val); + case (OP_RESET | ON_BOTH): + default_layer_set(action.layer.val); + overlay_clear(); break; - case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ + + /* Keymap Bit invert */ + case OP_INV: + /* with tap toggle */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { - layer_switch_move(action.layer.val); + debug("KEYMAP_INV: tap toggle(press).\n"); + keymap_invert(action.layer.val); } } else { - if (tap_count >= TAPPING_TOGGLE) { - debug("LAYER_PRESSED: tap toggle.\n"); - layer_switch_move(action.layer.val); + if (tap_count <= TAPPING_TOGGLE) { + debug("KEYMAP_INV: tap toggle(release).\n"); + keymap_invert(action.layer.val); } } break; - case LAYER_SET_DEFAULT_ON_PRESS: + case (OP_INV | ON_PRESS): if (event.pressed) { - default_layer = action.layer.val; - layer_switch_move(0); + keymap_invert(action.layer.val); } break; - case LAYER_SET_DEFAULT_ON_RELEASE: + case (OP_INV | ON_RELEASE): if (!event.pressed) { - default_layer = action.layer.val; - layer_switch_move(0); + keymap_invert(action.layer.val); } break; - case LAYER_SET_DEFAULT_ON_BOTH: - default_layer = action.layer.val; - layer_switch_move(0); + case (OP_INV | ON_BOTH): + keymap_invert(action.layer.val); break; - default: - /* tap key */ + + /* Keymap Bit on */ + case OP_ON: if (event.pressed) { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_SET: Tap: register_code\n"); - register_code(action.layer.code); - } else { - debug("LAYER_SET: No tap: layer_set(on press)\n"); - layer_switch_move(action.layer.val); - } + keymap_on(action.layer.val); } else { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_SET: Tap: unregister_code\n"); - unregister_code(action.layer.code); - } else { - // NOTE: This is needed by legacy keymap support - debug("LAYER_SET: No tap: return to default layer(on release)\n"); - layer_switch_move(0); - } + keymap_off(action.layer.val); } break; - } - break; - case ACT_LAYER_BIT: - switch (action.layer.code) { - case LAYER_MOMENTARY: /* momentary */ + case (OP_ON | ON_PRESS): if (event.pressed) { - layer_switch_move(layer_switch_get_layer() | action.layer.val); + keymap_on(action.layer.val); + } + break; + case (OP_ON | ON_RELEASE): + if (!event.pressed) { + keymap_on(action.layer.val); + } + break; + case (OP_ON | ON_BOTH): + keymap_on(action.layer.val); + break; + + /* Keymap Bit off */ + case OP_OFF: + if (event.pressed) { + keymap_off(action.layer.val); } else { - layer_switch_move(layer_switch_get_layer() & ~action.layer.val); + keymap_on(action.layer.val); } break; - case LAYER_ON_PRESS: + case (OP_OFF | ON_PRESS): if (event.pressed) { - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); + keymap_off(action.layer.val); } break; - case LAYER_ON_RELEASE: + case (OP_OFF | ON_RELEASE): if (!event.pressed) { - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); + keymap_off(action.layer.val); } break; - case LAYER_ON_BOTH: - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); + case (OP_OFF | ON_BOTH): + keymap_off(action.layer.val); break; - case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ + + /* Keymap Bit set */ + case OP_SET: if (event.pressed) { - if (tap_count < TAPPING_TOGGLE) { - debug("LAYER_BIT: tap toggle(press).\n"); - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); - } + keymap_set(action.layer.val); } else { - if (tap_count <= TAPPING_TOGGLE) { - debug("LAYER_BIT: tap toggle(release).\n"); - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); - } + keymap_clear(); } break; - case LAYER_SET_DEFAULT_ON_PRESS: + case (OP_SET | ON_PRESS): if (event.pressed) { - default_layer = default_layer ^ action.layer.val; - layer_switch_move(default_layer); + keymap_set(action.layer.val); } break; - case LAYER_SET_DEFAULT_ON_RELEASE: + case (OP_SET | ON_RELEASE): if (!event.pressed) { - default_layer = default_layer ^ action.layer.val; - layer_switch_move(default_layer); + keymap_set(action.layer.val); } break; - case LAYER_SET_DEFAULT_ON_BOTH: - default_layer = default_layer ^ action.layer.val; - layer_switch_move(default_layer); + case (OP_SET | ON_BOTH): + keymap_set(action.layer.val); break; + + /* Keymap Bit invert with tap key */ default: - // tap key if (event.pressed) { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_BIT: Tap: register_code\n"); + debug("KEYMAP_TAP_KEY: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("LAYER_BIT: No tap: layer_bit(on press)\n"); - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); + debug("KEYMAP_TAP_KEY: No tap: invert on press\n"); + keymap_invert(action.layer.val); } } else { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_BIT: Tap: unregister_code\n"); + debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("LAYER_BIT: No tap: layer_bit(on release)\n"); - layer_switch_move(layer_switch_get_layer() ^ action.layer.val); + debug("KEYMAP_TAP_KEY: No tap: invert on release\n"); + keymap_invert(action.layer.val); } } break; } break; - case ACT_LAYER_SWITCH: + + case ACT_OVERLAY: switch (action.layer.code) { - case LAYER_MOMENTARY: /* momentary */ - if (event.pressed) { - layer_switch_on(action.layer.val); + // Overlay Invert bit4 + case OP_INV4 | 0: + if (action.layer.val == 0) { + overlay_clear(); } else { - layer_switch_off(action.layer.val); + overlay_set(overlay_stat ^ action.layer.val); } break; - case LAYER_ON_PRESS: - if (event.pressed) { - layer_switch_invert(action.layer.val); + case OP_INV4 | 1: + if (action.layer.val == 0) { + if (event.pressed) overlay_clear(); + } else { + overlay_set(overlay_stat ^ action.layer.val<<4); } break; - case LAYER_ON_RELEASE: - if (!event.pressed) { - layer_switch_invert(action.layer.val); + case OP_INV4 | 2: + if (action.layer.val == 0) { + if (!event.pressed) overlay_clear(); + } else { + overlay_set(overlay_stat ^ action.layer.val<<8); } break; - case LAYER_ON_BOTH: - layer_switch_invert(action.layer.val); + case OP_INV4 | 3: + if (action.layer.val == 0) { + overlay_clear(); + } else { + overlay_set(overlay_stat ^ action.layer.val<<12); + } break; - case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ + + /* Overlay Bit invert */ + case OP_INV: + /* with tap toggle */ if (event.pressed) { if (tap_count < TAPPING_TOGGLE) { - debug("LAYER_SWITCH: tap toggle(press).\n"); - layer_switch_invert(action.layer.val); + debug("OVERLAY_INV: tap toggle(press).\n"); + overlay_invert(action.layer.val); } } else { if (tap_count <= TAPPING_TOGGLE) { - debug("LAYER_SWITCH: tap toggle(release).\n"); - layer_switch_invert(action.layer.val); + debug("OVERLAY_INV: tap toggle(release).\n"); + overlay_invert(action.layer.val); } } break; + case (OP_INV | ON_PRESS): + if (event.pressed) { + overlay_invert(action.layer.val); + } + break; + case (OP_INV | ON_RELEASE): + if (!event.pressed) { + overlay_invert(action.layer.val); + } + break; + case (OP_INV | ON_BOTH): + overlay_invert(action.layer.val); + break; + + /* Overlay Bit on */ + case OP_ON: + if (event.pressed) { + overlay_on(action.layer.val); + } else { + overlay_off(action.layer.val); + } + break; + case (OP_ON | ON_PRESS): + if (event.pressed) { + overlay_on(action.layer.val); + } + break; + case (OP_ON | ON_RELEASE): + if (!event.pressed) { + overlay_on(action.layer.val); + } + break; + case (OP_ON | ON_BOTH): + overlay_on(action.layer.val); + break; + + /* Overlay Bit off */ + case OP_OFF: + if (event.pressed) { + overlay_off(action.layer.val); + } else { + overlay_on(action.layer.val); + } + break; + case (OP_OFF | ON_PRESS): + if (event.pressed) { + overlay_off(action.layer.val); + } + break; + case (OP_OFF | ON_RELEASE): + if (!event.pressed) { + overlay_off(action.layer.val); + } + break; + case (OP_OFF | ON_BOTH): + overlay_off(action.layer.val); + break; + + /* Overlay Bit set */ + case OP_SET: + if (event.pressed) { + overlay_move(action.layer.val); + } else { + overlay_clear(); + } + break; + case (OP_SET | ON_PRESS): + if (event.pressed) { + overlay_move(action.layer.val); + } + break; + case (OP_SET | ON_RELEASE): + if (!event.pressed) { + overlay_move(action.layer.val); + } + break; + case (OP_SET | ON_BOTH): + overlay_move(action.layer.val); + break; + + /* Overlay Bit invert with tap key */ default: - // tap key if (event.pressed) { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_SWITCH: Tap: register_code\n"); + debug("OVERLAY_TAP_KEY: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("LAYER_SWITCH: No tap: layer_switch on press\n"); - layer_switch_invert(action.layer.val); + debug("OVERLAY_TAP_KEY: No tap: invert on press\n"); + overlay_invert(action.layer.val); } } else { if (IS_TAPPING_KEY(event.key) && tap_count > 0) { - debug("LAYER_SWITCH: Tap: unregister_code\n"); + debug("OVERLAY_TAP_KEY: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("LAYER_SWITCH: No tap: layer_switch on release\n"); - layer_switch_invert(action.layer.val); + debug("OVERLAY_TAP_KEY: No tap: invert on release\n"); + overlay_invert(action.layer.val); } } break; @@ -877,28 +947,21 @@ bool sending_anykey(void) bool is_tap_key(key_t key) { - action_t action = get_action(key); + action_t action = layer_switch_get_action(key); switch (action.kind.id) { case ACT_LMODS_TAP: case ACT_RMODS_TAP: return true; - case ACT_LAYER_SET: - case ACT_LAYER_BIT: + case ACT_KEYMAP: + case ACT_OVERLAY: switch (action.layer.code) { - case LAYER_MOMENTARY: - case LAYER_ON_PRESS: - case LAYER_ON_RELEASE: - case LAYER_ON_BOTH: - case LAYER_SET_DEFAULT_ON_PRESS: - case LAYER_SET_DEFAULT_ON_RELEASE: - case LAYER_SET_DEFAULT_ON_BOTH: - return false; - case LAYER_TAP_TOGGLE: - default: /* tap key */ + case 0x04 ... 0xEF: /* tap key */ + case OP_INV: return true; + default: + return false; } - return false; case ACT_FUNCTION: if (action.func.opt & FUNC_TAP) { return true; } return false; @@ -929,9 +992,8 @@ static void debug_action(action_t action) case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; case ACT_USAGE: debug("ACT_USAGE"); break; case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; - case ACT_LAYER_SET: debug("ACT_LAYER_SET"); break; - case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; - case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; + case ACT_KEYMAP: debug("ACT_KEYMAP"); break; + case ACT_OVERLAY: debug("ACT_OVERLAY"); break; case ACT_MACRO: debug("ACT_MACRO"); break; case ACT_COMMAND: debug("ACT_COMMAND"); break; case ACT_FUNCTION: debug("ACT_FUNCTION"); break; -- cgit v1.2.3 From c3d57b69e02fce40455c96f4a9ac6b68b89ce027 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 20 Feb 2013 15:52:32 +0900 Subject: Add keymap clear/reset action --- common/action.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 3703b4e8cc..844a35b3e1 100644 --- a/common/action.c +++ b/common/action.c @@ -355,26 +355,50 @@ static void process_action(keyrecord_t *record) case ACT_KEYMAP: switch (action.layer.code) { - /* Keymap Reset */ + /* Keymap clear */ case OP_RESET: - default_layer_set(action.layer.val); + switch (action.layer.val & 0x03) { + case 0: + overlay_clear(); + keymap_clear(); + break; + case ON_PRESS: + if (event.pressed) { + overlay_clear(); + keymap_clear(); + } + break; + case ON_RELEASE: + if (!event.pressed) { + overlay_clear(); + keymap_clear(); + } + break; + case ON_BOTH: + overlay_clear(); + keymap_clear(); + break; + } break; /* Keymap Reset default layer */ case (OP_RESET | ON_PRESS): if (event.pressed) { - default_layer_set(action.layer.val); overlay_clear(); + keymap_clear(); + default_layer_set(action.layer.val); } break; case (OP_RESET | ON_RELEASE): if (!event.pressed) { - default_layer_set(action.layer.val); overlay_clear(); + keymap_clear(); + default_layer_set(action.layer.val); } break; case (OP_RESET | ON_BOTH): - default_layer_set(action.layer.val); overlay_clear(); + keymap_clear(); + default_layer_set(action.layer.val); break; /* Keymap Bit invert */ -- cgit v1.2.3 From 59e073e82b0a8bee13270bf328945ee6b8769c36 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 20 Feb 2013 16:53:55 +0900 Subject: Fix tap key bug: layer stuck - Can't use Invert action for tap key, use On/Off insted. --- common/action.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 844a35b3e1..294ce00fb1 100644 --- a/common/action.c +++ b/common/action.c @@ -499,20 +499,20 @@ static void process_action(keyrecord_t *record) /* Keymap Bit invert with tap key */ default: if (event.pressed) { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + if (tap_count > 0) { debug("KEYMAP_TAP_KEY: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("KEYMAP_TAP_KEY: No tap: invert on press\n"); - keymap_invert(action.layer.val); + debug("KEYMAP_TAP_KEY: No tap: On on press\n"); + keymap_on(action.layer.val); } } else { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + if (tap_count > 0) { debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("KEYMAP_TAP_KEY: No tap: invert on release\n"); - keymap_invert(action.layer.val); + debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); + keymap_off(action.layer.val); } } break; @@ -649,20 +649,20 @@ static void process_action(keyrecord_t *record) /* Overlay Bit invert with tap key */ default: if (event.pressed) { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + if (tap_count > 0) { debug("OVERLAY_TAP_KEY: Tap: register_code\n"); register_code(action.layer.code); } else { - debug("OVERLAY_TAP_KEY: No tap: invert on press\n"); - overlay_invert(action.layer.val); + debug("OVERLAY_TAP_KEY: No tap: On on press\n"); + overlay_on(action.layer.val); } } else { - if (IS_TAPPING_KEY(event.key) && tap_count > 0) { + if (tap_count > 0) { debug("OVERLAY_TAP_KEY: Tap: unregister_code\n"); unregister_code(action.layer.code); } else { - debug("OVERLAY_TAP_KEY: No tap: invert on release\n"); - overlay_invert(action.layer.val); + debug("OVERLAY_TAP_KEY: No tap: Off on release\n"); + overlay_off(action.layer.val); } } break; -- cgit v1.2.3 From 23c32d304bcc5146a575e547bba80ee8d86a2856 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 25 Feb 2013 15:30:37 +0900 Subject: Add MACRO action --- common/action.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 294ce00fb1..fc88180309 100644 --- a/common/action.c +++ b/common/action.c @@ -23,8 +23,9 @@ along with this program. If not, see . #include "command.h" #include "util.h" #include "debug.h" -#include "action.h" #include "layer_switch.h" +#include "action_macro.h" +#include "action.h" static void process_action(keyrecord_t *record); @@ -671,7 +672,7 @@ static void process_action(keyrecord_t *record) /* Extentions */ case ACT_MACRO: - // TODO + action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); break; case ACT_COMMAND: break; -- cgit v1.2.3 From a207e848b3b308406263576c1e0d066067888416 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 26 Feb 2013 16:27:09 +0900 Subject: Add tap flags on record_t --- common/action.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index fc88180309..7f3e236f04 100644 --- a/common/action.c +++ b/common/action.c @@ -206,7 +206,7 @@ void action_exec(keyevent_t event) static void process_action(keyrecord_t *record) { keyevent_t event = record->event; - uint8_t tap_count = record->tap_count; + uint8_t tap_count = record->tap.count; if (IS_NOEVENT(event)) { return; } @@ -295,7 +295,7 @@ static void process_action(keyrecord_t *record) if (waiting_buffer_has_anykey_pressed()) { debug("MODS_TAP: Tap: Cancel: add_mods\n"); // ad hoc: set 0 to cancel tap - record->tap_count = 0; + record->tap.count = 0; add_mods(mods); } else { debug("MODS_TAP: Tap: register_code\n"); @@ -697,16 +697,17 @@ static bool process_tapping(keyrecord_t *keyp) // if tapping if (IS_TAPPING_PRESSED()) { if (WITHIN_TAPPING_TERM(event)) { - if (tapping_key.tap_count == 0) { + if (tapping_key.tap.count == 0) { if (IS_TAPPING_KEY(event.key) && !event.pressed) { // first tap! debug("Tapping: First tap(0->1).\n"); - tapping_key.tap_count = 1; + tapping_key.tap.count = 1; + tapping_key.tap.interrupted = (waiting_buffer_has_anykey_pressed() ? true : false); debug_tapping_key(); process_action(&tapping_key); // enqueue - keyp->tap_count = tapping_key.tap_count; + keyp->tap = tapping_key.tap; return false; } #if TAPPING_TERM >= 500 @@ -730,19 +731,19 @@ static bool process_tapping(keyrecord_t *keyp) // tap_count > 0 else { if (IS_TAPPING_KEY(event.key) && !event.pressed) { - debug("Tapping: Tap release("); debug_dec(tapping_key.tap_count); debug(")\n"); - keyp->tap_count = tapping_key.tap_count; + debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); + keyp->tap = tapping_key.tap; process_action(keyp); tapping_key = *keyp; debug_tapping_key(); return true; } else if (is_tap_key(keyp->event.key) && event.pressed) { - if (tapping_key.tap_count > 1) { + if (tapping_key.tap.count > 1) { debug("Tapping: Start new tap with releasing last tap(>1).\n"); // unregister key process_action(&(keyrecord_t){ - .tap_count = tapping_key.tap_count, + .tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false @@ -766,7 +767,7 @@ static bool process_tapping(keyrecord_t *keyp) } // after TAPPING_TERM else { - if (tapping_key.tap_count == 0) { + if (tapping_key.tap.count == 0) { debug("Tapping: End. Timeout. Not tap(0): "); debug_event(event); debug("\n"); process_action(&tapping_key); @@ -776,17 +777,17 @@ static bool process_tapping(keyrecord_t *keyp) } else { if (IS_TAPPING_KEY(event.key) && !event.pressed) { debug("Tapping: End. last timeout tap release(>0)."); - keyp->tap_count = tapping_key.tap_count; + keyp->tap = tapping_key.tap; process_action(keyp); tapping_key = (keyrecord_t){}; return true; } else if (is_tap_key(keyp->event.key) && event.pressed) { - if (tapping_key.tap_count > 1) { + if (tapping_key.tap.count > 1) { debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); // unregister key process_action(&(keyrecord_t){ - .tap_count = tapping_key.tap_count, + .tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false @@ -810,10 +811,11 @@ static bool process_tapping(keyrecord_t *keyp) } } else if (IS_TAPPING_RELEASED()) { if (WITHIN_TAPPING_TERM(event)) { - if (tapping_key.tap_count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { + if (tapping_key.tap.count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { // sequential tap. - keyp->tap_count = tapping_key.tap_count + 1; - debug("Tapping: Tap press("); debug_dec(keyp->tap_count); debug(")\n"); + keyp->tap = tapping_key.tap; + keyp->tap.count += 1; + debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); process_action(keyp); tapping_key = *keyp; debug_tapping_key(); @@ -858,16 +860,16 @@ static bool process_tapping(keyrecord_t *keyp) static void waiting_buffer_scan_tap(void) { // tapping already is settled - if (tapping_key.tap_count > 0) return; - // invalid state: tapping_key released && tap_count == 0 + if (tapping_key.tap.count > 0) return; + // invalid state: tapping_key released && tap.count == 0 if (!tapping_key.event.pressed) return; for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && !waiting_buffer[i].event.pressed && WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { - tapping_key.tap_count = 1; - waiting_buffer[i].tap_count = 1; + tapping_key.tap.count = 1; + waiting_buffer[i].tap.count = 1; process_action(&tapping_key); debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); @@ -987,6 +989,7 @@ bool is_tap_key(key_t key) default: return false; } + case ACT_MACRO: case ACT_FUNCTION: if (action.func.opt & FUNC_TAP) { return true; } return false; @@ -1006,7 +1009,8 @@ static void debug_event(keyevent_t event) } static void debug_record(keyrecord_t record) { - debug_event(record.event); debug(":"); debug_dec(record.tap_count); + debug_event(record.event); debug(":"); debug_dec(record.tap.count); + if (record.tap.interrupted) debug("-"); } static void debug_action(action_t action) { -- cgit v1.2.3 From 40f1a4930a10ce9253c1215949b497c322db41da Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 27 Feb 2013 10:32:46 +0900 Subject: Fix SET_DEFAULT_LAYER action and keymap of gh60 --- common/action.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 7f3e236f04..7ca481fba7 100644 --- a/common/action.c +++ b/common/action.c @@ -384,21 +384,15 @@ static void process_action(keyrecord_t *record) /* Keymap Reset default layer */ case (OP_RESET | ON_PRESS): if (event.pressed) { - overlay_clear(); - keymap_clear(); default_layer_set(action.layer.val); } break; case (OP_RESET | ON_RELEASE): if (!event.pressed) { - overlay_clear(); - keymap_clear(); default_layer_set(action.layer.val); } break; case (OP_RESET | ON_BOTH): - overlay_clear(); - keymap_clear(); default_layer_set(action.layer.val); break; -- cgit v1.2.3 From 1aa067e5414873559f59e310f38bb43e8803a45f Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 5 Mar 2013 02:42:28 +0900 Subject: Clean action.h and add keymap doc --- common/action.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'common/action.c') diff --git a/common/action.c b/common/action.c index 7ca481fba7..15e125a3ec 100644 --- a/common/action.c +++ b/common/action.c @@ -360,6 +360,7 @@ static void process_action(keyrecord_t *record) case OP_RESET: switch (action.layer.val & 0x03) { case 0: + // NOTE: reserved overlay_clear(); keymap_clear(); break; @@ -379,6 +380,7 @@ static void process_action(keyrecord_t *record) overlay_clear(); keymap_clear(); break; + /* NOTE: 4-7 rserved */ } break; /* Keymap Reset default layer */ @@ -519,6 +521,7 @@ static void process_action(keyrecord_t *record) // Overlay Invert bit4 case OP_INV4 | 0: if (action.layer.val == 0) { + // NOTE: reserved for future use overlay_clear(); } else { overlay_set(overlay_stat ^ action.layer.val); @@ -526,6 +529,7 @@ static void process_action(keyrecord_t *record) break; case OP_INV4 | 1: if (action.layer.val == 0) { + // on pressed if (event.pressed) overlay_clear(); } else { overlay_set(overlay_stat ^ action.layer.val<<4); @@ -533,6 +537,7 @@ static void process_action(keyrecord_t *record) break; case OP_INV4 | 2: if (action.layer.val == 0) { + // on released if (!event.pressed) overlay_clear(); } else { overlay_set(overlay_stat ^ action.layer.val<<8); @@ -540,6 +545,7 @@ static void process_action(keyrecord_t *record) break; case OP_INV4 | 3: if (action.layer.val == 0) { + // on both overlay_clear(); } else { overlay_set(overlay_stat ^ action.layer.val<<12); -- cgit v1.2.3