1 /* Copyright 2019 Jack Humbert
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.
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.
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/>.
16 #include "process_space_cadet.h"
19 #define TAPPING_TERM 200
22 // ********** OBSOLETE DEFINES, STOP USING! (pls?) **********
23 // Shift / paren setup
31 // Shift / Enter setup
33 #define SFTENT_KEY KC_ENT
36 #ifdef DISABLE_SPACE_CADET_MODIFIER
38 #define LSPO_MOD KC_TRNS
41 #define RSPC_MOD KC_TRNS
45 #define LSPO_MOD KC_LSFT
48 #define RSPC_MOD KC_RSFT
51 // **********************************************************
53 // Shift / paren setup
55 #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY
58 #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY
61 // Control / paren setup
63 #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9
66 #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0
71 #define LAPO_KEYS KC_LALT, KC_LALT, KC_9
74 #define RAPO_KEYS KC_RALT, KC_RALT, KC_0
77 // Shift / Enter setup
79 #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY
82 static uint8_t sc_last = 0;
83 static uint16_t sc_timer = 0;
85 void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) {
86 if (record->event.pressed) {
88 sc_timer = timer_read ();
89 if (IS_MOD(normalMod)) {
90 register_mods(MOD_BIT(normalMod));
94 if (IS_MOD(normalMod)) {
95 unregister_mods(MOD_BIT(normalMod));
98 if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
100 register_mods(MOD_BIT(tapMod));
103 if (IS_MOD(tapMod)) {
104 unregister_mods(MOD_BIT(tapMod));
110 bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
113 perform_space_cadet(record, LSPO_KEYS);
117 perform_space_cadet(record, RSPC_KEYS);
121 perform_space_cadet(record, LCPO_KEYS);
125 perform_space_cadet(record, RCPO_KEYS);
129 perform_space_cadet(record, LAPO_KEYS);
133 perform_space_cadet(record, RAPO_KEYS);
137 perform_space_cadet(record, SFTENT_KEYS);