]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Space Cadet: Reducing unnecessary reported keypresses (#5781)
authorXScorpion2 <rcalt2vt@gmail.com>
Sun, 5 May 2019 23:27:02 +0000 (18:27 -0500)
committerDrashna Jaelre <drashna@live.com>
Sun, 5 May 2019 23:27:02 +0000 (16:27 -0700)
* Reducing unnecessary reported keypresses and minor docs / variable name changes

* Apply suggestions from code review

Co-Authored-By: XScorpion2 <rcalt2vt@gmail.com>
docs/feature_space_cadet.md
quantum/process_keycode/process_space_cadet.c
quantum/process_keycode/process_space_cadet.h
users/xulkal/config.h

index 3e4665cde68164e9056e7ee77cd36b8a2c24a425..5c375c51842070d1e8c0f247848931f4031b7d8e 100644 (file)
@@ -39,15 +39,15 @@ By default Space Cadet assumes a US ANSI layout, but if your layout uses differe
 |`LSPO_KEYS`     |`KC_LSFT, LSPO_MOD, LSPO_KEY`  |Send `KC_LSFT` when held, the mod and  key defined by `LSPO_MOD` and `LSPO_KEY`. |
 |`RSPC_KEYS`     |`KC_RSFT, RSPC_MOD, RSPC_KEY`  |Send `KC_RSFT` when held, the mod and  key defined by `RSPC_MOD` and `RSPC_KEY`. |
 |`LCPO_KEYS`     |`KC_LCTL, KC_LCTL, KC_9`       |Send `KC_LCTL` when held, the mod `KC_LCTL` with the key `KC_9` when tapped.     |
-|`RCPO_KEYS`     |`KC_RCTL, KC_RCTL, KC_0`       |Send `KC_RCTL` when held, the mod `KC_RCTL` with the key `KC_0` when tapped.     |
+|`RCPC_KEYS`     |`KC_RCTL, KC_RCTL, KC_0`       |Send `KC_RCTL` when held, the mod `KC_RCTL` with the key `KC_0` when tapped.     |
 |`LAPO_KEYS`     |`KC_LALT, KC_LALT, KC_9`       |Send `KC_LALT` when held, the mod `KC_LALT` with the key `KC_9` when tapped.     |
-|`RAPO_KEYS`     |`KC_RALT, KC_RALT, KC_0`       |Send `KC_RALT` when held, the mod `KC_RALT` with the key `KC_0` when tapped.     |
+|`RAPC_KEYS`     |`KC_RALT, KC_RALT, KC_0`       |Send `KC_RALT` when held, the mod `KC_RALT` with the key `KC_0` when tapped.     |
 |`SFTENT_KEYS`   |`KC_RSFT, KC_TRNS, SFTENT_KEY` |Send `KC_RSFT` when held, no mod with the key `SFTENT_KEY` when tapped.          |
 
 
 ## Obsolete Configuration
 
-These defines are used in the above defines internally to support backwards compatibility, so you may continue to use them, however the above defines open up a larger range of flexibility than before. As an example, say you want to not send any modifier when you tap just `KC_LSPO`, with the old defines you had an all or nothing choice of using the `DISABLE_SPACE_CADET_MODIFIER` define. Now you can define that key as: `#define KC_LSPO_KEYS KC_LSFT, KC_TRNS, KC_9`. This tells the system to set Left Shift if held or used with other keys, then on tap send no modifier (transparent) with the `KC_9`
+These defines are used in the above defines internally to support backwards compatibility, so you may continue to use them, however the above defines open up a larger range of flexibility than before. As an example, say you want to not send any modifier when you tap just `KC_LSPO`, with the old defines you had an all or nothing choice of using the `DISABLE_SPACE_CADET_MODIFIER` define. Now you can define that key as: `#define LSPO_KEYS KC_LSFT, KC_TRNS, KC_9`. This tells the system to set Left Shift if held or used with other keys, then on tap send no modifier (transparent) with the `KC_9`.
 
 |Define                        |Default      |Description                                                       |
 |------------------------------|-------------|------------------------------------------------------------------|
index a9c506168d6119d06b14bcedb513d703d702e3f6..ac39df808938075834dd09e646335e459699e1e9 100644 (file)
 #ifndef LCPO_KEYS
   #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9
 #endif
-#ifndef RCPO_KEYS
-  #define RCPO_KEYS KC_RCTL, KC_RCTL, KC_0
+#ifndef RCPC_KEYS
+  #define RCPC_KEYS KC_RCTL, KC_RCTL, KC_0
 #endif
 
 // Alt / paren setup
 #ifndef LAPO_KEYS
   #define LAPO_KEYS KC_LALT, KC_LALT, KC_9
 #endif
-#ifndef RAPO_KEYS
-  #define RAPO_KEYS KC_RALT, KC_RALT, KC_0
+#ifndef RAPC_KEYS
+  #define RAPC_KEYS KC_RALT, KC_RALT, KC_0
 #endif
 
 // Shift / Enter setup
 static uint8_t sc_last = 0;
 static uint16_t sc_timer = 0;
 
-void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode) {
+void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) {
   if (record->event.pressed) {
-    sc_last = normalMod;
+    sc_last = holdMod;
     sc_timer = timer_read ();
-    if (IS_MOD(normalMod)) {
-      register_mods(MOD_BIT(normalMod));
+    if (IS_MOD(holdMod)) {
+      register_mods(MOD_BIT(holdMod));
     }
   }
   else {
-    if (IS_MOD(normalMod)) {
-      unregister_mods(MOD_BIT(normalMod));
-    }
-
-    if (sc_last == normalMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
-      if (IS_MOD(tapMod)) {
-        register_mods(MOD_BIT(tapMod));
+    if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
+      if (holdMod != tapMod) {
+        if (IS_MOD(holdMod)) {
+          unregister_mods(MOD_BIT(holdMod));
+        }
+        if (IS_MOD(tapMod)) {
+          register_mods(MOD_BIT(tapMod));
+        }
       }
       tap_code(keycode);
       if (IS_MOD(tapMod)) {
         unregister_mods(MOD_BIT(tapMod));
       }
+    } else {
+      if (IS_MOD(holdMod)) {
+        unregister_mods(MOD_BIT(holdMod));
+      }
     }
   }
 }
@@ -122,7 +127,7 @@ bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
       return false;
     }
     case KC_RCPC: {
-      perform_space_cadet(record, RCPO_KEYS);
+      perform_space_cadet(record, RCPC_KEYS);
       return false;
     }
     case KC_LAPO: {
@@ -130,7 +135,7 @@ bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
       return false;
     }
     case KC_RAPC: {
-      perform_space_cadet(record, RAPO_KEYS);
+      perform_space_cadet(record, RAPC_KEYS);
       return false;
     }
     case KC_SFTENT: {
index 3f08b8002adf622eea8f2cda5d7067b1068be1b1..c8231435046a4c28d952a0d5d84b61f9d931310d 100644 (file)
@@ -17,5 +17,5 @@
 
 #include "quantum.h"
 
-void perform_space_cadet(keyrecord_t *record, uint8_t normalMod, uint8_t tapMod, uint8_t keycode);
+void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode);
 bool process_space_cadet(uint16_t keycode, keyrecord_t *record);
index 6ff4ca49df44225531fd42d1bac8f5ff517292c3..2899017b0383beb92389474f003bc1217787e9ea 100644 (file)
@@ -10,7 +10,7 @@
 #define LSPO_KEYS KC_LSFT, KC_TRNS, KC_LBRC
 #define RSPC_KEYS KC_RSFT, KC_TRNS, KC_RBRC
 #define LCPO_KEYS KC_LCTL, KC_TRNS, KC_MINS
-#define RCPO_KEYS KC_RCTL, KC_TRNS, KC_EQL
+#define RCPC_KEYS KC_RCTL, KC_TRNS, KC_EQL
 
 // No need for the single versions when multi performance isn't a problem =D
 #define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE