Introduce a new event: onLayerChange

The intent is to make it easier for plugins to detect layer changes and schedule
work accordingly. There event receives no arguments, the current state can
always be queried with `Layer.getLayerState()`, and if a plugin requires the old
state too, they can track that on their own.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/363/head
Gergely Nagy 6 years ago
parent 705597f649
commit 445687634e
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -79,6 +79,10 @@ The [Cycle](doc/plugin/Cycle.md) plugin has much better support for cycling thro
There are situations where one would like to disable sending a report after each and every step of a macro, and rather have direct control over when reports are sent. The new `WITH_EXPLICIT_REPORT`, `WITH_IMPLICIT_REPORT` and `SEND_REPORT` steps help with that. Please see the [Macros](doc/plugin/Macros.md) documentation for more information. There are situations where one would like to disable sending a report after each and every step of a macro, and rather have direct control over when reports are sent. The new `WITH_EXPLICIT_REPORT`, `WITH_IMPLICIT_REPORT` and `SEND_REPORT` steps help with that. Please see the [Macros](doc/plugin/Macros.md) documentation for more information.
### Events now trigger on layer changes
Changing layers now triggers the `onLayerChange` event - but only if there was real change (thus, calling `Layer.on(SOME_LAYER)` multiple times in a row will only trigger one event). This event was introduced to help plugins that depend on layer state schedule their work better.
## New hardware support ## New hardware support
Kaleidoscope has been ported to the following devices: Kaleidoscope has been ported to the following devices:

@ -71,6 +71,12 @@
(const char *command), __NL__ \ (const char *command), __NL__ \
(command), ##__VA_ARGS__) __NL__ \ (command), ##__VA_ARGS__) __NL__ \
__NL__ \ __NL__ \
/* Called when the layer state changes. Which layes changed are */ __NL__ \
/* not passed as arguments. If one needs that info, they should */ __NL__ \
/* track Layer.getState() themselves. */ __NL__ \
OPERATION(onLayerChange, __NL__ \
_NOT_ABORTABLE, __NL__ \
(), (), ##__VA_ARGS__) __NL__ \
/* Called before reporting our state to the host. This is the */ __NL__ \ /* Called before reporting our state to the host. This is the */ __NL__ \
/* last point in a cycle where a plugin can alter what gets */ __NL__ \ /* last point in a cycle where a plugin can alter what gets */ __NL__ \
/* reported to the host. */ __NL__ \ /* reported to the host. */ __NL__ \

@ -32,6 +32,9 @@ extern void handleKeyswitchEvent(kaleidoscope::Key mappedKey, byte row, byte col
namespace kaleidoscope { namespace kaleidoscope {
// Forward declaration to enable friend declarations.
class Layer_;
// The reason why the hook routing entry point functions live within // The reason why the hook routing entry point functions live within
// class Hooks and not directly within a namespace is, that we want // class Hooks and not directly within a namespace is, that we want
// to restrict who is allowed to trigger hooks, mainly to prevent // to restrict who is allowed to trigger hooks, mainly to prevent
@ -49,6 +52,7 @@ class Hooks {
// Kaleidoscope_ calls Hooks::onSetup, Hooks::beforeReportingState // Kaleidoscope_ calls Hooks::onSetup, Hooks::beforeReportingState
// and Hooks::afterEachCycle. // and Hooks::afterEachCycle.
friend class Kaleidoscope_; friend class Kaleidoscope_;
friend class ::kaleidoscope::Layer_;
// ::handleKeyswitchEvent(...) calls Hooks::onKeyswitchEvent. // ::handleKeyswitchEvent(...) calls Hooks::onKeyswitchEvent.
friend void ::handleKeyswitchEvent(kaleidoscope::Key mappedKey, friend void ::handleKeyswitchEvent(kaleidoscope::Key mappedKey,

@ -168,6 +168,8 @@ void Layer_::on(uint8_t layer) {
// Update the keymap cache (but not liveCompositeKeymap; that gets // Update the keymap cache (but not liveCompositeKeymap; that gets
// updated separately, when keys toggle on or off. See layers.h) // updated separately, when keys toggle on or off. See layers.h)
updateActiveLayers(); updateActiveLayers();
kaleidoscope::Hooks::onLayerChange();
} }
// Deactivate a given layer // Deactivate a given layer
@ -187,6 +189,8 @@ void Layer_::off(uint8_t layer) {
// Update the keymap cache (but not liveCompositeKeymap; that gets // Update the keymap cache (but not liveCompositeKeymap; that gets
// updated separately, when keys toggle on or off. See layers.h) // updated separately, when keys toggle on or off. See layers.h)
updateActiveLayers(); updateActiveLayers();
kaleidoscope::Hooks::onLayerChange();
} }
boolean Layer_::isOn(uint8_t layer) { boolean Layer_::isOn(uint8_t layer) {

Loading…
Cancel
Save