|
|
@ -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);
|
|
|
|