Remove OneShot meta key handling from the OneShot plugin

The handling of these keys has been shifted to a separate OneShotMetaKeys
plugin.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1062/head
Michael Richters 4 years ago
parent d0b6f5a21b
commit 727d0ba23e
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -28,7 +28,7 @@ enum {
KEYMAPS(
[0] = KEYMAP_STACKED
(
M(TOGGLE_ONESHOT), Key_1, Key_2, Key_3, Key_4, Key_5, OneShot_MetaStickyKey,
M(TOGGLE_ONESHOT), Key_1, Key_2, Key_3, Key_4, Key_5, ___,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
@ -36,7 +36,7 @@ KEYMAPS(
OSM(LeftControl), Key_Backspace, OSM(LeftGui), OSM(LeftShift),
Key_Meh,
OneShot_ActiveStickyKey, Key_6, Key_7, Key_8, Key_9, Key_0, ___,
___, Key_6, Key_7, Key_8, Key_9, Key_0, ___,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
___, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,

@ -46,25 +46,6 @@ will have a yellow LED highlight; when sticky, a red highlight. When it is in a
"held" state, but will be deactivated when released like any non-one-shot key,
it will have a white highlight. (These colors are configurable.)
## Special OneShot keys
OneShot also comes with two special keys that can make any key on your keyboard
sticky: `OneShot_MetaStickyKey` & `OneShot_ActiveStickyKey`. These are both
`Key` values that can be used as entries in your sketch's keymap.
### `OneShot_MetaStickyKey`
This special OneShot key behaves like other OneShot keys, but its affect is to
make the next key pressed sticky. Tap `OneShot_MetaStickyKey`, then tap `X`, and
`X` will become sticky. Tap `X` again to deactivate it.
### `OneShot_ActiveStickyKey`
This special key doesn't act like a OneShot key, but instead makes any key(s)
currently held (or otherwise active) sticky. Press (and hold) `X`, tap
`OneShot_ActiveStickyKey`, then release `X`, and `X` will stay active until it
is tapped again to deactivate it.
## Using the plugin
After adding one-shot keys to the keymap, all one needs to do, is enable the

@ -52,10 +52,6 @@ KeyAddrBitfield OneShot::glue_addrs_;
uint16_t OneShot::start_time_ = 0;
KeyAddr OneShot::prev_key_addr_ = OneShot::invalid_key_addr;
#ifndef ONESHOT_WITHOUT_METASTICKY
KeyAddr OneShot::meta_sticky_key_addr_ {KeyAddr::invalid_state};
#endif
// ============================================================================
// Public interface
@ -133,10 +129,6 @@ bool OneShot::isStickableDefault(Key key) {
if (n < oneshot_key_count) {
return bitRead(stickable_keys_, n);
}
#ifndef ONESHOT_WITHOUT_METASTICKY
} else if (key == OneShot_MetaStickyKey) {
return true;
#endif
}
return true;
}
@ -224,27 +216,6 @@ EventHandlerResult OneShot::onKeyEvent(KeyEvent& event) {
if (keyToggledOn(event.state)) {
// Make all held keys sticky if `OneShot_ActiveStickyKey` toggles on.
if (event.key == OneShot_ActiveStickyKey) {
// Skip the stickify key itself
for (KeyAddr entry_addr : KeyAddr::all()) {
if (entry_addr == event.addr) {
continue;
}
// Get the entry from the keyboard state array
Key entry_key = live_keys[entry_addr];
// Skip empty entries
if (entry_key == Key_Transparent || entry_key == Key_NoKey) {
continue;
}
// Make everything else sticky
temp_addrs_.clear(entry_addr);
glue_addrs_.set(entry_addr);
}
prev_key_addr_ = event.addr;
return EventHandlerResult::OK;
}
if (!temp && !glue) {
// The key is in the "normal" state. The first thing we need to do is
// convert OneShot keys to their equivalent values, and record the fact
@ -256,34 +227,6 @@ EventHandlerResult OneShot::onKeyEvent(KeyEvent& event) {
is_oneshot = true;
}
#ifndef ONESHOT_WITHOUT_METASTICKY
bool is_meta_sticky_key_active = meta_sticky_key_addr_.isValid();
if (is_meta_sticky_key_active) {
// If the meta key isn't sticky, release it
bool ms_temp = temp_addrs_.read(meta_sticky_key_addr_);
bool ms_glue = glue_addrs_.read(meta_sticky_key_addr_);
if (ms_temp) {
if (ms_glue) {
// The meta key is in the "one-shot" state; release it immediately.
releaseKey(meta_sticky_key_addr_);
} else {
// The meta key is in the "pending" state; cancel that, and let it
// deactivate on release.
temp_addrs_.clear(meta_sticky_key_addr_);
}
}
glue_addrs_.set(event.addr);
} else if (event.key == OneShot_MetaStickyKey) {
meta_sticky_key_addr_ = event.addr;
temp_addrs_.set(event.addr);
}
if (is_meta_sticky_key_active || (event.key == OneShot_MetaStickyKey)) {
prev_key_addr_ = event.addr;
start_time_ = Runtime.millisAtCycleStart();
return EventHandlerResult::OK;
}
#endif
if (is_oneshot ||
(auto_modifiers_ && event.key.isKeyboardModifier()) ||
(auto_layers_ && event.key.isLayerShift())) {
@ -343,11 +286,6 @@ EventHandlerResult OneShot::onKeyEvent(KeyEvent& event) {
// stop that event from sending a report, and instead send a "hold"
// event. This is handled in the `beforeReportingState()` hook below.
return EventHandlerResult::ABORT;
#ifndef ONESHOT_WITHOUT_METASTICKY
} else if (event.key == OneShot_MetaStickyKey) {
// Turn off the meta key if it's released in its "normal" state.
meta_sticky_key_addr_ = KeyAddr::none();
#endif
}
}
@ -468,11 +406,6 @@ void OneShot::releaseKey(KeyAddr key_addr) {
glue_addrs_.clear(key_addr);
temp_addrs_.clear(key_addr);
#ifndef ONESHOT_WITHOUT_METASTICKY
if (live_keys[key_addr] == OneShot_MetaStickyKey)
meta_sticky_key_addr_ = KeyAddr::none();
#endif
KeyEvent event{key_addr, WAS_PRESSED | INJECTED};
Runtime.handleKeyEvent(event);
}

@ -68,11 +68,6 @@
#define OSM(kc) Key(kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).getKeyCode() - Key_LeftControl.getKeyCode())
#define OSL(n) Key(kaleidoscope::ranges::OSL_FIRST + n)
// ----------------------------------------------------------------------------
// Key constants
constexpr Key OneShot_MetaStickyKey {kaleidoscope::ranges::OS_META_STICKY};
constexpr Key OneShot_ActiveStickyKey {kaleidoscope::ranges::OS_ACTIVE_STICKY};
namespace kaleidoscope {
namespace plugin {
@ -299,10 +294,6 @@ class OneShot : public kaleidoscope::Plugin {
static uint16_t start_time_;
static KeyAddr prev_key_addr_;
#ifndef ONESHOT_WITHOUT_METASTICKY
static KeyAddr meta_sticky_key_addr_;
#endif
// --------------------------------------------------------------------------
// Internal utility functions
static bool hasTimedOut(uint16_t ttl) {

Loading…
Cancel
Save