Add public functions to set OneShot key(addr) state

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

@ -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

@ -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);

Loading…
Cancel
Save