Expose OneShot.isSticky

pull/389/head
David Glasser 7 years ago
parent 91971489cf
commit 2d0152e416

@ -78,6 +78,10 @@ modifiers and one-shot layer keys. It has the following methods:
> useful for macros that need to fiddle with either modifier or layer state: if
> one-shots are not active, they need not restore the original state.
### `.isSticky(key)`
> Returns if the key is currently sticky.
### `.isModifierActive(key)`
> Returns if the modifier `key` has a one-shot state active. Use this together

@ -44,7 +44,7 @@ bool OneShot::should_mask_on_interrupt_ = false;
#define setOneShot(idx) (bitWrite (state_.all, idx, 1))
#define clearOneShot(idx) (bitWrite (state_.all, idx, 0))
#define isSticky(idx) (bitRead (sticky_state_.all, idx))
#define isSticky_(idx) (bitRead (sticky_state_.all, idx))
#define setSticky(idx) (bitWrite (sticky_state_.all, idx, 1))
#define clearSticky(idx) bitWrite (sticky_state_.all, idx, 0)
@ -114,7 +114,7 @@ Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_st
return mapped_key;
if (isOneShotKey(mapped_key)) {
if (isSticky(idx)) {
if (isSticky_(idx)) {
if (keyToggledOn(key_state)) { // maybe on _off instead?
saveAsPrevious(mapped_key);
clearSticky(idx);
@ -173,7 +173,7 @@ void OneShot::loopHook(bool is_post_clear) {
for (uint8_t i = 0; i < 32; i++) {
if (should_cancel_) {
if (isSticky(i)) {
if (isSticky_(i)) {
if (should_cancel_stickies_) {
is_cancelled = true;
clearSticky(i);
@ -216,7 +216,13 @@ bool OneShot::isActive(void) {
bool OneShot::isActive(Key key) {
uint8_t idx = key.raw - ranges::OS_FIRST;
return (bitRead(state_.all, idx) && !hasTimedOut()) || (isPressed(idx)) || (isSticky(idx));
return (bitRead(state_.all, idx) && !hasTimedOut()) || (isPressed(idx)) || (isSticky_(idx));
}
bool OneShot::isSticky(Key key) {
uint8_t idx = key.raw - ranges::OS_FIRST;
return (isSticky_(idx));
}
bool OneShot::isModifierActive(Key key) {

@ -37,6 +37,7 @@ class OneShot : public KaleidoscopePlugin {
}
static bool isActive(void);
static bool isActive(Key key);
static bool isSticky(Key key);
static void cancel(bool with_stickies);
static void cancel(void) {
cancel(false);

Loading…
Cancel
Save