Move the live composite keymap cache back into the Layer object

f/keymap-cache-redesign
Jesse Vincent 4 years ago
parent 9165475da1
commit a98074ae47
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -21,7 +21,6 @@
namespace kaleidoscope {
uint32_t Runtime_::millis_at_cycle_start_;
Key Runtime_::active_keys_[kaleidoscope_internal::device.numKeys()];
Runtime_::Runtime_(void) {
}
@ -43,10 +42,6 @@ Runtime_::setup(void) {
device().setup();
// Clear the active keys array (all keys idle at start)
for (auto key_addr : KeyAddr::all()) {
updateActiveKey(key_addr, Key_Transparent);
}
Layer.setup();
}

@ -128,16 +128,8 @@ class Runtime_ {
return kaleidoscope::Hooks::onFocusEvent(command);
}
static Key activeKey(KeyAddr key_addr) {
return active_keys_[key_addr.toInt()];
}
static void updateActiveKey(KeyAddr key_addr, Key key) {
active_keys_[key_addr.toInt()] = key;
}
private:
static uint32_t millis_at_cycle_start_;
static Key active_keys_[kaleidoscope_internal::device.numKeys()];
};
extern kaleidoscope::Runtime_ Runtime;

@ -123,9 +123,9 @@ void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) {
// Update the active keys cache if the key toggled on or off.
if (key_addr.isValid()) {
if (keyToggledOn(keyState)) {
Runtime.updateActiveKey(key_addr, mappedKey);
Layer.updateLiveKeymap(key_addr, mappedKey);
} else if (keyToggledOff(keyState)) {
Runtime.updateActiveKey(key_addr, Key_Transparent);
Layer.updateLiveKeymap(key_addr, Key_Transparent);
}
}

@ -42,17 +42,27 @@ uint32_t Layer_::layer_state_;
uint8_t Layer_::active_layer_count_ = 1;
int8_t Layer_::active_layers_[31];
Key Layer_::live_keymap_[Runtime.device().numKeys()];
uint8_t Layer_::active_layer_keymap_[Runtime.device().numKeys()];
Layer_::GetKeyFunction Layer_::getKey = &Layer_::getKeyFromPROGMEM;
void Layer_::setup() {
// Explicitly set layer 0's state to 1
bitSet(layer_state_, 0);
// Update the active layer cache (every entry will be `0` to start)
Layer.updateActiveLayers();
Layer.setupLiveKeymap();
}
void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.getKeyCode() >= LAYER_MOVE_OFFSET) {
if (keyToggledOn(keyState)) {
@ -119,15 +129,7 @@ Key Layer_::getKeyFromPROGMEM(uint8_t layer, KeyAddr key_addr) {
}
// Deprecated
void Layer_::updateLiveCompositeKeymap(KeyAddr key_addr) {
// We could update the active keys cache here (as commented below), but I
// think that's unlikely to serve whatever purpose the caller had in
// mind. `Layer.lookup()` will still give the correct result, and without a
// `Key` value is specified, this function no longer serves a purpose.
// int8_t layer = active_layer_keymap_[key_addr.toInt()];
// Runtime.updateActiveKey(key_addr, (*getKey)(layer, key_addr));
}
void Layer_::updateLiveCompositeKeymap(KeyAddr key_addr) { }
void Layer_::updateActiveLayers(void) {
memset(active_layer_keymap_, 0, Runtime.device().numKeys());
@ -233,6 +235,25 @@ void Layer_::forEachActiveLayer(forEachHandler h) {
}
}
void Layer_::setupLiveKeymap() {
// Clear the active keys array (all keys idle at start)
for (auto key_addr : KeyAddr::all()) {
Layer.updateLiveKeymap(key_addr, Key_Transparent);
}
}
Key Layer_::lookupOnLiveKeymap(KeyAddr key_addr) {
return live_keymap_[key_addr.toInt()];
}
void Layer_::updateLiveKeymap(KeyAddr key_addr, Key key) {
live_keymap_[key_addr.toInt()] = key;
}
}
kaleidoscope::Layer_ Layer;

@ -20,7 +20,6 @@
#include "kaleidoscope/key_defs.h"
#include "kaleidoscope/keymaps.h"
#include "kaleidoscope/device/device.h"
#include "kaleidoscope/Runtime.h"
#include "kaleidoscope_internal/device.h"
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"
#include "kaleidoscope_internal/shortname.h"
@ -85,17 +84,22 @@ class Layer_ {
*/
static Key lookup(KeyAddr key_addr) {
// First check the active keys array
Key key = Runtime.activeKey(key_addr);
Key key = lookupOnLiveKeymap(key_addr);
// If that entry is clear, look up the entry from the active keymap layers
if (key == Key_Transparent) {
key = lookupOnActiveLayer(key_addr);
}
return key;
}
static Key lookupOnLiveKeymap(KeyAddr key_addr);
static Key lookupOnActiveLayer(KeyAddr key_addr) {
uint8_t layer = active_layer_keymap_[key_addr.toInt()];
return (*getKey)(layer, key_addr);
}
static uint8_t lookupActiveLayer(KeyAddr key_addr) {
return active_layer_keymap_[key_addr.toInt()];
}
@ -133,13 +137,19 @@ class Layer_ {
DEPRECATED(LAYER_UPDATELIVECOMPOSITEKEYMAP)
static void updateLiveCompositeKeymap(KeyAddr key_addr, Key mappedKey) {
Runtime.updateActiveKey(key_addr, mappedKey);
updateLiveKeymap(key_addr, mappedKey);
}
DEPRECATED(LAYER_UPDATELIVECOMPOSITEKEYMAP)
static void updateLiveCompositeKeymap(KeyAddr key_addr);
static void updateActiveLayers(void);
static void updateLiveKeymap(KeyAddr key_addr, Key key);
private:
static void setupLiveKeymap();
using forEachHandler = void(*)(uint8_t index, uint8_t layer);
public:
@ -149,7 +159,10 @@ class Layer_ {
static uint32_t layer_state_;
static uint8_t active_layer_count_;
static int8_t active_layers_[31];
static Key live_keymap_[kaleidoscope_internal::device.numKeys()];
static uint8_t active_layer_keymap_[kaleidoscope_internal::device.numKeys()];
};
}

@ -17,6 +17,7 @@
#include <Kaleidoscope-ShapeShifter.h>
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope {
namespace plugin {
@ -50,7 +51,7 @@ EventHandlerResult ShapeShifter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a
bool shift_detected = false;
for (KeyAddr k : KeyAddr::all()) {
if (Runtime.activeKey(k).isKeyboardShift())
if (Layer.lookupOnLiveKeymap(k).isKeyboardShift())
shift_detected = true;
}
if (! shift_detected)

@ -46,7 +46,7 @@ void TapDance::actionKeys(uint8_t tap_count,
break;
{
KeyAddr td_addr = event_queue_.addr(0);
bool key_released = (Runtime.activeKey(td_addr) == Key_Transparent);
bool key_released = (Layer.lookupOnLiveKeymap(td_addr) == Key_Transparent);
handleKeyswitchEvent(key, td_addr, IS_PRESSED | INJECTED);
if (key_released)
release_addr_ = td_addr;

Loading…
Cancel
Save