diff options
| -rw-r--r-- | common.mk | 2 | ||||
| -rw-r--r-- | common/action.c | 50 | ||||
| -rw-r--r-- | common/action.h | 39 | ||||
| -rw-r--r-- | common/command.c | 4 | ||||
| -rw-r--r-- | common/layer_stack.c | 108 | ||||
| -rw-r--r-- | common/layer_switch.c | 68 | ||||
| -rw-r--r-- | common/layer_switch.h (renamed from common/layer_stack.h) | 35 | ||||
| -rw-r--r-- | keyboard/gh60/keymap_poker.h | 62 | ||||
| -rw-r--r-- | keyboard/gh60/keymap_poker_stack.h | 6 |
9 files changed, 151 insertions, 223 deletions
| @@ -3,7 +3,7 @@ SRC += $(COMMON_DIR)/host.c \ | |||
| 3 | $(COMMON_DIR)/keyboard.c \ | 3 | $(COMMON_DIR)/keyboard.c \ |
| 4 | $(COMMON_DIR)/action.c \ | 4 | $(COMMON_DIR)/action.c \ |
| 5 | $(COMMON_DIR)/action_macro.c \ | 5 | $(COMMON_DIR)/action_macro.c \ |
| 6 | $(COMMON_DIR)/layer_stack.c \ | 6 | $(COMMON_DIR)/layer_switch.c \ |
| 7 | $(COMMON_DIR)/keymap.c \ | 7 | $(COMMON_DIR)/keymap.c \ |
| 8 | $(COMMON_DIR)/command.c \ | 8 | $(COMMON_DIR)/command.c \ |
| 9 | $(COMMON_DIR)/timer.c \ | 9 | $(COMMON_DIR)/timer.c \ |
diff --git a/common/action.c b/common/action.c index 9a8d75596..4f0a5f906 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "debug.h" | 25 | #include "debug.h" |
| 26 | #include "action.h" | 26 | #include "action.h" |
| 27 | #include "layer_stack.h" | 27 | #include "layer_switch.h" |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* default layer indicates base layer */ | 30 | /* default layer indicates base layer */ |
| @@ -213,8 +213,8 @@ static action_t get_action(key_t key) | |||
| 213 | action_t action; | 213 | action_t action; |
| 214 | action.code = ACTION_NO; | 214 | action.code = ACTION_NO; |
| 215 | 215 | ||
| 216 | /* layer stack */ | 216 | /* layer_switch */ |
| 217 | action = layer_stack_get_action(key); | 217 | action = layer_switch_get_action(key); |
| 218 | if (action.code != ACTION_TRANSPARENT) { | 218 | if (action.code != ACTION_TRANSPARENT) { |
| 219 | return action; | 219 | return action; |
| 220 | } | 220 | } |
| @@ -531,45 +531,38 @@ static void process_action(keyrecord_t *record) | |||
| 531 | break; | 531 | break; |
| 532 | } | 532 | } |
| 533 | break; | 533 | break; |
| 534 | case ACT_LAYER_STACK: | 534 | case ACT_LAYER_SWITCH: |
| 535 | switch (action.layer.code) { | 535 | switch (action.layer.code) { |
| 536 | case LAYER_MOMENTARY: /* momentary */ | 536 | case LAYER_MOMENTARY: /* momentary */ |
| 537 | if (event.pressed) { | 537 | if (event.pressed) { |
| 538 | layer_stack_remove_then_push(action.layer.val); | 538 | layer_switch_on(action.layer.val); |
| 539 | layer_stack_debug(); | ||
| 540 | } else { | 539 | } else { |
| 541 | layer_stack_remove(action.layer.val); | 540 | layer_switch_off(action.layer.val); |
| 542 | layer_stack_debug(); | ||
| 543 | } | 541 | } |
| 544 | break; | 542 | break; |
| 545 | case LAYER_ON_PRESS: | 543 | case LAYER_ON_PRESS: |
| 546 | if (event.pressed) { | 544 | if (event.pressed) { |
| 547 | layer_stack_remove_or_push(action.layer.val); | 545 | layer_switch_inv(action.layer.val); |
| 548 | layer_stack_debug(); | ||
| 549 | } | 546 | } |
| 550 | break; | 547 | break; |
| 551 | case LAYER_ON_RELEASE: | 548 | case LAYER_ON_RELEASE: |
| 552 | if (!event.pressed) { | 549 | if (!event.pressed) { |
| 553 | layer_stack_remove_or_push(action.layer.val); | 550 | layer_switch_inv(action.layer.val); |
| 554 | layer_stack_debug(); | ||
| 555 | } | 551 | } |
| 556 | break; | 552 | break; |
| 557 | case LAYER_ON_BOTH: | 553 | case LAYER_ON_BOTH: |
| 558 | layer_stack_remove_or_push(action.layer.val); | 554 | layer_switch_inv(action.layer.val); |
| 559 | layer_stack_debug(); | ||
| 560 | break; | 555 | break; |
| 561 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 556 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 562 | if (event.pressed) { | 557 | if (event.pressed) { |
| 563 | if (tap_count < TAPPING_TOGGLE) { | 558 | if (tap_count < TAPPING_TOGGLE) { |
| 564 | debug("LAYER_STACK: tap toggle(press).\n"); | 559 | debug("LAYER_SWITCH: tap toggle(press).\n"); |
| 565 | layer_stack_remove_or_push(action.layer.val); | 560 | layer_switch_inv(action.layer.val); |
| 566 | layer_stack_debug(); | ||
| 567 | } | 561 | } |
| 568 | } else { | 562 | } else { |
| 569 | if (tap_count <= TAPPING_TOGGLE) { | 563 | if (tap_count <= TAPPING_TOGGLE) { |
| 570 | debug("LAYER_STACK: tap toggle(release).\n"); | 564 | debug("LAYER_SWITCH: tap toggle(release).\n"); |
| 571 | layer_stack_remove_or_push(action.layer.val); | 565 | layer_switch_inv(action.layer.val); |
| 572 | layer_stack_debug(); | ||
| 573 | } | 566 | } |
| 574 | } | 567 | } |
| 575 | break; | 568 | break; |
| @@ -577,21 +570,19 @@ static void process_action(keyrecord_t *record) | |||
| 577 | // tap key | 570 | // tap key |
| 578 | if (event.pressed) { | 571 | if (event.pressed) { |
| 579 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 572 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 580 | debug("LAYER_STACK: Tap: register_code\n"); | 573 | debug("LAYER_SWITCH: Tap: register_code\n"); |
| 581 | register_code(action.layer.code); | 574 | register_code(action.layer.code); |
| 582 | } else { | 575 | } else { |
| 583 | debug("LAYER_STACK: No tap: layer_stack(on press)\n"); | 576 | debug("LAYER_SWITCH: No tap: layer_switch(on press)\n"); |
| 584 | layer_stack_remove_or_push(action.layer.val); | 577 | layer_switch_inv(action.layer.val); |
| 585 | layer_stack_debug(); | ||
| 586 | } | 578 | } |
| 587 | } else { | 579 | } else { |
| 588 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 580 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 589 | debug("LAYER_STACK: Tap: unregister_code\n"); | 581 | debug("LAYER_SWITCH: Tap: unregister_code\n"); |
| 590 | unregister_code(action.layer.code); | 582 | unregister_code(action.layer.code); |
| 591 | } else { | 583 | } else { |
| 592 | debug("LAYER_STACK: No tap: layer_stack(on release)\n"); | 584 | debug("LAYER_SWITCH: No tap: layer_switch(on release)\n"); |
| 593 | layer_stack_remove_or_push(action.layer.val); | 585 | layer_switch_inv(action.layer.val); |
| 594 | layer_stack_debug(); | ||
| 595 | } | 586 | } |
| 596 | } | 587 | } |
| 597 | break; | 588 | break; |
| @@ -898,6 +889,7 @@ bool sending_anykey(void) | |||
| 898 | host_last_sysytem_report() || host_last_consumer_report()); | 889 | host_last_sysytem_report() || host_last_consumer_report()); |
| 899 | } | 890 | } |
| 900 | 891 | ||
| 892 | // TODO: rename or reinpl with new layer_switch.c | ||
| 901 | void layer_switch(uint8_t new_layer) | 893 | void layer_switch(uint8_t new_layer) |
| 902 | { | 894 | { |
| 903 | if (current_layer != new_layer) { | 895 | if (current_layer != new_layer) { |
| @@ -966,7 +958,7 @@ static void debug_action(action_t action) | |||
| 966 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; | 958 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
| 967 | case ACT_LAYER: debug("ACT_LAYER"); break; | 959 | case ACT_LAYER: debug("ACT_LAYER"); break; |
| 968 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; | 960 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; |
| 969 | case ACT_LAYER_STACK: debug("ACT_LAYER_STACK"); break; | 961 | case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; |
| 970 | case ACT_MACRO: debug("ACT_MACRO"); break; | 962 | case ACT_MACRO: debug("ACT_MACRO"); break; |
| 971 | case ACT_COMMAND: debug("ACT_COMMAND"); break; | 963 | case ACT_COMMAND: debug("ACT_COMMAND"); break; |
| 972 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; | 964 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
diff --git a/common/action.h b/common/action.h index 96b8ba2ed..1d00e02d5 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -163,9 +163,6 @@ bool waiting_buffer_has_anykey_pressed(void); | |||
| 163 | * Layer Actions | 163 | * Layer Actions |
| 164 | * ------------- | 164 | * ------------- |
| 165 | * ACT_LAYER(1000): Set layer | 165 | * ACT_LAYER(1000): Set layer |
| 166 | * ACT_LAYER_BIT(1001): Bit-op layer | ||
| 167 | * ACT_LAYER_STACK: Layer stack | ||
| 168 | * | ||
| 169 | * 1000|LLLL|0000 0000 set current layer on press and return to default on release(momentary) | 166 | * 1000|LLLL|0000 0000 set current layer on press and return to default on release(momentary) |
| 170 | * 1000|LLLL|0000 0001 set current layer on press | 167 | * 1000|LLLL|0000 0001 set current layer on press |
| 171 | * 1000|LLLL|0000 0010 set current layer on release | 168 | * 1000|LLLL|0000 0010 set current layer on release |
| @@ -175,6 +172,7 @@ bool waiting_buffer_has_anykey_pressed(void); | |||
| 175 | * 1000|DDDD|1111 1111 set default layer on press | 172 | * 1000|DDDD|1111 1111 set default layer on press |
| 176 | * L: 0 means default layer | 173 | * L: 0 means default layer |
| 177 | * | 174 | * |
| 175 | * ACT_LAYER_BIT(1001): Bit-op layer | ||
| 178 | * 1001|BBBB|0000 0000 bit-on current layer on press and bit-off on release(momentary) | 176 | * 1001|BBBB|0000 0000 bit-on current layer on press and bit-off on release(momentary) |
| 179 | * 1001|BBBB|0000 0001 bit-xor current layer on press | 177 | * 1001|BBBB|0000 0001 bit-xor current layer on press |
| 180 | * 1001|BBBB|0000 0010 bit-xor current layer on release | 178 | * 1001|BBBB|0000 0010 bit-xor current layer on release |
| @@ -183,12 +181,13 @@ bool waiting_buffer_has_anykey_pressed(void); | |||
| 183 | * 1001|BBBB|1111 0000 bit-xor current layer on hold and toggle on several taps | 181 | * 1001|BBBB|1111 0000 bit-xor current layer on hold and toggle on several taps |
| 184 | * 1001|BBBB|1111 1111 bit-xor default layer on both | 182 | * 1001|BBBB|1111 1111 bit-xor default layer on both |
| 185 | * | 183 | * |
| 186 | * 1011|LLLL|0000 0000 push on press and remove on release(momentary) | 184 | * ACT_LAYER_SWITCH: Switch |
| 187 | * 1011|LLLL|0000 0001 push or remove on press | 185 | * 1011|LLLL|0000 0000 On on press and Off on release(momentary) |
| 188 | * 1011|LLLL|0000 0010 push or remove on release | 186 | * 1011|LLLL|0000 0001 Invert on press |
| 189 | * 1011|LLLL|0000 0011 push or remove on both | 187 | * 1011|LLLL|0000 0010 Invert on release |
| 190 | * 1011|LLLL| keycode push or remove on hold and send key on tap | 188 | * 1011|LLLL|0000 0011 Invert on both |
| 191 | * 1011|LLLL|1111 0000 push or remove on hold and toggle on several taps | 189 | * 1011|LLLL| keycode Invert on hold and send key on tap |
| 190 | * 1011|LLLL|1111 0000 Invert on hold and toggle on several taps | ||
| 192 | * 1011|LLLL|1111 1111 (not used) | 191 | * 1011|LLLL|1111 1111 (not used) |
| 193 | * | 192 | * |
| 194 | * | 193 | * |
| @@ -219,7 +218,7 @@ enum action_kind_id { | |||
| 219 | 218 | ||
| 220 | ACT_LAYER = 0b1000, | 219 | ACT_LAYER = 0b1000, |
| 221 | ACT_LAYER_BIT = 0b1001, | 220 | ACT_LAYER_BIT = 0b1001, |
| 222 | ACT_LAYER_STACK = 0b1011, | 221 | ACT_LAYER_SWITCH = 0b1011, |
| 223 | 222 | ||
| 224 | ACT_MACRO = 0b1100, | 223 | ACT_MACRO = 0b1100, |
| 225 | ACT_COMMAND = 0b1110, | 224 | ACT_COMMAND = 0b1110, |
| @@ -233,7 +232,7 @@ enum action_kind_id { | |||
| 233 | #define ACTION(kind, param) ((kind)<<12 | (param)) | 232 | #define ACTION(kind, param) ((kind)<<12 | (param)) |
| 234 | #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) | 233 | #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) |
| 235 | 234 | ||
| 236 | /* | 235 | /* |
| 237 | * Key | 236 | * Key |
| 238 | */ | 237 | */ |
| 239 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) | 238 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) |
| @@ -316,17 +315,17 @@ enum layer_codes { | |||
| 316 | #define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE) | 315 | #define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE) |
| 317 | #define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key)) | 316 | #define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key)) |
| 318 | /* | 317 | /* |
| 319 | * Layer Stack | 318 | * Layer SWITCH |
| 320 | */ | 319 | */ |
| 321 | /* momentary */ | 320 | /* momentary */ |
| 322 | #define ACTION_LAYER_STACK(layer) ACTION_LAYER_STACK_MOMENTARY(layer) | 321 | #define ACTION_LAYER_SWITCH(layer) ACTION_LAYER_SWITCH_MOMENTARY(layer) |
| 323 | #define ACTION_LAYER_STACK_MOMENTARY(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_MOMENTARY) | 322 | #define ACTION_LAYER_SWITCH_MOMENTARY(layer) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | LAYER_MOMENTARY) |
| 324 | #define ACTION_LAYER_STACK_TOGGLE(layer) ACTION_LAYER_STACK_R(layer) | 323 | #define ACTION_LAYER_SWITCH_TOGGLE(layer) ACTION_LAYER_SWITCH_R(layer) |
| 325 | #define ACTION_LAYER_STACK_P(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_PRESS) | 324 | #define ACTION_LAYER_SWITCH_P(layer) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | LAYER_ON_PRESS) |
| 326 | #define ACTION_LAYER_STACK_R(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_RELEASE) | 325 | #define ACTION_LAYER_SWITCH_R(layer) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | LAYER_ON_RELEASE) |
| 327 | #define ACTION_LAYER_STACK_B(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_BOTH) | 326 | #define ACTION_LAYER_SWITCH_B(layer) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | LAYER_ON_BOTH) |
| 328 | #define ACTION_LAYER_STACK_TAP_TOGGLE(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_TAP_TOGGLE) | 327 | #define ACTION_LAYER_SWITCH_TAP_TOGGLE(layer) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | LAYER_TAP_TOGGLE) |
| 329 | #define ACTION_LAYER_STACK_TAP_KEY(layer, key) ACTION(ACT_LAYER_STACK, (layer)<<8 | (key)) | 328 | #define ACTION_LAYER_SWITCH_TAP_KEY(layer, key) ACTION(ACT_LAYER_SWITCH, (layer)<<8 | (key)) |
| 330 | 329 | ||
| 331 | 330 | ||
| 332 | /* | 331 | /* |
diff --git a/common/command.c b/common/command.c index c5b9f0431..82f647c8f 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -26,8 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 26 | #include "timer.h" | 26 | #include "timer.h" |
| 27 | #include "keyboard.h" | 27 | #include "keyboard.h" |
| 28 | #include "bootloader.h" | 28 | #include "bootloader.h" |
| 29 | #include "layer_switch.h" | ||
| 29 | #include "command.h" | 30 | #include "command.h" |
| 30 | #include "layer_stack.h" | ||
| 31 | 31 | ||
| 32 | #ifdef MOUSEKEY_ENABLE | 32 | #ifdef MOUSEKEY_ENABLE |
| 33 | #include "mousekey.h" | 33 | #include "mousekey.h" |
| @@ -549,6 +549,6 @@ static void switch_default_layer(uint8_t layer) | |||
| 549 | 549 | ||
| 550 | default_layer = layer; | 550 | default_layer = layer; |
| 551 | current_layer = 0; /* 0 means default_layer */ | 551 | current_layer = 0; /* 0 means default_layer */ |
| 552 | layer_stack_clear(); | 552 | layer_switch_clear(); |
| 553 | clear_keyboard(); | 553 | clear_keyboard(); |
| 554 | } | 554 | } |
diff --git a/common/layer_stack.c b/common/layer_stack.c deleted file mode 100644 index 0076bf779..000000000 --- a/common/layer_stack.c +++ /dev/null | |||
| @@ -1,108 +0,0 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include "keyboard.h" | ||
| 3 | #include "layer_stack.h" | ||
| 4 | #include "debug.h" | ||
| 5 | |||
| 6 | |||
| 7 | static uint8_t top_layer = 0; | ||
| 8 | |||
| 9 | /* [0] always works as sentinel and not used for store.*/ | ||
| 10 | static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; | ||
| 11 | |||
| 12 | |||
| 13 | void layer_stack_clear(void) | ||
| 14 | { | ||
| 15 | for (uint8_t i = 0; i < LAYER_STACK_SIZE; i++) { | ||
| 16 | layer_stack[i] = (layer_item_t){ .layer = 0, | ||
| 17 | .next = 0, | ||
| 18 | .used = false }; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | bool layer_stack_push(uint8_t layer) | ||
| 23 | { | ||
| 24 | for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { | ||
| 25 | if (!layer_stack[i].used) { | ||
| 26 | layer_stack[i] = (layer_item_t){ .layer = layer, | ||
| 27 | .next = top_layer, | ||
| 28 | .used = true }; | ||
| 29 | top_layer = i; | ||
| 30 | return true; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | bool layer_stack_pop(void) | ||
| 37 | { | ||
| 38 | if (layer_stack[top_layer].used) { | ||
| 39 | uint8_t popped = top_layer; | ||
| 40 | top_layer = layer_stack[popped].next; | ||
| 41 | layer_stack[popped] = (layer_item_t){}; | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | return false; | ||
| 45 | } | ||
| 46 | |||
| 47 | bool layer_stack_remove(uint8_t layer) | ||
| 48 | { | ||
| 49 | if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) { | ||
| 50 | layer_stack_pop(); | ||
| 51 | debug("layer_stack_remove: top_layer\n"); | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | |||
| 55 | for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) { | ||
| 56 | debug("layer_stack_remove: ["); debug_dec(i); debug("]"); | ||
| 57 | debug_dec(layer_stack[i].layer); debug("\n"); | ||
| 58 | uint8_t removed = layer_stack[i].next; | ||
| 59 | if (layer_stack[removed].used && layer_stack[removed].layer == layer) { | ||
| 60 | layer_stack[i].next = layer_stack[removed].next; | ||
| 61 | layer_stack[removed] = (layer_item_t){}; | ||
| 62 | debug("layer_stack_remove: removed.\n"); | ||
| 63 | return true; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | return false; | ||
| 67 | } | ||
| 68 | |||
| 69 | bool layer_stack_remove_then_push(uint8_t layer) | ||
| 70 | { | ||
| 71 | layer_stack_remove(layer); | ||
| 72 | return layer_stack_push(layer); | ||
| 73 | } | ||
| 74 | |||
| 75 | bool layer_stack_remove_or_push(uint8_t layer) | ||
| 76 | { | ||
| 77 | return (layer_stack_remove(layer)) || layer_stack_push(layer); | ||
| 78 | } | ||
| 79 | |||
| 80 | void layer_stack_debug(void) | ||
| 81 | { | ||
| 82 | debug("layer_stack: "); | ||
| 83 | layer_item_t item = layer_stack[top_layer]; | ||
| 84 | while (item.used) { | ||
| 85 | debug_dec(item.layer); | ||
| 86 | debug("["); debug_dec(item.next); debug("] "); | ||
| 87 | item = layer_stack[item.next]; | ||
| 88 | } | ||
| 89 | debug("\n"); | ||
| 90 | } | ||
| 91 | |||
| 92 | action_t layer_stack_get_action(key_t key) | ||
| 93 | { | ||
| 94 | action_t action; | ||
| 95 | action.code = ACTION_TRANSPARENT; | ||
| 96 | |||
| 97 | /* layer stack */ | ||
| 98 | for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { | ||
| 99 | action = action_for_key(i.layer, key); | ||
| 100 | if (action.code != ACTION_TRANSPARENT) { | ||
| 101 | layer_stack_debug(); | ||
| 102 | debug("layer_stack: used. "); debug_dec(i.layer); debug("\n"); | ||
| 103 | return action; | ||
| 104 | } | ||
| 105 | debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); | ||
| 106 | } | ||
| 107 | return action; | ||
| 108 | } | ||
diff --git a/common/layer_switch.c b/common/layer_switch.c new file mode 100644 index 000000000..9bc804e64 --- /dev/null +++ b/common/layer_switch.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | #include <stdint.h> | ||
| 2 | #include "keyboard.h" | ||
| 3 | #include "action.h" | ||
| 4 | #include "debug.h" | ||
| 5 | #include "layer_switch.h" | ||
| 6 | |||
| 7 | |||
| 8 | uint16_t layer_switch_stat = 0; | ||
| 9 | |||
| 10 | |||
| 11 | uint16_t layer_switch_stat_get(void) | ||
| 12 | { | ||
| 13 | return layer_switch_stat; | ||
| 14 | } | ||
| 15 | |||
| 16 | void layer_switch_stat_set(uint16_t stat) | ||
| 17 | { | ||
| 18 | layer_switch_stat = stat; | ||
| 19 | layer_switch_debug(); | ||
| 20 | } | ||
| 21 | |||
| 22 | void layer_switch_clear(void) | ||
| 23 | { | ||
| 24 | layer_switch_stat = 0; | ||
| 25 | layer_switch_debug(); | ||
| 26 | } | ||
| 27 | |||
| 28 | void layer_switch_on(uint8_t layer) | ||
| 29 | { | ||
| 30 | layer_switch_stat |= (1<<layer); | ||
| 31 | layer_switch_debug(); | ||
| 32 | } | ||
| 33 | |||
| 34 | void layer_switch_off(uint8_t layer) | ||
| 35 | { | ||
| 36 | layer_switch_stat &= ~(1<<layer); | ||
| 37 | layer_switch_debug(); | ||
| 38 | } | ||
| 39 | |||
| 40 | void layer_switch_inv(uint8_t layer) | ||
| 41 | { | ||
| 42 | layer_switch_stat ^= (1<<layer); | ||
| 43 | layer_switch_debug(); | ||
| 44 | } | ||
| 45 | |||
| 46 | void layer_switch_debug(void) | ||
| 47 | { | ||
| 48 | debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n"); | ||
| 49 | } | ||
| 50 | |||
| 51 | action_t layer_switch_get_action(key_t key) | ||
| 52 | { | ||
| 53 | action_t action; | ||
| 54 | action.code = ACTION_TRANSPARENT; | ||
| 55 | |||
| 56 | /* higher layer first */ | ||
| 57 | for (int8_t i = 15; i >= 0; i--) { | ||
| 58 | if (layer_switch_stat & (1<<i)) { | ||
| 59 | action = action_for_key(i, key); | ||
| 60 | if (action.code != ACTION_TRANSPARENT) { | ||
| 61 | layer_switch_debug(); | ||
| 62 | debug("layer_switch: used. "); debug_dec(i); debug("\n"); | ||
| 63 | return action; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | return action; | ||
| 68 | } | ||
diff --git a/common/layer_stack.h b/common/layer_switch.h index 25bf37a5b..9f0695260 100644 --- a/common/layer_stack.h +++ b/common/layer_switch.h | |||
| @@ -14,32 +14,23 @@ GNU General Public License for more details. | |||
| 14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | #ifndef LAYER_STACK_H | 17 | #ifndef LAYER_SWITCH_H |
| 18 | #define LAYER_STACK_H | 18 | #define LAYER_SWITCH_H |
| 19 | 19 | ||
| 20 | #include <stdint.h> | 20 | #include <stdint.h> |
| 21 | #include "keyboard.h" | ||
| 21 | #include "action.h" | 22 | #include "action.h" |
| 22 | 23 | ||
| 24 | uint16_t layer_switch_stat; | ||
| 23 | 25 | ||
| 24 | /* | 26 | uint16_t layer_switch_stat_get(void); |
| 25 | * Layer stack | 27 | void layer_switch_stat_set(uint16_t stat); |
| 26 | */ | 28 | void layer_switch_clear(void); |
| 27 | #define LAYER_STACK_SIZE 8 | 29 | void layer_switch_on(uint8_t layer); |
| 28 | typedef struct { | 30 | void layer_switch_off(uint8_t layer); |
| 29 | uint8_t layer:4; | 31 | /* invert state */ |
| 30 | uint8_t next:3; | 32 | void layer_switch_inv(uint8_t layer); |
| 31 | bool used; | 33 | void layer_switch_debug(void); |
| 32 | } layer_item_t; | 34 | action_t layer_switch_get_action(key_t key); |
| 33 | |||
| 34 | |||
| 35 | void layer_stack_clear(void); | ||
| 36 | bool layer_stack_push(uint8_t layer); | ||
| 37 | bool layer_stack_pop(void); | ||
| 38 | bool layer_stack_remove(uint8_t layer); | ||
| 39 | bool layer_stack_remove_then_push(uint8_t layer); | ||
| 40 | bool layer_stack_remove_or_push(uint8_t layer); | ||
| 41 | void layer_stack_debug(void); | ||
| 42 | action_t layer_stack_get_action(key_t key); | ||
| 43 | 35 | ||
| 44 | #endif | 36 | #endif |
| 45 | |||
diff --git a/keyboard/gh60/keymap_poker.h b/keyboard/gh60/keymap_poker.h index 7dc4efe01..08c24f926 100644 --- a/keyboard/gh60/keymap_poker.h +++ b/keyboard/gh60/keymap_poker.h | |||
| @@ -20,59 +20,44 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 20 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ | 20 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ |
| 21 | LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ | 21 | LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ |
| 22 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ | 22 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ |
| 23 | LCTL,LGUI,LALT, SPC, FN2, RGUI,APP, RCTL), | 23 | LCTL,LGUI,LALT, SPC, FN3, RGUI,APP, RCTL), |
| 24 | /* Layer x001: Poker with Arrow */ | 24 | /* Layer 1: Poker with Arrow */ |
| 25 | KEYMAP_ANSI( | 25 | KEYMAP_ANSI( |
| 26 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | 26 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ |
| 27 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | 27 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ |
| 28 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | 28 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ |
| 29 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ | 29 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ |
| 30 | TRNS,TRNS,TRNS, TRNS, FN2, LEFT,DOWN,RGHT), | 30 | TRNS,TRNS,TRNS, TRNS, FN4, LEFT,DOWN,RGHT), |
| 31 | /* Layer x010: Poker with Esc */ | 31 | /* Layer 2: Poker with Esc */ |
| 32 | KEYMAP_ANSI( | 32 | KEYMAP_ANSI( |
| 33 | ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | 33 | ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ |
| 34 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | 34 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ |
| 35 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | 35 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ |
| 36 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | 36 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ |
| 37 | TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS), | 37 | TRNS,TRNS,TRNS, TRNS, FN5, TRNS,TRNS,TRNS), |
| 38 | /* Layer x011: Poker with Arrow and Esc */ | 38 | /* Layer 3: Poker Default + Fn'd */ |
| 39 | KEYMAP_ANSI( | ||
| 40 | ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | ||
| 41 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | ||
| 42 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | ||
| 43 | TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ | ||
| 44 | TRNS,TRNS,TRNS, TRNS, FN2, LEFT,DOWN,RGHT), | ||
| 45 | /* | ||
| 46 | * Poker Momentary Fn Layer | ||
| 47 | */ | ||
| 48 | /* Layer x100: Poker Default + Fn'd */ | ||
| 49 | KEYMAP_ANSI( | 39 | KEYMAP_ANSI( |
| 50 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | 40 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ |
| 51 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | 41 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ |
| 52 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ | 42 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN0, END, TRNS, \ |
| 53 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ | 43 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, UP, \ |
| 54 | TRNS,TRNS,TRNS, FN0, FN2, TRNS,TRNS,TRNS), | 44 | TRNS,TRNS,TRNS, FN0, FN3, LEFT,DOWN,RGHT), |
| 55 | /* Layer x101: Poker with Arrow + Fn'd */ | 45 | |
| 46 | /* Layer 4: Poker Default + Fn'd */ | ||
| 56 | KEYMAP_ANSI( | 47 | KEYMAP_ANSI( |
| 57 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | 48 | TRNS F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ |
| 58 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | 49 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ |
| 59 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ | 50 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN0, END, TRNS, \ |
| 60 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \ | 51 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, UP, \ |
| 61 | TRNS,TRNS,TRNS, FN0, FN2, HOME,PGDN,END), | 52 | TRNS,TRNS,TRNS, FN0, FN4, HOME,PGDN,END), |
| 62 | /* Layer x110: Poker with Esc + Fn'd */ | 53 | /* Layer 5: Poker Default + Fn'd */ |
| 63 | KEYMAP_ANSI( | 54 | KEYMAP_ANSI( |
| 64 | GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | 55 | GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ |
| 65 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | 56 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ |
| 66 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ | 57 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN0, END, TRNS, \ |
| 67 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ | 58 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ |
| 68 | TRNS,TRNS,TRNS, FN0, FN2, TRNS,TRNS,TRNS), | 59 | TRNS,TRNS,TRNS, FN0, FN5, TRNS,TRNS,TRNS), |
| 69 | /* Layer x111: Poker with Arrow and Esc + Fn'd */ | 60 | |
| 70 | KEYMAP_ANSI( | ||
| 71 | GRV, F9, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | ||
| 72 | CAPS,FN1, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | ||
| 73 | TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ | ||
| 74 | TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \ | ||
| 75 | TRNS,TRNS,TRNS, FN0, FN2, HOME,PGDN,END), | ||
| 76 | /* colemak */ | 61 | /* colemak */ |
| 77 | [8] = KEYMAP_ANSI( | 62 | [8] = KEYMAP_ANSI( |
| 78 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ | 63 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ |
| @@ -101,9 +86,10 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 101 | */ | 86 | */ |
| 102 | static const uint16_t PROGMEM fn_actions[] = { | 87 | static const uint16_t PROGMEM fn_actions[] = { |
| 103 | /* Poker Layout */ | 88 | /* Poker Layout */ |
| 104 | [0] = ACTION_LAYER_BIT_TOGGLE(1), // FN0 Poker Arrow toggle(Space) | 89 | [0] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN0 Task(RControl,RShift+Esc) |
| 105 | [1] = ACTION_LAYER_BIT_TOGGLE(2), // FN1 Poker Esc toggle(Q) | 90 | [0] = ACTION_LAYER_BIT_TOGGLE(1), // FN1 Poker Arrow toggle(Space) |
| 106 | [2] = ACTION_LAYER_BIT(4), // FN2 Poker Fn | 91 | [1] = ACTION_LAYER_BIT_TOGGLE(2), // FN2 Poker Esc toggle(Q) |
| 107 | [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc) | 92 | [2] = ACTION_LAYER_BIT(3), // FN3 Poker Fn |
| 93 | [3] = ACTION_LAYER_BIT(4), // FN4 Poker Fn | ||
| 108 | }; | 94 | }; |
| 109 | 95 | ||
diff --git a/keyboard/gh60/keymap_poker_stack.h b/keyboard/gh60/keymap_poker_stack.h index 4c1019352..b074abaa5 100644 --- a/keyboard/gh60/keymap_poker_stack.h +++ b/keyboard/gh60/keymap_poker_stack.h | |||
| @@ -70,8 +70,8 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 70 | */ | 70 | */ |
| 71 | static const uint16_t PROGMEM fn_actions[] = { | 71 | static const uint16_t PROGMEM fn_actions[] = { |
| 72 | /* Poker Layout */ | 72 | /* Poker Layout */ |
| 73 | [0] = ACTION_LAYER_STACK_TOGGLE(1), // FN0 Poker Arrow toggle(Space) | 73 | [0] = ACTION_LAYER_SWITCH_TOGGLE(1), // FN0 Poker Arrow toggle(Space) |
| 74 | [1] = ACTION_LAYER_STACK_TOGGLE(2), // FN1 Poker Esc toggle(Q) | 74 | [1] = ACTION_LAYER_SWITCH_TOGGLE(2), // FN1 Poker Esc toggle(Q) |
| 75 | [2] = ACTION_LAYER_STACK(3), // FN2 Poker Fn | 75 | [2] = ACTION_LAYER_SWITCH(3), // FN2 Poker Fn |
| 76 | [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc) | 76 | [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc) |
| 77 | }; | 77 | }; |
