aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/keycodes.md3
-rw-r--r--docs/one_shot_keys.md3
-rw-r--r--quantum/keycode_config.h1
-rw-r--r--quantum/quantum.c11
-rw-r--r--quantum/quantum_keycodes.h9
-rw-r--r--tmk_core/common/action_util.c58
-rw-r--r--tmk_core/common/action_util.h5
7 files changed, 81 insertions, 9 deletions
diff --git a/docs/keycodes.md b/docs/keycodes.md
index 9acf8b683..f3c519b13 100644
--- a/docs/keycodes.md
+++ b/docs/keycodes.md
@@ -516,6 +516,9 @@ See also: [One Shot Keys](one_shot_keys.md)
516|------------|----------------------------------| 516|------------|----------------------------------|
517|`OSM(mod)` |Hold `mod` for one keypress | 517|`OSM(mod)` |Hold `mod` for one keypress |
518|`OSL(layer)`|Switch to `layer` for one keypress| 518|`OSL(layer)`|Switch to `layer` for one keypress|
519|`OS_ON` |Turns One Shot keys on |
520|`OS_OFF` |Turns One Shot keys off |
521|`OS_TOGG` |Toggles One Shot keys status |
519 522
520## Space Cadet :id=space-cadet 523## Space Cadet :id=space-cadet
521 524
diff --git a/docs/one_shot_keys.md b/docs/one_shot_keys.md
index 9a082d7d6..9fc548629 100644
--- a/docs/one_shot_keys.md
+++ b/docs/one_shot_keys.md
@@ -17,6 +17,9 @@ You can control the behavior of one shot keys by defining these in `config.h`:
17 17
18* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](mod_tap.md), not the `KC_*` codes. 18* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](mod_tap.md), not the `KC_*` codes.
19* `OSL(layer)` - momentary switch to *layer*. 19* `OSL(layer)` - momentary switch to *layer*.
20* `OS_ON` - Turns on One Shot keys.
21* `OS_OFF` - Turns off One Shot keys. OSM act as regular mod keys, OSL act like `MO`.
22* `ON_TOGG` - Toggles the one shot key status.
20 23
21Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine. 24Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine.
22 25
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index f878168c5..d7e334fdc 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -37,6 +37,7 @@ typedef union {
37 bool nkro : 1; 37 bool nkro : 1;
38 bool swap_lctl_lgui : 1; 38 bool swap_lctl_lgui : 1;
39 bool swap_rctl_rgui : 1; 39 bool swap_rctl_rgui : 1;
40 bool oneshot_disable : 1;
40 }; 41 };
41} keymap_config_t; 42} keymap_config_t;
42 43
diff --git a/quantum/quantum.c b/quantum/quantum.c
index ef751a233..78601ce6b 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -319,6 +319,17 @@ bool process_record_quantum(keyrecord_t *record) {
319 set_output(OUTPUT_BLUETOOTH); 319 set_output(OUTPUT_BLUETOOTH);
320 return false; 320 return false;
321#endif 321#endif
322#ifndef NO_ACTION_ONESHOT
323 case ONESHOT_TOGGLE:
324 oneshot_toggle();
325 break;
326 case ONESHOT_ENABLE:
327 oneshot_enable();
328 break;
329 case ONESHOT_DISABLE:
330 oneshot_disable();
331 break;
332#endif
322 } 333 }
323 } 334 }
324 335
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index e0f5dbc61..63945a17c 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -578,6 +578,10 @@ enum quantum_keycodes {
578 578
579#endif 579#endif
580 580
581 ONESHOT_ENABLE,
582 ONESHOT_DISABLE,
583 ONESHOT_TOGGLE,
584
581 // always leave at the end 585 // always leave at the end
582 SAFE_RANGE 586 SAFE_RANGE
583}; 587};
@@ -885,3 +889,8 @@ enum quantum_keycodes {
885#define DM_RSTP DYN_REC_STOP 889#define DM_RSTP DYN_REC_STOP
886#define DM_PLY1 DYN_MACRO_PLAY1 890#define DM_PLY1 DYN_MACRO_PLAY1
887#define DM_PLY2 DYN_MACRO_PLAY2 891#define DM_PLY2 DYN_MACRO_PLAY2
892
893// One Shot toggle
894#define OS_TOGG ONESHOT_TOGGLE
895#define OS_ON ONESHOT_ENABLE
896#define OS_OFF ONESHOT_DISABLE
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 000503b08..a57c8bf66 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -147,12 +147,16 @@ void clear_oneshot_swaphands(void) {
147 * FIXME: needs doc 147 * FIXME: needs doc
148 */ 148 */
149void set_oneshot_layer(uint8_t layer, uint8_t state) { 149void set_oneshot_layer(uint8_t layer, uint8_t state) {
150 oneshot_layer_data = layer << 3 | state; 150 if (!keymap_config.oneshot_disable) {
151 layer_on(layer); 151 oneshot_layer_data = layer << 3 | state;
152 layer_on(layer);
152# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 153# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
153 oneshot_layer_time = timer_read(); 154 oneshot_layer_time = timer_read();
154# endif 155# endif
155 oneshot_layer_changed_kb(get_oneshot_layer()); 156 oneshot_layer_changed_kb(get_oneshot_layer());
157 } else {
158 layer_on(layer);
159 }
156} 160}
157/** \brief Reset oneshot layer 161/** \brief Reset oneshot layer
158 * 162 *
@@ -172,7 +176,7 @@ void reset_oneshot_layer(void) {
172void clear_oneshot_layer_state(oneshot_fullfillment_t state) { 176void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
173 uint8_t start_state = oneshot_layer_data; 177 uint8_t start_state = oneshot_layer_data;
174 oneshot_layer_data &= ~state; 178 oneshot_layer_data &= ~state;
175 if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { 179 if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) || keymap_config.oneshot_disable) {
176 layer_off(get_oneshot_layer()); 180 layer_off(get_oneshot_layer());
177 reset_oneshot_layer(); 181 reset_oneshot_layer();
178 } 182 }
@@ -182,6 +186,39 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
182 * FIXME: needs doc 186 * FIXME: needs doc
183 */ 187 */
184bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } 188bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); }
189
190/** \brief set oneshot
191 *
192 * FIXME: needs doc
193 */
194void oneshot_set(bool active) {
195 if (keymap_config.oneshot_disable != active) {
196 keymap_config.oneshot_disable = active;
197 eeconfig_update_keymap(keymap_config.raw);
198 dprintf("Oneshot: active: %d\n", active);
199 }
200}
201
202/** \brief toggle oneshot
203 *
204 * FIXME: needs doc
205 */
206void oneshot_toggle(void) { oneshot_set(!keymap_config.oneshot_disable); }
207
208/** \brief enable oneshot
209 *
210 * FIXME: needs doc
211 */
212void oneshot_enable(void) { oneshot_set(true); }
213
214/** \brief disable oneshot
215 *
216 * FIXME: needs doc
217 */
218void oneshot_disable(void) { oneshot_set(false); }
219
220bool is_oneshot_enabled(void) { return keymap_config.oneshot_disable; }
221
185#endif 222#endif
186 223
187/** \brief Send keyboard report 224/** \brief Send keyboard report
@@ -321,14 +358,17 @@ void del_oneshot_mods(uint8_t mods) {
321 * FIXME: needs doc 358 * FIXME: needs doc
322 */ 359 */
323void set_oneshot_mods(uint8_t mods) { 360void set_oneshot_mods(uint8_t mods) {
324 if (oneshot_mods != mods) { 361 if (!keymap_config.oneshot_disable) {
362 if (oneshot_mods != mods) {
325# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 363# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
326 oneshot_time = timer_read(); 364 oneshot_time = timer_read();
327# endif 365# endif
328 oneshot_mods = mods; 366 oneshot_mods = mods;
329 oneshot_mods_changed_kb(mods); 367 oneshot_mods_changed_kb(mods);
368 }
330 } 369 }
331} 370}
371
332/** \brief clear oneshot mods 372/** \brief clear oneshot mods
333 * 373 *
334 * FIXME: needs doc 374 * FIXME: needs doc
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h
index ff29f79b0..f2b3897ae 100644
--- a/tmk_core/common/action_util.h
+++ b/tmk_core/common/action_util.h
@@ -85,6 +85,11 @@ void oneshot_mods_changed_kb(uint8_t mods);
85void oneshot_layer_changed_user(uint8_t layer); 85void oneshot_layer_changed_user(uint8_t layer);
86void oneshot_layer_changed_kb(uint8_t layer); 86void oneshot_layer_changed_kb(uint8_t layer);
87 87
88void oneshot_toggle(void);
89void oneshot_enable(void);
90void oneshot_disable(void);
91bool is_oneshot_enabled(void);
92
88/* inspect */ 93/* inspect */
89uint8_t has_anymod(void); 94uint8_t has_anymod(void);
90 95