Add automatic OneShot modifier/layer-shift feature

This adds a new feature to OneShot: it can now (optionally) treat
modifiers and layer-shift keys as automatic OneShot keys, with
functions to enable and disable this feature for modifiers and
layer-shifts independently.

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

@ -45,8 +45,7 @@ EventHandlerResult ActiveModColorEffect::onKeyswitchEvent(
// it will get highlighted. Conditionally (if
// `highlight_normal_modifiers_` is set), we also highlight
// modifier and layer-shift keys.
if ((key >= Key_LeftControl && key <= Key_RightGui) ||
(key.getFlags() == (SYNTHETIC | SWITCH_TO_KEYMAP))) {
if (::OneShot.isModifier() || ::OneShot.isLayerShift()) {
mod_key_bits_.set(key_addr);
}
} else if (keyToggledOff(key_state)) {

@ -41,6 +41,9 @@ int16_t OneShot::double_tap_time_out = -1;
uint16_t OneShot::stickable_keys_ = -1;
bool OneShot::auto_modifiers_ = false;
bool OneShot::auto_layers_ = false;
KeyAddrBitfield OneShot::temp_addrs_;
KeyAddrBitfield OneShot::glue_addrs_;
@ -199,7 +202,9 @@ EventHandlerResult OneShot::onKeyswitchEvent(
if (!temp && !glue) {
// This key_addr is not in a OneShot state.
if (isOneShotKey(key)) {
if (isOneShotKey(key) ||
(auto_modifiers_ && isModifier(key)) ||
(auto_layers_ && isLayerShift(key))) {
// Replace the OneShot key with its corresponding normal key.
pressKey(key_addr, key);
return EventHandlerResult::ABORT;
@ -382,8 +387,10 @@ Key OneShot::decodeOneShotKey(Key oneshot_key) {
// ------------------------------------------------------------------------------
// Helper functions for sending key events for keys in OneShot states
void OneShot::pressKey(KeyAddr key_addr, Key oneshot_key) {
Key key = decodeOneShotKey(oneshot_key);
void OneShot::pressKey(KeyAddr key_addr, Key key) {
if (isOneShotKey(key)) {
key = decodeOneShotKey(key);
}
prev_key_addr_ = key_addr;
start_time_ = Runtime.millisAtCycleStart();
temp_addrs_.set(key_addr);
@ -404,8 +411,8 @@ void OneShot::releaseKey(KeyAddr key_addr) {
// Deprecated functions
void OneShot::inject(Key key, uint8_t key_state) {
if (! isOneShotKey(key)) {
return;
if (isOneShotKey(key)) {
key = decodeOneShotKey(key);
}
// Find an idle keyswitch to use for the injected OneShot key and activate
// it. This is an ugly hack, but it will work. It does mean that whatever key
@ -435,11 +442,10 @@ bool OneShot::isModifierActive(Key key) {
return false;
}
bool OneShot::isActive(Key oneshot_key) {
if (! isOneShotKey(oneshot_key)) {
return false;
bool OneShot::isActive(Key key) {
if (isOneShotKey(key)) {
key = decodeOneShotKey(key);
}
Key key = decodeOneShotKey(oneshot_key);
for (KeyAddr key_addr : glue_addrs_) {
if (live_keys[key_addr] == key) {
return true;
@ -448,11 +454,10 @@ bool OneShot::isActive(Key oneshot_key) {
return false;
}
bool OneShot::isSticky(Key oneshot_key) {
if (! isOneShotKey(oneshot_key)) {
return false;
bool OneShot::isSticky(Key key) {
if (isOneShotKey(key)) {
key = decodeOneShotKey(key);
}
Key key = decodeOneShotKey(oneshot_key);
for (KeyAddr key_addr : glue_addrs_) {
if (live_keys[key_addr] == key &&
!temp_addrs_.read(key_addr)) {

@ -91,6 +91,42 @@ class OneShot : public kaleidoscope::Plugin {
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();
}
}
// --------------------------------------------------------------------------
// Global test functions
@ -103,6 +139,9 @@ class OneShot : public kaleidoscope::Plugin {
return (key.getRaw() >= kaleidoscope::ranges::OS_FIRST &&
key.getRaw() <= kaleidoscope::ranges::OS_LAST);
}
static bool isModifier(Key key);
static bool isLayerShift(Key key);
static bool isStickable(Key key); // inline?
static bool isTemporary(KeyAddr key_addr); // inline?
@ -193,6 +232,8 @@ class OneShot : public kaleidoscope::Plugin {
// --------------------------------------------------------------------------
// State variables
static uint16_t stickable_keys_;
static bool auto_modifiers_;
static bool auto_layers_;
static KeyAddrBitfield temp_addrs_;
static KeyAddrBitfield glue_addrs_;

Loading…
Cancel
Save