From 2d0152e416cd27a0e78d33d3e466698e23bbadfe Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 17 Oct 2017 01:49:45 -0700 Subject: [PATCH] Expose OneShot.isSticky --- README.md | 4 ++++ src/Kaleidoscope/OneShot.cpp | 14 ++++++++++---- src/Kaleidoscope/OneShot.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a01674e5..446c8eed 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Kaleidoscope/OneShot.cpp b/src/Kaleidoscope/OneShot.cpp index 15d485bc..a625e024 100644 --- a/src/Kaleidoscope/OneShot.cpp +++ b/src/Kaleidoscope/OneShot.cpp @@ -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) { diff --git a/src/Kaleidoscope/OneShot.h b/src/Kaleidoscope/OneShot.h index 189188b4..1f4a8084 100644 --- a/src/Kaleidoscope/OneShot.h +++ b/src/Kaleidoscope/OneShot.h @@ -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);