diff options
| -rw-r--r-- | common.mk | 1 | ||||
| -rw-r--r-- | common/action.c | 50 | ||||
| -rw-r--r-- | common/action_oneshot.c | 21 | ||||
| -rw-r--r-- | common/action_oneshot.h | 52 |
4 files changed, 82 insertions, 42 deletions
| @@ -2,6 +2,7 @@ COMMON_DIR = common | |||
| 2 | SRC += $(COMMON_DIR)/host.c \ | 2 | SRC += $(COMMON_DIR)/host.c \ |
| 3 | $(COMMON_DIR)/keyboard.c \ | 3 | $(COMMON_DIR)/keyboard.c \ |
| 4 | $(COMMON_DIR)/action.c \ | 4 | $(COMMON_DIR)/action.c \ |
| 5 | $(COMMON_DIR)/action_oneshot.c \ | ||
| 5 | $(COMMON_DIR)/action_macro.c \ | 6 | $(COMMON_DIR)/action_macro.c \ |
| 6 | $(COMMON_DIR)/layer_switch.c \ | 7 | $(COMMON_DIR)/layer_switch.c \ |
| 7 | $(COMMON_DIR)/keymap.c \ | 8 | $(COMMON_DIR)/keymap.c \ |
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 | { |
diff --git a/common/action_oneshot.c b/common/action_oneshot.c new file mode 100644 index 000000000..d34f44b5a --- /dev/null +++ b/common/action_oneshot.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "action_oneshot.h" | ||
| 2 | |||
| 3 | |||
| 4 | #ifndef NO_ACTION_ONESHOT | ||
| 5 | oneshot_state_t oneshot_state; | ||
| 6 | |||
| 7 | void oneshot_start(uint8_t mods) | ||
| 8 | { | ||
| 9 | oneshot_state.mods = mods; | ||
| 10 | } | ||
| 11 | |||
| 12 | void oneshot_cancel(void) | ||
| 13 | { | ||
| 14 | oneshot_state.mods = 0; | ||
| 15 | } | ||
| 16 | |||
| 17 | void oneshot_toggle(void) | ||
| 18 | { | ||
| 19 | oneshot_state.disabled = !oneshot_state.disabled; | ||
| 20 | } | ||
| 21 | #endif | ||
diff --git a/common/action_oneshot.h b/common/action_oneshot.h new file mode 100644 index 000000000..36ef9e9bc --- /dev/null +++ b/common/action_oneshot.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #ifndef ACTION_ONESHOT_H | ||
| 18 | #define ACTION_ONESHOT_H | ||
| 19 | |||
| 20 | #include <stdint.h> | ||
| 21 | #include <stdbool.h> | ||
| 22 | |||
| 23 | #ifdef NO_ACTION_TAPPING | ||
| 24 | #define NO_ACTION_ONESHOT | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifndef NO_ACTION_ONESHOT | ||
| 28 | /* Oneshot modifier | ||
| 29 | * | ||
| 30 | * Problem: Want to capitalize like 'The' but the result tends to be 'THe'. | ||
| 31 | * Solution: Oneshot modifier have its effect on only one key coming next. | ||
| 32 | * Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key. | ||
| 33 | * | ||
| 34 | * Hold: works as normal modifier. | ||
| 35 | * Tap: one shot modifier. | ||
| 36 | * 2 Tap: cancel one shot modifier. | ||
| 37 | * 5-Tap: toggles enable/disable oneshot feature. | ||
| 38 | */ | ||
| 39 | typedef struct { | ||
| 40 | uint8_t mods; | ||
| 41 | bool disabled; | ||
| 42 | } oneshot_state_t; | ||
| 43 | |||
| 44 | |||
| 45 | oneshot_state_t oneshot_state; | ||
| 46 | |||
| 47 | void oneshot_start(uint8_t mods); | ||
| 48 | void oneshot_cancel(void); | ||
| 49 | void oneshot_toggle(void); | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
