From c04542759f1db579df11f1918e9da1fc8521eadc Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 13 Jun 2021 09:58:25 -0500 Subject: [PATCH] Add public functions to set OneShot key(addr) state Signed-off-by: Michael Richters --- .../src/kaleidoscope/plugin/OneShot.cpp | 29 ++++++++++++++++ .../src/kaleidoscope/plugin/OneShot.h | 34 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp index 0596bb71..aaf4dda1 100644 --- a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp +++ b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp @@ -145,6 +145,10 @@ bool OneShot::isTemporary(KeyAddr key_addr) { return temp_addrs_.read(key_addr); } +bool OneShot::isPending(KeyAddr key_addr) { + return (glue_addrs_.read(key_addr) && temp_addrs_.read(key_addr)); +} + bool OneShot::isSticky(KeyAddr key_addr) { return (glue_addrs_.read(key_addr) && !temp_addrs_.read(key_addr)); } @@ -153,6 +157,31 @@ bool OneShot::isActive(KeyAddr key_addr) { return (isTemporary(key_addr) || glue_addrs_.read(key_addr)); } +// ---------------------------------------------------------------------------- +// Public state-setting functions + +void OneShot::setPending(KeyAddr key_addr) { + temp_addrs_.set(key_addr); + glue_addrs_.clear(key_addr); + start_time_ = Runtime.millisAtCycleStart(); +} + +void OneShot::setOneShot(KeyAddr key_addr) { + temp_addrs_.set(key_addr); + glue_addrs_.set(key_addr); + start_time_ = Runtime.millisAtCycleStart(); +} + +void OneShot::setSticky(KeyAddr key_addr) { + temp_addrs_.clear(key_addr); + glue_addrs_.set(key_addr); +} + +void OneShot::clear(KeyAddr key_addr) { + temp_addrs_.clear(key_addr); + glue_addrs_.clear(key_addr); +} + // ---------------------------------------------------------------------------- // Other functions diff --git a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h index 63e8c83e..768fb553 100644 --- a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h +++ b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h @@ -159,9 +159,43 @@ class OneShot : public kaleidoscope::Plugin { static bool isStickableDefault(Key key); static bool isTemporary(KeyAddr key_addr); // inline? + static bool isPending(KeyAddr key_addr); static bool isSticky(KeyAddr key_addr); // inline? static bool isActive(KeyAddr key_addr); // inline? + // -------------------------------------------------------------------------- + // Public OneShot state control + + /// Put a key in the "pending" OneShot state. + /// + /// This function puts the key at `key_addr` in the "pending" OneShot state. + /// This is appropriate to use when a key toggles on and you want it to behave + /// like a OneShot key starting with the current event, and lasting until the + /// key becomes inactive (cancelled by a subsequent keypress). + static void setPending(KeyAddr key_addr); + + /// Put a key directly in the "one-shot" state. + /// + /// This function puts the key at `key_addr` in the "one-shot" state. This is + /// usually the state of a OneShot key after it is released, but before it is + /// cancelled by a subsequent keypress. In most cases, you probably want to + /// use `setPending()` instead, rather than calling this function explicitly, + /// as OneShot will automatically cause any key in the "pending" state to + /// progress to this state when it is (physically) released. + static void setOneShot(KeyAddr key_addr); + + /// Put a key in the "sticky" OneShot state. + /// + /// This function puts the key at `key_addr` in the "sticky" OneShot state. + /// It will remain active until it is pressed again. + static void setSticky(KeyAddr key_addr); + + /// Clear any OneShot state for a key. + /// + /// This function clears any OneShot state of the key at `key_addr`. It does + /// not, however, release the key if it is held. + static void clear(KeyAddr key_addr); + // -------------------------------------------------------------------------- // Utility function for other plugins to cancel OneShot keys static void cancel(bool with_stickies = false);