diff options
| author | Drashna Jaelre <drashna@live.com> | 2019-11-03 09:52:01 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-03 09:52:01 -0800 |
| commit | e9c44e396d21df990b1d08e8b4c30e288797dffe (patch) | |
| tree | db2d0ac705fb1896553ae43bbd572a99ab270b1e /quantum | |
| parent | 38353688f2cf2d077a0e16b9a3f2b054fffc74c0 (diff) | |
| download | qmk_firmware-e9c44e396d21df990b1d08e8b4c30e288797dffe.tar.gz qmk_firmware-e9c44e396d21df990b1d08e8b4c30e288797dffe.zip | |
Smallish overhaul of Auto-Shift feature (#6067)
* Fix edge case when using One Shot Layer with Auto Shift, and it not triggering the cleanup
* Remove junk code (no longer used)
* Replace `(un)register_code` calls with `tap_code` where appropriate
* Fixed up Switch check to be more readable (less verbose)
* Simplified modifier check (if it comes back non-zero, there are mods)
* Add additional function calls for autoshift settings
* Made all variables static, since there are function calls to get their status
* Fixed up documentation
* Re-add special characters that were missed
* formatting pass
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/process_keycode/process_auto_shift.c | 114 | ||||
| -rw-r--r-- | quantum/process_keycode/process_auto_shift.h | 15 |
2 files changed, 34 insertions, 95 deletions
diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 4ae3fe446..b474bda69 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c | |||
| @@ -20,19 +20,10 @@ | |||
| 20 | 20 | ||
| 21 | # include "process_auto_shift.h" | 21 | # include "process_auto_shift.h" |
| 22 | 22 | ||
| 23 | # define TAP(key) \ | 23 | static bool autoshift_enabled = true; |
| 24 | register_code(key); \ | 24 | static uint16_t autoshift_time = 0; |
| 25 | unregister_code(key) | 25 | static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; |
| 26 | 26 | static uint16_t autoshift_lastkey = KC_NO; | |
| 27 | # define TAP_WITH_MOD(mod, key) \ | ||
| 28 | register_code(mod); \ | ||
| 29 | register_code(key); \ | ||
| 30 | unregister_code(key); \ | ||
| 31 | unregister_code(mod) | ||
| 32 | |||
| 33 | uint16_t autoshift_time = 0; | ||
| 34 | uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT; | ||
| 35 | uint16_t autoshift_lastkey = KC_NO; | ||
| 36 | 27 | ||
| 37 | void autoshift_timer_report(void) { | 28 | void autoshift_timer_report(void) { |
| 38 | char display[8]; | 29 | char display[8]; |
| @@ -52,14 +43,9 @@ void autoshift_flush(void) { | |||
| 52 | uint16_t elapsed = timer_elapsed(autoshift_time); | 43 | uint16_t elapsed = timer_elapsed(autoshift_time); |
| 53 | 44 | ||
| 54 | if (elapsed > autoshift_timeout) { | 45 | if (elapsed > autoshift_timeout) { |
| 55 | register_code(KC_LSFT); | 46 | tap_code16(LSFT(autoshift_lastkey)); |
| 56 | } | 47 | } else { |
| 57 | 48 | tap_code(autoshift_lastkey); | |
| 58 | register_code(autoshift_lastkey); | ||
| 59 | unregister_code(autoshift_lastkey); | ||
| 60 | |||
| 61 | if (elapsed > autoshift_timeout) { | ||
| 62 | unregister_code(KC_LSFT); | ||
| 63 | } | 49 | } |
| 64 | 50 | ||
| 65 | autoshift_time = 0; | 51 | autoshift_time = 0; |
| @@ -67,8 +53,6 @@ void autoshift_flush(void) { | |||
| 67 | } | 53 | } |
| 68 | } | 54 | } |
| 69 | 55 | ||
| 70 | bool autoshift_enabled = true; | ||
| 71 | |||
| 72 | void autoshift_enable(void) { autoshift_enabled = true; } | 56 | void autoshift_enable(void) { autoshift_enabled = true; } |
| 73 | void autoshift_disable(void) { | 57 | void autoshift_disable(void) { |
| 74 | autoshift_enabled = false; | 58 | autoshift_enabled = false; |
| @@ -84,106 +68,62 @@ void autoshift_toggle(void) { | |||
| 84 | } | 68 | } |
| 85 | } | 69 | } |
| 86 | 70 | ||
| 87 | bool autoshift_state(void) { return autoshift_enabled; } | 71 | bool get_autoshift_state(void) { return autoshift_enabled; } |
| 88 | 72 | ||
| 89 | bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { | 73 | uint16_t get_autoshift_timeout(void) { return autoshift_timeout; } |
| 90 | # ifndef AUTO_SHIFT_MODIFIERS | ||
| 91 | static uint8_t any_mod_pressed; | ||
| 92 | # endif | ||
| 93 | 74 | ||
| 75 | void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; } | ||
| 76 | |||
| 77 | bool process_auto_shift(uint16_t keycode, keyrecord_t *record) { | ||
| 94 | if (record->event.pressed) { | 78 | if (record->event.pressed) { |
| 95 | switch (keycode) { | 79 | switch (keycode) { |
| 96 | case KC_ASUP: | 80 | case KC_ASUP: |
| 97 | autoshift_timeout += 5; | 81 | autoshift_timeout += 5; |
| 98 | return false; | 82 | return true; |
| 99 | 83 | ||
| 100 | case KC_ASDN: | 84 | case KC_ASDN: |
| 101 | autoshift_timeout -= 5; | 85 | autoshift_timeout -= 5; |
| 102 | return false; | 86 | return true; |
| 103 | 87 | ||
| 104 | case KC_ASRP: | 88 | case KC_ASRP: |
| 105 | autoshift_timer_report(); | 89 | autoshift_timer_report(); |
| 106 | return false; | 90 | return true; |
| 107 | 91 | ||
| 108 | case KC_ASTG: | 92 | case KC_ASTG: |
| 109 | autoshift_toggle(); | 93 | autoshift_toggle(); |
| 110 | return false; | 94 | return true; |
| 111 | case KC_ASON: | 95 | case KC_ASON: |
| 112 | autoshift_enable(); | 96 | autoshift_enable(); |
| 113 | return false; | 97 | return true; |
| 114 | case KC_ASOFF: | 98 | case KC_ASOFF: |
| 115 | autoshift_disable(); | 99 | autoshift_disable(); |
| 116 | return false; | 100 | return true; |
| 117 | 101 | ||
| 118 | # ifndef NO_AUTO_SHIFT_ALPHA | 102 | # ifndef NO_AUTO_SHIFT_ALPHA |
| 119 | case KC_A: | 103 | case KC_A ... KC_Z: |
| 120 | case KC_B: | ||
| 121 | case KC_C: | ||
| 122 | case KC_D: | ||
| 123 | case KC_E: | ||
| 124 | case KC_F: | ||
| 125 | case KC_G: | ||
| 126 | case KC_H: | ||
| 127 | case KC_I: | ||
| 128 | case KC_J: | ||
| 129 | case KC_K: | ||
| 130 | case KC_L: | ||
| 131 | case KC_M: | ||
| 132 | case KC_N: | ||
| 133 | case KC_O: | ||
| 134 | case KC_P: | ||
| 135 | case KC_Q: | ||
| 136 | case KC_R: | ||
| 137 | case KC_S: | ||
| 138 | case KC_T: | ||
| 139 | case KC_U: | ||
| 140 | case KC_V: | ||
| 141 | case KC_W: | ||
| 142 | case KC_X: | ||
| 143 | case KC_Y: | ||
| 144 | case KC_Z: | ||
| 145 | # endif | 104 | # endif |
| 146 | # ifndef NO_AUTO_SHIFT_NUMERIC | 105 | # ifndef NO_AUTO_SHIFT_NUMERIC |
| 147 | case KC_1: | 106 | case KC_1 ... KC_0: |
| 148 | case KC_2: | ||
| 149 | case KC_3: | ||
| 150 | case KC_4: | ||
| 151 | case KC_5: | ||
| 152 | case KC_6: | ||
| 153 | case KC_7: | ||
| 154 | case KC_8: | ||
| 155 | case KC_9: | ||
| 156 | case KC_0: | ||
| 157 | # endif | 107 | # endif |
| 158 | # ifndef NO_AUTO_SHIFT_SPECIAL | 108 | # ifndef NO_AUTO_SHIFT_SPECIAL |
| 159 | case KC_MINUS: | ||
| 160 | case KC_EQL: | ||
| 161 | case KC_TAB: | 109 | case KC_TAB: |
| 162 | case KC_LBRC: | 110 | case KC_MINUS ... KC_SLASH: |
| 163 | case KC_RBRC: | ||
| 164 | case KC_BSLS: | ||
| 165 | case KC_SCLN: | ||
| 166 | case KC_QUOT: | ||
| 167 | case KC_COMM: | ||
| 168 | case KC_DOT: | ||
| 169 | case KC_SLSH: | ||
| 170 | case KC_GRAVE: | ||
| 171 | case KC_NONUS_BSLASH: | 111 | case KC_NONUS_BSLASH: |
| 172 | case KC_NONUS_HASH: | ||
| 173 | # endif | 112 | # endif |
| 174 | |||
| 175 | autoshift_flush(); | 113 | autoshift_flush(); |
| 176 | if (!autoshift_enabled) return true; | 114 | if (!autoshift_enabled) return true; |
| 177 | 115 | ||
| 178 | # ifndef AUTO_SHIFT_MODIFIERS | 116 | # ifndef AUTO_SHIFT_MODIFIERS |
| 179 | any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)); | 117 | if (get_mods()) { |
| 180 | |||
| 181 | if (any_mod_pressed) { | ||
| 182 | return true; | 118 | return true; |
| 183 | } | 119 | } |
| 184 | # endif | 120 | # endif |
| 185 | |||
| 186 | autoshift_on(keycode); | 121 | autoshift_on(keycode); |
| 122 | |||
| 123 | // We need some extra handling here for OSL edge cases | ||
| 124 | # if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) | ||
| 125 | clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); | ||
| 126 | # endif | ||
| 187 | return false; | 127 | return false; |
| 188 | 128 | ||
| 189 | default: | 129 | default: |
diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index 083325d8e..e86c4658e 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h | |||
| @@ -14,8 +14,7 @@ | |||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #ifndef PROCESS_AUTO_SHIFT_H | 17 | #pragma once |
| 18 | #define PROCESS_AUTO_SHIFT_H | ||
| 19 | 18 | ||
| 20 | #include "quantum.h" | 19 | #include "quantum.h" |
| 21 | 20 | ||
| @@ -25,9 +24,9 @@ | |||
| 25 | 24 | ||
| 26 | bool process_auto_shift(uint16_t keycode, keyrecord_t *record); | 25 | bool process_auto_shift(uint16_t keycode, keyrecord_t *record); |
| 27 | 26 | ||
| 28 | void autoshift_enable(void); | 27 | void autoshift_enable(void); |
| 29 | void autoshift_disable(void); | 28 | void autoshift_disable(void); |
| 30 | void autoshift_toggle(void); | 29 | void autoshift_toggle(void); |
| 31 | bool autoshift_state(void); | 30 | bool get_autoshift_state(void); |
| 32 | 31 | uint16_t get_autoshift_timeout(void); | |
| 33 | #endif | 32 | void set_autoshift_timeout(uint16_t timeout); |
