diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2019-04-29 22:21:46 -0500 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-04-29 20:21:46 -0700 |
commit | c745d9b82e3f2047feb97a7a8937f27c6e989fd7 (patch) | |
tree | 503962c0a0aafa20c6c84bce0bf704b49cd98dd9 /quantum/process_keycode/process_space_cadet.c | |
parent | 7d4ae3e66ebe1e9ff52ad4eb87da8cd9f01c142a (diff) | |
download | qmk_firmware-c745d9b82e3f2047feb97a7a8937f27c6e989fd7.tar.gz qmk_firmware-c745d9b82e3f2047feb97a7a8937f27c6e989fd7.zip |
Simple extended space cadet (#5277)
* Simplifying and Extending Space Cadet to work on Ctrl and Alt keys
* PR Review feedback
* Reverting back to keycodes
Diffstat (limited to 'quantum/process_keycode/process_space_cadet.c')
-rw-r--r-- | quantum/process_keycode/process_space_cadet.c | 146 |
1 files changed, 146 insertions, 0 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 | } | ||