Rename 'keymapCache' to 'activeLayers' to better describe what it is

Rename effectiveKeymapCache to liveCompositeKeymap to try to
describe what it does just a tiny bit better
pull/174/head
Jesse Vincent 7 years ago
parent 29a8b95615
commit b82b6910ea
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -18,7 +18,7 @@ Kaleidoscope_::setup(void) {
handleKeyswitchEvent(Key_NoKey, 255, 255, 0); handleKeyswitchEvent(Key_NoKey, 255, 255, 0);
// Update the keymap cache, so we start with a non-empty state. // Update the keymap cache, so we start with a non-empty state.
Layer.updateKeymapCache(); Layer.updateActiveLayers();
} }
void void

@ -44,10 +44,10 @@ static bool handleKeyswitchEventDefault(Key mappedKey, byte row, byte col, uint8
} }
void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
/* If a key had an on or off event, we update the effective keymap cache. See /* If a key had an on or off event, we update the live composite keymap. See
* layers.h for an explanation about the different caches we have. */ * layers.h for an explanation about the different caches we have. */
if (keyToggledOn(keyState) || keyToggledOff(keyState)) if (keyToggledOn(keyState) || keyToggledOff(keyState))
Layer.updateEffectiveKeymapCache(row, col); Layer.updateLiveCompositeKeymap(row, col);
/* If the key we are dealing with is masked, ignore it until it is released. /* If the key we are dealing with is masked, ignore it until it is released.
* When releasing it, clear the mask, so future key events can be handled * When releasing it, clear the mask, so future key events can be handled

@ -4,8 +4,8 @@ static uint8_t DefaultLayer;
static uint32_t LayerState; static uint32_t LayerState;
uint8_t Layer_::highestLayer; uint8_t Layer_::highestLayer;
Key Layer_::effectiveKeymapCache[ROWS][COLS]; Key Layer_::liveCompositeKeymap[ROWS][COLS];
uint8_t Layer_::keymapCache[ROWS][COLS]; uint8_t Layer_::activeLayers[ROWS][COLS];
Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM; Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM;
static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
@ -63,14 +63,14 @@ Layer_::getKeyFromPROGMEM(uint8_t layer, byte row, byte col) {
} }
void void
Layer_::updateEffectiveKeymapCache(byte row, byte col) { Layer_::updateLiveCompositeKeymap(byte row, byte col) {
int8_t layer = keymapCache[row][col]; int8_t layer = activeLayers[row][col];
effectiveKeymapCache[row][col] = (*getKey)(layer, row, col); liveCompositeKeymap[row][col] = (*getKey)(layer, row, col);
} }
void void
Layer_::updateKeymapCache(void) { Layer_::updateActiveLayers(void) {
memset(keymapCache, DefaultLayer, ROWS * COLS); memset(activeLayers, DefaultLayer, ROWS * COLS);
for (byte row = 0; row < ROWS; row++) { for (byte row = 0; row < ROWS; row++) {
for (byte col = 0; col < COLS; col++) { for (byte col = 0; col < COLS; col++) {
int8_t layer = highestLayer; int8_t layer = highestLayer;
@ -80,7 +80,7 @@ Layer_::updateKeymapCache(void) {
Key mappedKey = (*getKey)(layer, row, col); Key mappedKey = (*getKey)(layer, row, col);
if (mappedKey != Key_Transparent) { if (mappedKey != Key_Transparent) {
keymapCache[row][col] = layer; activeLayers[row][col] = layer;
break; break;
} }
} }
@ -113,7 +113,7 @@ void Layer_::on(uint8_t layer) {
/* If the layer did turn on, update the keymap cache. See layers.h for an /* If the layer did turn on, update the keymap cache. See layers.h for an
* explanation about the caches we have. */ * explanation about the caches we have. */
if (!wasOn) if (!wasOn)
updateKeymapCache(); updateActiveLayers();
} }
void Layer_::off(uint8_t layer) { void Layer_::off(uint8_t layer) {
@ -126,7 +126,7 @@ void Layer_::off(uint8_t layer) {
/* If the layer did turn off, update the keymap cache. See layers.h for an /* If the layer did turn off, update the keymap cache. See layers.h for an
* explanation about the caches we have. */ * explanation about the caches we have. */
if (wasOn) if (wasOn)
updateKeymapCache(); updateActiveLayers();
} }
boolean Layer_::isOn(uint8_t layer) { boolean Layer_::isOn(uint8_t layer) {

@ -15,20 +15,22 @@ class Layer_ {
* First of all, we use caches because looking up a key through all the layers * First of all, we use caches because looking up a key through all the layers
* is costy, and the cost increases dramatically the more layers we have. * is costy, and the cost increases dramatically the more layers we have.
* *
* Then, we have the `effectiveKeymapCache`, because to have layer behaviours * Then, we have the `liveCompositeKeymap`, because to have layer behaviours
* we want, that is, if you hold a key on a layer, release the layer key but * we want, that is, if you hold a key on a layer, release the layer key but
* continue holding the other, we want for the layered keycode to continue * continue holding the other, we want for the layered keycode to continue
* repeating. At the same time, we want other keys to not be affected by the * repeating.
*
* At the same time, we want other keys to not be affected by the
* now-turned-off layer. So we update the keycode in the cache on-demand, when * now-turned-off layer. So we update the keycode in the cache on-demand, when
* the key is pressed or released. (see the top of `handleKeyswitchEvent`). * the key is pressed or released. (see the top of `handleKeyswitchEvent`).
* *
* On the other hand, we also have plugins that scan the whole keymap, and do * On the other hand, we also have plugins that scan the whole keymap, and do
* things based on that information, such as highlighting keys that changed * things based on that information, such as highlighting keys that changed
* between layers. These need to be able to look at a state of where the * between layers. These need to be able to look at a state of where the
* keymap *should* be, not necessarily where it is. The `effectiveKeymapCache` * keymap *should* be, not necessarily where it is. The `liveCompositeKeymap`
* is not useful here. So we use a `keymapCache` which we update whenever * is not useful here. So we use `activeLayers` which we update whenever
* layers change (see `Layer.on` and `Layer.off`), and it updates the cache to * layers change (see `Layer.on` and `Layer.off`), and it updates the cache to
* show how the keymap should look, without the `effectiveKeymapCache`-induced * show how the keymap should look, without the `liveCompositeKeymap`-induced
* behaviour. * behaviour.
* *
* Thus, if we are curious about what a given key will do, use `lookup`. If we * Thus, if we are curious about what a given key will do, use `lookup`. If we
@ -36,10 +38,10 @@ class Layer_ {
* `lookupUncached`. * `lookupUncached`.
*/ */
static Key lookup(byte row, byte col) { static Key lookup(byte row, byte col) {
return effectiveKeymapCache[row][col]; return liveCompositeKeymap[row][col];
} }
static Key lookupUncached(byte row, byte col) { static Key lookupUncached(byte row, byte col) {
uint8_t layer = keymapCache[row][col]; uint8_t layer = activeLayers[row][col];
return (*getKey)(layer, row, col); return (*getKey)(layer, row, col);
} }
@ -64,13 +66,13 @@ class Layer_ {
static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col); static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col);
static void updateEffectiveKeymapCache(byte row, byte col); static void updateLiveCompositeKeymap(byte row, byte col);
static void updateKeymapCache(void); static void updateActiveLayers(void);
private: private:
static uint8_t highestLayer; static uint8_t highestLayer;
static Key effectiveKeymapCache[ROWS][COLS]; static Key liveCompositeKeymap[ROWS][COLS];
static uint8_t keymapCache[ROWS][COLS]; static uint8_t activeLayers[ROWS][COLS];
}; };
Key layer_getKey(uint8_t layer, uint8_t r, uint8_t c); Key layer_getKey(uint8_t layer, uint8_t r, uint8_t c);

Loading…
Cancel
Save