Enable conditional compilation of PrepStickyKey & deprecated code

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent af19a43146
commit 52c1aef362
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -32,9 +32,11 @@ uint16_t OneShot::hold_timeout_ = 250;
int16_t OneShot::double_tap_timeout_ = -1; int16_t OneShot::double_tap_timeout_ = -1;
// Deprecated // Deprecated
#ifndef NDEPRECATED
uint16_t OneShot::time_out = 2500; uint16_t OneShot::time_out = 2500;
uint16_t OneShot::hold_time_out = 250; uint16_t OneShot::hold_time_out = 250;
int16_t OneShot::double_tap_time_out = -1; int16_t OneShot::double_tap_time_out = -1;
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// State variables // State variables
@ -44,8 +46,6 @@ uint16_t OneShot::stickable_keys_ = -1;
bool OneShot::auto_modifiers_ = false; bool OneShot::auto_modifiers_ = false;
bool OneShot::auto_layers_ = false; bool OneShot::auto_layers_ = false;
KeyAddr OneShot::meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
KeyAddrBitfield OneShot::temp_addrs_; KeyAddrBitfield OneShot::temp_addrs_;
KeyAddrBitfield OneShot::glue_addrs_; KeyAddrBitfield OneShot::glue_addrs_;
@ -53,6 +53,10 @@ uint16_t OneShot::start_time_ = 0;
KeyAddr OneShot::prev_key_addr_ = OneShot::invalid_key_addr; KeyAddr OneShot::prev_key_addr_ = OneShot::invalid_key_addr;
uint8_t OneShot::release_countdown_ = 0; uint8_t OneShot::release_countdown_ = 0;
#ifndef ONESHOT_WITHOUT_METASTICKY
KeyAddr OneShot::meta_sticky_key_addr_ {KeyAddr::invalid_state};
#endif
// ============================================================================ // ============================================================================
// Public interface // Public interface
@ -142,8 +146,10 @@ bool OneShot::isStickable(Key key) {
if (n < oneshot_key_count) { if (n < oneshot_key_count) {
return bitRead(stickable_keys_, n); return bitRead(stickable_keys_, n);
} }
#ifndef ONESHOT_WITHOUT_METASTICKY
} else if (key == OneShot_MetaStickyKey) { } else if (key == OneShot_MetaStickyKey) {
return true; return true;
#endif
} }
return false; return false;
} }
@ -206,6 +212,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(
if (!temp && !glue) { if (!temp && !glue) {
// This key_addr is not in a OneShot state. // This key_addr is not in a OneShot state.
#ifndef ONESHOT_WITHOUT_METASTICKY
if (meta_sticky_key_addr_.isValid()) { if (meta_sticky_key_addr_.isValid()) {
// If the meta key isn't sticky, release it // If the meta key isn't sticky, release it
bool ms_temp = temp_addrs_.read(meta_sticky_key_addr_); bool ms_temp = temp_addrs_.read(meta_sticky_key_addr_);
@ -231,10 +238,15 @@ EventHandlerResult OneShot::onKeyswitchEvent(
meta_sticky_key_addr_ = key_addr; meta_sticky_key_addr_ = key_addr;
temp_addrs_.set(key_addr); temp_addrs_.set(key_addr);
start_time_ = Runtime.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
} else // NOLINT
} else if (isOneShotKey(key) || #endif
(auto_modifiers_ && isModifier(key)) || // *INDENT-OFF*
(auto_layers_ && isLayerShift(key))) { // Because of the preceding #ifdef, indentation gets thrown off for astyle here.
// This is only an independent `if` block if `ONESHOT_WITHOUT_METASTICKY`
// is set (see above); otherwise it's an `else if`.
if (isOneShotKey(key) ||
(auto_modifiers_ && isModifier(key)) ||
(auto_layers_ && isLayerShift(key))) {
// Replace the OneShot key with its corresponding normal key. // Replace the OneShot key with its corresponding normal key.
pressKey(key_addr, key); pressKey(key_addr, key);
return EventHandlerResult::ABORT; return EventHandlerResult::ABORT;
@ -244,7 +256,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(
// pressed key is neither a modifier nor a layer shift. // pressed key is neither a modifier nor a layer shift.
release_countdown_ = (1 << 1); release_countdown_ = (1 << 1);
} }
// return EventHandlerResult::OK; // *INDENT-ON*
} else if (temp && glue) { } else if (temp && glue) {
// This key_addr is in the temporary OneShot state. // This key_addr is in the temporary OneShot state.
@ -307,9 +319,10 @@ EventHandlerResult OneShot::onKeyswitchEvent(
// `beforeReportingState()` hook below. // `beforeReportingState()` hook below.
//Layer.updateLiveCompositeKeymap(key_addr, key); //Layer.updateLiveCompositeKeymap(key_addr, key);
return EventHandlerResult::ABORT; return EventHandlerResult::ABORT;
#ifndef ONESHOT_WITHOUT_METASTICKY
} else if (key == OneShot_MetaStickyKey) { } else if (key == OneShot_MetaStickyKey) {
meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state}; meta_sticky_key_addr_ = KeyAddr{KeyAddr::invalid_state};
//cancel(true); #endif
} }
} else { } else {
@ -367,12 +380,14 @@ EventHandlerResult OneShot::afterEachCycle() {
release_countdown_ >>= 1; release_countdown_ >>= 1;
// Temporary fix for deprecated variables // Temporary fix for deprecated variables
#ifndef NDEPRECATED
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
timeout_ = time_out; timeout_ = time_out;
hold_timeout_ = hold_time_out; hold_timeout_ = hold_time_out;
double_tap_timeout_ = double_tap_time_out; double_tap_timeout_ = double_tap_time_out;
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -450,7 +465,7 @@ void OneShot::releaseKey(KeyAddr key_addr) {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Deprecated functions // Deprecated functions
#ifndef NDEPRECATED
void OneShot::inject(Key key, uint8_t key_state) { void OneShot::inject(Key key, uint8_t key_state) {
if (isOneShotKey(key)) { if (isOneShotKey(key)) {
key = decodeOneShotKey(key); key = decodeOneShotKey(key);
@ -507,6 +522,7 @@ bool OneShot::isSticky(Key key) {
} }
return false; return false;
} }
#endif
} // namespace plugin } // namespace plugin

@ -158,6 +158,7 @@ class OneShot : public kaleidoscope::Plugin {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Deprecated functions // Deprecated functions
#ifndef NDEPRECATED
DEPRECATED(ONESHOT_INJECT) DEPRECATED(ONESHOT_INJECT)
void inject(Key key, uint8_t key_state); void inject(Key key, uint8_t key_state);
@ -174,29 +175,36 @@ class OneShot : public kaleidoscope::Plugin {
static bool isPressed() { static bool isPressed() {
return false; return false;
} }
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Timeout onfiguration functions // Timeout onfiguration functions
static void setTimeout(uint16_t ttl) { static void setTimeout(uint16_t ttl) {
timeout_ = ttl; timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
time_out = ttl; time_out = ttl;
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif
} }
static void setHoldTimeout(uint16_t ttl) { static void setHoldTimeout(uint16_t ttl) {
hold_timeout_ = ttl; hold_timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
hold_time_out = ttl; hold_time_out = ttl;
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif
} }
static void setDoubleTapTimeout(int16_t ttl) { static void setDoubleTapTimeout(int16_t ttl) {
double_tap_timeout_ = ttl; double_tap_timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
double_tap_time_out = ttl; double_tap_time_out = ttl;
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -238,7 +246,6 @@ class OneShot : public kaleidoscope::Plugin {
static uint16_t stickable_keys_; static uint16_t stickable_keys_;
static bool auto_modifiers_; static bool auto_modifiers_;
static bool auto_layers_; static bool auto_layers_;
static KeyAddr meta_sticky_key_addr_;
static KeyAddrBitfield temp_addrs_; static KeyAddrBitfield temp_addrs_;
static KeyAddrBitfield glue_addrs_; static KeyAddrBitfield glue_addrs_;
@ -247,6 +254,10 @@ class OneShot : public kaleidoscope::Plugin {
static KeyAddr prev_key_addr_; static KeyAddr prev_key_addr_;
static uint8_t release_countdown_; static uint8_t release_countdown_;
#ifndef ONESHOT_WITHOUT_METASTICKY
static KeyAddr meta_sticky_key_addr_;
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Internal utility functions // Internal utility functions
static bool hasTimedOut(uint16_t ttl) { static bool hasTimedOut(uint16_t ttl) {

Loading…
Cancel
Save