diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/process_keycode/process_space_cadet.c | 146 | ||||
-rw-r--r-- | quantum/process_keycode/process_space_cadet.h | 21 | ||||
-rw-r--r-- | quantum/quantum.c | 123 | ||||
-rw-r--r-- | quantum/quantum.h | 4 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 12 |
5 files changed, 186 insertions, 120 deletions
diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c new file mode 100644 index 000000000..a9c506168 --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* Copyright 2019 Jack Humbert | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #include "process_space_cadet.h" | ||
17 | |||
18 | #ifndef TAPPING_TERM | ||
19 | #define TAPPING_TERM 200 | ||
20 | #endif | ||
21 | |||
22 | // ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** | ||
23 | // Shift / paren setup | ||
24 | #ifndef LSPO_KEY | ||
25 | #define LSPO_KEY KC_9 | ||
26 | #endif | ||
27 | #ifndef RSPC_KEY | ||
28 | #define RSPC_KEY KC_0 | ||
29 | #endif | ||
30 | |||
31 | // Shift / Enter setup | ||
32 | #ifndef SFTENT_KEY | ||
33 | #define SFTENT_KEY KC_ENT | ||
34 | #endif | ||
35 | |||
36 | #ifdef DISABLE_SPACE_CADET_MODIFIER | ||
37 | #ifndef LSPO_MOD | ||
38 | #define LSPO_MOD KC_TRNS | ||
39 | #endif | ||
40 | #ifndef RSPC_MOD | ||
41 | #define RSPC_MOD KC_TRNS | ||
42 | #endif | ||
43 | #else | ||
44 | #ifndef LSPO_MOD | ||
45 | #define LSPO_MOD KC_LSFT | ||
46 | #endif | ||
47 | #ifndef RSPC_MOD | ||
48 | #define RSPC_MOD KC_RSFT | ||
49 | #endif | ||
50 | #endif | ||
51 | // ********************************************************** | ||
52 | |||
53 | // Shift / paren setup | ||
54 | #ifndef LSPO_KEYS | ||
55 | #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY | ||
56 | #endif | ||
57 | #ifndef RSPC_KEYS | ||
58 | #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY | ||
59 | #endif | ||
60 | |||
61 | // Control / paren setup | ||
62 | #ifndef LCPO_KEYS | ||
63 | #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 | ||
64 | #endif | ||
65 | #ifndef RCPO_KEYS | ||
66 | #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0 | ||
67 | #endif | ||
68 | |||
69 | // Alt / paren setup | ||
70 | #ifndef LAPO_KEYS | ||
71 | #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 | ||
72 | #endif | ||
73 | #ifndef RAPO_KEYS | ||
74 | #define RAPO_KEYS KC_RALT, KC_RALT, KC_0 | ||
75 | #endif | ||
76 | |||
77 | // Shift / Enter setup | ||
78 | #ifndef SFTENT_KEYS | ||
79 | #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY | ||
80 | #endif | ||
81 | |||
82 | static uint8_t sc_last = 0; | ||
83 | static uint16_t sc_timer = 0; | ||
84 | |||
85 | void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) { | ||
86 | if (record->event.pressed) { | ||
87 | sc_last = normalMod; | ||
88 | sc_timer = timer_read (); | ||
89 | if (IS_MOD(normalMod)) { | ||
90 | register_mods(MOD_BIT(normalMod)); | ||
91 | } | ||
92 | } | ||
93 | else { | ||
94 | if (IS_MOD(normalMod)) { | ||
95 | unregister_mods(MOD_BIT(normalMod)); | ||
96 | } | ||
97 | |||
98 | if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) { | ||
99 | if (IS_MOD(tapMod)) { | ||
100 | register_mods(MOD_BIT(tapMod)); | ||
101 | } | ||
102 | tap_code(keycode); | ||
103 | if (IS_MOD(tapMod)) { | ||
104 | unregister_mods(MOD_BIT(tapMod)); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { | ||
111 | switch(keycode) { | ||
112 | case KC_LSPO: { | ||
113 | perform_space_cadet(record, LSPO_KEYS); | ||
114 | return false; | ||
115 | } | ||
116 | case KC_RSPC: { | ||
117 | perform_space_cadet(record, RSPC_KEYS); | ||
118 | return false; | ||
119 | } | ||
120 | case KC_LCPO: { | ||
121 | perform_space_cadet(record, LCPO_KEYS); | ||
122 | return false; | ||
123 | } | ||
124 | case KC_RCPC: { | ||
125 | perform_space_cadet(record, RCPO_KEYS); | ||
126 | return false; | ||
127 | } | ||
128 | case KC_LAPO: { | ||
129 | perform_space_cadet(record, LAPO_KEYS); | ||
130 | return false; | ||
131 | } | ||
132 | case KC_RAPC: { | ||
133 | perform_space_cadet(record, RAPO_KEYS); | ||
134 | return false; | ||
135 | } | ||
136 | case KC_SFTENT: { | ||
137 | perform_space_cadet(record, SFTENT_KEYS); | ||
138 | return false; | ||
139 | } | ||
140 | default: { | ||
141 | sc_last = 0; | ||
142 | break; | ||
143 | } | ||
144 | } | ||
145 | return true; | ||
146 | } | ||
diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h new file mode 100644 index 000000000..3f08b8002 --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2019 Jack Humbert | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #pragma once | ||
17 | |||
18 | #include "quantum.h" | ||
19 | |||
20 | void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode); | ||
21 | bool process_space_cadet(uint16_t keycode, keyrecord_t *record); | ||
diff --git a/quantum/quantum.c b/quantum/quantum.c index 0fb798a74..fcedf0bc1 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -24,10 +24,6 @@ | |||
24 | #include "outputselect.h" | 24 | #include "outputselect.h" |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifndef TAPPING_TERM | ||
28 | #define TAPPING_TERM 200 | ||
29 | #endif | ||
30 | |||
31 | #ifndef BREATHING_PERIOD | 27 | #ifndef BREATHING_PERIOD |
32 | #define BREATHING_PERIOD 6 | 28 | #define BREATHING_PERIOD 6 |
33 | #endif | 29 | #endif |
@@ -196,30 +192,6 @@ void reset_keyboard(void) { | |||
196 | bootloader_jump(); | 192 | bootloader_jump(); |
197 | } | 193 | } |
198 | 194 | ||
199 | // Shift / paren setup | ||
200 | |||
201 | #ifndef LSPO_KEY | ||
202 | #define LSPO_KEY KC_9 | ||
203 | #endif | ||
204 | #ifndef RSPC_KEY | ||
205 | #define RSPC_KEY KC_0 | ||
206 | #endif | ||
207 | |||
208 | #ifndef LSPO_MOD | ||
209 | #define LSPO_MOD KC_LSFT | ||
210 | #endif | ||
211 | #ifndef RSPC_MOD | ||
212 | #define RSPC_MOD KC_RSFT | ||
213 | #endif | ||
214 | |||
215 | // Shift / Enter setup | ||
216 | #ifndef SFTENT_KEY | ||
217 | #define SFTENT_KEY KC_ENT | ||
218 | #endif | ||
219 | |||
220 | static bool shift_interrupted[2] = {0, 0}; | ||
221 | static uint16_t scs_timer[2] = {0, 0}; | ||
222 | |||
223 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. | 195 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. |
224 | * Used to ensure that the correct keycode is released if the key is released. | 196 | * Used to ensure that the correct keycode is released if the key is released. |
225 | */ | 197 | */ |
@@ -329,6 +301,9 @@ bool process_record_quantum(keyrecord_t *record) { | |||
329 | #ifdef TERMINAL_ENABLE | 301 | #ifdef TERMINAL_ENABLE |
330 | process_terminal(keycode, record) && | 302 | process_terminal(keycode, record) && |
331 | #endif | 303 | #endif |
304 | #ifdef SPACE_CADET_ENABLE | ||
305 | process_space_cadet(keycode, record) && | ||
306 | #endif | ||
332 | true)) { | 307 | true)) { |
333 | return false; | 308 | return false; |
334 | } | 309 | } |
@@ -685,92 +660,6 @@ bool process_record_quantum(keyrecord_t *record) { | |||
685 | return false; | 660 | return false; |
686 | } | 661 | } |
687 | break; | 662 | break; |
688 | case KC_LSPO: { | ||
689 | if (record->event.pressed) { | ||
690 | shift_interrupted[0] = false; | ||
691 | scs_timer[0] = timer_read (); | ||
692 | register_mods(MOD_BIT(KC_LSFT)); | ||
693 | } | ||
694 | else { | ||
695 | #ifdef DISABLE_SPACE_CADET_ROLLOVER | ||
696 | if (get_mods() & MOD_BIT(RSPC_MOD)) { | ||
697 | shift_interrupted[0] = true; | ||
698 | shift_interrupted[1] = true; | ||
699 | } | ||
700 | #endif | ||
701 | if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) { | ||
702 | #ifdef DISABLE_SPACE_CADET_MODIFIER | ||
703 | unregister_mods(MOD_BIT(KC_LSFT)); | ||
704 | #else | ||
705 | if( LSPO_MOD != KC_LSFT ){ | ||
706 | unregister_mods(MOD_BIT(KC_LSFT)); | ||
707 | register_mods(MOD_BIT(LSPO_MOD)); | ||
708 | } | ||
709 | #endif | ||
710 | register_code(LSPO_KEY); | ||
711 | unregister_code(LSPO_KEY); | ||
712 | #ifndef DISABLE_SPACE_CADET_MODIFIER | ||
713 | if( LSPO_MOD != KC_LSFT ){ | ||
714 | unregister_mods(MOD_BIT(LSPO_MOD)); | ||
715 | } | ||
716 | #endif | ||
717 | } | ||
718 | unregister_mods(MOD_BIT(KC_LSFT)); | ||
719 | } | ||
720 | return false; | ||
721 | } | ||
722 | |||
723 | case KC_RSPC: { | ||
724 | if (record->event.pressed) { | ||
725 | shift_interrupted[1] = false; | ||
726 | scs_timer[1] = timer_read (); | ||
727 | register_mods(MOD_BIT(KC_RSFT)); | ||
728 | } | ||
729 | else { | ||
730 | #ifdef DISABLE_SPACE_CADET_ROLLOVER | ||
731 | if (get_mods() & MOD_BIT(LSPO_MOD)) { | ||
732 | shift_interrupted[0] = true; | ||
733 | shift_interrupted[1] = true; | ||
734 | } | ||
735 | #endif | ||
736 | if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { | ||
737 | #ifdef DISABLE_SPACE_CADET_MODIFIER | ||
738 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
739 | #else | ||
740 | if( RSPC_MOD != KC_RSFT ){ | ||
741 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
742 | register_mods(MOD_BIT(RSPC_MOD)); | ||
743 | } | ||
744 | #endif | ||
745 | register_code(RSPC_KEY); | ||
746 | unregister_code(RSPC_KEY); | ||
747 | #ifndef DISABLE_SPACE_CADET_MODIFIER | ||
748 | if ( RSPC_MOD != KC_RSFT ){ | ||
749 | unregister_mods(MOD_BIT(RSPC_MOD)); | ||
750 | } | ||
751 | #endif | ||
752 | } | ||
753 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
754 | } | ||
755 | return false; | ||
756 | } | ||
757 | |||
758 | case KC_SFTENT: { | ||
759 | if (record->event.pressed) { | ||
760 | shift_interrupted[1] = false; | ||
761 | scs_timer[1] = timer_read (); | ||
762 | register_mods(MOD_BIT(KC_RSFT)); | ||
763 | } | ||
764 | else if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { | ||
765 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
766 | register_code(SFTENT_KEY); | ||
767 | unregister_code(SFTENT_KEY); | ||
768 | } | ||
769 | else { | ||
770 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
771 | } | ||
772 | return false; | ||
773 | } | ||
774 | 663 | ||
775 | case GRAVE_ESC: { | 664 | case GRAVE_ESC: { |
776 | uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) | 665 | uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) |
@@ -825,12 +714,6 @@ bool process_record_quantum(keyrecord_t *record) { | |||
825 | return false; | 714 | return false; |
826 | } | 715 | } |
827 | #endif | 716 | #endif |
828 | |||
829 | default: { | ||
830 | shift_interrupted[0] = true; | ||
831 | shift_interrupted[1] = true; | ||
832 | break; | ||
833 | } | ||
834 | } | 717 | } |
835 | 718 | ||
836 | return process_action_kb(record); | 719 | return process_action_kb(record); |
diff --git a/quantum/quantum.h b/quantum/quantum.h index 17cb90274..208268df6 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -131,6 +131,10 @@ extern uint32_t default_layer_state; | |||
131 | #include "process_terminal_nop.h" | 131 | #include "process_terminal_nop.h" |
132 | #endif | 132 | #endif |
133 | 133 | ||
134 | #ifdef SPACE_CADET_ENABLE | ||
135 | #include "process_space_cadet.h" | ||
136 | #endif | ||
137 | |||
134 | #ifdef HD44780_ENABLE | 138 | #ifdef HD44780_ENABLE |
135 | #include "hd44780.h" | 139 | #include "hd44780.h" |
136 | #endif | 140 | #endif |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index fe2e3510d..19bd7c216 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -475,6 +475,18 @@ enum quantum_keycodes { | |||
475 | HPT_DWLI, | 475 | HPT_DWLI, |
476 | HPT_DWLD, | 476 | HPT_DWLD, |
477 | 477 | ||
478 | // Left control, open paren | ||
479 | KC_LCPO, | ||
480 | |||
481 | // Right control, close paren | ||
482 | KC_RCPC, | ||
483 | |||
484 | // Left control, open paren | ||
485 | KC_LAPO, | ||
486 | |||
487 | // Right control, close paren | ||
488 | KC_RAPC, | ||
489 | |||
478 | // always leave at the end | 490 | // always leave at the end |
479 | SAFE_RANGE | 491 | SAFE_RANGE |
480 | }; | 492 | }; |