diff options
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/common/action.c b/common/action.c index fc8818030..7f3e236f0 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -206,7 +206,7 @@ void action_exec(keyevent_t event) | |||
| 206 | static void process_action(keyrecord_t *record) | 206 | static void process_action(keyrecord_t *record) |
| 207 | { | 207 | { |
| 208 | keyevent_t event = record->event; | 208 | keyevent_t event = record->event; |
| 209 | uint8_t tap_count = record->tap_count; | 209 | uint8_t tap_count = record->tap.count; |
| 210 | 210 | ||
| 211 | if (IS_NOEVENT(event)) { return; } | 211 | if (IS_NOEVENT(event)) { return; } |
| 212 | 212 | ||
| @@ -295,7 +295,7 @@ static void process_action(keyrecord_t *record) | |||
| 295 | if (waiting_buffer_has_anykey_pressed()) { | 295 | if (waiting_buffer_has_anykey_pressed()) { |
| 296 | debug("MODS_TAP: Tap: Cancel: add_mods\n"); | 296 | debug("MODS_TAP: Tap: Cancel: add_mods\n"); |
| 297 | // ad hoc: set 0 to cancel tap | 297 | // ad hoc: set 0 to cancel tap |
| 298 | record->tap_count = 0; | 298 | record->tap.count = 0; |
| 299 | add_mods(mods); | 299 | add_mods(mods); |
| 300 | } else { | 300 | } else { |
| 301 | debug("MODS_TAP: Tap: register_code\n"); | 301 | debug("MODS_TAP: Tap: register_code\n"); |
| @@ -697,16 +697,17 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 697 | // if tapping | 697 | // if tapping |
| 698 | if (IS_TAPPING_PRESSED()) { | 698 | if (IS_TAPPING_PRESSED()) { |
| 699 | if (WITHIN_TAPPING_TERM(event)) { | 699 | if (WITHIN_TAPPING_TERM(event)) { |
| 700 | if (tapping_key.tap_count == 0) { | 700 | if (tapping_key.tap.count == 0) { |
| 701 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 701 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 702 | // first tap! | 702 | // first tap! |
| 703 | debug("Tapping: First tap(0->1).\n"); | 703 | debug("Tapping: First tap(0->1).\n"); |
| 704 | tapping_key.tap_count = 1; | 704 | tapping_key.tap.count = 1; |
| 705 | tapping_key.tap.interrupted = (waiting_buffer_has_anykey_pressed() ? true : false); | ||
| 705 | debug_tapping_key(); | 706 | debug_tapping_key(); |
| 706 | process_action(&tapping_key); | 707 | process_action(&tapping_key); |
| 707 | 708 | ||
| 708 | // enqueue | 709 | // enqueue |
| 709 | keyp->tap_count = tapping_key.tap_count; | 710 | keyp->tap = tapping_key.tap; |
| 710 | return false; | 711 | return false; |
| 711 | } | 712 | } |
| 712 | #if TAPPING_TERM >= 500 | 713 | #if TAPPING_TERM >= 500 |
| @@ -730,19 +731,19 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 730 | // tap_count > 0 | 731 | // tap_count > 0 |
| 731 | else { | 732 | else { |
| 732 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 733 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 733 | debug("Tapping: Tap release("); debug_dec(tapping_key.tap_count); debug(")\n"); | 734 | debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); |
| 734 | keyp->tap_count = tapping_key.tap_count; | 735 | keyp->tap = tapping_key.tap; |
| 735 | process_action(keyp); | 736 | process_action(keyp); |
| 736 | tapping_key = *keyp; | 737 | tapping_key = *keyp; |
| 737 | debug_tapping_key(); | 738 | debug_tapping_key(); |
| 738 | return true; | 739 | return true; |
| 739 | } | 740 | } |
| 740 | else if (is_tap_key(keyp->event.key) && event.pressed) { | 741 | else if (is_tap_key(keyp->event.key) && event.pressed) { |
| 741 | if (tapping_key.tap_count > 1) { | 742 | if (tapping_key.tap.count > 1) { |
| 742 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); | 743 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); |
| 743 | // unregister key | 744 | // unregister key |
| 744 | process_action(&(keyrecord_t){ | 745 | process_action(&(keyrecord_t){ |
| 745 | .tap_count = tapping_key.tap_count, | 746 | .tap = tapping_key.tap, |
| 746 | .event.key = tapping_key.event.key, | 747 | .event.key = tapping_key.event.key, |
| 747 | .event.time = event.time, | 748 | .event.time = event.time, |
| 748 | .event.pressed = false | 749 | .event.pressed = false |
| @@ -766,7 +767,7 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 766 | } | 767 | } |
| 767 | // after TAPPING_TERM | 768 | // after TAPPING_TERM |
| 768 | else { | 769 | else { |
| 769 | if (tapping_key.tap_count == 0) { | 770 | if (tapping_key.tap.count == 0) { |
| 770 | debug("Tapping: End. Timeout. Not tap(0): "); | 771 | debug("Tapping: End. Timeout. Not tap(0): "); |
| 771 | debug_event(event); debug("\n"); | 772 | debug_event(event); debug("\n"); |
| 772 | process_action(&tapping_key); | 773 | process_action(&tapping_key); |
| @@ -776,17 +777,17 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 776 | } else { | 777 | } else { |
| 777 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 778 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 778 | debug("Tapping: End. last timeout tap release(>0)."); | 779 | debug("Tapping: End. last timeout tap release(>0)."); |
| 779 | keyp->tap_count = tapping_key.tap_count; | 780 | keyp->tap = tapping_key.tap; |
| 780 | process_action(keyp); | 781 | process_action(keyp); |
| 781 | tapping_key = (keyrecord_t){}; | 782 | tapping_key = (keyrecord_t){}; |
| 782 | return true; | 783 | return true; |
| 783 | } | 784 | } |
| 784 | else if (is_tap_key(keyp->event.key) && event.pressed) { | 785 | else if (is_tap_key(keyp->event.key) && event.pressed) { |
| 785 | if (tapping_key.tap_count > 1) { | 786 | if (tapping_key.tap.count > 1) { |
| 786 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); | 787 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); |
| 787 | // unregister key | 788 | // unregister key |
| 788 | process_action(&(keyrecord_t){ | 789 | process_action(&(keyrecord_t){ |
| 789 | .tap_count = tapping_key.tap_count, | 790 | .tap = tapping_key.tap, |
| 790 | .event.key = tapping_key.event.key, | 791 | .event.key = tapping_key.event.key, |
| 791 | .event.time = event.time, | 792 | .event.time = event.time, |
| 792 | .event.pressed = false | 793 | .event.pressed = false |
| @@ -810,10 +811,11 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 810 | } | 811 | } |
| 811 | } else if (IS_TAPPING_RELEASED()) { | 812 | } else if (IS_TAPPING_RELEASED()) { |
| 812 | if (WITHIN_TAPPING_TERM(event)) { | 813 | if (WITHIN_TAPPING_TERM(event)) { |
| 813 | if (tapping_key.tap_count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { | 814 | if (tapping_key.tap.count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { |
| 814 | // sequential tap. | 815 | // sequential tap. |
| 815 | keyp->tap_count = tapping_key.tap_count + 1; | 816 | keyp->tap = tapping_key.tap; |
| 816 | debug("Tapping: Tap press("); debug_dec(keyp->tap_count); debug(")\n"); | 817 | keyp->tap.count += 1; |
| 818 | debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); | ||
| 817 | process_action(keyp); | 819 | process_action(keyp); |
| 818 | tapping_key = *keyp; | 820 | tapping_key = *keyp; |
| 819 | debug_tapping_key(); | 821 | debug_tapping_key(); |
| @@ -858,16 +860,16 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 858 | static void waiting_buffer_scan_tap(void) | 860 | static void waiting_buffer_scan_tap(void) |
| 859 | { | 861 | { |
| 860 | // tapping already is settled | 862 | // tapping already is settled |
| 861 | if (tapping_key.tap_count > 0) return; | 863 | if (tapping_key.tap.count > 0) return; |
| 862 | // invalid state: tapping_key released && tap_count == 0 | 864 | // invalid state: tapping_key released && tap.count == 0 |
| 863 | if (!tapping_key.event.pressed) return; | 865 | if (!tapping_key.event.pressed) return; |
| 864 | 866 | ||
| 865 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 867 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
| 866 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && | 868 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && |
| 867 | !waiting_buffer[i].event.pressed && | 869 | !waiting_buffer[i].event.pressed && |
| 868 | WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { | 870 | WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { |
| 869 | tapping_key.tap_count = 1; | 871 | tapping_key.tap.count = 1; |
| 870 | waiting_buffer[i].tap_count = 1; | 872 | waiting_buffer[i].tap.count = 1; |
| 871 | process_action(&tapping_key); | 873 | process_action(&tapping_key); |
| 872 | 874 | ||
| 873 | debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); | 875 | debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); |
| @@ -987,6 +989,7 @@ bool is_tap_key(key_t key) | |||
| 987 | default: | 989 | default: |
| 988 | return false; | 990 | return false; |
| 989 | } | 991 | } |
| 992 | case ACT_MACRO: | ||
| 990 | case ACT_FUNCTION: | 993 | case ACT_FUNCTION: |
| 991 | if (action.func.opt & FUNC_TAP) { return true; } | 994 | if (action.func.opt & FUNC_TAP) { return true; } |
| 992 | return false; | 995 | return false; |
| @@ -1006,7 +1009,8 @@ static void debug_event(keyevent_t event) | |||
| 1006 | } | 1009 | } |
| 1007 | static void debug_record(keyrecord_t record) | 1010 | static void debug_record(keyrecord_t record) |
| 1008 | { | 1011 | { |
| 1009 | debug_event(record.event); debug(":"); debug_dec(record.tap_count); | 1012 | debug_event(record.event); debug(":"); debug_dec(record.tap.count); |
| 1013 | if (record.tap.interrupted) debug("-"); | ||
| 1010 | } | 1014 | } |
| 1011 | static void debug_action(action_t action) | 1015 | static void debug_action(action_t action) |
| 1012 | { | 1016 | { |
