|
|
|
@ -15,20 +15,22 @@ class Layer_ {
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* 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
|
|
|
|
|
* 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
|
|
|
|
|
* 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
|
|
|
|
|
* keymap *should* be, not necessarily where it is. The `effectiveKeymapCache`
|
|
|
|
|
* is not useful here. So we use a `keymapCache` which we update whenever
|
|
|
|
|
* keymap *should* be, not necessarily where it is. The `liveCompositeKeymap`
|
|
|
|
|
* 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
|
|
|
|
|
* show how the keymap should look, without the `effectiveKeymapCache`-induced
|
|
|
|
|
* show how the keymap should look, without the `liveCompositeKeymap`-induced
|
|
|
|
|
* behaviour.
|
|
|
|
|
*
|
|
|
|
|
* Thus, if we are curious about what a given key will do, use `lookup`. If we
|
|
|
|
@ -36,10 +38,10 @@ class Layer_ {
|
|
|
|
|
* `lookupUncached`.
|
|
|
|
|
*/
|
|
|
|
|
static Key lookup(byte row, byte col) {
|
|
|
|
|
return effectiveKeymapCache[row][col];
|
|
|
|
|
return liveCompositeKeymap[row][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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -64,13 +66,13 @@ class Layer_ {
|
|
|
|
|
|
|
|
|
|
static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col);
|
|
|
|
|
|
|
|
|
|
static void updateEffectiveKeymapCache(byte row, byte col);
|
|
|
|
|
static void updateKeymapCache(void);
|
|
|
|
|
static void updateLiveCompositeKeymap(byte row, byte col);
|
|
|
|
|
static void updateActiveLayers(void);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static uint8_t highestLayer;
|
|
|
|
|
static Key effectiveKeymapCache[ROWS][COLS];
|
|
|
|
|
static uint8_t keymapCache[ROWS][COLS];
|
|
|
|
|
static Key liveCompositeKeymap[ROWS][COLS];
|
|
|
|
|
static uint8_t activeLayers[ROWS][COLS];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Key layer_getKey(uint8_t layer, uint8_t r, uint8_t c);
|
|
|
|
|