You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kaleidoscope/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h

278 lines
9.3 KiB

/* -*- mode: c++ -*-
* Kaleidoscope-OneShot -- One-shot modifiers and layers
* Copyright (C) 2016-2021 Keyboard.io, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h>
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/KeyAddrBitfield.h"
// ----------------------------------------------------------------------------
// Deprecation warning messages
#define _DEPRECATED_MESSAGE_ONESHOT_TIMEOUT \
"The `OneShot.time_out` variable is deprecated. Please use the\n" \
"`OneShot.setTimeout()` function instead."
#define _DEPRECATED_MESSAGE_ONESHOT_HOLD_TIMEOUT \
"The `OneShot.hold_time_out` variable is deprecated. Please use the\n" \
"`OneShot.setHoldTimeout()` function instead."
#define _DEPRECATED_MESSAGE_ONESHOT_DOUBLE_TAP_TIMEOUT \
"The `OneShot.double_tap_time_out` variable is deprecated. Please use the\n" \
"`OneShot.setDoubleTapTimeout()` function instead."
#define _DEPRECATED_MESSAGE_ONESHOT_INJECT \
"The `OneShot.inject(key, key_state)` function has been deprecated."
#define _DEPRECATED_MESSAGE_ONESHOT_ISACTIVE_KEY \
"The `OneShot.isActive(key)` function is deprecated. Please use\n" \
"`OneShot.isActive(key_addr)` instead, if possible."
#define _DEPRECATED_MESSAGE_ONESHOT_ISSTICKY_KEY \
"The `OneShot.isSticky(key)` function is deprecated. Please use\n" \
"`OneShot.isSticky(key_addr)` instead, if possible."
#define _DEPRECATED_MESSAGE_ONESHOT_ISPRESSED \
"The `OneShot.isPressed()` function is deprecated. This function now\n" \
"always returns false."
#define _DEPRECATED_MESSAGE_ONESHOT_ISMODIFIERACTIVE \
"The `OneShot.isModifierActive()` function is deprecated."
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// ----------------------------------------------------------------------------
// Keymap macros
#define OSM(kc) Key(kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).getKeyCode() - Key_LeftControl.getKeyCode())
#define OSL(n) Key(kaleidoscope::ranges::OSL_FIRST + n)
// ----------------------------------------------------------------------------
// Key constants
constexpr Key OneShot_MetaStickyKey {kaleidoscope::ranges::OS_META_STICKY};
constexpr Key OneShot_ActiveStickyKey {kaleidoscope::ranges::OS_ACTIVE_STICKY};
namespace kaleidoscope {
namespace plugin {
class OneShot : public kaleidoscope::Plugin {
public:
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// Constructor
OneShot() {}
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Configuration functions
static inline void enableStickablity() {}
static void enableStickability(Key key);
template <typename... Keys>
static void enableStickability(Key key, Keys&&... keys) {
enableStickability(key);
enableStickability(keys...);
}
static void enableStickabilityForModifiers();
static void enableStickabilityForLayers();
static inline void disableStickability() {}
static void disableStickability(Key key);
template <typename... Keys>
static void disableStickability(Key key, Keys&&... keys) {
disableStickability(key);
disableStickability(keys...);
}
static void disableStickabilityForModifiers();
static void disableStickabilityForLayers();
static void enableAutoModifiers() {
auto_modifiers_ = true;
}
static void enableAutoLayers() {
auto_layers_ = true;
}
static void enableAutoOneShot() {
enableAutoModifiers();
enableAutoLayers();
}
static void disableAutoModifiers() {
auto_modifiers_ = false;
}
static void disableAutoLayers() {
auto_layers_ = false;
}
static void disableAutoOneShot() {
disableAutoModifiers();
disableAutoLayers();
}
static void toggleAutoModifiers() {
auto_modifiers_ = ! auto_modifiers_;
}
static void toggleAutoLayers() {
auto_layers_ = ! auto_layers_;
}
static void toggleAutoOneShot() {
if (auto_modifiers_ || auto_layers_) {
disableAutoOneShot();
} else {
enableAutoOneShot();
}
}
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Global test functions
static bool isActive();
static bool isSticky();
// --------------------------------------------------------------------------
// Single-key test functions
static bool isOneShotKey(Key key) {
return (key.getRaw() >= kaleidoscope::ranges::OS_FIRST &&
key.getRaw() <= kaleidoscope::ranges::OS_LAST);
}
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static bool isStickable(Key key); // inline?
static bool isTemporary(KeyAddr key_addr); // inline?
static bool isSticky(KeyAddr key_addr); // inline?
static bool isActive(KeyAddr key_addr); // inline?
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Utility function for other plugins to cancel OneShot keys
static void cancel(bool with_stickies = false);
// --------------------------------------------------------------------------
// Deprecated functions
#ifndef NDEPRECATED
DEPRECATED(ONESHOT_INJECT)
void inject(Key key, uint8_t key_state);
DEPRECATED(ONESHOT_ISMODIFIERACTIVE)
static bool isModifierActive(Key key);
DEPRECATED(ONESHOT_ISACTIVE_KEY)
static bool isActive(Key oneshot_key);
DEPRECATED(ONESHOT_ISSTICKY_KEY)
static bool isSticky(Key oneshot_key);
DEPRECATED(ONESHOT_ISPRESSED)
static bool isPressed() {
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
return false;
}
#endif
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Timeout onfiguration functions
static void setTimeout(uint16_t ttl) {
timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
time_out = ttl;
#pragma GCC diagnostic pop
#endif
}
static void setHoldTimeout(uint16_t ttl) {
hold_timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
hold_time_out = ttl;
#pragma GCC diagnostic pop
#endif
}
static void setDoubleTapTimeout(int16_t ttl) {
double_tap_timeout_ = ttl;
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
double_tap_time_out = ttl;
#pragma GCC diagnostic pop
#endif
}
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Configuration variables (should probably be private)
DEPRECATED(ONESHOT_TIMEOUT)
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static uint16_t time_out;
DEPRECATED(ONESHOT_HOLD_TIMEOUT)
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static uint16_t hold_time_out;
DEPRECATED(ONESHOT_DOUBLE_TAP_TIMEOUT)
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static int16_t double_tap_time_out;
// --------------------------------------------------------------------------
// Plugin hook functions
EventHandlerResult onNameQuery();
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult beforeReportingState();
EventHandlerResult afterEachCycle();
private:
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Constants
static constexpr uint8_t oneshot_key_count = 16;
static constexpr uint8_t oneshot_mod_count = 8;
static constexpr uint8_t oneshot_layer_count = oneshot_key_count - oneshot_mod_count;
static constexpr uint16_t stickable_modifiers_mask = uint16_t(uint16_t(-1) >> oneshot_layer_count);
static constexpr uint16_t stickable_layers_mask = uint16_t(uint16_t(-1) << oneshot_mod_count);
static constexpr KeyAddr invalid_key_addr = KeyAddr(KeyAddr::invalid_state);
// --------------------------------------------------------------------------
// Configuration variables
static uint16_t timeout_;
static uint16_t hold_timeout_;
static int16_t double_tap_timeout_;
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// State variables
static uint16_t stickable_keys_;
static bool auto_modifiers_;
static bool auto_layers_;
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static KeyAddrBitfield temp_addrs_;
static KeyAddrBitfield glue_addrs_;
static uint16_t start_time_;
static KeyAddr prev_key_addr_;
static uint8_t release_countdown_;
#ifndef ONESHOT_WITHOUT_METASTICKY
static KeyAddr meta_sticky_key_addr_;
#endif
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
// --------------------------------------------------------------------------
// Internal utility functions
static bool hasTimedOut(uint16_t ttl) {
return Runtime.hasTimeExpired(start_time_, ttl);
}
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
static uint8_t getOneShotKeyIndex(Key oneshot_key);
static uint8_t getKeyIndex(Key key);
static Key decodeOneShotKey(Key oneshot_key);
static void pressKey(KeyAddr key_addr, Key oneshot_key);
static void holdKey(KeyAddr key_addr);
static void releaseKey(KeyAddr key_addr);
};
Rewrite OneShot plugin This is a complete rewrite of OneShot, based on the keymap cache redesign. This allows OneShot to abort the release of a key, causing its cache entry to stay valid if it's in an active state after the key is released, allowing us to fix #896 (double-tapping a layer shift key doesn't make it sticky). Instead of tracking `Key` values, OneShot now uses two bitfields of the keyboard in order to track the OneShot state of every valid `KeyAddr` independently. This could enable the creation of a OneShot "meta" key, which could be used as a way to make any key on the keyboard exhibit OneShot behaviour. The new OneShot plugin immediately replaces the OneShot `Key` value with its corresponding "normal" key, and activates its OneShot status by setting one bit in one of the bitfields. Also included: * A rewrite of LED-ActiveModColor that makes it compatible with the new OneShot, and add support for Qukeys * Updates to Escape-OneShot for compatibility and efficiency * Minor updates to Qukeys * The new KeyAddrBitfield class KeyAddrBitfield: This class can be used to represent a binary state of the physical key addresses on the keyboard. For example, ActiveModColor can use to to mark all the keys which should be highlighted at any given time. It includes a very efficient iterator, which returns only `KeyAddr` values corresponding to bits that are set in the bitfield. It checks a whole byte at a time before examining individual bits, so if most bits are unset most of the time, it's very fast, and suitable for use in hooks that get called every cycle. ActiveModColor: This makes LED-ActiveModColor compatible with Qukeys, and removes its 16-modifier limit, while simultaneously reducing it's footprint in RAM and eliminating a potential buffer overrun bug where it could have written past the end of its state array. Fixes #882 Fixes #894 Fixes #896 Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
4 years ago
} // namespace plugin
} // namespace kaleidoscope
extern kaleidoscope::plugin::OneShot OneShot;