Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This causes all one shot that were sticking to be clearer if no keys … #1276

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,27 +287,34 @@ EventHandlerResult OneShot::afterEachCycle() {

bool oneshot_expired = hasTimedOut(settings_.timeout);
bool hold_expired = hasTimedOut(settings_.hold_timeout);
bool sticky_expired = (sticky_time_out_ > 0) && hasTimedOut32(sticky_time_out_);
bool any_temp_keys = false;

for (KeyAddr key_addr : temp_addrs_) {
any_temp_keys = true;

if (glue_addrs_.read(key_addr)) {
// Release keys in "one-shot" state that have timed out or been cancelled
// by another key press.
if (oneshot_expired)
releaseKey(key_addr);
} else {
// Cancel "pending" state of keys held longer than the hold timeout.
if (hold_expired)
temp_addrs_.clear(key_addr);
}
bool any_sticky_keys = false;

if(sticky_expired)
cancel(true);
else {
for (KeyAddr key_addr : temp_addrs_) {
any_temp_keys = true;

if (glue_addrs_.read(key_addr)) {
// Release keys in "one-shot" state that have timed out or been cancelled
// by another key press.
if (oneshot_expired)
releaseKey(key_addr);
} else {
// Cancel "pending" state of keys held longer than the hold timeout.
if (hold_expired)
temp_addrs_.clear(key_addr);
}
}
any_sticky_keys = (glue_addrs_.size > 0);
}

// Keep the start time from getting stale; if there are no keys waiting for a
// timeout, it's safe to advance the timer to the current time.
if (!any_temp_keys) {
start_time_ = Runtime.millisAtCycleStart();
if (!any_temp_keys && !any_sticky_keys) {
start_time_ = Runtime.millisAtCycleStart();
}

return EventHandlerResult::OK;
Expand Down
22 changes: 21 additions & 1 deletion plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,22 @@ class OneShot : public kaleidoscope::Plugin {
void setDoubleTapTimeout(int16_t ttl) {
settings_.double_tap_timeout = ttl;
}

int16_t getDoubleTapTimeout() {
return settings_.double_tap_timeout;
}

void setStickyTimeout(uint32_t ttl) {
settings_.sticky_time_out_ = ttl;
}

void setStickyTimeOutSeconds(uint32_t ttl) {
settings.sticky_time_out_ = ttl * 1000;
}

uint32_t getStickyTimeOut() {
return settings_.sticky_time_out_;
}
// --------------------------------------------------------------------------
// Plugin hook functions

Expand All @@ -216,6 +228,7 @@ class OneShot : public kaleidoscope::Plugin {
uint16_t timeout = 2500;
uint16_t hold_timeout = 250;
int16_t double_tap_timeout = -1;
uint32_t sticky_time_out_ = -1;

uint16_t stickable_keys = -1;
bool auto_modifiers = false;
Expand All @@ -228,21 +241,28 @@ class OneShot : public kaleidoscope::Plugin {
KeyAddrBitfield temp_addrs_;
KeyAddrBitfield glue_addrs_;

uint16_t start_time_ = 0;
uint32_t start_time_ = 0;
KeyAddr prev_key_addr_ = invalid_key_addr;

// --------------------------------------------------------------------------
// Internal utility functions
bool hasTimedOut(uint16_t ttl) const {
return Runtime.hasTimeExpired(start_time_, ttl);
}
bool hasTimedOut32(uint32_t ttl) const {
return Runtime.hasTimeExpired(start_time_, ttl);
}
bool hasDoubleTapTimedOut() const {
// Derive the true double-tap timeout value if we're using the default.
uint16_t dtto = (settings_.double_tap_timeout < 0)
? settings_.timeout
: settings_.double_tap_timeout;
return hasTimedOut(dtto);
}
bool hasStickyTimedOut() const {
// uint32_t dtto = (sticky_time_out_ < 0) ? timeout_ : sticky_time_out_;
return hasTimedOut32(sticky_time_out_);
}
uint8_t getOneShotKeyIndex(Key oneshot_key) const;
uint8_t getKeyIndex(Key key) const;
Key decodeOneShotKey(Key oneshot_key) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ EventHandlerResult OneShotConfig::onFocusEvent(const char *input) {
TIMEOUT,
HOLD_TIMEOUT,
DOUBLE_TAP_TIMEOUT,
STICKY_TIMEOUT,
STICKABLE_KEYS,
AUTO_MODS,
AUTO_LAYERS,
} cmd;
const char *cmd_timeout = PSTR("oneshot.timeout");
const char *cmd_hold_timeout = PSTR("oneshot.hold_timeout");
const char *cmd_double_tap_timeout = PSTR("oneshot.double_tap_timeout");
const char *cmd_sticky_temeout = PSTR("oneshot.sticky_timeout");
const char *cmd_stickable_keys = PSTR("oneshot.stickable_keys");
const char *cmd_auto_mods = PSTR("oneshot.auto_mods");
const char *cmd_auto_layers = PSTR("oneshot.auto_layers");
Expand All @@ -77,6 +79,8 @@ EventHandlerResult OneShotConfig::onFocusEvent(const char *input) {
cmd = Command::HOLD_TIMEOUT;
else if (::Focus.inputMatchesCommand(input, cmd_double_tap_timeout))
cmd = Command::DOUBLE_TAP_TIMEOUT;
else if (::Focus.inputMatchesCommand(input, cmd_sticky_timeout))
cmd = Command::STICKY_TIMEOUT;
else if (::Focus.inputMatchesCommand(input, cmd_stickable_keys))
cmd = Command::STICKABLE_KEYS;
else if (::Focus.inputMatchesCommand(input, cmd_auto_mods))
Expand All @@ -98,6 +102,9 @@ EventHandlerResult OneShotConfig::onFocusEvent(const char *input) {
case Command::DOUBLE_TAP_TIMEOUT:
::Focus.send(::OneShot.getDoubleTapTimeout());
break;
case Command::STICKY_TIMEOUT:
::Focus.send(::OneShot.getStickyTimeout());
break;
case Command::STICKABLE_KEYS:
::Focus.send(::OneShot.settings_.stickable_keys);
break;
Expand Down Expand Up @@ -129,6 +136,10 @@ EventHandlerResult OneShotConfig::onFocusEvent(const char *input) {
::Focus.read(v);
::OneShot.setDoubleTapTimeout(static_cast<int16_t>(v));
break;
case Command::STICKY_TIMEOUT:
::Focus.read(v);
::OneShot.setStickyTimeout(static_cast<uint32_t>(v));
break;
case Command::STICKABLE_KEYS:
::Focus.read(v);
::OneShot.settings_.stickable_keys = v;
Expand Down