Add `OneShot_MetaStickyKey`

This is a special OneShot key that makes any subsequently-pressed key sticky,
regardless of its value.

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

@ -45,7 +45,9 @@ EventHandlerResult ActiveModColorEffect::onKeyswitchEvent(
// it will get highlighted. Conditionally (if
// `highlight_normal_modifiers_` is set), we also highlight
// modifier and layer-shift keys.
if (::OneShot.isModifier() || ::OneShot.isLayerShift()) {
if (::OneShot.isModifier(key) ||
::OneShot.isLayerShift(key) ||
::OneShot.isActive(key_addr)) {
mod_key_bits_.set(key_addr);
}
} else if (keyToggledOff(key_state)) {

@ -44,6 +44,8 @@ uint16_t OneShot::stickable_keys_ = -1;
bool OneShot::auto_modifiers_ = false;
bool OneShot::auto_layers_ = false;
KeyAddr OneShot::meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
KeyAddrBitfield OneShot::temp_addrs_;
KeyAddrBitfield OneShot::glue_addrs_;
@ -140,6 +142,8 @@ bool OneShot::isStickable(Key key) {
if (n < oneshot_key_count) {
return bitRead(stickable_keys_, n);
}
} else if (key == OneShot_MetaStickyKey) {
return true;
}
return false;
}
@ -202,13 +206,40 @@ EventHandlerResult OneShot::onKeyswitchEvent(
if (!temp && !glue) {
// This key_addr is not in a OneShot state.
if (isOneShotKey(key) ||
if (meta_sticky_key_addr_.isValid()) {
// 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) {
// ms key is temp one-shot
releaseKey(meta_sticky_key_addr_);
meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
} else {
// ms key is held
temp_addrs_.clear(meta_sticky_key_addr_);
}
} else {
// ms key is sticky
}
glue_addrs_.set(key_addr);
//prev_key_addr_ = key_addr;
start_time_ = Runtime.millisAtCycleStart();
//return EventHandlerResult::OK;
} else if (key == OneShot_MetaStickyKey) {
meta_sticky_key_addr_ = key_addr;
temp_addrs_.set(key_addr);
start_time_ = Runtime.millisAtCycleStart();
} else if (isOneShotKey(key) ||
(auto_modifiers_ && isModifier(key)) ||
(auto_layers_ && isLayerShift(key))) {
// Replace the OneShot key with its corresponding normal key.
pressKey(key_addr, key);
return EventHandlerResult::ABORT;
} else if (!isModifier(key) && !isLayerShift(key)) {
// Only trigger release of temporary OneShot keys if the
// pressed key is neither a modifier nor a layer shift.
release_countdown_ = (1 << 1);
@ -246,6 +277,9 @@ EventHandlerResult OneShot::onKeyswitchEvent(
// This is a sticky OneShot key that has been pressed. Clear
// state now, so it will become a normal key.
glue_addrs_.clear(key_addr);
// Then replace the key toggled on event with a key held event.
holdKey(key_addr);
return EventHandlerResult::EVENT_CONSUMED;
} else { // (temp && !glue)
// A key has been pressed that is in the "pending" OneShot
@ -273,6 +307,9 @@ EventHandlerResult OneShot::onKeyswitchEvent(
// `beforeReportingState()` hook below.
//Layer.updateLiveCompositeKeymap(key_addr, key);
return EventHandlerResult::ABORT;
} else if (key == OneShot_MetaStickyKey) {
meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
//cancel(true);
}
} else {
@ -404,6 +441,10 @@ void OneShot::holdKey(KeyAddr key_addr) {
void OneShot::releaseKey(KeyAddr key_addr) {
glue_addrs_.clear(key_addr);
temp_addrs_.clear(key_addr);
if (live_keys[key_addr] == OneShot_MetaStickyKey)
meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
handleKeyswitchEvent(Key_NoKey, key_addr, WAS_PRESSED | INJECTED);
}

@ -60,6 +60,10 @@
#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};
namespace kaleidoscope {
namespace plugin {
@ -234,6 +238,7 @@ class OneShot : public kaleidoscope::Plugin {
static uint16_t stickable_keys_;
static bool auto_modifiers_;
static bool auto_layers_;
static KeyAddr meta_sticky_key_addr_;
static KeyAddrBitfield temp_addrs_;
static KeyAddrBitfield glue_addrs_;

@ -56,7 +56,6 @@ enum : uint16_t {
OSL_FIRST,
OSL_LAST = OSL_FIRST + 7,
OS_LAST = OSL_LAST,
OS_CANCEL,
DU_FIRST,
DUM_FIRST = DU_FIRST,
DUM_LAST = DUM_FIRST + (8 << 8),
@ -79,6 +78,8 @@ enum : uint16_t {
TURBO,
DYNAMIC_MACRO_FIRST,
DYNAMIC_MACRO_LAST = DYNAMIC_MACRO_FIRST + 31,
OS_META_STICKY,
OS_CANCEL,
SAFE_START,
KALEIDOSCOPE_SAFE_START = SAFE_START

Loading…
Cancel
Save