summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-03-01 08:57:02 -0800
committerGitHub <noreply@github.com>2021-03-01 08:57:02 -0800
commit0e984b6e7e216a62df0b5d53f6a8f0d4bc13dca3 (patch)
tree1e85b1d15a9ea6ad86fcb6ae8d084f926dd11ab8
parent86f6f682744b81bba1003e555f902af78dcdaad4 (diff)
Add ability to toggle One Shot functionality (#4198)
Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Ryan <fauxpark@gmail.com>
-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 9acf8b6839..f3c519b130 100644
--- a/docs/keycodes.md
+++ b/docs/keycodes.md
@@ -516,6 +516,9 @@ See also: [One Shot Keys](one_shot_keys.md)
|------------|----------------------------------|
|`OSM(mod)` |Hold `mod` for one keypress |
|`OSL(layer)`|Switch to `layer` for one keypress|
+|`OS_ON` |Turns One Shot keys on |
+|`OS_OFF` |Turns One Shot keys off |
+|`OS_TOGG` |Toggles One Shot keys status |
## Space Cadet :id=space-cadet
diff --git a/docs/one_shot_keys.md b/docs/one_shot_keys.md
index 9a082d7d6d..9fc5486299 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`:
* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](mod_tap.md), not the `KC_*` codes.
* `OSL(layer)` - momentary switch to *layer*.
+* `OS_ON` - Turns on One Shot keys.
+* `OS_OFF` - Turns off One Shot keys. OSM act as regular mod keys, OSL act like `MO`.
+* `ON_TOGG` - Toggles the one shot key status.
Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine.
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index f878168c5f..d7e334fdc8 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -37,6 +37,7 @@ typedef union {
bool nkro : 1;
bool swap_lctl_lgui : 1;
bool swap_rctl_rgui : 1;
+ bool oneshot_disable : 1;
};
} keymap_config_t;
diff --git a/quantum/quantum.c b/quantum/quantum.c
index ef751a2331..78601ce6bf 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -319,6 +319,17 @@ bool process_record_quantum(keyrecord_t *record) {
set_output(OUTPUT_BLUETOOTH);
return false;
#endif
+#ifndef NO_ACTION_ONESHOT
+ case ONESHOT_TOGGLE:
+ oneshot_toggle();
+ break;
+ case ONESHOT_ENABLE:
+ oneshot_enable();
+ break;
+ case ONESHOT_DISABLE:
+ oneshot_disable();
+ break;
+#endif
}
}
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index e0f5dbc61e..63945a17ca 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -578,6 +578,10 @@ enum quantum_keycodes {
#endif
+ ONESHOT_ENABLE,
+ ONESHOT_DISABLE,
+ ONESHOT_TOGGLE,
+
// always leave at the end
SAFE_RANGE
};
@@ -885,3 +889,8 @@ enum quantum_keycodes {
#define DM_RSTP DYN_REC_STOP
#define DM_PLY1 DYN_MACRO_PLAY1
#define DM_PLY2 DYN_MACRO_PLAY2
+
+// One Shot toggle
+#define OS_TOGG ONESHOT_TOGGLE
+#define OS_ON ONESHOT_ENABLE
+#define OS_OFF ONESHOT_DISABLE
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 000503b082..a57c8bf66a 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -147,12 +147,16 @@ void clear_oneshot_swaphands(void) {
* FIXME: needs doc
*/
void set_oneshot_layer(uint8_t layer, uint8_t state) {
- oneshot_layer_data = layer << 3 | state;
- layer_on(layer);
+ if (!keymap_config.oneshot_disable) {
+ oneshot_layer_data = layer << 3 | state;
+ layer_on(layer);
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
- oneshot_layer_time = timer_read();
+ oneshot_layer_time = timer_read();
# endif
- oneshot_layer_changed_kb(get_oneshot_layer());
+ oneshot_layer_changed_kb(get_oneshot_layer());
+ } else {
+ layer_on(layer);
+ }
}
/** \brief Reset oneshot layer
*
@@ -172,7 +176,7 @@ void reset_oneshot_layer(void) {
void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
uint8_t start_state = oneshot_layer_data;
oneshot_layer_data &= ~state;
- if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) {
+ if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) || keymap_config.oneshot_disable) {
layer_off(get_oneshot_layer());
reset_oneshot_layer();
}
@@ -182,6 +186,39 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
* FIXME: needs doc
*/
bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); }
+
+/** \brief set oneshot
+ *
+ * FIXME: needs doc
+ */
+void oneshot_set(bool active) {
+ if (keymap_config.oneshot_disable != active) {
+ keymap_config.oneshot_disable = active;
+ eeconfig_update_keymap(keymap_config.raw);
+ dprintf("Oneshot: active: %d\n", active);
+ }
+}
+
+/** \brief toggle oneshot
+ *
+ * FIXME: needs doc
+ */
+void oneshot_toggle(void) { oneshot_set(!keymap_config.oneshot_disable); }
+
+/** \brief enable oneshot
+ *
+ * FIXME: needs doc
+ */
+void oneshot_enable(void) { oneshot_set(true); }
+
+/** \brief disable oneshot
+ *
+ * FIXME: needs doc
+ */
+void oneshot_disable(void) { oneshot_set(false); }
+
+bool is_oneshot_enabled(void) { return keymap_config.oneshot_disable; }
+
#endif
/** \brief Send keyboard report
@@ -321,14 +358,17 @@ void del_oneshot_mods(uint8_t mods) {
* FIXME: needs doc
*/
void set_oneshot_mods(uint8_t mods) {
- if (oneshot_mods != mods) {
+ if (!keymap_config.oneshot_disable) {
+ if (oneshot_mods != mods) {
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
- oneshot_time = timer_read();
+ oneshot_time = timer_read();
# endif
- oneshot_mods = mods;
- oneshot_mods_changed_kb(mods);
+ oneshot_mods = mods;
+ oneshot_mods_changed_kb(mods);
+ }
}
}
+
/** \brief clear oneshot mods
*
* FIXME: needs doc
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h
index ff29f79b09..f2b3897ae5 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);
void oneshot_layer_changed_user(uint8_t layer);
void oneshot_layer_changed_kb(uint8_t layer);
+void oneshot_toggle(void);
+void oneshot_enable(void);
+void oneshot_disable(void);
+bool is_oneshot_enabled(void);
+
/* inspect */
uint8_t has_anymod(void);