diff options
| author | tmk <nobody@nowhere> | 2013-03-21 14:42:40 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-21 14:42:40 +0900 |
| commit | d44290b91b96f89cfc2dfa85a59cc267ffd13fb4 (patch) | |
| tree | 0acf399005d0d5fba6511dd9ca16a65f0bb46037 /common/action.c | |
| parent | 9a3edb897ab8549bae089645c0d7f27df8fa15b7 (diff) | |
| download | qmk_firmware-d44290b91b96f89cfc2dfa85a59cc267ffd13fb4.tar.gz qmk_firmware-d44290b91b96f89cfc2dfa85a59cc267ffd13fb4.zip | |
Add NO_ACTION_ONESHOT config option
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/common/action.c b/common/action.c index 3d81318a9..49bfc54e7 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 25 | #include "debug.h" | 25 | #include "debug.h" |
| 26 | #include "led.h" | 26 | #include "led.h" |
| 27 | #include "layer_switch.h" | 27 | #include "layer_switch.h" |
| 28 | #include "action_oneshot.h" | ||
| 28 | #include "action_macro.h" | 29 | #include "action_macro.h" |
| 29 | #include "action.h" | 30 | #include "action.h" |
| 30 | 31 | ||
| @@ -125,44 +126,6 @@ bool waiting_buffer_has_anykey_pressed(void) | |||
| 125 | } | 126 | } |
| 126 | return false; | 127 | return false; |
| 127 | } | 128 | } |
| 128 | |||
| 129 | |||
| 130 | /* Oneshot modifier | ||
| 131 | * | ||
| 132 | * Problem: Want to capitalize like 'The' but the result tends to be 'THe'. | ||
| 133 | * Solution: Oneshot modifier have its effect on only one key coming next. | ||
| 134 | * Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key. | ||
| 135 | * | ||
| 136 | * Hold: works as normal modifier. | ||
| 137 | * Tap: one shot modifier. | ||
| 138 | * 2 Tap: cancel one shot modifier. | ||
| 139 | * 5-Tap: toggles enable/disable oneshot feature. | ||
| 140 | */ | ||
| 141 | static struct { | ||
| 142 | uint8_t mods; | ||
| 143 | uint8_t time; | ||
| 144 | bool ready; | ||
| 145 | bool disabled; | ||
| 146 | } oneshot_state; | ||
| 147 | |||
| 148 | static void oneshot_start(uint8_t mods, uint16_t time) | ||
| 149 | { | ||
| 150 | oneshot_state.mods = mods; | ||
| 151 | oneshot_state.time = time; | ||
| 152 | oneshot_state.ready = true; | ||
| 153 | } | ||
| 154 | |||
| 155 | static void oneshot_cancel(void) | ||
| 156 | { | ||
| 157 | oneshot_state.mods = 0; | ||
| 158 | oneshot_state.time = 0; | ||
| 159 | oneshot_state.ready = false; | ||
| 160 | } | ||
| 161 | |||
| 162 | static void oneshot_toggle(void) | ||
| 163 | { | ||
| 164 | oneshot_state.disabled = !oneshot_state.disabled; | ||
| 165 | } | ||
| 166 | #endif | 129 | #endif |
| 167 | 130 | ||
| 168 | 131 | ||
| @@ -263,6 +226,7 @@ static void process_action(keyrecord_t *record) | |||
| 263 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : | 226 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : |
| 264 | action.key.mods<<4; | 227 | action.key.mods<<4; |
| 265 | switch (action.layer.code) { | 228 | switch (action.layer.code) { |
| 229 | #ifndef NO_ACTION_ONESHOT | ||
| 266 | case 0x00: | 230 | case 0x00: |
| 267 | // Oneshot modifier | 231 | // Oneshot modifier |
| 268 | if (event.pressed) { | 232 | if (event.pressed) { |
| @@ -272,7 +236,7 @@ static void process_action(keyrecord_t *record) | |||
| 272 | } | 236 | } |
| 273 | else if (tap_count == 1) { | 237 | else if (tap_count == 1) { |
| 274 | debug("MODS_TAP: Oneshot: start\n"); | 238 | debug("MODS_TAP: Oneshot: start\n"); |
| 275 | oneshot_start(mods, event.time); | 239 | oneshot_start(mods); |
| 276 | } | 240 | } |
| 277 | else if (tap_count == TAPPING_TOGGLE) { | 241 | else if (tap_count == TAPPING_TOGGLE) { |
| 278 | debug("MODS_TAP: Oneshot: toggle\n"); | 242 | debug("MODS_TAP: Oneshot: toggle\n"); |
| @@ -303,6 +267,7 @@ static void process_action(keyrecord_t *record) | |||
| 303 | } | 267 | } |
| 304 | } | 268 | } |
| 305 | break; | 269 | break; |
| 270 | #endif | ||
| 306 | default: | 271 | default: |
| 307 | if (event.pressed) { | 272 | if (event.pressed) { |
| 308 | if (tap_count > 0) { | 273 | if (tap_count > 0) { |
| @@ -930,15 +895,16 @@ void register_code(uint8_t code) | |||
| 930 | // TODO: should push command_proc out of this block? | 895 | // TODO: should push command_proc out of this block? |
| 931 | if (command_proc(code)) return; | 896 | if (command_proc(code)) return; |
| 932 | 897 | ||
| 933 | #ifndef NO_ACTION_TAPPING | 898 | #ifndef NO_ACTION_ONESHOT |
| 934 | if (oneshot_state.mods && oneshot_state.ready && !oneshot_state.disabled) { | 899 | if (oneshot_state.mods && !oneshot_state.disabled) { |
| 935 | uint8_t tmp_mods = host_get_mods(); | 900 | uint8_t tmp_mods = host_get_mods(); |
| 936 | host_add_mods(oneshot_state.mods); | 901 | host_add_mods(oneshot_state.mods); |
| 902 | |||
| 937 | host_add_key(code); | 903 | host_add_key(code); |
| 938 | host_send_keyboard_report(); | 904 | host_send_keyboard_report(); |
| 939 | 905 | ||
| 940 | host_set_mods(tmp_mods); | 906 | host_set_mods(tmp_mods); |
| 941 | oneshot_state.ready = false; | 907 | oneshot_cancel(); |
| 942 | } else | 908 | } else |
| 943 | #endif | 909 | #endif |
| 944 | { | 910 | { |
